On 12/16/2011 01:14 AM, Dan Fandrich wrote:
> On Thu, Dec 15, 2011 at 10:57:19PM +0000, Michael McTernan wrote:
>> +                            val = strtok(NULL, ", \t/-");
> 
> / and - seems like they would be confusing as separators in this
> context (e.g. 1.2.3.4/5.6.7.8/9.8.7.6 would be parsed the same way
> as 1.2.3.4/5, 9.8.7.6) but I can also see that it maintains compatibility
> with OPTION_IP_PAIR.

Yep - I wasn't sure about that, but chose to use the same as IP_PAIR.  I guess 
the compiler may get to reuse the string constant for some small space saving 
too.  

>> +
>> +                    if (retval) {
> 
> This block could be moved one line up into the previous else block.

Done.
 
> How about adding an example in examples/udhcp/udhcpd.conf?

Done.  That should help users with any ambiguity as per your first point.


Thanks for the prompt feedback; here is a revised version of the patch for all 
to review.

Kind Regards,

Mike


Signed-off-by: Michael McTernan <Michael.McTernan.2001 at cs.bris.ac.uk>
---
 examples/udhcp/udhcpd.conf |    7 +++++--
 networking/udhcp/common.c  |   38 +++++++++++++++++++++++++++++++-------
 2 files changed, 36 insertions(+), 9 deletions(-)

diff -Naur -x .svn busybox-1.19.3/examples/udhcp/udhcpd.conf 
busybox-1.19.3-static-route/examples/udhcp/udhcpd.conf
--- busybox-1.19.3/examples/udhcp/udhcpd.conf   2011-09-06 03:35:17.000000000 
+0100
+++ busybox-1.19.3-static-route/examples/udhcp/udhcpd.conf      2011-12-16 
08:57:31.517279398 +0000
@@ -68,6 +68,8 @@
 option dns     129.219.13.81   # appended to above DNS servers for a total of 3
 option domain  local
 option lease   864000          # default: 10 days
+option msstaticroutes  10.0.0.0/8 10.127.0.1           # single static route
+option staticroutes    10.0.0.0/8 10.127.0.1, 10.11.12.0/24 10.11.12.1
 # Arbitrary option in hex form:
 option 0x08    01020304        # option 8: "cookie server IP addr: 1.2.3.4"

@@ -101,6 +103,8 @@
 #opt swapsrv    IP
 # Options specifying routes
 #opt routes     IP_PAIR_LIST
+#opt staticroutes   STATIC_ROUTES # RFC 3442 classless static route option
+#opt msstaticroutes STATIC_ROUTES # RFC 3442, using MS option number
 # Obsolete options, no longer supported
 #opt logsrv     IP_LIST        # 704/UDP log server (not syslog!)
 #opt namesrv    IP_LIST        # IEN 116 name server, obsolete (August 1979!!!)
@@ -109,5 +113,4 @@
 # TODO: in development
 #opt userclass  STRING         # RFC 3004. set of LASCII strings. "I am a 
printer" etc
 #opt sipserv    STRING LIST    # RFC 3361. flag byte, then: 0: domain names, 
1: IP addrs
-#opt staticroutes   STATIC_ROUTES
-#opt msstaticroutes STATIC_ROUTES
+
diff -Naur -x .svn busybox-1.19.3/networking/udhcp/common.c 
busybox-1.19.3-static-route/networking/udhcp/common.c
--- busybox-1.19.3/networking/udhcp/common.c    2011-09-06 03:35:17.000000000 
+0100
+++ busybox-1.19.3-static-route/networking/udhcp/common.c       2011-12-16 
08:53:58.302295297 +0000
@@ -54,12 +54,12 @@
        { OPTION_DNS_STRING | OPTION_LIST         , 0x77 }, /* 
DHCP_DOMAIN_SEARCH */
        { OPTION_SIP_SERVERS                      , 0x78 }, /* DHCP_SIP_SERVERS 
  */
 #endif
-       { OPTION_STATIC_ROUTES                    , 0x79 }, /* 
DHCP_STATIC_ROUTES */
+       { OPTION_STATIC_ROUTES | OPTION_LIST      , 0x79 }, /* 
DHCP_STATIC_ROUTES */
 #if ENABLE_FEATURE_UDHCP_8021Q
        { OPTION_U16                              , 0x84 }, /* DHCP_VLAN_ID     
  */
        { OPTION_U8                               , 0x85 }, /* 
DHCP_VLAN_PRIORITY */
 #endif
-       { OPTION_STATIC_ROUTES                    , 0xf9 }, /* 
DHCP_MS_STATIC_ROUTES */
+       { OPTION_STATIC_ROUTES | OPTION_LIST      , 0xf9 }, /* 
DHCP_MS_STATIC_ROUTES */
        { OPTION_STRING                           , 0xfc }, /* DHCP_WPAD        
  */

        /* Options below have no match in dhcp_option_strings[],
@@ -119,8 +119,6 @@
 // is not handled yet by "string->option" conversion code:
        "sipsrv" "\0"      /* DHCP_SIP_SERVERS    */
 #endif
-// doesn't work in udhcpd.conf since OPTION_STATIC_ROUTES
-// is not handled yet by "string->option" conversion code:
        "staticroutes" "\0"/* DHCP_STATIC_ROUTES  */
 #if ENABLE_FEATURE_UDHCP_8021Q
        "vlanid" "\0"      /* DHCP_VLAN_ID        */
@@ -331,7 +329,7 @@
        lsa = host_and_af2sockaddr(str, 0, AF_INET);
        if (!lsa)
                return 0;
-       *(uint32_t*)arg = lsa->u.sin.sin_addr.s_addr;
+       memcpy(arg, &lsa->u.sin.sin_addr.s_addr, sizeof(uint32_t)); /* *arg 
maybe unaligned */
        free(lsa);
        return 1;
 }
@@ -434,7 +432,7 @@
        struct dhcp_optflag bin_optflag;
        unsigned optcode;
        int retval, length;
-       char buffer[8] ALIGNED(4);
+       char buffer[9] ALIGNED(4);
        uint16_t *result_u16 = (uint16_t *) buffer;
        uint32_t *result_u32 = (uint32_t *) buffer;

@@ -521,9 +519,35 @@
                        retval = (endptr[0] == '\0');
                        break;
                }
-               case OPTION_BIN: /* handled in attach_option() */
+               case OPTION_BIN: { /* handled in attach_option() */
                        opt = val;
                        retval = 1;
+                       break;
+               }
+               case OPTION_STATIC_ROUTES: {
+                       char *bits;
+
+                       /* expect a.b.c.d/m format */
+                       bits = strchr(val, '/');
+                       if(!bits) {
+                               retval = 0;
+                       } else {
+                               *bits = '\0';
+                               buffer[0] = strtoul(bits + 1, NULL, 0);
+
+                               retval = udhcp_str2nip(val, buffer + 1);
+                               val = strtok(NULL, ", \t/-");
+                               if (!val || (unsigned char)buffer[0] > 32)
+                                       retval = 0;
+
+                               if (retval) {
+                                       length = ((buffer[0] + 7) >> 3) + 5;
+                                       retval = udhcp_str2nip(val, buffer + 
(length - 4));
+                                       opt = buffer;
+                               }
+                       }
+                       break;
+               }
                default:
                        break;
                }


--
Mike
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to