diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-06-16 12:04:23 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-06-16 12:04:23 +0200 |
commit | 26918dd28ef6f2c6380ed23b384ddc8e98a8ad81 (patch) | |
tree | 77c5bd48717b9dbfd683937e3f70fc902b7c7119 | |
parent | cab3a0127c3e6b7fc4f794ba6abcb8e01492118e (diff) | |
download | busybox-w32-26918dd28ef6f2c6380ed23b384ddc8e98a8ad81.tar.gz busybox-w32-26918dd28ef6f2c6380ed23b384ddc8e98a8ad81.tar.bz2 busybox-w32-26918dd28ef6f2c6380ed23b384ddc8e98a8ad81.zip |
udhcp: rename server/client_config.arp to server_mac and client_mac
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/udhcp/clientpacket.c | 7 | ||||
-rw-r--r-- | networking/udhcp/common.h | 2 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.c | 15 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.h | 2 | ||||
-rw-r--r-- | networking/udhcp/dhcpd.c | 7 | ||||
-rw-r--r-- | networking/udhcp/dhcpd.h | 24 | ||||
-rw-r--r-- | networking/udhcp/leases.c | 5 | ||||
-rw-r--r-- | networking/udhcp/serverpacket.c | 2 | ||||
-rw-r--r-- | networking/udhcp/socket.c | 8 |
9 files changed, 44 insertions, 28 deletions
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c index 3f9522ff8..068f947cc 100644 --- a/networking/udhcp/clientpacket.c +++ b/networking/udhcp/clientpacket.c | |||
@@ -37,11 +37,11 @@ uint32_t FAST_FUNC random_xid(void) | |||
37 | } | 37 | } |
38 | 38 | ||
39 | 39 | ||
40 | /* initialize a packet with the proper defaults */ | 40 | /* Initialize the packet with the proper defaults */ |
41 | static void init_packet(struct dhcpMessage *packet, char type) | 41 | static void init_packet(struct dhcpMessage *packet, char type) |
42 | { | 42 | { |
43 | udhcp_init_header(packet, type); | 43 | udhcp_init_header(packet, type); |
44 | memcpy(packet->chaddr, client_config.arp, 6); | 44 | memcpy(packet->chaddr, client_config.client_mac, 6); |
45 | if (client_config.clientid) | 45 | if (client_config.clientid) |
46 | add_option_string(packet->options, client_config.clientid); | 46 | add_option_string(packet->options, client_config.clientid); |
47 | if (client_config.hostname) | 47 | if (client_config.hostname) |
@@ -122,6 +122,7 @@ int FAST_FUNC send_decline(uint32_t xid, uint32_t server, uint32_t requested) | |||
122 | } | 122 | } |
123 | #endif | 123 | #endif |
124 | 124 | ||
125 | |||
125 | /* Broadcast a DHCP discover packet to the network, with an optionally requested IP */ | 126 | /* Broadcast a DHCP discover packet to the network, with an optionally requested IP */ |
126 | int FAST_FUNC send_discover(uint32_t xid, uint32_t requested) | 127 | int FAST_FUNC send_discover(uint32_t xid, uint32_t requested) |
127 | { | 128 | { |
@@ -143,7 +144,7 @@ int FAST_FUNC send_discover(uint32_t xid, uint32_t requested) | |||
143 | } | 144 | } |
144 | 145 | ||
145 | 146 | ||
146 | /* Broadcasts a DHCP request message */ | 147 | /* Broadcast a DHCP request message */ |
147 | /* RFC 2131 3.1 paragraph 3: | 148 | /* RFC 2131 3.1 paragraph 3: |
148 | * "The client _broadcasts_ a DHCPREQUEST message..." | 149 | * "The client _broadcasts_ a DHCPREQUEST message..." |
149 | */ | 150 | */ |
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index de784adf5..91e8ccc53 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h | |||
@@ -88,7 +88,7 @@ void udhcp_run_script(struct dhcpMessage *packet, const char *name) FAST_FUNC; | |||
88 | void udhcp_sp_setup(void) FAST_FUNC; | 88 | void udhcp_sp_setup(void) FAST_FUNC; |
89 | int udhcp_sp_fd_set(fd_set *rfds, int extra_fd) FAST_FUNC; | 89 | int udhcp_sp_fd_set(fd_set *rfds, int extra_fd) FAST_FUNC; |
90 | int udhcp_sp_read(const fd_set *rfds) FAST_FUNC; | 90 | int udhcp_sp_read(const fd_set *rfds) FAST_FUNC; |
91 | int udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *arp) FAST_FUNC; | 91 | int udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac) FAST_FUNC; |
92 | int udhcp_raw_socket(int ifindex) FAST_FUNC; | 92 | int udhcp_raw_socket(int ifindex) FAST_FUNC; |
93 | int udhcp_listen_socket(/*uint32_t ip,*/ int port, const char *inf) FAST_FUNC; | 93 | int udhcp_listen_socket(/*uint32_t ip,*/ int port, const char *inf) FAST_FUNC; |
94 | /* Returns 1 if no reply received */ | 94 | /* Returns 1 if no reply received */ |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index ab34b0472..44ff197b9 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -273,9 +273,14 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
273 | client_config.opt_mask[n >> 3] |= 1 << (n & 7); | 273 | client_config.opt_mask[n >> 3] |= 1 << (n & 7); |
274 | } | 274 | } |
275 | 275 | ||
276 | if (udhcp_read_interface(client_config.interface, &client_config.ifindex, | 276 | if (udhcp_read_interface(client_config.interface, |
277 | NULL, client_config.arp)) | 277 | &client_config.ifindex, |
278 | NULL, | ||
279 | client_config.client_mac) | ||
280 | ) { | ||
278 | return 1; | 281 | return 1; |
282 | } | ||
283 | |||
279 | #if !BB_MMU | 284 | #if !BB_MMU |
280 | /* on NOMMU reexec (i.e., background) early */ | 285 | /* on NOMMU reexec (i.e., background) early */ |
281 | if (!(opt & OPT_f)) { | 286 | if (!(opt & OPT_f)) { |
@@ -303,7 +308,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
303 | if (!client_config.clientid && !(opt & OPT_C)) { | 308 | if (!client_config.clientid && !(opt & OPT_C)) { |
304 | client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, "", 7); | 309 | client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, "", 7); |
305 | client_config.clientid[OPT_DATA] = 1; | 310 | client_config.clientid[OPT_DATA] = 1; |
306 | memcpy(client_config.clientid + OPT_DATA+1, client_config.arp, 6); | 311 | memcpy(client_config.clientid + OPT_DATA+1, client_config.client_mac, 6); |
307 | } | 312 | } |
308 | 313 | ||
309 | if (!client_config.vendorclass) | 314 | if (!client_config.vendorclass) |
@@ -490,7 +495,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
490 | } | 495 | } |
491 | 496 | ||
492 | /* Ignore packets that aren't for us */ | 497 | /* Ignore packets that aren't for us */ |
493 | if (memcmp(packet.chaddr, client_config.arp, 6)) { | 498 | if (memcmp(packet.chaddr, client_config.client_mac, 6)) { |
494 | DEBUG("Packet does not have our chaddr - ignoring"); | 499 | DEBUG("Packet does not have our chaddr - ignoring"); |
495 | continue; | 500 | continue; |
496 | } | 501 | } |
@@ -555,7 +560,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv) | |||
555 | if (!arpping(packet.yiaddr, | 560 | if (!arpping(packet.yiaddr, |
556 | NULL, | 561 | NULL, |
557 | (uint32_t) 0, | 562 | (uint32_t) 0, |
558 | client_config.arp, | 563 | client_config.client_mac, |
559 | client_config.interface) | 564 | client_config.interface) |
560 | ) { | 565 | ) { |
561 | bb_info_msg("offered address is in use " | 566 | bb_info_msg("offered address is in use " |
diff --git a/networking/udhcp/dhcpc.h b/networking/udhcp/dhcpc.h index 361624f17..861e134bd 100644 --- a/networking/udhcp/dhcpc.h +++ b/networking/udhcp/dhcpc.h | |||
@@ -6,7 +6,7 @@ | |||
6 | PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN | 6 | PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN |
7 | 7 | ||
8 | struct client_config_t { | 8 | struct client_config_t { |
9 | uint8_t arp[6]; /* Our arp address */ | 9 | uint8_t client_mac[6]; /* Our arp address */ |
10 | /* TODO: combine flag fields into single "unsigned opt" */ | 10 | /* TODO: combine flag fields into single "unsigned opt" */ |
11 | /* (can be set directly to the result of getopt32) */ | 11 | /* (can be set directly to the result of getopt32) */ |
12 | char no_default_options; /* Do not include default optins in request */ | 12 | char no_default_options; /* Do not include default optins in request */ |
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 5993042cd..c74a11b31 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c | |||
@@ -93,8 +93,11 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
93 | leases = xzalloc(server_config.max_leases * sizeof(*leases)); | 93 | leases = xzalloc(server_config.max_leases * sizeof(*leases)); |
94 | read_leases(server_config.lease_file); | 94 | read_leases(server_config.lease_file); |
95 | 95 | ||
96 | if (udhcp_read_interface(server_config.interface, &server_config.ifindex, | 96 | if (udhcp_read_interface(server_config.interface, |
97 | &server_config.server_nip, server_config.arp)) { | 97 | &server_config.ifindex, |
98 | &server_config.server_nip, | ||
99 | server_config.server_mac) | ||
100 | ) { | ||
98 | retval = 1; | 101 | retval = 1; |
99 | goto ret; | 102 | goto ret; |
100 | } | 103 | } |
diff --git a/networking/udhcp/dhcpd.h b/networking/udhcp/dhcpd.h index 4774fd12c..b233962b0 100644 --- a/networking/udhcp/dhcpd.h +++ b/networking/udhcp/dhcpd.h | |||
@@ -28,17 +28,23 @@ struct static_lease { | |||
28 | }; | 28 | }; |
29 | 29 | ||
30 | struct server_config_t { | 30 | struct server_config_t { |
31 | uint32_t server_nip; /* Our IP, in network order */ | 31 | char *interface; /* interface to use */ |
32 | //TODO: ifindex, server_nip, server_mac | ||
33 | // are obtained from interface name. | ||
34 | // Instead of querying them *once*, create update_server_network_data_cache() | ||
35 | // and call it before any usage of these fields. | ||
36 | // update_server_network_data_cache() must re-query data | ||
37 | // if more than N seconds have passed after last use. | ||
38 | int ifindex; | ||
39 | uint32_t server_nip; | ||
32 | #if ENABLE_FEATURE_UDHCP_PORT | 40 | #if ENABLE_FEATURE_UDHCP_PORT |
33 | uint16_t port; | 41 | uint16_t port; |
34 | #endif | 42 | #endif |
43 | uint8_t server_mac[6]; /* our MAC address (used only for ARP probing) */ | ||
44 | struct option_set *options; /* list of DHCP options loaded from the config file */ | ||
35 | /* start,end are in host order: we need to compare start <= ip <= end */ | 45 | /* start,end are in host order: we need to compare start <= ip <= end */ |
36 | uint32_t start_ip; /* Start address of leases, in host order */ | 46 | uint32_t start_ip; /* start address of leases, in host order */ |
37 | uint32_t end_ip; /* End of leases, in host order */ | 47 | uint32_t end_ip; /* end of leases, in host order */ |
38 | struct option_set *options; /* List of DHCP options loaded from the config file */ | ||
39 | char *interface; /* The name of the interface to use */ | ||
40 | int ifindex; /* Index number of the interface to use */ | ||
41 | uint8_t arp[6]; /* Our arp address */ | ||
42 | uint32_t lease; /* lease time in seconds (host order) */ | 48 | uint32_t lease; /* lease time in seconds (host order) */ |
43 | uint32_t max_leases; /* maximum number of leases (including reserved address) */ | 49 | uint32_t max_leases; /* maximum number of leases (including reserved address) */ |
44 | uint32_t auto_time; /* how long should udhcpd wait before writing a config file. | 50 | uint32_t auto_time; /* how long should udhcpd wait before writing a config file. |
@@ -48,10 +54,10 @@ struct server_config_t { | |||
48 | uint32_t conflict_time; /* how long an arp conflict offender is leased for */ | 54 | uint32_t conflict_time; /* how long an arp conflict offender is leased for */ |
49 | uint32_t offer_time; /* how long an offered address is reserved */ | 55 | uint32_t offer_time; /* how long an offered address is reserved */ |
50 | uint32_t min_lease; /* minimum lease time a client can request */ | 56 | uint32_t min_lease; /* minimum lease time a client can request */ |
51 | uint32_t siaddr_nip; /* next server bootp option */ | 57 | uint32_t siaddr_nip; /* "next server" bootp option */ |
52 | char *lease_file; | 58 | char *lease_file; |
53 | char *pidfile; | 59 | char *pidfile; |
54 | char *notify_file; /* What to run whenever leases are written */ | 60 | char *notify_file; /* what to run whenever leases are written */ |
55 | char *sname; /* bootp server name */ | 61 | char *sname; /* bootp server name */ |
56 | char *boot_file; /* bootp boot file option */ | 62 | char *boot_file; /* bootp boot file option */ |
57 | struct static_lease *static_leases; /* List of ip/mac pairs to assign static leases */ | 63 | struct static_lease *static_leases; /* List of ip/mac pairs to assign static leases */ |
diff --git a/networking/udhcp/leases.c b/networking/udhcp/leases.c index c318856f5..291ae8053 100644 --- a/networking/udhcp/leases.c +++ b/networking/udhcp/leases.c | |||
@@ -117,7 +117,7 @@ struct dhcpOfferedAddr* FAST_FUNC find_lease_by_yiaddr(uint32_t yiaddr) | |||
117 | } | 117 | } |
118 | 118 | ||
119 | 119 | ||
120 | /* check is an IP is taken, if it is, add it to the lease table */ | 120 | /* Check if the IP is taken; if it is, add it to the lease table */ |
121 | static int nobody_responds_to_arp(uint32_t addr, const uint8_t *safe_mac) | 121 | static int nobody_responds_to_arp(uint32_t addr, const uint8_t *safe_mac) |
122 | { | 122 | { |
123 | /* 16 zero bytes */ | 123 | /* 16 zero bytes */ |
@@ -128,7 +128,8 @@ static int nobody_responds_to_arp(uint32_t addr, const uint8_t *safe_mac) | |||
128 | int r; | 128 | int r; |
129 | 129 | ||
130 | r = arpping(addr, safe_mac, | 130 | r = arpping(addr, safe_mac, |
131 | server_config.server_nip, server_config.arp, | 131 | server_config.server_nip, |
132 | server_config.server_mac, | ||
132 | server_config.interface); | 133 | server_config.interface); |
133 | if (r) | 134 | if (r) |
134 | return r; | 135 | return r; |
diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c index 5aa494ba1..d9c5ce3ed 100644 --- a/networking/udhcp/serverpacket.c +++ b/networking/udhcp/serverpacket.c | |||
@@ -37,7 +37,7 @@ static int send_packet_to_relay(struct dhcpMessage *payload) | |||
37 | } | 37 | } |
38 | 38 | ||
39 | 39 | ||
40 | /* send a packet to a specific arp address and ip address by creating our own ip packet */ | 40 | /* send a packet to a specific mac address and ip address by creating our own ip packet */ |
41 | static int send_packet_to_client(struct dhcpMessage *payload, int force_broadcast) | 41 | static int send_packet_to_client(struct dhcpMessage *payload, int force_broadcast) |
42 | { | 42 | { |
43 | const uint8_t *chaddr; | 43 | const uint8_t *chaddr; |
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c index 449fcb7aa..de494ca38 100644 --- a/networking/udhcp/socket.c +++ b/networking/udhcp/socket.c | |||
@@ -37,7 +37,7 @@ | |||
37 | #include "common.h" | 37 | #include "common.h" |
38 | 38 | ||
39 | 39 | ||
40 | int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *arp) | 40 | int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac) |
41 | { | 41 | { |
42 | int fd; | 42 | int fd; |
43 | struct ifreq ifr; | 43 | struct ifreq ifr; |
@@ -69,14 +69,14 @@ int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t | |||
69 | *ifindex = ifr.ifr_ifindex; | 69 | *ifindex = ifr.ifr_ifindex; |
70 | } | 70 | } |
71 | 71 | ||
72 | if (arp) { | 72 | if (mac) { |
73 | if (ioctl_or_warn(fd, SIOCGIFHWADDR, &ifr) != 0) { | 73 | if (ioctl_or_warn(fd, SIOCGIFHWADDR, &ifr) != 0) { |
74 | close(fd); | 74 | close(fd); |
75 | return -1; | 75 | return -1; |
76 | } | 76 | } |
77 | memcpy(arp, ifr.ifr_hwaddr.sa_data, 6); | 77 | memcpy(mac, ifr.ifr_hwaddr.sa_data, 6); |
78 | DEBUG("adapter hardware address %02x:%02x:%02x:%02x:%02x:%02x", | 78 | DEBUG("adapter hardware address %02x:%02x:%02x:%02x:%02x:%02x", |
79 | arp[0], arp[1], arp[2], arp[3], arp[4], arp[5]); | 79 | mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); |
80 | } | 80 | } |
81 | 81 | ||
82 | close(fd); | 82 | close(fd); |