File: interface.c

package info (click to toggle)
radvd 1:0.7.3-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 608 kB
  • ctags: 280
  • sloc: sh: 5,816; ansic: 2,801; yacc: 415; lex: 121; makefile: 46
file content (295 lines) | stat: -rw-r--r-- 7,120 bytes parent folder | download
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/*
 *   $Id: interface.c,v 1.7 2004/10/26 05:30:34 psavola Exp $
 *
 *   Authors:
 *    Lars Fenneberg		<lf@elemental.net>	 
 *
 *   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 <lutchann@litech.org>.
 *
 */

#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->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->MinRtrAdvInterval  = -1;
	iface->AdvDefaultLifetime = -1;
	iface->AdvDefaultPreference = DFLT_AdvDefaultPreference;
	iface->HomeAgentLifetime  = 0;
}

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->if6to4[0] = 0;
	prefix->enabled = 1;
}

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;
}

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;
	}

	prefix = iface->AdvPrefixList;	
	while (!MIPv6 && prefix)
	{
		if (prefix->AdvRouterAddr)
		{
			MIPv6 = 1;
		}
		prefix = prefix->next;
	}

	if (MIPv6)
	{
		flog(LOG_INFO, "using Mobile IPv6 extensions");
	}

	if (iface->MinRtrAdvInterval == -1)
		iface->MinRtrAdvInterval = DFLT_MinRtrAdvInterval(iface);

	/* Mobile IPv6 ext */
	if (MIPv6)
	{
		if ((iface->MinRtrAdvInterval < MIN_MinRtrAdvInterval_MIPv6) || 
		    (iface->MinRtrAdvInterval > MAX_MinRtrAdvInterval(iface)))
		{
			flog(LOG_ERR, 
				"MinRtrAdvInterval for %s must be between %.2f and %.2f",
				iface->Name, MIN_MinRtrAdvInterval_MIPv6,
				MAX2(MIN_MinRtrAdvInterval_MIPv6, MIN_MinRtrAdvInterval_MIPv6));
			res = -1;
		}
	}
	else
	{
		if ((iface->MinRtrAdvInterval < MIN_MinRtrAdvInterval) || 
		    (iface->MinRtrAdvInterval > MAX_MinRtrAdvInterval(iface)))
		{
			flog(LOG_ERR, 
				"MinRtrAdvInterval for %s must be between %d and %d",
				iface->Name, (int)MIN_MinRtrAdvInterval,
				(int)MAX_MinRtrAdvInterval(iface));
			res = -1;
		}
	}

	/* Mobile IPv6 ext */
	if (MIPv6)
	{
		if ((iface->MaxRtrAdvInterval < MIN_MaxRtrAdvInterval_MIPv6) 
			|| (iface->MaxRtrAdvInterval > MAX_MaxRtrAdvInterval))
		{
			flog(LOG_ERR, 
				"MaxRtrAdvInterval for %s must be between %.2f and %d",
				iface->Name, MIN_MaxRtrAdvInterval_MIPv6,
				MAX_MaxRtrAdvInterval);
			res = -1;
		}
	}
	else
	{
		if ((iface->MaxRtrAdvInterval < MIN_MaxRtrAdvInterval) 
			|| (iface->MaxRtrAdvInterval > MAX_MaxRtrAdvInterval))
		{
			flog(LOG_ERR, 
				"MaxRtrAdvInterval must be between %d and %d for %s",
				MIN_MaxRtrAdvInterval, MAX_MaxRtrAdvInterval, iface->Name);
			res = -1;
		}
	}

	/* Mobile IPv6 ext */
	if (MIPv6)
	{
		if (iface->MinDelayBetweenRAs < MIN_DELAY_BETWEEN_RAS_MIPv6) 
		{
			flog(LOG_ERR, 
				"MinDelayBetweenRAs for %s must be greater than %.2f",
				iface->Name, MIN_DELAY_BETWEEN_RAS_MIPv6);
			res = -1;
		}
	}
	else
	{
		if (iface->MinDelayBetweenRAs < MIN_DELAY_BETWEEN_RAS)
		{
			flog(LOG_ERR, 
				"MinDelayBetweenRAs for %s must be greater than %.2f",
				iface->Name, (double) MIN_DELAY_BETWEEN_RAS);
			res = -1;
		}
	}

	if (iface->if_maxmtu != -1)
	{
		if ((iface->AdvLinkMTU != 0) &&
		   ((iface->AdvLinkMTU < MIN_AdvLinkMTU) || 
		   (iface->AdvLinkMTU > iface->if_maxmtu)))
		{
			flog(LOG_ERR,  "AdvLinkMTU must be zero or between %d and %d for %s",
			MIN_AdvLinkMTU, iface->if_maxmtu, iface->Name);
			res = -1;
		}
	}
	else
	{
		if ((iface->AdvLinkMTU != 0) 
			&& (iface->AdvLinkMTU < MIN_AdvLinkMTU))
		{
			flog(LOG_ERR,  "AdvLinkMTU must be zero or greater than %d for %s",
			MIN_AdvLinkMTU, iface->Name);
			res = -1;
		}
	}

	if (iface->AdvReachableTime >  MAX_AdvReachableTime)
	{
		flog(LOG_ERR, 
			"AdvReachableTime must be less than %d for %s",
			MAX_AdvReachableTime, iface->Name);
		res = -1;
	}

	if (iface->AdvCurHopLimit > MAX_AdvCurHopLimit)
	{
		flog(LOG_ERR, "AdvCurHopLimit must not be greater than %d for %s",
			MAX_AdvCurHopLimit, iface->Name);
		res = -1;
	}
	
	if (iface->AdvDefaultLifetime == -1)
	{
		iface->AdvDefaultLifetime = DFLT_AdvDefaultLifetime(iface);
	}

	/* Mobile IPv6 ext */
	if (iface->HomeAgentLifetime == 0)
	{
		iface->HomeAgentLifetime = DFLT_HomeAgentLifetime(iface);
	}

	if ((iface->AdvDefaultLifetime != 0) &&
	   ((iface->AdvDefaultLifetime > MAX_AdvDefaultLifetime) ||
	    (iface->AdvDefaultLifetime < MIN_AdvDefaultLifetime(iface))))
	{
		flog(LOG_ERR, 
			"AdvDefaultLifetime for %s must be zero or between %.0f and %.0f",
			iface->Name, MIN_AdvDefaultLifetime(iface),
			MAX_AdvDefaultLifetime);
		res = -1;
	}

	/* Mobile IPv6 ext */
	if (iface->AdvHomeAgentInfo)
	{
		if ((iface->HomeAgentLifetime > MAX_HomeAgentLifetime) ||
			(iface->HomeAgentLifetime < MIN_HomeAgentLifetime))
		{
			flog(LOG_ERR, 
				"HomeAgentLifetime must be between %d and %d for %s",
				MIN_HomeAgentLifetime, MAX_HomeAgentLifetime,
				iface->Name);
			res = -1;
		}
	}

	/* Mobile IPv6 ext */
	if (MIPv6)
	{
		if (iface->AdvHomeAgentInfo && !(iface->AdvHomeAgentFlag))
		{
			flog(LOG_ERR, 
				"AdvHomeAgentFlag must be set with HomeAgentInfo");
			res = -1;
		}
	}

	/* XXX: need this? prefix = iface->AdvPrefixList; */

	while (prefix)
	{
		if (prefix->PrefixLen > MAX_PrefixLen)
		{
			flog(LOG_ERR, "invalid prefix length for %s", iface->Name);
			res = -1;
		}

		if (prefix->AdvPreferredLifetime > prefix->AdvValidLifetime)
		{
			flog(LOG_ERR, "AdvValidLifetime must be "
				"greater than AdvPreferredLifetime for %s", 
				iface->Name);
			res = -1;
		}

		prefix = prefix->next;
	}


	route = iface->AdvRouteList;

	while(route)
	{
		if (route->PrefixLen > MAX_PrefixLen)
		{
			flog(LOG_ERR, "invalid route prefix length for %s", iface->Name);
			res = -1;
		}

		route = route->next;
	}

	return res;
}