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