Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 31 May 2011 15:02:30 +0000 (UTC)
From:      "Bjoern A. Zeeb" <bz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r222528 - in head/usr.sbin/pc-sysinstall: backend backend-query
Message-ID:  <201105311502.p4VF2Uew028482@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bz
Date: Tue May 31 15:02:30 2011
New Revision: 222528
URL: http://svn.freebsd.org/changeset/base/222528

Log:
  Start teaching pc-sysinstall about IPv6.
  
  Add some additional empty string checks for IPv4 and try to configure
  a netmask along with the address rather than doing things twice.
  
  Contrary to AUTO-DHCP, IPv6-SLAAC will accept static configuration
  as well, which we will use at least for resolv.conf currently and
  if we were given a static address configure that as an alias as well.
  
  The pc-sysinstaller changes going along were committed to PC-BSD as r10773.
  
  Reviewed by:	kmoore
  Sponsored by:	The FreeBSD Foundation
  Sponsored by:	iXsystems
  MFC after:	20 days

Modified:
  head/usr.sbin/pc-sysinstall/backend-query/enable-net.sh
  head/usr.sbin/pc-sysinstall/backend-query/test-netup.sh
  head/usr.sbin/pc-sysinstall/backend/functions-networking.sh

Modified: head/usr.sbin/pc-sysinstall/backend-query/enable-net.sh
==============================================================================
--- head/usr.sbin/pc-sysinstall/backend-query/enable-net.sh	Tue May 31 14:40:21 2011	(r222527)
+++ head/usr.sbin/pc-sysinstall/backend-query/enable-net.sh	Tue May 31 15:02:30 2011	(r222528)
@@ -1,6 +1,11 @@
 #!/bin/sh
 #-
 # Copyright (c) 2010 iXsystems, Inc.  All rights reserved.
+# Copyright (c) 2011 The FreeBSD Foundation
+# All rights reserved.
+#
+# Portions of this software were developed by Bjoern Zeeb
+# under sponsorship from the FreeBSD Foundation.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -40,23 +45,67 @@ NETMASK="$3"
 DNS="$4"
 GATEWAY="$5"
 MIRRORFETCH="$6"
+IPV6="$7"
+IPV6GATE="$8"
+IPV6DNS="$9"
 
 if [ -z "${NIC}" ]
 then
-  echo "ERROR: Usage enable-net <nic> <ip> <netmask> <dns> <gateway>"
+  echo "ERROR: Usage enable-net <nic> <ip> <netmask> <dns> <gateway> <ipv6> " \
+	"<ipv6gateway> <ipv6dns>"
   exit 150
 fi
 
 if [ "$NIC" = "AUTO-DHCP" ]
 then
   enable_auto_dhcp
+elif [ "$NIC" = "IPv6-SLAAC" ]
+then
+  enable_auto_slaac
+  # In addition, if static values were defined, add them as well.
+  # We might not get DNS information from RAs, for example.
+  if [ -n "${IPV6}" ]; then
+    VAL=""
+    get_first_wired_nic
+    if [ -n "${VAL}" ]; then
+      ifconfig ${VAL} inet6 ${IPV6} alias
+    fi
+  fi
+  # Append only here.
+  if [ -n "${IPV6DNS}" ]; then
+    echo "nameserver ${IPV6DNS}" >>/etc/resolv.conf
+  fi
+  # Do not 
+  if [ -n "${IPV6GATE}" ]; then
+    # Check if we have a default route already to not overwrite.
+    if ! route -n get -inet6 default > /dev/null 2>&1 ; then
+      route add -inet6 default ${IPV6GATE}
+    fi
+  fi
 else
   echo "Enabling NIC: $NIC"
-  ifconfig ${NIC} ${IP} ${NETMASK}
-
-  echo "nameserver ${DNS}" >/etc/resolv.conf
-
-  route add default ${GATE}
+  if [ -n "${IP}" ]; then
+    ifconfig ${NIC} inet ${IP} ${NETMASK}
+  fi
+  if [ -n "${IPV6}" ]; then
+    ifconfig ${NIC} inet6 ${IPV6} alias
+  fi
+
+  # Keep default from IPv4-only support times and clear the resolv.conf file.
+  : > /etc/resolv.conf
+  if [ -n "${DNS}" ]; then
+    echo "nameserver ${DNS}" >>/etc/resolv.conf
+  fi
+  if [ -n "${IPV6DNS}" ]; then
+    echo "nameserver ${IPV6DNS}" >>/etc/resolv.conf
+  fi
+
+  if [ -n "${GATE}" ]; then
+    route add -inet default ${GATE}
+  fi
+  if [ -n "${IPV6GATE}" ]; then
+    route add -inet6 default ${IPV6GATE}
+  fi
 fi
 
 case ${MIRRORFETCH} in

Modified: head/usr.sbin/pc-sysinstall/backend-query/test-netup.sh
==============================================================================
--- head/usr.sbin/pc-sysinstall/backend-query/test-netup.sh	Tue May 31 14:40:21 2011	(r222527)
+++ head/usr.sbin/pc-sysinstall/backend-query/test-netup.sh	Tue May 31 15:02:30 2011	(r222528)
@@ -1,6 +1,11 @@
 #!/bin/sh
 #-
 # Copyright (c) 2010 iXsystems, Inc.  All rights reserved.
+# Copyright (c) 2011 The FreeBSD Foundation
+# All rights reserved.
+#
+# Portions of this software were developed by Bjoern Zeeb
+# under sponsorship from the FreeBSD Foundation.#
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -26,8 +31,8 @@
 # $FreeBSD$
 
 
-# Script which tests "fetch" when using a network connection, and saves
-# if we are using direct connect, or need FTP passive mode
+# Script which tries to ping "home" to see if Internet connectivity is
+# available.
 #############################################################################
 
 rm ${TMPDIR}/.testftp >/dev/null 2>/dev/null
@@ -39,12 +44,26 @@ then
   exit 0
 fi
 
+ping6 -c 2 www.pcbsd.org >/dev/null 2>/dev/null
+if [ "$?" = "0" ]
+then
+  echo "ftp: Up"
+  exit 0
+fi
+
 ping -c 2 www.freebsd.org >/dev/null 2>/dev/null
 if [ "$?" = "0" ]
 then
   echo "ftp: Up"
   exit 0
 fi
-   
+
+ping6 -c 2 www.freebsd.org >/dev/null 2>/dev/null
+if [ "$?" = "0" ]
+then
+  echo "ftp: Up"
+  exit 0
+fi
+
 echo "ftp: Down"
 exit 1

Modified: head/usr.sbin/pc-sysinstall/backend/functions-networking.sh
==============================================================================
--- head/usr.sbin/pc-sysinstall/backend/functions-networking.sh	Tue May 31 14:40:21 2011	(r222527)
+++ head/usr.sbin/pc-sysinstall/backend/functions-networking.sh	Tue May 31 15:02:30 2011	(r222528)
@@ -1,6 +1,11 @@
 #!/bin/sh
 #-
 # Copyright (c) 2010 iXsystems, Inc.  All rights reserved.
+# Copyright (c) 2011 The FreeBSD Foundation
+# All rights reserved.
+#
+# Portions of this software were developed by Bjoern Zeeb
+# under sponsorship from the FreeBSD Foundation.
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -119,6 +124,61 @@ save_auto_dhcp()
   enable_dhcp_all
 };
 
+# Function which simply enables iPv6 SLAAC on all detected nics
+enable_slaac_all()
+{
+  rm ${TMPDIR}/.niclist >/dev/null 2>/dev/null
+  # start by getting a list of nics on this system
+  ${QUERYDIR}/detect-nics.sh > ${TMPDIR}/.niclist
+  if [ -e "${TMPDIR}/.niclist" ]
+  then
+    echo "# Auto-Enabled NICs from pc-sysinstall" >>${FSMNT}/etc/rc.conf
+    WLANCOUNT="0"
+    while read line
+    do
+      NIC="`echo $line | cut -d ':' -f 1`"
+      DESC="`echo $line | cut -d ':' -f 2`"
+      echo_log "Setting $NIC to acceptign RAs on the system."
+      check_is_wifi ${NIC}
+      if [ $? -eq 0 ]
+      then
+        # We have a wifi device, setup a wlan* entry for it
+        # Given we cannot have DHCP and SLAAC the same time currently
+	# it's save to just duplicate.
+        WLAN="wlan${WLANCOUNT}"
+        echo "wlans_${NIC}=\"${WLAN}\"" >>${FSMNT}/etc/rc.conf
+	#echo "ifconfig_${NIC}=\"up\"" >>${FSMNT}/etc/rc.conf
+        echo "ifconfig_${WLAN}=\"inet6 accept_rtadv\"" >>${FSMNT}/etc/rc.conf
+        CNIC="${WLAN}"
+        WLANCOUNT=$((WLANCOUNT+1))
+      else
+	#echo "ifconfig_${NIC}=\"up\"" >>${FSMNT}/etc/rc.conf
+        echo "ifconfig_${NIC}_ipv6=\"inet6 accept_rtadv\"" >>${FSMNT}/etc/rc.conf
+        CNIC="${NIC}"
+      fi
+ 
+    done < ${TMPDIR}/.niclist 
+  fi
+
+  # Given we cannot yet rely on RAs to provide DNS information as much
+  # as we can in the DHCP world, we should append a given nameserver.
+  : > ${FSMNT}/etc/resolv.conf
+  get_value_from_cfg netSaveIPv6NameServer
+  NAMESERVER="${VAL}"
+  if [ -n "${NAMESERVER}" ]
+  then
+    echo "nameserver ${NAMESERVER}" >>${FSMNT}/etc/resolv.conf
+  fi
+
+};
+
+
+# Function which detects available nics, and enables IPv6 SLAAC on them
+save_auto_slaac()
+{
+  enable_slaac_all
+};
+
 
 # Function which saves a manual nic setup to the installed system
 save_manual_nic()
@@ -137,21 +197,41 @@ save_manual_nic()
   fi
 
   # If we get here, we have a manual setup, lets do so now
+  IFARGS=""
+  IF6ARGS=""
 
   # Set the manual IP
-  IFARGS="inet ${NETIP}"
-
-  # Check if we have a netmask to set
-  get_value_from_cfg netSaveMask
-  NETMASK="${VAL}"
-  if [ -n "${NETMASK}" ]
+  if [ -n "${NETIP}" ]
   then
-    IFARGS="${IFARGS} netmask ${NETMASK}"
+    IFARGS="inet ${NETIP}"
+
+    # Check if we have a netmask to set
+    get_value_from_cfg netSaveMask
+    NETMASK="${VAL}"
+    if [ -n "${NETMASK}" ]
+    then
+      IFARGS="${IFARGS} netmask ${NETMASK}"
+    fi
   fi
 
+  get_value_from_cfg netSaveIPv6
+  NETIP6="${VAL}"
+  if [ -n "${NETIP6}" ]
+  then
+    # Make sure we have one inet6 prefix.
+    IF6ARGS=`echo "${NETIP6}" | awk '{ if ("^inet6 ") { print $0; } else
+      { printf "inet6 %s", $0; } }'`
+  fi
 
   echo "# Auto-Enabled NICs from pc-sysinstall" >>${FSMNT}/etc/rc.conf
-  echo "ifconfig_${NIC}=\"${IFARGS}\"" >>${FSMNT}/etc/rc.conf
+  if [ -n "${IFARGS}" ]
+  then
+    echo "ifconfig_${NIC}=\"${IFARGS}\"" >>${FSMNT}/etc/rc.conf
+  fi
+  if [ -n "${IF6ARGS}" ]
+  then
+    echo "ifconfig_${NIC}_ipv6=\"${IF6ARGS}\"" >>${FSMNT}/etc/rc.conf
+  fi
 
   # Check if we have a default router to set
   get_value_from_cfg netSaveDefaultRouter
@@ -160,15 +240,28 @@ save_manual_nic()
   then
     echo "defaultrouter=\"${NETROUTE}\"" >>${FSMNT}/etc/rc.conf
   fi
+  get_value_from_cfg netSaveIPv6DefaultRouter
+  NETROUTE="${VAL}"
+  if [ -n "${NETROUTE}" ]
+  then
+    echo "ipv6_defaultrouter=\"${NETROUTE}\"" >>${FSMNT}/etc/rc.conf
+  fi
 
   # Check if we have a nameserver to enable
+  : > ${FSMNT}/etc/resolv.conf
   get_value_from_cfg netSaveNameServer
   NAMESERVER="${VAL}"
   if [ -n "${NAMESERVER}" ]
   then
-    echo "nameserver ${NAMESERVER}" >${FSMNT}/etc/resolv.conf
+    echo "nameserver ${NAMESERVER}" >>${FSMNT}/etc/resolv.conf
   fi
- 
+  get_value_from_cfg netSaveIPv6NameServer
+  NAMESERVER="${VAL}"
+  if [ -n "${NAMESERVER}" ]
+  then
+    echo "nameserver ${NAMESERVER}" >>${FSMNT}/etc/resolv.conf
+  fi
+
 };
 
 # Function which determines if a nic is active / up
@@ -208,6 +301,31 @@ enable_auto_dhcp()
 
 };
 
+# Function which detects available nics, and runs rtsol on them.
+enable_auto_slaac()
+{
+
+  # start by getting a list of nics on this system
+  ${QUERYDIR}/detect-nics.sh > ${TMPDIR}/.niclist
+  ALLNICS=""
+  while read line
+  do
+    NIC="`echo $line | cut -d ':' -f 1`"
+    DESC="`echo $line | cut -d ':' -f 2`"
+
+    is_nic_active "${NIC}"
+    if [ $? -eq 0 ] ; then
+      echo_log "Will try IPv6 SLAAC on $NIC $DESC"
+      ifconfig ${NIC} inet6 -ifdisabled accept_rtadv up
+      ALLNICS="${ALLNICS} ${NIC}"
+    fi
+  done < ${TMPDIR}/.niclist 
+
+  # XXX once we support it in-tree call /sbin/resovconf here.
+  echo_log "Running rtsol on ${ALLNICS}"
+  rtsol -F ${ALLNICS} >/dev/null 2>/dev/null
+}
+
 # Get the mac address of a target NIC
 get_nic_mac()
 {
@@ -236,15 +354,20 @@ enable_manual_nic()
 
   # If we get here, we have a manual setup, lets do so now
 
-  # Set the manual IP
-  rc_halt "ifconfig ${NIC} ${NETIP}"
+  # IPv4:
 
-  # Check if we have a netmask to set
-  get_value_from_cfg netMask
-  NETMASK="${VAL}"
-  if [ -n "${NETMASK}" ]
+  # Set the manual IP
+  if [ -n "${NETIP}" ]
   then
-    rc_halt "ifconfig ${NIC} netmask ${NETMASK}"
+    # Check if we have a netmask to set
+    get_value_from_cfg netMask
+    NETMASK="${VAL}"
+    if [ -n "${NETMASK}" ]
+    then
+      rc_halt "ifconfig inet ${NIC} netmask ${NETMASK}"
+    else
+      rc_halt "ifconfig inet ${NIC} ${NETIP}"
+    fi
   fi
 
   # Check if we have a default router to set
@@ -252,18 +375,42 @@ enable_manual_nic()
   NETROUTE="${VAL}"
   if [ -n "${NETROUTE}" ]
   then
-    rc_halt "route add default ${NETROUTE}"
+    rc_halt "route add -inet default ${NETROUTE}"
+  fi
+
+  # IPv6:
+
+  # Set static IPv6 address
+  get_value_from_cfg netIPv6
+  NETIP="${VAL}"
+  if [ -n ${NETIP} ]
+  then
+      rc_halt "ifconfig inet6 ${NIC} ${NETIP} -ifdisabled up"
+  fi
+
+  # Default router
+  get_value_from_cfg netIPv6DefaultRouter
+  NETROUTE="${VAL}"
+  if [ -n "${NETROUTE}" ]
+  then
+    rc_halt "route add -inet6 default ${NETROUTE}"
   fi
 
   # Check if we have a nameserver to enable
+  : >/etc/resolv.conf
   get_value_from_cfg netNameServer
   NAMESERVER="${VAL}"
   if [ -n "${NAMESERVER}" ]
   then
-    echo "nameserver ${NAMESERVER}" >/etc/resolv.conf
+    echo "nameserver ${NAMESERVER}" >>/etc/resolv.conf
   fi
-  
-  
+  get_value_from_cfg netIPv6NameServer
+  NAMESERVER="${VAL}"
+  if [ -n "${NAMESERVER}" ]
+  then
+    echo "nameserver ${NAMESERVER}" >>/etc/resolv.conf
+  fi
+
 };
 
 
@@ -281,6 +428,9 @@ start_networking()
   if [ "$NETDEV" = "AUTO-DHCP" ]
   then
     enable_auto_dhcp
+  elif [ "$NETDEV" = "IPv6-SLAAC" ]
+  then
+    enable_auto_slaac
   else
     enable_manual_nic ${NETDEV}
   fi
@@ -304,6 +454,9 @@ save_networking_install()
   if [ "$NETDEV" = "AUTO-DHCP" ]
   then
     save_auto_dhcp
+  elif [ "$NETDEV" = "IPv6-SLAAC" ]
+  then
+    save_auto_slaac
   else
     save_manual_nic ${NETDEV}
   fi



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201105311502.p4VF2Uew028482>