Don't enable dnsmasq IPSET functionality on 2.4 kernel
[tomato.git] / release / src / router / radvd / device-bsd44.c
blob8cd82e9ee1b99246cd83589291431b4ac75df917
1 /*
3 * Authors:
4 * Craig Metz <cmetz@inner.net>
6 * This software is Copyright 1996,1997 by the above mentioned author(s),
7 * All Rights Reserved.
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>.
15 #include "config.h"
16 #include "includes.h"
17 #include "radvd.h"
18 #include "defaults.h"
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
28 int
29 setup_deviceinfo(struct Interface *iface)
31 struct ifaddrs *addresses = 0, *ifa;
33 struct ifreq ifr;
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));
39 goto ret;
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));
48 goto ret;
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);
57 goto ret;
60 for (ifa = addresses; ifa != NULL; ifa = ifa->ifa_next)
62 if (strcmp(ifa->ifa_name, iface->Name) != 0)
63 continue;
65 if (ifa->ifa_addr == NULL)
66 continue;
68 if (ifa->ifa_addr->sa_family != AF_LINK)
69 continue;
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",
77 dl->sdl_alen,
78 iface->Name);
79 goto ret;
82 memcpy(iface->if_hwaddr, LLADDR(dl), dl->sdl_alen);
83 iface->if_hwaddr_len = dl->sdl_alen << 3;
85 switch(dl->sdl_type) {
86 case IFT_ETHER:
87 case IFT_ISO88023:
88 iface->if_prefix_len = 64;
89 break;
90 case IFT_FDDI:
91 iface->if_prefix_len = 64;
92 break;
93 default:
94 iface->if_prefix_len = -1;
95 iface->if_maxmtu = -1;
96 break;
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!",
109 iface->Name);
112 prefix = iface->AdvPrefixList;
113 while (prefix)
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);
126 return 0;
130 ret:
131 iface->if_maxmtu = -1;
132 iface->if_hwaddr_len = -1;
133 iface->if_prefix_len = -1;
134 if (addresses != 0)
135 freeifaddrs(addresses);
136 return -1;
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);
150 goto ret;
153 for (ifa = addresses; ifa != NULL; ifa = ifa->ifa_next)
155 if (strcmp(ifa->ifa_name, iface->Name) != 0)
156 continue;
158 if (ifa->ifa_addr == NULL)
159 continue;
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;
165 continue;
168 if (ifa->ifa_addr->sa_family != AF_INET6)
169 continue;
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)
175 continue;
177 memcpy(&iface->if_addr, &(a6->sin6_addr), sizeof(struct in6_addr));
178 freeifaddrs(addresses);
179 return 0;
182 ret:
183 if(addresses)
184 freeifaddrs(addresses);
185 flog(LOG_ERR, "no linklocal address configured for %s", iface->Name);
186 return -1;
189 int setup_allrouters_membership(struct Interface *iface)
191 return (0);
194 int check_allrouters_membership(struct Interface *iface)
196 return (0);
200 set_interface_linkmtu(const char *iface, uint32_t mtu)
202 dlog(LOG_DEBUG, 4, "setting LinkMTU (%u) for %s is not supported",
203 mtu, iface);
204 return -1;
208 set_interface_curhlim(const char *iface, uint8_t hlim)
210 dlog(LOG_DEBUG, 4, "setting CurHopLimit (%u) for %s is not supported",
211 hlim, iface);
212 return -1;
216 set_interface_reachtime(const char *iface, uint32_t rtime)
218 dlog(LOG_DEBUG, 4, "setting BaseReachableTime (%u) for %s is not supported",
219 rtime, iface);
220 return -1;
224 set_interface_retranstimer(const char *iface, uint32_t rettimer)
226 dlog(LOG_DEBUG, 4, "setting RetransTimer (%u) for %s is not supported",
227 rettimer, iface);
228 return -1;