diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-26 09:32:09 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-26 09:32:09 +0100 |
commit | 7724c766bdfba5f3af5cdf5d869bcf03f45149e3 (patch) | |
tree | d1cb0db7b683bdc9c9ecb954cc83dea7d53ae440 /networking/udhcp/common.c | |
parent | a8f6b9998727ad67db4b812270a1bbceea011dde (diff) | |
download | busybox-w32-7724c766bdfba5f3af5cdf5d869bcf03f45149e3.tar.gz busybox-w32-7724c766bdfba5f3af5cdf5d869bcf03f45149e3.tar.bz2 busybox-w32-7724c766bdfba5f3af5cdf5d869bcf03f45149e3.zip |
udhcp: pass pointer to whole packet to "add option" functions
This is needed for "overflow option" support
function old new delta
udhcp_find_option - 34 +34
udhcp_add_binary_option 94 106 +12
write_leases 227 223 -4
udhcp_init_header 86 82 -4
send_release 104 99 -5
init_packet 87 81 -6
add_client_options 160 154 -6
add_server_options 100 92 -8
udhcpd_main 1964 1954 -10
udhcpc_main 2859 2837 -22
find_option 34 - -34
------------------------------------------------------------------------------
(add/remove: 1/1 grow/shrink: 1/8 up/down: 46/-99) Total: -53 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/common.c')
-rw-r--r-- | networking/udhcp/common.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index bc458ac7a..9316774ff 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c | |||
@@ -226,14 +226,16 @@ int FAST_FUNC udhcp_end_option(uint8_t *optionptr) | |||
226 | /* Add an option (supplied in binary form) to the options. | 226 | /* Add an option (supplied in binary form) to the options. |
227 | * Option format: [code][len][data1][data2]..[dataLEN] | 227 | * Option format: [code][len][data1][data2]..[dataLEN] |
228 | */ | 228 | */ |
229 | void FAST_FUNC udhcp_add_binary_option(uint8_t *optionptr, uint8_t *addopt) | 229 | void FAST_FUNC udhcp_add_binary_option(struct dhcp_packet *packet, uint8_t *addopt) |
230 | { | 230 | { |
231 | unsigned len; | 231 | unsigned len; |
232 | uint8_t *optionptr = packet->options; | ||
232 | unsigned end = udhcp_end_option(optionptr); | 233 | unsigned end = udhcp_end_option(optionptr); |
233 | 234 | ||
234 | /* end position + option code/length + addopt length + end option */ | ||
235 | len = OPT_DATA + addopt[OPT_LEN]; | 235 | len = OPT_DATA + addopt[OPT_LEN]; |
236 | /* end position + (option code/length + addopt length) + end option */ | ||
236 | if (end + len + 1 >= DHCP_OPTIONS_BUFSIZE) { | 237 | if (end + len + 1 >= DHCP_OPTIONS_BUFSIZE) { |
238 | //TODO: learn how to use overflow option if we exhaust packet->options[] | ||
237 | bb_error_msg("option 0x%02x did not fit into the packet", | 239 | bb_error_msg("option 0x%02x did not fit into the packet", |
238 | addopt[OPT_CODE]); | 240 | addopt[OPT_CODE]); |
239 | return; | 241 | return; |
@@ -243,8 +245,8 @@ void FAST_FUNC udhcp_add_binary_option(uint8_t *optionptr, uint8_t *addopt) | |||
243 | optionptr[end + len] = DHCP_END; | 245 | optionptr[end + len] = DHCP_END; |
244 | } | 246 | } |
245 | 247 | ||
246 | /* Add a one to four byte option to a packet */ | 248 | /* Add an one to four byte option to a packet */ |
247 | void FAST_FUNC udhcp_add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data) | 249 | void FAST_FUNC udhcp_add_simple_option(struct dhcp_packet *packet, uint8_t code, uint32_t data) |
248 | { | 250 | { |
249 | const struct dhcp_option *dh; | 251 | const struct dhcp_option *dh; |
250 | 252 | ||
@@ -259,7 +261,7 @@ void FAST_FUNC udhcp_add_simple_option(uint8_t *optionptr, uint8_t code, uint32_ | |||
259 | data <<= 8 * (4 - len); | 261 | data <<= 8 * (4 - len); |
260 | /* Assignment is unaligned! */ | 262 | /* Assignment is unaligned! */ |
261 | move_to_unaligned32(&option[OPT_DATA], data); | 263 | move_to_unaligned32(&option[OPT_DATA], data); |
262 | udhcp_add_binary_option(optionptr, option); | 264 | udhcp_add_binary_option(packet, option); |
263 | return; | 265 | return; |
264 | } | 266 | } |
265 | } | 267 | } |
@@ -268,7 +270,7 @@ void FAST_FUNC udhcp_add_simple_option(uint8_t *optionptr, uint8_t code, uint32_ | |||
268 | } | 270 | } |
269 | 271 | ||
270 | /* Find option 'code' in opt_list */ | 272 | /* Find option 'code' in opt_list */ |
271 | struct option_set* FAST_FUNC find_option(struct option_set *opt_list, uint8_t code) | 273 | struct option_set* FAST_FUNC udhcp_find_option(struct option_set *opt_list, uint8_t code) |
272 | { | 274 | { |
273 | while (opt_list && opt_list->data[OPT_CODE] < code) | 275 | while (opt_list && opt_list->data[OPT_CODE] < code) |
274 | opt_list = opt_list->next; | 276 | opt_list = opt_list->next; |
@@ -307,7 +309,7 @@ static NOINLINE void attach_option( | |||
307 | char *allocated = NULL; | 309 | char *allocated = NULL; |
308 | #endif | 310 | #endif |
309 | 311 | ||
310 | existing = find_option(*opt_list, option->code); | 312 | existing = udhcp_find_option(*opt_list, option->code); |
311 | if (!existing) { | 313 | if (!existing) { |
312 | log2("Attaching option %02x to list", option->code); | 314 | log2("Attaching option %02x to list", option->code); |
313 | #if ENABLE_FEATURE_UDHCP_RFC3397 | 315 | #if ENABLE_FEATURE_UDHCP_RFC3397 |