]> git.proxmox.com Git - mirror_frr.git/blame - ripd/ripd.h
*: require ISO C11 (or C++11)
[mirror_frr.git] / ripd / ripd.h
CommitLineData
718e3744 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 *
896014f4
DL
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
718e3744 19 */
20
21#ifndef _ZEBRA_RIP_H
22#define _ZEBRA_RIP_H
23
3012671f 24#include "hook.h"
dd127197 25#include "nexthop.h"
03a38493 26#include "distribute.h"
814a2585 27#include "memory.h"
4a1ab8e4 28
718e3744 29/* RIP version number. */
30#define RIPv1 1
31#define RIPv2 2
f38a471c 32/* N.B. stuff will break if
33 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
34
718e3744 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. */
6a7cff75 56#define RIP_MAX_RTE ((RIP_PACKET_MAXSIZ - RIP_HEADER_SIZE) / RIP_RTE_SIZE)
718e3744 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
718e3744 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
718e3744 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
ca5e516c 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
b14ee00b 89/* RIPv2 Simple authentication */
90#define RIP_AUTH_SIMPLE_SIZE 16
91
ca5e516c 92/* RIPv2 MD5 authentication. */
718e3744 93#define RIP_AUTH_MD5_SIZE 16
ca5e516c 94#define RIP_AUTH_MD5_COMPAT_SIZE RIP_RTE_SIZE
718e3744 95
707656ec
RW
96/* YANG paths */
97#define RIP_INSTANCE "/frr-ripd:ripd/instance"
98#define RIP_IFACE "/frr-interface:lib/interface/frr-ripd:rip"
99
814a2585
DL
100DECLARE_MGROUP(RIPD)
101
718e3744 102/* RIP structure. */
d62a17ae 103struct rip {
ae7b826a
RW
104 RB_ENTRY(rip) entry;
105
106 /* VRF this routing instance is associated with. */
107 char *vrf_name;
108
109 /* VRF backpointer (might be NULL if the VRF doesn't exist). */
110 struct vrf *vrf;
111
112 /* Status of the routing instance. */
113 bool enabled;
045c5389 114
d62a17ae 115 /* RIP socket. */
116 int sock;
117
118 /* Default version of rip instance. */
119 int version_send; /* version 1 or 2 (but not both) */
120 int version_recv; /* version 1 or 2 or both */
121
122 /* Output buffer of RIP. */
123 struct stream *obuf;
124
125 /* RIP routing information base. */
126 struct route_table *table;
127
29e897ad 128 /* RIP static neighbors. */
d62a17ae 129 struct route_table *neighbor;
130
29e897ad
RW
131 /* Linked list of RIP peers. */
132 struct list *peer_list;
133
d62a17ae 134 /* RIP threads. */
135 struct thread *t_read;
136
137 /* Update and garbage timer. */
138 struct thread *t_update;
139
140 /* Triggered update hack. */
141 int trigger;
142 struct thread *t_triggered_update;
143 struct thread *t_triggered_interval;
144
145 /* RIP timer values. */
b745780b
RW
146 uint32_t update_time;
147 uint32_t timeout_time;
148 uint32_t garbage_time;
d62a17ae 149
150 /* RIP default metric. */
282ae30c 151 uint8_t default_metric;
d62a17ae 152
d62a17ae 153 /* RIP default distance. */
d7c0a89a 154 uint8_t distance;
d62a17ae 155 struct route_table *distance_table;
156
157 /* RIP ECMP flag */
edbf59d2 158 bool ecmp;
d62a17ae 159
44f2f852
RW
160 /* Are we in passive-interface default mode? */
161 bool passive_default;
162
ca046902
RW
163 /* RIP enabled interfaces. */
164 vector enable_interface;
165
1205fdc4
RW
166 /* RIP enabled networks. */
167 struct route_table *enable_network;
168
5a29c0d5
RW
169 /* Vector to store passive-interface name. */
170 vector passive_nondefault;
171
3f21c8c4
RW
172 /* RIP offset-lists. */
173 struct list *offset_list_master;
174
f9120f71 175 /* RIP redistribute configuration. */
d62a17ae 176 struct {
f9120f71
RW
177 bool enabled;
178 struct {
179 char *name;
180 struct route_map *map;
181 } route_map;
908f0020
RW
182 bool metric_config;
183 uint8_t metric;
f9120f71 184 } redist[ZEBRA_ROUTE_MAX];
03a38493
PG
185
186 /* For distribute-list container */
187 struct distribute_ctx *distribute_ctx;
c08a2107 188
4b23867c
PG
189 /* For if_rmap container */
190 struct if_rmap_ctx *if_rmap_ctx;
8f88441d 191
c08a2107
RW
192 /* Counters for SNMP. */
193 struct {
194 /* RIP route changes. */
195 long route_changes;
196
197 /* RIP queries. */
198 long queries;
199 } counters;
718e3744 200};
ae7b826a
RW
201RB_HEAD(rip_instance_head, rip);
202RB_PROTOTYPE(rip_instance_head, rip, entry, rip_instance_compare)
718e3744 203
204/* RIP routing table entry which belong to rip_packet. */
d62a17ae 205struct rte {
d7c0a89a
QY
206 uint16_t family; /* Address family of this route. */
207 uint16_t tag; /* Route Tag which included in RIP2 packet. */
d62a17ae 208 struct in_addr prefix; /* Prefix of rip route. */
209 struct in_addr mask; /* Netmask of rip route. */
210 struct in_addr nexthop; /* Next hop of rip route. */
d7c0a89a 211 uint32_t metric; /* Metric value of rip route. */
718e3744 212};
213
214/* RIP packet structure. */
d62a17ae 215struct rip_packet {
216 unsigned char command; /* Command type of RIP packet. */
217 unsigned char version; /* RIP version which coming from peer. */
218 unsigned char pad1; /* Padding of RIP packet header. */
219 unsigned char pad2; /* Same as above. */
220 struct rte rte[1]; /* Address structure. */
718e3744 221};
222
223/* Buffer to read RIP packet. */
d62a17ae 224union rip_buf {
225 struct rip_packet rip_packet;
226 char buf[RIP_PACKET_MAXSIZ];
718e3744 227};
228
229/* RIP route information. */
d62a17ae 230struct rip_info {
231 /* This route's type. */
232 int type;
718e3744 233
d62a17ae 234 /* Sub type. */
235 int sub_type;
718e3744 236
d62a17ae 237 /* RIP nexthop. */
dd127197 238 struct nexthop nh;
d62a17ae 239 struct in_addr from;
718e3744 240
d62a17ae 241 /* Metric of this route. */
d7c0a89a 242 uint32_t metric;
718e3744 243
d62a17ae 244 /* External metric of this route.
245 if learnt from an externalm proto */
d7c0a89a 246 uint32_t external_metric;
fbf5d033 247
d62a17ae 248 /* Tag information of this route. */
d7c0a89a 249 uint16_t tag;
718e3744 250
d62a17ae 251/* Flags of RIP route. */
718e3744 252#define RIP_RTF_FIB 1
253#define RIP_RTF_CHANGED 2
d7c0a89a 254 uint8_t flags;
718e3744 255
d62a17ae 256 /* Garbage collect timer. */
257 struct thread *t_timeout;
258 struct thread *t_garbage_collect;
718e3744 259
d62a17ae 260 /* Route-map futures - this variables can be changed. */
261 struct in_addr nexthop_out;
d7c0a89a
QY
262 uint8_t metric_set;
263 uint32_t metric_out;
264 uint16_t tag_out;
d62a17ae 265 ifindex_t ifindex_out;
718e3744 266
d62a17ae 267 struct route_node *rp;
718e3744 268
d7c0a89a 269 uint8_t distance;
718e3744 270};
271
16705130 272typedef enum {
d62a17ae 273 RIP_NO_SPLIT_HORIZON = 0,
274 RIP_SPLIT_HORIZON,
275 RIP_SPLIT_HORIZON_POISONED_REVERSE
16705130 276} split_horizon_policy_t;
277
718e3744 278/* RIP specific interface configuration. */
d62a17ae 279struct rip_interface {
045c5389
RW
280 /* Parent routing instance. */
281 struct rip *rip;
282
d62a17ae 283 /* RIP is enabled on this interface. */
284 int enable_network;
285 int enable_interface;
718e3744 286
d62a17ae 287 /* RIP is running on this interface. */
288 int running;
718e3744 289
d62a17ae 290 /* RIP version control. */
291 int ri_send;
292 int ri_receive;
718e3744 293
d62a17ae 294 /* RIPv2 broadcast mode */
94b117b2 295 bool v2_broadcast;
f90310cf 296
d62a17ae 297 /* RIPv2 authentication type. */
298 int auth_type;
718e3744 299
d62a17ae 300 /* RIPv2 authentication string. */
301 char *auth_str;
718e3744 302
d62a17ae 303 /* RIPv2 authentication key chain. */
304 char *key_chain;
718e3744 305
d62a17ae 306 /* value to use for md5->auth_len */
94b117b2 307 int md5_auth_len;
ca5e516c 308
d62a17ae 309 /* Split horizon flag. */
310 split_horizon_policy_t split_horizon;
718e3744 311
d62a17ae 312/* For filter type slot. */
718e3744 313#define RIP_FILTER_IN 0
314#define RIP_FILTER_OUT 1
315#define RIP_FILTER_MAX 2
316
d62a17ae 317 /* Access-list. */
318 struct access_list *list[RIP_FILTER_MAX];
718e3744 319
d62a17ae 320 /* Prefix-list. */
321 struct prefix_list *prefix[RIP_FILTER_MAX];
718e3744 322
d62a17ae 323 /* Route-map. */
324 struct route_map *routemap[RIP_FILTER_MAX];
16705130 325
d62a17ae 326 /* Wake up thread. */
327 struct thread *t_wakeup;
718e3744 328
d62a17ae 329 /* Interface statistics. */
330 int recv_badpackets;
331 int recv_badroutes;
332 int sent_updates;
718e3744 333
d62a17ae 334 /* Passive interface. */
335 int passive;
718e3744 336};
337
338/* RIP peer information. */
d62a17ae 339struct rip_peer {
045c5389
RW
340 /* Parent routing instance. */
341 struct rip *rip;
342
d62a17ae 343 /* Peer address. */
344 struct in_addr addr;
718e3744 345
d62a17ae 346 /* Peer RIP tag value. */
347 int domain;
718e3744 348
d62a17ae 349 /* Last update time. */
350 time_t uptime;
718e3744 351
d62a17ae 352 /* Peer RIP version. */
d7c0a89a 353 uint8_t version;
718e3744 354
d62a17ae 355 /* Statistics. */
356 int recv_badpackets;
357 int recv_badroutes;
718e3744 358
d62a17ae 359 /* Timeout thread. */
360 struct thread *t_timeout;
718e3744 361};
362
23b23d8c
RW
363struct rip_distance {
364 /* Distance value for the IP source prefix. */
365 uint8_t distance;
366
367 /* Name of the access-list to be matched. */
368 char *access_list;
369};
370
d62a17ae 371struct rip_md5_info {
d7c0a89a
QY
372 uint16_t family;
373 uint16_t type;
374 uint16_t packet_len;
375 uint8_t keyid;
376 uint8_t auth_len;
377 uint32_t sequence;
378 uint32_t reserv1;
379 uint32_t reserv2;
718e3744 380};
381
d62a17ae 382struct rip_md5_data {
d7c0a89a
QY
383 uint16_t family;
384 uint16_t type;
385 uint8_t digest[16];
718e3744 386};
387
388/* RIP accepet/announce methods. */
389#define RI_RIP_UNSPEC 0
390#define RI_RIP_VERSION_1 1
391#define RI_RIP_VERSION_2 2
392#define RI_RIP_VERSION_1_AND_2 3
6aec4b41 393#define RI_RIP_VERSION_NONE 4
f38a471c 394/* N.B. stuff will break if
395 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
718e3744 396
718e3744 397/* RIP event. */
d62a17ae 398enum rip_event {
399 RIP_READ,
400 RIP_UPDATE_EVENT,
401 RIP_TRIGGERED_UPDATE,
718e3744 402};
403
404/* Macro for timer turn on. */
ffa2c898 405#define RIP_TIMER_ON(T,F,V) thread_add_timer (master, (F), rinfo, (V), &(T))
718e3744 406
407/* Macro for timer turn off. */
50478845 408#define RIP_TIMER_OFF(X) thread_cancel(&(X))
718e3744 409
8c942f65
RW
410#define RIP_OFFSET_LIST_IN 0
411#define RIP_OFFSET_LIST_OUT 1
412#define RIP_OFFSET_LIST_MAX 2
413
414struct rip_offset_list {
045c5389
RW
415 /* Parent routing instance. */
416 struct rip *rip;
417
8c942f65
RW
418 char *ifname;
419
420 struct {
421 char *alist_name;
422 /* struct access_list *alist; */
423 uint8_t metric;
424 } direct[RIP_OFFSET_LIST_MAX];
425};
426
718e3744 427/* Prototypes. */
d62a17ae 428extern void rip_init(void);
045c5389
RW
429extern void rip_clean(struct rip *rip);
430extern void rip_clean_network(struct rip *rip);
431extern void rip_interfaces_clean(struct rip *rip);
432extern int rip_passive_nondefault_set(struct rip *rip, const char *ifname);
433extern int rip_passive_nondefault_unset(struct rip *rip, const char *ifname);
434extern void rip_passive_nondefault_clean(struct rip *rip);
d62a17ae 435extern void rip_if_init(void);
d62a17ae 436extern void rip_route_map_init(void);
ae7b826a
RW
437extern void rip_zebra_vrf_register(struct vrf *vrf);
438extern void rip_zebra_vrf_deregister(struct vrf *vrf);
4140ca4d 439extern void rip_zclient_init(struct thread_master *);
a2f9eb82 440extern void rip_zclient_stop(void);
045c5389
RW
441extern int if_check_address(struct rip *rip, struct in_addr addr);
442extern struct rip *rip_lookup_by_vrf_id(vrf_id_t vrf_id);
ae7b826a
RW
443extern struct rip *rip_lookup_by_vrf_name(const char *vrf_name);
444extern struct rip *rip_create(const char *vrf_name, struct vrf *vrf,
445 int socket);
d62a17ae 446
d7c0a89a 447extern int rip_request_send(struct sockaddr_in *, struct interface *, uint8_t,
d62a17ae 448 struct connected *);
045c5389
RW
449extern int rip_neighbor_lookup(struct rip *rip, struct sockaddr_in *from);
450extern int rip_neighbor_add(struct rip *rip, struct prefix_ipv4 *p);
451extern int rip_neighbor_delete(struct rip *rip, struct prefix_ipv4 *p);
d62a17ae 452
045c5389
RW
453extern int rip_enable_network_add(struct rip *rip, struct prefix *p);
454extern int rip_enable_network_delete(struct rip *rip, struct prefix *p);
455extern int rip_enable_if_add(struct rip *rip, const char *ifname);
456extern int rip_enable_if_delete(struct rip *rip, const char *ifname);
3d7a1be8 457
045c5389
RW
458extern void rip_event(struct rip *rip, enum rip_event event, int sock);
459extern void rip_ecmp_disable(struct rip *rip);
edbf59d2 460
ae7b826a 461extern int rip_create_socket(struct vrf *vrf);
8c9226c2 462
045c5389
RW
463extern int rip_redistribute_check(struct rip *rip, int type);
464extern void rip_redistribute_conf_update(struct rip *rip, int type);
465extern void rip_redistribute_conf_delete(struct rip *rip, int type);
466extern void rip_redistribute_add(struct rip *rip, int type, int sub_type,
467 struct prefix_ipv4 *p, struct nexthop *nh,
468 unsigned int metric, unsigned char distance,
469 route_tag_t tag);
470extern void rip_redistribute_delete(struct rip *rip, int type, int sub_type,
471 struct prefix_ipv4 *p, ifindex_t ifindex);
472extern void rip_redistribute_withdraw(struct rip *rip, int type);
473extern void rip_zebra_ipv4_add(struct rip *rip, struct route_node *rp);
474extern void rip_zebra_ipv4_delete(struct rip *rip, struct route_node *rp);
d62a17ae 475extern void rip_interface_multicast_set(int, struct connected *);
476extern void rip_distribute_update_interface(struct interface *);
4b23867c 477extern void rip_if_rmap_update_interface(struct interface *ifp);
d62a17ae 478
045c5389
RW
479extern int rip_show_network_config(struct vty *vty, struct rip *rip);
480extern void rip_show_redistribute_config(struct vty *vty, struct rip *rip);
481
482extern void rip_peer_update(struct rip *rip, struct sockaddr_in *from,
483 uint8_t version);
484extern void rip_peer_bad_route(struct rip *rip, struct sockaddr_in *from);
485extern void rip_peer_bad_packet(struct rip *rip, struct sockaddr_in *from);
486extern void rip_peer_display(struct vty *vty, struct rip *rip);
487extern struct rip_peer *rip_peer_lookup(struct rip *rip, struct in_addr *addr);
488extern struct rip_peer *rip_peer_lookup_next(struct rip *rip,
489 struct in_addr *addr);
29e897ad 490extern int rip_peer_list_cmp(struct rip_peer *p1, struct rip_peer *p2);
711915d2 491extern void rip_peer_list_del(void *arg);
d62a17ae 492
d62a17ae 493extern void rip_info_free(struct rip_info *);
045c5389 494extern struct rip *rip_info_get_instance(const struct rip_info *rinfo);
23b23d8c
RW
495extern struct rip_distance *rip_distance_new(void);
496extern void rip_distance_free(struct rip_distance *rdistance);
045c5389 497extern uint8_t rip_distance_apply(struct rip *rip, struct rip_info *rinfo);
f9120f71
RW
498extern void rip_redistribute_enable(struct rip *rip);
499extern void rip_redistribute_disable(struct rip *rip);
d62a17ae 500
1137aef4 501extern int rip_route_rte(struct rip_info *rinfo);
045c5389
RW
502extern struct rip_info *rip_ecmp_add(struct rip *rip,
503 struct rip_info *rinfo_new);
504extern struct rip_info *rip_ecmp_replace(struct rip *rip,
505 struct rip_info *rinfo_new);
506extern struct rip_info *rip_ecmp_delete(struct rip *rip,
507 struct rip_info *rinfo);
508
509extern struct rip_offset_list *rip_offset_list_new(struct rip *rip,
510 const char *ifname);
8c942f65 511extern void offset_list_del(struct rip_offset_list *offset);
6c4c3561 512extern void offset_list_free(struct rip_offset_list *offset);
045c5389
RW
513extern struct rip_offset_list *rip_offset_list_lookup(struct rip *rip,
514 const char *ifname);
8c942f65
RW
515extern int rip_offset_list_apply_in(struct prefix_ipv4 *, struct interface *,
516 uint32_t *);
517extern int rip_offset_list_apply_out(struct prefix_ipv4 *, struct interface *,
518 uint32_t *);
3f21c8c4
RW
519extern int offset_list_cmp(struct rip_offset_list *o1,
520 struct rip_offset_list *o2);
8c942f65 521
ae7b826a
RW
522extern void rip_vrf_init(void);
523extern void rip_vrf_terminate(void);
f80ec39e 524extern void rip_cli_init(void);
fe339c95 525
32b5a493 526extern struct zebra_privs_t ripd_privs;
32600a98 527extern struct rip_instance_head rip_instances;
32b5a493 528
718e3744 529/* Master thread strucutre. */
530extern struct thread_master *master;
531
d62a17ae 532DECLARE_HOOK(rip_ifaddr_add, (struct connected * ifc), (ifc))
533DECLARE_HOOK(rip_ifaddr_del, (struct connected * ifc), (ifc))
3012671f 534
718e3744 535#endif /* _ZEBRA_RIP_H */