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