What's new

udhcpc startup config

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Shonk

Senior Member
I want to add a hard coded dhcp option pre built into the firmware

I can ofc killall udhcpc and then run below
udhcpc -i eth0 -p /var/run/udhcpc0.pid -s /tmp/udhcpc -O33 -O249 -x 61:hex -x 60:hex

but would like to cleanly insert it into the firmware without having to kill udhcpc

im trying to find how udhcpc is started in the source but i just cant seem to find it

im just not used to everything running from a ramdisk

im also wanting to change upnpd settings but also cant find how the config is generated

if someone can point out where i should be looking in the source that would be great
 
Last edited:
thats a cool feature
but im looking to edit how the config is generated in the source
to avoid using jffs

so that it just works with a fresh factory reset
 
this looks like a winner in udhcpc.c


start_udhcpc(char *wan_ifname, int unit, pid_t *ppid)
{
char tmp[100], prefix[] = "wanXXXXXXXXXX_";
char pid[sizeof("/var/run/udhcpcXXXXXXXXXX.pid")];
char clientid[sizeof("61:") + (32+32+1)*2];
char *value;
char *dhcp_argv[] = { "udhcpc",
"-i", wan_ifname,
"-p", (snprintf(pid, sizeof(pid), "/var/run/udhcpc%d.pid", unit), pid),
"-s", "/tmp/udhcpc",
NULL, /* -t2 */
NULL, /* -T5 */
NULL, /* -A120 */
NULL, /* -b */
NULL, NULL, /* -H wan_hostname */
NULL, /* -Oroutes */
NULL, /* -Ostaticroutes */
NULL, /* -Omsstaticroutes */
#ifdef __CONFIG_IPV6__
NULL, /* -Oip6rd rfc */
NULL, /* -Oip6rd comcast */
#endif
#ifdef RTCONFIG_DSL
NULL, NULL, /* -x 61:wan_clientid */
#endif
NULL, NULL, /* -x 61:wan_clientid (non-DSL) */
NULL };
int index = 7; /* first NULL */
int dr_enable;

i presume im good just just edit that to

"/tmp/udhcpc -x 61:hex -x 60:hex"
 
Last edited:
That looks promising, but there appears to be something built-in to do that:

nvram set wan_dhcpc_options="61:hex 60:hex"
 
Last edited:
the command looked good but didnt pull an ip

gona try it slightly different

/* 0: disable, 1: MS routes, 2: RFC routes, 3: Both */
dr_enable = nvram_get_int("dr_enable_x");
if (dr_enable != 0) {
dhcp_argv[index++] = "-O33"; /* routes */
if (dr_enable & (1 << 0))
dhcp_argv[index++] = "-O249"; /* "msstaticroutes" */
if (dr_enable & (1 << 1))
dhcp_argv[index++] = "-O121"; /* "staticroutes" */
dhcp_argv[index++] = "-x 61:hex"; /* "msstaticroutes" */
if (dr_enable & (1 << 1))
dhcp_argv[index++] = "-x 60:hex"; /* "msstaticroutes" */
if (dr_enable & (1 << 1))

}
 
Last edited:
Don't know whether you'd need to increase the number of elements in the array? (I'm not a C programmer)

Code:
                NULL, NULL,     /* -H wan_hostname */
                NULL,           /* -Oroutes */
                NULL,           /* -Ostaticroutes */
                NULL,           /* -Omsstaticroutes */
[B]                NULL,           /* -x 61:hex */
                NULL,           /* -x 60:hex */[/B]
#ifdef __CONFIG_IPV6__
                NULL,           /* -Oip6rd rfc */
                NULL,           /* -Oip6rd comcast */
#endif
 
the command looked good but didnt pull an ip

Just found this in a completely unrelated post on the internet:
Code:
if [ -n "$dhcp_client_id" ]; then
    # convert client id to hex
    hex_client_id=`hexify $dhcp_client_id`
    # -C surpresses default MAC address as client id;
    # -x 61:hex-encoded-client-id
    dhcp_client_id_arg="-C -x 61:$hex_client_id"
fi
Maybe you need the "-C" option?
 
by default its

udhcpc -i eth0 -p /var/run/udhcpc0.pid -s /tmp/udhcpc -O33 -O249

This works

killall udhcpc
udhcpc -i eth0 -p /var/run/udhcpc0.pid -s /tmp/udhcpc -O33 -O249 -x 61:hex -x 60:hex

also works but is slow pulling an ip 5 secs or so
killall udhcpc
udhcpc -i eth0 -p /var/run/udhcpc0.pid -s /tmp/udhcpc -x 61:hex -x 60:hex -O33 -O249

when using
"-s", "/tmp/udhcpc -x 61:hex -x 60:hex",

it looks to be good but truncates off the screen in ps so cant tell for sure that the command is 100% correct

and doesnt pull an ip

i just tried

killall udhcpc
udhcpc -i eth0 -p /var/run/udhcpc0.pid -s /tmp/udhcpc -C -x 61:hex -x 60:hex -O33 -O249

and it pulled instantly

odd thats its fine with -O33 -O249 first without -C but not with -O33 -O249 after
 
ok i have found out the problem but im unsure how to fix it

"/tmp/udhcpc -x 61:hex -x 60:hex"

results in a ps of

udhcpc -i eth0 -p /var/run/udhcpc0.pid -s /tmp/udhcpc -x 61:hex -x 60:hex

i can killall udhcpc then copy paste the ps

udhcpc -i eth0 -p /var/run/udhcpc0.pid -s /tmp/udhcpc -x 61:hex -x 60:hex

it pulls an ip straight away

but if i ps again it shows as

udhcpc -i eth0 -p /var/run/udhcpc0.pid -s /tmp/udhcpc -x 61 hex -x 60 hex
 
Can I just confirm something? When you say:

"-x 61:hex"

what you are in fact typing is something like:

"-x 61:006d6f6e23206c6170746f70"

Am I correct?

If I specifiy a client ID of "01234" through the GUI it results in this:

Code:
# ps w | grep dhcp
  911 admin     1444 S    udhcpc -i eth0 -p /var/run/udhcpc0.pid -s /tmp/udhcpc -t2 -T5 -A160 -O33 -O249 -x 61 3031323334
So it looks like the removal of the : is normal?
 
Last edited:
all of above correct

"/tmp/udhcpc -x 61:hex -x 60:hex" in udhcpc.c

should result in a ps of

udhcpc -i eth0 -p /var/run/udhcpc0.pid -s /tmp/udhcpc -x 61 hex -x 60 hex

but it results in a ps of

udhcpc -i eth0 -p /var/run/udhcpc0.pid -s /tmp/udhcpc -x 61:hex -x 60:hex


hence my problem

if i do a killall udhcpc and manually paste the command it works fine
 
How about these 3 changes:
Code:
        char *dhcp_argv[] = { "udhcpc",
                "-i", wan_ifname,
                "-p", (snprintf(pid, sizeof(pid), "/var/run/udhcpc%d.pid", unit), pid),
                "-s", "/tmp/udhcpc",
[B]                "-x", "61:hex",
                "-x", "60:hex",[/B]
                NULL,           /* -t2 */
                NULL,           /* -T5 */
                NULL,           /* -A120 */
                NULL,           /* -b */
                NULL, NULL,     /* -H wan_hostname */
                NULL,           /* -Oroutes */
                NULL,           /* -Ostaticroutes */
                NULL,           /* -Omsstaticroutes */
#ifdef __CONFIG_IPV6__
                NULL,           /* -Oip6rd rfc */
                NULL,           /* -Oip6rd comcast */
#endif
#ifdef RTCONFIG_DSL
                NULL, NULL,     /* -x 61:wan_clientid */
#endif
                NULL, NULL,     /* -x 61:wan_clientid (non-DSL) */
                NULL };
[B]        int index = 11;         /* first NULL */[/B]
        int dr_enable;
It's still ugly because of the potential for multiple 61 options if there's a clientid already set in the GUI/nvram.
 
Last edited:
trying it now thanks

int index = 11;

that was 7 shouldnt it goto 9 as i have added two lines?
 
tried it with 9 it resulted in

Untitled.png


building it with 11 now
 
int index = 11;

that was 7 shouldnt it goto 9 as i have added two lines?
No, because you've added 4 elements to the array. They just happen to have been written as 2 lines of code, it could equally have been written as 4 lines of code (with 1 element on each line).

If you set the index to 9 the other parameters will overwrite the "-x" and "60:hex".

P.S. Can I ask why you need to set the clientid like this rather than using the built-in facilty (GUI/nvram)? Is it because you need to set some non-alphanumeric value?
 
Last edited:

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!

Members online

Top