]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
718e3744 | 2 | /* |
3 | * RIPng related value and structure. | |
4 | * Copyright (C) 1998 Kunihiro Ishiguro | |
718e3744 | 5 | */ |
6 | ||
7 | #ifndef _ZEBRA_RIPNG_RIPNGD_H | |
8 | #define _ZEBRA_RIPNG_RIPNGD_H | |
9 | ||
6ac29a51 PJ |
10 | #include <zclient.h> |
11 | #include <vty.h> | |
03a38493 | 12 | #include <distribute.h> |
b0ba762f | 13 | #include <vector.h> |
b3a7e30d | 14 | #include <memory.h> |
4a1ab8e4 | 15 | |
718e3744 | 16 | /* RIPng version and port number. */ |
17 | #define RIPNG_V1 1 | |
18 | #define RIPNG_PORT_DEFAULT 521 | |
19 | #define RIPNG_VTY_PORT 2603 | |
718e3744 | 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 | ||
a94434b6 | 32 | /* RIPng peer timeout value. */ |
33 | #define RIPNG_PEER_TIMER_DEFAULT 180 | |
34 | ||
718e3744 | 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 | |
a94434b6 | 41 | #define RIPNG_ROUTE_DEFAULT 2 |
42 | #define RIPNG_ROUTE_REDISTRIBUTE 3 | |
43 | #define RIPNG_ROUTE_INTERFACE 4 | |
44 | #define RIPNG_ROUTE_AGGREGATE 5 | |
718e3744 | 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 | ||
718e3744 | 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 | ||
718e3744 | 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 | ||
e9ce224b RW |
70 | /* YANG paths */ |
71 | #define RIPNG_INSTANCE "/frr-ripngd:ripngd/instance" | |
72 | #define RIPNG_IFACE "/frr-interface:lib/interface/frr-ripngd:ripng" | |
73 | ||
bf8d3d6a | 74 | DECLARE_MGROUP(RIPNGD); |
b3a7e30d | 75 | |
718e3744 | 76 | /* RIPng structure. */ |
d62a17ae | 77 | struct ripng { |
dde7b15b RW |
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; | |
5c84b9a5 | 88 | |
d62a17ae | 89 | /* RIPng socket. */ |
90 | int sock; | |
91 | ||
92 | /* RIPng Parameters.*/ | |
d7c0a89a QY |
93 | uint8_t command; |
94 | uint8_t version; | |
f8981ec5 RW |
95 | uint16_t update_time; |
96 | uint16_t timeout_time; | |
97 | uint16_t garbage_time; | |
d62a17ae | 98 | int max_mtu; |
ad8778c0 | 99 | uint8_t default_metric; |
d62a17ae | 100 | |
101 | /* Input/output buffer of RIPng. */ | |
102 | struct stream *ibuf; | |
103 | struct stream *obuf; | |
104 | ||
105 | /* RIPng routing information base. */ | |
fe08ba7e | 106 | struct agg_table *table; |
d62a17ae | 107 | |
ecece94c RW |
108 | /* Linked list of RIPng peers. */ |
109 | struct list *peer_list; | |
110 | ||
b0ba762f RW |
111 | /* RIPng enabled interfaces. */ |
112 | vector enable_if; | |
113 | ||
29b94d58 RW |
114 | /* RIPng enabled networks. */ |
115 | struct agg_table *enable_network; | |
116 | ||
0c32404f RW |
117 | /* Vector to store passive-interface name. */ |
118 | vector passive_interface; | |
119 | ||
26c6be93 RW |
120 | /* RIPng offset-lists. */ |
121 | struct list *offset_list_master; | |
122 | ||
d62a17ae | 123 | /* RIPng threads. */ |
e6685141 DS |
124 | struct event *t_read; |
125 | struct event *t_update; | |
d62a17ae | 126 | |
127 | /* Triggered update hack. */ | |
128 | int trigger; | |
e6685141 DS |
129 | struct event *t_triggered_update; |
130 | struct event *t_triggered_interval; | |
d62a17ae | 131 | |
132 | /* RIPng ECMP flag */ | |
57aedde6 | 133 | uint8_t ecmp; |
d62a17ae | 134 | |
f9120f71 | 135 | /* RIPng redistribute configuration. */ |
d62a17ae | 136 | struct { |
f9120f71 RW |
137 | bool enabled; |
138 | struct { | |
139 | char *name; | |
140 | struct route_map *map; | |
141 | } route_map; | |
db2038c7 RW |
142 | bool metric_config; |
143 | uint8_t metric; | |
f9120f71 | 144 | } redist[ZEBRA_ROUTE_MAX]; |
03a38493 PG |
145 | |
146 | /* For distribute-list container */ | |
147 | struct distribute_ctx *distribute_ctx; | |
4b23867c PG |
148 | |
149 | /* For if_rmap container */ | |
150 | struct if_rmap_ctx *if_rmap_ctx; | |
718e3744 | 151 | }; |
dde7b15b RW |
152 | RB_HEAD(ripng_instance_head, ripng); |
153 | RB_PROTOTYPE(ripng_instance_head, ripng, entry, ripng_instance_compare) | |
718e3744 | 154 | |
155 | /* Routing table entry. */ | |
d62a17ae | 156 | struct rte { |
157 | struct in6_addr addr; /* RIPng destination prefix */ | |
d7c0a89a QY |
158 | uint16_t tag; /* RIPng tag */ |
159 | uint8_t prefixlen; /* Length of the RIPng prefix */ | |
160 | uint8_t metric; /* Metric of the RIPng route */ | |
d62a17ae | 161 | /* The nexthop is stored by the structure |
162 | * ripng_nexthop within ripngd.c */ | |
718e3744 | 163 | }; |
164 | ||
165 | /* RIPNG send packet. */ | |
d62a17ae | 166 | struct ripng_packet { |
d7c0a89a QY |
167 | uint8_t command; |
168 | uint8_t version; | |
169 | uint16_t zero; | |
d62a17ae | 170 | struct rte rte[1]; |
718e3744 | 171 | }; |
172 | ||
173 | /* Each route's information. */ | |
d62a17ae | 174 | struct ripng_info { |
175 | /* This route's type. Static, ripng or aggregate. */ | |
d7c0a89a | 176 | uint8_t type; |
718e3744 | 177 | |
d62a17ae | 178 | /* Sub type for static route. */ |
d7c0a89a | 179 | uint8_t sub_type; |
718e3744 | 180 | |
d62a17ae | 181 | /* RIPng specific information */ |
182 | struct in6_addr nexthop; | |
183 | struct in6_addr from; | |
718e3744 | 184 | |
d62a17ae | 185 | /* Which interface does this route come from. */ |
186 | ifindex_t ifindex; | |
718e3744 | 187 | |
d62a17ae | 188 | /* Metric of this route. */ |
d7c0a89a | 189 | uint8_t metric; |
718e3744 | 190 | |
d62a17ae | 191 | /* Tag field of RIPng packet.*/ |
d7c0a89a | 192 | uint16_t tag; |
718e3744 | 193 | |
d62a17ae | 194 | /* For aggregation. */ |
195 | unsigned int suppress; | |
718e3744 | 196 | |
d62a17ae | 197 | /* Flags of RIPng route. */ |
718e3744 | 198 | #define RIPNG_RTF_FIB 1 |
199 | #define RIPNG_RTF_CHANGED 2 | |
d7c0a89a | 200 | uint8_t flags; |
718e3744 | 201 | |
d62a17ae | 202 | /* Garbage collect timer. */ |
e6685141 DS |
203 | struct event *t_timeout; |
204 | struct event *t_garbage_collect; | |
718e3744 | 205 | |
d62a17ae | 206 | /* Route-map features - this variables can be changed. */ |
207 | struct in6_addr nexthop_out; | |
d7c0a89a QY |
208 | uint8_t metric_set; |
209 | uint8_t metric_out; | |
210 | uint16_t tag_out; | |
718e3744 | 211 | |
fe08ba7e | 212 | struct agg_node *rp; |
718e3744 | 213 | }; |
214 | ||
a94434b6 | 215 | typedef enum { |
d62a17ae | 216 | RIPNG_NO_SPLIT_HORIZON = 0, |
217 | RIPNG_SPLIT_HORIZON, | |
218 | RIPNG_SPLIT_HORIZON_POISONED_REVERSE | |
a94434b6 | 219 | } split_horizon_policy_t; |
718e3744 | 220 | |
221 | /* RIPng specific interface configuration. */ | |
d62a17ae | 222 | struct ripng_interface { |
5c84b9a5 RW |
223 | /* Parent routing instance. */ |
224 | struct ripng *ripng; | |
225 | ||
d62a17ae | 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; | |
d62a17ae | 235 | |
236 | /* For filter type slot. */ | |
718e3744 | 237 | #define RIPNG_FILTER_IN 0 |
238 | #define RIPNG_FILTER_OUT 1 | |
239 | #define RIPNG_FILTER_MAX 2 | |
240 | ||
d62a17ae | 241 | /* Access-list. */ |
242 | struct access_list *list[RIPNG_FILTER_MAX]; | |
718e3744 | 243 | |
d62a17ae | 244 | /* Prefix-list. */ |
245 | struct prefix_list *prefix[RIPNG_FILTER_MAX]; | |
718e3744 | 246 | |
d62a17ae | 247 | /* Route-map. */ |
248 | struct route_map *routemap[RIPNG_FILTER_MAX]; | |
718e3744 | 249 | |
d62a17ae | 250 | /* Default information originate. */ |
d7c0a89a | 251 | uint8_t default_originate; |
718e3744 | 252 | |
d62a17ae | 253 | /* Default information only. */ |
d7c0a89a | 254 | uint8_t default_only; |
718e3744 | 255 | |
d62a17ae | 256 | /* Wake up thread. */ |
e6685141 | 257 | struct event *t_wakeup; |
718e3744 | 258 | |
d62a17ae | 259 | /* Passive interface. */ |
260 | int passive; | |
718e3744 | 261 | }; |
262 | ||
a94434b6 | 263 | /* RIPng peer information. */ |
d62a17ae | 264 | struct ripng_peer { |
5c84b9a5 RW |
265 | /* Parent routing instance. */ |
266 | struct ripng *ripng; | |
267 | ||
d62a17ae | 268 | /* Peer address. */ |
269 | struct in6_addr addr; | |
a94434b6 | 270 | |
d62a17ae | 271 | /* Peer RIPng tag value. */ |
272 | int domain; | |
a94434b6 | 273 | |
d62a17ae | 274 | /* Last update time. */ |
275 | time_t uptime; | |
a94434b6 | 276 | |
d62a17ae | 277 | /* Peer RIP version. */ |
d7c0a89a | 278 | uint8_t version; |
a94434b6 | 279 | |
d62a17ae | 280 | /* Statistics. */ |
281 | int recv_badpackets; | |
282 | int recv_badroutes; | |
a94434b6 | 283 | |
d62a17ae | 284 | /* Timeout thread. */ |
e6685141 | 285 | struct event *t_timeout; |
a94434b6 | 286 | }; |
287 | ||
718e3744 | 288 | /* All RIPng events. */ |
d62a17ae | 289 | enum ripng_event { |
290 | RIPNG_READ, | |
291 | RIPNG_ZEBRA, | |
292 | RIPNG_REQUEST_EVENT, | |
293 | RIPNG_UPDATE_EVENT, | |
294 | RIPNG_TRIGGERED_UPDATE, | |
718e3744 | 295 | }; |
296 | ||
297 | /* RIPng timer on/off macro. */ | |
907a2395 | 298 | #define RIPNG_TIMER_ON(T, F, V) event_add_timer(master, (F), rinfo, (V), &(T)) |
718e3744 | 299 | |
b09956ca RW |
300 | #define RIPNG_OFFSET_LIST_IN 0 |
301 | #define RIPNG_OFFSET_LIST_OUT 1 | |
302 | #define RIPNG_OFFSET_LIST_MAX 2 | |
303 | ||
304 | struct ripng_offset_list { | |
5c84b9a5 RW |
305 | /* Parent routing instance. */ |
306 | struct ripng *ripng; | |
307 | ||
b09956ca RW |
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 | ||
718e3744 | 317 | /* Extern variables. */ |
5cb6ce9c | 318 | extern struct zebra_privs_t ripngd_privs; |
cd9d0537 | 319 | extern struct event_loop *master; |
80cf4e45 | 320 | extern struct ripng_instance_head ripng_instances; |
718e3744 | 321 | |
322 | /* Prototypes. */ | |
d62a17ae | 323 | extern void ripng_init(void); |
5c84b9a5 RW |
324 | extern void ripng_clean(struct ripng *ripng); |
325 | extern void ripng_clean_network(struct ripng *ripng); | |
326 | extern void ripng_interface_clean(struct ripng *ripng); | |
327 | extern int ripng_enable_network_add(struct ripng *ripng, struct prefix *p); | |
328 | extern int ripng_enable_network_delete(struct ripng *ripng, struct prefix *p); | |
329 | extern int ripng_enable_if_add(struct ripng *ripng, const char *ifname); | |
330 | extern int ripng_enable_if_delete(struct ripng *ripng, const char *ifname); | |
331 | extern int ripng_passive_interface_set(struct ripng *ripng, const char *ifname); | |
332 | extern int ripng_passive_interface_unset(struct ripng *ripng, | |
333 | const char *ifname); | |
334 | extern void ripng_passive_interface_clean(struct ripng *ripng); | |
d62a17ae | 335 | extern void ripng_if_init(void); |
336 | extern void ripng_route_map_init(void); | |
dde7b15b RW |
337 | extern void ripng_zebra_vrf_register(struct vrf *vrf); |
338 | extern void ripng_zebra_vrf_deregister(struct vrf *vrf); | |
d62a17ae | 339 | extern void ripng_terminate(void); |
340 | /* zclient_init() is done by ripng_zebra.c:zebra_init() */ | |
cd9d0537 | 341 | extern void zebra_init(struct event_loop *master); |
d62a17ae | 342 | extern void ripng_zebra_stop(void); |
5c84b9a5 RW |
343 | extern void ripng_redistribute_conf_update(struct ripng *ripng, int type); |
344 | extern void ripng_redistribute_conf_delete(struct ripng *ripng, int type); | |
345 | ||
346 | extern void ripng_peer_update(struct ripng *ripng, struct sockaddr_in6 *from, | |
347 | uint8_t version); | |
348 | extern void ripng_peer_bad_route(struct ripng *ripng, | |
349 | struct sockaddr_in6 *from); | |
350 | extern void ripng_peer_bad_packet(struct ripng *ripng, | |
351 | struct sockaddr_in6 *from); | |
352 | extern void ripng_peer_display(struct vty *vty, struct ripng *ripng); | |
353 | extern struct ripng_peer *ripng_peer_lookup(struct ripng *ripng, | |
354 | struct in6_addr *addr); | |
355 | extern struct ripng_peer *ripng_peer_lookup_next(struct ripng *ripng, | |
356 | struct in6_addr *addr); | |
ecece94c | 357 | extern int ripng_peer_list_cmp(struct ripng_peer *p1, struct ripng_peer *p2); |
56bf1cb2 | 358 | extern void ripng_peer_list_del(void *arg); |
d62a17ae | 359 | |
5c84b9a5 RW |
360 | extern struct ripng_offset_list *ripng_offset_list_new(struct ripng *ripng, |
361 | const char *ifname); | |
b09956ca | 362 | extern void ripng_offset_list_del(struct ripng_offset_list *offset); |
6c4c3561 | 363 | extern void ripng_offset_list_free(struct ripng_offset_list *offset); |
5c84b9a5 RW |
364 | extern struct ripng_offset_list *ripng_offset_list_lookup(struct ripng *ripng, |
365 | const char *ifname); | |
366 | extern int ripng_offset_list_apply_in(struct ripng *ripng, | |
367 | struct prefix_ipv6 *p, | |
368 | struct interface *ifp, uint8_t *metric); | |
369 | extern int ripng_offset_list_apply_out(struct ripng *ripng, | |
370 | struct prefix_ipv6 *p, | |
371 | struct interface *ifp, uint8_t *metric); | |
26c6be93 RW |
372 | extern int offset_list_cmp(struct ripng_offset_list *o1, |
373 | struct ripng_offset_list *o2); | |
d62a17ae | 374 | |
49e06d25 | 375 | extern int ripng_route_rte(struct ripng_info *rinfo); |
d62a17ae | 376 | extern struct ripng_info *ripng_info_new(void); |
377 | extern void ripng_info_free(struct ripng_info *rinfo); | |
5c84b9a5 RW |
378 | extern struct ripng *ripng_info_get_instance(const struct ripng_info *rinfo); |
379 | extern void ripng_event(struct ripng *ripng, enum ripng_event event, int sock); | |
d62a17ae | 380 | extern int ripng_request(struct interface *ifp); |
5c84b9a5 RW |
381 | extern 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); | |
384 | extern void ripng_redistribute_delete(struct ripng *ripng, int type, | |
385 | int sub_type, struct prefix_ipv6 *p, | |
386 | ifindex_t ifindex); | |
387 | extern void ripng_redistribute_withdraw(struct ripng *ripng, int type); | |
388 | ||
389 | extern void ripng_ecmp_disable(struct ripng *ripng); | |
d62a17ae | 390 | extern void ripng_distribute_update_interface(struct interface *); |
391 | extern void ripng_if_rmap_update_interface(struct interface *); | |
392 | ||
5c84b9a5 RW |
393 | extern void ripng_zebra_ipv6_add(struct ripng *ripng, struct agg_node *node); |
394 | extern void ripng_zebra_ipv6_delete(struct ripng *ripng, struct agg_node *node); | |
d62a17ae | 395 | |
f9120f71 RW |
396 | extern void ripng_redistribute_enable(struct ripng *ripng); |
397 | extern void ripng_redistribute_disable(struct ripng *ripng); | |
5c84b9a5 RW |
398 | extern int ripng_redistribute_check(struct ripng *ripng, int type); |
399 | extern void ripng_redistribute_write(struct vty *vty, struct ripng *ripng); | |
d62a17ae | 400 | |
401 | extern int ripng_write_rte(int num, struct stream *s, struct prefix_ipv6 *p, | |
d7c0a89a QY |
402 | struct in6_addr *nexthop, uint16_t tag, |
403 | uint8_t metric); | |
d62a17ae | 404 | extern int ripng_send_packet(caddr_t buf, int bufsize, struct sockaddr_in6 *to, |
405 | struct interface *ifp); | |
406 | ||
407 | extern void ripng_packet_dump(struct ripng_packet *packet, int size, | |
408 | const char *sndrcv); | |
409 | ||
121f9dee QY |
410 | extern int ripng_interface_up(ZAPI_CALLBACK_ARGS); |
411 | extern int ripng_interface_down(ZAPI_CALLBACK_ARGS); | |
412 | extern int ripng_interface_add(ZAPI_CALLBACK_ARGS); | |
413 | extern int ripng_interface_delete(ZAPI_CALLBACK_ARGS); | |
414 | extern int ripng_interface_address_add(ZAPI_CALLBACK_ARGS); | |
415 | extern int ripng_interface_address_delete(ZAPI_CALLBACK_ARGS); | |
416 | extern int ripng_interface_vrf_update(ZAPI_CALLBACK_ARGS); | |
dde7b15b | 417 | extern void ripng_interface_sync(struct interface *ifp); |
d62a17ae | 418 | |
5c84b9a5 | 419 | extern struct ripng *ripng_lookup_by_vrf_id(vrf_id_t vrf_id); |
dde7b15b RW |
420 | extern struct ripng *ripng_lookup_by_vrf_name(const char *vrf_name); |
421 | extern struct ripng *ripng_create(const char *vrf_name, struct vrf *vrf, | |
422 | int socket); | |
423 | extern int ripng_make_socket(struct vrf *vrf); | |
5c84b9a5 RW |
424 | extern int ripng_network_write(struct vty *vty, struct ripng *ripng); |
425 | ||
426 | extern struct ripng_info *ripng_ecmp_add(struct ripng *ripng, | |
427 | struct ripng_info *rinfo); | |
428 | extern struct ripng_info *ripng_ecmp_replace(struct ripng *ripng, | |
429 | struct ripng_info *rinfo); | |
430 | extern struct ripng_info *ripng_ecmp_delete(struct ripng *ripng, | |
431 | struct ripng_info *rinfo); | |
57aedde6 | 432 | extern void ripng_ecmp_change(struct ripng *ripng); |
c880b636 | 433 | |
dde7b15b RW |
434 | extern void ripng_vrf_init(void); |
435 | extern void ripng_vrf_terminate(void); | |
e9ce224b | 436 | extern void ripng_cli_init(void); |
e9ce224b | 437 | |
6c5ffa88 DA |
438 | extern uint32_t zebra_ecmp_count; |
439 | ||
718e3744 | 440 | #endif /* _ZEBRA_RIPNG_RIPNGD_H */ |