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