From 8be0edb971eab9a5241a1912726ca91812f4a75f Mon Sep 17 00:00:00 2001 From: Kyle MacLeod Date: Sun, 16 Apr 2023 22:52:21 -0400 Subject: [PATCH] Support nexthop_gateway in IPv6 Re-add support for nexthop_gateway in IPv6 configurations in Debian. Ensure the translated nexthop_gateway boot parameter is applied to IPv6 network configurations. These changes are applied to both the pre-ostree-pull network configuration (via 'ip' command), and the /etc/network/interfaces.d ifupdown interface configuration. Test Plan PASS: - Test IPv6 install using only nexthop_gateway value - With and without bootstrap_vlan - Ensure that the default route is created, via the given nexthop_gateway - Validate successful ostree repo pull - Ensure that the default route is created via the - /etc/network/interfaces.d upon reboot into the ostree repo - Validate that communications are established to subcloud, ready for ansible bootstrap - Test IPv6 install using no nexthop_gateway value - With and without bootstrap_vlan - Verify that default route is created, with no gateway - Test IPv4 install using only nexthop_gateway value - With and without bootstrap_vlan - Ensure that the default route is created, via the given nexthop_gateway - Full install plus bootstrap, as above - Tested in libvirt - Test IPv4 install using no nexthop_gateway value - With and without bootstrap_vlan - Verify that default route is created, with no gateway - Full install plus bootstrap, as above - Tested in libvirt Closes-Bug: 2017007 Signed-off-by: Kyle MacLeod Change-Id: Iee71f753983fa77ad396a6a90e2f6cec189cbaa8 Signed-off-by: Kyle MacLeod --- kickstart/files/miniboot.cfg | 217 +++++++++++++++++++---------------- 1 file changed, 115 insertions(+), 102 deletions(-) diff --git a/kickstart/files/miniboot.cfg b/kickstart/files/miniboot.cfg index aa9a4e3b..70721b8c 100644 --- a/kickstart/files/miniboot.cfg +++ b/kickstart/files/miniboot.cfg @@ -673,26 +673,30 @@ function parse_miniboot_network_params() { BOOTPARAM_MGMT_ADDRESS_FAMILY= BOOTPARAM_IP_ADDR= - BOOTPARAM_VLAN=0 + BOOTPARAM_VLAN= BOOTPARAM_GW= BOOTPARAM_PREFIX_LEN= BOOTPARAM_IFNAME= BOOTPARAM_IP_VER= - BOOTPARAM_ROUTE_OPTIONS= BOOTPARAM_METRIC= BOOTPARAM_DNS= - # Pull out the ip= line from /proc/cmdline: - local ipstring + # Parse values from /proc/cmdline + local ipstring= + local vlan= for arg in \$(cat /proc/cmdline); do - case "\$arg" in + case "\${arg}" in ip=*) ipstring=\${arg:3} ilog "Using ip=\$ipstring" - break + ;; + vlan=*) + vlan=\${arg:5} + ilog "Using vlan=\${vlan}" ;; esac done + ilog "Parsing boot ipstring=\$ipstring" # Now we have a string like: @@ -704,7 +708,7 @@ function parse_miniboot_network_params() # [2620:10a:a001:d41::212],,,64,subcloud3,ens1f0.401,none (for ipv6) BOOTPARAM_IP_ADDR=\$(echo \$ipstring | awk -F',' '{print \$1}' | tr -d '\[\]') - BOOTPARAM_GW=\$(echo \$ipstring | awk -F',' '{print \$3}') + BOOTPARAM_GW=\$(echo \$ipstring | awk -F',' '{print \$3}' | tr -d '\[\]') BOOTPARAM_PREFIX_LEN=\$(echo \$ipstring | awk -F',' '{print \$4}') hostname=\$(echo \$ipstring | awk -F',' '{print \$5}') BOOTPARAM_IFNAME=\$(echo \$ipstring | awk -F',' '{print \$6}') @@ -720,22 +724,9 @@ function parse_miniboot_network_params() ;; *) BOOTPARAM_MGMT_ADDRESS_FAMILY="inet" - BOOTPARAM_ROUTE_OPTIONS="via \$BOOTPARAM_GW" ;; esac - # Parse the vlan= line from /proc/cmdline (if it exists): - local vlan= - for arg in \$(cat /proc/cmdline); do - case "\${arg}" in - vlan=*) - vlan=\${arg:5} - ilog "Parsing vlan=\${vlan}" - break - ;; - esac - done - if [ -n "\${vlan}" ]; then # Parameter format: "bootstrap_interface.bootstrap_vlan:bootstrap_interface" dlog "Parsing vlan from \${vlan}" @@ -746,11 +737,14 @@ function parse_miniboot_network_params() fi logmsg="Using IP values: ip:\$BOOTPARAM_IP_ADDR, family: \$BOOTPARAM_MGMT_ADDRESS_FAMILY" - if [ "\$BOOTPARAM_VLAN" -ne 0 ]; then + if [ -n "\$BOOTPARAM_VLAN" ]; then logmsg="\$logmsg vlan: \$BOOTPARAM_VLAN, " fi - logmsg="\$logmsg prefix:\$BOOTPARAM_PREFIX_LEN, gw:\$BOOTPARAM_GW, ifname: \$BOOTPARAM_IFNAME, " - logmsg="\$logmsg route options: \$BOOTPARAM_ROUTE_OPTIONS, metric: \$BOOTPARAM_METRIC, dns: \$BOOTPARAM_DNS" + logmsg="\$logmsg prefix:\$BOOTPARAM_PREFIX_LEN, ifname: \$BOOTPARAM_IFNAME, " + if [ -n "\${BOOTPARAM_GW}" ]; then + logmsg="\$logmsg gw:\$BOOTPARAM_GW, " + fi + logmsg="\$logmsg metric: \$BOOTPARAM_METRIC, dns: \$BOOTPARAM_DNS" ilog "\$logmsg" export BOOTPARAM_MGMT_ADDRESS_FAMILY @@ -760,7 +754,6 @@ function parse_miniboot_network_params() export BOOTPARAM_PREFIX_LEN export BOOTPARAM_IFNAME export BOOTPARAM_IP_VER - export BOOTPARAM_ROUTE_OPTIONS export BOOTPARAM_METRIC export BOOTPARAM_DNS } @@ -1543,8 +1536,8 @@ mgmt_dev=${BOOTPARAM_IFNAME} mgmt_vlan=${BOOTPARAM_VLAN} mgmt_address_family=${BOOTPARAM_MGMT_ADDRESS_FAMILY} -if [ $mgmt_vlan -eq 0 ] ; then - +if [ -z "${mgmt_vlan}" ] ; then + # NO VLAN if [ "$mgmt_address_family" = "inet" ]; then ilog "ip ${BOOTPARAM_IP_VER} address add ${BOOTPARAM_IP_ADDR}/${BOOTPARAM_PREFIX_LEN} dev ${mgmt_dev}" ip ${BOOTPARAM_IP_VER} address add ${BOOTPARAM_IP_ADDR}/${BOOTPARAM_PREFIX_LEN} dev ${mgmt_dev} @@ -1554,8 +1547,16 @@ if [ $mgmt_vlan -eq 0 ] ; then fi ilog "ip ${BOOTPARAM_IP_VER} link set dev ${mgmt_dev} up" ip ${BOOTPARAM_IP_VER} link set dev ${mgmt_dev} up - ilog "ip ${BOOTPARAM_IP_VER} route add default ${BOOTPARAM_ROUTE_OPTIONS} dev ${mgmt_dev} ${BOOTPARAM_METRIC}" - ip ${BOOTPARAM_IP_VER} route add default ${BOOTPARAM_ROUTE_OPTIONS} dev ${mgmt_dev} ${BOOTPARAM_METRIC} + + if [ -z "${BOOTPARAM_GW}" ]; then + # No gateway + ilog "ip ${BOOTPARAM_IP_VER} route add default dev ${mgmt_dev} ${BOOTPARAM_METRIC}" + ip ${BOOTPARAM_IP_VER} route add default dev ${mgmt_dev} ${BOOTPARAM_METRIC} + else + ilog "Setting up default route:" + ilog "ip ${BOOTPARAM_IP_VER} route add default via ${BOOTPARAM_GW} dev ${mgmt_dev} ${BOOTPARAM_METRIC}" + ip ${BOOTPARAM_IP_VER} route add default via ${BOOTPARAM_GW} dev ${mgmt_dev} ${BOOTPARAM_METRIC} + fi wait_for_interface ${mgmt_dev} 60 ilog "ip addr:" ip addr show @@ -1563,6 +1564,7 @@ if [ $mgmt_vlan -eq 0 ] ; then ip ${BOOTPARAM_IP_VER} route show else + # VLAN CONFIG mgmt_iface=vlan${mgmt_vlan} ilog "mgmt_dev=${mgmt_dev}" ilog "mgmt_iface=vlan${mgmt_vlan}" @@ -1580,19 +1582,30 @@ else fi ilog "ip ${BOOTPARAM_IP_VER} link set up dev ${mgmt_dev}" ip ${BOOTPARAM_IP_VER} link set up dev ${mgmt_dev} + # TODO(kmacleod) change to wait_for_interface 60: sleep 15 ilog "ip ${BOOTPARAM_IP_VER} link set up dev ${mgmt_iface}" ip ${BOOTPARAM_IP_VER} link set up dev ${mgmt_iface} + # TODO(kmacleod) change to wait_for_interface 60: ilog "Wait 10s to settle interface..." sleep 10 - ilog "ip ${BOOTPARAM_IP_VER} route add default ${BOOTPARAM_ROUTE_OPTIONS} dev ${mgmt_iface} ${BOOTPARAM_METRIC}" - ip ${BOOTPARAM_IP_VER} route add default ${BOOTPARAM_ROUTE_OPTIONS} dev ${mgmt_iface} ${BOOTPARAM_METRIC} + if [ -z "${BOOTPARAM_GW}" ]; then + # No gateway + ilog "ip ${BOOTPARAM_IP_VER} route add default dev ${mgmt_iface} ${BOOTPARAM_METRIC}" + ip ${BOOTPARAM_IP_VER} route add default dev ${mgmt_iface} ${BOOTPARAM_METRIC} + else + ilog "Setting up default route:" + ilog "ip ${BOOTPARAM_IP_VER} route add default via ${BOOTPARAM_GW} dev ${mgmt_iface} ${BOOTPARAM_METRIC}" + ip ${BOOTPARAM_IP_VER} route add default via ${BOOTPARAM_GW} dev ${mgmt_iface} ${BOOTPARAM_METRIC} + fi + ilog "ip ${BOOTPARAM_IP_VER} addr:" ip ${BOOTPARAM_IP_VER} addr show ilog "ip ${BOOTPARAM_IP_VER} route:" ip ${BOOTPARAM_IP_VER} route show fi + # get the nameserver local dns="none" for e in \${dns}; do @@ -2646,84 +2659,82 @@ fi ilog "Setup network scripts" -if [ $mgmt_vlan -eq 0 ] ; then +function create_network_interface_file() +{ + local ifname=${1} + local address_family=${2} + local vlan=${3:-} - # Persist the boot device to the platform configuration. This will get - # overwritten later if the management_interface is on a bonded interface. - update_platform_conf "management_interface=$mgmt_dev" + local ipversion=ipv4 + local ip_cmd_flag="-4" + if [ "${address_family}" == "inet6" ]; then + local ipversion=ipv6 + local ip_cmd_flag="-6" + fi + local ifname_vlan="vlan${vlan}" - # Build networking scripts - cat << EOF > ${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-lo -auto lo -iface lo inet loopback -EOF + local logstr="Creating ${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-${ifname}, ${ipversion}" + [ -n "${vlan}" ] && logstr="${logstr}, vlan interface: ${ifname_vlan}" + [ -n "${BOOTPARAM_GW}" ] && logstr="${logstr}, gw: ${BOOTPARAM_GW}" + ilog "${logstr}" - if [ $mgmt_dev != "lo" ]; then - ilog "Creating ${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-$mgmt_dev" - if [ "${mgmt_address_family}" == "inet" ]; then - cat << EOF > ${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-$mgmt_dev -auto $mgmt_dev -iface $mgmt_dev inet static - address $BOOTPARAM_IP_ADDR/$BOOTPARAM_PREFIX_LEN - gateway $BOOTPARAM_GW - mtu 1500 -EOF - else # inet6 - cat << EOF > ${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-$mgmt_dev -auto $mgmt_dev -iface $mgmt_dev inet6 static - address $BOOTPARAM_IP_ADDR/$BOOTPARAM_PREFIX_LEN - mtu 1500 - post-up echo 0 > /proc/sys/net/ipv6/conf/lo/autoconf; echo 0 > /proc/sys/net/ipv6/conf/lo/accept_ra; echo 0 > /proc/sys/net/ipv6/conf/lo/accept_redirects -EOF + local output + if [ -z "${vlan}" ]; then + # Persist the boot device to the platform configuration + # overwritten later if the management_interface is on a bonded interface. + update_platform_conf "management_interface=${ifname}" + + # NO VLAN + output="auto ${ifname}\n" + output="${output}iface ${ifname} ${address_family} static\n" + output="${output} address ${BOOTPARAM_IP_ADDR}/$BOOTPARAM_PREFIX_LEN\n" + if [ -n "${BOOTPARAM_GW}" ]; then + output="${output} gateway $BOOTPARAM_GW\n" fi + output="${output} mtu 1500\n" + output="${output} post-up echo 0 > /proc/sys/net/${ipversion}/conf/lo/autoconf\n" + output="${output} post-up echo 0 > /proc/sys/net/${ipversion}/conf/lo/accept_ra\n" + output="${output} post-up echo 0 > /proc/sys/net/${ipversion}/conf/lo/accept_redirects\n" + echo -e "${output}" > "${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-${ifname}" + else + # CONFIGURE FOR VLAN + # Persist the boot device to the platform configuration. This will get + # overwritten later if the management_interface is on a bonded interface. + update_platform_conf "management_interface=${ifname_vlan}" + + # 1. Configure device interface: + output="auto ${ifname}\n" + output="${output}iface ${ifname} ${address_family} manual\n" + output="${output} post-up echo 0 > /proc/sys/net/${ipversion}/conf/${ifname}/autoconf\n" + output="${output} post-up echo 0 > /proc/sys/net/${ipversion}/conf/${ifname}/accept_ra\n" + output="${output} post-up echo 0 > /proc/sys/net/${ipversion}/conf/${ifname}/accept_redirects\n" + echo -e "${output}" > "${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-${ifname}" + + # 2. Configure VLAN interface: + output="auto ${ifname_vlan}\n" + output="${output}iface ${ifname_vlan} ${address_family} static\n" + output="${output} vlan-raw-device ${ifname}\n" + output="${output} address ${BOOTPARAM_IP_ADDR}/${BOOTPARAM_PREFIX_LEN}\n" + if [ -n "${BOOTPARAM_GW}" ]; then + output="${output} gateway ${BOOTPARAM_GW}\n" + fi + output="${output} mtu 1500\n" + output="${output} post-up echo 0 > /proc/sys/net/${ipversion}/conf/${ifname_vlan}/autoconf\n" + output="${output} post-up echo 0 > /proc/sys/net/${ipversion}/conf/${ifname_vlan}/accept_ra\n" + output="${output} post-up echo 0 > /proc/sys/net/${ipversion}/conf/${ifname_vlan}/accept_redirects\n" + echo -e "${output}" > "${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-${ifname_vlan}" fi +} -else # vlan - ilog "Configuring vlan: mgmt_iface=vlan${mgmt_vlan}" +# Build networking scripts - # Persist the boot device to the platform configuration. This will get - # overwritten later if the management_interface is on a bonded interface. - update_platform_conf "management_interface=vlan${mgmt_vlan}" +# Loopback file +lo_file="${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-lo" +echo "auto lo" > "${lo_file}" +echo "iface lo ${mgmt_address_family} loopback" >> "${lo_file}" - # Build networking scripts - cat << EOF > ${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-lo -auto lo -iface lo ${mgmt_address_family} loopback -EOF - - if [ "${mgmt_address_family}" == "inet" ]; then - cat << EOF > ${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-$mgmt_dev -auto ${mgmt_dev} -iface ${mgmt_dev} inet manual - post-up echo 0 > /proc/sys/net/ipv4/conf/${mgmt_dev}/autoconf; echo 0 > /proc/sys/net/ipv4/conf/${mgmt_dev}/accept_ra; echo 0 > /proc/sys/net/ipv4/conf/${mgmt_dev}/accept_redirects -EOF - - cat << EOF > ${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-vlan${mgmt_vlan} -auto vlan${mgmt_vlan} -iface vlan${mgmt_vlan} inet static - vlan-raw-device ${mgmt_dev} - address ${BOOTPARAM_IP_ADDR}/${BOOTPARAM_PREFIX_LEN} - gateway ${BOOTPARAM_GW} - mtu 1500 - post-up echo 0 > /proc/sys/net/ipv4/conf/vlan${mgmt_vlan}/autoconf; echo 0 > /proc/sys/net/ipv4/conf/vlan${mgmt_vlan}/accept_ra; echo 0 > /proc/sys/net/ipv4/conf/vlan${mgmt_vlan}/accept_redirects -EOF - else # inet6 - cat << EOF > ${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-${mgmt_dev} -auto ${mgmt_dev} -iface ${mgmt_dev} inet6 manual - post-up echo 0 > /proc/sys/net/ipv6/conf/${mgmt_dev}/autoconf; echo 0 > /proc/sys/net/ipv6/conf/${mgmt_dev}/accept_ra; echo 0 > /proc/sys/net/ipv6/conf/${mgmt_dev}/accept_redirects -EOF - - cat << EOF > ${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-vlan${mgmt_vlan} -auto vlan${mgmt_vlan} -iface vlan${mgmt_vlan} inet6 static - vlan-raw-device ${mgmt_dev} - address ${BOOTPARAM_IP_ADDR}/${BOOTPARAM_PREFIX_LEN} - mtu 1500 - post-up echo 0 > /proc/sys/net/ipv6/conf/vlan${mgmt_vlan}/autoconf; echo 0 > /proc/sys/net/ipv6/conf/vlan${mgmt_vlan}/accept_ra; echo 0 > /proc/sys/net/ipv6/conf/vlan${mgmt_vlan}/accept_redirects -EOF - fi +if [ "${mgmt_dev}" != "lo" ]; then + create_network_interface_file "${mgmt_dev}" "${mgmt_address_family}" "${mgmt_vlan}" fi ilog "Contents of ${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-lo:" @@ -2733,8 +2744,8 @@ ilog "Contents of ${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-${mgmt_dev}:" ilog "$(cat "${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-${mgmt_dev}")" if [ -f "${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-vlan${mgmt_vlan}" ]; then - ilog "Contents of ${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-vlan${mgmt_vlan}:" - ilog "$(cat "${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-vlan${mgmt_vlan}")" + ilog "Contents of ${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-vlan${mgmt_vlan}:" + ilog "$(cat "${IMAGE_ROOTFS}/etc/network/interfaces.d/ifcfg-vlan${mgmt_vlan}")" fi true @@ -3065,3 +3076,5 @@ fi true %end + +# vim: filetype=sh