Bug 735

Summary: Specifying a binary option in udhcpc is not possible
Product: Busybox Reporter: Nikos Mavrogianopoulos <nmav>
Component: NetworkingAssignee: unassigned
Status: RESOLVED FIXED    
Severity: enhancement CC: busybox-cvs
Priority: P5    
Version: 1.15.x   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:
Attachments: DHCP binary options patch

Description Nikos Mavrogianopoulos 2009-11-23 12:17:36 UTC
It is not possible with the current interface to specify a binary option at udhcpc. This is desirable since DHCP options such as Client ID are usually binary. This patch will convert command line input that starts with 0x... and is followed by hex to binary.
Comment 1 Denys Vlasenko 2009-11-29 02:13:07 UTC
Forgot to attach the patch?
Comment 2 Nikos Mavrogianopoulos 2009-11-30 07:35:30 UTC
Created attachment 773 [details]
DHCP binary options patch

I don't know what happened. Those patches were there last time I checked. Anyway reattaching.
Comment 3 Denys Vlasenko 2010-04-04 00:35:34 UTC
Simply special-casing "Ox" is not a clean implementation - now hostname "0xcart" is suddenly invalid (!).
Moreover, it acts only on -h, -c and -V.

I added support for adding any DHCP options, not just selected few (like -h,-c,-V,-F we had before) but any one using -x optname:optval syntax.

This code reuses the same machinery which is employed by dhcp server to parse options from config file.

Because of this, best way to add binary option is to add a bit of code in networking/udhcp/common.c, udhcp_str2optset() function. Currently, its start looks like this:

        opt = strtok(str, " \t=");
        if (!opt)
                return 0;

        option = &dhcp_options[udhcp_option_idx(opt)];

The last line parses "optname".
If we'd insert a code

        if (optname is a number) {
                val = strtok(NULL, ", \t");
                opt,length = parse_optval_as_a_hex_string(val);
                attach_option(opt_list, opt, length);
                return;
        }

directly before it, both dhcp client and server would be able to use it: via -x "23:deadface" and "option 23 deadface" respectively.
Comment 4 Denys Vlasenko 2010-04-04 13:32:04 UTC
Fixed in git, please test.
Comment 5 Nikos Mavrogianopoulos 2010-04-05 20:44:16 UTC
The idea looks good!