diff options
Diffstat (limited to 'networking/udhcp/script.c')
-rw-r--r-- | networking/udhcp/script.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c index 33d96e687..8a188988e 100644 --- a/networking/udhcp/script.c +++ b/networking/udhcp/script.c | |||
@@ -33,7 +33,7 @@ static const uint8_t max_option_length[] = { | |||
33 | static inline int upper_length(int length, int opt_index) | 33 | static inline int upper_length(int length, int opt_index) |
34 | { | 34 | { |
35 | return max_option_length[opt_index] * | 35 | return max_option_length[opt_index] * |
36 | (length / option_lengths[opt_index]); | 36 | (length / dhcp_option_lengths[opt_index]); |
37 | } | 37 | } |
38 | 38 | ||
39 | 39 | ||
@@ -57,7 +57,7 @@ static int mton(uint32_t mask) | |||
57 | 57 | ||
58 | 58 | ||
59 | /* Allocate and fill with the text of option 'option'. */ | 59 | /* Allocate and fill with the text of option 'option'. */ |
60 | static char *alloc_fill_opts(uint8_t *option, const struct dhcp_option *type_p) | 60 | static char *alloc_fill_opts(uint8_t *option, const struct dhcp_option *type_p, const char *opt_name) |
61 | { | 61 | { |
62 | int len, type, optlen; | 62 | int len, type, optlen; |
63 | uint16_t val_u16; | 63 | uint16_t val_u16; |
@@ -68,10 +68,10 @@ static char *alloc_fill_opts(uint8_t *option, const struct dhcp_option *type_p) | |||
68 | 68 | ||
69 | len = option[OPT_LEN - 2]; | 69 | len = option[OPT_LEN - 2]; |
70 | type = type_p->flags & TYPE_MASK; | 70 | type = type_p->flags & TYPE_MASK; |
71 | optlen = option_lengths[type]; | 71 | optlen = dhcp_option_lengths[type]; |
72 | 72 | ||
73 | dest = ret = xmalloc(upper_length(len, type) + strlen(type_p->opt_name) + 2); | 73 | dest = ret = xmalloc(upper_length(len, type) + strlen(opt_name) + 2); |
74 | dest += sprintf(ret, "%s=", type_p->opt_name); | 74 | dest += sprintf(ret, "%s=", opt_name); |
75 | 75 | ||
76 | for (;;) { | 76 | for (;;) { |
77 | switch (type) { | 77 | switch (type) { |
@@ -133,6 +133,7 @@ static char **fill_envp(struct dhcpMessage *packet) | |||
133 | int i, j; | 133 | int i, j; |
134 | char **envp; | 134 | char **envp; |
135 | char *var; | 135 | char *var; |
136 | const char *opt_name; | ||
136 | uint8_t *temp; | 137 | uint8_t *temp; |
137 | char over = 0; | 138 | char over = 0; |
138 | 139 | ||
@@ -171,11 +172,13 @@ static char **fill_envp(struct dhcpMessage *packet) | |||
171 | envp[j] = xmalloc(sizeof("ip=255.255.255.255")); | 172 | envp[j] = xmalloc(sizeof("ip=255.255.255.255")); |
172 | sprintip(envp[j++], "ip=", (uint8_t *) &packet->yiaddr); | 173 | sprintip(envp[j++], "ip=", (uint8_t *) &packet->yiaddr); |
173 | 174 | ||
174 | for (i = 0; dhcp_options[i].code; i++) { | 175 | opt_name = dhcp_option_strings; |
176 | i = 0; | ||
177 | while (*opt_name) { | ||
175 | temp = get_option(packet, dhcp_options[i].code); | 178 | temp = get_option(packet, dhcp_options[i].code); |
176 | if (!temp) | 179 | if (!temp) |
177 | continue; | 180 | goto next; |
178 | envp[j++] = alloc_fill_opts(temp, &dhcp_options[i]); | 181 | envp[j++] = alloc_fill_opts(temp, &dhcp_options[i], opt_name); |
179 | 182 | ||
180 | /* Fill in a subnet bits option for things like /24 */ | 183 | /* Fill in a subnet bits option for things like /24 */ |
181 | if (dhcp_options[i].code == DHCP_SUBNET) { | 184 | if (dhcp_options[i].code == DHCP_SUBNET) { |
@@ -183,6 +186,9 @@ static char **fill_envp(struct dhcpMessage *packet) | |||
183 | memcpy(&subnet, temp, 4); | 186 | memcpy(&subnet, temp, 4); |
184 | envp[j++] = xasprintf("mask=%d", mton(subnet)); | 187 | envp[j++] = xasprintf("mask=%d", mton(subnet)); |
185 | } | 188 | } |
189 | next: | ||
190 | opt_name += strlen(opt_name) + 1; | ||
191 | i++; | ||
186 | } | 192 | } |
187 | if (packet->siaddr) { | 193 | if (packet->siaddr) { |
188 | envp[j] = xmalloc(sizeof("siaddr=255.255.255.255")); | 194 | envp[j] = xmalloc(sizeof("siaddr=255.255.255.255")); |