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