]> git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripngd.h
95039bf57961a398de80cc85d223193581bd4178
[mirror_frr.git] / ripngd / ripngd.h
1 /*
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 along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #ifndef _ZEBRA_RIPNG_RIPNGD_H
23 #define _ZEBRA_RIPNG_RIPNGD_H
24
25 #include <zclient.h>
26 #include <vty.h>
27 #include <distribute.h>
28 #include <vector.h>
29
30 #include "ripng_memory.h"
31
32 /* RIPng version and port number. */
33 #define RIPNG_V1 1
34 #define RIPNG_PORT_DEFAULT 521
35 #define RIPNG_VTY_PORT 2603
36 #define RIPNG_MAX_PACKET_SIZE 1500
37 #define RIPNG_PRIORITY_DEFAULT 0
38
39 /* RIPng commands. */
40 #define RIPNG_REQUEST 1
41 #define RIPNG_RESPONSE 2
42
43 /* RIPng metric and multicast group address. */
44 #define RIPNG_METRIC_INFINITY 16
45 #define RIPNG_METRIC_NEXTHOP 0xff
46 #define RIPNG_GROUP "ff02::9"
47
48 /* RIPng peer timeout value. */
49 #define RIPNG_PEER_TIMER_DEFAULT 180
50
51 /* Default config file name. */
52 #define RIPNG_DEFAULT_CONFIG "ripngd.conf"
53
54 /* RIPng route types. */
55 #define RIPNG_ROUTE_RTE 0
56 #define RIPNG_ROUTE_STATIC 1
57 #define RIPNG_ROUTE_DEFAULT 2
58 #define RIPNG_ROUTE_REDISTRIBUTE 3
59 #define RIPNG_ROUTE_INTERFACE 4
60 #define RIPNG_ROUTE_AGGREGATE 5
61
62 /* Interface send/receive configuration. */
63 #define RIPNG_SEND_UNSPEC 0
64 #define RIPNG_SEND_OFF 1
65 #define RIPNG_RECEIVE_UNSPEC 0
66 #define RIPNG_RECEIVE_OFF 1
67
68 /* RIP default route's accept/announce methods. */
69 #define RIPNG_DEFAULT_ADVERTISE_UNSPEC 0
70 #define RIPNG_DEFAULT_ADVERTISE_NONE 1
71 #define RIPNG_DEFAULT_ADVERTISE 2
72
73 #define RIPNG_DEFAULT_ACCEPT_UNSPEC 0
74 #define RIPNG_DEFAULT_ACCEPT_NONE 1
75 #define RIPNG_DEFAULT_ACCEPT 2
76
77 /* For max RTE calculation. */
78 #ifndef IPV6_HDRLEN
79 #define IPV6_HDRLEN 40
80 #endif /* IPV6_HDRLEN */
81
82 #ifndef IFMINMTU
83 #define IFMINMTU 576
84 #endif /* IFMINMTU */
85
86 /* YANG paths */
87 #define RIPNG_INSTANCE "/frr-ripngd:ripngd/instance"
88 #define RIPNG_IFACE "/frr-interface:lib/interface/frr-ripngd:ripng"
89
90 /* RIPng structure. */
91 struct ripng {
92 /* VRF ID. */
93 vrf_id_t vrf_id;
94
95 /* RIPng socket. */
96 int sock;
97
98 /* RIPng Parameters.*/
99 uint8_t command;
100 uint8_t version;
101 uint16_t update_time;
102 uint16_t timeout_time;
103 uint16_t garbage_time;
104 int max_mtu;
105 uint8_t default_metric;
106
107 /* Input/output buffer of RIPng. */
108 struct stream *ibuf;
109 struct stream *obuf;
110
111 /* RIPng routing information base. */
112 struct agg_table *table;
113
114 /* Linked list of RIPng peers. */
115 struct list *peer_list;
116
117 /* RIPng enabled interfaces. */
118 vector enable_if;
119
120 /* RIPng enabled networks. */
121 struct agg_table *enable_network;
122
123 /* Vector to store passive-interface name. */
124 vector passive_interface;
125
126 /* RIPng offset-lists. */
127 struct list *offset_list_master;
128
129 /* RIPng threads. */
130 struct thread *t_read;
131 struct thread *t_write;
132 struct thread *t_update;
133 struct thread *t_garbage;
134 struct thread *t_zebra;
135
136 /* Triggered update hack. */
137 int trigger;
138 struct thread *t_triggered_update;
139 struct thread *t_triggered_interval;
140
141 /* RIPng ECMP flag */
142 bool ecmp;
143
144 /* For redistribute route map. */
145 struct {
146 char *name;
147 struct route_map *map;
148 bool metric_config;
149 uint8_t metric;
150 } route_map[ZEBRA_ROUTE_MAX];
151
152 /* For distribute-list container */
153 struct distribute_ctx *distribute_ctx;
154 };
155
156 /* Routing table entry. */
157 struct rte {
158 struct in6_addr addr; /* RIPng destination prefix */
159 uint16_t tag; /* RIPng tag */
160 uint8_t prefixlen; /* Length of the RIPng prefix */
161 uint8_t metric; /* Metric of the RIPng route */
162 /* The nexthop is stored by the structure
163 * ripng_nexthop within ripngd.c */
164 };
165
166 /* RIPNG send packet. */
167 struct ripng_packet {
168 uint8_t command;
169 uint8_t version;
170 uint16_t zero;
171 struct rte rte[1];
172 };
173
174 /* Each route's information. */
175 struct ripng_info {
176 /* This route's type. Static, ripng or aggregate. */
177 uint8_t type;
178
179 /* Sub type for static route. */
180 uint8_t sub_type;
181
182 /* RIPng specific information */
183 struct in6_addr nexthop;
184 struct in6_addr from;
185
186 /* Which interface does this route come from. */
187 ifindex_t ifindex;
188
189 /* Metric of this route. */
190 uint8_t metric;
191
192 /* Tag field of RIPng packet.*/
193 uint16_t tag;
194
195 /* For aggregation. */
196 unsigned int suppress;
197
198 /* Flags of RIPng route. */
199 #define RIPNG_RTF_FIB 1
200 #define RIPNG_RTF_CHANGED 2
201 uint8_t flags;
202
203 /* Garbage collect timer. */
204 struct thread *t_timeout;
205 struct thread *t_garbage_collect;
206
207 /* Route-map features - this variables can be changed. */
208 struct in6_addr nexthop_out;
209 uint8_t metric_set;
210 uint8_t metric_out;
211 uint16_t tag_out;
212
213 struct agg_node *rp;
214 };
215
216 #ifdef notyet
217 #if 0
218 /* RIPng tag structure. */
219 struct ripng_tag
220 {
221 /* Tag value. */
222 uint16_t tag;
223
224 /* Port. */
225 uint16_t port;
226
227 /* Multicast group. */
228 struct in6_addr maddr;
229
230 /* Table number. */
231 int table;
232
233 /* Distance. */
234 int distance;
235
236 /* Split horizon. */
237 uint8_t split_horizon;
238
239 /* Poison reverse. */
240 uint8_t poison_reverse;
241 };
242 #endif /* 0 */
243 #endif /* not yet */
244
245 typedef enum {
246 RIPNG_NO_SPLIT_HORIZON = 0,
247 RIPNG_SPLIT_HORIZON,
248 RIPNG_SPLIT_HORIZON_POISONED_REVERSE
249 } split_horizon_policy_t;
250
251 /* RIPng specific interface configuration. */
252 struct ripng_interface {
253 /* Parent routing instance. */
254 struct ripng *ripng;
255
256 /* RIPng is enabled on this interface. */
257 int enable_network;
258 int enable_interface;
259
260 /* RIPng is running on this interface. */
261 int running;
262
263 /* Split horizon flag. */
264 split_horizon_policy_t split_horizon;
265
266 /* For filter type slot. */
267 #define RIPNG_FILTER_IN 0
268 #define RIPNG_FILTER_OUT 1
269 #define RIPNG_FILTER_MAX 2
270
271 /* Access-list. */
272 struct access_list *list[RIPNG_FILTER_MAX];
273
274 /* Prefix-list. */
275 struct prefix_list *prefix[RIPNG_FILTER_MAX];
276
277 /* Route-map. */
278 struct route_map *routemap[RIPNG_FILTER_MAX];
279
280 #ifdef notyet
281 #if 0
282 /* RIPng tag configuration. */
283 struct ripng_tag *rtag;
284 #endif /* 0 */
285 #endif /* notyet */
286
287 /* Default information originate. */
288 uint8_t default_originate;
289
290 /* Default information only. */
291 uint8_t default_only;
292
293 /* Wake up thread. */
294 struct thread *t_wakeup;
295
296 /* Passive interface. */
297 int passive;
298 };
299
300 /* RIPng peer information. */
301 struct ripng_peer {
302 /* Parent routing instance. */
303 struct ripng *ripng;
304
305 /* Peer address. */
306 struct in6_addr addr;
307
308 /* Peer RIPng tag value. */
309 int domain;
310
311 /* Last update time. */
312 time_t uptime;
313
314 /* Peer RIP version. */
315 uint8_t version;
316
317 /* Statistics. */
318 int recv_badpackets;
319 int recv_badroutes;
320
321 /* Timeout thread. */
322 struct thread *t_timeout;
323 };
324
325 /* All RIPng events. */
326 enum ripng_event {
327 RIPNG_READ,
328 RIPNG_ZEBRA,
329 RIPNG_REQUEST_EVENT,
330 RIPNG_UPDATE_EVENT,
331 RIPNG_TRIGGERED_UPDATE,
332 };
333
334 /* RIPng timer on/off macro. */
335 #define RIPNG_TIMER_ON(T,F,V) thread_add_timer (master, (F), rinfo, (V), &(T))
336
337 #define RIPNG_TIMER_OFF(T) \
338 do { \
339 if (T) { \
340 thread_cancel(T); \
341 (T) = NULL; \
342 } \
343 } while (0)
344
345 #define RIPNG_OFFSET_LIST_IN 0
346 #define RIPNG_OFFSET_LIST_OUT 1
347 #define RIPNG_OFFSET_LIST_MAX 2
348
349 struct ripng_offset_list {
350 /* Parent routing instance. */
351 struct ripng *ripng;
352
353 char *ifname;
354
355 struct {
356 char *alist_name;
357 /* struct access_list *alist; */
358 uint8_t metric;
359 } direct[RIPNG_OFFSET_LIST_MAX];
360 };
361
362 /* Extern variables. */
363 extern struct zebra_privs_t ripngd_privs;
364 extern struct thread_master *master;
365
366 /* Prototypes. */
367 extern void ripng_init(void);
368 extern void ripng_clean(struct ripng *ripng);
369 extern void ripng_clean_network(struct ripng *ripng);
370 extern void ripng_interface_clean(struct ripng *ripng);
371 extern int ripng_enable_network_add(struct ripng *ripng, struct prefix *p);
372 extern int ripng_enable_network_delete(struct ripng *ripng, struct prefix *p);
373 extern int ripng_enable_if_add(struct ripng *ripng, const char *ifname);
374 extern int ripng_enable_if_delete(struct ripng *ripng, const char *ifname);
375 extern int ripng_passive_interface_set(struct ripng *ripng, const char *ifname);
376 extern int ripng_passive_interface_unset(struct ripng *ripng,
377 const char *ifname);
378 extern void ripng_passive_interface_clean(struct ripng *ripng);
379 extern void ripng_if_init(void);
380 extern void ripng_route_map_init(void);
381 extern void ripng_terminate(void);
382 /* zclient_init() is done by ripng_zebra.c:zebra_init() */
383 extern void zebra_init(struct thread_master *);
384 extern void ripng_zebra_stop(void);
385 extern void ripng_redistribute_conf_update(struct ripng *ripng, int type);
386 extern void ripng_redistribute_conf_delete(struct ripng *ripng, int type);
387
388 extern void ripng_peer_update(struct ripng *ripng, struct sockaddr_in6 *from,
389 uint8_t version);
390 extern void ripng_peer_bad_route(struct ripng *ripng,
391 struct sockaddr_in6 *from);
392 extern void ripng_peer_bad_packet(struct ripng *ripng,
393 struct sockaddr_in6 *from);
394 extern void ripng_peer_display(struct vty *vty, struct ripng *ripng);
395 extern struct ripng_peer *ripng_peer_lookup(struct ripng *ripng,
396 struct in6_addr *addr);
397 extern struct ripng_peer *ripng_peer_lookup_next(struct ripng *ripng,
398 struct in6_addr *addr);
399 extern int ripng_peer_list_cmp(struct ripng_peer *p1, struct ripng_peer *p2);
400 extern void ripng_peer_list_del(void *arg);
401
402 extern struct ripng_offset_list *ripng_offset_list_new(struct ripng *ripng,
403 const char *ifname);
404 extern void ripng_offset_list_del(struct ripng_offset_list *offset);
405 extern struct ripng_offset_list *ripng_offset_list_lookup(struct ripng *ripng,
406 const char *ifname);
407 extern int ripng_offset_list_apply_in(struct ripng *ripng,
408 struct prefix_ipv6 *p,
409 struct interface *ifp, uint8_t *metric);
410 extern int ripng_offset_list_apply_out(struct ripng *ripng,
411 struct prefix_ipv6 *p,
412 struct interface *ifp, uint8_t *metric);
413 extern int offset_list_cmp(struct ripng_offset_list *o1,
414 struct ripng_offset_list *o2);
415
416 extern int ripng_route_rte(struct ripng_info *rinfo);
417 extern struct ripng_info *ripng_info_new(void);
418 extern void ripng_info_free(struct ripng_info *rinfo);
419 extern struct ripng *ripng_info_get_instance(const struct ripng_info *rinfo);
420 extern void ripng_event(struct ripng *ripng, enum ripng_event event, int sock);
421 extern int ripng_request(struct interface *ifp);
422 extern void ripng_redistribute_add(struct ripng *ripng, int type, int sub_type,
423 struct prefix_ipv6 *p, ifindex_t ifindex,
424 struct in6_addr *nexthop, route_tag_t tag);
425 extern void ripng_redistribute_delete(struct ripng *ripng, int type,
426 int sub_type, struct prefix_ipv6 *p,
427 ifindex_t ifindex);
428 extern void ripng_redistribute_withdraw(struct ripng *ripng, int type);
429
430 extern void ripng_ecmp_disable(struct ripng *ripng);
431 extern void ripng_distribute_update_interface(struct interface *);
432 extern void ripng_if_rmap_update_interface(struct interface *);
433
434 extern void ripng_zebra_ipv6_add(struct ripng *ripng, struct agg_node *node);
435 extern void ripng_zebra_ipv6_delete(struct ripng *ripng, struct agg_node *node);
436
437 extern void ripng_redistribute_clean(struct ripng *ripng);
438 extern int ripng_redistribute_check(struct ripng *ripng, int type);
439 extern void ripng_redistribute_write(struct vty *vty, struct ripng *ripng);
440
441 extern int ripng_write_rte(int num, struct stream *s, struct prefix_ipv6 *p,
442 struct in6_addr *nexthop, uint16_t tag,
443 uint8_t metric);
444 extern int ripng_send_packet(caddr_t buf, int bufsize, struct sockaddr_in6 *to,
445 struct interface *ifp);
446
447 extern void ripng_packet_dump(struct ripng_packet *packet, int size,
448 const char *sndrcv);
449
450 extern int ripng_interface_up(int command, struct zclient *, zebra_size_t,
451 vrf_id_t);
452 extern int ripng_interface_down(int command, struct zclient *, zebra_size_t,
453 vrf_id_t);
454 extern int ripng_interface_add(int command, struct zclient *, zebra_size_t,
455 vrf_id_t);
456 extern int ripng_interface_delete(int command, struct zclient *, zebra_size_t,
457 vrf_id_t);
458 extern int ripng_interface_address_add(int command, struct zclient *,
459 zebra_size_t, vrf_id_t);
460 extern int ripng_interface_address_delete(int command, struct zclient *,
461 zebra_size_t, vrf_id_t);
462
463 extern struct ripng *ripng_lookup_by_vrf_id(vrf_id_t vrf_id);
464 extern struct ripng *ripng_create(struct vrf *vrf, int socket);
465 extern int ripng_make_socket(void);
466 extern int ripng_network_write(struct vty *vty, struct ripng *ripng);
467
468 extern struct ripng_info *ripng_ecmp_add(struct ripng *ripng,
469 struct ripng_info *rinfo);
470 extern struct ripng_info *ripng_ecmp_replace(struct ripng *ripng,
471 struct ripng_info *rinfo);
472 extern struct ripng_info *ripng_ecmp_delete(struct ripng *ripng,
473 struct ripng_info *rinfo);
474
475 /* Northbound. */
476 extern void ripng_cli_init(void);
477 extern const struct frr_yang_module_info frr_ripngd_info;
478
479 #endif /* _ZEBRA_RIPNG_RIPNGD_H */