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