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 | |
| 81 | /* RIP MD5 authentication. */ |
| 82 | #define RIP_AUTH_MD5_SIZE 16 |
| 83 | |
| 84 | /* RIP structure. */ |
| 85 | struct rip |
| 86 | { |
| 87 | /* RIP socket. */ |
| 88 | int sock; |
| 89 | |
| 90 | /* Default version of rip instance. */ |
paul | f38a471 | 2003-06-07 01:10:00 +0000 | [diff] [blame] | 91 | int version_send; /* version 1 or 2 (but not both) */ |
| 92 | int version_recv; /* version 1 or 2 or both */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 93 | |
| 94 | /* Output buffer of RIP. */ |
| 95 | struct stream *obuf; |
| 96 | |
| 97 | /* RIP routing information base. */ |
| 98 | struct route_table *table; |
| 99 | |
| 100 | /* RIP only static routing information. */ |
| 101 | struct route_table *route; |
| 102 | |
| 103 | /* RIP neighbor. */ |
| 104 | struct route_table *neighbor; |
| 105 | |
| 106 | /* RIP threads. */ |
| 107 | struct thread *t_read; |
| 108 | |
| 109 | /* Update and garbage timer. */ |
| 110 | struct thread *t_update; |
| 111 | |
| 112 | /* Triggered update hack. */ |
| 113 | int trigger; |
| 114 | struct thread *t_triggered_update; |
| 115 | struct thread *t_triggered_interval; |
| 116 | |
| 117 | /* RIP timer values. */ |
| 118 | unsigned long update_time; |
| 119 | unsigned long timeout_time; |
| 120 | unsigned long garbage_time; |
| 121 | |
| 122 | /* RIP default metric. */ |
| 123 | int default_metric; |
| 124 | |
| 125 | /* RIP default-information originate. */ |
| 126 | u_char default_information; |
| 127 | char *default_information_route_map; |
| 128 | |
| 129 | /* RIP default distance. */ |
| 130 | u_char distance; |
| 131 | struct route_table *distance_table; |
| 132 | |
| 133 | /* For redistribute route map. */ |
| 134 | struct |
| 135 | { |
| 136 | char *name; |
| 137 | struct route_map *map; |
| 138 | int metric_config; |
| 139 | u_int32_t metric; |
| 140 | } route_map[ZEBRA_ROUTE_MAX]; |
| 141 | }; |
| 142 | |
| 143 | /* RIP routing table entry which belong to rip_packet. */ |
| 144 | struct rte |
| 145 | { |
| 146 | u_int16_t family; /* Address family of this route. */ |
| 147 | u_int16_t tag; /* Route Tag which included in RIP2 packet. */ |
| 148 | struct in_addr prefix; /* Prefix of rip route. */ |
| 149 | struct in_addr mask; /* Netmask of rip route. */ |
| 150 | struct in_addr nexthop; /* Next hop of rip route. */ |
| 151 | u_int32_t metric; /* Metric value of rip route. */ |
| 152 | }; |
| 153 | |
| 154 | /* RIP packet structure. */ |
| 155 | struct rip_packet |
| 156 | { |
| 157 | unsigned char command; /* Command type of RIP packet. */ |
| 158 | unsigned char version; /* RIP version which coming from peer. */ |
| 159 | unsigned char pad1; /* Padding of RIP packet header. */ |
| 160 | unsigned char pad2; /* Same as above. */ |
| 161 | struct rte rte[1]; /* Address structure. */ |
| 162 | }; |
| 163 | |
| 164 | /* Buffer to read RIP packet. */ |
| 165 | union rip_buf |
| 166 | { |
| 167 | struct rip_packet rip_packet; |
| 168 | char buf[RIP_PACKET_MAXSIZ]; |
| 169 | }; |
| 170 | |
| 171 | /* RIP route information. */ |
| 172 | struct rip_info |
| 173 | { |
| 174 | /* This route's type. */ |
| 175 | int type; |
| 176 | |
| 177 | /* Sub type. */ |
| 178 | int sub_type; |
| 179 | |
| 180 | /* RIP nexthop. */ |
| 181 | struct in_addr nexthop; |
| 182 | struct in_addr from; |
| 183 | |
| 184 | /* Which interface does this route come from. */ |
| 185 | unsigned int ifindex; |
| 186 | |
| 187 | /* Metric of this route. */ |
| 188 | u_int32_t metric; |
| 189 | |
| 190 | /* Tag information of this route. */ |
| 191 | u_int16_t tag; |
| 192 | |
| 193 | /* Flags of RIP route. */ |
| 194 | #define RIP_RTF_FIB 1 |
| 195 | #define RIP_RTF_CHANGED 2 |
| 196 | u_char flags; |
| 197 | |
| 198 | /* Garbage collect timer. */ |
| 199 | struct thread *t_timeout; |
| 200 | struct thread *t_garbage_collect; |
| 201 | |
| 202 | /* Route-map futures - this variables can be changed. */ |
| 203 | struct in_addr nexthop_out; |
| 204 | u_char metric_set; |
| 205 | u_int32_t metric_out; |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 206 | u_short tag_out; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 207 | unsigned int ifindex_out; |
| 208 | |
| 209 | struct route_node *rp; |
| 210 | |
| 211 | u_char distance; |
| 212 | |
| 213 | #ifdef NEW_RIP_TABLE |
| 214 | struct rip_info *next; |
| 215 | struct rip_info *prev; |
| 216 | #endif /* NEW_RIP_TABLE */ |
| 217 | }; |
| 218 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 219 | typedef enum { |
| 220 | RIP_NO_SPLIT_HORIZON = 0, |
| 221 | RIP_SPLIT_HORIZON, |
| 222 | RIP_SPLIT_HORIZON_POISONED_REVERSE |
| 223 | } split_horizon_policy_t; |
| 224 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 225 | /* RIP specific interface configuration. */ |
| 226 | struct rip_interface |
| 227 | { |
| 228 | /* RIP is enabled on this interface. */ |
| 229 | int enable_network; |
| 230 | int enable_interface; |
| 231 | |
| 232 | /* RIP is running on this interface. */ |
| 233 | int running; |
| 234 | |
| 235 | /* RIP version control. */ |
| 236 | int ri_send; |
| 237 | int ri_receive; |
| 238 | |
| 239 | /* RIPv2 authentication type. */ |
| 240 | #define RIP_NO_AUTH 0 |
| 241 | #define RIP_AUTH_DATA 1 |
| 242 | #define RIP_AUTH_SIMPLE_PASSWORD 2 |
| 243 | #define RIP_AUTH_MD5 3 |
| 244 | int auth_type; |
| 245 | |
| 246 | /* RIPv2 authentication string. */ |
| 247 | char *auth_str; |
| 248 | |
| 249 | /* RIPv2 authentication key chain. */ |
| 250 | char *key_chain; |
| 251 | |
| 252 | /* Split horizon flag. */ |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 253 | split_horizon_policy_t split_horizon; |
| 254 | split_horizon_policy_t split_horizon_default; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 255 | |
| 256 | /* For filter type slot. */ |
| 257 | #define RIP_FILTER_IN 0 |
| 258 | #define RIP_FILTER_OUT 1 |
| 259 | #define RIP_FILTER_MAX 2 |
| 260 | |
| 261 | /* Access-list. */ |
| 262 | struct access_list *list[RIP_FILTER_MAX]; |
| 263 | |
| 264 | /* Prefix-list. */ |
| 265 | struct prefix_list *prefix[RIP_FILTER_MAX]; |
| 266 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 267 | /* Route-map. */ |
| 268 | struct route_map *routemap[RIP_FILTER_MAX]; |
| 269 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 270 | /* Wake up thread. */ |
| 271 | struct thread *t_wakeup; |
| 272 | |
| 273 | /* Interface statistics. */ |
| 274 | int recv_badpackets; |
| 275 | int recv_badroutes; |
| 276 | int sent_updates; |
| 277 | |
| 278 | /* Passive interface. */ |
| 279 | int passive; |
| 280 | }; |
| 281 | |
| 282 | /* RIP peer information. */ |
| 283 | struct rip_peer |
| 284 | { |
| 285 | /* Peer address. */ |
| 286 | struct in_addr addr; |
| 287 | |
| 288 | /* Peer RIP tag value. */ |
| 289 | int domain; |
| 290 | |
| 291 | /* Last update time. */ |
| 292 | time_t uptime; |
| 293 | |
| 294 | /* Peer RIP version. */ |
| 295 | u_char version; |
| 296 | |
| 297 | /* Statistics. */ |
| 298 | int recv_badpackets; |
| 299 | int recv_badroutes; |
| 300 | |
| 301 | /* Timeout thread. */ |
| 302 | struct thread *t_timeout; |
| 303 | }; |
| 304 | |
| 305 | struct rip_md5_info |
| 306 | { |
| 307 | u_int16_t family; |
| 308 | u_int16_t type; |
| 309 | u_int16_t packet_len; |
| 310 | u_char keyid; |
| 311 | u_char auth_len; |
| 312 | u_int32_t sequence; |
| 313 | u_int32_t reserv1; |
| 314 | u_int32_t reserv2; |
| 315 | }; |
| 316 | |
| 317 | struct rip_md5_data |
| 318 | { |
| 319 | u_int16_t family; |
| 320 | u_int16_t type; |
| 321 | u_char digest[16]; |
| 322 | }; |
| 323 | |
| 324 | /* RIP accepet/announce methods. */ |
| 325 | #define RI_RIP_UNSPEC 0 |
| 326 | #define RI_RIP_VERSION_1 1 |
| 327 | #define RI_RIP_VERSION_2 2 |
| 328 | #define RI_RIP_VERSION_1_AND_2 3 |
paul | f38a471 | 2003-06-07 01:10:00 +0000 | [diff] [blame] | 329 | /* N.B. stuff will break if |
| 330 | (RIPv1 != RI_RIP_VERSION_1) || (RIPv2 != RI_RIP_VERSION_2) */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 331 | |
| 332 | /* Default value for "default-metric" command. */ |
| 333 | #define RIP_DEFAULT_METRIC_DEFAULT 1 |
| 334 | |
| 335 | /* RIP event. */ |
| 336 | enum rip_event |
| 337 | { |
| 338 | RIP_READ, |
| 339 | RIP_UPDATE_EVENT, |
| 340 | RIP_TRIGGERED_UPDATE, |
| 341 | }; |
| 342 | |
| 343 | /* Macro for timer turn on. */ |
| 344 | #define RIP_TIMER_ON(T,F,V) \ |
| 345 | do { \ |
| 346 | if (!(T)) \ |
| 347 | (T) = thread_add_timer (master, (F), rinfo, (V)); \ |
| 348 | } while (0) |
| 349 | |
| 350 | /* Macro for timer turn off. */ |
| 351 | #define RIP_TIMER_OFF(X) \ |
| 352 | do { \ |
| 353 | if (X) \ |
| 354 | { \ |
| 355 | thread_cancel (X); \ |
| 356 | (X) = NULL; \ |
| 357 | } \ |
| 358 | } while (0) |
| 359 | |
| 360 | /* Prototypes. */ |
| 361 | void rip_init (); |
| 362 | void rip_reset (); |
| 363 | void rip_clean (); |
| 364 | void rip_clean_network (); |
| 365 | void rip_interface_clean (); |
| 366 | void rip_interface_reset (); |
paul | 4aaff3f | 2003-06-07 01:04:45 +0000 | [diff] [blame] | 367 | void rip_passive_nondefault_clean (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 368 | void rip_if_init (); |
| 369 | void rip_if_down_all (); |
| 370 | void rip_route_map_init (); |
| 371 | void rip_route_map_reset (); |
| 372 | void rip_snmp_init (); |
| 373 | void rip_zclient_init (); |
| 374 | void rip_zclient_start (); |
| 375 | void rip_zclient_reset (); |
| 376 | void rip_offset_init (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 377 | |
| 378 | int rip_request_send (struct sockaddr_in *, struct interface *, u_char); |
| 379 | int rip_neighbor_lookup (struct sockaddr_in *); |
| 380 | void rip_redistribute_add (int, int, struct prefix_ipv4 *, unsigned int, |
| 381 | struct in_addr *); |
| 382 | void rip_redistribute_delete (int, int, struct prefix_ipv4 *, unsigned int); |
| 383 | void rip_redistribute_withdraw (int); |
| 384 | void rip_zebra_ipv4_add (struct prefix_ipv4 *, struct in_addr *, u_int32_t, u_char); |
| 385 | void rip_zebra_ipv4_delete (struct prefix_ipv4 *, struct in_addr *, u_int32_t); |
| 386 | void rip_interface_multicast_set (int, struct interface *); |
| 387 | void rip_distribute_update_interface (struct interface *); |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 388 | void rip_if_rmap_update_interface (struct interface *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 389 | |
| 390 | int config_write_rip_network (struct vty *, int); |
| 391 | int config_write_rip_offset_list (struct vty *); |
| 392 | int config_write_rip_redistribute (struct vty *, int); |
| 393 | |
| 394 | void rip_peer_init (); |
| 395 | void rip_peer_update (struct sockaddr_in *, u_char); |
| 396 | void rip_peer_bad_route (struct sockaddr_in *); |
| 397 | void rip_peer_bad_packet (struct sockaddr_in *); |
| 398 | void rip_peer_display (struct vty *); |
| 399 | struct rip_peer *rip_peer_lookup (struct in_addr *); |
| 400 | struct rip_peer *rip_peer_lookup_next (struct in_addr *); |
| 401 | |
| 402 | int rip_offset_list_apply_in (struct prefix_ipv4 *, struct interface *, u_int32_t *); |
| 403 | int rip_offset_list_apply_out (struct prefix_ipv4 *, struct interface *, u_int32_t *); |
| 404 | void rip_offset_clean (); |
| 405 | |
| 406 | void rip_info_free (struct rip_info *); |
| 407 | u_char rip_distance_apply (struct rip_info *); |
| 408 | void rip_redistribute_clean (); |
| 409 | void rip_ifaddr_add (struct interface *, struct connected *); |
| 410 | void rip_ifaddr_delete (struct interface *, struct connected *); |
| 411 | |
| 412 | /* There is only one rip strucutre. */ |
| 413 | extern struct rip *rip; |
| 414 | |
| 415 | /* Master thread strucutre. */ |
| 416 | extern struct thread_master *master; |
| 417 | |
| 418 | /* RIP statistics for SNMP. */ |
| 419 | extern long rip_global_route_changes; |
| 420 | extern long rip_global_queries; |
| 421 | |
| 422 | #endif /* _ZEBRA_RIP_H */ |