]> git.proxmox.com Git - mirror_frr.git/blob - ripd/ripd.h
Merge pull request #12933 from Orange-OpenSource/link_state
[mirror_frr.git] / ripd / ripd.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* RIP related values and structures.
3 * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
4 */
5
6 #ifndef _ZEBRA_RIP_H
7 #define _ZEBRA_RIP_H
8
9 #include "hook.h"
10 #include "nexthop.h"
11 #include "distribute.h"
12 #include "memory.h"
13
14 /* RIP version number. */
15 #define RIPv1 1
16 #define RIPv2 2
17 /* N.B. stuff will break if
18 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
19
20
21 /* RIP command list. */
22 #define RIP_REQUEST 1
23 #define RIP_RESPONSE 2
24 #define RIP_TRACEON 3 /* Obsolete */
25 #define RIP_TRACEOFF 4 /* Obsolete */
26 #define RIP_POLL 5
27 #define RIP_POLL_ENTRY 6
28 #define RIP_COMMAND_MAX 7
29
30 /* RIP metric infinity value.*/
31 #define RIP_METRIC_INFINITY 16
32
33 /* Normal RIP packet min and max size. */
34 #define RIP_PACKET_MINSIZ 4
35 #define RIP_PACKET_MAXSIZ 512
36
37 #define RIP_HEADER_SIZE 4
38 #define RIP_RTE_SIZE 20
39
40 /* Max count of routing table entry in one rip packet. */
41 #define RIP_MAX_RTE ((RIP_PACKET_MAXSIZ - RIP_HEADER_SIZE) / RIP_RTE_SIZE)
42
43 /* RIP version 2 multicast address. */
44 #ifndef INADDR_RIP_GROUP
45 #define INADDR_RIP_GROUP 0xe0000009 /* 224.0.0.9 */
46 #endif
47
48 /* RIP peer timeout value. */
49 #define RIP_PEER_TIMER_DEFAULT 180
50
51 /* RIP port number. */
52 #define RIP_PORT_DEFAULT 520
53 #define RIP_VTY_PORT 2602
54
55 /* Default configuration file name. */
56 #define RIPD_DEFAULT_CONFIG "ripd.conf"
57
58 /* RIP route types. */
59 #define RIP_ROUTE_RTE 0
60 #define RIP_ROUTE_STATIC 1
61 #define RIP_ROUTE_DEFAULT 2
62 #define RIP_ROUTE_REDISTRIBUTE 3
63 #define RIP_ROUTE_INTERFACE 4
64
65 /* RIPv2 special RTE family types */
66 #define RIP_FAMILY_AUTH 0xffff
67
68 /* RIPv2 authentication types, for RIP_FAMILY_AUTH RTE's */
69 #define RIP_NO_AUTH 0
70 #define RIP_AUTH_DATA 1
71 #define RIP_AUTH_SIMPLE_PASSWORD 2
72 #define RIP_AUTH_MD5 3
73
74 /* RIPv2 Simple authentication */
75 #define RIP_AUTH_SIMPLE_SIZE 16
76
77 /* RIPv2 MD5 authentication. */
78 #define RIP_AUTH_MD5_SIZE 16
79 #define RIP_AUTH_MD5_COMPAT_SIZE RIP_RTE_SIZE
80
81 /* YANG paths */
82 #define RIP_INSTANCE "/frr-ripd:ripd/instance"
83 #define RIP_IFACE "/frr-interface:lib/interface/frr-ripd:rip"
84
85 DECLARE_MGROUP(RIPD);
86
87 /* RIP structure. */
88 struct rip {
89 RB_ENTRY(rip) entry;
90
91 /* VRF this routing instance is associated with. */
92 char *vrf_name;
93
94 /* VRF backpointer (might be NULL if the VRF doesn't exist). */
95 struct vrf *vrf;
96
97 /* Status of the routing instance. */
98 bool enabled;
99
100 /* RIP socket. */
101 int sock;
102
103 /* Default version of rip instance. */
104 int version_send; /* version 1 or 2 (but not both) */
105 int version_recv; /* version 1 or 2 or both */
106
107 /* Output buffer of RIP. */
108 struct stream *obuf;
109
110 /* RIP routing information base. */
111 struct route_table *table;
112
113 /* RIP static neighbors. */
114 struct route_table *neighbor;
115
116 /* Linked list of RIP peers. */
117 struct list *peer_list;
118
119 /* RIP threads. */
120 struct event *t_read;
121
122 /* Update and garbage timer. */
123 struct event *t_update;
124
125 /* Triggered update hack. */
126 int trigger;
127 struct event *t_triggered_update;
128 struct event *t_triggered_interval;
129
130 /* RIP timer values. */
131 uint32_t update_time;
132 uint32_t timeout_time;
133 uint32_t garbage_time;
134
135 /* RIP default metric. */
136 uint8_t default_metric;
137
138 /* RIP default distance. */
139 uint8_t distance;
140 struct route_table *distance_table;
141
142 /* RIP ECMP flag */
143 bool ecmp;
144
145 /* Are we in passive-interface default mode? */
146 bool passive_default;
147
148 /* RIP enabled interfaces. */
149 vector enable_interface;
150
151 /* RIP enabled networks. */
152 struct route_table *enable_network;
153
154 /* Vector to store passive-interface name. */
155 vector passive_nondefault;
156
157 /* RIP offset-lists. */
158 struct list *offset_list_master;
159
160 /* RIP redistribute configuration. */
161 struct {
162 bool enabled;
163 struct {
164 char *name;
165 struct route_map *map;
166 } route_map;
167 bool metric_config;
168 uint8_t metric;
169 } redist[ZEBRA_ROUTE_MAX];
170
171 /* For distribute-list container */
172 struct distribute_ctx *distribute_ctx;
173
174 /* For if_rmap container */
175 struct if_rmap_ctx *if_rmap_ctx;
176
177 /* Counters for SNMP. */
178 struct {
179 /* RIP route changes. */
180 long route_changes;
181
182 /* RIP queries. */
183 long queries;
184 } counters;
185 };
186 RB_HEAD(rip_instance_head, rip);
187 RB_PROTOTYPE(rip_instance_head, rip, entry, rip_instance_compare)
188
189 /* RIP routing table entry which belong to rip_packet. */
190 struct rte {
191 uint16_t family; /* Address family of this route. */
192 uint16_t tag; /* Route Tag which included in RIP2 packet. */
193 struct in_addr prefix; /* Prefix of rip route. */
194 struct in_addr mask; /* Netmask of rip route. */
195 struct in_addr nexthop; /* Next hop of rip route. */
196 uint32_t metric; /* Metric value of rip route. */
197 };
198
199 /* RIP packet structure. */
200 struct rip_packet {
201 unsigned char command; /* Command type of RIP packet. */
202 unsigned char version; /* RIP version which coming from peer. */
203 unsigned char pad1; /* Padding of RIP packet header. */
204 unsigned char pad2; /* Same as above. */
205 struct rte rte[1]; /* Address structure. */
206 };
207
208 /* Buffer to read RIP packet. */
209 union rip_buf {
210 struct rip_packet rip_packet;
211 char buf[RIP_PACKET_MAXSIZ];
212 };
213
214 /* RIP route information. */
215 struct rip_info {
216 /* This route's type. */
217 int type;
218
219 /* Sub type. */
220 int sub_type;
221
222 /* RIP nexthop. */
223 struct nexthop nh;
224 struct in_addr from;
225
226 /* Metric of this route. */
227 uint32_t metric;
228
229 /* External metric of this route.
230 if learnt from an externalm proto */
231 uint32_t external_metric;
232
233 /* Tag information of this route. */
234 uint16_t tag;
235
236 /* Flags of RIP route. */
237 #define RIP_RTF_FIB 1
238 #define RIP_RTF_CHANGED 2
239 uint8_t flags;
240
241 /* Garbage collect timer. */
242 struct event *t_timeout;
243 struct event *t_garbage_collect;
244
245 /* Route-map futures - this variables can be changed. */
246 struct in_addr nexthop_out;
247 uint8_t metric_set;
248 uint32_t metric_out;
249 uint16_t tag_out;
250 ifindex_t ifindex_out;
251
252 struct route_node *rp;
253
254 uint8_t distance;
255 };
256
257 typedef enum {
258 RIP_NO_SPLIT_HORIZON = 0,
259 RIP_SPLIT_HORIZON,
260 RIP_SPLIT_HORIZON_POISONED_REVERSE
261 } split_horizon_policy_t;
262
263 /* RIP specific interface configuration. */
264 struct rip_interface {
265 /* Parent routing instance. */
266 struct rip *rip;
267
268 /* RIP is enabled on this interface. */
269 int enable_network;
270 int enable_interface;
271
272 /* RIP is running on this interface. */
273 int running;
274
275 /* RIP version control. */
276 int ri_send;
277 int ri_receive;
278
279 /* RIPv2 broadcast mode */
280 bool v2_broadcast;
281
282 /* RIPv2 authentication type. */
283 int auth_type;
284
285 /* RIPv2 authentication string. */
286 char *auth_str;
287
288 /* RIPv2 authentication key chain. */
289 char *key_chain;
290
291 /* value to use for md5->auth_len */
292 int md5_auth_len;
293
294 /* Split horizon flag. */
295 split_horizon_policy_t split_horizon;
296
297 /* For filter type slot. */
298 #define RIP_FILTER_IN 0
299 #define RIP_FILTER_OUT 1
300 #define RIP_FILTER_MAX 2
301
302 /* Access-list. */
303 struct access_list *list[RIP_FILTER_MAX];
304
305 /* Prefix-list. */
306 struct prefix_list *prefix[RIP_FILTER_MAX];
307
308 /* Route-map. */
309 struct route_map *routemap[RIP_FILTER_MAX];
310
311 /* Wake up thread. */
312 struct event *t_wakeup;
313
314 /* Interface statistics. */
315 int recv_badpackets;
316 int recv_badroutes;
317 int sent_updates;
318
319 /* Passive interface. */
320 int passive;
321 };
322
323 /* RIP peer information. */
324 struct rip_peer {
325 /* Parent routing instance. */
326 struct rip *rip;
327
328 /* Peer address. */
329 struct in_addr addr;
330
331 /* Peer RIP tag value. */
332 int domain;
333
334 /* Last update time. */
335 time_t uptime;
336
337 /* Peer RIP version. */
338 uint8_t version;
339
340 /* Statistics. */
341 int recv_badpackets;
342 int recv_badroutes;
343
344 /* Timeout thread. */
345 struct event *t_timeout;
346 };
347
348 struct rip_distance {
349 /* Distance value for the IP source prefix. */
350 uint8_t distance;
351
352 /* Name of the access-list to be matched. */
353 char *access_list;
354 };
355
356 struct rip_md5_info {
357 uint16_t family;
358 uint16_t type;
359 uint16_t packet_len;
360 uint8_t keyid;
361 uint8_t auth_len;
362 uint32_t sequence;
363 uint32_t reserv1;
364 uint32_t reserv2;
365 };
366
367 struct rip_md5_data {
368 uint16_t family;
369 uint16_t type;
370 uint8_t digest[16];
371 };
372
373 /* RIP accepet/announce methods. */
374 #define RI_RIP_UNSPEC 0
375 #define RI_RIP_VERSION_1 1
376 #define RI_RIP_VERSION_2 2
377 #define RI_RIP_VERSION_1_AND_2 3
378 #define RI_RIP_VERSION_NONE 4
379 /* N.B. stuff will break if
380 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
381
382 /* RIP event. */
383 enum rip_event {
384 RIP_READ,
385 RIP_UPDATE_EVENT,
386 RIP_TRIGGERED_UPDATE,
387 };
388
389 /* Macro for timer turn on. */
390 #define RIP_TIMER_ON(T, F, V) event_add_timer(master, (F), rinfo, (V), &(T))
391
392 #define RIP_OFFSET_LIST_IN 0
393 #define RIP_OFFSET_LIST_OUT 1
394 #define RIP_OFFSET_LIST_MAX 2
395
396 struct rip_offset_list {
397 /* Parent routing instance. */
398 struct rip *rip;
399
400 char *ifname;
401
402 struct {
403 char *alist_name;
404 /* struct access_list *alist; */
405 uint8_t metric;
406 } direct[RIP_OFFSET_LIST_MAX];
407 };
408
409 /* Prototypes. */
410 extern void rip_init(void);
411 extern void rip_clean(struct rip *rip);
412 extern void rip_clean_network(struct rip *rip);
413 extern void rip_interfaces_clean(struct rip *rip);
414 extern int rip_passive_nondefault_set(struct rip *rip, const char *ifname);
415 extern int rip_passive_nondefault_unset(struct rip *rip, const char *ifname);
416 extern void rip_passive_nondefault_clean(struct rip *rip);
417 extern void rip_if_init(void);
418 extern void rip_route_map_init(void);
419 extern void rip_zebra_vrf_register(struct vrf *vrf);
420 extern void rip_zebra_vrf_deregister(struct vrf *vrf);
421 extern void rip_zclient_init(struct event_loop *e);
422 extern void rip_zclient_stop(void);
423 extern int if_check_address(struct rip *rip, struct in_addr addr);
424 extern struct rip *rip_lookup_by_vrf_id(vrf_id_t vrf_id);
425 extern struct rip *rip_lookup_by_vrf_name(const char *vrf_name);
426 extern struct rip *rip_create(const char *vrf_name, struct vrf *vrf,
427 int socket);
428
429 extern int rip_request_send(struct sockaddr_in *, struct interface *, uint8_t,
430 struct connected *);
431 extern int rip_neighbor_lookup(struct rip *rip, struct sockaddr_in *from);
432 extern int rip_neighbor_add(struct rip *rip, struct prefix_ipv4 *p);
433 extern int rip_neighbor_delete(struct rip *rip, struct prefix_ipv4 *p);
434
435 extern int rip_enable_network_add(struct rip *rip, struct prefix *p);
436 extern int rip_enable_network_delete(struct rip *rip, struct prefix *p);
437 extern int rip_enable_if_add(struct rip *rip, const char *ifname);
438 extern int rip_enable_if_delete(struct rip *rip, const char *ifname);
439
440 extern void rip_event(struct rip *rip, enum rip_event event, int sock);
441 extern void rip_ecmp_disable(struct rip *rip);
442
443 extern int rip_create_socket(struct vrf *vrf);
444
445 extern int rip_redistribute_check(struct rip *rip, int type);
446 extern void rip_redistribute_conf_update(struct rip *rip, int type);
447 extern void rip_redistribute_conf_delete(struct rip *rip, int type);
448 extern void rip_redistribute_add(struct rip *rip, int type, int sub_type,
449 struct prefix_ipv4 *p, struct nexthop *nh,
450 unsigned int metric, unsigned char distance,
451 route_tag_t tag);
452 extern void rip_redistribute_delete(struct rip *rip, int type, int sub_type,
453 struct prefix_ipv4 *p, ifindex_t ifindex);
454 extern void rip_redistribute_withdraw(struct rip *rip, int type);
455 extern void rip_zebra_ipv4_add(struct rip *rip, struct route_node *rp);
456 extern void rip_zebra_ipv4_delete(struct rip *rip, struct route_node *rp);
457 extern void rip_interface_multicast_set(int, struct connected *);
458 extern void rip_distribute_update_interface(struct interface *);
459 extern void rip_if_rmap_update_interface(struct interface *ifp);
460
461 extern int rip_show_network_config(struct vty *vty, struct rip *rip);
462 extern void rip_show_redistribute_config(struct vty *vty, struct rip *rip);
463
464 extern void rip_peer_update(struct rip *rip, struct sockaddr_in *from,
465 uint8_t version);
466 extern void rip_peer_bad_route(struct rip *rip, struct sockaddr_in *from);
467 extern void rip_peer_bad_packet(struct rip *rip, struct sockaddr_in *from);
468 extern void rip_peer_display(struct vty *vty, struct rip *rip);
469 extern struct rip_peer *rip_peer_lookup(struct rip *rip, struct in_addr *addr);
470 extern struct rip_peer *rip_peer_lookup_next(struct rip *rip,
471 struct in_addr *addr);
472 extern int rip_peer_list_cmp(struct rip_peer *p1, struct rip_peer *p2);
473 extern void rip_peer_list_del(void *arg);
474
475 extern void rip_info_free(struct rip_info *);
476 extern struct rip *rip_info_get_instance(const struct rip_info *rinfo);
477 extern struct rip_distance *rip_distance_new(void);
478 extern void rip_distance_free(struct rip_distance *rdistance);
479 extern uint8_t rip_distance_apply(struct rip *rip, struct rip_info *rinfo);
480 extern void rip_redistribute_enable(struct rip *rip);
481 extern void rip_redistribute_disable(struct rip *rip);
482
483 extern int rip_route_rte(struct rip_info *rinfo);
484 extern struct rip_info *rip_ecmp_add(struct rip *rip,
485 struct rip_info *rinfo_new);
486 extern struct rip_info *rip_ecmp_replace(struct rip *rip,
487 struct rip_info *rinfo_new);
488 extern struct rip_info *rip_ecmp_delete(struct rip *rip,
489 struct rip_info *rinfo);
490
491 extern struct rip_offset_list *rip_offset_list_new(struct rip *rip,
492 const char *ifname);
493 extern void offset_list_del(struct rip_offset_list *offset);
494 extern void offset_list_free(struct rip_offset_list *offset);
495 extern struct rip_offset_list *rip_offset_list_lookup(struct rip *rip,
496 const char *ifname);
497 extern int rip_offset_list_apply_in(struct prefix_ipv4 *, struct interface *,
498 uint32_t *);
499 extern int rip_offset_list_apply_out(struct prefix_ipv4 *, struct interface *,
500 uint32_t *);
501 extern int offset_list_cmp(struct rip_offset_list *o1,
502 struct rip_offset_list *o2);
503
504 extern void rip_vrf_init(void);
505 extern void rip_vrf_terminate(void);
506 extern void rip_cli_init(void);
507
508 extern struct zebra_privs_t ripd_privs;
509 extern struct rip_instance_head rip_instances;
510
511 /* Master thread structure. */
512 extern struct event_loop *master;
513
514 DECLARE_HOOK(rip_ifaddr_add, (struct connected * ifc), (ifc));
515 DECLARE_HOOK(rip_ifaddr_del, (struct connected * ifc), (ifc));
516
517 #endif /* _ZEBRA_RIP_H */