paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * RIPng related value and structure. |
| 3 | * Copyright (C) 1998 Kunihiro Ishiguro |
| 4 | * |
| 5 | * This file is part of GNU Zebra. |
| 6 | * |
| 7 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2, or (at your option) any |
| 10 | * later version. |
| 11 | * |
| 12 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 20 | * 02111-1307, USA. |
| 21 | */ |
| 22 | |
| 23 | #ifndef _ZEBRA_RIPNG_RIPNGD_H |
| 24 | #define _ZEBRA_RIPNG_RIPNGD_H |
| 25 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 26 | #include <zclient.h> |
| 27 | #include <vty.h> |
| 28 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 29 | /* RIPng version and port number. */ |
| 30 | #define RIPNG_V1 1 |
| 31 | #define RIPNG_PORT_DEFAULT 521 |
| 32 | #define RIPNG_VTY_PORT 2603 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 33 | #define RIPNG_MAX_PACKET_SIZE 1500 |
| 34 | #define RIPNG_PRIORITY_DEFAULT 0 |
| 35 | |
| 36 | /* RIPng commands. */ |
| 37 | #define RIPNG_REQUEST 1 |
| 38 | #define RIPNG_RESPONSE 2 |
| 39 | |
| 40 | /* RIPng metric and multicast group address. */ |
| 41 | #define RIPNG_METRIC_INFINITY 16 |
| 42 | #define RIPNG_METRIC_NEXTHOP 0xff |
| 43 | #define RIPNG_GROUP "ff02::9" |
| 44 | |
| 45 | /* RIPng timers. */ |
| 46 | #define RIPNG_UPDATE_TIMER_DEFAULT 30 |
| 47 | #define RIPNG_TIMEOUT_TIMER_DEFAULT 180 |
| 48 | #define RIPNG_GARBAGE_TIMER_DEFAULT 120 |
| 49 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 50 | /* RIPng peer timeout value. */ |
| 51 | #define RIPNG_PEER_TIMER_DEFAULT 180 |
| 52 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 53 | /* Default config file name. */ |
| 54 | #define RIPNG_DEFAULT_CONFIG "ripngd.conf" |
| 55 | |
| 56 | /* RIPng route types. */ |
| 57 | #define RIPNG_ROUTE_RTE 0 |
| 58 | #define RIPNG_ROUTE_STATIC 1 |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 59 | #define RIPNG_ROUTE_DEFAULT 2 |
| 60 | #define RIPNG_ROUTE_REDISTRIBUTE 3 |
| 61 | #define RIPNG_ROUTE_INTERFACE 4 |
| 62 | #define RIPNG_ROUTE_AGGREGATE 5 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 63 | |
| 64 | /* Interface send/receive configuration. */ |
| 65 | #define RIPNG_SEND_UNSPEC 0 |
| 66 | #define RIPNG_SEND_OFF 1 |
| 67 | #define RIPNG_RECEIVE_UNSPEC 0 |
| 68 | #define RIPNG_RECEIVE_OFF 1 |
| 69 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 70 | /* RIP default route's accept/announce methods. */ |
| 71 | #define RIPNG_DEFAULT_ADVERTISE_UNSPEC 0 |
| 72 | #define RIPNG_DEFAULT_ADVERTISE_NONE 1 |
| 73 | #define RIPNG_DEFAULT_ADVERTISE 2 |
| 74 | |
| 75 | #define RIPNG_DEFAULT_ACCEPT_UNSPEC 0 |
| 76 | #define RIPNG_DEFAULT_ACCEPT_NONE 1 |
| 77 | #define RIPNG_DEFAULT_ACCEPT 2 |
| 78 | |
| 79 | /* Default value for "default-metric" command. */ |
| 80 | #define RIPNG_DEFAULT_METRIC_DEFAULT 1 |
| 81 | |
| 82 | /* For max RTE calculation. */ |
| 83 | #ifndef IPV6_HDRLEN |
| 84 | #define IPV6_HDRLEN 40 |
| 85 | #endif /* IPV6_HDRLEN */ |
| 86 | |
| 87 | #ifndef IFMINMTU |
| 88 | #define IFMINMTU 576 |
| 89 | #endif /* IFMINMTU */ |
| 90 | |
| 91 | /* RIPng structure. */ |
| 92 | struct ripng |
| 93 | { |
| 94 | /* RIPng socket. */ |
| 95 | int sock; |
| 96 | |
| 97 | /* RIPng Parameters.*/ |
| 98 | u_char command; |
| 99 | u_char version; |
| 100 | unsigned long update_time; |
| 101 | unsigned long timeout_time; |
| 102 | unsigned long garbage_time; |
| 103 | int max_mtu; |
| 104 | int default_metric; |
| 105 | int default_information; |
| 106 | |
| 107 | /* Input/output buffer of RIPng. */ |
| 108 | struct stream *ibuf; |
| 109 | struct stream *obuf; |
| 110 | |
| 111 | /* RIPng routing information base. */ |
| 112 | struct route_table *table; |
| 113 | |
| 114 | /* RIPng only static route information. */ |
| 115 | struct route_table *route; |
| 116 | |
| 117 | /* RIPng aggregate route information. */ |
| 118 | struct route_table *aggregate; |
| 119 | |
| 120 | /* RIPng threads. */ |
| 121 | struct thread *t_read; |
| 122 | struct thread *t_write; |
| 123 | struct thread *t_update; |
| 124 | struct thread *t_garbage; |
| 125 | struct thread *t_zebra; |
| 126 | |
| 127 | /* Triggered update hack. */ |
| 128 | int trigger; |
| 129 | struct thread *t_triggered_update; |
| 130 | struct thread *t_triggered_interval; |
| 131 | |
Feng Lu | 72855b1 | 2015-05-22 11:39:54 +0200 | [diff] [blame] | 132 | /* RIPng ECMP flag */ |
| 133 | unsigned int ecmp; |
| 134 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 135 | /* For redistribute route map. */ |
| 136 | struct |
| 137 | { |
| 138 | char *name; |
| 139 | struct route_map *map; |
| 140 | int metric_config; |
| 141 | u_int32_t metric; |
| 142 | } route_map[ZEBRA_ROUTE_MAX]; |
| 143 | }; |
| 144 | |
| 145 | /* Routing table entry. */ |
| 146 | struct rte |
| 147 | { |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 148 | struct in6_addr addr; /* RIPng destination prefix */ |
| 149 | u_short tag; /* RIPng tag */ |
| 150 | u_char prefixlen; /* Length of the RIPng prefix */ |
| 151 | u_char metric; /* Metric of the RIPng route */ |
| 152 | /* The nexthop is stored by the structure |
| 153 | * ripng_nexthop within ripngd.c */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | /* RIPNG send packet. */ |
| 157 | struct ripng_packet |
| 158 | { |
| 159 | u_char command; |
| 160 | u_char version; |
| 161 | u_int16_t zero; |
| 162 | struct rte rte[1]; |
| 163 | }; |
| 164 | |
| 165 | /* Each route's information. */ |
| 166 | struct ripng_info |
| 167 | { |
| 168 | /* This route's type. Static, ripng or aggregate. */ |
| 169 | u_char type; |
| 170 | |
| 171 | /* Sub type for static route. */ |
| 172 | u_char sub_type; |
| 173 | |
| 174 | /* RIPng specific information */ |
| 175 | struct in6_addr nexthop; |
| 176 | struct in6_addr from; |
| 177 | |
| 178 | /* Which interface does this route come from. */ |
| 179 | unsigned int ifindex; |
| 180 | |
| 181 | /* Metric of this route. */ |
| 182 | u_char metric; |
| 183 | |
| 184 | /* Tag field of RIPng packet.*/ |
| 185 | u_int16_t tag; |
| 186 | |
| 187 | /* For aggregation. */ |
| 188 | unsigned int suppress; |
| 189 | |
| 190 | /* Flags of RIPng route. */ |
| 191 | #define RIPNG_RTF_FIB 1 |
| 192 | #define RIPNG_RTF_CHANGED 2 |
| 193 | u_char flags; |
| 194 | |
| 195 | /* Garbage collect timer. */ |
| 196 | struct thread *t_timeout; |
| 197 | struct thread *t_garbage_collect; |
| 198 | |
| 199 | /* Route-map features - this variables can be changed. */ |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 200 | struct in6_addr nexthop_out; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 201 | u_char metric_set; |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 202 | u_char metric_out; |
| 203 | u_short tag_out; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 204 | |
| 205 | struct route_node *rp; |
| 206 | }; |
| 207 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 208 | #ifdef notyet |
| 209 | #if 0 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 210 | /* RIPng tag structure. */ |
| 211 | struct ripng_tag |
| 212 | { |
| 213 | /* Tag value. */ |
| 214 | u_int16_t tag; |
| 215 | |
| 216 | /* Port. */ |
| 217 | u_int16_t port; |
| 218 | |
| 219 | /* Multicast group. */ |
| 220 | struct in6_addr maddr; |
| 221 | |
| 222 | /* Table number. */ |
| 223 | int table; |
| 224 | |
| 225 | /* Distance. */ |
| 226 | int distance; |
| 227 | |
| 228 | /* Split horizon. */ |
| 229 | u_char split_horizon; |
| 230 | |
| 231 | /* Poison reverse. */ |
| 232 | u_char poison_reverse; |
| 233 | }; |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 234 | #endif /* 0 */ |
| 235 | #endif /* not yet */ |
| 236 | |
| 237 | typedef enum { |
| 238 | RIPNG_NO_SPLIT_HORIZON = 0, |
| 239 | RIPNG_SPLIT_HORIZON, |
| 240 | RIPNG_SPLIT_HORIZON_POISONED_REVERSE |
| 241 | } split_horizon_policy_t; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 242 | |
| 243 | /* RIPng specific interface configuration. */ |
| 244 | struct ripng_interface |
| 245 | { |
| 246 | /* RIPng is enabled on this interface. */ |
| 247 | int enable_network; |
| 248 | int enable_interface; |
| 249 | |
| 250 | /* RIPng is running on this interface. */ |
| 251 | int running; |
| 252 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 253 | /* Split horizon flag. */ |
| 254 | split_horizon_policy_t split_horizon; |
| 255 | split_horizon_policy_t split_horizon_default; |
| 256 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 257 | /* For filter type slot. */ |
| 258 | #define RIPNG_FILTER_IN 0 |
| 259 | #define RIPNG_FILTER_OUT 1 |
| 260 | #define RIPNG_FILTER_MAX 2 |
| 261 | |
| 262 | /* Access-list. */ |
| 263 | struct access_list *list[RIPNG_FILTER_MAX]; |
| 264 | |
| 265 | /* Prefix-list. */ |
| 266 | struct prefix_list *prefix[RIPNG_FILTER_MAX]; |
| 267 | |
| 268 | /* Route-map. */ |
| 269 | struct route_map *routemap[RIPNG_FILTER_MAX]; |
| 270 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 271 | #ifdef notyet |
| 272 | #if 0 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 273 | /* RIPng tag configuration. */ |
| 274 | struct ripng_tag *rtag; |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 275 | #endif /* 0 */ |
| 276 | #endif /* notyet */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 277 | |
| 278 | /* Default information originate. */ |
| 279 | u_char default_originate; |
| 280 | |
| 281 | /* Default information only. */ |
| 282 | u_char default_only; |
| 283 | |
| 284 | /* Wake up thread. */ |
| 285 | struct thread *t_wakeup; |
| 286 | |
| 287 | /* Passive interface. */ |
| 288 | int passive; |
| 289 | }; |
| 290 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 291 | /* RIPng peer information. */ |
| 292 | struct ripng_peer |
| 293 | { |
| 294 | /* Peer address. */ |
| 295 | struct in6_addr addr; |
| 296 | |
| 297 | /* Peer RIPng 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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 314 | /* All RIPng events. */ |
| 315 | enum ripng_event |
| 316 | { |
| 317 | RIPNG_READ, |
| 318 | RIPNG_ZEBRA, |
| 319 | RIPNG_REQUEST_EVENT, |
| 320 | RIPNG_UPDATE_EVENT, |
| 321 | RIPNG_TRIGGERED_UPDATE, |
| 322 | }; |
| 323 | |
| 324 | /* RIPng timer on/off macro. */ |
| 325 | #define RIPNG_TIMER_ON(T,F,V) \ |
| 326 | do { \ |
| 327 | if (!(T)) \ |
| 328 | (T) = thread_add_timer (master, (F), rinfo, (V)); \ |
| 329 | } while (0) |
| 330 | |
| 331 | #define RIPNG_TIMER_OFF(T) \ |
| 332 | do { \ |
| 333 | if (T) \ |
| 334 | { \ |
| 335 | thread_cancel(T); \ |
| 336 | (T) = NULL; \ |
| 337 | } \ |
| 338 | } while (0) |
| 339 | |
| 340 | /* Count prefix size from mask length */ |
| 341 | #define PSIZE(a) (((a) + 7) / (8)) |
| 342 | |
| 343 | /* Extern variables. */ |
| 344 | extern struct ripng *ripng; |
| 345 | |
| 346 | extern struct thread_master *master; |
| 347 | |
| 348 | /* Prototypes. */ |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 349 | extern void ripng_init (void); |
| 350 | extern void ripng_reset (void); |
| 351 | extern void ripng_clean (void); |
| 352 | extern void ripng_clean_network (void); |
| 353 | extern void ripng_interface_clean (void); |
| 354 | extern void ripng_interface_reset (void); |
| 355 | extern void ripng_passive_interface_clean (void); |
| 356 | extern void ripng_if_init (void); |
| 357 | extern void ripng_route_map_init (void); |
| 358 | extern void ripng_route_map_reset (void); |
| 359 | extern void ripng_terminate (void); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 360 | /* zclient_init() is done by ripng_zebra.c:zebra_init() */ |
Donald Sharp | 7125293 | 2015-09-24 09:25:19 -0400 | [diff] [blame] | 361 | extern void zebra_init (struct thread_master *); |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 362 | extern void ripng_zclient_start (void); |
| 363 | extern void ripng_zclient_reset (void); |
| 364 | extern void ripng_offset_init (void); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 365 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 366 | extern int config_write_ripng_offset_list (struct vty *); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 367 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 368 | extern void ripng_peer_init (void); |
| 369 | extern void ripng_peer_update (struct sockaddr_in6 *, u_char); |
| 370 | extern void ripng_peer_bad_route (struct sockaddr_in6 *); |
| 371 | extern void ripng_peer_bad_packet (struct sockaddr_in6 *); |
| 372 | extern void ripng_peer_display (struct vty *); |
| 373 | extern struct ripng_peer *ripng_peer_lookup (struct in6_addr *); |
| 374 | extern struct ripng_peer *ripng_peer_lookup_next (struct in6_addr *); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 375 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 376 | extern int ripng_offset_list_apply_in (struct prefix_ipv6 *, |
| 377 | struct interface *, u_char *); |
| 378 | extern int ripng_offset_list_apply_out (struct prefix_ipv6 *, |
| 379 | struct interface *, u_char *); |
| 380 | extern void ripng_offset_clean (void); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 381 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 382 | extern struct ripng_info * ripng_info_new (void); |
| 383 | extern void ripng_info_free (struct ripng_info *rinfo); |
| 384 | extern void ripng_event (enum ripng_event, int); |
| 385 | extern int ripng_request (struct interface *ifp); |
| 386 | extern void ripng_redistribute_add (int, int, struct prefix_ipv6 *, |
| 387 | unsigned int, struct in6_addr *); |
| 388 | extern void ripng_redistribute_delete (int, int, struct prefix_ipv6 *, |
| 389 | unsigned int); |
| 390 | extern void ripng_redistribute_withdraw (int type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 391 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 392 | extern void ripng_distribute_update_interface (struct interface *); |
| 393 | extern void ripng_if_rmap_update_interface (struct interface *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 394 | |
Feng Lu | e97c31a | 2015-05-22 11:39:53 +0200 | [diff] [blame] | 395 | extern void ripng_zebra_ipv6_add (struct route_node *); |
| 396 | extern void ripng_zebra_ipv6_delete (struct route_node *); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 397 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 398 | extern void ripng_redistribute_clean (void); |
| 399 | extern int ripng_redistribute_check (int); |
| 400 | extern void ripng_redistribute_write (struct vty *, int); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 401 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 402 | extern int ripng_write_rte (int num, struct stream *s, struct prefix_ipv6 *p, |
| 403 | struct in6_addr *nexthop, |
| 404 | u_int16_t tag, u_char metric); |
| 405 | extern int ripng_send_packet (caddr_t buf, int bufsize, |
| 406 | struct sockaddr_in6 *to, struct interface *ifp); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 407 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 408 | extern void ripng_packet_dump (struct ripng_packet *packet, int size, |
| 409 | const char *sndrcv); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 410 | |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 411 | extern int ripng_interface_up (int command, struct zclient *, zebra_size_t, |
| 412 | vrf_id_t); |
| 413 | extern int ripng_interface_down (int command, struct zclient *, zebra_size_t, |
| 414 | vrf_id_t); |
| 415 | extern int ripng_interface_add (int command, struct zclient *, zebra_size_t, |
| 416 | vrf_id_t); |
| 417 | extern int ripng_interface_delete (int command, struct zclient *, zebra_size_t, |
| 418 | vrf_id_t); |
| 419 | extern int ripng_interface_address_add (int command, struct zclient *, zebra_size_t, |
| 420 | vrf_id_t); |
| 421 | extern int ripng_interface_address_delete (int command, struct zclient *, zebra_size_t, |
| 422 | vrf_id_t); |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 423 | |
| 424 | extern int ripng_network_write (struct vty *, int); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 425 | |
Feng Lu | e97c31a | 2015-05-22 11:39:53 +0200 | [diff] [blame] | 426 | extern struct ripng_info *ripng_ecmp_add (struct ripng_info *); |
| 427 | extern struct ripng_info *ripng_ecmp_replace (struct ripng_info *); |
| 428 | extern struct ripng_info *ripng_ecmp_delete (struct ripng_info *); |
| 429 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 430 | #endif /* _ZEBRA_RIPNG_RIPNGD_H */ |