tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

rc.d/network



On Thu, 18 Sep 2008, der Mouse wrote:
> > something like this would be nice for ifconfig_ifX too, to not
> > require an /etc/ifconfig.ifX file if multiple lines are needed.
> 
> But, yes, I agree that anything which can be done via /etc/ifconfig.*
> should be doable via suitable rc.conf variable settings.

I have an implementation of that.  The $ifconfig_nnX variable is split
into lines (using semicolons or actual newlines as the separator), and
then parsed using the same code that currently parses /etc/ifconfig.nnX
files.  There's no way to escape a ';' to prevent it from being treated
as a line separator, but apart from that limitation, anything you can
do in an /etc/ifconfig.nnX file can also be done in a $ifconfig_nnX
variable.

I append the patch.  Don't be concerned about the apparent deletion of
the special case for "dhcp" -- the previous code was duplicated and only
one of the copies is deleted.

--apb (Alan Barrett)

--- etc/rc.d/network    24 Jul 2008 19:48:19 -0000      1.53
+++ etc/rc.d/network    18 Sep 2008 10:24:50 -0000
@@ -155,12 +155,18 @@
        # Configure all of the network interfaces listed in $net_interfaces;
        # if $auto_ifconfig is YES, grab all interfaces from ifconfig.
        # In the following, "xxN" stands in for interface names, like "le0".
-       # For any interfaces that has an $ifconfig_xxN variable associated,
-       # we do "ifconfig xxN $ifconfig_xxN".
-       # If there is no such variable, we take the contents of the file
-       # /etc/ifconfig.xxN, and run "ifconfig xxN" repeatedly, using each
-       # line of the file as the arguments for a separate "ifconfig"
-       # invocation.
+       #
+       # For any interfaces that has an $ifconfig_xxN variable
+       # associated, we break it into lines using ';' as a separator,
+       # then process it just like the contents of an /etc/ifconfig.xxN
+       # file.
+       #
+       # For each line from the $ifconfig_xxN variable or the
+       # /etc/ifconfig.xxN file, we ignore comments and blank lines,
+       # treat lines beginning with "!" as commands to execute, treat
+       # "dhcp" as a special case to invoke dhcpcd, and for any other
+       # line we run "ifconfig xxN", using each line of the file as the
+       # arguments for a separate "ifconfig" invocation.
        #
        # In order to configure an interface reasonably, you at the very least
        # need to specify "[addr_family] [hostname]" (e.g "inet my.domain.org"),
@@ -192,22 +198,19 @@
                fi
                echo -n 'Configuring network interfaces:'
                for int in $tmp; do
-                       eval args=\$ifconfig_$int
-                       if [ -n "$args" ] || [ -f /etc/ifconfig.$int ]; then
+                       eval argslist=\$ifconfig_$int
+                       if [ -n "$argslist" ] || [ -f /etc/ifconfig.$int ]; then
+                               echo -n " $int"
                                if /sbin/ifconfig $int create 2>/dev/null && \
                                   checkyesno ipfilter; then
                                        # resync ipf(4)
                                        /sbin/ipf -y >/dev/null
                                fi
-                       fi
-                       if [ "$args" = "dhcp" ]; then
-                               echo -n " $int"
-                               /sbin/dhcpcd -n ${dhcpcd_flags} $int
-                       elif [ -n "$args" ]; then
-                               echo -n " $int"
-                               /sbin/ifconfig $int $args
-                       elif [ -f /etc/ifconfig.$int ]; then
-                               echo -n " $int"
+                               if [ -n "$argslist" ]; then
+                                       printf "%s\n" "$argslist" | tr ';' '\n'
+                               else
+                                       cat /etc/ifconfig.$int
+                               fi | \
                                while read args; do
                                        [ -z "$args" ] && continue
                                        case "$args" in
@@ -224,7 +227,7 @@
                                                eval /sbin/ifconfig $int $args
                                                ;;
                                        esac
-                               done < /etc/ifconfig.$int
+                               done
                        else
                                if ! checkyesno auto_ifconfig; then
                                        echo


Home | Main Index | Thread Index | Old Index