udhcp: rename server/client_config.arp to server_mac and client_mac
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 16 Jun 2009 10:04:23 +0000 (12:04 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 16 Jun 2009 10:04:23 +0000 (12:04 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
networking/udhcp/clientpacket.c
networking/udhcp/common.h
networking/udhcp/dhcpc.c
networking/udhcp/dhcpc.h
networking/udhcp/dhcpd.c
networking/udhcp/dhcpd.h
networking/udhcp/leases.c
networking/udhcp/serverpacket.c
networking/udhcp/socket.c

index 3f9522ff8bf8ba67a434d732d2bff8bf359c519f..068f947ccb8a738c25b050b623b40a6d05db570d 100644 (file)
@@ -37,11 +37,11 @@ uint32_t FAST_FUNC random_xid(void)
 }
 
 
-/* initialize a packet with the proper defaults */
+/* Initialize the packet with the proper defaults */
 static void init_packet(struct dhcpMessage *packet, char type)
 {
        udhcp_init_header(packet, type);
-       memcpy(packet->chaddr, client_config.arp, 6);
+       memcpy(packet->chaddr, client_config.client_mac, 6);
        if (client_config.clientid)
                add_option_string(packet->options, client_config.clientid);
        if (client_config.hostname)
@@ -122,6 +122,7 @@ int FAST_FUNC send_decline(uint32_t xid, uint32_t server, uint32_t requested)
 }
 #endif
 
+
 /* Broadcast a DHCP discover packet to the network, with an optionally requested IP */
 int FAST_FUNC send_discover(uint32_t xid, uint32_t requested)
 {
@@ -143,7 +144,7 @@ int FAST_FUNC send_discover(uint32_t xid, uint32_t requested)
 }
 
 
-/* Broadcasts a DHCP request message */
+/* Broadcast a DHCP request message */
 /* RFC 2131 3.1 paragraph 3:
  * "The client _broadcasts_ a DHCPREQUEST message..."
  */
index de784adf57abac3497ec01c21ef1fbf3015d12c6..91e8ccc53542a192f85f36f64f06badb84f13750 100644 (file)
@@ -88,7 +88,7 @@ void udhcp_run_script(struct dhcpMessage *packet, const char *name) FAST_FUNC;
 void udhcp_sp_setup(void) FAST_FUNC;
 int udhcp_sp_fd_set(fd_set *rfds, int extra_fd) FAST_FUNC;
 int udhcp_sp_read(const fd_set *rfds) FAST_FUNC;
-int udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *arp) FAST_FUNC;
+int udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac) FAST_FUNC;
 int udhcp_raw_socket(int ifindex) FAST_FUNC;
 int udhcp_listen_socket(/*uint32_t ip,*/ int port, const char *inf) FAST_FUNC;
 /* Returns 1 if no reply received */
index ab34b0472cd638a65fafb3b87d99ceccf1fbf5e1..44ff197b9b0a9b1a54145cbf92f3bd8a05d621a9 100644 (file)
@@ -273,9 +273,14 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
                client_config.opt_mask[n >> 3] |= 1 << (n & 7);
        }
 
-       if (udhcp_read_interface(client_config.interface, &client_config.ifindex,
-                          NULL, client_config.arp))
+       if (udhcp_read_interface(client_config.interface,
+                       &client_config.ifindex,
+                       NULL,
+                       client_config.client_mac)
+       ) {
                return 1;
+       }
+
 #if !BB_MMU
        /* on NOMMU reexec (i.e., background) early */
        if (!(opt & OPT_f)) {
@@ -303,7 +308,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
        if (!client_config.clientid && !(opt & OPT_C)) {
                client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, "", 7);
                client_config.clientid[OPT_DATA] = 1;
-               memcpy(client_config.clientid + OPT_DATA+1, client_config.arp, 6);
+               memcpy(client_config.clientid + OPT_DATA+1, client_config.client_mac, 6);
        }
 
        if (!client_config.vendorclass)
@@ -490,7 +495,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
                        }
 
                        /* Ignore packets that aren't for us */
-                       if (memcmp(packet.chaddr, client_config.arp, 6)) {
+                       if (memcmp(packet.chaddr, client_config.client_mac, 6)) {
                                DEBUG("Packet does not have our chaddr - ignoring");
                                continue;
                        }
@@ -555,7 +560,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
                                                if (!arpping(packet.yiaddr,
                                                                NULL,
                                                                (uint32_t) 0,
-                                                               client_config.arp,
+                                                               client_config.client_mac,
                                                                client_config.interface)
                                                ) {
                                                        bb_info_msg("offered address is in use "
index 361624f17e84c2fe30d23fc92db8bacf0d185c0e..861e134bdb66b6c0a312c70190f1afc59db92946 100644 (file)
@@ -6,7 +6,7 @@
 PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
 
 struct client_config_t {
-       uint8_t arp[6];                 /* Our arp address */
+       uint8_t client_mac[6];          /* Our arp address */
        /* TODO: combine flag fields into single "unsigned opt" */
        /* (can be set directly to the result of getopt32) */
        char no_default_options;        /* Do not include default optins in request */
index 5993042cdb8290569854cf1090ed3885f4c3c983..c74a11b3133063b1fce159157f5811ee2041f9a0 100644 (file)
@@ -93,8 +93,11 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
        leases = xzalloc(server_config.max_leases * sizeof(*leases));
        read_leases(server_config.lease_file);
 
-       if (udhcp_read_interface(server_config.interface, &server_config.ifindex,
-                          &server_config.server_nip, server_config.arp)) {
+       if (udhcp_read_interface(server_config.interface,
+                       &server_config.ifindex,
+                       &server_config.server_nip,
+                       server_config.server_mac)
+       ) {
                retval = 1;
                goto ret;
        }
index 4774fd12c6d9e47e1ecdfb748e4b0a332d54a173..b233962b04b455a1e4f1d5061516a4b78fb286a6 100644 (file)
@@ -28,17 +28,23 @@ struct static_lease {
 };
 
 struct server_config_t {
-       uint32_t server_nip;            /* Our IP, in network order */
+       char *interface;                /* interface to use */
+//TODO: ifindex, server_nip, server_mac
+// are obtained from interface name.
+// Instead of querying them *once*, create update_server_network_data_cache()
+// and call it before any usage of these fields.
+// update_server_network_data_cache() must re-query data
+// if more than N seconds have passed after last use.
+       int ifindex;
+       uint32_t server_nip;
 #if ENABLE_FEATURE_UDHCP_PORT
        uint16_t port;
 #endif
+       uint8_t server_mac[6];          /* our MAC address (used only for ARP probing) */
+       struct option_set *options;     /* list of DHCP options loaded from the config file */
        /* start,end are in host order: we need to compare start <= ip <= end */
-       uint32_t start_ip;              /* Start address of leases, in host order */
-       uint32_t end_ip;                /* End of leases, in host order */
-       struct option_set *options;     /* List of DHCP options loaded from the config file */
-       char *interface;                /* The name of the interface to use */
-       int ifindex;                    /* Index number of the interface to use */
-       uint8_t arp[6];                 /* Our arp address */
+       uint32_t start_ip;              /* start address of leases, in host order */
+       uint32_t end_ip;                /* end of leases, in host order */
        uint32_t lease;                 /* lease time in seconds (host order) */
        uint32_t max_leases;            /* maximum number of leases (including reserved address) */
        uint32_t auto_time;             /* how long should udhcpd wait before writing a config file.
@@ -48,10 +54,10 @@ struct server_config_t {
        uint32_t conflict_time;         /* how long an arp conflict offender is leased for */
        uint32_t offer_time;            /* how long an offered address is reserved */
        uint32_t min_lease;             /* minimum lease time a client can request */
-       uint32_t siaddr_nip;                /* next server bootp option */
+       uint32_t siaddr_nip;            /* "next server" bootp option */
        char *lease_file;
        char *pidfile;
-       char *notify_file;              /* What to run whenever leases are written */
+       char *notify_file;              /* what to run whenever leases are written */
        char *sname;                    /* bootp server name */
        char *boot_file;                /* bootp boot file option */
        struct static_lease *static_leases; /* List of ip/mac pairs to assign static leases */
index c318856f5eb01c3578721702556c53ca3d3c7e40..291ae805379934acd18bf82ecde67e44a9f0fd1a 100644 (file)
@@ -117,7 +117,7 @@ struct dhcpOfferedAddr* FAST_FUNC find_lease_by_yiaddr(uint32_t yiaddr)
 }
 
 
-/* check is an IP is taken, if it is, add it to the lease table */
+/* Check if the IP is taken; if it is, add it to the lease table */
 static int nobody_responds_to_arp(uint32_t addr, const uint8_t *safe_mac)
 {
        /* 16 zero bytes */
@@ -128,7 +128,8 @@ static int nobody_responds_to_arp(uint32_t addr, const uint8_t *safe_mac)
        int r;
 
        r = arpping(addr, safe_mac,
-                       server_config.server_nip, server_config.arp,
+                       server_config.server_nip,
+                       server_config.server_mac,
                        server_config.interface);
        if (r)
                return r;
index 5aa494ba13f83215a345570bc5116756ae21af0e..d9c5ce3edab449fd9496e4d34686976b658559e2 100644 (file)
@@ -37,7 +37,7 @@ static int send_packet_to_relay(struct dhcpMessage *payload)
 }
 
 
-/* send a packet to a specific arp address and ip address by creating our own ip packet */
+/* send a packet to a specific mac address and ip address by creating our own ip packet */
 static int send_packet_to_client(struct dhcpMessage *payload, int force_broadcast)
 {
        const uint8_t *chaddr;
index 449fcb7aa589c0eec7089dc7f1d5be832ead0350..de494ca38eae26ba5719ab0ea0a42d5d20c5b152 100644 (file)
@@ -37,7 +37,7 @@
 #include "common.h"
 
 
-int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *arp)
+int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac)
 {
        int fd;
        struct ifreq ifr;
@@ -69,14 +69,14 @@ int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t
                *ifindex = ifr.ifr_ifindex;
        }
 
-       if (arp) {
+       if (mac) {
                if (ioctl_or_warn(fd, SIOCGIFHWADDR, &ifr) != 0) {
                        close(fd);
                        return -1;
                }
-               memcpy(arp, ifr.ifr_hwaddr.sa_data, 6);
+               memcpy(mac, ifr.ifr_hwaddr.sa_data, 6);
                DEBUG("adapter hardware address %02x:%02x:%02x:%02x:%02x:%02x",
-                       arp[0], arp[1], arp[2], arp[3], arp[4], arp[5]);
+                       mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
        }
 
        close(fd);