forked from radvd-project/radvd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.c
257 lines (220 loc) · 7.09 KB
/
interface.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*
* $Id: interface.c,v 1.27 2011/04/28 15:08:40 reubenhwk Exp $
*
* Authors:
* Lars Fenneberg <[email protected]>
*
* This software is Copyright 1996,1997 by the above mentioned author(s),
* All Rights Reserved.
*
* The license which is distributed with this software in the file COPYRIGHT
* applies to this software. If your distribution is missing this file, you
* may request it from <[email protected]>.
*
*/
#include "config.h"
#include "includes.h"
#include "radvd.h"
#include "defaults.h"
void
iface_init_defaults(struct Interface *iface)
{
memset(iface, 0, sizeof(struct Interface));
iface->cease_adv = 0;
iface->HasFailed = 0;
iface->IgnoreIfMissing = DFLT_IgnoreIfMissing;
iface->AdvSendAdvert = DFLT_AdvSendAdv;
iface->MaxRtrAdvInterval = DFLT_MaxRtrAdvInterval;
iface->AdvSourceLLAddress = DFLT_AdvSourceLLAddress;
iface->AdvReachableTime = DFLT_AdvReachableTime;
iface->AdvRetransTimer = DFLT_AdvRetransTimer;
iface->AdvLinkMTU = DFLT_AdvLinkMTU;
iface->AdvCurHopLimit = DFLT_AdvCurHopLimit;
iface->AdvIntervalOpt = DFLT_AdvIntervalOpt;
iface->AdvHomeAgentInfo = DFLT_AdvHomeAgentInfo;
iface->AdvHomeAgentFlag = DFLT_AdvHomeAgentFlag;
iface->HomeAgentPreference = DFLT_HomeAgentPreference;
iface->MinDelayBetweenRAs = DFLT_MinDelayBetweenRAs;
iface->AdvMobRtrSupportFlag = DFLT_AdvMobRtrSupportFlag;
iface->MinRtrAdvInterval = -1;
iface->AdvDefaultLifetime = -1;
iface->AdvDefaultPreference = DFLT_AdvDefaultPreference;
iface->HomeAgentLifetime = -1;
}
void
prefix_init_defaults(struct AdvPrefix *prefix)
{
memset(prefix, 0, sizeof(struct AdvPrefix));
prefix->AdvOnLinkFlag = DFLT_AdvOnLinkFlag;
prefix->AdvAutonomousFlag = DFLT_AdvAutonomousFlag;
prefix->AdvRouterAddr = DFLT_AdvRouterAddr;
prefix->AdvValidLifetime = DFLT_AdvValidLifetime;
prefix->AdvPreferredLifetime = DFLT_AdvPreferredLifetime;
prefix->DeprecatePrefixFlag = DFLT_DeprecatePrefixFlag;
prefix->DecrementLifetimesFlag = DFLT_DecrementLifetimesFlag;
prefix->if6to4[0] = 0;
prefix->enabled = 1;
prefix->curr_validlft = prefix->AdvValidLifetime;
prefix->curr_preferredlft = prefix->AdvPreferredLifetime;
}
void
route_init_defaults(struct AdvRoute *route, struct Interface *iface)
{
memset(route, 0, sizeof(struct AdvRoute));
route->AdvRouteLifetime = DFLT_AdvRouteLifetime(iface);
route->AdvRoutePreference = DFLT_AdvRoutePreference;
route->RemoveRouteFlag = DFLT_RemoveRouteFlag;
}
void
rdnss_init_defaults(struct AdvRDNSS *rdnss, struct Interface *iface)
{
memset(rdnss, 0, sizeof(struct AdvRDNSS));
rdnss->AdvRDNSSLifetime = DFLT_AdvRDNSSLifetime(iface);
rdnss->AdvRDNSSNumber = 0;
rdnss->FlushRDNSSFlag = DFLT_FlushRDNSSFlag;
}
void
dnssl_init_defaults(struct AdvDNSSL *dnssl, struct Interface *iface)
{
memset(dnssl, 0, sizeof(struct AdvDNSSL));
dnssl->AdvDNSSLLifetime = DFLT_AdvDNSSLLifetime(iface);
dnssl->FlushDNSSLFlag = DFLT_FlushDNSSLFlag;
}
int
check_iface(struct Interface *iface)
{
struct AdvPrefix *prefix;
struct AdvRoute *route;
int res = 0;
int MIPv6 = 0;
/* Check if we use Mobile IPv6 extensions */
if (iface->AdvHomeAgentFlag || iface->AdvHomeAgentInfo ||
iface->AdvIntervalOpt)
{
MIPv6 = 1;
flog(LOG_INFO, "using Mobile IPv6 extensions");
}
prefix = iface->AdvPrefixList;
while (!MIPv6 && prefix)
{
if (prefix->AdvRouterAddr)
{
MIPv6 = 1;
}
prefix = prefix->next;
}
if (iface->MinRtrAdvInterval < 0)
iface->MinRtrAdvInterval = DFLT_MinRtrAdvInterval(iface);
if ((iface->MinRtrAdvInterval < (MIPv6 ? MIN_MinRtrAdvInterval_MIPv6 : MIN_MinRtrAdvInterval)) ||
(iface->MinRtrAdvInterval > MAX_MinRtrAdvInterval(iface)))
{
flog(LOG_ERR,
"MinRtrAdvInterval for %s (%.2f) must be at least %.2f but no more than 3/4 of MaxRtrAdvInterval (%.2f)",
iface->Name, iface->MinRtrAdvInterval,
MIPv6 ? MIN_MinRtrAdvInterval_MIPv6 : (int)MIN_MinRtrAdvInterval,
MAX_MinRtrAdvInterval(iface));
res = -1;
}
if ((iface->MaxRtrAdvInterval < (MIPv6 ? MIN_MaxRtrAdvInterval_MIPv6 : MIN_MaxRtrAdvInterval))
|| (iface->MaxRtrAdvInterval > MAX_MaxRtrAdvInterval))
{
flog(LOG_ERR,
"MaxRtrAdvInterval for %s (%.2f) must be between %.2f and %d",
iface->Name, iface->MaxRtrAdvInterval,
MIPv6 ? MIN_MaxRtrAdvInterval_MIPv6 : (int)MIN_MaxRtrAdvInterval,
MAX_MaxRtrAdvInterval);
res = -1;
}
if (iface->MinDelayBetweenRAs < (MIPv6 ? MIN_DELAY_BETWEEN_RAS_MIPv6 : MIN_DELAY_BETWEEN_RAS))
{
flog(LOG_ERR,
"MinDelayBetweenRAs for %s (%.2f) must be at least %.2f",
iface->Name, iface->MinDelayBetweenRAs,
MIPv6 ? MIN_DELAY_BETWEEN_RAS_MIPv6 : MIN_DELAY_BETWEEN_RAS);
res = -1;
}
if ((iface->AdvLinkMTU != 0) &&
((iface->AdvLinkMTU < MIN_AdvLinkMTU) ||
(iface->if_maxmtu != -1 && (iface->AdvLinkMTU > iface->if_maxmtu))))
{
flog(LOG_ERR, "AdvLinkMTU for %s (%u) must be zero or between %u and %u",
iface->Name, iface->AdvLinkMTU, MIN_AdvLinkMTU, iface->if_maxmtu);
res = -1;
}
if (iface->AdvReachableTime > MAX_AdvReachableTime)
{
flog(LOG_ERR,
"AdvReachableTime for %s (%u) must not be greater than %u",
iface->Name, iface->AdvReachableTime, MAX_AdvReachableTime);
res = -1;
}
if (iface->AdvDefaultLifetime < 0)
iface->AdvDefaultLifetime = DFLT_AdvDefaultLifetime(iface);
if ((iface->AdvDefaultLifetime != 0) &&
((iface->AdvDefaultLifetime > MAX_AdvDefaultLifetime) ||
(iface->AdvDefaultLifetime < MIN_AdvDefaultLifetime(iface))))
{
flog(LOG_ERR,
"AdvDefaultLifetime for %s (%u) must be zero or between %u and %u",
iface->Name, iface->AdvDefaultLifetime, (int)MIN_AdvDefaultLifetime(iface),
MAX_AdvDefaultLifetime);
res = -1;
}
/* Mobile IPv6 ext */
if (iface->HomeAgentLifetime < 0)
iface->HomeAgentLifetime = DFLT_HomeAgentLifetime(iface);
/* Mobile IPv6 ext */
if (iface->AdvHomeAgentInfo)
{
if ((iface->HomeAgentLifetime > MAX_HomeAgentLifetime) ||
(iface->HomeAgentLifetime < MIN_HomeAgentLifetime))
{
flog(LOG_ERR,
"HomeAgentLifetime for %s (%u) must be between %u and %u",
iface->Name, iface->HomeAgentLifetime,
MIN_HomeAgentLifetime, MAX_HomeAgentLifetime);
res = -1;
}
}
/* Mobile IPv6 ext */
if (iface->AdvHomeAgentInfo && !(iface->AdvHomeAgentFlag))
{
flog(LOG_ERR,
"AdvHomeAgentFlag for %s must be set with HomeAgentInfo", iface->Name);
res = -1;
}
if (iface->AdvMobRtrSupportFlag && !(iface->AdvHomeAgentInfo))
{
flog(LOG_ERR,
"AdvHomeAgentInfo for %s must be set with AdvMobRtrSupportFlag", iface->Name);
res = -1;
}
/* XXX: need this? prefix = iface->AdvPrefixList; */
while (prefix)
{
if (prefix->PrefixLen > MAX_PrefixLen)
{
flog(LOG_ERR, "invalid prefix length (%u) for %s", prefix->PrefixLen, iface->Name);
res = -1;
}
if (prefix->AdvPreferredLifetime > prefix->AdvValidLifetime)
{
flog(LOG_ERR, "AdvValidLifetime for %s (%u) must be "
"greater than AdvPreferredLifetime for",
iface->Name, prefix->AdvValidLifetime);
res = -1;
}
prefix = prefix->next;
}
route = iface->AdvRouteList;
while(route)
{
if (route->PrefixLen > MAX_PrefixLen)
{
flog(LOG_ERR, "invalid route prefix length (%u) for %s", route->PrefixLen, iface->Name);
res = -1;
}
route = route->next;
}
return res;
}