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