paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * RIPngd and zebra interface. |
| 3 | * Copyright (C) 1998, 1999 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 | #include <zebra.h> |
| 24 | |
| 25 | #include "command.h" |
| 26 | #include "prefix.h" |
| 27 | #include "stream.h" |
| 28 | #include "routemap.h" |
| 29 | #include "zclient.h" |
| 30 | #include "log.h" |
| 31 | |
| 32 | #include "ripngd/ripngd.h" |
| 33 | |
| 34 | /* All information about zebra. */ |
| 35 | struct zclient *zclient = NULL; |
| 36 | |
| 37 | /* Callback prototypes for zebra client service. */ |
| 38 | int ripng_interface_up (int, struct zclient *, zebra_size_t); |
| 39 | int ripng_interface_down (int, struct zclient *, zebra_size_t); |
| 40 | int ripng_interface_add (int, struct zclient *, zebra_size_t); |
| 41 | int ripng_interface_delete (int, struct zclient *, zebra_size_t); |
| 42 | int ripng_interface_address_add (int, struct zclient *, zebra_size_t); |
| 43 | int ripng_interface_address_delete (int, struct zclient *, zebra_size_t); |
| 44 | |
| 45 | void |
| 46 | ripng_zebra_ipv6_add (struct prefix_ipv6 *p, struct in6_addr *nexthop, |
hasso | deba355 | 2005-08-27 06:19:39 +0000 | [diff] [blame] | 47 | unsigned int ifindex, u_char metric) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 48 | { |
| 49 | struct zapi_ipv6 api; |
| 50 | |
| 51 | if (zclient->redist[ZEBRA_ROUTE_RIPNG]) |
| 52 | { |
| 53 | api.type = ZEBRA_ROUTE_RIPNG; |
| 54 | api.flags = 0; |
| 55 | api.message = 0; |
Denis Ovsienko | b4e45f6 | 2011-12-05 16:35:14 +0400 | [diff] [blame] | 56 | api.safi = SAFI_UNICAST; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 57 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
| 58 | api.nexthop_num = 1; |
| 59 | api.nexthop = &nexthop; |
| 60 | SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); |
| 61 | api.ifindex_num = 1; |
| 62 | api.ifindex = &ifindex; |
hasso | deba355 | 2005-08-27 06:19:39 +0000 | [diff] [blame] | 63 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
| 64 | api.metric = metric; |
| 65 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 66 | zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, p, &api); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
| 70 | void |
| 71 | ripng_zebra_ipv6_delete (struct prefix_ipv6 *p, struct in6_addr *nexthop, |
| 72 | unsigned int ifindex) |
| 73 | { |
| 74 | struct zapi_ipv6 api; |
| 75 | |
| 76 | if (zclient->redist[ZEBRA_ROUTE_RIPNG]) |
| 77 | { |
| 78 | api.type = ZEBRA_ROUTE_RIPNG; |
| 79 | api.flags = 0; |
| 80 | api.message = 0; |
Denis Ovsienko | b4e45f6 | 2011-12-05 16:35:14 +0400 | [diff] [blame] | 81 | api.safi = SAFI_UNICAST; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 82 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
| 83 | api.nexthop_num = 1; |
| 84 | api.nexthop = &nexthop; |
| 85 | SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX); |
| 86 | api.ifindex_num = 1; |
| 87 | api.ifindex = &ifindex; |
| 88 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 89 | zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, p, &api); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 90 | } |
| 91 | } |
| 92 | |
| 93 | /* Zebra route add and delete treatment. */ |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 94 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 95 | ripng_zebra_read_ipv6 (int command, struct zclient *zclient, |
| 96 | zebra_size_t length) |
| 97 | { |
| 98 | struct stream *s; |
| 99 | struct zapi_ipv6 api; |
| 100 | unsigned long ifindex; |
| 101 | struct in6_addr nexthop; |
| 102 | struct prefix_ipv6 p; |
| 103 | |
| 104 | s = zclient->ibuf; |
| 105 | ifindex = 0; |
| 106 | memset (&nexthop, 0, sizeof (struct in6_addr)); |
| 107 | |
| 108 | /* Type, flags, message. */ |
| 109 | api.type = stream_getc (s); |
| 110 | api.flags = stream_getc (s); |
| 111 | api.message = stream_getc (s); |
| 112 | |
| 113 | /* IPv6 prefix. */ |
| 114 | memset (&p, 0, sizeof (struct prefix_ipv6)); |
| 115 | p.family = AF_INET6; |
| 116 | p.prefixlen = stream_getc (s); |
| 117 | stream_get (&p.prefix, s, PSIZE (p.prefixlen)); |
| 118 | |
| 119 | /* Nexthop, ifindex, distance, metric. */ |
| 120 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) |
| 121 | { |
| 122 | api.nexthop_num = stream_getc (s); |
| 123 | stream_get (&nexthop, s, 16); |
| 124 | } |
| 125 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) |
| 126 | { |
| 127 | api.ifindex_num = stream_getc (s); |
| 128 | ifindex = stream_getl (s); |
| 129 | } |
| 130 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) |
| 131 | api.distance = stream_getc (s); |
| 132 | else |
| 133 | api.distance = 0; |
| 134 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) |
| 135 | api.metric = stream_getl (s); |
| 136 | else |
| 137 | api.metric = 0; |
| 138 | |
| 139 | if (command == ZEBRA_IPV6_ROUTE_ADD) |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 140 | ripng_redistribute_add (api.type, RIPNG_ROUTE_REDISTRIBUTE, &p, ifindex, &nexthop); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 141 | else |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 142 | ripng_redistribute_delete (api.type, RIPNG_ROUTE_REDISTRIBUTE, &p, ifindex); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 147 | void |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 148 | ripng_zclient_reset (void) |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 149 | { |
| 150 | zclient_reset (zclient); |
| 151 | } |
| 152 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 153 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 154 | ripng_redistribute_unset (int type) |
| 155 | { |
| 156 | if (! zclient->redist[type]) |
| 157 | return CMD_SUCCESS; |
| 158 | |
| 159 | zclient->redist[type] = 0; |
| 160 | |
| 161 | if (zclient->sock > 0) |
ajs | 634f9ea | 2005-04-11 15:51:40 +0000 | [diff] [blame] | 162 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 163 | |
| 164 | ripng_redistribute_withdraw (type); |
| 165 | |
| 166 | return CMD_SUCCESS; |
| 167 | } |
| 168 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 169 | int |
| 170 | ripng_redistribute_check (int type) |
| 171 | { |
| 172 | return (zclient->redist[type]); |
| 173 | } |
| 174 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 175 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 176 | ripng_redistribute_metric_set (int type, int metric) |
| 177 | { |
| 178 | ripng->route_map[type].metric_config = 1; |
| 179 | ripng->route_map[type].metric = metric; |
| 180 | } |
| 181 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 182 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 183 | ripng_redistribute_metric_unset (int type) |
| 184 | { |
| 185 | ripng->route_map[type].metric_config = 0; |
| 186 | ripng->route_map[type].metric = 0; |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 187 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 188 | } |
| 189 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 190 | static void |
hasso | 98b718a | 2004-10-11 12:57:57 +0000 | [diff] [blame] | 191 | ripng_redistribute_routemap_set (int type, const char *name) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 192 | { |
| 193 | if (ripng->route_map[type].name) |
| 194 | free (ripng->route_map[type].name); |
| 195 | |
| 196 | ripng->route_map[type].name = strdup (name); |
| 197 | ripng->route_map[type].map = route_map_lookup_by_name (name); |
| 198 | } |
| 199 | |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 200 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 201 | ripng_redistribute_routemap_unset (int type) |
| 202 | { |
| 203 | if (ripng->route_map[type].name) |
| 204 | free (ripng->route_map[type].name); |
| 205 | |
| 206 | ripng->route_map[type].name = NULL; |
| 207 | ripng->route_map[type].map = NULL; |
| 208 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 209 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 210 | /* Redistribution types */ |
| 211 | static struct { |
| 212 | int type; |
| 213 | int str_min_len; |
hasso | 7a1d583 | 2004-10-08 06:32:23 +0000 | [diff] [blame] | 214 | const char *str; |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 215 | } redist_type[] = { |
| 216 | {ZEBRA_ROUTE_KERNEL, 1, "kernel"}, |
| 217 | {ZEBRA_ROUTE_CONNECT, 1, "connected"}, |
| 218 | {ZEBRA_ROUTE_STATIC, 1, "static"}, |
| 219 | {ZEBRA_ROUTE_OSPF6, 1, "ospf6"}, |
| 220 | {ZEBRA_ROUTE_BGP, 1, "bgp"}, |
| 221 | {0, 0, NULL} |
| 222 | }; |
| 223 | |
| 224 | void |
| 225 | ripng_redistribute_clean () |
| 226 | { |
| 227 | int i; |
| 228 | |
| 229 | for (i = 0; redist_type[i].str; i++) |
| 230 | { |
| 231 | if (zclient->redist[redist_type[i].type]) |
| 232 | { |
| 233 | if (zclient->sock > 0) |
| 234 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, |
ajs | 634f9ea | 2005-04-11 15:51:40 +0000 | [diff] [blame] | 235 | zclient, redist_type[i].type); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 236 | |
| 237 | zclient->redist[redist_type[i].type] = 0; |
| 238 | |
| 239 | /* Remove the routes from RIPng table. */ |
| 240 | ripng_redistribute_withdraw (redist_type[i].type); |
| 241 | } |
| 242 | } |
| 243 | } |
| 244 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 245 | DEFUN (router_zebra, |
| 246 | router_zebra_cmd, |
| 247 | "router zebra", |
| 248 | "Enable a routing process\n" |
| 249 | "Make connection to zebra daemon\n") |
| 250 | { |
| 251 | vty->node = ZEBRA_NODE; |
| 252 | zclient->enable = 1; |
| 253 | zclient_start (zclient); |
| 254 | return CMD_SUCCESS; |
| 255 | } |
| 256 | |
| 257 | DEFUN (no_router_zebra, |
| 258 | no_router_zebra_cmd, |
| 259 | "no router zebra", |
| 260 | NO_STR |
| 261 | "Disable a routing process\n" |
| 262 | "Stop connection to zebra daemon\n") |
| 263 | { |
| 264 | zclient->enable = 0; |
| 265 | zclient_stop (zclient); |
| 266 | return CMD_SUCCESS; |
| 267 | } |
| 268 | |
| 269 | DEFUN (ripng_redistribute_ripng, |
| 270 | ripng_redistribute_ripng_cmd, |
| 271 | "redistribute ripng", |
| 272 | "Redistribute information from another routing protocol\n" |
| 273 | "RIPng route\n") |
| 274 | { |
| 275 | zclient->redist[ZEBRA_ROUTE_RIPNG] = 1; |
| 276 | return CMD_SUCCESS; |
| 277 | } |
| 278 | |
| 279 | DEFUN (no_ripng_redistribute_ripng, |
| 280 | no_ripng_redistribute_ripng_cmd, |
| 281 | "no redistribute ripng", |
| 282 | NO_STR |
| 283 | "Redistribute information from another routing protocol\n" |
| 284 | "RIPng route\n") |
| 285 | { |
| 286 | zclient->redist[ZEBRA_ROUTE_RIPNG] = 0; |
| 287 | return CMD_SUCCESS; |
| 288 | } |
| 289 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 290 | DEFUN (ripng_redistribute_type, |
| 291 | ripng_redistribute_type_cmd, |
| 292 | "redistribute (kernel|connected|static|ospf6|bgp)", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 293 | "Redistribute information from another routing protocol\n" |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 294 | "Kernel routes\n" |
| 295 | "Connected\n" |
| 296 | "Static routes\n" |
| 297 | "Open Shortest Path First (OSPFv3)\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 298 | "Border Gateway Protocol (BGP)\n") |
| 299 | { |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 300 | int i; |
| 301 | |
| 302 | for(i = 0; redist_type[i].str; i++) |
| 303 | { |
| 304 | if (strncmp (redist_type[i].str, argv[0], |
| 305 | redist_type[i].str_min_len) == 0) |
| 306 | { |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 307 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 308 | return CMD_SUCCESS; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 313 | VTY_NEWLINE); |
| 314 | |
| 315 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 316 | } |
| 317 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 318 | DEFUN (no_ripng_redistribute_type, |
| 319 | no_ripng_redistribute_type_cmd, |
| 320 | "no redistribute (kernel|connected|static|ospf6|bgp)", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 321 | NO_STR |
| 322 | "Redistribute information from another routing protocol\n" |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 323 | "Kernel routes\n" |
| 324 | "Connected\n" |
| 325 | "Static routes\n" |
| 326 | "Open Shortest Path First (OSPFv3)\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 327 | "Border Gateway Protocol (BGP)\n") |
| 328 | { |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 329 | int i; |
| 330 | |
| 331 | for (i = 0; redist_type[i].str; i++) |
| 332 | { |
| 333 | if (strncmp(redist_type[i].str, argv[0], |
| 334 | redist_type[i].str_min_len) == 0) |
| 335 | { |
| 336 | ripng_redistribute_metric_unset (redist_type[i].type); |
| 337 | ripng_redistribute_routemap_unset (redist_type[i].type); |
| 338 | return ripng_redistribute_unset (redist_type[i].type); |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 343 | VTY_NEWLINE); |
| 344 | |
| 345 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 346 | } |
| 347 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 348 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 349 | DEFUN (ripng_redistribute_type_metric, |
| 350 | ripng_redistribute_type_metric_cmd, |
| 351 | "redistribute (kernel|connected|static|ospf6|bgp) metric <0-16>", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 352 | "Redistribute information from another routing protocol\n" |
| 353 | "Kernel routes\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 354 | "Connected\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 355 | "Static routes\n" |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 356 | "Open Shortest Path First (OSPFv3)\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 357 | "Border Gateway Protocol (BGP)\n" |
| 358 | "Metric\n" |
| 359 | "Metric value\n") |
| 360 | { |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 361 | int i; |
| 362 | int metric; |
| 363 | |
| 364 | metric = atoi (argv[1]); |
| 365 | |
| 366 | for (i = 0; redist_type[i].str; i++) { |
| 367 | if (strncmp(redist_type[i].str, argv[0], |
| 368 | redist_type[i].str_min_len) == 0) |
| 369 | { |
| 370 | ripng_redistribute_metric_set (redist_type[i].type, metric); |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 371 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 372 | return CMD_SUCCESS; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 377 | VTY_NEWLINE); |
| 378 | |
| 379 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 380 | } |
| 381 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 382 | ALIAS (no_ripng_redistribute_type, |
| 383 | no_ripng_redistribute_type_metric_cmd, |
| 384 | "no redistribute (kernel|connected|static|ospf6|bgp) metric <0-16>", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 385 | NO_STR |
| 386 | "Redistribute information from another routing protocol\n" |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 387 | "Kernel routes\n" |
| 388 | "Connected\n" |
| 389 | "Static routes\n" |
| 390 | "Open Shortest Path First (OSPFv3)\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 391 | "Border Gateway Protocol (BGP)\n" |
| 392 | "Metric\n" |
| 393 | "Metric value\n") |
| 394 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 395 | DEFUN (ripng_redistribute_type_routemap, |
| 396 | ripng_redistribute_type_routemap_cmd, |
| 397 | "redistribute (kernel|connected|static|ospf6|bgp) route-map WORD", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 398 | "Redistribute information from another routing protocol\n" |
| 399 | "Kernel routes\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 400 | "Connected\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 401 | "Static routes\n" |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 402 | "Open Shortest Path First (OSPFv3)\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 403 | "Border Gateway Protocol (BGP)\n" |
| 404 | "Route map reference\n" |
| 405 | "Pointer to route-map entries\n") |
| 406 | { |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 407 | int i; |
| 408 | |
| 409 | for (i = 0; redist_type[i].str; i++) { |
| 410 | if (strncmp(redist_type[i].str, argv[0], |
| 411 | redist_type[i].str_min_len) == 0) |
| 412 | { |
| 413 | ripng_redistribute_routemap_set (redist_type[i].type, argv[1]); |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 414 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 415 | return CMD_SUCCESS; |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 420 | VTY_NEWLINE); |
| 421 | |
| 422 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 423 | } |
| 424 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 425 | ALIAS (no_ripng_redistribute_type, |
| 426 | no_ripng_redistribute_type_routemap_cmd, |
| 427 | "no redistribute (kernel|connected|static|ospf6|bgp) route-map WORD", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 428 | NO_STR |
| 429 | "Redistribute information from another routing protocol\n" |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 430 | "Kernel routes\n" |
| 431 | "Connected\n" |
| 432 | "Static routes\n" |
| 433 | "Open Shortest Path First (OSPFv3)\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 434 | "Border Gateway Protocol (BGP)\n" |
| 435 | "Route map reference\n" |
| 436 | "Pointer to route-map entries\n") |
| 437 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 438 | DEFUN (ripng_redistribute_type_metric_routemap, |
| 439 | ripng_redistribute_type_metric_routemap_cmd, |
| 440 | "redistribute (kernel|connected|static|ospf6|bgp) metric <0-16> route-map WORD", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 441 | "Redistribute information from another routing protocol\n" |
| 442 | "Kernel routes\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 443 | "Connected\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 444 | "Static routes\n" |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 445 | "Open Shortest Path First (OSPFv3)\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 446 | "Border Gateway Protocol (BGP)\n" |
| 447 | "Metric\n" |
| 448 | "Metric value\n" |
| 449 | "Route map reference\n" |
| 450 | "Pointer to route-map entries\n") |
| 451 | { |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 452 | int i; |
| 453 | int metric; |
| 454 | |
| 455 | metric = atoi (argv[1]); |
| 456 | |
| 457 | for (i = 0; redist_type[i].str; i++) { |
| 458 | if (strncmp(redist_type[i].str, argv[0], |
| 459 | redist_type[i].str_min_len) == 0) |
| 460 | { |
| 461 | ripng_redistribute_metric_set (redist_type[i].type, metric); |
| 462 | ripng_redistribute_routemap_set (redist_type[i].type, argv[2]); |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 463 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 464 | return CMD_SUCCESS; |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 469 | VTY_NEWLINE); |
| 470 | |
| 471 | return CMD_WARNING; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 472 | } |
| 473 | |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 474 | ALIAS (no_ripng_redistribute_type, |
| 475 | no_ripng_redistribute_type_metric_routemap_cmd, |
| 476 | "no redistribute (kernel|connected|static|ospf6|bgp) metric <0-16> route-map WORD", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 477 | NO_STR |
| 478 | "Redistribute information from another routing protocol\n" |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 479 | "Kernel routes\n" |
| 480 | "Connected\n" |
| 481 | "Static routes\n" |
| 482 | "Open Shortest Path First (OSPFv3)\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 483 | "Border Gateway Protocol (BGP)\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 484 | "Route map reference\n" |
| 485 | "Pointer to route-map entries\n") |
| 486 | |
| 487 | void |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 488 | ripng_redistribute_write (struct vty *vty, int config_mode) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 489 | { |
| 490 | int i; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 491 | |
| 492 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) |
| 493 | if (i != zclient->redist_default && zclient->redist[i]) |
| 494 | { |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 495 | if (config_mode) |
| 496 | { |
| 497 | if (ripng->route_map[i].metric_config) |
| 498 | { |
| 499 | if (ripng->route_map[i].name) |
| 500 | vty_out (vty, " redistribute %s metric %d route-map %s%s", |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 501 | zebra_route_string(i), ripng->route_map[i].metric, |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 502 | ripng->route_map[i].name, VTY_NEWLINE); |
| 503 | else |
| 504 | vty_out (vty, " redistribute %s metric %d%s", |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 505 | zebra_route_string(i), ripng->route_map[i].metric, |
| 506 | VTY_NEWLINE); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 507 | } |
| 508 | else |
| 509 | { |
| 510 | if (ripng->route_map[i].name) |
| 511 | vty_out (vty, " redistribute %s route-map %s%s", |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 512 | zebra_route_string(i), ripng->route_map[i].name, |
| 513 | VTY_NEWLINE); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 514 | else |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 515 | vty_out (vty, " redistribute %s%s", zebra_route_string(i), |
| 516 | VTY_NEWLINE); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 517 | } |
| 518 | } |
| 519 | else |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 520 | vty_out (vty, " %s", zebra_route_string(i)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 521 | } |
| 522 | } |
| 523 | |
| 524 | /* RIPng configuration write function. */ |
Paul Jakma | 6ac29a5 | 2008-08-15 13:45:30 +0100 | [diff] [blame] | 525 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 526 | zebra_config_write (struct vty *vty) |
| 527 | { |
| 528 | if (! zclient->enable) |
| 529 | { |
| 530 | vty_out (vty, "no router zebra%s", VTY_NEWLINE); |
| 531 | return 1; |
| 532 | } |
| 533 | else if (! zclient->redist[ZEBRA_ROUTE_RIPNG]) |
| 534 | { |
| 535 | vty_out (vty, "router zebra%s", VTY_NEWLINE); |
| 536 | vty_out (vty, " no redistribute ripng%s", VTY_NEWLINE); |
| 537 | return 1; |
| 538 | } |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | /* Zebra node structure. */ |
Stephen Hemminger | 7fc626d | 2008-12-01 11:10:34 -0800 | [diff] [blame] | 543 | static struct cmd_node zebra_node = |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 544 | { |
| 545 | ZEBRA_NODE, |
| 546 | "%s(config-router)# ", |
| 547 | }; |
| 548 | |
| 549 | /* Initialize zebra structure and it's commands. */ |
| 550 | void |
| 551 | zebra_init () |
| 552 | { |
| 553 | /* Allocate zebra structure. */ |
| 554 | zclient = zclient_new (); |
| 555 | zclient_init (zclient, ZEBRA_ROUTE_RIPNG); |
| 556 | |
| 557 | zclient->interface_up = ripng_interface_up; |
| 558 | zclient->interface_down = ripng_interface_down; |
| 559 | zclient->interface_add = ripng_interface_add; |
| 560 | zclient->interface_delete = ripng_interface_delete; |
| 561 | zclient->interface_address_add = ripng_interface_address_add; |
| 562 | zclient->interface_address_delete = ripng_interface_address_delete; |
| 563 | zclient->ipv6_route_add = ripng_zebra_read_ipv6; |
| 564 | zclient->ipv6_route_delete = ripng_zebra_read_ipv6; |
| 565 | |
| 566 | /* Install zebra node. */ |
| 567 | install_node (&zebra_node, zebra_config_write); |
| 568 | |
| 569 | /* Install command element for zebra node. */ |
| 570 | install_element (CONFIG_NODE, &router_zebra_cmd); |
| 571 | install_element (CONFIG_NODE, &no_router_zebra_cmd); |
| 572 | install_default (ZEBRA_NODE); |
| 573 | install_element (ZEBRA_NODE, &ripng_redistribute_ripng_cmd); |
| 574 | install_element (ZEBRA_NODE, &no_ripng_redistribute_ripng_cmd); |
hasso | a94434b | 2003-05-25 17:10:12 +0000 | [diff] [blame] | 575 | |
| 576 | /* Install command elements to ripng node */ |
| 577 | install_element (RIPNG_NODE, &ripng_redistribute_type_cmd); |
| 578 | install_element (RIPNG_NODE, &ripng_redistribute_type_routemap_cmd); |
| 579 | install_element (RIPNG_NODE, &ripng_redistribute_type_metric_cmd); |
| 580 | install_element (RIPNG_NODE, &ripng_redistribute_type_metric_routemap_cmd); |
| 581 | install_element (RIPNG_NODE, &no_ripng_redistribute_type_cmd); |
| 582 | install_element (RIPNG_NODE, &no_ripng_redistribute_type_routemap_cmd); |
| 583 | install_element (RIPNG_NODE, &no_ripng_redistribute_type_metric_cmd); |
| 584 | install_element (RIPNG_NODE, &no_ripng_redistribute_type_metric_routemap_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 585 | } |