2 * $Id: interface.c,v 1.27 2011/04/28 15:08:40 reubenhwk Exp $
5 * Lars Fenneberg <lf@elemental.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>.
22 iface_init_defaults(struct Interface
*iface
)
24 memset(iface
, 0, sizeof(struct Interface
));
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;
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;
65 prefix
->curr_validlft
= prefix
->AdvValidLifetime
;
66 prefix
->curr_preferredlft
= prefix
->AdvPreferredLifetime
;
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
;
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
;
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
;
99 check_iface(struct Interface
*iface
)
101 struct AdvPrefix
*prefix
;
102 struct AdvRoute
*route
;
106 /* Check if we use Mobile IPv6 extensions */
107 if (iface
->AdvHomeAgentFlag
|| iface
->AdvHomeAgentInfo
||
108 iface
->AdvIntervalOpt
)
111 flog(LOG_INFO
, "using Mobile IPv6 extensions");
114 prefix
= iface
->AdvPrefixList
;
115 while (!MIPv6
&& prefix
)
117 if (prefix
->AdvRouterAddr
)
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
)))
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
));
138 if ((iface
->MaxRtrAdvInterval
< (MIPv6
? MIN_MaxRtrAdvInterval_MIPv6
: MIN_MaxRtrAdvInterval
))
139 || (iface
->MaxRtrAdvInterval
> MAX_MaxRtrAdvInterval
))
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
);
149 if (iface
->MinDelayBetweenRAs
< (MIPv6
? MIN_DELAY_BETWEEN_RAS_MIPv6
: MIN_DELAY_BETWEEN_RAS
))
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
);
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
);
167 if (iface
->AdvReachableTime
> MAX_AdvReachableTime
)
170 "AdvReachableTime for %s (%u) must not be greater than %u",
171 iface
->Name
, iface
->AdvReachableTime
, MAX_AdvReachableTime
);
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
))))
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
);
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
))
200 "HomeAgentLifetime for %s (%u) must be between %u and %u",
201 iface
->Name
, iface
->HomeAgentLifetime
,
202 MIN_HomeAgentLifetime
, MAX_HomeAgentLifetime
);
207 /* Mobile IPv6 ext */
208 if (iface
->AdvHomeAgentInfo
&& !(iface
->AdvHomeAgentFlag
))
211 "AdvHomeAgentFlag for %s must be set with HomeAgentInfo", iface
->Name
);
214 if (iface
->AdvMobRtrSupportFlag
&& !(iface
->AdvHomeAgentInfo
))
217 "AdvHomeAgentInfo for %s must be set with AdvMobRtrSupportFlag", iface
->Name
);
221 /* XXX: need this? prefix = iface->AdvPrefixList; */
225 if (prefix
->PrefixLen
> MAX_PrefixLen
)
227 flog(LOG_ERR
, "invalid prefix length (%u) for %s", prefix
->PrefixLen
, iface
->Name
);
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
);
239 prefix
= prefix
->next
;
243 route
= iface
->AdvRouteList
;
247 if (route
->PrefixLen
> MAX_PrefixLen
)
249 flog(LOG_ERR
, "invalid route prefix length (%u) for %s", route
->PrefixLen
, iface
->Name
);