diff options
Diffstat (limited to 'networking/udhcp/script.c')
-rw-r--r-- | networking/udhcp/script.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c index d2b0bb05b..dc8ff7a1c 100644 --- a/networking/udhcp/script.c +++ b/networking/udhcp/script.c | |||
@@ -19,6 +19,9 @@ static const int max_option_length[] = { | |||
19 | [OPTION_IP] = sizeof("255.255.255.255 "), | 19 | [OPTION_IP] = sizeof("255.255.255.255 "), |
20 | [OPTION_IP_PAIR] = sizeof("255.255.255.255 ") * 2, | 20 | [OPTION_IP_PAIR] = sizeof("255.255.255.255 ") * 2, |
21 | [OPTION_STRING] = 1, | 21 | [OPTION_STRING] = 1, |
22 | #if ENABLE_FEATURE_RFC3397 | ||
23 | [OPTION_STR1035] = 1, | ||
24 | #endif | ||
22 | [OPTION_BOOLEAN] = sizeof("yes "), | 25 | [OPTION_BOOLEAN] = sizeof("yes "), |
23 | [OPTION_U8] = sizeof("255 "), | 26 | [OPTION_U8] = sizeof("255 "), |
24 | [OPTION_U16] = sizeof("65535 "), | 27 | [OPTION_U16] = sizeof("65535 "), |
@@ -53,21 +56,23 @@ static int mton(struct in_addr *mask) | |||
53 | } | 56 | } |
54 | 57 | ||
55 | 58 | ||
56 | /* Fill dest with the text of option 'option'. */ | 59 | /* Allocate and fill with the text of option 'option'. */ |
57 | static void fill_options(char *dest, uint8_t *option, | 60 | static char *alloc_fill_opts(uint8_t *option, const struct dhcp_option *type_p) |
58 | const struct dhcp_option *type_p) | ||
59 | { | 61 | { |
60 | int type, optlen; | 62 | int len, type, optlen; |
61 | uint16_t val_u16; | 63 | uint16_t val_u16; |
62 | int16_t val_s16; | 64 | int16_t val_s16; |
63 | uint32_t val_u32; | 65 | uint32_t val_u32; |
64 | int32_t val_s32; | 66 | int32_t val_s32; |
65 | int len = option[OPT_LEN - 2]; | 67 | char *dest, *ret; |
66 | |||
67 | dest += sprintf(dest, "%s=", type_p->name); | ||
68 | 68 | ||
69 | len = option[OPT_LEN - 2]; | ||
69 | type = type_p->flags & TYPE_MASK; | 70 | type = type_p->flags & TYPE_MASK; |
70 | optlen = option_lengths[type]; | 71 | optlen = option_lengths[type]; |
72 | |||
73 | dest = ret = xmalloc(upper_length(len, type) + strlen(type_p->name) + 2); | ||
74 | dest += sprintf(ret, "%s=", type_p->name); | ||
75 | |||
71 | for (;;) { | 76 | for (;;) { |
72 | switch (type) { | 77 | switch (type) { |
73 | case OPTION_IP_PAIR: | 78 | case OPTION_IP_PAIR: |
@@ -103,13 +108,21 @@ static void fill_options(char *dest, uint8_t *option, | |||
103 | case OPTION_STRING: | 108 | case OPTION_STRING: |
104 | memcpy(dest, option, len); | 109 | memcpy(dest, option, len); |
105 | dest[len] = '\0'; | 110 | dest[len] = '\0'; |
106 | return; /* Short circuit this case */ | 111 | return ret; /* Short circuit this case */ |
112 | #if ENABLE_FEATURE_RFC3397 | ||
113 | case OPTION_STR1035: | ||
114 | /* unpack option into dest; use ret for prefix (i.e., "optname=") */ | ||
115 | dest = dname_dec(option, len, ret); | ||
116 | free(ret); | ||
117 | return dest; | ||
118 | #endif | ||
107 | } | 119 | } |
108 | option += optlen; | 120 | option += optlen; |
109 | len -= optlen; | 121 | len -= optlen; |
110 | if (len <= 0) break; | 122 | if (len <= 0) break; |
111 | dest += sprintf(dest, " "); | 123 | dest += sprintf(dest, " "); |
112 | } | 124 | } |
125 | return ret; | ||
113 | } | 126 | } |
114 | 127 | ||
115 | 128 | ||
@@ -155,9 +168,7 @@ static char **fill_envp(struct dhcpMessage *packet) | |||
155 | temp = get_option(packet, dhcp_options[i].code); | 168 | temp = get_option(packet, dhcp_options[i].code); |
156 | if (!temp) | 169 | if (!temp) |
157 | continue; | 170 | continue; |
158 | envp[j] = xmalloc(upper_length(temp[OPT_LEN - 2], | 171 | envp[j++] = alloc_fill_opts(temp, &dhcp_options[i]); |
159 | dhcp_options[i].flags & TYPE_MASK) + strlen(dhcp_options[i].name) + 2); | ||
160 | fill_options(envp[j++], temp, &dhcp_options[i]); | ||
161 | 172 | ||
162 | /* Fill in a subnet bits option for things like /24 */ | 173 | /* Fill in a subnet bits option for things like /24 */ |
163 | if (dhcp_options[i].code == DHCP_SUBNET) { | 174 | if (dhcp_options[i].code == DHCP_SUBNET) { |