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