aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/dhcpd.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-06-17 11:54:52 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-06-17 11:54:52 +0200
commitac906fa85e61b4e34161709de777616f858bc945 (patch)
tree7b247714814fd9dcf3fd3dccf954521b29eef5a2 /networking/udhcp/dhcpd.c
parented8982bfc0e9895fe707a5f6152cf184e06f2052 (diff)
downloadbusybox-w32-ac906fa85e61b4e34161709de777616f858bc945.tar.gz
busybox-w32-ac906fa85e61b4e34161709de777616f858bc945.tar.bz2
busybox-w32-ac906fa85e61b4e34161709de777616f858bc945.zip
udhcp: change UDHCP_DEBUG into int, make verbosity selectable with -v
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'networking/udhcp/dhcpd.c')
-rw-r--r--networking/udhcp/dhcpd.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index c74a11b31..cbc968401 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -44,7 +44,15 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
44 CLIENT_PORT = 68; 44 CLIENT_PORT = 68;
45#endif 45#endif
46 46
47 opt = getopt32(argv, "fS" IF_FEATURE_UDHCP_PORT("P:", &str_P)); 47#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
48 opt_complementary = "vv";
49#endif
50 opt = getopt32(argv, "fSv"
51 IF_FEATURE_UDHCP_PORT("P:", &str_P)
52#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
53 , &dhcp_verbose
54#endif
55 );
48 argv += optind; 56 argv += optind;
49 if (!(opt & 1)) { /* no -f */ 57 if (!(opt & 1)) { /* no -f */
50 bb_daemonize_or_rexec(0, argv); 58 bb_daemonize_or_rexec(0, argv);
@@ -131,7 +139,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
131 continue; 139 continue;
132 } 140 }
133 if (retval < 0 && errno != EINTR) { 141 if (retval < 0 && errno != EINTR) {
134 DEBUG("error on select"); 142 log1("Error on select");
135 continue; 143 continue;
136 } 144 }
137 145
@@ -155,7 +163,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
155 if (bytes < 0) { 163 if (bytes < 0) {
156 /* bytes can also be -2 ("bad packet data") */ 164 /* bytes can also be -2 ("bad packet data") */
157 if (bytes == -1 && errno != EINTR) { 165 if (bytes == -1 && errno != EINTR) {
158 DEBUG("error on read, %s, reopening socket", strerror(errno)); 166 log1("Read error: %s, reopening socket", strerror(errno));
159 close(server_socket); 167 close(server_socket);
160 server_socket = -1; 168 server_socket = -1;
161 } 169 }
@@ -164,7 +172,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
164 172
165 state = get_option(&packet, DHCP_MESSAGE_TYPE); 173 state = get_option(&packet, DHCP_MESSAGE_TYPE);
166 if (state == NULL) { 174 if (state == NULL) {
167 bb_error_msg("cannot get option from packet, ignoring"); 175 bb_error_msg("no message type option, ignoring packet");
168 continue; 176 continue;
169 } 177 }
170 178
@@ -184,14 +192,14 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
184 192
185 switch (state[0]) { 193 switch (state[0]) {
186 case DHCPDISCOVER: 194 case DHCPDISCOVER:
187 DEBUG("Received DISCOVER"); 195 log1("Received DISCOVER");
188 196
189 if (send_offer(&packet) < 0) { 197 if (send_offer(&packet) < 0) {
190 bb_error_msg("send OFFER failed"); 198 bb_error_msg("send OFFER failed");
191 } 199 }
192 break; 200 break;
193 case DHCPREQUEST: 201 case DHCPREQUEST:
194 DEBUG("received REQUEST"); 202 log1("Received REQUEST");
195 203
196 requested = get_option(&packet, DHCP_REQUESTED_IP); 204 requested = get_option(&packet, DHCP_REQUESTED_IP);
197 server_id = get_option(&packet, DHCP_SERVER_ID); 205 server_id = get_option(&packet, DHCP_SERVER_ID);
@@ -204,7 +212,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
204 if (lease) { 212 if (lease) {
205 if (server_id) { 213 if (server_id) {
206 /* SELECTING State */ 214 /* SELECTING State */
207 DEBUG("server_id = %08x", ntohl(server_id_aligned)); 215 log1("server_id = %08x", ntohl(server_id_aligned));
208 if (server_id_aligned == server_config.server_nip 216 if (server_id_aligned == server_config.server_nip
209 && requested 217 && requested
210 && requested_aligned == lease->lease_nip 218 && requested_aligned == lease->lease_nip
@@ -254,19 +262,19 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
254 } 262 }
255 break; 263 break;
256 case DHCPDECLINE: 264 case DHCPDECLINE:
257 DEBUG("Received DECLINE"); 265 log1("Received DECLINE");
258 if (lease) { 266 if (lease) {
259 memset(lease->lease_mac16, 0, 16); 267 memset(lease->lease_mac16, 0, 16);
260 lease->expires = time(NULL) + server_config.decline_time; 268 lease->expires = time(NULL) + server_config.decline_time;
261 } 269 }
262 break; 270 break;
263 case DHCPRELEASE: 271 case DHCPRELEASE:
264 DEBUG("Received RELEASE"); 272 log1("Received RELEASE");
265 if (lease) 273 if (lease)
266 lease->expires = time(NULL); 274 lease->expires = time(NULL);
267 break; 275 break;
268 case DHCPINFORM: 276 case DHCPINFORM:
269 DEBUG("Received INFORM"); 277 log1("Received INFORM");
270 send_inform(&packet); 278 send_inform(&packet);
271 break; 279 break;
272 default: 280 default: