]> git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripngd.h
Merge pull request #5396 from ton31337/fix/send_BGP_NOTIFY_CEASE_PEER_UNCONFIG_after_...
[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 RB_ENTRY(ripng) entry;
93
94 /* VRF this routing instance is associated with. */
95 char *vrf_name;
96
97 /* VRF backpointer (might be NULL if the VRF doesn't exist). */
98 struct vrf *vrf;
99
100 /* Status of the routing instance. */
101 bool enabled;
102
103 /* RIPng socket. */
104 int sock;
105
106 /* RIPng Parameters.*/
107 uint8_t command;
108 uint8_t version;
109 uint16_t update_time;
110 uint16_t timeout_time;
111 uint16_t garbage_time;
112 int max_mtu;
113 uint8_t default_metric;
114
115 /* Input/output buffer of RIPng. */
116 struct stream *ibuf;
117 struct stream *obuf;
118
119 /* RIPng routing information base. */
120 struct agg_table *table;
121
122 /* Linked list of RIPng peers. */
123 struct list *peer_list;
124
125 /* RIPng enabled interfaces. */
126 vector enable_if;
127
128 /* RIPng enabled networks. */
129 struct agg_table *enable_network;
130
131 /* Vector to store passive-interface name. */
132 vector passive_interface;
133
134 /* RIPng offset-lists. */
135 struct list *offset_list_master;
136
137 /* RIPng threads. */
138 struct thread *t_read;
139 struct thread *t_write;
140 struct thread *t_update;
141 struct thread *t_garbage;
142 struct thread *t_zebra;
143
144 /* Triggered update hack. */
145 int trigger;
146 struct thread *t_triggered_update;
147 struct thread *t_triggered_interval;
148
149 /* RIPng ECMP flag */
150 bool ecmp;
151
152 /* RIPng redistribute configuration. */
153 struct {
154 bool enabled;
155 struct {
156 char *name;
157 struct route_map *map;
158 } route_map;
159 bool metric_config;
160 uint8_t metric;
161 } redist[ZEBRA_ROUTE_MAX];
162
163 /* For distribute-list container */
164 struct distribute_ctx *distribute_ctx;
165
166 /* For if_rmap container */
167 struct if_rmap_ctx *if_rmap_ctx;
168 };
169 RB_HEAD(ripng_instance_head, ripng);
170 RB_PROTOTYPE(ripng_instance_head, ripng, entry, ripng_instance_compare)
171
172 /* Routing table entry. */
173 struct rte {
174 struct in6_addr addr; /* RIPng destination prefix */
175 uint16_t tag; /* RIPng tag */
176 uint8_t prefixlen; /* Length of the RIPng prefix */
177 uint8_t metric; /* Metric of the RIPng route */
178 /* The nexthop is stored by the structure
179 * ripng_nexthop within ripngd.c */
180 };
181
182 /* RIPNG send packet. */
183 struct ripng_packet {
184 uint8_t command;
185 uint8_t version;
186 uint16_t zero;
187 struct rte rte[1];
188 };
189
190 /* Each route's information. */
191 struct ripng_info {
192 /* This route's type. Static, ripng or aggregate. */
193 uint8_t type;
194
195 /* Sub type for static route. */
196 uint8_t sub_type;
197
198 /* RIPng specific information */
199 struct in6_addr nexthop;
200 struct in6_addr from;
201
202 /* Which interface does this route come from. */
203 ifindex_t ifindex;
204
205 /* Metric of this route. */
206 uint8_t metric;
207
208 /* Tag field of RIPng packet.*/
209 uint16_t tag;
210
211 /* For aggregation. */
212 unsigned int suppress;
213
214 /* Flags of RIPng route. */
215 #define RIPNG_RTF_FIB 1
216 #define RIPNG_RTF_CHANGED 2
217 uint8_t flags;
218
219 /* Garbage collect timer. */
220 struct thread *t_timeout;
221 struct thread *t_garbage_collect;
222
223 /* Route-map features - this variables can be changed. */
224 struct in6_addr nexthop_out;
225 uint8_t metric_set;
226 uint8_t metric_out;
227 uint16_t tag_out;
228
229 struct agg_node *rp;
230 };
231
232 #ifdef notyet
233 #if 0
234 /* RIPng tag structure. */
235 struct ripng_tag
236 {
237 /* Tag value. */
238 uint16_t tag;
239
240 /* Port. */
241 uint16_t port;
242
243 /* Multicast group. */
244 struct in6_addr maddr;
245
246 /* Table number. */
247 int table;
248
249 /* Distance. */
250 int distance;
251
252 /* Split horizon. */
253 uint8_t split_horizon;
254
255 /* Poison reverse. */
256 uint8_t poison_reverse;
257 };
258 #endif /* 0 */
259 #endif /* not yet */
260
261 typedef enum {
262 RIPNG_NO_SPLIT_HORIZON = 0,
263 RIPNG_SPLIT_HORIZON,
264 RIPNG_SPLIT_HORIZON_POISONED_REVERSE
265 } split_horizon_policy_t;
266
267 /* RIPng specific interface configuration. */
268 struct ripng_interface {
269 /* Parent routing instance. */
270 struct ripng *ripng;
271
272 /* RIPng is enabled on this interface. */
273 int enable_network;
274 int enable_interface;
275
276 /* RIPng is running on this interface. */
277 int running;
278
279 /* Split horizon flag. */
280 split_horizon_policy_t split_horizon;
281
282 /* For filter type slot. */
283 #define RIPNG_FILTER_IN 0
284 #define RIPNG_FILTER_OUT 1
285 #define RIPNG_FILTER_MAX 2
286
287 /* Access-list. */
288 struct access_list *list[RIPNG_FILTER_MAX];
289
290 /* Prefix-list. */
291 struct prefix_list *prefix[RIPNG_FILTER_MAX];
292
293 /* Route-map. */
294 struct route_map *routemap[RIPNG_FILTER_MAX];
295
296 #ifdef notyet
297 #if 0
298 /* RIPng tag configuration. */
299 struct ripng_tag *rtag;
300 #endif /* 0 */
301 #endif /* notyet */
302
303 /* Default information originate. */
304 uint8_t default_originate;
305
306 /* Default information only. */
307 uint8_t default_only;
308
309 /* Wake up thread. */
310 struct thread *t_wakeup;
311
312 /* Passive interface. */
313 int passive;
314 };
315
316 /* RIPng peer information. */
317 struct ripng_peer {
318 /* Parent routing instance. */
319 struct ripng *ripng;
320
321 /* Peer address. */
322 struct in6_addr addr;
323
324 /* Peer RIPng tag value. */
325 int domain;
326
327 /* Last update time. */
328 time_t uptime;
329
330 /* Peer RIP version. */
331 uint8_t version;
332
333 /* Statistics. */
334 int recv_badpackets;
335 int recv_badroutes;
336
337 /* Timeout thread. */
338 struct thread *t_timeout;
339 };
340
341 /* All RIPng events. */
342 enum ripng_event {
343 RIPNG_READ,
344 RIPNG_ZEBRA,
345 RIPNG_REQUEST_EVENT,
346 RIPNG_UPDATE_EVENT,
347 RIPNG_TRIGGERED_UPDATE,
348 };
349
350 /* RIPng timer on/off macro. */
351 #define RIPNG_TIMER_ON(T,F,V) thread_add_timer (master, (F), rinfo, (V), &(T))
352
353 #define RIPNG_TIMER_OFF(T) \
354 do { \
355 if (T) { \
356 thread_cancel(T); \
357 (T) = NULL; \
358 } \
359 } while (0)
360
361 #define RIPNG_OFFSET_LIST_IN 0
362 #define RIPNG_OFFSET_LIST_OUT 1
363 #define RIPNG_OFFSET_LIST_MAX 2
364
365 struct ripng_offset_list {
366 /* Parent routing instance. */
367 struct ripng *ripng;
368
369 char *ifname;
370
371 struct {
372 char *alist_name;
373 /* struct access_list *alist; */
374 uint8_t metric;
375 } direct[RIPNG_OFFSET_LIST_MAX];
376 };
377
378 /* Extern variables. */
379 extern struct zebra_privs_t ripngd_privs;
380 extern struct thread_master *master;
381 extern struct ripng_instance_head ripng_instances;
382
383 /* Prototypes. */
384 extern void ripng_init(void);
385 extern void ripng_clean(struct ripng *ripng);
386 extern void ripng_clean_network(struct ripng *ripng);
387 extern void ripng_interface_clean(struct ripng *ripng);
388 extern int ripng_enable_network_add(struct ripng *ripng, struct prefix *p);
389 extern int ripng_enable_network_delete(struct ripng *ripng, struct prefix *p);
390 extern int ripng_enable_if_add(struct ripng *ripng, const char *ifname);
391 extern int ripng_enable_if_delete(struct ripng *ripng, const char *ifname);
392 extern int ripng_passive_interface_set(struct ripng *ripng, const char *ifname);
393 extern int ripng_passive_interface_unset(struct ripng *ripng,
394 const char *ifname);
395 extern void ripng_passive_interface_clean(struct ripng *ripng);
396 extern void ripng_if_init(void);
397 extern void ripng_route_map_init(void);
398 extern void ripng_zebra_vrf_register(struct vrf *vrf);
399 extern void ripng_zebra_vrf_deregister(struct vrf *vrf);
400 extern void ripng_terminate(void);
401 /* zclient_init() is done by ripng_zebra.c:zebra_init() */
402 extern void zebra_init(struct thread_master *);
403 extern void ripng_zebra_stop(void);
404 extern void ripng_redistribute_conf_update(struct ripng *ripng, int type);
405 extern void ripng_redistribute_conf_delete(struct ripng *ripng, int type);
406
407 extern void ripng_peer_update(struct ripng *ripng, struct sockaddr_in6 *from,
408 uint8_t version);
409 extern void ripng_peer_bad_route(struct ripng *ripng,
410 struct sockaddr_in6 *from);
411 extern void ripng_peer_bad_packet(struct ripng *ripng,
412 struct sockaddr_in6 *from);
413 extern void ripng_peer_display(struct vty *vty, struct ripng *ripng);
414 extern struct ripng_peer *ripng_peer_lookup(struct ripng *ripng,
415 struct in6_addr *addr);
416 extern struct ripng_peer *ripng_peer_lookup_next(struct ripng *ripng,
417 struct in6_addr *addr);
418 extern int ripng_peer_list_cmp(struct ripng_peer *p1, struct ripng_peer *p2);
419 extern void ripng_peer_list_del(void *arg);
420
421 extern struct ripng_offset_list *ripng_offset_list_new(struct ripng *ripng,
422 const char *ifname);
423 extern void ripng_offset_list_del(struct ripng_offset_list *offset);
424 extern void ripng_offset_list_free(struct ripng_offset_list *offset);
425 extern struct ripng_offset_list *ripng_offset_list_lookup(struct ripng *ripng,
426 const char *ifname);
427 extern int ripng_offset_list_apply_in(struct ripng *ripng,
428 struct prefix_ipv6 *p,
429 struct interface *ifp, uint8_t *metric);
430 extern int ripng_offset_list_apply_out(struct ripng *ripng,
431 struct prefix_ipv6 *p,
432 struct interface *ifp, uint8_t *metric);
433 extern int offset_list_cmp(struct ripng_offset_list *o1,
434 struct ripng_offset_list *o2);
435
436 extern int ripng_route_rte(struct ripng_info *rinfo);
437 extern struct ripng_info *ripng_info_new(void);
438 extern void ripng_info_free(struct ripng_info *rinfo);
439 extern struct ripng *ripng_info_get_instance(const struct ripng_info *rinfo);
440 extern void ripng_event(struct ripng *ripng, enum ripng_event event, int sock);
441 extern int ripng_request(struct interface *ifp);
442 extern void ripng_redistribute_add(struct ripng *ripng, int type, int sub_type,
443 struct prefix_ipv6 *p, ifindex_t ifindex,
444 struct in6_addr *nexthop, route_tag_t tag);
445 extern void ripng_redistribute_delete(struct ripng *ripng, int type,
446 int sub_type, struct prefix_ipv6 *p,
447 ifindex_t ifindex);
448 extern void ripng_redistribute_withdraw(struct ripng *ripng, int type);
449
450 extern void ripng_ecmp_disable(struct ripng *ripng);
451 extern void ripng_distribute_update_interface(struct interface *);
452 extern void ripng_if_rmap_update_interface(struct interface *);
453
454 extern void ripng_zebra_ipv6_add(struct ripng *ripng, struct agg_node *node);
455 extern void ripng_zebra_ipv6_delete(struct ripng *ripng, struct agg_node *node);
456
457 extern void ripng_redistribute_enable(struct ripng *ripng);
458 extern void ripng_redistribute_disable(struct ripng *ripng);
459 extern int ripng_redistribute_check(struct ripng *ripng, int type);
460 extern void ripng_redistribute_write(struct vty *vty, struct ripng *ripng);
461
462 extern int ripng_write_rte(int num, struct stream *s, struct prefix_ipv6 *p,
463 struct in6_addr *nexthop, uint16_t tag,
464 uint8_t metric);
465 extern int ripng_send_packet(caddr_t buf, int bufsize, struct sockaddr_in6 *to,
466 struct interface *ifp);
467
468 extern void ripng_packet_dump(struct ripng_packet *packet, int size,
469 const char *sndrcv);
470
471 extern int ripng_interface_up(ZAPI_CALLBACK_ARGS);
472 extern int ripng_interface_down(ZAPI_CALLBACK_ARGS);
473 extern int ripng_interface_add(ZAPI_CALLBACK_ARGS);
474 extern int ripng_interface_delete(ZAPI_CALLBACK_ARGS);
475 extern int ripng_interface_address_add(ZAPI_CALLBACK_ARGS);
476 extern int ripng_interface_address_delete(ZAPI_CALLBACK_ARGS);
477 extern int ripng_interface_vrf_update(ZAPI_CALLBACK_ARGS);
478 extern void ripng_interface_sync(struct interface *ifp);
479
480 extern struct ripng *ripng_lookup_by_vrf_id(vrf_id_t vrf_id);
481 extern struct ripng *ripng_lookup_by_vrf_name(const char *vrf_name);
482 extern struct ripng *ripng_create(const char *vrf_name, struct vrf *vrf,
483 int socket);
484 extern int ripng_make_socket(struct vrf *vrf);
485 extern int ripng_network_write(struct vty *vty, struct ripng *ripng);
486
487 extern struct ripng_info *ripng_ecmp_add(struct ripng *ripng,
488 struct ripng_info *rinfo);
489 extern struct ripng_info *ripng_ecmp_replace(struct ripng *ripng,
490 struct ripng_info *rinfo);
491 extern struct ripng_info *ripng_ecmp_delete(struct ripng *ripng,
492 struct ripng_info *rinfo);
493
494 extern void ripng_vrf_init(void);
495 extern void ripng_vrf_terminate(void);
496
497 /* Northbound. */
498 extern void ripng_cli_init(void);
499 extern const struct frr_yang_module_info frr_ripngd_info;
500
501 #endif /* _ZEBRA_RIPNG_RIPNGD_H */