diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-03-27 22:10:15 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-03-27 22:41:59 +0200 |
commit | e09f5e3045fc90547be9ec49c63b633d103cfc45 (patch) | |
tree | 5044ae5060fec01909714eaab1da3567993cd222 | |
parent | 8f3bf4f0d3605b50a8e4c48c89aeabc455f04884 (diff) | |
download | busybox-w32-e09f5e3045fc90547be9ec49c63b633d103cfc45.tar.gz busybox-w32-e09f5e3045fc90547be9ec49c63b633d103cfc45.tar.bz2 busybox-w32-e09f5e3045fc90547be9ec49c63b633d103cfc45.zip |
udhcp6: read_interface should save link-local ipv6 address
Patch is based on work by tiggerswelt.net. They say:
"Using this patch it was no problem to acquire an IPv6-Address via DHCPv6
using ISC DHCPD6 on server-side."
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/udhcp/d6_common.h | 4 | ||||
-rw-r--r-- | networking/udhcp/d6_dhcpc.c | 11 | ||||
-rw-r--r-- | networking/udhcp/d6_socket.c | 61 |
3 files changed, 71 insertions, 5 deletions
diff --git a/networking/udhcp/d6_common.h b/networking/udhcp/d6_common.h index eb211ea0f..f7cfa4ab8 100644 --- a/networking/udhcp/d6_common.h +++ b/networking/udhcp/d6_common.h | |||
@@ -91,10 +91,14 @@ struct client6_data_t { | |||
91 | struct d6_option *ia_na; | 91 | struct d6_option *ia_na; |
92 | char **env_ptr; | 92 | char **env_ptr; |
93 | unsigned env_idx; | 93 | unsigned env_idx; |
94 | /* link-local IPv6 address */ | ||
95 | struct in6_addr ll_ip6; | ||
94 | }; | 96 | }; |
95 | 97 | ||
96 | #define client6_data (*(struct client6_data_t*)(&bb_common_bufsiz1[COMMON_BUFSIZE - sizeof(struct client6_data_t)])) | 98 | #define client6_data (*(struct client6_data_t*)(&bb_common_bufsiz1[COMMON_BUFSIZE - sizeof(struct client6_data_t)])) |
97 | 99 | ||
100 | int FAST_FUNC d6_read_interface(const char *interface, int *ifindex, struct in6_addr *nip6, uint8_t *mac); | ||
101 | |||
98 | int FAST_FUNC d6_listen_socket(int port, const char *inf); | 102 | int FAST_FUNC d6_listen_socket(int port, const char *inf); |
99 | 103 | ||
100 | int FAST_FUNC d6_recv_kernel_packet( | 104 | int FAST_FUNC d6_recv_kernel_packet( |
diff --git a/networking/udhcp/d6_dhcpc.c b/networking/udhcp/d6_dhcpc.c index bea589d71..95f8939b4 100644 --- a/networking/udhcp/d6_dhcpc.c +++ b/networking/udhcp/d6_dhcpc.c | |||
@@ -311,7 +311,7 @@ static int d6_mcast_from_client_config_ifindex(struct d6_packet *packet, uint8_t | |||
311 | 311 | ||
312 | return d6_send_raw_packet( | 312 | return d6_send_raw_packet( |
313 | packet, (end - (uint8_t*) packet), | 313 | packet, (end - (uint8_t*) packet), |
314 | /*src*/ NULL, CLIENT_PORT6, | 314 | /*src*/ &client6_data.ll_ip6, CLIENT_PORT6, |
315 | /*dst*/ (struct in6_addr*)FF02__1_2, SERVER_PORT6, MAC_BCAST_ADDR, | 315 | /*dst*/ (struct in6_addr*)FF02__1_2, SERVER_PORT6, MAC_BCAST_ADDR, |
316 | client_config.ifindex | 316 | client_config.ifindex |
317 | ); | 317 | ); |
@@ -1003,9 +1003,9 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1003 | udhcp_str2optset(optstr, &client_config.options); | 1003 | udhcp_str2optset(optstr, &client_config.options); |
1004 | } | 1004 | } |
1005 | 1005 | ||
1006 | if (udhcp_read_interface(client_config.interface, | 1006 | if (d6_read_interface(client_config.interface, |
1007 | &client_config.ifindex, | 1007 | &client_config.ifindex, |
1008 | NULL, | 1008 | &client6_data.ll_ip6, |
1009 | client_config.client_mac) | 1009 | client_config.client_mac) |
1010 | ) { | 1010 | ) { |
1011 | return 1; | 1011 | return 1; |
@@ -1106,13 +1106,14 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv) | |||
1106 | * or if the status of the bridge changed). | 1106 | * or if the status of the bridge changed). |
1107 | * Refresh ifindex and client_mac: | 1107 | * Refresh ifindex and client_mac: |
1108 | */ | 1108 | */ |
1109 | if (udhcp_read_interface(client_config.interface, | 1109 | if (d6_read_interface(client_config.interface, |
1110 | &client_config.ifindex, | 1110 | &client_config.ifindex, |
1111 | NULL, | 1111 | &client6_data.ll_ip6, |
1112 | client_config.client_mac) | 1112 | client_config.client_mac) |
1113 | ) { | 1113 | ) { |
1114 | goto ret0; /* iface is gone? */ | 1114 | goto ret0; /* iface is gone? */ |
1115 | } | 1115 | } |
1116 | |||
1116 | memcpy(clientid_mac_ptr, client_config.client_mac, 6); | 1117 | memcpy(clientid_mac_ptr, client_config.client_mac, 6); |
1117 | 1118 | ||
1118 | /* We will restart the wait in any case */ | 1119 | /* We will restart the wait in any case */ |
diff --git a/networking/udhcp/d6_socket.c b/networking/udhcp/d6_socket.c index 910f296a3..930e5e4f5 100644 --- a/networking/udhcp/d6_socket.c +++ b/networking/udhcp/d6_socket.c | |||
@@ -7,6 +7,67 @@ | |||
7 | #include "common.h" | 7 | #include "common.h" |
8 | #include "d6_common.h" | 8 | #include "d6_common.h" |
9 | #include <net/if.h> | 9 | #include <net/if.h> |
10 | #include <ifaddrs.h> | ||
11 | #include <netpacket/packet.h> | ||
12 | |||
13 | int FAST_FUNC d6_read_interface(const char *interface, int *ifindex, struct in6_addr *nip6, uint8_t *mac) | ||
14 | { | ||
15 | int retval = 3; | ||
16 | struct ifaddrs *ifap, *ifa; | ||
17 | |||
18 | getifaddrs(&ifap); | ||
19 | |||
20 | for (ifa = ifap; ifa; ifa = ifa->ifa_next) { | ||
21 | struct sockaddr_in6 *sip6; | ||
22 | |||
23 | if (!ifa->ifa_addr || (strcmp(ifa->ifa_name, interface) != 0)) | ||
24 | continue; | ||
25 | |||
26 | sip6 = (struct sockaddr_in6*)(ifa->ifa_addr); | ||
27 | |||
28 | if (ifa->ifa_addr->sa_family == AF_PACKET) { | ||
29 | struct sockaddr_ll *sll = (struct sockaddr_ll*)(ifa->ifa_addr); | ||
30 | memcpy(mac, sll->sll_addr, 6); | ||
31 | log1("MAC %02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); | ||
32 | log1("adapter index %d", sll->sll_ifindex); | ||
33 | *ifindex = sll->sll_ifindex; | ||
34 | retval &= (0xf - (1<<0)); | ||
35 | } | ||
36 | #if 0 | ||
37 | if (ifa->ifa_addr->sa_family == AF_INET) { | ||
38 | *nip = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr; | ||
39 | log1("IP %s", inet_ntoa(((struct sockaddr_in *)ifa->ifa_addr)->sin_addr)); | ||
40 | } | ||
41 | #endif | ||
42 | if (ifa->ifa_addr->sa_family == AF_INET6 | ||
43 | && IN6_IS_ADDR_LINKLOCAL(&sip6->sin6_addr) | ||
44 | ) { | ||
45 | *nip6 = sip6->sin6_addr; /* struct copy */ | ||
46 | log1( | ||
47 | "IPv6 %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", | ||
48 | nip6->s6_addr[0], nip6->s6_addr[1], | ||
49 | nip6->s6_addr[2], nip6->s6_addr[3], | ||
50 | nip6->s6_addr[4], nip6->s6_addr[5], | ||
51 | nip6->s6_addr[6], nip6->s6_addr[7], | ||
52 | nip6->s6_addr[8], nip6->s6_addr[9], | ||
53 | nip6->s6_addr[10], nip6->s6_addr[11], | ||
54 | nip6->s6_addr[12], nip6->s6_addr[13], | ||
55 | nip6->s6_addr[14], nip6->s6_addr[15] | ||
56 | ); | ||
57 | retval &= (0xf - (1<<1)); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | freeifaddrs(ifap); | ||
62 | if (retval == 0) | ||
63 | return retval; | ||
64 | |||
65 | if (retval & (1<<0)) | ||
66 | bb_error_msg("can't get %s", "MAC"); | ||
67 | if (retval & (1<<1)) | ||
68 | bb_error_msg("can't get %s", "link-local IPv6 address"); | ||
69 | return -1; | ||
70 | } | ||
10 | 71 | ||
11 | int FAST_FUNC d6_listen_socket(int port, const char *inf) | 72 | int FAST_FUNC d6_listen_socket(int port, const char *inf) |
12 | { | 73 | { |