]> git.proxmox.com Git - mirror_frr.git/blob - ripd/ripd.h
yang, ripd: add 'frr-ripd.yang' and associated stub callbacks
[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 "qobj.h"
25 #include "hook.h"
26 #include "nexthop.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 timers */
64 #define RIP_UPDATE_TIMER_DEFAULT 30
65 #define RIP_TIMEOUT_TIMER_DEFAULT 180
66 #define RIP_GARBAGE_TIMER_DEFAULT 120
67
68 /* RIP peer timeout value. */
69 #define RIP_PEER_TIMER_DEFAULT 180
70
71 /* RIP port number. */
72 #define RIP_PORT_DEFAULT 520
73 #define RIP_VTY_PORT 2602
74
75 /* Default configuration file name. */
76 #define RIPD_DEFAULT_CONFIG "ripd.conf"
77
78 /* RIP route types. */
79 #define RIP_ROUTE_RTE 0
80 #define RIP_ROUTE_STATIC 1
81 #define RIP_ROUTE_DEFAULT 2
82 #define RIP_ROUTE_REDISTRIBUTE 3
83 #define RIP_ROUTE_INTERFACE 4
84
85 /* RIPv2 special RTE family types */
86 #define RIP_FAMILY_AUTH 0xffff
87
88 /* RIPv2 authentication types, for RIP_FAMILY_AUTH RTE's */
89 #define RIP_NO_AUTH 0
90 #define RIP_AUTH_DATA 1
91 #define RIP_AUTH_SIMPLE_PASSWORD 2
92 #define RIP_AUTH_MD5 3
93
94 /* RIPv2 Simple authentication */
95 #define RIP_AUTH_SIMPLE_SIZE 16
96
97 /* RIPv2 MD5 authentication. */
98 #define RIP_AUTH_MD5_SIZE 16
99 #define RIP_AUTH_MD5_COMPAT_SIZE RIP_RTE_SIZE
100
101 /* YANG paths */
102 #define RIP_INSTANCE "/frr-ripd:ripd/instance"
103 #define RIP_IFACE "/frr-interface:lib/interface/frr-ripd:rip"
104
105 /* RIP structure. */
106 struct rip {
107 /* RIP socket. */
108 int sock;
109
110 /* Default version of rip instance. */
111 int version_send; /* version 1 or 2 (but not both) */
112 int version_recv; /* version 1 or 2 or both */
113
114 /* Output buffer of RIP. */
115 struct stream *obuf;
116
117 /* RIP routing information base. */
118 struct route_table *table;
119
120 /* RIP only static routing information. */
121 struct route_table *route;
122
123 /* RIP neighbor. */
124 struct route_table *neighbor;
125
126 /* RIP threads. */
127 struct thread *t_read;
128
129 /* Update and garbage timer. */
130 struct thread *t_update;
131
132 /* Triggered update hack. */
133 int trigger;
134 struct thread *t_triggered_update;
135 struct thread *t_triggered_interval;
136
137 /* RIP timer values. */
138 unsigned long update_time;
139 unsigned long timeout_time;
140 unsigned long garbage_time;
141
142 /* RIP default metric. */
143 int default_metric;
144
145 /* RIP default-information originate. */
146 uint8_t default_information;
147 char *default_information_route_map;
148
149 /* RIP default distance. */
150 uint8_t distance;
151 struct route_table *distance_table;
152
153 /* RIP ECMP flag */
154 unsigned int ecmp;
155
156 /* For redistribute route map. */
157 struct {
158 char *name;
159 struct route_map *map;
160 int metric_config;
161 uint32_t metric;
162 } route_map[ZEBRA_ROUTE_MAX];
163
164 QOBJ_FIELDS
165 };
166 DECLARE_QOBJ_TYPE(rip)
167
168 /* RIP routing table entry which belong to rip_packet. */
169 struct rte {
170 uint16_t family; /* Address family of this route. */
171 uint16_t tag; /* Route Tag which included in RIP2 packet. */
172 struct in_addr prefix; /* Prefix of rip route. */
173 struct in_addr mask; /* Netmask of rip route. */
174 struct in_addr nexthop; /* Next hop of rip route. */
175 uint32_t metric; /* Metric value of rip route. */
176 };
177
178 /* RIP packet structure. */
179 struct rip_packet {
180 unsigned char command; /* Command type of RIP packet. */
181 unsigned char version; /* RIP version which coming from peer. */
182 unsigned char pad1; /* Padding of RIP packet header. */
183 unsigned char pad2; /* Same as above. */
184 struct rte rte[1]; /* Address structure. */
185 };
186
187 /* Buffer to read RIP packet. */
188 union rip_buf {
189 struct rip_packet rip_packet;
190 char buf[RIP_PACKET_MAXSIZ];
191 };
192
193 /* RIP route information. */
194 struct rip_info {
195 /* This route's type. */
196 int type;
197
198 /* Sub type. */
199 int sub_type;
200
201 /* RIP nexthop. */
202 struct nexthop nh;
203 struct in_addr from;
204
205 /* Metric of this route. */
206 uint32_t metric;
207
208 /* External metric of this route.
209 if learnt from an externalm proto */
210 uint32_t external_metric;
211
212 /* Tag information of this route. */
213 uint16_t tag;
214
215 /* Flags of RIP route. */
216 #define RIP_RTF_FIB 1
217 #define RIP_RTF_CHANGED 2
218 uint8_t flags;
219
220 /* Garbage collect timer. */
221 struct thread *t_timeout;
222 struct thread *t_garbage_collect;
223
224 /* Route-map futures - this variables can be changed. */
225 struct in_addr nexthop_out;
226 uint8_t metric_set;
227 uint32_t metric_out;
228 uint16_t tag_out;
229 ifindex_t ifindex_out;
230
231 struct route_node *rp;
232
233 uint8_t distance;
234
235 #ifdef NEW_RIP_TABLE
236 struct rip_info *next;
237 struct rip_info *prev;
238 #endif /* NEW_RIP_TABLE */
239 };
240
241 typedef enum {
242 RIP_NO_SPLIT_HORIZON = 0,
243 RIP_SPLIT_HORIZON,
244 RIP_SPLIT_HORIZON_POISONED_REVERSE
245 } split_horizon_policy_t;
246
247 /* RIP specific interface configuration. */
248 struct rip_interface {
249 /* RIP is enabled on this interface. */
250 int enable_network;
251 int enable_interface;
252
253 /* RIP is running on this interface. */
254 int running;
255
256 /* RIP version control. */
257 int ri_send;
258 int ri_receive;
259
260 /* RIPv2 broadcast mode */
261 int v2_broadcast;
262
263 /* RIPv2 authentication type. */
264 int auth_type;
265
266 /* RIPv2 authentication string. */
267 char *auth_str;
268
269 /* RIPv2 authentication key chain. */
270 char *key_chain;
271
272 /* value to use for md5->auth_len */
273 uint8_t md5_auth_len;
274
275 /* Split horizon flag. */
276 split_horizon_policy_t split_horizon;
277 split_horizon_policy_t split_horizon_default;
278
279 /* For filter type slot. */
280 #define RIP_FILTER_IN 0
281 #define RIP_FILTER_OUT 1
282 #define RIP_FILTER_MAX 2
283
284 /* Access-list. */
285 struct access_list *list[RIP_FILTER_MAX];
286
287 /* Prefix-list. */
288 struct prefix_list *prefix[RIP_FILTER_MAX];
289
290 /* Route-map. */
291 struct route_map *routemap[RIP_FILTER_MAX];
292
293 /* Wake up thread. */
294 struct thread *t_wakeup;
295
296 /* Interface statistics. */
297 int recv_badpackets;
298 int recv_badroutes;
299 int sent_updates;
300
301 /* Passive interface. */
302 int passive;
303 };
304
305 /* RIP peer information. */
306 struct rip_peer {
307 /* Peer address. */
308 struct in_addr addr;
309
310 /* Peer RIP tag value. */
311 int domain;
312
313 /* Last update time. */
314 time_t uptime;
315
316 /* Peer RIP version. */
317 uint8_t version;
318
319 /* Statistics. */
320 int recv_badpackets;
321 int recv_badroutes;
322
323 /* Timeout thread. */
324 struct thread *t_timeout;
325 };
326
327 struct rip_md5_info {
328 uint16_t family;
329 uint16_t type;
330 uint16_t packet_len;
331 uint8_t keyid;
332 uint8_t auth_len;
333 uint32_t sequence;
334 uint32_t reserv1;
335 uint32_t reserv2;
336 };
337
338 struct rip_md5_data {
339 uint16_t family;
340 uint16_t type;
341 uint8_t digest[16];
342 };
343
344 /* RIP accepet/announce methods. */
345 #define RI_RIP_UNSPEC 0
346 #define RI_RIP_VERSION_1 1
347 #define RI_RIP_VERSION_2 2
348 #define RI_RIP_VERSION_1_AND_2 3
349 #define RI_RIP_VERSION_NONE 4
350 /* N.B. stuff will break if
351 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
352
353 /* Default value for "default-metric" command. */
354 #define RIP_DEFAULT_METRIC_DEFAULT 1
355
356 /* RIP event. */
357 enum rip_event {
358 RIP_READ,
359 RIP_UPDATE_EVENT,
360 RIP_TRIGGERED_UPDATE,
361 };
362
363 /* Macro for timer turn on. */
364 #define RIP_TIMER_ON(T,F,V) thread_add_timer (master, (F), rinfo, (V), &(T))
365
366 /* Macro for timer turn off. */
367 #define RIP_TIMER_OFF(X) THREAD_TIMER_OFF(X)
368
369 /* Prototypes. */
370 extern void rip_init(void);
371 extern void rip_reset(void);
372 extern void rip_clean(void);
373 extern void rip_clean_network(void);
374 extern void rip_interfaces_clean(void);
375 extern void rip_interfaces_reset(void);
376 extern void rip_passive_nondefault_clean(void);
377 extern void rip_if_init(void);
378 extern void rip_if_down_all(void);
379 extern void rip_route_map_init(void);
380 extern void rip_route_map_reset(void);
381 extern void rip_zclient_init(struct thread_master *);
382 extern void rip_zclient_stop(void);
383 extern void rip_zclient_reset(void);
384 extern void rip_offset_init(void);
385 extern int if_check_address(struct in_addr addr);
386
387 extern int rip_request_send(struct sockaddr_in *, struct interface *, uint8_t,
388 struct connected *);
389 extern int rip_neighbor_lookup(struct sockaddr_in *);
390
391 extern int rip_redistribute_check(int);
392 extern void rip_redistribute_add(int type, int sub_type, struct prefix_ipv4 *p,
393 struct nexthop *nh, unsigned int metric,
394 unsigned char distance, route_tag_t tag);
395 extern void rip_redistribute_delete(int, int, struct prefix_ipv4 *, ifindex_t);
396 extern void rip_redistribute_withdraw(int);
397 extern void rip_zebra_ipv4_add(struct route_node *);
398 extern void rip_zebra_ipv4_delete(struct route_node *);
399 extern void rip_interface_multicast_set(int, struct connected *);
400 extern void rip_distribute_update_interface(struct interface *);
401 extern void rip_if_rmap_update_interface(struct interface *);
402
403 extern int config_write_rip_network(struct vty *, int);
404 extern int config_write_rip_offset_list(struct vty *);
405 extern int config_write_rip_redistribute(struct vty *, int);
406
407 extern void rip_peer_init(void);
408 extern void rip_peer_update(struct sockaddr_in *, uint8_t);
409 extern void rip_peer_bad_route(struct sockaddr_in *);
410 extern void rip_peer_bad_packet(struct sockaddr_in *);
411 extern void rip_peer_display(struct vty *);
412 extern struct rip_peer *rip_peer_lookup(struct in_addr *);
413 extern struct rip_peer *rip_peer_lookup_next(struct in_addr *);
414
415 extern int rip_offset_list_apply_in(struct prefix_ipv4 *, struct interface *,
416 uint32_t *);
417 extern int rip_offset_list_apply_out(struct prefix_ipv4 *, struct interface *,
418 uint32_t *);
419 extern void rip_offset_clean(void);
420
421 extern void rip_info_free(struct rip_info *);
422 extern uint8_t rip_distance_apply(struct rip_info *);
423 extern void rip_redistribute_clean(void);
424
425 extern struct rip_info *rip_ecmp_add(struct rip_info *);
426 extern struct rip_info *rip_ecmp_replace(struct rip_info *);
427 extern struct rip_info *rip_ecmp_delete(struct rip_info *);
428
429 /* There is only one rip strucutre. */
430 extern struct rip *rip;
431
432 extern struct zebra_privs_t ripd_privs;
433
434 /* Master thread strucutre. */
435 extern struct thread_master *master;
436
437 /* RIP statistics for SNMP. */
438 extern long rip_global_route_changes;
439 extern long rip_global_queries;
440
441 DECLARE_HOOK(rip_ifaddr_add, (struct connected * ifc), (ifc))
442 DECLARE_HOOK(rip_ifaddr_del, (struct connected * ifc), (ifc))
443
444 /* Northbound. */
445 extern void rip_cli_init(void);
446 extern const struct frr_yang_module_info frr_ripd_info;
447
448 #endif /* _ZEBRA_RIP_H */