From 41a0a938f844f96450bc13dc35a9102016e650fd Mon Sep 17 00:00:00 2001 From: Simon <965089+sarthurdev@users.noreply.github.com> Date: Mon, 16 Aug 2021 15:59:03 +0200 Subject: [PATCH] Add LAGG support to console (#4499) --- src/etc/inc/console.inc | 133 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/src/etc/inc/console.inc b/src/etc/inc/console.inc index 397dff958..b171918da 100644 --- a/src/etc/inc/console.inc +++ b/src/etc/inc/console.inc @@ -132,6 +132,40 @@ EOD; $ifnames = array_keys($iflist); + echo << $ifa) { + $unused_ifs[$iface] = $ifa; + } + + while (1) { + $lagg = array(); + + echo "\nLAGG-capable interfaces:\n\n"; + if (!is_array($iflist)) { + echo "No interfaces found!\n"; + } else { + $lagg_capable = 0; + foreach ($unused_ifs as $iface => $ifa) { + echo sprintf( + "% -8s%s%s\n", + $iface, + $ifa['mac'], + $ifa['up'] ? " (up)" : "" + ); + $lagg_capable++; + } + } + + if ($lagg_capable == 0) { + echo "No LAGG-capable interfaces detected.\n"; + return; + } + + echo "\nEnter the member interface names for the new LAGG seperated by commas (or nothing if finished): "; + $members_str = chop(fgets($fp)); + + if ($members_str) { + $members = explode(",", str_replace(" ", "", $members_str)); + $unused_ifnames = array_keys($unused_ifs); + $valid_ifs = array_intersect($unused_ifnames, $members); + if (count($members) != count($valid_ifs)) { + $invalid_ifs = array_diff($members, $unused_ifnames); + printf("\nInvalid interfaces: %s\n", implode(", ", $invalid_ifs)); + continue; + } + $lagg['members'] = str_replace(" ", "", $members_str); + + foreach($members as $member) { + unset($unused_ifs[$member]); + } + } else { + break; + } + + echo 'Enter the LAGG protocol (none,lacp,failover,fec,loadbalance,roundrobin): '; + $lagg['proto'] = strtolower(chop(fgets($fp))); + if (!in_array($lagg['proto'], ['none', 'lacp', 'failover', 'fec', 'loadbalance', 'roundrobin'])) { + printf("\nInvalid LAGG protocol '%s'\n", $lagg['proto']); + continue; + } + + if ($lagg['proto'] == "lacp") { + echo "Do you want to enable LACP fast timeout? ${yes_no_prompt}"; + + if (strcasecmp(chop(fgets($fp)), "y") == 0) { + $lagg['lacp_fast_timeout'] = true; + } + } + + echo 'Enter the LAGG MTU (leave blank for auto): '; + $lagg['mtu'] = chop(fgets($fp)); + if (!$lagg['mtu']) { + $lagg['mtu'] = null; + } + + $lagg['laggif'] = 'lagg' . $laggif; + + $laggcfg[] = $lagg; + $laggif++; + } +} + function vlan_setup($iflist, $fp) { $vlancfg = &config_read_array('vlans', 'vlan');