blob: ab06d81bfdeb350a6a6a5a9b49f3c0dfcde6887c [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
Paul Jakma6ac29a52008-08-15 13:45:30 +010026#include <zclient.h>
27#include <vty.h>
28
paul718e3742002-12-13 20:15:29 +000029/* RIPng version and port number. */
30#define RIPNG_V1 1
31#define RIPNG_PORT_DEFAULT 521
32#define RIPNG_VTY_PORT 2603
paul718e3742002-12-13 20:15:29 +000033#define RIPNG_MAX_PACKET_SIZE 1500
34#define RIPNG_PRIORITY_DEFAULT 0
35
36/* RIPng commands. */
37#define RIPNG_REQUEST 1
38#define RIPNG_RESPONSE 2
39
40/* RIPng metric and multicast group address. */
41#define RIPNG_METRIC_INFINITY 16
42#define RIPNG_METRIC_NEXTHOP 0xff
43#define RIPNG_GROUP "ff02::9"
44
45/* RIPng timers. */
46#define RIPNG_UPDATE_TIMER_DEFAULT 30
47#define RIPNG_TIMEOUT_TIMER_DEFAULT 180
48#define RIPNG_GARBAGE_TIMER_DEFAULT 120
49
hassoa94434b2003-05-25 17:10:12 +000050/* RIPng peer timeout value. */
51#define RIPNG_PEER_TIMER_DEFAULT 180
52
paul718e3742002-12-13 20:15:29 +000053/* Default config file name. */
54#define RIPNG_DEFAULT_CONFIG "ripngd.conf"
55
56/* RIPng route types. */
57#define RIPNG_ROUTE_RTE 0
58#define RIPNG_ROUTE_STATIC 1
hassoa94434b2003-05-25 17:10:12 +000059#define RIPNG_ROUTE_DEFAULT 2
60#define RIPNG_ROUTE_REDISTRIBUTE 3
61#define RIPNG_ROUTE_INTERFACE 4
62#define RIPNG_ROUTE_AGGREGATE 5
paul718e3742002-12-13 20:15:29 +000063
64/* Interface send/receive configuration. */
65#define RIPNG_SEND_UNSPEC 0
66#define RIPNG_SEND_OFF 1
67#define RIPNG_RECEIVE_UNSPEC 0
68#define RIPNG_RECEIVE_OFF 1
69
paul718e3742002-12-13 20:15:29 +000070/* RIP default route's accept/announce methods. */
71#define RIPNG_DEFAULT_ADVERTISE_UNSPEC 0
72#define RIPNG_DEFAULT_ADVERTISE_NONE 1
73#define RIPNG_DEFAULT_ADVERTISE 2
74
75#define RIPNG_DEFAULT_ACCEPT_UNSPEC 0
76#define RIPNG_DEFAULT_ACCEPT_NONE 1
77#define RIPNG_DEFAULT_ACCEPT 2
78
79/* Default value for "default-metric" command. */
80#define RIPNG_DEFAULT_METRIC_DEFAULT 1
81
82/* For max RTE calculation. */
83#ifndef IPV6_HDRLEN
84#define IPV6_HDRLEN 40
85#endif /* IPV6_HDRLEN */
86
87#ifndef IFMINMTU
88#define IFMINMTU 576
89#endif /* IFMINMTU */
90
91/* RIPng structure. */
92struct ripng
93{
94 /* RIPng socket. */
95 int sock;
96
97 /* RIPng Parameters.*/
98 u_char command;
99 u_char version;
100 unsigned long update_time;
101 unsigned long timeout_time;
102 unsigned long garbage_time;
103 int max_mtu;
104 int default_metric;
105 int default_information;
106
107 /* Input/output buffer of RIPng. */
108 struct stream *ibuf;
109 struct stream *obuf;
110
111 /* RIPng routing information base. */
112 struct route_table *table;
113
114 /* RIPng only static route information. */
115 struct route_table *route;
116
117 /* RIPng aggregate route information. */
118 struct route_table *aggregate;
119
120 /* RIPng threads. */
121 struct thread *t_read;
122 struct thread *t_write;
123 struct thread *t_update;
124 struct thread *t_garbage;
125 struct thread *t_zebra;
126
127 /* Triggered update hack. */
128 int trigger;
129 struct thread *t_triggered_update;
130 struct thread *t_triggered_interval;
131
132 /* For redistribute route map. */
133 struct
134 {
135 char *name;
136 struct route_map *map;
137 int metric_config;
138 u_int32_t metric;
139 } route_map[ZEBRA_ROUTE_MAX];
140};
141
142/* Routing table entry. */
143struct rte
144{
hassoa94434b2003-05-25 17:10:12 +0000145 struct in6_addr addr; /* RIPng destination prefix */
146 u_short tag; /* RIPng tag */
147 u_char prefixlen; /* Length of the RIPng prefix */
148 u_char metric; /* Metric of the RIPng route */
149 /* The nexthop is stored by the structure
150 * ripng_nexthop within ripngd.c */
paul718e3742002-12-13 20:15:29 +0000151};
152
153/* RIPNG send packet. */
154struct ripng_packet
155{
156 u_char command;
157 u_char version;
158 u_int16_t zero;
159 struct rte rte[1];
160};
161
162/* Each route's information. */
163struct ripng_info
164{
165 /* This route's type. Static, ripng or aggregate. */
166 u_char type;
167
168 /* Sub type for static route. */
169 u_char sub_type;
170
171 /* RIPng specific information */
172 struct in6_addr nexthop;
173 struct in6_addr from;
174
175 /* Which interface does this route come from. */
176 unsigned int ifindex;
177
178 /* Metric of this route. */
179 u_char metric;
180
181 /* Tag field of RIPng packet.*/
182 u_int16_t tag;
183
184 /* For aggregation. */
185 unsigned int suppress;
186
187 /* Flags of RIPng route. */
188#define RIPNG_RTF_FIB 1
189#define RIPNG_RTF_CHANGED 2
190 u_char flags;
191
192 /* Garbage collect timer. */
193 struct thread *t_timeout;
194 struct thread *t_garbage_collect;
195
196 /* Route-map features - this variables can be changed. */
hassoa94434b2003-05-25 17:10:12 +0000197 struct in6_addr nexthop_out;
paul718e3742002-12-13 20:15:29 +0000198 u_char metric_set;
hassoa94434b2003-05-25 17:10:12 +0000199 u_char metric_out;
200 u_short tag_out;
paul718e3742002-12-13 20:15:29 +0000201
202 struct route_node *rp;
203};
204
hassoa94434b2003-05-25 17:10:12 +0000205#ifdef notyet
206#if 0
paul718e3742002-12-13 20:15:29 +0000207/* RIPng tag structure. */
208struct ripng_tag
209{
210 /* Tag value. */
211 u_int16_t tag;
212
213 /* Port. */
214 u_int16_t port;
215
216 /* Multicast group. */
217 struct in6_addr maddr;
218
219 /* Table number. */
220 int table;
221
222 /* Distance. */
223 int distance;
224
225 /* Split horizon. */
226 u_char split_horizon;
227
228 /* Poison reverse. */
229 u_char poison_reverse;
230};
hassoa94434b2003-05-25 17:10:12 +0000231#endif /* 0 */
232#endif /* not yet */
233
234typedef enum {
235 RIPNG_NO_SPLIT_HORIZON = 0,
236 RIPNG_SPLIT_HORIZON,
237 RIPNG_SPLIT_HORIZON_POISONED_REVERSE
238} split_horizon_policy_t;
paul718e3742002-12-13 20:15:29 +0000239
240/* RIPng specific interface configuration. */
241struct ripng_interface
242{
243 /* RIPng is enabled on this interface. */
244 int enable_network;
245 int enable_interface;
246
247 /* RIPng is running on this interface. */
248 int running;
249
hassoa94434b2003-05-25 17:10:12 +0000250 /* Split horizon flag. */
251 split_horizon_policy_t split_horizon;
252 split_horizon_policy_t split_horizon_default;
253
paul718e3742002-12-13 20:15:29 +0000254 /* For filter type slot. */
255#define RIPNG_FILTER_IN 0
256#define RIPNG_FILTER_OUT 1
257#define RIPNG_FILTER_MAX 2
258
259 /* Access-list. */
260 struct access_list *list[RIPNG_FILTER_MAX];
261
262 /* Prefix-list. */
263 struct prefix_list *prefix[RIPNG_FILTER_MAX];
264
265 /* Route-map. */
266 struct route_map *routemap[RIPNG_FILTER_MAX];
267
hassoa94434b2003-05-25 17:10:12 +0000268#ifdef notyet
269#if 0
paul718e3742002-12-13 20:15:29 +0000270 /* RIPng tag configuration. */
271 struct ripng_tag *rtag;
hassoa94434b2003-05-25 17:10:12 +0000272#endif /* 0 */
273#endif /* notyet */
paul718e3742002-12-13 20:15:29 +0000274
275 /* Default information originate. */
276 u_char default_originate;
277
278 /* Default information only. */
279 u_char default_only;
280
281 /* Wake up thread. */
282 struct thread *t_wakeup;
283
284 /* Passive interface. */
285 int passive;
286};
287
hassoa94434b2003-05-25 17:10:12 +0000288/* RIPng peer information. */
289struct ripng_peer
290{
291 /* Peer address. */
292 struct in6_addr addr;
293
294 /* Peer RIPng tag value. */
295 int domain;
296
297 /* Last update time. */
298 time_t uptime;
299
300 /* Peer RIP version. */
301 u_char version;
302
303 /* Statistics. */
304 int recv_badpackets;
305 int recv_badroutes;
306
307 /* Timeout thread. */
308 struct thread *t_timeout;
309};
310
paul718e3742002-12-13 20:15:29 +0000311/* All RIPng events. */
312enum ripng_event
313{
314 RIPNG_READ,
315 RIPNG_ZEBRA,
316 RIPNG_REQUEST_EVENT,
317 RIPNG_UPDATE_EVENT,
318 RIPNG_TRIGGERED_UPDATE,
319};
320
321/* RIPng timer on/off macro. */
322#define RIPNG_TIMER_ON(T,F,V) \
323do { \
324 if (!(T)) \
325 (T) = thread_add_timer (master, (F), rinfo, (V)); \
326} while (0)
327
328#define RIPNG_TIMER_OFF(T) \
329do { \
330 if (T) \
331 { \
332 thread_cancel(T); \
333 (T) = NULL; \
334 } \
335} while (0)
336
337/* Count prefix size from mask length */
338#define PSIZE(a) (((a) + 7) / (8))
339
340/* Extern variables. */
341extern struct ripng *ripng;
342
343extern struct thread_master *master;
344
345/* Prototypes. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100346extern void ripng_init (void);
347extern void ripng_reset (void);
348extern void ripng_clean (void);
349extern void ripng_clean_network (void);
350extern void ripng_interface_clean (void);
351extern void ripng_interface_reset (void);
352extern void ripng_passive_interface_clean (void);
353extern void ripng_if_init (void);
354extern void ripng_route_map_init (void);
355extern void ripng_route_map_reset (void);
356extern void ripng_terminate (void);
hassoa94434b2003-05-25 17:10:12 +0000357 /* zclient_init() is done by ripng_zebra.c:zebra_init() */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100358extern void zebra_init (void);
359extern void ripng_zclient_start (void);
360extern void ripng_zclient_reset (void);
361extern void ripng_offset_init (void);
hassoa94434b2003-05-25 17:10:12 +0000362
Paul Jakma6ac29a52008-08-15 13:45:30 +0100363extern int config_write_ripng_offset_list (struct vty *);
hassoa94434b2003-05-25 17:10:12 +0000364
Paul Jakma6ac29a52008-08-15 13:45:30 +0100365extern void ripng_peer_init (void);
366extern void ripng_peer_update (struct sockaddr_in6 *, u_char);
367extern void ripng_peer_bad_route (struct sockaddr_in6 *);
368extern void ripng_peer_bad_packet (struct sockaddr_in6 *);
369extern void ripng_peer_display (struct vty *);
370extern struct ripng_peer *ripng_peer_lookup (struct in6_addr *);
371extern struct ripng_peer *ripng_peer_lookup_next (struct in6_addr *);
hassoa94434b2003-05-25 17:10:12 +0000372
Paul Jakma6ac29a52008-08-15 13:45:30 +0100373extern int ripng_offset_list_apply_in (struct prefix_ipv6 *,
374 struct interface *, u_char *);
375extern int ripng_offset_list_apply_out (struct prefix_ipv6 *,
376 struct interface *, u_char *);
377extern void ripng_offset_clean (void);
hassoa94434b2003-05-25 17:10:12 +0000378
Paul Jakma6ac29a52008-08-15 13:45:30 +0100379extern struct ripng_info * ripng_info_new (void);
380extern void ripng_info_free (struct ripng_info *rinfo);
381extern void ripng_event (enum ripng_event, int);
382extern int ripng_request (struct interface *ifp);
383extern void ripng_redistribute_add (int, int, struct prefix_ipv6 *,
384 unsigned int, struct in6_addr *);
385extern void ripng_redistribute_delete (int, int, struct prefix_ipv6 *,
386 unsigned int);
387extern void ripng_redistribute_withdraw (int type);
paul718e3742002-12-13 20:15:29 +0000388
Paul Jakma6ac29a52008-08-15 13:45:30 +0100389extern void ripng_distribute_update_interface (struct interface *);
390extern void ripng_if_rmap_update_interface (struct interface *);
paul718e3742002-12-13 20:15:29 +0000391
Paul Jakma6ac29a52008-08-15 13:45:30 +0100392extern void ripng_zebra_ipv6_add (struct prefix_ipv6 *p,
393 struct in6_addr *nexthop,
394 unsigned int ifindex, u_char metric);
395extern void ripng_zebra_ipv6_delete (struct prefix_ipv6 *p,
396 struct in6_addr *nexthop,
397 unsigned int ifindex);
hassoa94434b2003-05-25 17:10:12 +0000398
Paul Jakma6ac29a52008-08-15 13:45:30 +0100399extern void ripng_redistribute_clean (void);
400extern int ripng_redistribute_check (int);
401extern void ripng_redistribute_write (struct vty *, int);
hassoa94434b2003-05-25 17:10:12 +0000402
Paul Jakma6ac29a52008-08-15 13:45:30 +0100403extern int ripng_write_rte (int num, struct stream *s, struct prefix_ipv6 *p,
404 struct in6_addr *nexthop,
405 u_int16_t tag, u_char metric);
406extern int ripng_send_packet (caddr_t buf, int bufsize,
407 struct sockaddr_in6 *to, struct interface *ifp);
hassoa94434b2003-05-25 17:10:12 +0000408
Paul Jakma6ac29a52008-08-15 13:45:30 +0100409extern void ripng_packet_dump (struct ripng_packet *packet, int size,
410 const char *sndrcv);
hassoa94434b2003-05-25 17:10:12 +0000411
Paul Jakma6ac29a52008-08-15 13:45:30 +0100412extern int ripng_interface_up (int command, struct zclient *, zebra_size_t);
413extern int ripng_interface_down (int command, struct zclient *, zebra_size_t);
414extern int ripng_interface_add (int command, struct zclient *, zebra_size_t);
415extern int ripng_interface_delete (int command, struct zclient *, zebra_size_t);
416extern int ripng_interface_address_add (int command, struct zclient *, zebra_size_t);
417extern int ripng_interface_address_delete (int command, struct zclient *, zebra_size_t);
418
419extern int ripng_network_write (struct vty *, int);
paul718e3742002-12-13 20:15:29 +0000420
421#endif /* _ZEBRA_RIPNG_RIPNGD_H */