diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-03 12:29:53 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-03 12:29:53 +0000 |
commit | af906a3b6ca6e2ae098ed2b3beb34db351d2eae8 (patch) | |
tree | a6f7000d518d0ded7cd63b34a6f3e0145cb89828 /networking/zcip.c | |
parent | a9abecd85e5e6a9e1623d7edffd154e717f8a6d7 (diff) | |
download | busybox-w32-af906a3b6ca6e2ae098ed2b3beb34db351d2eae8.tar.gz busybox-w32-af906a3b6ca6e2ae098ed2b3beb34db351d2eae8.tar.bz2 busybox-w32-af906a3b6ca6e2ae098ed2b3beb34db351d2eae8.zip |
zcip: minor fixes
Diffstat (limited to 'networking/zcip.c')
-rw-r--r-- | networking/zcip.c | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/networking/zcip.c b/networking/zcip.c index 330ec7af4..a7f19d5db 100644 --- a/networking/zcip.c +++ b/networking/zcip.c | |||
@@ -72,9 +72,8 @@ enum { | |||
72 | DEFEND | 72 | DEFEND |
73 | }; | 73 | }; |
74 | 74 | ||
75 | #define DBG(fmt,args...) \ | 75 | #define VDBG(fmt,args...) \ |
76 | do { } while (0) | 76 | do { } while (0) |
77 | #define VDBG DBG | ||
78 | 77 | ||
79 | static unsigned long opts; | 78 | static unsigned long opts; |
80 | #define FOREGROUND (opts & 1) | 79 | #define FOREGROUND (opts & 1) |
@@ -86,7 +85,7 @@ static unsigned long opts; | |||
86 | */ | 85 | */ |
87 | static void pick(struct in_addr *ip) | 86 | static void pick(struct in_addr *ip) |
88 | { | 87 | { |
89 | unsigned tmp; | 88 | unsigned tmp; |
90 | 89 | ||
91 | /* use cheaper math than lrand48() mod N */ | 90 | /* use cheaper math than lrand48() mod N */ |
92 | do { | 91 | do { |
@@ -95,10 +94,12 @@ static void pick(struct in_addr *ip) | |||
95 | ip->s_addr = htonl((LINKLOCAL_ADDR + 0x0100) + tmp); | 94 | ip->s_addr = htonl((LINKLOCAL_ADDR + 0x0100) + tmp); |
96 | } | 95 | } |
97 | 96 | ||
97 | /* TODO: we need a flag to direct bb_[p]error_msg output to stderr. */ | ||
98 | |||
98 | /** | 99 | /** |
99 | * Broadcast an ARP packet. | 100 | * Broadcast an ARP packet. |
100 | */ | 101 | */ |
101 | static int arp(int fd, struct sockaddr *saddr, int op, | 102 | static void arp(int fd, struct sockaddr *saddr, int op, |
102 | const struct ether_addr *source_addr, struct in_addr source_ip, | 103 | const struct ether_addr *source_addr, struct in_addr source_ip, |
103 | const struct ether_addr *target_addr, struct in_addr target_ip) | 104 | const struct ether_addr *target_addr, struct in_addr target_ip) |
104 | { | 105 | { |
@@ -127,14 +128,15 @@ static int arp(int fd, struct sockaddr *saddr, int op, | |||
127 | perror("sendto"); | 128 | perror("sendto"); |
128 | else | 129 | else |
129 | syslog(LOG_ERR, "sendto: %s", strerror(errno)); | 130 | syslog(LOG_ERR, "sendto: %s", strerror(errno)); |
130 | return -errno; | 131 | //return -errno; |
131 | } | 132 | } |
132 | return 0; | 133 | // Currently all callers ignore errors, that's why returns are |
134 | // commented out... | ||
135 | //return 0; | ||
133 | } | 136 | } |
134 | 137 | ||
135 | /** | 138 | /** |
136 | * Run a script. | 139 | * Run a script. |
137 | * TODO: we need a flag to direct bb_[p]error_msg output to stderr. | ||
138 | */ | 140 | */ |
139 | static int run(char *script, char *arg, char *intf, struct in_addr *ip) | 141 | static int run(char *script, char *arg, char *intf, struct in_addr *ip) |
140 | { | 142 | { |
@@ -233,22 +235,20 @@ int zcip_main(int argc, char *argv[]) | |||
233 | char *r_opt; | 235 | char *r_opt; |
234 | bb_opt_complementally = "vv"; // -v options accumulate | 236 | bb_opt_complementally = "vv"; // -v options accumulate |
235 | opts = bb_getopt_ulflags(argc, argv, "fqr:v", &r_opt, &verbose); | 237 | opts = bb_getopt_ulflags(argc, argv, "fqr:v", &r_opt, &verbose); |
236 | if (opts & 4) { | 238 | if (opts & 4) { // -r n.n.n.n |
237 | if (inet_aton(r_opt, &ip) == 0 | 239 | if (inet_aton(r_opt, &ip) == 0 |
238 | || (ntohl(ip.s_addr) & IN_CLASSB_NET) != LINKLOCAL_ADDR) { | 240 | || (ntohl(ip.s_addr) & IN_CLASSB_NET) != LINKLOCAL_ADDR) { |
239 | bb_error_msg_and_die("invalid link address"); | 241 | bb_error_msg_and_die("invalid link address"); |
240 | } | 242 | } |
241 | } | 243 | } |
242 | if (verbose) opts |= 1; | 244 | if (verbose) opts |= 1; // -v implies -f |
243 | argc -= optind; | 245 | argc -= optind; |
244 | argv += optind; | 246 | argv += optind; |
245 | if (argc != 2) | 247 | if (argc != 2) |
246 | bb_show_usage(); | 248 | bb_show_usage(); |
247 | |||
248 | intf = argv[0]; | 249 | intf = argv[0]; |
249 | script = argv[1]; | 250 | script = argv[1]; |
250 | setenv("interface", intf, 1); | 251 | setenv("interface", intf, 1); |
251 | openlog(bb_applet_name, 0, LOG_DAEMON); | ||
252 | 252 | ||
253 | // initialize the interface (modprobe, ifup, etc) | 253 | // initialize the interface (modprobe, ifup, etc) |
254 | if (run(script, "init", intf, NULL) < 0) | 254 | if (run(script, "init", intf, NULL) < 0) |
@@ -287,6 +287,7 @@ int zcip_main(int argc, char *argv[]) | |||
287 | // daemonize now; don't delay system startup | 287 | // daemonize now; don't delay system startup |
288 | if (!FOREGROUND) { | 288 | if (!FOREGROUND) { |
289 | xdaemon(0, verbose); | 289 | xdaemon(0, verbose); |
290 | openlog(bb_applet_name, 0, LOG_DAEMON); | ||
290 | syslog(LOG_INFO, "start, interface %s", intf); | 291 | syslog(LOG_INFO, "start, interface %s", intf); |
291 | } | 292 | } |
292 | 293 | ||
@@ -335,13 +336,13 @@ int zcip_main(int argc, char *argv[]) | |||
335 | VDBG("state = %d\n", state); | 336 | VDBG("state = %d\n", state); |
336 | switch (state) { | 337 | switch (state) { |
337 | case PROBE: | 338 | case PROBE: |
338 | // timeouts in the PROBE state means no conflicting ARP packets | 339 | // timeouts in the PROBE state mean no conflicting ARP packets |
339 | // have been received, so we can progress through the states | 340 | // have been received, so we can progress through the states |
340 | if (nprobes < PROBE_NUM) { | 341 | if (nprobes < PROBE_NUM) { |
341 | nprobes++; | 342 | nprobes++; |
342 | VDBG("probe/%d %s@%s\n", | 343 | VDBG("probe/%d %s@%s\n", |
343 | nprobes, intf, inet_ntoa(ip)); | 344 | nprobes, intf, inet_ntoa(ip)); |
344 | (void)arp(fd, &saddr, ARPOP_REQUEST, | 345 | arp(fd, &saddr, ARPOP_REQUEST, |
345 | ð_addr, null_ip, | 346 | ð_addr, null_ip, |
346 | &null_addr, ip); | 347 | &null_addr, ip); |
347 | timeout = PROBE_MIN * 1000; | 348 | timeout = PROBE_MIN * 1000; |
@@ -354,32 +355,32 @@ int zcip_main(int argc, char *argv[]) | |||
354 | nclaims = 0; | 355 | nclaims = 0; |
355 | VDBG("announce/%d %s@%s\n", | 356 | VDBG("announce/%d %s@%s\n", |
356 | nclaims, intf, inet_ntoa(ip)); | 357 | nclaims, intf, inet_ntoa(ip)); |
357 | (void)arp(fd, &saddr, ARPOP_REQUEST, | 358 | arp(fd, &saddr, ARPOP_REQUEST, |
358 | ð_addr, ip, | 359 | ð_addr, ip, |
359 | ð_addr, ip); | 360 | ð_addr, ip); |
360 | timeout = ANNOUNCE_INTERVAL * 1000; | 361 | timeout = ANNOUNCE_INTERVAL * 1000; |
361 | } | 362 | } |
362 | break; | 363 | break; |
363 | case RATE_LIMIT_PROBE: | 364 | case RATE_LIMIT_PROBE: |
364 | // timeouts in the RATE_LIMIT_PROBE state means no conflicting ARP packets | 365 | // timeouts in the RATE_LIMIT_PROBE state mean no conflicting ARP packets |
365 | // have been received, so we can move immediately to the announce state | 366 | // have been received, so we can move immediately to the announce state |
366 | state = ANNOUNCE; | 367 | state = ANNOUNCE; |
367 | nclaims = 0; | 368 | nclaims = 0; |
368 | VDBG("announce/%d %s@%s\n", | 369 | VDBG("announce/%d %s@%s\n", |
369 | nclaims, intf, inet_ntoa(ip)); | 370 | nclaims, intf, inet_ntoa(ip)); |
370 | (void)arp(fd, &saddr, ARPOP_REQUEST, | 371 | arp(fd, &saddr, ARPOP_REQUEST, |
371 | ð_addr, ip, | 372 | ð_addr, ip, |
372 | ð_addr, ip); | 373 | ð_addr, ip); |
373 | timeout = ANNOUNCE_INTERVAL * 1000; | 374 | timeout = ANNOUNCE_INTERVAL * 1000; |
374 | break; | 375 | break; |
375 | case ANNOUNCE: | 376 | case ANNOUNCE: |
376 | // timeouts in the ANNOUNCE state means no conflicting ARP packets | 377 | // timeouts in the ANNOUNCE state mean no conflicting ARP packets |
377 | // have been received, so we can progress through the states | 378 | // have been received, so we can progress through the states |
378 | if (nclaims < ANNOUNCE_NUM) { | 379 | if (nclaims < ANNOUNCE_NUM) { |
379 | nclaims++; | 380 | nclaims++; |
380 | VDBG("announce/%d %s@%s\n", | 381 | VDBG("announce/%d %s@%s\n", |
381 | nclaims, intf, inet_ntoa(ip)); | 382 | nclaims, intf, inet_ntoa(ip)); |
382 | (void)arp(fd, &saddr, ARPOP_REQUEST, | 383 | arp(fd, &saddr, ARPOP_REQUEST, |
383 | ð_addr, ip, | 384 | ð_addr, ip, |
384 | ð_addr, ip); | 385 | ð_addr, ip); |
385 | timeout = ANNOUNCE_INTERVAL * 1000; | 386 | timeout = ANNOUNCE_INTERVAL * 1000; |
@@ -394,7 +395,7 @@ int zcip_main(int argc, char *argv[]) | |||
394 | conflicts = 0; | 395 | conflicts = 0; |
395 | timeout = -1; // Never timeout in the monitor state. | 396 | timeout = -1; // Never timeout in the monitor state. |
396 | 397 | ||
397 | // NOTE: all other exit paths | 398 | // NOTE: all other exit paths |
398 | // should deconfig ... | 399 | // should deconfig ... |
399 | if (QUIT) | 400 | if (QUIT) |
400 | return EXIT_SUCCESS; | 401 | return EXIT_SUCCESS; |
@@ -518,7 +519,7 @@ int zcip_main(int argc, char *argv[]) | |||
518 | VDBG("monitor conflict -- defending\n"); | 519 | VDBG("monitor conflict -- defending\n"); |
519 | state = DEFEND; | 520 | state = DEFEND; |
520 | timeout = DEFEND_INTERVAL * 1000; | 521 | timeout = DEFEND_INTERVAL * 1000; |
521 | (void)arp(fd, &saddr, | 522 | arp(fd, &saddr, |
522 | ARPOP_REQUEST, | 523 | ARPOP_REQUEST, |
523 | ð_addr, ip, | 524 | ð_addr, ip, |
524 | ð_addr, ip); | 525 | ð_addr, ip); |