paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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 |
| 17 | * along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 18 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 19 | * 02111-1307, USA. |
| 20 | */ |
| 21 | |
| 22 | #ifndef _ZEBRA_RIP_H |
| 23 | #define _ZEBRA_RIP_H |
| 24 | |
| 25 | /* RIP version number. */ |
| 26 | #define RIPv1 1 |
| 27 | #define RIPv2 2 |
paul | f38a471 | 2003-06-07 01:10:00 +0000 | [diff] [blame] | 28 | /* N.B. stuff will break if |
| 29 | (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */ |
| 30 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 31 | |
| 32 | /* RIP command list. */ |
| 33 | #define RIP_REQUEST 1 |
| 34 | #define RIP_RESPONSE 2 |
| 35 | #define RIP_TRACEON 3 /* Obsolete */ |
| 36 | #define RIP_TRACEOFF 4 /* Obsolete */ |
| 37 | #define RIP_POLL 5 |
| 38 | #define RIP_POLL_ENTRY 6 |
| 39 | #define RIP_COMMAND_MAX 7 |
| 40 | |
| 41 | /* RIP metric infinity value.*/ |
| 42 | #define RIP_METRIC_INFINITY 16 |
| 43 | |
| 44 | /* Normal RIP packet min and max size. */ |
| 45 | #define RIP_PACKET_MINSIZ 4 |
| 46 | #define RIP_PACKET_MAXSIZ 512 |
| 47 | |
| 48 | #define RIP_HEADER_SIZE 4 |
| 49 | #define RIP_RTE_SIZE 20 |
| 50 | |
| 51 | /* Max count of routing table entry in one rip packet. */ |
| 52 | #define RIP_MAX_RTE 25 |
| 53 | |
| 54 | /* RIP version 2 multicast address. */ |
| 55 | #ifndef INADDR_RIP_GROUP |
| 56 | #define INADDR_RIP_GROUP 0xe0000009 /* 224.0.0.9 */ |
| 57 | #endif |
| 58 | |
| 59 | /* RIP timers */ |
| 60 | #define RIP_UPDATE_TIMER_DEFAULT 30 |
| 61 | #define RIP_TIMEOUT_TIMER_DEFAULT 180 |
| 62 | #define RIP_GARBAGE_TIMER_DEFAULT 120 |
| 63 | |
| 64 | /* RIP peer timeout value. */ |
| 65 | #define RIP_PEER_TIMER_DEFAULT 180 |
| 66 | |
| 67 | /* RIP port number. */ |
| 68 | #define RIP_PORT_DEFAULT 520 |
| 69 | #define RIP_VTY_PORT 2602 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 70 | |
| 71 | /* Default configuration file name. */ |
| 72 | #define RIPD_DEFAULT_CONFIG "ripd.conf" |
| 73 | |
| 74 | /* RIP route types. */ |
| 75 | #define RIP_ROUTE_RTE 0 |
| 76 | #define RIP_ROUTE_STATIC 1 |
| 77 | #define RIP_ROUTE_DEFAULT 2 |
| 78 | #define RIP_ROUTE_REDISTRIBUTE 3 |
| 79 | #define RIP_ROUTE_INTERFACE 4 |
| 80 | |
paul | ca5e516 | 2004-06-06 22:06:33 +0000 | [diff] [blame] | 81 | /* RIPv2 special RTE family types */ |
| 82 | #define RIP_FAMILY_AUTH 0xffff |
| 83 | |
| 84 | /* RIPv2 authentication types, for RIP_FAMILY_AUTH RTE's */ |
| 85 | #define RIP_NO_AUTH 0 |
| 86 | #define RIP_AUTH_DATA 1 |
| 87 | #define RIP_AUTH_SIMPLE_PASSWORD 2 |
| 88 | #define RIP_AUTH_MD5 3 |
| 89 | |
| 90 | /* RIPv2 MD5 authentication. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 91 | #define RIP_AUTH_MD5_SIZE 16 |
paul | ca5e516 | 2004-06-06 22:06:33 +0000 | [diff] [blame] | 92 | #define RIP_AUTH_MD5_COMPAT_SIZE RIP_RTE_SIZE |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 93 | |
| 94 | /* RIP structure. */ |
| 95 | struct rip |
| 96 | { |
| 97 | /* RIP socket. */ |
| 98 | int sock; |
| 99 | |
| 100 | /* Default version of rip instance. */ |
paul | f38a471 | 2003-06-07 01:10:00 +0000 | [diff] [blame] | 101 | int version_send; /* version 1 or 2 (but not both) */ |
| 102 | int version_recv; /* version 1 or 2 or both */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 103 | |
| 104 | /* Output buffer of RIP. */ |
| 105 | struct stream *obuf; |
| 106 | |
| 107 | /* RIP routing information base. */ |
| 108 | struct route_table *table; |
| 109 | |
| 110 | /* RIP only static routing information. */ |
| 111 | struct route_table *route; |
| 112 | |
| 113 | /* RIP neighbor. */ |
| 114 | struct route_table *neighbor; |
| 115 | |
| 116 | /* RIP threads. */ |
| 117 | struct thread *t_read; |
| 118 | |
| 119 | /* Update and garbage timer. */ |
| 120 | struct thread *t_update; |
| 121 | |
| 122 | /* Triggered update hack. */ |
| 123 | int trigger; |
| 124 | struct thread *t_triggered_update; |
| 125 | struct thread *t_triggered_interval; |
| 126 | |
| 127 | /* RIP timer values. */ |
| 128 | unsigned long update_time; |
| 129 | unsigned long timeout_time; |
| 130 | unsigned long garbage_time; |
| 131 | |
| 132 | /* RIP default metric. */ |
| 133 | int default_metric; |
| 134 | |
| 135 | /* RIP default-information originate. */ |
| 136 | u_char default_information; |
| 137 | char *default_information_route_map; |
| 138 | |
| 139 | /* RIP default distance. */ |
| 140 | u_char distance; |
| 141 | struct route_table *distance_table; |
| 142 | |
| 143 | /* For redistribute route map. */ |
| 144 | struct |
| 145 | { |
| 146 | char *name; |
| 147 | struct route_map *map; |
| 148 | int metric_config; |
| 149 | u_int32_t metric; |
| 150 | } route_map[ZEBRA_ROUTE_MAX]; |
| 151 | }; |
| 152 | |
| 153 | /* RIP routing table entry which belong to rip_packet. */ |
| 154 | struct rte |
| 155 | { |
| 156 | u_int16_t family; /* Address family of this route. */ |
| 157 | u_int16_t tag; /* Route Tag which included in RIP2 packet. */ |
| 158 | struct in_addr prefix; /* Prefix of rip route. */ |
| 159 | struct in_addr mask; /* Netmask of rip route. */ |
| 160 | struct in_addr nexthop; /* Next hop of rip route. */ |
| 161 | u_int32_t metric; /* Metric value of rip route. */ |
| 162 | }; |
| 163 | |
| 164 | /* RIP packet structure. */ |
| 165 | struct rip_packet |
| 166 | { |
| 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 | { |
| 177 | struct rip_packet rip_packet; |
| 178 | char buf[RIP_PACKET_MAXSIZ]; |
| 179 | }; |
| 180 | |
| 181 | /* RIP route information. */ |
| 182 | struct rip_info |
| 183 | { |
| 184 | /* This route's type. */ |
| 185 | int type; |
| 186 | |
| 187 | /* Sub type. */ |
| 188 | int sub_type; |
| 189 | |
| 190 | /* RIP nexthop. */ |
| 191 | struct in_addr nexthop; |
| 192 | struct in_addr from; |
| 193 | |
| 194 | /* Which interface does this route come from. */ |
| 195 | unsigned int ifindex; |
| 196 | |
| 197 | /* Metric of this route. */ |
| 198 | u_int32_t metric; |
| 199 | |
| 200 | /* Tag information of this route. */ |
| 201 | u_int16_t tag; |
| 202 | |
| 203 | /* Flags of RIP route. */ |
| 204 | #define RIP_RTF_FIB 1 |
| 205 | #define RIP_RTF_CHANGED 2 |
| 206 | u_char flags; |
| 207 | |
| 208 | /* Garbage collect timer. */ |
| 209 | struct thread *t_timeout; |
| 210 | struct thread *t_garbage_collect; |
| 211 | |
| 212 | /* Route-map futures - this variables can be changed. */ |
| 213 | struct in_addr nexthop_out; |
| 214 | u_char metric_set; |
| 215 | u_int32_t metric_out; |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 216 | u_short tag_out; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 217 | unsigned int ifindex_out; |
| 218 | |
| 219 | struct route_node *rp; |
| 220 | |
| 221 | u_char distance; |
| 222 | |
| 223 | #ifdef NEW_RIP_TABLE |
| 224 | struct rip_info *next; |
| 225 | struct rip_info *prev; |
| 226 | #endif /* NEW_RIP_TABLE */ |
| 227 | }; |
| 228 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 229 | typedef enum { |
| 230 | RIP_NO_SPLIT_HORIZON = 0, |
| 231 | RIP_SPLIT_HORIZON, |
| 232 | RIP_SPLIT_HORIZON_POISONED_REVERSE |
| 233 | } split_horizon_policy_t; |
| 234 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 235 | /* RIP specific interface configuration. */ |
| 236 | struct rip_interface |
| 237 | { |
| 238 | /* RIP is enabled on this interface. */ |
| 239 | int enable_network; |
| 240 | int enable_interface; |
| 241 | |
| 242 | /* RIP is running on this interface. */ |
| 243 | int running; |
| 244 | |
| 245 | /* RIP version control. */ |
| 246 | int ri_send; |
| 247 | int ri_receive; |
| 248 | |
| 249 | /* RIPv2 authentication type. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 250 | int auth_type; |
| 251 | |
| 252 | /* RIPv2 authentication string. */ |
| 253 | char *auth_str; |
| 254 | |
| 255 | /* RIPv2 authentication key chain. */ |
| 256 | char *key_chain; |
| 257 | |
paul | ca5e516 | 2004-06-06 22:06:33 +0000 | [diff] [blame] | 258 | /* value to use for md5->auth_len */ |
| 259 | u_int8_t md5_auth_len; |
| 260 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 261 | /* Split horizon flag. */ |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 262 | split_horizon_policy_t split_horizon; |
| 263 | split_horizon_policy_t split_horizon_default; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 264 | |
| 265 | /* For filter type slot. */ |
| 266 | #define RIP_FILTER_IN 0 |
| 267 | #define RIP_FILTER_OUT 1 |
| 268 | #define RIP_FILTER_MAX 2 |
| 269 | |
| 270 | /* Access-list. */ |
| 271 | struct access_list *list[RIP_FILTER_MAX]; |
| 272 | |
| 273 | /* Prefix-list. */ |
| 274 | struct prefix_list *prefix[RIP_FILTER_MAX]; |
| 275 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 276 | /* Route-map. */ |
| 277 | struct route_map *routemap[RIP_FILTER_MAX]; |
| 278 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 279 | /* Wake up thread. */ |
| 280 | struct thread *t_wakeup; |
| 281 | |
| 282 | /* Interface statistics. */ |
| 283 | int recv_badpackets; |
| 284 | int recv_badroutes; |
| 285 | int sent_updates; |
| 286 | |
| 287 | /* Passive interface. */ |
| 288 | int passive; |
| 289 | }; |
| 290 | |
| 291 | /* RIP peer information. */ |
| 292 | struct rip_peer |
| 293 | { |
| 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 | u_char 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_md5_info |
| 315 | { |
| 316 | u_int16_t family; |
| 317 | u_int16_t type; |
| 318 | u_int16_t packet_len; |
| 319 | u_char keyid; |
| 320 | u_char auth_len; |
| 321 | u_int32_t sequence; |
| 322 | u_int32_t reserv1; |
| 323 | u_int32_t reserv2; |
| 324 | }; |
| 325 | |
| 326 | struct rip_md5_data |
| 327 | { |
| 328 | u_int16_t family; |
| 329 | u_int16_t type; |
| 330 | u_char digest[16]; |
| 331 | }; |
| 332 | |
| 333 | /* RIP accepet/announce methods. */ |
| 334 | #define RI_RIP_UNSPEC 0 |
| 335 | #define RI_RIP_VERSION_1 1 |
| 336 | #define RI_RIP_VERSION_2 2 |
| 337 | #define RI_RIP_VERSION_1_AND_2 3 |
paul | f38a471 | 2003-06-07 01:10:00 +0000 | [diff] [blame] | 338 | /* N.B. stuff will break if |
| 339 | (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 340 | |
| 341 | /* Default value for "default-metric" command. */ |
| 342 | #define RIP_DEFAULT_METRIC_DEFAULT 1 |
| 343 | |
| 344 | /* RIP event. */ |
| 345 | enum rip_event |
| 346 | { |
| 347 | RIP_READ, |
| 348 | RIP_UPDATE_EVENT, |
| 349 | RIP_TRIGGERED_UPDATE, |
| 350 | }; |
| 351 | |
| 352 | /* Macro for timer turn on. */ |
| 353 | #define RIP_TIMER_ON(T,F,V) \ |
| 354 | do { \ |
| 355 | if (!(T)) \ |
| 356 | (T) = thread_add_timer (master, (F), rinfo, (V)); \ |
| 357 | } while (0) |
| 358 | |
| 359 | /* Macro for timer turn off. */ |
| 360 | #define RIP_TIMER_OFF(X) \ |
| 361 | do { \ |
| 362 | if (X) \ |
| 363 | { \ |
| 364 | thread_cancel (X); \ |
| 365 | (X) = NULL; \ |
| 366 | } \ |
| 367 | } while (0) |
| 368 | |
| 369 | /* Prototypes. */ |
| 370 | void rip_init (); |
| 371 | void rip_reset (); |
| 372 | void rip_clean (); |
| 373 | void rip_clean_network (); |
| 374 | void rip_interface_clean (); |
| 375 | void rip_interface_reset (); |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 376 | void rip_passive_nondefault_clean (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 377 | void rip_if_init (); |
| 378 | void rip_if_down_all (); |
| 379 | void rip_route_map_init (); |
| 380 | void rip_route_map_reset (); |
| 381 | void rip_snmp_init (); |
| 382 | void rip_zclient_init (); |
| 383 | void rip_zclient_start (); |
| 384 | void rip_zclient_reset (); |
| 385 | void rip_offset_init (); |
paul | 31a476c | 2003-09-29 19:54:53 +0000 | [diff] [blame] | 386 | int if_check_address (struct in_addr addr); |
| 387 | int if_valid_neighbor (struct in_addr addr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 388 | |
paul | 931cd54 | 2004-01-23 15:31:42 +0000 | [diff] [blame] | 389 | int rip_request_send (struct sockaddr_in *, struct interface *, u_char, |
| 390 | struct connected *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 391 | int rip_neighbor_lookup (struct sockaddr_in *); |
| 392 | void rip_redistribute_add (int, int, struct prefix_ipv4 *, unsigned int, |
| 393 | struct in_addr *); |
| 394 | void rip_redistribute_delete (int, int, struct prefix_ipv4 *, unsigned int); |
| 395 | void rip_redistribute_withdraw (int); |
| 396 | void rip_zebra_ipv4_add (struct prefix_ipv4 *, struct in_addr *, u_int32_t, u_char); |
| 397 | void rip_zebra_ipv4_delete (struct prefix_ipv4 *, struct in_addr *, u_int32_t); |
paul | 1a51786 | 2004-08-19 04:03:08 +0000 | [diff] [blame] | 398 | void rip_interface_multicast_set (int, struct connected *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 399 | void rip_distribute_update_interface (struct interface *); |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 400 | void rip_if_rmap_update_interface (struct interface *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 401 | |
| 402 | int config_write_rip_network (struct vty *, int); |
| 403 | int config_write_rip_offset_list (struct vty *); |
| 404 | int config_write_rip_redistribute (struct vty *, int); |
| 405 | |
| 406 | void rip_peer_init (); |
| 407 | void rip_peer_update (struct sockaddr_in *, u_char); |
| 408 | void rip_peer_bad_route (struct sockaddr_in *); |
| 409 | void rip_peer_bad_packet (struct sockaddr_in *); |
| 410 | void rip_peer_display (struct vty *); |
| 411 | struct rip_peer *rip_peer_lookup (struct in_addr *); |
| 412 | struct rip_peer *rip_peer_lookup_next (struct in_addr *); |
| 413 | |
| 414 | int rip_offset_list_apply_in (struct prefix_ipv4 *, struct interface *, u_int32_t *); |
| 415 | int rip_offset_list_apply_out (struct prefix_ipv4 *, struct interface *, u_int32_t *); |
| 416 | void rip_offset_clean (); |
| 417 | |
| 418 | void rip_info_free (struct rip_info *); |
| 419 | u_char rip_distance_apply (struct rip_info *); |
| 420 | void rip_redistribute_clean (); |
| 421 | void rip_ifaddr_add (struct interface *, struct connected *); |
| 422 | void rip_ifaddr_delete (struct interface *, struct connected *); |
| 423 | |
| 424 | /* There is only one rip strucutre. */ |
| 425 | extern struct rip *rip; |
| 426 | |
| 427 | /* Master thread strucutre. */ |
| 428 | extern struct thread_master *master; |
| 429 | |
| 430 | /* RIP statistics for SNMP. */ |
| 431 | extern long rip_global_route_changes; |
| 432 | extern long rip_global_queries; |
| 433 | |
| 434 | #endif /* _ZEBRA_RIP_H */ |