blob: 609e6925a594d853adb53ffeebfd40cb74743e76 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
2 * RIPng related value and structure.
3 * Copyright (C) 1998 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23#ifndef _ZEBRA_RIPNG_RIPNGD_H
24#define _ZEBRA_RIPNG_RIPNGD_H
25
26/* RIPng version and port number. */
27#define RIPNG_V1 1
28#define RIPNG_PORT_DEFAULT 521
29#define RIPNG_VTY_PORT 2603
paul718e3742002-12-13 20:15:29 +000030#define RIPNG_MAX_PACKET_SIZE 1500
31#define RIPNG_PRIORITY_DEFAULT 0
32
33/* RIPng commands. */
34#define RIPNG_REQUEST 1
35#define RIPNG_RESPONSE 2
36
37/* RIPng metric and multicast group address. */
38#define RIPNG_METRIC_INFINITY 16
39#define RIPNG_METRIC_NEXTHOP 0xff
40#define RIPNG_GROUP "ff02::9"
41
42/* RIPng timers. */
43#define RIPNG_UPDATE_TIMER_DEFAULT 30
44#define RIPNG_TIMEOUT_TIMER_DEFAULT 180
45#define RIPNG_GARBAGE_TIMER_DEFAULT 120
46
hassoa94434b2003-05-25 17:10:12 +000047/* RIPng peer timeout value. */
48#define RIPNG_PEER_TIMER_DEFAULT 180
49
paul718e3742002-12-13 20:15:29 +000050/* Default config file name. */
51#define RIPNG_DEFAULT_CONFIG "ripngd.conf"
52
53/* RIPng route types. */
54#define RIPNG_ROUTE_RTE 0
55#define RIPNG_ROUTE_STATIC 1
hassoa94434b2003-05-25 17:10:12 +000056#define RIPNG_ROUTE_DEFAULT 2
57#define RIPNG_ROUTE_REDISTRIBUTE 3
58#define RIPNG_ROUTE_INTERFACE 4
59#define RIPNG_ROUTE_AGGREGATE 5
paul718e3742002-12-13 20:15:29 +000060
61/* Interface send/receive configuration. */
62#define RIPNG_SEND_UNSPEC 0
63#define RIPNG_SEND_OFF 1
64#define RIPNG_RECEIVE_UNSPEC 0
65#define RIPNG_RECEIVE_OFF 1
66
paul718e3742002-12-13 20:15:29 +000067/* RIP default route's accept/announce methods. */
68#define RIPNG_DEFAULT_ADVERTISE_UNSPEC 0
69#define RIPNG_DEFAULT_ADVERTISE_NONE 1
70#define RIPNG_DEFAULT_ADVERTISE 2
71
72#define RIPNG_DEFAULT_ACCEPT_UNSPEC 0
73#define RIPNG_DEFAULT_ACCEPT_NONE 1
74#define RIPNG_DEFAULT_ACCEPT 2
75
76/* Default value for "default-metric" command. */
77#define RIPNG_DEFAULT_METRIC_DEFAULT 1
78
79/* For max RTE calculation. */
80#ifndef IPV6_HDRLEN
81#define IPV6_HDRLEN 40
82#endif /* IPV6_HDRLEN */
83
84#ifndef IFMINMTU
85#define IFMINMTU 576
86#endif /* IFMINMTU */
87
88/* RIPng structure. */
89struct ripng
90{
91 /* RIPng socket. */
92 int sock;
93
94 /* RIPng Parameters.*/
95 u_char command;
96 u_char version;
97 unsigned long update_time;
98 unsigned long timeout_time;
99 unsigned long garbage_time;
100 int max_mtu;
101 int default_metric;
102 int default_information;
103
104 /* Input/output buffer of RIPng. */
105 struct stream *ibuf;
106 struct stream *obuf;
107
108 /* RIPng routing information base. */
109 struct route_table *table;
110
111 /* RIPng only static route information. */
112 struct route_table *route;
113
114 /* RIPng aggregate route information. */
115 struct route_table *aggregate;
116
117 /* RIPng threads. */
118 struct thread *t_read;
119 struct thread *t_write;
120 struct thread *t_update;
121 struct thread *t_garbage;
122 struct thread *t_zebra;
123
124 /* Triggered update hack. */
125 int trigger;
126 struct thread *t_triggered_update;
127 struct thread *t_triggered_interval;
128
129 /* For redistribute route map. */
130 struct
131 {
132 char *name;
133 struct route_map *map;
134 int metric_config;
135 u_int32_t metric;
136 } route_map[ZEBRA_ROUTE_MAX];
137};
138
139/* Routing table entry. */
140struct rte
141{
hassoa94434b2003-05-25 17:10:12 +0000142 struct in6_addr addr; /* RIPng destination prefix */
143 u_short tag; /* RIPng tag */
144 u_char prefixlen; /* Length of the RIPng prefix */
145 u_char metric; /* Metric of the RIPng route */
146 /* The nexthop is stored by the structure
147 * ripng_nexthop within ripngd.c */
paul718e3742002-12-13 20:15:29 +0000148};
149
150/* RIPNG send packet. */
151struct ripng_packet
152{
153 u_char command;
154 u_char version;
155 u_int16_t zero;
156 struct rte rte[1];
157};
158
159/* Each route's information. */
160struct ripng_info
161{
162 /* This route's type. Static, ripng or aggregate. */
163 u_char type;
164
165 /* Sub type for static route. */
166 u_char sub_type;
167
168 /* RIPng specific information */
169 struct in6_addr nexthop;
170 struct in6_addr from;
171
172 /* Which interface does this route come from. */
173 unsigned int ifindex;
174
175 /* Metric of this route. */
176 u_char metric;
177
178 /* Tag field of RIPng packet.*/
179 u_int16_t tag;
180
181 /* For aggregation. */
182 unsigned int suppress;
183
184 /* Flags of RIPng route. */
185#define RIPNG_RTF_FIB 1
186#define RIPNG_RTF_CHANGED 2
187 u_char flags;
188
189 /* Garbage collect timer. */
190 struct thread *t_timeout;
191 struct thread *t_garbage_collect;
192
193 /* Route-map features - this variables can be changed. */
hassoa94434b2003-05-25 17:10:12 +0000194 struct in6_addr nexthop_out;
paul718e3742002-12-13 20:15:29 +0000195 u_char metric_set;
hassoa94434b2003-05-25 17:10:12 +0000196 u_char metric_out;
197 u_short tag_out;
paul718e3742002-12-13 20:15:29 +0000198
199 struct route_node *rp;
200};
201
hassoa94434b2003-05-25 17:10:12 +0000202#ifdef notyet
203#if 0
paul718e3742002-12-13 20:15:29 +0000204/* RIPng tag structure. */
205struct ripng_tag
206{
207 /* Tag value. */
208 u_int16_t tag;
209
210 /* Port. */
211 u_int16_t port;
212
213 /* Multicast group. */
214 struct in6_addr maddr;
215
216 /* Table number. */
217 int table;
218
219 /* Distance. */
220 int distance;
221
222 /* Split horizon. */
223 u_char split_horizon;
224
225 /* Poison reverse. */
226 u_char poison_reverse;
227};
hassoa94434b2003-05-25 17:10:12 +0000228#endif /* 0 */
229#endif /* not yet */
230
231typedef enum {
232 RIPNG_NO_SPLIT_HORIZON = 0,
233 RIPNG_SPLIT_HORIZON,
234 RIPNG_SPLIT_HORIZON_POISONED_REVERSE
235} split_horizon_policy_t;
paul718e3742002-12-13 20:15:29 +0000236
237/* RIPng specific interface configuration. */
238struct ripng_interface
239{
240 /* RIPng is enabled on this interface. */
241 int enable_network;
242 int enable_interface;
243
244 /* RIPng is running on this interface. */
245 int running;
246
hassoa94434b2003-05-25 17:10:12 +0000247 /* Split horizon flag. */
248 split_horizon_policy_t split_horizon;
249 split_horizon_policy_t split_horizon_default;
250
paul718e3742002-12-13 20:15:29 +0000251 /* For filter type slot. */
252#define RIPNG_FILTER_IN 0
253#define RIPNG_FILTER_OUT 1
254#define RIPNG_FILTER_MAX 2
255
256 /* Access-list. */
257 struct access_list *list[RIPNG_FILTER_MAX];
258
259 /* Prefix-list. */
260 struct prefix_list *prefix[RIPNG_FILTER_MAX];
261
262 /* Route-map. */
263 struct route_map *routemap[RIPNG_FILTER_MAX];
264
hassoa94434b2003-05-25 17:10:12 +0000265#ifdef notyet
266#if 0
paul718e3742002-12-13 20:15:29 +0000267 /* RIPng tag configuration. */
268 struct ripng_tag *rtag;
hassoa94434b2003-05-25 17:10:12 +0000269#endif /* 0 */
270#endif /* notyet */
paul718e3742002-12-13 20:15:29 +0000271
272 /* Default information originate. */
273 u_char default_originate;
274
275 /* Default information only. */
276 u_char default_only;
277
278 /* Wake up thread. */
279 struct thread *t_wakeup;
280
281 /* Passive interface. */
282 int passive;
283};
284
hassoa94434b2003-05-25 17:10:12 +0000285/* RIPng peer information. */
286struct ripng_peer
287{
288 /* Peer address. */
289 struct in6_addr addr;
290
291 /* Peer RIPng tag value. */
292 int domain;
293
294 /* Last update time. */
295 time_t uptime;
296
297 /* Peer RIP version. */
298 u_char version;
299
300 /* Statistics. */
301 int recv_badpackets;
302 int recv_badroutes;
303
304 /* Timeout thread. */
305 struct thread *t_timeout;
306};
307
paul718e3742002-12-13 20:15:29 +0000308/* All RIPng events. */
309enum ripng_event
310{
311 RIPNG_READ,
312 RIPNG_ZEBRA,
313 RIPNG_REQUEST_EVENT,
314 RIPNG_UPDATE_EVENT,
315 RIPNG_TRIGGERED_UPDATE,
316};
317
318/* RIPng timer on/off macro. */
319#define RIPNG_TIMER_ON(T,F,V) \
320do { \
321 if (!(T)) \
322 (T) = thread_add_timer (master, (F), rinfo, (V)); \
323} while (0)
324
325#define RIPNG_TIMER_OFF(T) \
326do { \
327 if (T) \
328 { \
329 thread_cancel(T); \
330 (T) = NULL; \
331 } \
332} while (0)
333
334/* Count prefix size from mask length */
335#define PSIZE(a) (((a) + 7) / (8))
336
337/* Extern variables. */
338extern struct ripng *ripng;
339
340extern struct thread_master *master;
341
342/* Prototypes. */
343void ripng_init ();
hassoa94434b2003-05-25 17:10:12 +0000344void ripng_reset ();
345void ripng_clean ();
346void ripng_clean_network ();
347void ripng_interface_clean ();
348void ripng_interface_reset ();
349void ripng_passive_interface_clean ();
paul718e3742002-12-13 20:15:29 +0000350void ripng_if_init ();
hassoa94434b2003-05-25 17:10:12 +0000351void ripng_route_map_init ();
352void ripng_route_map_reset ();
paul718e3742002-12-13 20:15:29 +0000353void ripng_terminate ();
hassoa94434b2003-05-25 17:10:12 +0000354 /* zclient_init() is done by ripng_zebra.c:zebra_init() */
paul718e3742002-12-13 20:15:29 +0000355void zebra_init ();
hassoa94434b2003-05-25 17:10:12 +0000356void ripng_zclient_start ();
357void ripng_zclient_reset ();
358void ripng_offset_init ();
359
360int config_write_ripng_offset_list (struct vty *);
361
362void ripng_peer_init ();
363void ripng_peer_update (struct sockaddr_in6 *, u_char);
364void ripng_peer_bad_route (struct sockaddr_in6 *);
365void ripng_peer_bad_packet (struct sockaddr_in6 *);
366void ripng_peer_display (struct vty *);
367struct ripng_peer *ripng_peer_lookup (struct in6_addr *);
368struct ripng_peer *ripng_peer_lookup_next (struct in6_addr *);
369
370int ripng_offset_list_apply_in (struct prefix_ipv6 *, struct interface *, u_char *);
371int ripng_offset_list_apply_out (struct prefix_ipv6 *, struct interface *, u_char *);
372void ripng_offset_clean ();
373
paul718e3742002-12-13 20:15:29 +0000374struct ripng_info * ripng_info_new ();
375void ripng_info_free (struct ripng_info *rinfo);
376void ripng_event (enum ripng_event, int);
377int ripng_request (struct interface *ifp);
hassoa94434b2003-05-25 17:10:12 +0000378void ripng_redistribute_add (int, int, struct prefix_ipv6 *, unsigned int,
379 struct in6_addr *);
paul718e3742002-12-13 20:15:29 +0000380void ripng_redistribute_delete (int, int, struct prefix_ipv6 *, unsigned int);
381void ripng_redistribute_withdraw (int type);
382
383void ripng_distribute_update_interface (struct interface *);
384void ripng_if_rmap_update_interface (struct interface *);
385
386void ripng_zebra_ipv6_add (struct prefix_ipv6 *p, struct in6_addr *nexthop, unsigned int ifindex);
387void ripng_zebra_ipv6_delete (struct prefix_ipv6 *p, struct in6_addr *nexthop, unsigned int ifindex);
hassoa94434b2003-05-25 17:10:12 +0000388
389void ripng_redistribute_clean ();
390
391const char *inet6_ntop (struct in6_addr *p);
392
393int ripng_write_rte (int num, struct stream *s, struct prefix_ipv6 *p,
394 struct in6_addr *nexthop, u_int16_t tag, u_char metric);
395int ripng_send_packet (caddr_t buf, int bufsize, struct sockaddr_in6 *to,
396 struct interface *ifp);
397
398void ripng_packet_dump (struct ripng_packet *packet, int size, char *sndrcv);
399
paul718e3742002-12-13 20:15:29 +0000400
401#endif /* _ZEBRA_RIPNG_RIPNGD_H */