4 * Craig Metz <cmetz@inner.net>
6 * This software is Copyright 1996,1997 by the above mentioned author(s),
9 * The license which is distributed with this software in the file COPYRIGHT
10 * applies to this software. If your distribution is missing this file, you
11 * may request it from <pekkas@netcore.fi>.
19 #include "pathnames.h" /* for PATH_PROC_NET_IF_INET6 */
21 static uint8_t ll_prefix
[] = { 0xfe, 0x80 };
24 * this function gets the hardware type and address of an interface,
25 * determines the link layer token length and checks it against
26 * the defined prefixes
29 setup_deviceinfo(struct Interface
*iface
)
31 struct ifaddrs
*addresses
= 0, *ifa
;
34 struct AdvPrefix
*prefix
;
35 char zero
[sizeof(iface
->if_addr
)];
37 if(if_nametoindex(iface
->Name
) == 0){
38 flog(LOG_ERR
, "%s not found: %s", iface
->Name
, strerror(errno
));
42 memset(&ifr
, 0, sizeof(ifr
));
43 strncpy(ifr
.ifr_name
, iface
->Name
, IFNAMSIZ
-1);
44 ifr
.ifr_name
[IFNAMSIZ
-1] = '\0';
46 if (ioctl(sock
, SIOCGIFMTU
, &ifr
) < 0) {
47 flog(LOG_ERR
, "ioctl(SIOCGIFMTU) failed for %s: %s", iface
->Name
, strerror(errno
));
51 dlog(LOG_DEBUG
, 3, "mtu for %s is %d", iface
->Name
, ifr
.ifr_mtu
);
52 iface
->if_maxmtu
= ifr
.ifr_mtu
;
54 if (getifaddrs(&addresses
) != 0)
56 flog(LOG_ERR
, "getifaddrs failed: %s(%d)", strerror(errno
), errno
);
60 for (ifa
= addresses
; ifa
!= NULL
; ifa
= ifa
->ifa_next
)
62 if (strcmp(ifa
->ifa_name
, iface
->Name
) != 0)
65 if (ifa
->ifa_addr
== NULL
)
68 if (ifa
->ifa_addr
->sa_family
!= AF_LINK
)
71 struct sockaddr_dl
*dl
= (struct sockaddr_dl
*)ifa
->ifa_addr
;
74 if (dl
->sdl_alen
> sizeof(iface
->if_addr
))
76 flog(LOG_ERR
, "address length %d too big for",
82 memcpy(iface
->if_hwaddr
, LLADDR(dl
), dl
->sdl_alen
);
83 iface
->if_hwaddr_len
= dl
->sdl_alen
<< 3;
85 switch(dl
->sdl_type
) {
88 iface
->if_prefix_len
= 64;
91 iface
->if_prefix_len
= 64;
94 iface
->if_prefix_len
= -1;
95 iface
->if_maxmtu
= -1;
99 dlog(LOG_DEBUG
, 3, "link layer token length for %s is %d", iface
->Name
,
100 iface
->if_hwaddr_len
);
102 dlog(LOG_DEBUG
, 3, "prefix length for %s is %d", iface
->Name
,
103 iface
->if_prefix_len
);
105 if (iface
->if_prefix_len
!= -1) {
106 memset(zero
, 0, dl
->sdl_alen
);
107 if (!memcmp(iface
->if_hwaddr
, zero
, dl
->sdl_alen
))
108 flog(LOG_WARNING
, "WARNING, MAC address on %s is all zero!",
112 prefix
= iface
->AdvPrefixList
;
115 if ((iface
->if_prefix_len
!= -1) &&
116 (iface
->if_prefix_len
!= prefix
->PrefixLen
))
118 flog(LOG_WARNING
, "prefix length should be %d for %s",
119 iface
->if_prefix_len
, iface
->Name
);
122 prefix
= prefix
->next
;
125 freeifaddrs(addresses
);
131 iface
->if_maxmtu
= -1;
132 iface
->if_hwaddr_len
= -1;
133 iface
->if_prefix_len
= -1;
135 freeifaddrs(addresses
);
140 * Saves the first link local address seen on the specified interface to iface->if_addr
143 int setup_linklocal_addr(struct Interface
*iface
)
145 struct ifaddrs
*addresses
= 0, *ifa
;
147 if (getifaddrs(&addresses
) != 0)
149 flog(LOG_ERR
, "getifaddrs failed: %s(%d)", strerror(errno
), errno
);
153 for (ifa
= addresses
; ifa
!= NULL
; ifa
= ifa
->ifa_next
)
155 if (strcmp(ifa
->ifa_name
, iface
->Name
) != 0)
158 if (ifa
->ifa_addr
== NULL
)
161 if (ifa
->ifa_addr
->sa_family
== AF_LINK
) {
162 struct sockaddr_dl
*dl
= (struct sockaddr_dl
*)ifa
->ifa_addr
;
163 if (memcmp(iface
->Name
, dl
->sdl_data
, dl
->sdl_nlen
) == 0)
164 iface
->if_index
= dl
->sdl_index
;
168 if (ifa
->ifa_addr
->sa_family
!= AF_INET6
)
171 struct sockaddr_in6
*a6
= (struct sockaddr_in6
*)ifa
->ifa_addr
;
173 /* Skip if it is not a linklocal address */
174 if (memcmp(&(a6
->sin6_addr
), ll_prefix
, sizeof(ll_prefix
)) != 0)
177 memcpy(&iface
->if_addr
, &(a6
->sin6_addr
), sizeof(struct in6_addr
));
178 freeifaddrs(addresses
);
184 freeifaddrs(addresses
);
185 flog(LOG_ERR
, "no linklocal address configured for %s", iface
->Name
);
189 int setup_allrouters_membership(struct Interface
*iface
)
194 int check_allrouters_membership(struct Interface
*iface
)
200 set_interface_linkmtu(const char *iface
, uint32_t mtu
)
202 dlog(LOG_DEBUG
, 4, "setting LinkMTU (%u) for %s is not supported",
208 set_interface_curhlim(const char *iface
, uint8_t hlim
)
210 dlog(LOG_DEBUG
, 4, "setting CurHopLimit (%u) for %s is not supported",
216 set_interface_reachtime(const char *iface
, uint32_t rtime
)
218 dlog(LOG_DEBUG
, 4, "setting BaseReachableTime (%u) for %s is not supported",
224 set_interface_retranstimer(const char *iface
, uint32_t rettimer
)
226 dlog(LOG_DEBUG
, 4, "setting RetransTimer (%u) for %s is not supported",