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>
This commit is contained in:
parent
8f3bf4f0d3
commit
e09f5e3045
@ -91,10 +91,14 @@ struct client6_data_t {
|
|||||||
struct d6_option *ia_na;
|
struct d6_option *ia_na;
|
||||||
char **env_ptr;
|
char **env_ptr;
|
||||||
unsigned env_idx;
|
unsigned env_idx;
|
||||||
|
/* link-local IPv6 address */
|
||||||
|
struct in6_addr ll_ip6;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define client6_data (*(struct client6_data_t*)(&bb_common_bufsiz1[COMMON_BUFSIZE - sizeof(struct client6_data_t)]))
|
#define client6_data (*(struct client6_data_t*)(&bb_common_bufsiz1[COMMON_BUFSIZE - sizeof(struct client6_data_t)]))
|
||||||
|
|
||||||
|
int FAST_FUNC d6_read_interface(const char *interface, int *ifindex, struct in6_addr *nip6, uint8_t *mac);
|
||||||
|
|
||||||
int FAST_FUNC d6_listen_socket(int port, const char *inf);
|
int FAST_FUNC d6_listen_socket(int port, const char *inf);
|
||||||
|
|
||||||
int FAST_FUNC d6_recv_kernel_packet(
|
int FAST_FUNC d6_recv_kernel_packet(
|
||||||
|
@ -311,7 +311,7 @@ static int d6_mcast_from_client_config_ifindex(struct d6_packet *packet, uint8_t
|
|||||||
|
|
||||||
return d6_send_raw_packet(
|
return d6_send_raw_packet(
|
||||||
packet, (end - (uint8_t*) packet),
|
packet, (end - (uint8_t*) packet),
|
||||||
/*src*/ NULL, CLIENT_PORT6,
|
/*src*/ &client6_data.ll_ip6, CLIENT_PORT6,
|
||||||
/*dst*/ (struct in6_addr*)FF02__1_2, SERVER_PORT6, MAC_BCAST_ADDR,
|
/*dst*/ (struct in6_addr*)FF02__1_2, SERVER_PORT6, MAC_BCAST_ADDR,
|
||||||
client_config.ifindex
|
client_config.ifindex
|
||||||
);
|
);
|
||||||
@ -1003,9 +1003,9 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
udhcp_str2optset(optstr, &client_config.options);
|
udhcp_str2optset(optstr, &client_config.options);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (udhcp_read_interface(client_config.interface,
|
if (d6_read_interface(client_config.interface,
|
||||||
&client_config.ifindex,
|
&client_config.ifindex,
|
||||||
NULL,
|
&client6_data.ll_ip6,
|
||||||
client_config.client_mac)
|
client_config.client_mac)
|
||||||
) {
|
) {
|
||||||
return 1;
|
return 1;
|
||||||
@ -1106,13 +1106,14 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
* or if the status of the bridge changed).
|
* or if the status of the bridge changed).
|
||||||
* Refresh ifindex and client_mac:
|
* Refresh ifindex and client_mac:
|
||||||
*/
|
*/
|
||||||
if (udhcp_read_interface(client_config.interface,
|
if (d6_read_interface(client_config.interface,
|
||||||
&client_config.ifindex,
|
&client_config.ifindex,
|
||||||
NULL,
|
&client6_data.ll_ip6,
|
||||||
client_config.client_mac)
|
client_config.client_mac)
|
||||||
) {
|
) {
|
||||||
goto ret0; /* iface is gone? */
|
goto ret0; /* iface is gone? */
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(clientid_mac_ptr, client_config.client_mac, 6);
|
memcpy(clientid_mac_ptr, client_config.client_mac, 6);
|
||||||
|
|
||||||
/* We will restart the wait in any case */
|
/* We will restart the wait in any case */
|
||||||
|
@ -7,6 +7,67 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "d6_common.h"
|
#include "d6_common.h"
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
|
#include <ifaddrs.h>
|
||||||
|
#include <netpacket/packet.h>
|
||||||
|
|
||||||
|
int FAST_FUNC d6_read_interface(const char *interface, int *ifindex, struct in6_addr *nip6, uint8_t *mac)
|
||||||
|
{
|
||||||
|
int retval = 3;
|
||||||
|
struct ifaddrs *ifap, *ifa;
|
||||||
|
|
||||||
|
getifaddrs(&ifap);
|
||||||
|
|
||||||
|
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
|
||||||
|
struct sockaddr_in6 *sip6;
|
||||||
|
|
||||||
|
if (!ifa->ifa_addr || (strcmp(ifa->ifa_name, interface) != 0))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
sip6 = (struct sockaddr_in6*)(ifa->ifa_addr);
|
||||||
|
|
||||||
|
if (ifa->ifa_addr->sa_family == AF_PACKET) {
|
||||||
|
struct sockaddr_ll *sll = (struct sockaddr_ll*)(ifa->ifa_addr);
|
||||||
|
memcpy(mac, sll->sll_addr, 6);
|
||||||
|
log1("MAC %02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
|
log1("adapter index %d", sll->sll_ifindex);
|
||||||
|
*ifindex = sll->sll_ifindex;
|
||||||
|
retval &= (0xf - (1<<0));
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
if (ifa->ifa_addr->sa_family == AF_INET) {
|
||||||
|
*nip = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
|
||||||
|
log1("IP %s", inet_ntoa(((struct sockaddr_in *)ifa->ifa_addr)->sin_addr));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (ifa->ifa_addr->sa_family == AF_INET6
|
||||||
|
&& IN6_IS_ADDR_LINKLOCAL(&sip6->sin6_addr)
|
||||||
|
) {
|
||||||
|
*nip6 = sip6->sin6_addr; /* struct copy */
|
||||||
|
log1(
|
||||||
|
"IPv6 %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
|
||||||
|
nip6->s6_addr[0], nip6->s6_addr[1],
|
||||||
|
nip6->s6_addr[2], nip6->s6_addr[3],
|
||||||
|
nip6->s6_addr[4], nip6->s6_addr[5],
|
||||||
|
nip6->s6_addr[6], nip6->s6_addr[7],
|
||||||
|
nip6->s6_addr[8], nip6->s6_addr[9],
|
||||||
|
nip6->s6_addr[10], nip6->s6_addr[11],
|
||||||
|
nip6->s6_addr[12], nip6->s6_addr[13],
|
||||||
|
nip6->s6_addr[14], nip6->s6_addr[15]
|
||||||
|
);
|
||||||
|
retval &= (0xf - (1<<1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
freeifaddrs(ifap);
|
||||||
|
if (retval == 0)
|
||||||
|
return retval;
|
||||||
|
|
||||||
|
if (retval & (1<<0))
|
||||||
|
bb_error_msg("can't get %s", "MAC");
|
||||||
|
if (retval & (1<<1))
|
||||||
|
bb_error_msg("can't get %s", "link-local IPv6 address");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int FAST_FUNC d6_listen_socket(int port, const char *inf)
|
int FAST_FUNC d6_listen_socket(int port, const char *inf)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user