diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-01 12:36:09 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-01 12:36:09 +0000 |
commit | bd79c3d337304a96dcce4ae4f97b36143919af10 (patch) | |
tree | 75115aadc65ea14c8b038be883abfe74ca5f4ced | |
parent | 3266aa9ec285dbcf254daa17c103bf69dc755967 (diff) | |
download | busybox-w32-bd79c3d337304a96dcce4ae4f97b36143919af10.tar.gz busybox-w32-bd79c3d337304a96dcce4ae4f97b36143919af10.tar.bz2 busybox-w32-bd79c3d337304a96dcce4ae4f97b36143919af10.zip |
dhcpd: remember and record hostnames; optimize get_option
dumpleases: show hostnames
function old new delta
add_lease 230 292 +62
send_offer 403 421 +18
send_ACK 232 249 +17
read_leases 249 258 +9
dumpleases_main 604 609 +5
nobody_responds_to_arp 84 86 +2
udhcp_end_option 32 30 -2
udhcp_get_option 222 171 -51
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 6/2 up/down: 113/-53) Total: 60 bytes
-rw-r--r-- | networking/udhcp/dhcpd.h | 10 | ||||
-rw-r--r-- | networking/udhcp/dumpleases.c | 9 | ||||
-rw-r--r-- | networking/udhcp/files.c | 2 | ||||
-rw-r--r-- | networking/udhcp/leases.c | 20 | ||||
-rw-r--r-- | networking/udhcp/options.c | 96 | ||||
-rw-r--r-- | networking/udhcp/options.h | 123 | ||||
-rw-r--r-- | networking/udhcp/script.c | 4 | ||||
-rw-r--r-- | networking/udhcp/serverpacket.c | 9 |
8 files changed, 149 insertions, 124 deletions
diff --git a/networking/udhcp/dhcpd.h b/networking/udhcp/dhcpd.h index 02e392aaf..b4e180882 100644 --- a/networking/udhcp/dhcpd.h +++ b/networking/udhcp/dhcpd.h | |||
@@ -74,8 +74,6 @@ struct server_config_t { | |||
74 | #define SERVER_PORT 67 | 74 | #define SERVER_PORT 67 |
75 | #endif | 75 | #endif |
76 | 76 | ||
77 | extern struct dhcpOfferedAddr *leases; | ||
78 | |||
79 | 77 | ||
80 | /*** leases.h ***/ | 78 | /*** leases.h ***/ |
81 | 79 | ||
@@ -92,9 +90,15 @@ struct dhcpOfferedAddr { | |||
92 | * and optionally adjusted (current time subtracted) | 90 | * and optionally adjusted (current time subtracted) |
93 | * if server_config.remaining = 1 */ | 91 | * if server_config.remaining = 1 */ |
94 | leasetime_t expires; | 92 | leasetime_t expires; |
93 | uint8_t hostname[20]; /* (size is a multiply of 4) */ | ||
95 | }; | 94 | }; |
96 | 95 | ||
97 | struct dhcpOfferedAddr *add_lease(const uint8_t *chaddr, uint32_t yiaddr, leasetime_t leasetime) FAST_FUNC; | 96 | extern struct dhcpOfferedAddr *leases; |
97 | |||
98 | struct dhcpOfferedAddr *add_lease( | ||
99 | const uint8_t *chaddr, uint32_t yiaddr, | ||
100 | leasetime_t leasetime, uint8_t *hostname | ||
101 | ) FAST_FUNC; | ||
98 | int lease_expired(struct dhcpOfferedAddr *lease) FAST_FUNC; | 102 | int lease_expired(struct dhcpOfferedAddr *lease) FAST_FUNC; |
99 | struct dhcpOfferedAddr *find_lease_by_chaddr(const uint8_t *chaddr) FAST_FUNC; | 103 | struct dhcpOfferedAddr *find_lease_by_chaddr(const uint8_t *chaddr) FAST_FUNC; |
100 | struct dhcpOfferedAddr *find_lease_by_yiaddr(uint32_t yiaddr) FAST_FUNC; | 104 | struct dhcpOfferedAddr *find_lease_by_yiaddr(uint32_t yiaddr) FAST_FUNC; |
diff --git a/networking/udhcp/dumpleases.c b/networking/udhcp/dumpleases.c index c0d515d28..1558f8848 100644 --- a/networking/udhcp/dumpleases.c +++ b/networking/udhcp/dumpleases.c | |||
@@ -47,8 +47,9 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv) | |||
47 | 47 | ||
48 | fd = xopen(file, O_RDONLY); | 48 | fd = xopen(file, O_RDONLY); |
49 | 49 | ||
50 | printf("Mac Address IP-Address Expires %s\n", (opt & OPT_a) ? "at" : "in"); | 50 | printf("Mac Address IP Address Host Name Expires %s\n", (opt & OPT_a) ? "at" : "in"); |
51 | /* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */ | 51 | /* "00:00:00:00:00:00 255.255.255.255 ABCDEFGHIJKLMNOPQRS Wed Jun 30 21:49:08 1993" */ |
52 | /* "123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 */ | ||
52 | 53 | ||
53 | if (full_read(fd, &written_at, sizeof(written_at)) != sizeof(written_at)) | 54 | if (full_read(fd, &written_at, sizeof(written_at)) != sizeof(written_at)) |
54 | return 0; | 55 | return 0; |
@@ -64,7 +65,9 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv) | |||
64 | fmt = ":%02x"; | 65 | fmt = ":%02x"; |
65 | } | 66 | } |
66 | addr.s_addr = lease.yiaddr; | 67 | addr.s_addr = lease.yiaddr; |
67 | printf(" %-15s ", inet_ntoa(addr)); | 68 | /* actually, 15+1 and 19+1, +1 is a space between columns */ |
69 | /* lease.hostname is char[20] and is always NUL terminated */ | ||
70 | printf(" %-16s%-20s", inet_ntoa(addr), lease.hostname); | ||
68 | expires_abs = ntohl(lease.expires) + written_at; | 71 | expires_abs = ntohl(lease.expires) + written_at; |
69 | if (expires_abs <= curr) { | 72 | if (expires_abs <= curr) { |
70 | puts("expired"); | 73 | puts("expired"); |
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c index fb6fe01ae..a061a9c9b 100644 --- a/networking/udhcp/files.c +++ b/networking/udhcp/files.c | |||
@@ -420,7 +420,7 @@ void FAST_FUNC read_leases(const char *file) | |||
420 | continue; | 420 | continue; |
421 | /* NB: add_lease takes "relative time", IOW, | 421 | /* NB: add_lease takes "relative time", IOW, |
422 | * lease duration, not lease deadline. */ | 422 | * lease duration, not lease deadline. */ |
423 | if (!(add_lease(lease.chaddr, lease.yiaddr, expires))) { | 423 | if (!(add_lease(lease.chaddr, lease.yiaddr, expires, lease.hostname))) { |
424 | bb_error_msg("too many leases while loading %s", file); | 424 | bb_error_msg("too many leases while loading %s", file); |
425 | break; | 425 | break; |
426 | } | 426 | } |
diff --git a/networking/udhcp/leases.c b/networking/udhcp/leases.c index 3044c2040..d62f32471 100644 --- a/networking/udhcp/leases.c +++ b/networking/udhcp/leases.c | |||
@@ -48,9 +48,12 @@ static void clear_lease(const uint8_t *chaddr, uint32_t yiaddr) | |||
48 | 48 | ||
49 | 49 | ||
50 | /* Add a lease into the table, clearing out any old ones */ | 50 | /* Add a lease into the table, clearing out any old ones */ |
51 | struct dhcpOfferedAddr* FAST_FUNC add_lease(const uint8_t *chaddr, uint32_t yiaddr, leasetime_t leasetime) | 51 | struct dhcpOfferedAddr* FAST_FUNC add_lease( |
52 | const uint8_t *chaddr, uint32_t yiaddr, | ||
53 | leasetime_t leasetime, uint8_t *hostname) | ||
52 | { | 54 | { |
53 | struct dhcpOfferedAddr *oldest; | 55 | struct dhcpOfferedAddr *oldest; |
56 | uint8_t hostname_length; | ||
54 | 57 | ||
55 | /* clean out any old ones */ | 58 | /* clean out any old ones */ |
56 | clear_lease(chaddr, yiaddr); | 59 | clear_lease(chaddr, yiaddr); |
@@ -58,6 +61,19 @@ struct dhcpOfferedAddr* FAST_FUNC add_lease(const uint8_t *chaddr, uint32_t yiad | |||
58 | oldest = oldest_expired_lease(); | 61 | oldest = oldest_expired_lease(); |
59 | 62 | ||
60 | if (oldest) { | 63 | if (oldest) { |
64 | oldest->hostname[0] = '\0'; | ||
65 | if (hostname) { | ||
66 | hostname_length = hostname[-1]; /* look at option size byte */ | ||
67 | if (hostname_length > sizeof(oldest->hostname)) | ||
68 | hostname_length = sizeof(oldest->hostname); | ||
69 | hostname = (uint8_t*) safe_strncpy((char*)oldest->hostname, (char*)hostname, hostname_length); | ||
70 | /* sanitization (s/non-ACSII/^/g) */ | ||
71 | while (*hostname) { | ||
72 | if (*hostname < ' ' || *hostname > 126) | ||
73 | *hostname = '^'; | ||
74 | hostname++; | ||
75 | } | ||
76 | } | ||
61 | memcpy(oldest->chaddr, chaddr, 16); | 77 | memcpy(oldest->chaddr, chaddr, 16); |
62 | oldest->yiaddr = yiaddr; | 78 | oldest->yiaddr = yiaddr; |
63 | oldest->expires = time(NULL) + leasetime; | 79 | oldest->expires = time(NULL) + leasetime; |
@@ -117,7 +133,7 @@ static int nobody_responds_to_arp(uint32_t addr) | |||
117 | temp.s_addr = addr; | 133 | temp.s_addr = addr; |
118 | bb_info_msg("%s belongs to someone, reserving it for %u seconds", | 134 | bb_info_msg("%s belongs to someone, reserving it for %u seconds", |
119 | inet_ntoa(temp), (unsigned)server_config.conflict_time); | 135 | inet_ntoa(temp), (unsigned)server_config.conflict_time); |
120 | add_lease(blank_chaddr, addr, server_config.conflict_time); | 136 | add_lease(blank_chaddr, addr, server_config.conflict_time, NULL); |
121 | return 0; | 137 | return 0; |
122 | } | 138 | } |
123 | 139 | ||
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c index 581a7b671..143a1fd1c 100644 --- a/networking/udhcp/options.c +++ b/networking/udhcp/options.c | |||
@@ -119,58 +119,61 @@ const uint8_t dhcp_option_lengths[] ALIGN1 = { | |||
119 | }; | 119 | }; |
120 | 120 | ||
121 | 121 | ||
122 | /* get an option with bounds checking (warning, not aligned). */ | 122 | /* get an option with bounds checking (warning, result is not aligned). */ |
123 | uint8_t* FAST_FUNC get_option(struct dhcpMessage *packet, int code) | 123 | uint8_t* FAST_FUNC get_option(struct dhcpMessage *packet, int code) |
124 | { | 124 | { |
125 | int i, length; | ||
126 | uint8_t *optionptr; | 125 | uint8_t *optionptr; |
127 | int over = 0; | 126 | int len; |
128 | int curr = OPTION_FIELD; | 127 | int rem; |
129 | 128 | int overload = 0; | |
129 | enum { | ||
130 | FILE_FIELD101 = FILE_FIELD * 0x101, | ||
131 | SNAME_FIELD101 = SNAME_FIELD * 0x101, | ||
132 | }; | ||
133 | |||
134 | /* option bytes: [code][len][data1][data2]..[dataLEN] */ | ||
130 | optionptr = packet->options; | 135 | optionptr = packet->options; |
131 | i = 0; | 136 | rem = sizeof(packet->options); |
132 | length = sizeof(packet->options); | ||
133 | while (1) { | 137 | while (1) { |
134 | if (i >= length) { | 138 | if (rem <= 0) { |
135 | bb_error_msg("bogus packet, option fields too long"); | 139 | bb_error_msg("bogus packet, malformed option field"); |
136 | return NULL; | 140 | return NULL; |
137 | } | 141 | } |
138 | if (optionptr[i + OPT_CODE] == code) { | 142 | if (optionptr[OPT_CODE] == DHCP_PADDING) { |
139 | if (i + 1 + optionptr[i + OPT_LEN] >= length) { | 143 | rem--; |
140 | bb_error_msg("bogus packet, option fields too long"); | 144 | optionptr++; |
141 | return NULL; | 145 | continue; |
142 | } | ||
143 | return optionptr + i + 2; | ||
144 | } | 146 | } |
145 | switch (optionptr[i + OPT_CODE]) { | 147 | if (optionptr[OPT_CODE] == DHCP_END) { |
146 | case DHCP_PADDING: | 148 | if ((overload & FILE_FIELD101) == FILE_FIELD) { |
147 | i++; | 149 | /* can use packet->file, and didn't look at it yet */ |
148 | break; | 150 | overload |= FILE_FIELD101; /* "we looked at it" */ |
149 | case DHCP_OPTION_OVER: | ||
150 | if (i + 1 + optionptr[i + OPT_LEN] >= length) { | ||
151 | bb_error_msg("bogus packet, option fields too long"); | ||
152 | return NULL; | ||
153 | } | ||
154 | over = optionptr[i + 3]; | ||
155 | i += optionptr[OPT_LEN] + 2; | ||
156 | break; | ||
157 | case DHCP_END: | ||
158 | if (curr == OPTION_FIELD && (over & FILE_FIELD)) { | ||
159 | optionptr = packet->file; | 151 | optionptr = packet->file; |
160 | i = 0; | 152 | rem = sizeof(packet->file); |
161 | length = sizeof(packet->file); | 153 | continue; |
162 | curr = FILE_FIELD; | 154 | } |
163 | } else if (curr == FILE_FIELD && (over & SNAME_FIELD)) { | 155 | if ((overload & SNAME_FIELD101) == SNAME_FIELD) { |
156 | /* can use packet->sname, and didn't look at it yet */ | ||
157 | overload |= SNAME_FIELD101; /* "we looked at it" */ | ||
164 | optionptr = packet->sname; | 158 | optionptr = packet->sname; |
165 | i = 0; | 159 | rem = sizeof(packet->sname); |
166 | length = sizeof(packet->sname); | 160 | continue; |
167 | curr = SNAME_FIELD; | 161 | } |
168 | } else | 162 | return NULL; |
169 | return NULL; | 163 | } |
170 | break; | 164 | len = 2 + optionptr[OPT_LEN]; |
171 | default: | 165 | rem -= len; |
172 | i += optionptr[OPT_LEN + i] + 2; | 166 | if (rem < 0) |
167 | continue; /* complain and return NULL */ | ||
168 | |||
169 | if (optionptr[OPT_CODE] == code) | ||
170 | return optionptr + OPT_DATA; | ||
171 | |||
172 | if (optionptr[OPT_CODE] == DHCP_OPTION_OVERLOAD) { | ||
173 | overload |= optionptr[OPT_DATA]; | ||
174 | /* fall through */ | ||
173 | } | 175 | } |
176 | optionptr += len; | ||
174 | } | 177 | } |
175 | return NULL; | 178 | return NULL; |
176 | } | 179 | } |
@@ -182,17 +185,16 @@ int FAST_FUNC end_option(uint8_t *optionptr) | |||
182 | int i = 0; | 185 | int i = 0; |
183 | 186 | ||
184 | while (optionptr[i] != DHCP_END) { | 187 | while (optionptr[i] != DHCP_END) { |
185 | if (optionptr[i] == DHCP_PADDING) | 188 | if (optionptr[i] != DHCP_PADDING) |
186 | i++; | 189 | i += optionptr[i + OPT_LEN] + 1; |
187 | else | 190 | i++; |
188 | i += optionptr[i + OPT_LEN] + 2; | ||
189 | } | 191 | } |
190 | return i; | 192 | return i; |
191 | } | 193 | } |
192 | 194 | ||
193 | 195 | ||
194 | /* add an option string to the options (an option string contains an option code, | 196 | /* add an option string to the options */ |
195 | * length, then data) */ | 197 | /* option bytes: [code][len][data1][data2]..[dataLEN] */ |
196 | int FAST_FUNC add_option_string(uint8_t *optionptr, uint8_t *string) | 198 | int FAST_FUNC add_option_string(uint8_t *optionptr, uint8_t *string) |
197 | { | 199 | { |
198 | int end = end_option(optionptr); | 200 | int end = end_option(optionptr); |
diff --git a/networking/udhcp/options.h b/networking/udhcp/options.h index d18a353d0..87440c30c 100644 --- a/networking/udhcp/options.h +++ b/networking/udhcp/options.h | |||
@@ -7,7 +7,7 @@ | |||
7 | # pragma GCC visibility push(hidden) | 7 | # pragma GCC visibility push(hidden) |
8 | #endif | 8 | #endif |
9 | 9 | ||
10 | #define TYPE_MASK 0x0F | 10 | #define TYPE_MASK 0x0F |
11 | 11 | ||
12 | enum { | 12 | enum { |
13 | OPTION_IP = 1, | 13 | OPTION_IP = 1, |
@@ -24,8 +24,8 @@ enum { | |||
24 | OPTION_S32 | 24 | OPTION_S32 |
25 | }; | 25 | }; |
26 | 26 | ||
27 | #define OPTION_REQ 0x10 /* have the client request this option */ | 27 | #define OPTION_REQ 0x10 /* have the client request this option */ |
28 | #define OPTION_LIST 0x20 /* There can be a list of 1 or more of these */ | 28 | #define OPTION_LIST 0x20 /* There can be a list of 1 or more of these */ |
29 | 29 | ||
30 | /*****************************************************************/ | 30 | /*****************************************************************/ |
31 | /* Do not modify below here unless you know what you are doing!! */ | 31 | /* Do not modify below here unless you know what you are doing!! */ |
@@ -34,67 +34,64 @@ enum { | |||
34 | /* DHCP protocol -- see RFC 2131 */ | 34 | /* DHCP protocol -- see RFC 2131 */ |
35 | #define DHCP_MAGIC 0x63825363 | 35 | #define DHCP_MAGIC 0x63825363 |
36 | 36 | ||
37 | |||
38 | /* DHCP option codes (partial list) */ | 37 | /* DHCP option codes (partial list) */ |
39 | #define DHCP_PADDING 0x00 | 38 | #define DHCP_PADDING 0x00 |
40 | #define DHCP_SUBNET 0x01 | 39 | #define DHCP_SUBNET 0x01 |
41 | #define DHCP_TIME_OFFSET 0x02 | 40 | #define DHCP_TIME_OFFSET 0x02 |
42 | #define DHCP_ROUTER 0x03 | 41 | #define DHCP_ROUTER 0x03 |
43 | #define DHCP_TIME_SERVER 0x04 | 42 | #define DHCP_TIME_SERVER 0x04 |
44 | #define DHCP_NAME_SERVER 0x05 | 43 | #define DHCP_NAME_SERVER 0x05 |
45 | #define DHCP_DNS_SERVER 0x06 | 44 | #define DHCP_DNS_SERVER 0x06 |
46 | #define DHCP_LOG_SERVER 0x07 | 45 | #define DHCP_LOG_SERVER 0x07 |
47 | #define DHCP_COOKIE_SERVER 0x08 | 46 | #define DHCP_COOKIE_SERVER 0x08 |
48 | #define DHCP_LPR_SERVER 0x09 | 47 | #define DHCP_LPR_SERVER 0x09 |
49 | #define DHCP_HOST_NAME 0x0c | 48 | #define DHCP_HOST_NAME 0x0c |
50 | #define DHCP_BOOT_SIZE 0x0d | 49 | #define DHCP_BOOT_SIZE 0x0d |
51 | #define DHCP_DOMAIN_NAME 0x0f | 50 | #define DHCP_DOMAIN_NAME 0x0f |
52 | #define DHCP_SWAP_SERVER 0x10 | 51 | #define DHCP_SWAP_SERVER 0x10 |
53 | #define DHCP_ROOT_PATH 0x11 | 52 | #define DHCP_ROOT_PATH 0x11 |
54 | #define DHCP_IP_TTL 0x17 | 53 | #define DHCP_IP_TTL 0x17 |
55 | #define DHCP_MTU 0x1a | 54 | #define DHCP_MTU 0x1a |
56 | #define DHCP_BROADCAST 0x1c | 55 | #define DHCP_BROADCAST 0x1c |
57 | #define DHCP_NTP_SERVER 0x2a | 56 | #define DHCP_NTP_SERVER 0x2a |
58 | #define DHCP_WINS_SERVER 0x2c | 57 | #define DHCP_WINS_SERVER 0x2c |
59 | #define DHCP_REQUESTED_IP 0x32 | 58 | #define DHCP_REQUESTED_IP 0x32 |
60 | #define DHCP_LEASE_TIME 0x33 | 59 | #define DHCP_LEASE_TIME 0x33 |
61 | #define DHCP_OPTION_OVER 0x34 | 60 | #define DHCP_OPTION_OVERLOAD 0x34 |
62 | #define DHCP_MESSAGE_TYPE 0x35 | 61 | #define DHCP_MESSAGE_TYPE 0x35 |
63 | #define DHCP_SERVER_ID 0x36 | 62 | #define DHCP_SERVER_ID 0x36 |
64 | #define DHCP_PARAM_REQ 0x37 | 63 | #define DHCP_PARAM_REQ 0x37 |
65 | #define DHCP_MESSAGE 0x38 | 64 | #define DHCP_MESSAGE 0x38 |
66 | #define DHCP_MAX_SIZE 0x39 | 65 | #define DHCP_MAX_SIZE 0x39 |
67 | #define DHCP_T1 0x3a | 66 | #define DHCP_T1 0x3a |
68 | #define DHCP_T2 0x3b | 67 | #define DHCP_T2 0x3b |
69 | #define DHCP_VENDOR 0x3c | 68 | #define DHCP_VENDOR 0x3c |
70 | #define DHCP_CLIENT_ID 0x3d | 69 | #define DHCP_CLIENT_ID 0x3d |
71 | #define DHCP_FQDN 0x51 | 70 | #define DHCP_FQDN 0x51 |
72 | #define DHCP_END 0xFF | 71 | #define DHCP_END 0xFF |
73 | 72 | /* Offsets in option byte sequence */ | |
74 | 73 | #define OPT_CODE 0 | |
75 | #define BOOTREQUEST 1 | 74 | #define OPT_LEN 1 |
76 | #define BOOTREPLY 2 | 75 | #define OPT_DATA 2 |
77 | 76 | /* Bits in "overload" option */ | |
78 | #define ETH_10MB 1 | 77 | #define OPTION_FIELD 0 |
79 | #define ETH_10MB_LEN 6 | 78 | #define FILE_FIELD 1 |
80 | 79 | #define SNAME_FIELD 2 | |
81 | #define DHCPDISCOVER 1 /* client -> server */ | 80 | |
82 | #define DHCPOFFER 2 /* client <- server */ | 81 | #define BOOTREQUEST 1 |
83 | #define DHCPREQUEST 3 /* client -> server */ | 82 | #define BOOTREPLY 2 |
84 | #define DHCPDECLINE 4 /* client -> server */ | 83 | |
85 | #define DHCPACK 5 /* client <- server */ | 84 | #define ETH_10MB 1 |
86 | #define DHCPNAK 6 /* client <- server */ | 85 | #define ETH_10MB_LEN 6 |
87 | #define DHCPRELEASE 7 /* client -> server */ | 86 | |
88 | #define DHCPINFORM 8 /* client -> server */ | 87 | #define DHCPDISCOVER 1 /* client -> server */ |
89 | 88 | #define DHCPOFFER 2 /* client <- server */ | |
90 | #define OPTION_FIELD 0 | 89 | #define DHCPREQUEST 3 /* client -> server */ |
91 | #define FILE_FIELD 1 | 90 | #define DHCPDECLINE 4 /* client -> server */ |
92 | #define SNAME_FIELD 2 | 91 | #define DHCPACK 5 /* client <- server */ |
93 | 92 | #define DHCPNAK 6 /* client <- server */ | |
94 | /* miscellaneous defines */ | 93 | #define DHCPRELEASE 7 /* client -> server */ |
95 | #define OPT_CODE 0 | 94 | #define DHCPINFORM 8 /* client -> server */ |
96 | #define OPT_LEN 1 | ||
97 | #define OPT_DATA 2 | ||
98 | 95 | ||
99 | struct dhcp_option { | 96 | struct dhcp_option { |
100 | uint8_t flags; | 97 | uint8_t flags; |
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c index 5d42a45db..3029b1367 100644 --- a/networking/udhcp/script.c +++ b/networking/udhcp/script.c | |||
@@ -135,7 +135,7 @@ static char **fill_envp(struct dhcpMessage *packet) | |||
135 | char **envp, **curr; | 135 | char **envp, **curr; |
136 | const char *opt_name; | 136 | const char *opt_name; |
137 | uint8_t *temp; | 137 | uint8_t *temp; |
138 | char over = 0; | 138 | uint8_t over = 0; |
139 | 139 | ||
140 | if (packet) { | 140 | if (packet) { |
141 | for (i = 0; dhcp_options[i].code; i++) { | 141 | for (i = 0; dhcp_options[i].code; i++) { |
@@ -147,7 +147,7 @@ static char **fill_envp(struct dhcpMessage *packet) | |||
147 | } | 147 | } |
148 | if (packet->siaddr) | 148 | if (packet->siaddr) |
149 | num_options++; | 149 | num_options++; |
150 | temp = get_option(packet, DHCP_OPTION_OVER); | 150 | temp = get_option(packet, DHCP_OPTION_OVERLOAD); |
151 | if (temp) | 151 | if (temp) |
152 | over = *temp; | 152 | over = *temp; |
153 | if (!(over & FILE_FIELD) && packet->file[0]) | 153 | if (!(over & FILE_FIELD) && packet->file[0]) |
diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c index afc0fb40d..8b0f1856b 100644 --- a/networking/udhcp/serverpacket.c +++ b/networking/udhcp/serverpacket.c | |||
@@ -105,7 +105,7 @@ int FAST_FUNC send_offer(struct dhcpMessage *oldpacket) | |||
105 | uint32_t req_align; | 105 | uint32_t req_align; |
106 | uint32_t lease_time_aligned = server_config.lease; | 106 | uint32_t lease_time_aligned = server_config.lease; |
107 | uint32_t static_lease_ip; | 107 | uint32_t static_lease_ip; |
108 | uint8_t *req, *lease_time; | 108 | uint8_t *req, *lease_time, *p_host_name; |
109 | struct option_set *curr; | 109 | struct option_set *curr; |
110 | struct in_addr addr; | 110 | struct in_addr addr; |
111 | 111 | ||
@@ -146,7 +146,8 @@ int FAST_FUNC send_offer(struct dhcpMessage *oldpacket) | |||
146 | bb_error_msg("no IP addresses to give - OFFER abandoned"); | 146 | bb_error_msg("no IP addresses to give - OFFER abandoned"); |
147 | return -1; | 147 | return -1; |
148 | } | 148 | } |
149 | if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) { | 149 | p_host_name = get_option(oldpacket, DHCP_HOST_NAME); |
150 | if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time, p_host_name)) { | ||
150 | bb_error_msg("lease pool is full - OFFER abandoned"); | 151 | bb_error_msg("lease pool is full - OFFER abandoned"); |
151 | return -1; | 152 | return -1; |
152 | } | 153 | } |
@@ -201,6 +202,7 @@ int FAST_FUNC send_ACK(struct dhcpMessage *oldpacket, uint32_t yiaddr) | |||
201 | uint8_t *lease_time; | 202 | uint8_t *lease_time; |
202 | uint32_t lease_time_aligned = server_config.lease; | 203 | uint32_t lease_time_aligned = server_config.lease; |
203 | struct in_addr addr; | 204 | struct in_addr addr; |
205 | uint8_t *p_host_name; | ||
204 | 206 | ||
205 | init_packet(&packet, oldpacket, DHCPACK); | 207 | init_packet(&packet, oldpacket, DHCPACK); |
206 | packet.yiaddr = yiaddr; | 208 | packet.yiaddr = yiaddr; |
@@ -232,7 +234,8 @@ int FAST_FUNC send_ACK(struct dhcpMessage *oldpacket, uint32_t yiaddr) | |||
232 | if (send_packet(&packet, 0) < 0) | 234 | if (send_packet(&packet, 0) < 0) |
233 | return -1; | 235 | return -1; |
234 | 236 | ||
235 | add_lease(packet.chaddr, packet.yiaddr, lease_time_aligned); | 237 | p_host_name = get_option(oldpacket, DHCP_HOST_NAME); |
238 | add_lease(packet.chaddr, packet.yiaddr, lease_time_aligned, p_host_name); | ||
236 | if (ENABLE_FEATURE_UDHCPD_WRITE_LEASES_EARLY) { | 239 | if (ENABLE_FEATURE_UDHCPD_WRITE_LEASES_EARLY) { |
237 | /* rewrite the file with leases at every new acceptance */ | 240 | /* rewrite the file with leases at every new acceptance */ |
238 | write_leases(); | 241 | write_leases(); |