diff options
-rw-r--r-- | networking/udhcp/dhcpd.c | 2 | ||||
-rw-r--r-- | networking/udhcp/dhcpd.h | 18 | ||||
-rw-r--r-- | networking/udhcp/files.c | 4 | ||||
-rw-r--r-- | networking/udhcp/leases.c | 4 | ||||
-rw-r--r-- | networking/udhcp/serverpacket.c | 2 | ||||
-rw-r--r-- | networking/udhcp/static_leases.c | 63 |
6 files changed, 45 insertions, 48 deletions
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c index 09524e29c..5993042cd 100644 --- a/networking/udhcp/dhcpd.c +++ b/networking/udhcp/dhcpd.c | |||
@@ -166,7 +166,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv) | |||
166 | } | 166 | } |
167 | 167 | ||
168 | /* Look for a static lease */ | 168 | /* Look for a static lease */ |
169 | static_lease_ip = getIpByMac(server_config.static_leases, &packet.chaddr); | 169 | static_lease_ip = get_static_nip_by_mac(server_config.static_leases, &packet.chaddr); |
170 | if (static_lease_ip) { | 170 | if (static_lease_ip) { |
171 | bb_info_msg("Found static lease: %x", static_lease_ip); | 171 | bb_info_msg("Found static lease: %x", static_lease_ip); |
172 | 172 | ||
diff --git a/networking/udhcp/dhcpd.h b/networking/udhcp/dhcpd.h index 61cd8c7be..4774fd12c 100644 --- a/networking/udhcp/dhcpd.h +++ b/networking/udhcp/dhcpd.h | |||
@@ -23,7 +23,7 @@ struct option_set { | |||
23 | 23 | ||
24 | struct static_lease { | 24 | struct static_lease { |
25 | struct static_lease *next; | 25 | struct static_lease *next; |
26 | uint32_t ip; | 26 | uint32_t nip; |
27 | uint8_t mac[6]; | 27 | uint8_t mac[6]; |
28 | }; | 28 | }; |
29 | 29 | ||
@@ -97,15 +97,15 @@ uint32_t find_free_or_expired_address(const uint8_t *chaddr) FAST_FUNC; | |||
97 | 97 | ||
98 | /*** static_leases.h ***/ | 98 | /*** static_leases.h ***/ |
99 | 99 | ||
100 | /* Config file will pass static lease info to this function which will add it | 100 | /* Config file parser will pass static lease info to this function |
101 | * to a data structure that can be searched later */ | 101 | * which will add it to a data structure that can be searched later */ |
102 | void addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t ip) FAST_FUNC; | 102 | void add_static_lease(struct static_lease **st_lease_pp, uint8_t *mac, uint32_t nip) FAST_FUNC; |
103 | /* Check to see if a mac has an associated static lease */ | 103 | /* Find static lease IP by mac */ |
104 | uint32_t getIpByMac(struct static_lease *lease_struct, void *arg) FAST_FUNC; | 104 | uint32_t get_static_nip_by_mac(struct static_lease *st_lease, void *arg) FAST_FUNC; |
105 | /* Check to see if an ip is reserved as a static ip */ | 105 | /* Check to see if an IP is reserved as a static IP */ |
106 | int reservedIp(struct static_lease *lease_struct, uint32_t ip) FAST_FUNC; | 106 | int is_nip_reserved(struct static_lease *st_lease, uint32_t nip) FAST_FUNC; |
107 | /* Print out static leases just to check what's going on (debug code) */ | 107 | /* Print out static leases just to check what's going on (debug code) */ |
108 | void printStaticLeases(struct static_lease **lease_struct) FAST_FUNC; | 108 | void print_static_leases(struct static_lease **st_lease_pp) FAST_FUNC; |
109 | 109 | ||
110 | 110 | ||
111 | /*** serverpacket.h ***/ | 111 | /*** serverpacket.h ***/ |
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c index a69a7531b..f3899711c 100644 --- a/networking/udhcp/files.c +++ b/networking/udhcp/files.c | |||
@@ -268,9 +268,9 @@ static int FAST_FUNC read_staticlease(const char *const_line, void *arg) | |||
268 | ip_string = strtok_r(NULL, " \t", &line); | 268 | ip_string = strtok_r(NULL, " \t", &line); |
269 | read_nip(ip_string, &ip); | 269 | read_nip(ip_string, &ip); |
270 | 270 | ||
271 | addStaticLease(arg, (uint8_t*) &mac_bytes, ip); | 271 | add_static_lease(arg, (uint8_t*) &mac_bytes, ip); |
272 | 272 | ||
273 | if (ENABLE_UDHCP_DEBUG) printStaticLeases(arg); | 273 | if (ENABLE_UDHCP_DEBUG) print_static_leases(arg); |
274 | 274 | ||
275 | return 1; | 275 | return 1; |
276 | } | 276 | } |
diff --git a/networking/udhcp/leases.c b/networking/udhcp/leases.c index 403a8bca6..c318856f5 100644 --- a/networking/udhcp/leases.c +++ b/networking/udhcp/leases.c | |||
@@ -159,8 +159,8 @@ uint32_t FAST_FUNC find_free_or_expired_address(const uint8_t *chaddr) | |||
159 | if ((addr & 0xff) == 0xff) | 159 | if ((addr & 0xff) == 0xff) |
160 | continue; | 160 | continue; |
161 | net_addr = htonl(addr); | 161 | net_addr = htonl(addr); |
162 | /* addr has a static lease? */ | 162 | /* is this a static lease addr? */ |
163 | if (reservedIp(server_config.static_leases, net_addr)) | 163 | if (is_nip_reserved(server_config.static_leases, net_addr)) |
164 | continue; | 164 | continue; |
165 | 165 | ||
166 | lease = find_lease_by_yiaddr(net_addr); | 166 | lease = find_lease_by_yiaddr(net_addr); |
diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c index 294a6a666..5aa494ba1 100644 --- a/networking/udhcp/serverpacket.c +++ b/networking/udhcp/serverpacket.c | |||
@@ -120,7 +120,7 @@ int FAST_FUNC send_offer(struct dhcpMessage *oldpacket) | |||
120 | 120 | ||
121 | init_packet(&packet, oldpacket, DHCPOFFER); | 121 | init_packet(&packet, oldpacket, DHCPOFFER); |
122 | 122 | ||
123 | static_lease_ip = getIpByMac(server_config.static_leases, oldpacket->chaddr); | 123 | static_lease_ip = get_static_nip_by_mac(server_config.static_leases, oldpacket->chaddr); |
124 | 124 | ||
125 | /* ADDME: if static, short circuit */ | 125 | /* ADDME: if static, short circuit */ |
126 | if (!static_lease_ip) { | 126 | if (!static_lease_ip) { |
diff --git a/networking/udhcp/static_leases.c b/networking/udhcp/static_leases.c index 1e77a58f9..7d1aa2f27 100644 --- a/networking/udhcp/static_leases.c +++ b/networking/udhcp/static_leases.c | |||
@@ -13,48 +13,45 @@ | |||
13 | 13 | ||
14 | 14 | ||
15 | /* Takes the address of the pointer to the static_leases linked list, | 15 | /* Takes the address of the pointer to the static_leases linked list, |
16 | * Address to a 6 byte mac address | 16 | * address to a 6 byte mac address, |
17 | * Address to a 4 byte ip address */ | 17 | * 4 byte IP address */ |
18 | void FAST_FUNC addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t ip) | 18 | void FAST_FUNC add_static_lease(struct static_lease **st_lease_pp, |
19 | uint8_t *mac, | ||
20 | uint32_t nip) | ||
19 | { | 21 | { |
20 | struct static_lease *new_static_lease; | 22 | struct static_lease *st_lease; |
21 | 23 | ||
22 | /* Build new node */ | 24 | /* Find the tail of the list */ |
23 | new_static_lease = xzalloc(sizeof(struct static_lease)); | 25 | while ((st_lease = *st_lease_pp) != NULL) { |
24 | memcpy(new_static_lease->mac, mac, 6); | 26 | st_lease_pp = &st_lease->next; |
25 | new_static_lease->ip = ip; | ||
26 | /*new_static_lease->next = NULL;*/ | ||
27 | |||
28 | /* If it's the first node to be added... */ | ||
29 | if (*lease_struct == NULL) { | ||
30 | *lease_struct = new_static_lease; | ||
31 | } else { | ||
32 | struct static_lease *cur = *lease_struct; | ||
33 | while (cur->next) | ||
34 | cur = cur->next; | ||
35 | cur->next = new_static_lease; | ||
36 | } | 27 | } |
28 | |||
29 | /* Add new node */ | ||
30 | *st_lease_pp = st_lease = xzalloc(sizeof(*st_lease)); | ||
31 | memcpy(st_lease->mac, mac, 6); | ||
32 | st_lease->nip = nip; | ||
33 | /*st_lease->next = NULL;*/ | ||
37 | } | 34 | } |
38 | 35 | ||
39 | /* Check to see if a mac has an associated static lease */ | 36 | /* Find static lease IP by mac */ |
40 | uint32_t FAST_FUNC getIpByMac(struct static_lease *lease_struct, void *mac) | 37 | uint32_t FAST_FUNC get_static_nip_by_mac(struct static_lease *st_lease, void *mac) |
41 | { | 38 | { |
42 | while (lease_struct) { | 39 | while (st_lease) { |
43 | if (memcmp(lease_struct->mac, mac, 6) == 0) | 40 | if (memcmp(st_lease->mac, mac, 6) == 0) |
44 | return lease_struct->ip; | 41 | return st_lease->nip; |
45 | lease_struct = lease_struct->next; | 42 | st_lease = st_lease->next; |
46 | } | 43 | } |
47 | 44 | ||
48 | return 0; | 45 | return 0; |
49 | } | 46 | } |
50 | 47 | ||
51 | /* Check to see if an ip is reserved as a static ip */ | 48 | /* Check to see if an IP is reserved as a static IP */ |
52 | int FAST_FUNC reservedIp(struct static_lease *lease_struct, uint32_t ip) | 49 | int FAST_FUNC is_nip_reserved(struct static_lease *st_lease, uint32_t nip) |
53 | { | 50 | { |
54 | while (lease_struct) { | 51 | while (st_lease) { |
55 | if (lease_struct->ip == ip) | 52 | if (st_lease->nip == nip) |
56 | return 1; | 53 | return 1; |
57 | lease_struct = lease_struct->next; | 54 | st_lease = st_lease->next; |
58 | } | 55 | } |
59 | 56 | ||
60 | return 0; | 57 | return 0; |
@@ -63,16 +60,16 @@ int FAST_FUNC reservedIp(struct static_lease *lease_struct, uint32_t ip) | |||
63 | #if ENABLE_UDHCP_DEBUG | 60 | #if ENABLE_UDHCP_DEBUG |
64 | /* Print out static leases just to check what's going on */ | 61 | /* Print out static leases just to check what's going on */ |
65 | /* Takes the address of the pointer to the static_leases linked list */ | 62 | /* Takes the address of the pointer to the static_leases linked list */ |
66 | void FAST_FUNC printStaticLeases(struct static_lease **arg) | 63 | void FAST_FUNC print_static_leases(struct static_lease **st_lease_pp) |
67 | { | 64 | { |
68 | struct static_lease *cur = *arg; | 65 | struct static_lease *cur = *st_lease_pp; |
69 | 66 | ||
70 | while (cur) { | 67 | while (cur) { |
71 | printf("PrintStaticLeases: Lease mac Value: %02x:%02x:%02x:%02x:%02x:%02x\n", | 68 | printf("PrintStaticLeases: lease mac: %02x:%02x:%02x:%02x:%02x:%02x\n", |
72 | cur->mac[0], cur->mac[1], cur->mac[2], | 69 | cur->mac[0], cur->mac[1], cur->mac[2], |
73 | cur->mac[3], cur->mac[4], cur->mac[5] | 70 | cur->mac[3], cur->mac[4], cur->mac[5] |
74 | ); | 71 | ); |
75 | printf("PrintStaticLeases: Lease ip Value: %x\n", cur->ip); | 72 | printf("PrintStaticLeases: lease ip: %x\n", cur->nip); |
76 | cur = cur->next; | 73 | cur = cur->next; |
77 | } | 74 | } |
78 | } | 75 | } |