sulogin: use bb_error_msg instead of bb_info_msg; better message
[oweals/busybox.git] / networking / zcip.c
index a167c7e9168aa72f9292c7bbc5fd52a4934f1d6e..c930826194a3644fe0f383d994ee7c81be10f582 100644 (file)
@@ -56,9 +56,6 @@ struct arp_packet {
 } PACKED;
 
 enum {
-       /* 169.254.0.0 */
-       LINKLOCAL_ADDR = 0xa9fe0000,
-
        /* 0-1 seconds before sending 1st probe */
        PROBE_WAIT = 1,
        /* 1-2 seconds between probes */
@@ -70,7 +67,7 @@ enum {
        /* if probe/announce sees a conflict, multiply RANDOM(NUM_CONFLICT) by... */
        CONFLICT_MULTIPLIER = 2,
        /* if we monitor and see a conflict, how long is defend state? */
-       DEFEND_INTERVAL = 10
+       DEFEND_INTERVAL = 10,
 };
 
 /* States during the configuration process. */
@@ -179,7 +176,7 @@ static int run(char *argv[3], const char *param, uint32_t nip)
                xsetenv("ip", addr);
                fmt -= 3;
        }
-       bb_info_msg(fmt, argv[2], argv[0], addr);
+       bb_error_msg(fmt, argv[2], argv[0], addr);
 
        status = spawn_and_wait(argv + 1);
        if (status < 0) {
@@ -196,7 +193,7 @@ static int run(char *argv[3], const char *param, uint32_t nip)
  */
 static ALWAYS_INLINE unsigned random_delay_ms(unsigned secs)
 {
-       return rand() % (secs * 1000);
+       return (unsigned)rand() % (secs * 1000);
 }
 
 /**
@@ -320,7 +317,7 @@ int zcip_main(int argc UNUSED_PARAM, char **argv)
 #if BB_MMU
                bb_daemonize(0 /*was: DAEMON_CHDIR_ROOT*/);
 #endif
-               bb_info_msg("start, interface %s", argv_intf);
+               bb_error_msg("start, interface %s", argv_intf);
        }
 
        // Run the dynamic address negotiation protocol,
@@ -328,9 +325,9 @@ int zcip_main(int argc UNUSED_PARAM, char **argv)
        //  - start with some address we want to try
        //  - short random delay
        //  - arp probes to see if another host uses it
-       //    00:04:e2:64:23:c2 > ff:ff:ff:ff:ff:ff: arp who-has 169.254.194.171 tell 0.0.0.0
+       //    00:04:e2:64:23:c2 > ff:ff:ff:ff:ff:ff arp who-has 169.254.194.171 tell 0.0.0.0
        //  - arp announcements that we're claiming it
-       //    00:04:e2:64:23:c2 > ff:ff:ff:ff:ff:ff: arp who-has 169.254.194.171 (00:04:e2:64:23:c2) tell 169.254.194.171
+       //    00:04:e2:64:23:c2 > ff:ff:ff:ff:ff:ff arp who-has 169.254.194.171 (00:04:e2:64:23:c2) tell 169.254.194.171
        //  - use it
        //  - defend it, within limits
        // exit if:
@@ -348,7 +345,7 @@ int zcip_main(int argc UNUSED_PARAM, char **argv)
        state = PROBE;
        while (1) {
                struct pollfd fds[1];
-               unsigned deadline_us;
+               unsigned deadline_us = deadline_us;
                struct arp_packet p;
                int ip_conflict;
                int n;
@@ -364,8 +361,10 @@ int zcip_main(int argc UNUSED_PARAM, char **argv)
                        // make the kernel filter out all packets except
                        // ones we'd care about.
                }
-               // Set deadline_us to the point in time when we timeout
-               deadline_us = MONOTONIC_US() + timeout_ms * 1000;
+               if (timeout_ms >= 0) {
+                       // Set deadline_us to the point in time when we timeout
+                       deadline_us = MONOTONIC_US() + timeout_ms * 1000;
+               }
 
                VDBG("...wait %d %s nsent=%u\n",
                                timeout_ms, argv_intf, nsent);
@@ -390,7 +389,7 @@ int zcip_main(int argc UNUSED_PARAM, char **argv)
                                        send_arp_request(0, &null_ethaddr, chosen_nip);
                                        continue;
                                }
-                               // Switch to announce state
+                               // Switch to announce state
                                nsent = 0;
                                state = ANNOUNCE;
                                goto send_announce;
@@ -412,7 +411,7 @@ int zcip_main(int argc UNUSED_PARAM, char **argv)
                                // NOTE: all other exit paths should deconfig...
                                if (QUIT)
                                        return EXIT_SUCCESS;
-                               // fall through: switch_to_MONITOR
+                               // fall through: switch to MONITOR
                        default:
                        // case DEFEND:
                        // case MONITOR: (shouldn't happen, MONITOR timeout is infinite)
@@ -520,7 +519,7 @@ int zcip_main(int argc UNUSED_PARAM, char **argv)
                }
                // Note: if we only have a target IP conflict here (ip_conflict & 2),
                // IOW: if we just saw this sort of ARP packet:
-               //  aa:bb:cc:dd:ee:ff > xx:xx:xx:xx:xx:xx: arp who-has <chosen_nip> tell 0.0.0.0
+               //  aa:bb:cc:dd:ee:ff > xx:xx:xx:xx:xx:xx arp who-has <chosen_nip> tell 0.0.0.0
                // we expect _kernel_ to respond to that, because <chosen_nip>
                // is (expected to be) configured on this iface.
        } // while (1)