aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/d6_socket.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/d6_socket.c')
-rw-r--r--networking/udhcp/d6_socket.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/networking/udhcp/d6_socket.c b/networking/udhcp/d6_socket.c
index d00c217d6..315c8d98a 100644
--- a/networking/udhcp/d6_socket.c
+++ b/networking/udhcp/d6_socket.c
@@ -16,7 +16,6 @@ int FAST_FUNC d6_read_interface(const char *interface, int *ifindex, struct in6_
16 struct ifaddrs *ifap, *ifa; 16 struct ifaddrs *ifap, *ifa;
17 17
18 getifaddrs(&ifap); 18 getifaddrs(&ifap);
19
20 for (ifa = ifap; ifa; ifa = ifa->ifa_next) { 19 for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
21 struct sockaddr_in6 *sip6; 20 struct sockaddr_in6 *sip6;
22 21
@@ -29,9 +28,9 @@ int FAST_FUNC d6_read_interface(const char *interface, int *ifindex, struct in6_
29 struct sockaddr_ll *sll = (struct sockaddr_ll*)(ifa->ifa_addr); 28 struct sockaddr_ll *sll = (struct sockaddr_ll*)(ifa->ifa_addr);
30 memcpy(mac, sll->sll_addr, 6); 29 memcpy(mac, sll->sll_addr, 6);
31 log2("MAC %02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 30 log2("MAC %02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
32 log2("ifindex %d", sll->sll_ifindex);
33 *ifindex = sll->sll_ifindex; 31 *ifindex = sll->sll_ifindex;
34 retval &= (0xf - (1<<0)); 32 log2("ifindex %d", *ifindex);
33 retval &= (3 - (1<<0));
35 } 34 }
36#if 0 35#if 0
37 if (ifa->ifa_addr->sa_family == AF_INET) { 36 if (ifa->ifa_addr->sa_family == AF_INET) {
@@ -54,11 +53,33 @@ int FAST_FUNC d6_read_interface(const char *interface, int *ifindex, struct in6_
54 nip6->s6_addr[12], nip6->s6_addr[13], 53 nip6->s6_addr[12], nip6->s6_addr[13],
55 nip6->s6_addr[14], nip6->s6_addr[15] 54 nip6->s6_addr[14], nip6->s6_addr[15]
56 ); 55 );
57 retval &= (0xf - (1<<1)); 56 retval &= (3 - (1<<1));
58 } 57 }
59 } 58 }
60
61 freeifaddrs(ifap); 59 freeifaddrs(ifap);
60
61 if (retval & (1<<0)) {
62 /* This iface has no MAC (e.g. ppp), generate a random one */
63 struct ifreq ifr;
64 int fd;
65
66 memset(&ifr, 0, sizeof(ifr));
67 strncpy_IFNAMSIZ(ifr.ifr_name, interface);
68 fd = xsocket(AF_INET6, SOCK_RAW, IPPROTO_RAW);
69 if (ioctl(fd, SIOCGIFINDEX, &ifr) == 0) {
70 *ifindex = ifr.ifr_ifindex;
71 log2("ifindex %d", *ifindex);
72 if (((uint32_t*)mac)[0] == 0) {
73 /* invent a fictitious MAC (once) */
74 ((uint32_t*)mac)[0] = rand();
75 ((uint16_t*)mac)[2] = rand();
76 mac[0] &= 0xfc; /* make sure it's not bcast */
77 }
78 retval &= (3 - (1<<0));
79 }
80 close(fd);
81 }
82
62 if (retval == 0) 83 if (retval == 0)
63 return retval; 84 return retval;
64 85