diff options
author | Denys Vlasenko | 2011-10-20 14:24:18 +0200 |
---|---|---|
committer | Denys Vlasenko | 2011-10-20 14:24:18 +0200 |
commit | fbca0c68a75d0f2243bd7995d130e9cb8f6d2e18 (patch) | |
tree | 74c5f26b77d346d6975f0cc1f51762a74e688031 /networking | |
parent | cd4d78f525526df0d2b62dce5a0dfc510debd6de (diff) | |
download | busybox-fbca0c68a75d0f2243bd7995d130e9cb8f6d2e18.zip busybox-fbca0c68a75d0f2243bd7995d130e9cb8f6d2e18.tar.gz |
udhcpc: in fill_envp, export BOOTP fields first
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking')
-rw-r--r-- | networking/udhcp/dhcpc.c | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index d67769e..36c8a3d 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -393,7 +393,7 @@ static char **fill_envp(struct dhcp_packet *packet) if (i == DHCP_OPTION_OVERLOAD) overload = *temp; else if (i == DHCP_SUBNET) - envc++; /* for mton */ + envc++; /* for $mask */ envc++; /*if (i != DHCP_MESSAGE_TYPE)*/ FOUND_OPTS(i) |= BMASK(i); @@ -408,10 +408,42 @@ static char **fill_envp(struct dhcp_packet *packet) if (!packet) return envp; + /* Export BOOTP fields. Fields we don't (yet?) export: + * uint8_t op; // always BOOTREPLY + * uint8_t htype; // hardware address type. 1 = 10mb ethernet + * uint8_t hlen; // hardware address length + * uint8_t hops; // used by relay agents only + * uint32_t xid; + * uint16_t secs; // elapsed since client began acquisition/renewal + * uint16_t flags; // only one flag so far: bcast. Never set by server + * uint32_t ciaddr; // client IP (usually == yiaddr. can it be different + * // if during renew server wants to give us differn IP?) + * uint32_t gateway_nip; // relay agent IP address + * uint8_t chaddr[16]; // link-layer client hardware address (MAC) + * TODO: export gateway_nip as $giaddr? + */ + /* Most important one: yiaddr as $ip */ *curr = xmalloc(sizeof("ip=255.255.255.255")); sprint_nip(*curr, "ip=", (uint8_t *) &packet->yiaddr); putenv(*curr++); + if (packet->siaddr_nip) { + /* IP address of next server to use in bootstrap */ + *curr = xmalloc(sizeof("siaddr=255.255.255.255")); + sprint_nip(*curr, "siaddr=", (uint8_t *) &packet->siaddr_nip); + putenv(*curr++); + } + if (!(overload & FILE_FIELD) && packet->file[0]) { + /* watch out for invalid packets */ + *curr = xasprintf("boot_file=%."DHCP_PKT_FILE_LEN_STR"s", packet->file); + putenv(*curr++); + } + if (!(overload & SNAME_FIELD) && packet->sname[0]) { + /* watch out for invalid packets */ + *curr = xasprintf("sname=%."DHCP_PKT_SNAME_LEN_STR"s", packet->sname); + putenv(*curr++); + } + /* Export known DHCP options */ opt_name = dhcp_option_strings; i = 0; while (*opt_name) { @@ -428,29 +460,14 @@ static char **fill_envp(struct dhcp_packet *packet) /* Subnet option: make things like "$ip/$mask" possible */ uint32_t subnet; move_from_unaligned32(subnet, temp); - *curr = xasprintf("mask=%d", mton(subnet)); + *curr = xasprintf("mask=%u", mton(subnet)); putenv(*curr++); } next: opt_name += strlen(opt_name) + 1; i++; } - if (packet->siaddr_nip) { - *curr = xmalloc(sizeof("siaddr=255.255.255.255")); - sprint_nip(*curr, "siaddr=", (uint8_t *) &packet->siaddr_nip); - putenv(*curr++); - } - if (!(overload & FILE_FIELD) && packet->file[0]) { - /* watch out for invalid packets */ - *curr = xasprintf("boot_file=%."DHCP_PKT_FILE_LEN_STR"s", packet->file); - putenv(*curr++); - } - if (!(overload & SNAME_FIELD) && packet->sname[0]) { - /* watch out for invalid packets */ - *curr = xasprintf("sname=%."DHCP_PKT_SNAME_LEN_STR"s", packet->sname); - putenv(*curr++); - } - /* Handle unknown options */ + /* Export unknown options */ for (i = 0; i < 256;) { BITMAP bitmap = FOUND_OPTS(i); if (!bitmap) { @@ -472,6 +489,7 @@ static char **fill_envp(struct dhcp_packet *packet) } i++; } + return envp; } |