Annotation of /trunk/mkinitrd-magellan/busybox/networking/udhcp/static_leases.c
Parent Directory | Revision Log
Revision 1123 -
(hide annotations)
(download)
Wed Aug 18 21:56:57 2010 UTC (13 years, 9 months ago) by niro
File MIME type: text/plain
File size: 1848 byte(s)
Wed Aug 18 21:56:57 2010 UTC (13 years, 9 months ago) by niro
File MIME type: text/plain
File size: 1848 byte(s)
-updated to busybox-1.17.1
1 | niro | 532 | /* vi: set sw=4 ts=4: */ |
2 | /* | ||
3 | niro | 1123 | * Storing and retrieving data for static leases |
4 | niro | 532 | * |
5 | * Wade Berrier <wberrier@myrealbox.com> September 2004 | ||
6 | * | ||
7 | niro | 984 | * Licensed under GPLv2, see file LICENSE in this tarball for details. |
8 | niro | 532 | */ |
9 | #include "common.h" | ||
10 | #include "dhcpd.h" | ||
11 | |||
12 | /* Takes the address of the pointer to the static_leases linked list, | ||
13 | niro | 984 | * address to a 6 byte mac address, |
14 | * 4 byte IP address */ | ||
15 | void FAST_FUNC add_static_lease(struct static_lease **st_lease_pp, | ||
16 | uint8_t *mac, | ||
17 | uint32_t nip) | ||
18 | niro | 532 | { |
19 | niro | 984 | struct static_lease *st_lease; |
20 | niro | 532 | |
21 | niro | 984 | /* Find the tail of the list */ |
22 | while ((st_lease = *st_lease_pp) != NULL) { | ||
23 | st_lease_pp = &st_lease->next; | ||
24 | niro | 532 | } |
25 | |||
26 | niro | 984 | /* Add new node */ |
27 | *st_lease_pp = st_lease = xzalloc(sizeof(*st_lease)); | ||
28 | memcpy(st_lease->mac, mac, 6); | ||
29 | st_lease->nip = nip; | ||
30 | /*st_lease->next = NULL;*/ | ||
31 | niro | 532 | } |
32 | |||
33 | niro | 984 | /* Find static lease IP by mac */ |
34 | uint32_t FAST_FUNC get_static_nip_by_mac(struct static_lease *st_lease, void *mac) | ||
35 | niro | 532 | { |
36 | niro | 984 | while (st_lease) { |
37 | if (memcmp(st_lease->mac, mac, 6) == 0) | ||
38 | return st_lease->nip; | ||
39 | st_lease = st_lease->next; | ||
40 | niro | 532 | } |
41 | |||
42 | niro | 984 | return 0; |
43 | niro | 532 | } |
44 | |||
45 | niro | 984 | /* Check to see if an IP is reserved as a static IP */ |
46 | int FAST_FUNC is_nip_reserved(struct static_lease *st_lease, uint32_t nip) | ||
47 | niro | 532 | { |
48 | niro | 984 | while (st_lease) { |
49 | if (st_lease->nip == nip) | ||
50 | return 1; | ||
51 | st_lease = st_lease->next; | ||
52 | niro | 532 | } |
53 | |||
54 | niro | 984 | return 0; |
55 | niro | 532 | } |
56 | |||
57 | niro | 984 | #if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2 |
58 | niro | 532 | /* Print out static leases just to check what's going on */ |
59 | /* Takes the address of the pointer to the static_leases linked list */ | ||
60 | niro | 984 | void FAST_FUNC log_static_leases(struct static_lease **st_lease_pp) |
61 | niro | 532 | { |
62 | niro | 984 | struct static_lease *cur; |
63 | niro | 532 | |
64 | niro | 984 | if (dhcp_verbose < 2) |
65 | return; | ||
66 | |||
67 | cur = *st_lease_pp; | ||
68 | niro | 532 | while (cur) { |
69 | niro | 984 | bb_info_msg("static lease: mac:%02x:%02x:%02x:%02x:%02x:%02x nip:%x", |
70 | cur->mac[0], cur->mac[1], cur->mac[2], | ||
71 | cur->mac[3], cur->mac[4], cur->mac[5], | ||
72 | cur->nip | ||
73 | ); | ||
74 | niro | 532 | cur = cur->next; |
75 | } | ||
76 | } | ||
77 | #endif |