1 /* RIP related values and structures.
2 * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
4 * This file is part of GNU Zebra.
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
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.
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
27 #include "rip_memory.h"
29 /* RIP version number. */
32 /* N.B. stuff will break if
33 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
36 /* RIP command list. */
38 #define RIP_RESPONSE 2
39 #define RIP_TRACEON 3 /* Obsolete */
40 #define RIP_TRACEOFF 4 /* Obsolete */
42 #define RIP_POLL_ENTRY 6
43 #define RIP_COMMAND_MAX 7
45 /* RIP metric infinity value.*/
46 #define RIP_METRIC_INFINITY 16
48 /* Normal RIP packet min and max size. */
49 #define RIP_PACKET_MINSIZ 4
50 #define RIP_PACKET_MAXSIZ 512
52 #define RIP_HEADER_SIZE 4
53 #define RIP_RTE_SIZE 20
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)
58 /* RIP version 2 multicast address. */
59 #ifndef INADDR_RIP_GROUP
60 #define INADDR_RIP_GROUP 0xe0000009 /* 224.0.0.9 */
64 #define RIP_UPDATE_TIMER_DEFAULT 30
65 #define RIP_TIMEOUT_TIMER_DEFAULT 180
66 #define RIP_GARBAGE_TIMER_DEFAULT 120
68 /* RIP peer timeout value. */
69 #define RIP_PEER_TIMER_DEFAULT 180
71 /* RIP port number. */
72 #define RIP_PORT_DEFAULT 520
73 #define RIP_VTY_PORT 2602
75 /* Default configuration file name. */
76 #define RIPD_DEFAULT_CONFIG "ripd.conf"
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
85 /* RIPv2 special RTE family types */
86 #define RIP_FAMILY_AUTH 0xffff
88 /* RIPv2 authentication types, for RIP_FAMILY_AUTH RTE's */
90 #define RIP_AUTH_DATA 1
91 #define RIP_AUTH_SIMPLE_PASSWORD 2
92 #define RIP_AUTH_MD5 3
94 /* RIPv2 Simple authentication */
95 #define RIP_AUTH_SIMPLE_SIZE 16
97 /* RIPv2 MD5 authentication. */
98 #define RIP_AUTH_MD5_SIZE 16
99 #define RIP_AUTH_MD5_COMPAT_SIZE RIP_RTE_SIZE
102 #define RIP_INSTANCE "/frr-ripd:ripd/instance"
103 #define RIP_IFACE "/frr-interface:lib/interface/frr-ripd:rip"
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 */
114 /* Output buffer of RIP. */
117 /* RIP routing information base. */
118 struct route_table
*table
;
121 struct route_table
*neighbor
;
124 struct thread
*t_read
;
126 /* Update and garbage timer. */
127 struct thread
*t_update
;
129 /* Triggered update hack. */
131 struct thread
*t_triggered_update
;
132 struct thread
*t_triggered_interval
;
134 /* RIP timer values. */
135 unsigned long update_time
;
136 unsigned long timeout_time
;
137 unsigned long garbage_time
;
139 /* RIP default metric. */
140 uint8_t default_metric
;
142 /* RIP default distance. */
144 struct route_table
*distance_table
;
149 /* Are we in passive-interface default mode? */
150 bool passive_default
;
152 /* For redistribute route map. */
155 struct route_map
*map
;
158 } route_map
[ZEBRA_ROUTE_MAX
];
162 DECLARE_QOBJ_TYPE(rip
)
164 /* RIP routing table entry which belong to rip_packet. */
166 uint16_t family
; /* Address family of this route. */
167 uint16_t tag
; /* Route Tag which included in RIP2 packet. */
168 struct in_addr prefix
; /* Prefix of rip route. */
169 struct in_addr mask
; /* Netmask of rip route. */
170 struct in_addr nexthop
; /* Next hop of rip route. */
171 uint32_t metric
; /* Metric value of rip route. */
174 /* RIP packet structure. */
176 unsigned char command
; /* Command type of RIP packet. */
177 unsigned char version
; /* RIP version which coming from peer. */
178 unsigned char pad1
; /* Padding of RIP packet header. */
179 unsigned char pad2
; /* Same as above. */
180 struct rte rte
[1]; /* Address structure. */
183 /* Buffer to read RIP packet. */
185 struct rip_packet rip_packet
;
186 char buf
[RIP_PACKET_MAXSIZ
];
189 /* RIP route information. */
191 /* This route's type. */
201 /* Metric of this route. */
204 /* External metric of this route.
205 if learnt from an externalm proto */
206 uint32_t external_metric
;
208 /* Tag information of this route. */
211 /* Flags of RIP route. */
212 #define RIP_RTF_FIB 1
213 #define RIP_RTF_CHANGED 2
216 /* Garbage collect timer. */
217 struct thread
*t_timeout
;
218 struct thread
*t_garbage_collect
;
220 /* Route-map futures - this variables can be changed. */
221 struct in_addr nexthop_out
;
225 ifindex_t ifindex_out
;
227 struct route_node
*rp
;
232 struct rip_info
*next
;
233 struct rip_info
*prev
;
234 #endif /* NEW_RIP_TABLE */
238 RIP_NO_SPLIT_HORIZON
= 0,
240 RIP_SPLIT_HORIZON_POISONED_REVERSE
241 } split_horizon_policy_t
;
243 /* RIP specific interface configuration. */
244 struct rip_interface
{
245 /* RIP is enabled on this interface. */
247 int enable_interface
;
249 /* RIP is running on this interface. */
252 /* RIP version control. */
256 /* RIPv2 broadcast mode */
259 /* RIPv2 authentication type. */
262 /* RIPv2 authentication string. */
265 /* RIPv2 authentication key chain. */
268 /* value to use for md5->auth_len */
269 uint8_t md5_auth_len
;
271 /* Split horizon flag. */
272 split_horizon_policy_t split_horizon
;
273 split_horizon_policy_t split_horizon_default
;
275 /* For filter type slot. */
276 #define RIP_FILTER_IN 0
277 #define RIP_FILTER_OUT 1
278 #define RIP_FILTER_MAX 2
281 struct access_list
*list
[RIP_FILTER_MAX
];
284 struct prefix_list
*prefix
[RIP_FILTER_MAX
];
287 struct route_map
*routemap
[RIP_FILTER_MAX
];
289 /* Wake up thread. */
290 struct thread
*t_wakeup
;
292 /* Interface statistics. */
297 /* Passive interface. */
301 /* RIP peer information. */
306 /* Peer RIP tag value. */
309 /* Last update time. */
312 /* Peer RIP version. */
319 /* Timeout thread. */
320 struct thread
*t_timeout
;
323 struct rip_distance
{
324 /* Distance value for the IP source prefix. */
327 /* Name of the access-list to be matched. */
331 struct rip_md5_info
{
342 struct rip_md5_data
{
348 /* RIP accepet/announce methods. */
349 #define RI_RIP_UNSPEC 0
350 #define RI_RIP_VERSION_1 1
351 #define RI_RIP_VERSION_2 2
352 #define RI_RIP_VERSION_1_AND_2 3
353 #define RI_RIP_VERSION_NONE 4
354 /* N.B. stuff will break if
355 (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */
361 RIP_TRIGGERED_UPDATE
,
364 /* Macro for timer turn on. */
365 #define RIP_TIMER_ON(T,F,V) thread_add_timer (master, (F), rinfo, (V), &(T))
367 /* Macro for timer turn off. */
368 #define RIP_TIMER_OFF(X) THREAD_TIMER_OFF(X)
370 #define RIP_OFFSET_LIST_IN 0
371 #define RIP_OFFSET_LIST_OUT 1
372 #define RIP_OFFSET_LIST_MAX 2
374 struct rip_offset_list
{
379 /* struct access_list *alist; */
381 } direct
[RIP_OFFSET_LIST_MAX
];
385 extern void rip_init(void);
386 extern void rip_reset(void);
387 extern void rip_clean(void);
388 extern void rip_clean_network(void);
389 extern void rip_interfaces_clean(void);
390 extern void rip_interfaces_reset(void);
391 extern int rip_passive_nondefault_set(const char *ifname
);
392 extern int rip_passive_nondefault_unset(const char *ifname
);
393 extern void rip_passive_nondefault_clean(void);
394 extern void rip_if_init(void);
395 extern void rip_if_down_all(void);
396 extern void rip_route_map_init(void);
397 extern void rip_route_map_reset(void);
398 extern void rip_zclient_init(struct thread_master
*);
399 extern void rip_zclient_stop(void);
400 extern void rip_zclient_reset(void);
401 extern int if_check_address(struct in_addr addr
);
402 extern int rip_create(int socket
);
404 extern int rip_request_send(struct sockaddr_in
*, struct interface
*, uint8_t,
406 extern int rip_neighbor_lookup(struct sockaddr_in
*);
407 extern int rip_neighbor_add(struct prefix_ipv4
*p
);
408 extern int rip_neighbor_delete(struct prefix_ipv4
*p
);
410 extern int rip_enable_network_add(struct prefix
*p
);
411 extern int rip_enable_network_delete(struct prefix
*p
);
412 extern int rip_enable_if_add(const char *ifname
);
413 extern int rip_enable_if_delete(const char *ifname
);
415 extern void rip_ecmp_disable(void);
417 extern int rip_create_socket(void);
419 extern int rip_redistribute_check(int);
420 extern void rip_redistribute_conf_update(int type
);
421 extern void rip_redistribute_conf_delete(int type
);
422 extern void rip_redistribute_add(int type
, int sub_type
, struct prefix_ipv4
*p
,
423 struct nexthop
*nh
, unsigned int metric
,
424 unsigned char distance
, route_tag_t tag
);
425 extern void rip_redistribute_delete(int, int, struct prefix_ipv4
*, ifindex_t
);
426 extern void rip_redistribute_withdraw(int);
427 extern void rip_zebra_ipv4_add(struct route_node
*);
428 extern void rip_zebra_ipv4_delete(struct route_node
*);
429 extern void rip_interface_multicast_set(int, struct connected
*);
430 extern void rip_distribute_update_interface(struct interface
*);
431 extern void rip_if_rmap_update_interface(struct interface
*);
433 extern int rip_show_network_config(struct vty
*);
434 extern void rip_show_redistribute_config(struct vty
*);
436 extern void rip_peer_init(void);
437 extern void rip_peer_update(struct sockaddr_in
*, uint8_t);
438 extern void rip_peer_bad_route(struct sockaddr_in
*);
439 extern void rip_peer_bad_packet(struct sockaddr_in
*);
440 extern void rip_peer_display(struct vty
*);
441 extern struct rip_peer
*rip_peer_lookup(struct in_addr
*);
442 extern struct rip_peer
*rip_peer_lookup_next(struct in_addr
*);
444 extern void rip_info_free(struct rip_info
*);
445 extern struct rip_distance
*rip_distance_new(void);
446 extern void rip_distance_free(struct rip_distance
*rdistance
);
447 extern uint8_t rip_distance_apply(struct rip_info
*);
448 extern void rip_redistribute_clean(void);
450 extern struct rip_info
*rip_ecmp_add(struct rip_info
*);
451 extern struct rip_info
*rip_ecmp_replace(struct rip_info
*);
452 extern struct rip_info
*rip_ecmp_delete(struct rip_info
*);
454 extern struct rip_offset_list
*rip_offset_list_new(const char *ifname
);
455 extern void offset_list_del(struct rip_offset_list
*offset
);
456 extern struct rip_offset_list
*rip_offset_list_lookup(const char *ifname
);
457 extern int rip_offset_list_apply_in(struct prefix_ipv4
*, struct interface
*,
459 extern int rip_offset_list_apply_out(struct prefix_ipv4
*, struct interface
*,
461 extern void rip_offset_init(void);
462 extern void rip_offset_clean(void);
464 /* There is only one rip strucutre. */
465 extern struct rip
*rip
;
467 extern struct zebra_privs_t ripd_privs
;
469 /* Master thread strucutre. */
470 extern struct thread_master
*master
;
472 /* RIP statistics for SNMP. */
473 extern long rip_global_route_changes
;
474 extern long rip_global_queries
;
476 DECLARE_HOOK(rip_ifaddr_add
, (struct connected
* ifc
), (ifc
))
477 DECLARE_HOOK(rip_ifaddr_del
, (struct connected
* ifc
), (ifc
))
479 extern struct route_table
*rip_distance_table
;
480 extern vector Vrip_passive_nondefault
;
483 extern void rip_cli_init(void);
484 extern const struct frr_yang_module_info frr_ripd_info
;
486 #endif /* _ZEBRA_RIP_H */