Reinstate dropbear 0.54 update
[tomato.git] / release / src / router / radvd / interface.c
blobabdbc89adbe5c376860223b8aaa20c54a35f6345
1 /*
2 * $Id: interface.c,v 1.27 2011/04/28 15:08:40 reubenhwk Exp $
4 * Authors:
5 * Lars Fenneberg <lf@elemental.net>
7 * This software is Copyright 1996,1997 by the above mentioned author(s),
8 * All Rights Reserved.
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>.
16 #include "config.h"
17 #include "includes.h"
18 #include "radvd.h"
19 #include "defaults.h"
21 void
22 iface_init_defaults(struct Interface *iface)
24 memset(iface, 0, sizeof(struct Interface));
26 iface->cease_adv = 0;
28 iface->HasFailed = 0;
29 iface->IgnoreIfMissing = DFLT_IgnoreIfMissing;
30 iface->AdvSendAdvert = DFLT_AdvSendAdv;
31 iface->MaxRtrAdvInterval = DFLT_MaxRtrAdvInterval;
32 iface->AdvSourceLLAddress = DFLT_AdvSourceLLAddress;
33 iface->AdvReachableTime = DFLT_AdvReachableTime;
34 iface->AdvRetransTimer = DFLT_AdvRetransTimer;
35 iface->AdvLinkMTU = DFLT_AdvLinkMTU;
36 iface->AdvCurHopLimit = DFLT_AdvCurHopLimit;
37 iface->AdvIntervalOpt = DFLT_AdvIntervalOpt;
38 iface->AdvHomeAgentInfo = DFLT_AdvHomeAgentInfo;
39 iface->AdvHomeAgentFlag = DFLT_AdvHomeAgentFlag;
40 iface->HomeAgentPreference = DFLT_HomeAgentPreference;
41 iface->MinDelayBetweenRAs = DFLT_MinDelayBetweenRAs;
42 iface->AdvMobRtrSupportFlag = DFLT_AdvMobRtrSupportFlag;
44 iface->MinRtrAdvInterval = -1;
45 iface->AdvDefaultLifetime = -1;
46 iface->AdvDefaultPreference = DFLT_AdvDefaultPreference;
47 iface->HomeAgentLifetime = -1;
50 void
51 prefix_init_defaults(struct AdvPrefix *prefix)
53 memset(prefix, 0, sizeof(struct AdvPrefix));
55 prefix->AdvOnLinkFlag = DFLT_AdvOnLinkFlag;
56 prefix->AdvAutonomousFlag = DFLT_AdvAutonomousFlag;
57 prefix->AdvRouterAddr = DFLT_AdvRouterAddr;
58 prefix->AdvValidLifetime = DFLT_AdvValidLifetime;
59 prefix->AdvPreferredLifetime = DFLT_AdvPreferredLifetime;
60 prefix->DeprecatePrefixFlag = DFLT_DeprecatePrefixFlag;
61 prefix->DecrementLifetimesFlag = DFLT_DecrementLifetimesFlag;
62 prefix->if6to4[0] = 0;
63 prefix->enabled = 1;
65 prefix->curr_validlft = prefix->AdvValidLifetime;
66 prefix->curr_preferredlft = prefix->AdvPreferredLifetime;
69 void
70 route_init_defaults(struct AdvRoute *route, struct Interface *iface)
72 memset(route, 0, sizeof(struct AdvRoute));
74 route->AdvRouteLifetime = DFLT_AdvRouteLifetime(iface);
75 route->AdvRoutePreference = DFLT_AdvRoutePreference;
76 route->RemoveRouteFlag = DFLT_RemoveRouteFlag;
79 void
80 rdnss_init_defaults(struct AdvRDNSS *rdnss, struct Interface *iface)
82 memset(rdnss, 0, sizeof(struct AdvRDNSS));
84 rdnss->AdvRDNSSLifetime = DFLT_AdvRDNSSLifetime(iface);
85 rdnss->AdvRDNSSNumber = 0;
86 rdnss->FlushRDNSSFlag = DFLT_FlushRDNSSFlag;
89 void
90 dnssl_init_defaults(struct AdvDNSSL *dnssl, struct Interface *iface)
92 memset(dnssl, 0, sizeof(struct AdvDNSSL));
94 dnssl->AdvDNSSLLifetime = DFLT_AdvDNSSLLifetime(iface);
95 dnssl->FlushDNSSLFlag = DFLT_FlushDNSSLFlag;
98 int
99 check_iface(struct Interface *iface)
101 struct AdvPrefix *prefix;
102 struct AdvRoute *route;
103 int res = 0;
104 int MIPv6 = 0;
106 /* Check if we use Mobile IPv6 extensions */
107 if (iface->AdvHomeAgentFlag || iface->AdvHomeAgentInfo ||
108 iface->AdvIntervalOpt)
110 MIPv6 = 1;
111 flog(LOG_INFO, "using Mobile IPv6 extensions");
114 prefix = iface->AdvPrefixList;
115 while (!MIPv6 && prefix)
117 if (prefix->AdvRouterAddr)
119 MIPv6 = 1;
121 prefix = prefix->next;
124 if (iface->MinRtrAdvInterval < 0)
125 iface->MinRtrAdvInterval = DFLT_MinRtrAdvInterval(iface);
127 if ((iface->MinRtrAdvInterval < (MIPv6 ? MIN_MinRtrAdvInterval_MIPv6 : MIN_MinRtrAdvInterval)) ||
128 (iface->MinRtrAdvInterval > MAX_MinRtrAdvInterval(iface)))
130 flog(LOG_ERR,
131 "MinRtrAdvInterval for %s (%.2f) must be at least %.2f but no more than 3/4 of MaxRtrAdvInterval (%.2f)",
132 iface->Name, iface->MinRtrAdvInterval,
133 MIPv6 ? MIN_MinRtrAdvInterval_MIPv6 : (int)MIN_MinRtrAdvInterval,
134 MAX_MinRtrAdvInterval(iface));
135 res = -1;
138 if ((iface->MaxRtrAdvInterval < (MIPv6 ? MIN_MaxRtrAdvInterval_MIPv6 : MIN_MaxRtrAdvInterval))
139 || (iface->MaxRtrAdvInterval > MAX_MaxRtrAdvInterval))
141 flog(LOG_ERR,
142 "MaxRtrAdvInterval for %s (%.2f) must be between %.2f and %d",
143 iface->Name, iface->MaxRtrAdvInterval,
144 MIPv6 ? MIN_MaxRtrAdvInterval_MIPv6 : (int)MIN_MaxRtrAdvInterval,
145 MAX_MaxRtrAdvInterval);
146 res = -1;
149 if (iface->MinDelayBetweenRAs < (MIPv6 ? MIN_DELAY_BETWEEN_RAS_MIPv6 : MIN_DELAY_BETWEEN_RAS))
151 flog(LOG_ERR,
152 "MinDelayBetweenRAs for %s (%.2f) must be at least %.2f",
153 iface->Name, iface->MinDelayBetweenRAs,
154 MIPv6 ? MIN_DELAY_BETWEEN_RAS_MIPv6 : MIN_DELAY_BETWEEN_RAS);
155 res = -1;
158 if ((iface->AdvLinkMTU != 0) &&
159 ((iface->AdvLinkMTU < MIN_AdvLinkMTU) ||
160 (iface->if_maxmtu != -1 && (iface->AdvLinkMTU > iface->if_maxmtu))))
162 flog(LOG_ERR, "AdvLinkMTU for %s (%u) must be zero or between %u and %u",
163 iface->Name, iface->AdvLinkMTU, MIN_AdvLinkMTU, iface->if_maxmtu);
164 res = -1;
167 if (iface->AdvReachableTime > MAX_AdvReachableTime)
169 flog(LOG_ERR,
170 "AdvReachableTime for %s (%u) must not be greater than %u",
171 iface->Name, iface->AdvReachableTime, MAX_AdvReachableTime);
172 res = -1;
175 if (iface->AdvDefaultLifetime < 0)
176 iface->AdvDefaultLifetime = DFLT_AdvDefaultLifetime(iface);
178 if ((iface->AdvDefaultLifetime != 0) &&
179 ((iface->AdvDefaultLifetime > MAX_AdvDefaultLifetime) ||
180 (iface->AdvDefaultLifetime < MIN_AdvDefaultLifetime(iface))))
182 flog(LOG_ERR,
183 "AdvDefaultLifetime for %s (%u) must be zero or between %u and %u",
184 iface->Name, iface->AdvDefaultLifetime, (int)MIN_AdvDefaultLifetime(iface),
185 MAX_AdvDefaultLifetime);
186 res = -1;
189 /* Mobile IPv6 ext */
190 if (iface->HomeAgentLifetime < 0)
191 iface->HomeAgentLifetime = DFLT_HomeAgentLifetime(iface);
193 /* Mobile IPv6 ext */
194 if (iface->AdvHomeAgentInfo)
196 if ((iface->HomeAgentLifetime > MAX_HomeAgentLifetime) ||
197 (iface->HomeAgentLifetime < MIN_HomeAgentLifetime))
199 flog(LOG_ERR,
200 "HomeAgentLifetime for %s (%u) must be between %u and %u",
201 iface->Name, iface->HomeAgentLifetime,
202 MIN_HomeAgentLifetime, MAX_HomeAgentLifetime);
203 res = -1;
207 /* Mobile IPv6 ext */
208 if (iface->AdvHomeAgentInfo && !(iface->AdvHomeAgentFlag))
210 flog(LOG_ERR,
211 "AdvHomeAgentFlag for %s must be set with HomeAgentInfo", iface->Name);
212 res = -1;
214 if (iface->AdvMobRtrSupportFlag && !(iface->AdvHomeAgentInfo))
216 flog(LOG_ERR,
217 "AdvHomeAgentInfo for %s must be set with AdvMobRtrSupportFlag", iface->Name);
218 res = -1;
221 /* XXX: need this? prefix = iface->AdvPrefixList; */
223 while (prefix)
225 if (prefix->PrefixLen > MAX_PrefixLen)
227 flog(LOG_ERR, "invalid prefix length (%u) for %s", prefix->PrefixLen, iface->Name);
228 res = -1;
231 if (prefix->AdvPreferredLifetime > prefix->AdvValidLifetime)
233 flog(LOG_ERR, "AdvValidLifetime for %s (%u) must be "
234 "greater than AdvPreferredLifetime for",
235 iface->Name, prefix->AdvValidLifetime);
236 res = -1;
239 prefix = prefix->next;
243 route = iface->AdvRouteList;
245 while(route)
247 if (route->PrefixLen > MAX_PrefixLen)
249 flog(LOG_ERR, "invalid route prefix length (%u) for %s", route->PrefixLen, iface->Name);
250 res = -1;
253 route = route->next;
256 return res;