2 * $Id: device-bsd44.c,v 1.29 2011/02/06 03:41:38 reubenhwk Exp $
5 * Craig Metz <cmetz@inner.net>
7 * This software is Copyright 1996,1997 by the above mentioned author(s),
10 * The license which is distributed with this software in the file COPYRIGHT
11 * applies to this software. If your distribution is missing this file, you
12 * may request it from <pekkas@netcore.fi>.
20 #include "pathnames.h" /* for PATH_PROC_NET_IF_INET6 */
22 static uint8_t ll_prefix
[] = { 0xfe, 0x80 };
25 * this function gets the hardware type and address of an interface,
26 * determines the link layer token length and checks it against
27 * the defined prefixes
30 setup_deviceinfo(struct Interface
*iface
)
32 struct ifaddrs
*addresses
= 0, *ifa
;
35 struct AdvPrefix
*prefix
;
36 char zero
[sizeof(iface
->if_addr
)];
38 if(if_nametoindex(iface
->Name
) == 0){
39 flog(LOG_ERR
, "%s not found: %s", iface
->Name
, strerror(errno
));
43 memset(&ifr
, 0, sizeof(ifr
));
44 strncpy(ifr
.ifr_name
, iface
->Name
, IFNAMSIZ
-1);
45 ifr
.ifr_name
[IFNAMSIZ
-1] = '\0';
47 if (ioctl(sock
, SIOCGIFMTU
, &ifr
) < 0) {
48 flog(LOG_ERR
, "ioctl(SIOCGIFMTU) failed for %s: %s", iface
->Name
, strerror(errno
));
52 dlog(LOG_DEBUG
, 3, "mtu for %s is %d", iface
->Name
, ifr
.ifr_mtu
);
53 iface
->if_maxmtu
= ifr
.ifr_mtu
;
55 if (getifaddrs(&addresses
) != 0)
57 flog(LOG_ERR
, "getifaddrs failed: %s(%d)", strerror(errno
), errno
);
61 for (ifa
= addresses
; ifa
!= NULL
; ifa
= ifa
->ifa_next
)
63 if (strcmp(ifa
->ifa_name
, iface
->Name
) != 0)
66 if (ifa
->ifa_addr
== NULL
)
69 if (ifa
->ifa_addr
->sa_family
!= AF_LINK
)
72 struct sockaddr_dl
*dl
= (struct sockaddr_dl
*)ifa
->ifa_addr
;
75 if (dl
->sdl_alen
> sizeof(iface
->if_addr
))
77 flog(LOG_ERR
, "address length %d too big for",
83 memcpy(iface
->if_hwaddr
, LLADDR(dl
), dl
->sdl_alen
);
84 iface
->if_hwaddr_len
= dl
->sdl_alen
<< 3;
86 switch(dl
->sdl_type
) {
89 iface
->if_prefix_len
= 64;
92 iface
->if_prefix_len
= 64;
95 iface
->if_prefix_len
= -1;
96 iface
->if_maxmtu
= -1;
100 dlog(LOG_DEBUG
, 3, "link layer token length for %s is %d", iface
->Name
,
101 iface
->if_hwaddr_len
);
103 dlog(LOG_DEBUG
, 3, "prefix length for %s is %d", iface
->Name
,
104 iface
->if_prefix_len
);
106 if (iface
->if_prefix_len
!= -1) {
107 memset(zero
, 0, dl
->sdl_alen
);
108 if (!memcmp(iface
->if_hwaddr
, zero
, dl
->sdl_alen
))
109 flog(LOG_WARNING
, "WARNING, MAC address on %s is all zero!",
113 prefix
= iface
->AdvPrefixList
;
116 if ((iface
->if_prefix_len
!= -1) &&
117 (iface
->if_prefix_len
!= prefix
->PrefixLen
))
119 flog(LOG_WARNING
, "prefix length should be %d for %s",
120 iface
->if_prefix_len
, iface
->Name
);
123 prefix
= prefix
->next
;
126 freeifaddrs(addresses
);
132 iface
->if_maxmtu
= -1;
133 iface
->if_hwaddr_len
= -1;
134 iface
->if_prefix_len
= -1;
136 freeifaddrs(addresses
);
141 * Saves the first link local address seen on the specified interface to iface->if_addr
144 int setup_linklocal_addr(struct Interface
*iface
)
146 struct ifaddrs
*addresses
= 0, *ifa
;
148 if (getifaddrs(&addresses
) != 0)
150 flog(LOG_ERR
, "getifaddrs failed: %s(%d)", strerror(errno
), errno
);
154 for (ifa
= addresses
; ifa
!= NULL
; ifa
= ifa
->ifa_next
)
156 if (strcmp(ifa
->ifa_name
, iface
->Name
) != 0)
159 if (ifa
->ifa_addr
== NULL
)
162 if (ifa
->ifa_addr
->sa_family
== AF_LINK
) {
163 struct sockaddr_dl
*dl
= (struct sockaddr_dl
*)ifa
->ifa_addr
;
164 if (memcmp(iface
->Name
, dl
->sdl_data
, dl
->sdl_nlen
) == 0)
165 iface
->if_index
= dl
->sdl_index
;
169 if (ifa
->ifa_addr
->sa_family
!= AF_INET6
)
172 struct sockaddr_in6
*a6
= (struct sockaddr_in6
*)ifa
->ifa_addr
;
174 /* Skip if it is not a linklocal address */
175 if (memcmp(&(a6
->sin6_addr
), ll_prefix
, sizeof(ll_prefix
)) != 0)
178 memcpy(&iface
->if_addr
, &(a6
->sin6_addr
), sizeof(struct in6_addr
));
179 freeifaddrs(addresses
);
185 freeifaddrs(addresses
);
186 flog(LOG_ERR
, "no linklocal address configured for %s", iface
->Name
);
190 int setup_allrouters_membership(struct Interface
*iface
)
195 int check_allrouters_membership(struct Interface
*iface
)
201 set_interface_linkmtu(const char *iface
, uint32_t mtu
)
203 dlog(LOG_DEBUG
, 4, "setting LinkMTU (%u) for %s is not supported",
209 set_interface_curhlim(const char *iface
, uint8_t hlim
)
211 dlog(LOG_DEBUG
, 4, "setting CurHopLimit (%u) for %s is not supported",
217 set_interface_reachtime(const char *iface
, uint32_t rtime
)
219 dlog(LOG_DEBUG
, 4, "setting BaseReachableTime (%u) for %s is not supported",
225 set_interface_retranstimer(const char *iface
, uint32_t rettimer
)
227 dlog(LOG_DEBUG
, 4, "setting RetransTimer (%u) for %s is not supported",