summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluwenpeng <[email protected]>2022-03-15 11:56:31 +0800
committerluwenpeng <[email protected]>2022-03-23 14:31:51 +0800
commit4a45654452d089f3fce284ee778ecae832e4c548 (patch)
tree706054d68a2ed5dafa64da5a6628107edc9922e4
parent5f6f5e7c510098107bbd1adcd0a17a59cfcfb91b (diff)
TSG-9977 ONIE适配TSG-X设备支持配置主备模式的LAGv2.0.3-20220323
-rw-r--r--machine/geedge/TSG-X_NXR620G40_R01/kernel/config8
-rwxr-xr-xmachine/geedge/TSG-X_NXR620G40_R01/rootconf/sysroot-init/networking.sh216
-rwxr-xr-xrootconf/default/bin/onie-netcfg-set164
3 files changed, 150 insertions, 238 deletions
diff --git a/machine/geedge/TSG-X_NXR620G40_R01/kernel/config b/machine/geedge/TSG-X_NXR620G40_R01/kernel/config
index 0de5f57d..83fe6db6 100644
--- a/machine/geedge/TSG-X_NXR620G40_R01/kernel/config
+++ b/machine/geedge/TSG-X_NXR620G40_R01/kernel/config
@@ -304,4 +304,10 @@ CONFIG_USB_HIDDEV=y
CONFIG_I40E=y
CONFIG_I40E_DCB=y
-CONFIG_I40EVF=y \ No newline at end of file
+CONFIG_I40EVF=y
+
+#
+# Support LAG
+#
+
+CONFIG_BONDING=y \ No newline at end of file
diff --git a/machine/geedge/TSG-X_NXR620G40_R01/rootconf/sysroot-init/networking.sh b/machine/geedge/TSG-X_NXR620G40_R01/rootconf/sysroot-init/networking.sh
index 4603a88c..f3a226eb 100755
--- a/machine/geedge/TSG-X_NXR620G40_R01/rootconf/sysroot-init/networking.sh
+++ b/machine/geedge/TSG-X_NXR620G40_R01/rootconf/sysroot-init/networking.sh
@@ -12,188 +12,56 @@ PATH=/usr/bin:/usr/sbin:/bin:/sbin
import_cmdline
-# Static ethernet management configuration
-config_ethmgmt_static()
-{
- local intf=$1
- shift
-
- if [ -n "$onie_ip" ] ; then
- # ip= was set on the kernel command line and configured by the
- # kernel already. Do no more.
- log_console_msg "${intf}: Using static IP config: ip=$onie_ip"
- return 0
- fi
-
- return 1
-}
-
-# DHCPv6 ethernet management configuration
-config_ethmgmt_dhcp6()
-{
- intf=$1
- shift
+arch_networking="/lib/onie/networking-${onie_switch_asic}"
+platform_networking="/lib/onie/networking-platform"
- # TODO
- # log_info_msg "TODO: Checking for DHCPv6 ethmgmt configuration."
+[ -r "$arch_networking" ] && . "$arch_networking"
+[ -r "$platform_networking" ] && . "$platform_networking"
- return 1
-}
+config_ethmgmt() {
+ onie_env_array=$(cat /mnt/onie-boot/grub/grubenv | grep ONIE_NETWORK_ | grep -v "\#")
+ onie_env_num=$(cat /mnt/onie-boot/grub/grubenv | grep ONIE_NETWORK_ | grep -v "\#" | wc -l)
-# DHCPv4 ethernet management configuration
-config_ethmgmt_dhcp4()
-{
- intf=$1
- shift
-
- # no default args
- udhcp_args="$(udhcpc_args) -n -o"
- if [ "$1" = "discover" ] ; then
- udhcp_args="$udhcp_args -t 5 -T 3"
- else
- udhcp_args="$udhcp_args -t 15 -T 3"
+ if [ "$onie_env_num" == 0 ]; then
+ log_info_msg "Please use onie-netcfg-set config ONIE network !!!"
+ return 0
fi
- udhcp_request_opts=
- for o in subnet broadcast router domain hostname ntpsrv dns logsrv search ; do
- udhcp_request_opts="$udhcp_request_opts -O $o"
+
+ for onie_env in $onie_env_array; do
+ cmd_run export $onie_env
done
- log_info_msg "Trying DHCPv4 on interface: $intf"
- udhcpc $udhcp_args $udhcp_request_opts $udhcp_user_class \
- -i $intf -s /lib/onie/udhcp4_net > /dev/null 2>&1
- if [ "$?" = "0" ] ; then
- local ipaddr=$(ifconfig $intf |grep 'inet '|sed -e 's/:/ /g'|awk '{ print $3 " / " $7 }')
- log_console_msg "Using DHCPv4 addr: ${intf}: $ipaddr"
- else
- log_warning_msg "Unable to configure interface using DHCPv4: $intf"
- return 1
+ dump_env=$(env | grep ONIE_NETWORK | sort)
+ log_console_msg "$dump_env"
+
+ if [ -n "ONIE_NETWORK_BOND_SLAVES" ]; then
+ cmd_run ifconfig bond0 down
+ #cmd_run echo +bond0 >/sys/class/net/bonding_masters
+ cmd_run echo active-backup >/sys/class/net/bond0/bonding/mode
+ cmd_run echo 100 >/sys/class/net/bond0/bonding/miimon
+
+ interface_array=$(echo $ONIE_NETWORK_BOND_SLAVES | tr ',' ' ')
+ for eth in $interface_array; do
+ cmd_run ifconfig $eth down
+ cmd_run echo +$eth >/sys/class/net/bond0/bonding/slaves
+ cmd_run ifconfig $eth up
+ done
fi
- return 0
-}
-
-# Fall back ethernet management configuration
-# Configure an IPv4 link-local address per RFC-3927.
-config_ethmgmt_fallback()
-{
-
- local prefix=16
- local default_hn="onie-host"
- local intf_counter=$1
- shift
- local intf=$1
- shift
-
- # Remove any previously configured, IPv4 addresses
- ip -f inet addr flush dev $intf
-
- # Maximum number of attempts to find an unused 169.254.x.y/16
- # address.
- local max_retry=20
- local attempt=1
- while [ $attempt -lt $max_retry ] ; do
- local rnd1=$(( ( $RANDOM % 254 ) + 1 ))
- local rnd2=$(( ( $RANDOM % 254 ) + 1 ))
- local test_ip="169.254.${rnd1}.${rnd2}"
-
- # use arping to check if IP is in use
- arping -qD -c 5 -I $intf $test_ip && {
- # Claim this IP
- ip addr add ${test_ip}/$prefix dev $intf || {
- log_failure_msg "Problems setting default IPv4 addr: ${intf}: ${test_ip}/$prefix"
- return 1
- }
- arping -c 3 -Uq -I $intf -s $test_ip $test_ip
- log_console_msg "Using link-local IPv4 addr: ${intf}: ${test_ip}/$prefix"
- break
- }
- attempt=$(( $attempt + 1 ))
- done
-
- if [ $attempt -eq $max_retry ] ; then
- log_warning_msg "Unable to configure link-local IPv4 address within $max_retry attempts"
+ if [ -n "ONIE_NETWORK_INTERFACE" ] || [ -n "ONIE_NETWORK_ADDRESS" ] || [ -n "ONIE_NETWORK_MASK" ]; then
+ cmd_run ifconfig $ONIE_NETWORK_INTERFACE $ONIE_NETWORK_ADDRESS netmask $ONIE_NETWORK_MASK up
+ log_console_msg "$ONIE_NETWORK_INTERFACE: Using static IP config: ip=$ONIE_NETWORK_ADDRESS"
fi
- hostname $default_hn || {
- log_failure_msg "Problems setting default hostname: ${intf}: ${default_hn}\n"
- return 1
- }
+ if [ -z "$ONIE_NETWORK_GATEWAY" ]; then
+ cmd_run route add default gw $ONIE_NETWORK_GATEWAY
+ log_console_msg "Add default gateway $ONIE_NETWORK_INTERFACE"
+ fi
return 0
-
}
-# Check the operational state of the specified interface before trying
-# DHCP. From linux/Documentation/networking/operstates.txt, the
-# appropriate states are "up" and "unknown" for DHCP.
-check_link_up()
-{
- local intf=$1
- local operstate="/sys/class/net/${intf}/operstate"
-
- _log_info_msg "Info: ${intf}: Checking link... "
- local i=0
- [ -r $operstate ] && while [ $i -lt 100 ] ; do
- intf_operstate="$(cat $operstate)"
- if [ "$intf_operstate" = "up" -o "$intf_operstate" = "unknown" ] ; then
- _log_info_msg "up.\n"
- return 0
- fi
- sleep 0.1
- i=$(( $i + 1 ))
- done
-
- # no link
- _log_info_msg "down.\n"
- return 1
-}
-
-# Configure the management interface
-# Try these methods in order:
-# 1. static, from kernel command line parameters
-# 2. DHCPv6
-# 3. DHCPv4
-# 4. Fall back to well known IP address
-config_ethmgmt()
-{
- intf_list=$(net_intf)
- intf_counter=0
- return_value=0
-
- # Bring up all the interfaces for the subsequent methods.
- for intf in $intf_list ; do
- cmd_run ifconfig $intf up
- params="$intf $*"
- eval "result_${intf}=0"
- check_link_up $intf || {
- log_console_msg "${intf}: link down. Skipping configuration."
- eval "result_${intf}=1"
- continue
- }
- config_ethmgmt_static $params || \
- config_ethmgmt_dhcp6 $params || \
- config_ethmgmt_dhcp4 $params || \
- config_ethmgmt_fallback $intf_counter $params || \
- eval "result_${intf}=1"
- intf_counter=$(( $intf_counter + 1))
- done
- for intf in $intf_list ; do
- eval "curr_intf_result=\${result_${intf}}"
- if [ "x$curr_intf_result" != "x0" ] ; then
- log_console_msg "Failed to configure ${intf} interface"
- return_value=1
- fi
- done
- return $return_value
-}
-
-arch_networking="/lib/onie/networking-${onie_switch_asic}"
-platform_networking="/lib/onie/networking-platform"
-
-[ -r "$arch_networking" ] && . "$arch_networking"
-[ -r "$platform_networking" ] && . "$platform_networking"
-
-if [ "$1" = "start" ] ; then
+if [ "$1" = "start" ]; then
# Bring up the loopback interface
cmd_run ip link set dev lo up
@@ -204,10 +72,10 @@ if [ "$1" = "start" ] ; then
# Set MAC addr for all interfaces, but leave the interfaces down.
base_mac=$(onie-sysinfo -e)
- for intf in $intf_list ; do
- if [ "$onie_skip_ethmgmt_macs" = "no" ] ; then
+ for intf in $intf_list; do
+ if [ "$onie_skip_ethmgmt_macs" = "no" ]; then
mac="$(mac_add $base_mac $intf_counter)"
- if [ $? -eq 0 ] ; then
+ if [ $? -eq 0 ]; then
cmd_run ifconfig $intf down
cmd_run ifconfig $intf hw ether $mac down
else
@@ -217,8 +85,8 @@ if [ "$1" = "start" ] ; then
mac="$(cat /sys/class/net/${intf}/address)"
fi
log_info_msg "Using $intf MAC address: $mac"
- intf_counter=$(( $intf_counter + 1))
+ intf_counter=$(($intf_counter + 1))
done
-fi
-config_ethmgmt "$*"
+ config_ethmgmt
+fi
diff --git a/rootconf/default/bin/onie-netcfg-set b/rootconf/default/bin/onie-netcfg-set
index 847cdcbe..cf1f8749 100755
--- a/rootconf/default/bin/onie-netcfg-set
+++ b/rootconf/default/bin/onie-netcfg-set
@@ -1,14 +1,22 @@
#!/bin/sh
+bond="bond"
+address="address"
+gateway="gateway"
+slaves="slaves"
+
function usage() {
- echo ""
- echo "Usage: $(basename $0) interface address netmask [gateway]"
+ echo "Usage: $(basename $0) $bond|$address|$gateway [VARIABLE]..."
echo ""
cat <<EOF
Configuring the IPv4 Network of the ONIE Management Port.
- Example: onie-netcfg-set eth0 192.168.100.10 255.255.255.0 192.168.100.1
- Example: onie-netcfg-set eth1 192.168.200.10 255.255.255.0
+ Example: onie-netcfg-set address eth0 192.168.100.10 255.255.255.0
+ onie-netcfg-set gateway 192.168.100.1
+
+ Example: onie-netcfg-set bond slaves eth0,eth1
+ onie-netcfg-set address bond0 192.168.100.10 255.255.255.0
+ onie-netcfg-set gateway 192.168.100.1
EOF
}
@@ -36,39 +44,61 @@ function check_interface() {
fi
}
-function check_cmd_args() {
- interface=$1
- address=$2
- netmask=$3
- gateway=$4
+function check_bond_cmd_args() {
+ sub_option=$2
+ interface=$3
- # check network interface, interface is required
- if [ -z "$interface" ]; then
- echo "Network Interface not config."
+ if [ -z "$sub_option" ] || [ "$sub_option" != "$slaves" ] || [ -z "$interface" ] || [ -n "$4" ]; then
+ echo "Invalid options args, Usage: onie-netcfg-set $bond $slaves interface1,interface2"
return 1
fi
- check_interface $interface
- ret=$?
- if [ "$ret" == 1 ]; then
- exit 1
+ interface_array=$(echo $interface | tr ',' ' ')
+ interface_uniq_num=$(echo $interface_array | sed 's/ /\n/g' | sort | uniq | wc -l)
+ interface_num=$(echo $interface_array | sed 's/ /\n/g' | sort | wc -l)
+
+ if [ "$interface_num" -lt 2 ] || [ "$interface_uniq_num" != "$interface_num" ]; then
+ echo "The bond slaves needs to configure multiple uniq interfaces"
+ return 1
+ fi
+
+ for eth in $interface_array; do
+ check_interface $eth
+ ret=$?
+ if [ "$ret" == 1 ]; then
+ return 1
+ fi
+ done
+
+ if [ -r /mnt/onie-boot/grub/grubenv ]; then
+ sed -i "/ONIE_NETWORK_BOND_SLAVES/d" /mnt/onie-boot/grub/grubenv
+ else
+ touch /mnt/onie-boot/grub/grubenv
fi
- # check ipv4 network address, address is required
- if [ -z "$address" ]; then
- echo "IPv4 Network Address not config."
+ echo "ONIE_NETWORK_BOND_SLAVES=$interface" >>/mnt/onie-boot/grub/grubenv
+ return 0
+}
+
+function check_address_cmd_args() {
+ interface=$2
+ ip_address=$3
+ netmask=$4
+
+ if [ -z "$interface" ] || [ -z "$ip_address" ] || [ -z "$netmask" ] || [ -n "$5" ]; then
+ echo "Invalid options args, Usage: onie-netcfg-set $1 \$interface \$address \$netmask"
return 1
fi
- check_ipv4_foramt $address
+ check_interface $interface
ret=$?
if [ "$ret" == 1 ]; then
return 1
fi
- # check ipv4 network mask, mask is required
- if [ -z "$netmask" ]; then
- echo "IPv4 Network Mask not config."
+ check_ipv4_foramt $ip_address
+ ret=$?
+ if [ "$ret" == 1 ]; then
return 1
fi
@@ -78,9 +108,26 @@ function check_cmd_args() {
return 1
fi
- # check ipv4 network gateway, gateway is optioned
- if [ -z "$gateway" ]; then
- return 0
+ if [ -r /mnt/onie-boot/grub/grubenv ]; then
+ sed -i "/ONIE_NETWORK_INTERFACE/d" /mnt/onie-boot/grub/grubenv
+ sed -i "/ONIE_NETWORK_ADDRESS/d" /mnt/onie-boot/grub/grubenv
+ sed -i "/ONIE_NETWORK_MASK/d" /mnt/onie-boot/grub/grubenv
+ else
+ touch /mnt/onie-boot/grub/grubenv
+ fi
+
+ echo "ONIE_NETWORK_INTERFACE=$interface" >>/mnt/onie-boot/grub/grubenv
+ echo "ONIE_NETWORK_ADDRESS=$ip_address" >>/mnt/onie-boot/grub/grubenv
+ echo "ONIE_NETWORK_MASK=$netmask" >>/mnt/onie-boot/grub/grubenv
+
+}
+
+function check_gateway_cmd_args() {
+ gateway=$2
+
+ if [ -z "$gateway" ] || [ -n "$3" ]; then
+ echo "Invalid options args, Usage: onie-netcfg-set $1 \$gateway"
+ return 1
fi
check_ipv4_foramt $gateway
@@ -89,44 +136,35 @@ function check_cmd_args() {
return 1
fi
- return 0
+ if [ -r /mnt/onie-boot/grub/grubenv ]; then
+ sed -i "/ONIE_NETWORK_GATEWAY/d" /mnt/onie-boot/grub/grubenv
+ else
+ touch /mnt/onie-boot/grub/grubenv
+ fi
+
+ echo "ONIE_NETWORK_GATEWAY=$gateway" >>/mnt/onie-boot/grub/grubenv
}
-ret=0
-interface=$1
-address=$2
-netmask=$3
-gateway=$4
+option=$1
-if [ -z "$interface" ] || [ -z "$address" ] || [ -z "$netmask" ]; then
- usage
- exit 1
-fi
-
-check_cmd_args $interface $address $netmask $gateway
-ret=$?
-if [ "$ret" == 1 ]; then
- exit 1
-fi
-
-# save config to file
-if [ -r /mnt/onie-boot/grub/grubenv ]; then
- # Plan A: If the current network interface has been configured with an IP, delete it
- # sed -i "/::$interface$/d" /mnt/onie-boot/grub/grubenv
-
- # Plan B: Delete all config info
- sed -i "/ONIE_NETWORK_CONFIG/d" /mnt/onie-boot/grub/grubenv
+if [ "$option" = "$bond" ]; then
+ check_bond_cmd_args $1 $2 $3 $4
+ ret=$?
+ if [ "$ret" == 1 ]; then
+ exit 1
+ fi
+elif [ "$option" = "$address" ]; then
+ check_address_cmd_args $1 $2 $3 $4 $5
+ ret=$?
+ if [ "$ret" == 1 ]; then
+ exit 1
+ fi
+elif [ "$option" = "$gateway" ]; then
+ check_gateway_cmd_args $1 $2 $3
+ ret=$?
+ if [ "$ret" == 1 ]; then
+ exit 1
+ fi
else
- touch /mnt/onie-boot/grub/grubenv
-fi
-
-curr_time=$(date)
-echo "# ONIE_NETWORK_CONFIG config date: $curr_time, content: $address::$gateway:$netmask::$interface" >>/mnt/onie-boot/grub/grubenv
-echo "ONIE_NETWORK_CONFIG=ip=$address::$gateway:$netmask::$interface" >>/mnt/onie-boot/grub/grubenv
-
-#ifconfig $interface up
-#ifconfig $interface $address netmask $netmask
-#route add default gw $gateway
-
-echo "ONIE Network config Success !!!"
-echo "Please reboot to take effect."
+ usage
+fi \ No newline at end of file