[rtems-libbsd commit] rc.conf/net: Let interface option appear on a DHCP ifconfig_ line.

Chris Johns chrisj at rtems.org
Fri Aug 12 06:10:22 UTC 2016


Module:    rtems-libbsd
Branch:    master
Commit:    ab7739a574e174b71b51ceaeef409df97463f16b
Changeset: http://git.rtems.org/rtems-libbsd/commit/?id=ab7739a574e174b71b51ceaeef409df97463f16b

Author:    Chris Johns <chrisj at rtems.org>
Date:      Fri Aug 12 13:55:37 2016 +1000

rc.conf/net: Let interface option appear on a DHCP ifconfig_ line.

An ifconfig_ line can have other options for the interface such as
ether or hardware checksum control. Allow these to be set on the
interface.

---

 rtemsbsd/rtems/rtems-bsd-rc-conf-net.c | 42 ++++++++++++++++++++++------------
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/rtemsbsd/rtems/rtems-bsd-rc-conf-net.c b/rtemsbsd/rtems/rtems-bsd-rc-conf-net.c
index 5437841..67b18d1 100644
--- a/rtemsbsd/rtems/rtems-bsd-rc-conf-net.c
+++ b/rtemsbsd/rtems/rtems-bsd-rc-conf-net.c
@@ -235,6 +235,8 @@ ifconfig_(rtems_bsd_rc_conf* rc_conf,
 {
   const char**      args;
   int               arg;
+  int               ifconfig_argc = 0;
+  bool              add_up = true;
   int               r;
   const char const* ifconfig_show[] = { "ifconfig", ifname, NULL };
 
@@ -249,17 +251,25 @@ ifconfig_(rtems_bsd_rc_conf* rc_conf,
     return -1;
   }
 
-  args[0] = "ifconfig";
-  args[1] = ifname;
+  args[ifconfig_argc++] = "ifconfig";
+  args[ifconfig_argc++] = ifname;
 
-  for (arg = 1; arg < argc; ++arg)
-    args[arg + 1] = argv[arg];
+  for (arg = 1; arg < argc; ++arg) {
+    if (strcasecmp("DHCP",     argv[arg]) == 0 ||
+        strcasecmp("SYNCDHCP", argv[arg]) == 0) {
+      add_up = false;
+    }
+    else {
+      args[ifconfig_argc++] = argv[arg];
+    }
+  }
 
-  args[argc + 1] = "up";
+  if (add_up)
+    args[ifconfig_argc++] = "up";
 
-  rtems_bsd_rc_conf_print_cmd(rc_conf, "ifconfig", argc + 2, args);
+  rtems_bsd_rc_conf_print_cmd(rc_conf, "ifconfig", ifconfig_argc, args);
 
-  r = rtems_bsd_command_ifconfig(argc + 2, (char**) args);
+  r = rtems_bsd_command_ifconfig(ifconfig_argc, (char**) args);
 
   free(args);
 
@@ -374,10 +384,12 @@ show_interfaces(const char* msg, struct ifaddrs* ifap)
 static int
 dhcp_check(rtems_bsd_rc_conf_argc_argv* aa)
 {
-  if (aa->argc == 2 &&
-      (strcasecmp("DHCP",     aa->argv[1]) == 0 ||
-       strcasecmp("SYNCDHCP", aa->argv[1]) == 0))
-    return true;
+  int arg;
+  for (arg = 0; arg < aa->argc; ++arg) {
+    if (strcasestr(aa->argv[1], "DHCP") != NULL ||
+        strcasestr(aa->argv[1], "SYNCDHCP") != NULL)
+      return true;
+  }
   return false;
 }
 
@@ -419,9 +431,11 @@ setup_interfaces(rtems_bsd_rc_conf*           rc_conf,
         if (dhcp_check(aa)) {
           *dhcp = true;
         }
-        else {
-          show_result(iface, ifconfig_(rc_conf, ifa->ifa_name, aa->argc, aa->argv));
-        }
+        /*
+         * A DHCP ifconfig can have other options we need to set on the
+         * interface.
+         */
+        show_result(iface, ifconfig_(rc_conf, ifa->ifa_name, aa->argc, aa->argv));
       }
     }
   }




More information about the vc mailing list