udhcp: rename fields in struct dhcpOfferedAddr
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 16 Jun 2009 08:23:01 +0000 (10:23 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 16 Jun 2009 08:23:01 +0000 (10:23 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
networking/udhcp/dhcpd.c
networking/udhcp/dhcpd.h
networking/udhcp/dumpleases.c
networking/udhcp/files.c
networking/udhcp/leases.c
networking/udhcp/serverpacket.c

index ccdfd362b7fd5a32c663a8adde12620fe7efcf50..61e4a1d95767df838cdca475a528a982cb0b3570 100644 (file)
@@ -170,8 +170,8 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
                if (static_lease_ip) {
                        bb_info_msg("Found static lease: %x", static_lease_ip);
 
-                       memcpy(&static_lease.chaddr, &packet.chaddr, 16);
-                       static_lease.yiaddr = static_lease_ip;
+                       memcpy(&static_lease.lease_mac16, &packet.chaddr, 16);
+                       static_lease.lease_nip = static_lease_ip;
                        static_lease.expires = 0;
 
                        lease = &static_lease;
@@ -204,19 +204,19 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
                                        DEBUG("server_id = %08x", ntohl(server_id_aligned));
                                        if (server_id_aligned == server_config.server
                                         && requested
-                                        && requested_aligned == lease->yiaddr
+                                        && requested_aligned == lease->lease_nip
                                        ) {
-                                               send_ACK(&packet, lease->yiaddr);
+                                               send_ACK(&packet, lease->lease_nip);
                                        }
                                } else if (requested) {
                                        /* INIT-REBOOT State */
-                                       if (lease->yiaddr == requested_aligned)
-                                               send_ACK(&packet, lease->yiaddr);
+                                       if (lease->lease_nip == requested_aligned)
+                                               send_ACK(&packet, lease->lease_nip);
                                        else
                                                send_NAK(&packet);
-                               } else if (lease->yiaddr == packet.ciaddr) {
+                               } else if (lease->lease_nip == packet.ciaddr) {
                                        /* RENEWING or REBINDING State */
-                                       send_ACK(&packet, lease->yiaddr);
+                                       send_ACK(&packet, lease->lease_nip);
                                } else { /* don't know what to do!!!! */
                                        send_NAK(&packet);
                                }
@@ -231,10 +231,11 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
                                if (lease) {
                                        if (lease_expired(lease)) {
                                                /* probably best if we drop this lease */
-                                               memset(lease->chaddr, 0, 16);
-                                       /* make some contention for this address */
-                                       } else
+                                               memset(lease->lease_mac16, 0, 16);
+                                       } else {
+                                               /* make some contention for this address */
                                                send_NAK(&packet);
+                                       }
                                } else {
                                        uint32_t r = ntohl(requested_aligned);
                                        if (r < server_config.start_ip
@@ -252,7 +253,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
                case DHCPDECLINE:
                        DEBUG("Received DECLINE");
                        if (lease) {
-                               memset(lease->chaddr, 0, 16);
+                               memset(lease->lease_mac16, 0, 16);
                                lease->expires = time(NULL) + server_config.decline_time;
                        }
                        break;
index 4b5fcc00f45d96389243e2c746c03a9b9e963aa2..a3ace92d4a4b27efd18e03840fbc35f725392755 100644 (file)
@@ -78,9 +78,9 @@ typedef uint32_t leasetime_t;
 typedef int32_t signed_leasetime_t;
 
 struct dhcpOfferedAddr {
-       uint8_t chaddr[16];
-       /* In network order */
-       uint32_t yiaddr;
+       uint8_t lease_mac16[16];
+       /* "nip": IP in network order */
+       uint32_t lease_nip;
        /* Unix time when lease expires, regardless of value of
         * server_config.remaining. Kept in memory in host order.
         * When written to file, converted to network order
index 1558f8848c8ea53ec1392da58a82153bdc6c55cb..5b98aa5fef7d887d2959d5a780fdd684abc8f29b 100644 (file)
@@ -61,10 +61,10 @@ int dumpleases_main(int argc UNUSED_PARAM, char **argv)
        while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) {
                const char *fmt = ":%02x" + 1;
                for (i = 0; i < 6; i++) {
-                       printf(fmt, lease.chaddr[i]);
+                       printf(fmt, lease.lease_mac16[i]);
                        fmt = ":%02x";
                }
-               addr.s_addr = lease.yiaddr;
+               addr.s_addr = lease.lease_nip;
                /* actually, 15+1 and 19+1, +1 is a space between columns */
                /* lease.hostname is char[20] and is always NUL terminated */
                printf(" %-16s%-20s", inet_ntoa(addr), lease.hostname);
index af77308902edaf6b79fdfd2d9e65819db267d528..671ea94c9afab28c6647a298f824edda38d63466 100644 (file)
@@ -360,7 +360,7 @@ void FAST_FUNC write_leases(void)
        for (i = 0; i < server_config.max_leases; i++) {
                leasetime_t tmp_time;
 
-               if (leases[i].yiaddr == 0)
+               if (leases[i].lease_nip == 0)
                        continue;
 
                /* Screw with the time in the struct, for easier writing */
@@ -413,14 +413,14 @@ void FAST_FUNC read_leases(const char *file)
        IF_UDHCP_DEBUG(i = 0;)
        while (full_read(fd, &lease, sizeof(lease)) == sizeof(lease)) {
                /* ADDME: what if it matches some static lease? */
-               uint32_t y = ntohl(lease.yiaddr);
+               uint32_t y = ntohl(lease.lease_nip);
                if (y >= server_config.start_ip && y <= server_config.end_ip) {
                        signed_leasetime_t expires = ntohl(lease.expires) - (signed_leasetime_t)time_passed;
                        if (expires <= 0)
                                continue;
                        /* NB: add_lease takes "relative time", IOW,
                         * lease duration, not lease deadline. */
-                       if (!(add_lease(lease.chaddr, lease.yiaddr, expires, lease.hostname))) {
+                       if (!(add_lease(lease.lease_mac16, lease.lease_nip, expires, lease.hostname))) {
                                bb_error_msg("too many leases while loading %s", file);
                                break;
                        }
index b2cdd19423416482dc30025afb92b77817ce6455..040126fe897d8d8fbedaffaddaa7210455c272cd 100644 (file)
@@ -38,10 +38,10 @@ static void clear_lease(const uint8_t *chaddr, uint32_t yiaddr)
                continue;
 
        for (i = 0; i < server_config.max_leases; i++) {
-               if ((j != 16 && memcmp(leases[i].chaddr, chaddr, 16) == 0)
-                || (yiaddr && leases[i].yiaddr == yiaddr)
+               if ((j != 16 && memcmp(leases[i].lease_mac16, chaddr, 16) == 0)
+                || (yiaddr && leases[i].lease_nip == yiaddr)
                ) {
-                       memset(&(leases[i]), 0, sizeof(leases[i]));
+                       memset(&leases[i], 0, sizeof(leases[i]));
                }
        }
 }
@@ -75,8 +75,8 @@ struct dhcpOfferedAddr* FAST_FUNC add_lease(
                                hostname++;
                        }
                }
-               memcpy(oldest->chaddr, chaddr, 16);
-               oldest->yiaddr = yiaddr;
+               memcpy(oldest->lease_mac16, chaddr, 16);
+               oldest->lease_nip = yiaddr;
                oldest->expires = time(NULL) + leasetime;
        }
 
@@ -97,7 +97,7 @@ struct dhcpOfferedAddr* FAST_FUNC find_lease_by_chaddr(const uint8_t *chaddr)
        unsigned i;
 
        for (i = 0; i < server_config.max_leases; i++)
-               if (!memcmp(leases[i].chaddr, chaddr, 16))
+               if (!memcmp(leases[i].lease_mac16, chaddr, 16))
                        return &(leases[i]);
 
        return NULL;
@@ -110,8 +110,8 @@ struct dhcpOfferedAddr* FAST_FUNC find_lease_by_yiaddr(uint32_t yiaddr)
        unsigned i;
 
        for (i = 0; i < server_config.max_leases; i++)
-               if (leases[i].yiaddr == yiaddr)
-                       return &(leases[i]);
+               if (leases[i].lease_nip == yiaddr)
+                       return &leases[i];
 
        return NULL;
 }
@@ -174,9 +174,9 @@ uint32_t FAST_FUNC find_free_or_expired_address(const uint8_t *chaddr)
        }
 
        if (oldest_lease && lease_expired(oldest_lease)
-        && nobody_responds_to_arp(oldest_lease->yiaddr, chaddr)
+        && nobody_responds_to_arp(oldest_lease->lease_nip, chaddr)
        ) {
-               return oldest_lease->yiaddr;
+               return oldest_lease->lease_nip;
        }
 
        return 0;
index 157d157ba53caf47625b7de151a1e9c401975f14..6aa2d34faee9b19e3f86192c8a7949c247e5217f 100644 (file)
@@ -132,7 +132,7 @@ int FAST_FUNC send_offer(struct dhcpMessage *oldpacket)
                        signed_leasetime_t tmp = lease->expires - time(NULL);
                        if (tmp >= 0)
                                lease_time_aligned = tmp;
-                       packet.yiaddr = lease->yiaddr;
+                       packet.yiaddr = lease->lease_nip;
                }
                /* Or the client has requested an IP */
                else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) != NULL