paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* RIPd and zebra interface. |
| 2 | * Copyright (C) 1997, 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 | #include <zebra.h> |
| 23 | |
| 24 | #include "command.h" |
| 25 | #include "prefix.h" |
| 26 | #include "stream.h" |
| 27 | #include "routemap.h" |
| 28 | #include "zclient.h" |
| 29 | #include "log.h" |
| 30 | #include "ripd/ripd.h" |
| 31 | #include "ripd/rip_debug.h" |
paul | dc63bfd | 2005-10-25 23:31:05 +0000 | [diff] [blame] | 32 | #include "ripd/rip_interface.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 33 | |
| 34 | /* All information about zebra. */ |
| 35 | struct zclient *zclient = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 36 | |
| 37 | /* RIPd to zebra command interface. */ |
| 38 | void |
| 39 | rip_zebra_ipv4_add (struct prefix_ipv4 *p, struct in_addr *nexthop, |
| 40 | u_int32_t metric, u_char distance) |
| 41 | { |
| 42 | struct zapi_ipv4 api; |
| 43 | |
| 44 | if (zclient->redist[ZEBRA_ROUTE_RIP]) |
| 45 | { |
| 46 | api.type = ZEBRA_ROUTE_RIP; |
| 47 | api.flags = 0; |
| 48 | api.message = 0; |
Denis Ovsienko | b4e45f6 | 2011-12-05 16:35:14 +0400 | [diff] [blame^] | 49 | api.safi = SAFI_UNICAST; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 50 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
| 51 | api.nexthop_num = 1; |
| 52 | api.nexthop = &nexthop; |
| 53 | api.ifindex_num = 0; |
| 54 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
| 55 | api.metric = metric; |
| 56 | |
| 57 | if (distance && distance != ZEBRA_RIP_DISTANCE_DEFAULT) |
| 58 | { |
| 59 | SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE); |
| 60 | api.distance = distance; |
| 61 | } |
| 62 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 63 | zapi_ipv4_route (ZEBRA_IPV4_ROUTE_ADD, zclient, p, &api); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 64 | |
| 65 | rip_global_route_changes++; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | void |
| 70 | rip_zebra_ipv4_delete (struct prefix_ipv4 *p, struct in_addr *nexthop, |
| 71 | u_int32_t metric) |
| 72 | { |
| 73 | struct zapi_ipv4 api; |
| 74 | |
| 75 | if (zclient->redist[ZEBRA_ROUTE_RIP]) |
| 76 | { |
| 77 | api.type = ZEBRA_ROUTE_RIP; |
| 78 | api.flags = 0; |
| 79 | api.message = 0; |
Denis Ovsienko | b4e45f6 | 2011-12-05 16:35:14 +0400 | [diff] [blame^] | 80 | api.safi = SAFI_UNICAST; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 81 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
| 82 | api.nexthop_num = 1; |
| 83 | api.nexthop = &nexthop; |
| 84 | api.ifindex_num = 0; |
| 85 | SET_FLAG (api.message, ZAPI_MESSAGE_METRIC); |
| 86 | api.metric = metric; |
| 87 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 88 | zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, p, &api); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 89 | |
| 90 | rip_global_route_changes++; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | /* Zebra route add and delete treatment. */ |
paul | dc63bfd | 2005-10-25 23:31:05 +0000 | [diff] [blame] | 95 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 96 | rip_zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length) |
| 97 | { |
| 98 | struct stream *s; |
| 99 | struct zapi_ipv4 api; |
| 100 | unsigned long ifindex; |
| 101 | struct in_addr nexthop; |
| 102 | struct prefix_ipv4 p; |
| 103 | |
| 104 | s = zclient->ibuf; |
| 105 | ifindex = 0; |
| 106 | nexthop.s_addr = 0; |
| 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 | /* IPv4 prefix. */ |
| 114 | memset (&p, 0, sizeof (struct prefix_ipv4)); |
| 115 | p.family = AF_INET; |
| 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 | nexthop.s_addr = stream_get_ipv4 (s); |
| 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); |
vincent | fbf5d03 | 2005-09-29 11:25:50 +0000 | [diff] [blame] | 132 | else |
| 133 | api.distance = 255; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 134 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) |
| 135 | api.metric = stream_getl (s); |
vincent | fbf5d03 | 2005-09-29 11:25:50 +0000 | [diff] [blame] | 136 | else |
| 137 | api.metric = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 138 | |
| 139 | /* Then fetch IPv4 prefixes. */ |
| 140 | if (command == ZEBRA_IPV4_ROUTE_ADD) |
vincent | fbf5d03 | 2005-09-29 11:25:50 +0000 | [diff] [blame] | 141 | rip_redistribute_add (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex, |
| 142 | &nexthop, api.metric, api.distance); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 143 | else |
| 144 | rip_redistribute_delete (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex); |
| 145 | |
| 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | void |
paul | dc63bfd | 2005-10-25 23:31:05 +0000 | [diff] [blame] | 150 | rip_zclient_reset (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 151 | { |
| 152 | zclient_reset (zclient); |
| 153 | } |
| 154 | |
| 155 | /* RIP route-map set for redistribution */ |
paul | dc63bfd | 2005-10-25 23:31:05 +0000 | [diff] [blame] | 156 | static void |
hasso | 98b718a | 2004-10-11 12:57:57 +0000 | [diff] [blame] | 157 | rip_routemap_set (int type, const char *name) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 158 | { |
| 159 | if (rip->route_map[type].name) |
| 160 | free(rip->route_map[type].name); |
| 161 | |
| 162 | rip->route_map[type].name = strdup (name); |
| 163 | rip->route_map[type].map = route_map_lookup_by_name (name); |
| 164 | } |
| 165 | |
paul | dc63bfd | 2005-10-25 23:31:05 +0000 | [diff] [blame] | 166 | static void |
hasso | 8a676be | 2004-10-08 06:36:38 +0000 | [diff] [blame] | 167 | rip_redistribute_metric_set (int type, unsigned int metric) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 168 | { |
| 169 | rip->route_map[type].metric_config = 1; |
| 170 | rip->route_map[type].metric = metric; |
| 171 | } |
| 172 | |
paul | dc63bfd | 2005-10-25 23:31:05 +0000 | [diff] [blame] | 173 | static int |
hasso | 8a676be | 2004-10-08 06:36:38 +0000 | [diff] [blame] | 174 | rip_metric_unset (int type, unsigned int metric) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 175 | { |
| 176 | #define DONT_CARE_METRIC_RIP 17 |
| 177 | if (metric != DONT_CARE_METRIC_RIP && |
| 178 | rip->route_map[type].metric != metric) |
| 179 | return 1; |
| 180 | rip->route_map[type].metric_config = 0; |
| 181 | rip->route_map[type].metric = 0; |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | /* RIP route-map unset for redistribution */ |
paul | dc63bfd | 2005-10-25 23:31:05 +0000 | [diff] [blame] | 186 | static int |
hasso | 98b718a | 2004-10-11 12:57:57 +0000 | [diff] [blame] | 187 | rip_routemap_unset (int type, const char *name) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 188 | { |
| 189 | if (! rip->route_map[type].name || |
| 190 | (name != NULL && strcmp(rip->route_map[type].name,name))) |
| 191 | return 1; |
| 192 | |
| 193 | free (rip->route_map[type].name); |
| 194 | rip->route_map[type].name = NULL; |
| 195 | rip->route_map[type].map = NULL; |
| 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | /* Redistribution types */ |
| 201 | static struct { |
| 202 | int type; |
| 203 | int str_min_len; |
hasso | 8a676be | 2004-10-08 06:36:38 +0000 | [diff] [blame] | 204 | const char *str; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 205 | } redist_type[] = { |
| 206 | {ZEBRA_ROUTE_KERNEL, 1, "kernel"}, |
| 207 | {ZEBRA_ROUTE_CONNECT, 1, "connected"}, |
| 208 | {ZEBRA_ROUTE_STATIC, 1, "static"}, |
| 209 | {ZEBRA_ROUTE_OSPF, 1, "ospf"}, |
| 210 | {ZEBRA_ROUTE_BGP, 1, "bgp"}, |
| 211 | {0, 0, NULL} |
| 212 | }; |
| 213 | |
| 214 | DEFUN (router_zebra, |
| 215 | router_zebra_cmd, |
| 216 | "router zebra", |
| 217 | "Enable a routing process\n" |
| 218 | "Make connection to zebra daemon\n") |
| 219 | { |
| 220 | vty->node = ZEBRA_NODE; |
| 221 | zclient->enable = 1; |
| 222 | zclient_start (zclient); |
| 223 | return CMD_SUCCESS; |
| 224 | } |
| 225 | |
| 226 | DEFUN (no_router_zebra, |
| 227 | no_router_zebra_cmd, |
| 228 | "no router zebra", |
| 229 | NO_STR |
| 230 | "Enable a routing process\n" |
| 231 | "Make connection to zebra daemon\n") |
| 232 | { |
| 233 | zclient->enable = 0; |
| 234 | zclient_stop (zclient); |
| 235 | return CMD_SUCCESS; |
| 236 | } |
| 237 | |
Stephen Hemminger | 2c23970 | 2009-12-10 19:16:05 +0300 | [diff] [blame] | 238 | #if 0 |
paul | dc63bfd | 2005-10-25 23:31:05 +0000 | [diff] [blame] | 239 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 240 | rip_redistribute_set (int type) |
| 241 | { |
| 242 | if (zclient->redist[type]) |
| 243 | return CMD_SUCCESS; |
| 244 | |
| 245 | zclient->redist[type] = 1; |
| 246 | |
| 247 | if (zclient->sock > 0) |
ajs | 634f9ea | 2005-04-11 15:51:40 +0000 | [diff] [blame] | 248 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 249 | |
| 250 | return CMD_SUCCESS; |
| 251 | } |
Stephen Hemminger | 2c23970 | 2009-12-10 19:16:05 +0300 | [diff] [blame] | 252 | #endif |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 253 | |
paul | dc63bfd | 2005-10-25 23:31:05 +0000 | [diff] [blame] | 254 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 255 | rip_redistribute_unset (int type) |
| 256 | { |
| 257 | if (! zclient->redist[type]) |
| 258 | return CMD_SUCCESS; |
| 259 | |
| 260 | zclient->redist[type] = 0; |
| 261 | |
| 262 | if (zclient->sock > 0) |
ajs | 634f9ea | 2005-04-11 15:51:40 +0000 | [diff] [blame] | 263 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 264 | |
| 265 | /* Remove the routes from RIP table. */ |
| 266 | rip_redistribute_withdraw (type); |
| 267 | |
| 268 | return CMD_SUCCESS; |
| 269 | } |
| 270 | |
| 271 | int |
| 272 | rip_redistribute_check (int type) |
| 273 | { |
| 274 | return (zclient->redist[type]); |
| 275 | } |
| 276 | |
| 277 | void |
paul | dc63bfd | 2005-10-25 23:31:05 +0000 | [diff] [blame] | 278 | rip_redistribute_clean (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 279 | { |
| 280 | int i; |
| 281 | |
| 282 | for (i = 0; redist_type[i].str; i++) |
| 283 | { |
| 284 | if (zclient->redist[redist_type[i].type]) |
| 285 | { |
| 286 | if (zclient->sock > 0) |
| 287 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, |
ajs | 634f9ea | 2005-04-11 15:51:40 +0000 | [diff] [blame] | 288 | zclient, redist_type[i].type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 289 | |
| 290 | zclient->redist[redist_type[i].type] = 0; |
| 291 | |
| 292 | /* Remove the routes from RIP table. */ |
| 293 | rip_redistribute_withdraw (redist_type[i].type); |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | DEFUN (rip_redistribute_rip, |
| 299 | rip_redistribute_rip_cmd, |
| 300 | "redistribute rip", |
| 301 | "Redistribute information from another routing protocol\n" |
| 302 | "Routing Information Protocol (RIP)\n") |
| 303 | { |
| 304 | zclient->redist[ZEBRA_ROUTE_RIP] = 1; |
| 305 | return CMD_SUCCESS; |
| 306 | } |
| 307 | |
| 308 | DEFUN (no_rip_redistribute_rip, |
| 309 | no_rip_redistribute_rip_cmd, |
| 310 | "no redistribute rip", |
| 311 | NO_STR |
| 312 | "Redistribute information from another routing protocol\n" |
| 313 | "Routing Information Protocol (RIP)\n") |
| 314 | { |
| 315 | zclient->redist[ZEBRA_ROUTE_RIP] = 0; |
| 316 | return CMD_SUCCESS; |
| 317 | } |
| 318 | |
| 319 | DEFUN (rip_redistribute_type, |
| 320 | rip_redistribute_type_cmd, |
Paul Jakma | 9a57dc6 | 2006-06-30 16:58:53 +0000 | [diff] [blame] | 321 | "redistribute " QUAGGA_REDIST_STR_RIPD, |
| 322 | REDIST_STR |
| 323 | QUAGGA_REDIST_HELP_STR_RIPD) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 324 | { |
| 325 | int i; |
| 326 | |
| 327 | for(i = 0; redist_type[i].str; i++) |
| 328 | { |
| 329 | if (strncmp (redist_type[i].str, argv[0], |
| 330 | redist_type[i].str_min_len) == 0) |
| 331 | { |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 332 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, |
| 333 | redist_type[i].type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 334 | return CMD_SUCCESS; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 339 | VTY_NEWLINE); |
| 340 | |
| 341 | return CMD_WARNING; |
| 342 | } |
| 343 | |
| 344 | DEFUN (no_rip_redistribute_type, |
| 345 | no_rip_redistribute_type_cmd, |
Paul Jakma | 9a57dc6 | 2006-06-30 16:58:53 +0000 | [diff] [blame] | 346 | "no redistribute " QUAGGA_REDIST_STR_RIPD, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 347 | NO_STR |
Paul Jakma | 9a57dc6 | 2006-06-30 16:58:53 +0000 | [diff] [blame] | 348 | REDIST_STR |
| 349 | QUAGGA_REDIST_HELP_STR_RIPD) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 350 | { |
| 351 | int i; |
| 352 | |
| 353 | for (i = 0; redist_type[i].str; i++) |
| 354 | { |
| 355 | if (strncmp(redist_type[i].str, argv[0], |
| 356 | redist_type[i].str_min_len) == 0) |
| 357 | { |
| 358 | rip_metric_unset (redist_type[i].type, DONT_CARE_METRIC_RIP); |
| 359 | rip_routemap_unset (redist_type[i].type,NULL); |
| 360 | rip_redistribute_unset (redist_type[i].type); |
| 361 | return CMD_SUCCESS; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 366 | VTY_NEWLINE); |
| 367 | |
| 368 | return CMD_WARNING; |
| 369 | } |
| 370 | |
| 371 | DEFUN (rip_redistribute_type_routemap, |
| 372 | rip_redistribute_type_routemap_cmd, |
Paul Jakma | 9a57dc6 | 2006-06-30 16:58:53 +0000 | [diff] [blame] | 373 | "redistribute " QUAGGA_REDIST_STR_RIPD " route-map WORD", |
| 374 | REDIST_STR |
| 375 | QUAGGA_REDIST_HELP_STR_RIPD |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 376 | "Route map reference\n" |
| 377 | "Pointer to route-map entries\n") |
| 378 | { |
| 379 | int i; |
| 380 | |
| 381 | for (i = 0; redist_type[i].str; i++) { |
| 382 | if (strncmp(redist_type[i].str, argv[0], |
| 383 | redist_type[i].str_min_len) == 0) |
| 384 | { |
| 385 | rip_routemap_set (redist_type[i].type, argv[1]); |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 386 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 387 | return CMD_SUCCESS; |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 392 | VTY_NEWLINE); |
| 393 | |
| 394 | return CMD_WARNING; |
| 395 | } |
| 396 | |
| 397 | DEFUN (no_rip_redistribute_type_routemap, |
| 398 | no_rip_redistribute_type_routemap_cmd, |
Paul Jakma | 9a57dc6 | 2006-06-30 16:58:53 +0000 | [diff] [blame] | 399 | "no redistribute " QUAGGA_REDIST_STR_RIPD " route-map WORD", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 400 | NO_STR |
Paul Jakma | 9a57dc6 | 2006-06-30 16:58:53 +0000 | [diff] [blame] | 401 | REDIST_STR |
| 402 | QUAGGA_REDIST_HELP_STR_RIPD |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 403 | "Route map reference\n" |
| 404 | "Pointer to route-map entries\n") |
| 405 | { |
| 406 | int i; |
| 407 | |
| 408 | for (i = 0; redist_type[i].str; i++) |
| 409 | { |
| 410 | if (strncmp(redist_type[i].str, argv[0], |
| 411 | redist_type[i].str_min_len) == 0) |
| 412 | { |
| 413 | if (rip_routemap_unset (redist_type[i].type,argv[1])) |
| 414 | return CMD_WARNING; |
| 415 | rip_redistribute_unset (redist_type[i].type); |
| 416 | return CMD_SUCCESS; |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 421 | VTY_NEWLINE); |
| 422 | |
| 423 | return CMD_WARNING; |
| 424 | } |
| 425 | |
| 426 | DEFUN (rip_redistribute_type_metric, |
| 427 | rip_redistribute_type_metric_cmd, |
Paul Jakma | 9a57dc6 | 2006-06-30 16:58:53 +0000 | [diff] [blame] | 428 | "redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16>", |
| 429 | REDIST_STR |
| 430 | QUAGGA_REDIST_HELP_STR_RIPD |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 431 | "Metric\n" |
| 432 | "Metric value\n") |
| 433 | { |
| 434 | int i; |
| 435 | int metric; |
| 436 | |
| 437 | metric = atoi (argv[1]); |
| 438 | |
| 439 | for (i = 0; redist_type[i].str; i++) { |
| 440 | if (strncmp(redist_type[i].str, argv[0], |
| 441 | redist_type[i].str_min_len) == 0) |
| 442 | { |
| 443 | rip_redistribute_metric_set (redist_type[i].type, metric); |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 444 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 445 | return CMD_SUCCESS; |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 450 | VTY_NEWLINE); |
| 451 | |
| 452 | return CMD_WARNING; |
| 453 | } |
| 454 | |
| 455 | DEFUN (no_rip_redistribute_type_metric, |
| 456 | no_rip_redistribute_type_metric_cmd, |
Paul Jakma | 9a57dc6 | 2006-06-30 16:58:53 +0000 | [diff] [blame] | 457 | "no redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16>", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 458 | NO_STR |
Paul Jakma | 9a57dc6 | 2006-06-30 16:58:53 +0000 | [diff] [blame] | 459 | REDIST_STR |
| 460 | QUAGGA_REDIST_HELP_STR_RIPD |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 461 | "Metric\n" |
| 462 | "Metric value\n") |
| 463 | { |
| 464 | int i; |
| 465 | |
| 466 | for (i = 0; redist_type[i].str; i++) |
| 467 | { |
| 468 | if (strncmp(redist_type[i].str, argv[0], |
| 469 | redist_type[i].str_min_len) == 0) |
| 470 | { |
| 471 | if (rip_metric_unset (redist_type[i].type, atoi(argv[1]))) |
| 472 | return CMD_WARNING; |
| 473 | rip_redistribute_unset (redist_type[i].type); |
| 474 | return CMD_SUCCESS; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 479 | VTY_NEWLINE); |
| 480 | |
| 481 | return CMD_WARNING; |
| 482 | } |
| 483 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 484 | DEFUN (rip_redistribute_type_metric_routemap, |
| 485 | rip_redistribute_type_metric_routemap_cmd, |
Paul Jakma | 9a57dc6 | 2006-06-30 16:58:53 +0000 | [diff] [blame] | 486 | "redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16> route-map WORD", |
| 487 | REDIST_STR |
| 488 | QUAGGA_REDIST_HELP_STR_RIPD |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 489 | "Metric\n" |
| 490 | "Metric value\n" |
| 491 | "Route map reference\n" |
| 492 | "Pointer to route-map entries\n") |
| 493 | { |
| 494 | int i; |
| 495 | int metric; |
| 496 | |
| 497 | metric = atoi (argv[1]); |
| 498 | |
| 499 | for (i = 0; redist_type[i].str; i++) { |
| 500 | if (strncmp(redist_type[i].str, argv[0], |
| 501 | redist_type[i].str_min_len) == 0) |
| 502 | { |
| 503 | rip_redistribute_metric_set (redist_type[i].type, metric); |
| 504 | rip_routemap_set (redist_type[i].type, argv[2]); |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 505 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type); |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 506 | return CMD_SUCCESS; |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 511 | VTY_NEWLINE); |
| 512 | |
| 513 | return CMD_WARNING; |
| 514 | } |
| 515 | |
| 516 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 517 | DEFUN (no_rip_redistribute_type_metric_routemap, |
| 518 | no_rip_redistribute_type_metric_routemap_cmd, |
Paul Jakma | 9a57dc6 | 2006-06-30 16:58:53 +0000 | [diff] [blame] | 519 | "no redistribute " QUAGGA_REDIST_STR_RIPD |
| 520 | " metric <0-16> route-map WORD", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 521 | NO_STR |
Paul Jakma | 9a57dc6 | 2006-06-30 16:58:53 +0000 | [diff] [blame] | 522 | REDIST_STR |
| 523 | QUAGGA_REDIST_HELP_STR_RIPD |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 524 | "Metric\n" |
| 525 | "Metric value\n" |
| 526 | "Route map reference\n" |
| 527 | "Pointer to route-map entries\n") |
| 528 | { |
| 529 | int i; |
| 530 | |
| 531 | for (i = 0; redist_type[i].str; i++) |
| 532 | { |
| 533 | if (strncmp(redist_type[i].str, argv[0], |
| 534 | redist_type[i].str_min_len) == 0) |
| 535 | { |
| 536 | if (rip_metric_unset (redist_type[i].type, atoi(argv[1]))) |
| 537 | return CMD_WARNING; |
| 538 | if (rip_routemap_unset (redist_type[i].type, argv[2])) |
| 539 | { |
| 540 | rip_redistribute_metric_set(redist_type[i].type, atoi(argv[1])); |
| 541 | return CMD_WARNING; |
| 542 | } |
| 543 | rip_redistribute_unset (redist_type[i].type); |
| 544 | return CMD_SUCCESS; |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 549 | VTY_NEWLINE); |
| 550 | |
| 551 | return CMD_WARNING; |
| 552 | } |
| 553 | |
| 554 | /* Default information originate. */ |
| 555 | |
| 556 | DEFUN (rip_default_information_originate, |
| 557 | rip_default_information_originate_cmd, |
| 558 | "default-information originate", |
| 559 | "Control distribution of default route\n" |
| 560 | "Distribute a default route\n") |
| 561 | { |
| 562 | struct prefix_ipv4 p; |
| 563 | |
| 564 | if (! rip->default_information) |
| 565 | { |
| 566 | memset (&p, 0, sizeof (struct prefix_ipv4)); |
| 567 | p.family = AF_INET; |
| 568 | |
| 569 | rip->default_information = 1; |
| 570 | |
vincent | fbf5d03 | 2005-09-29 11:25:50 +0000 | [diff] [blame] | 571 | rip_redistribute_add (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0, |
| 572 | NULL, 0, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | return CMD_SUCCESS; |
| 576 | } |
| 577 | |
| 578 | DEFUN (no_rip_default_information_originate, |
| 579 | no_rip_default_information_originate_cmd, |
| 580 | "no default-information originate", |
| 581 | NO_STR |
| 582 | "Control distribution of default route\n" |
| 583 | "Distribute a default route\n") |
| 584 | { |
| 585 | struct prefix_ipv4 p; |
| 586 | |
| 587 | if (rip->default_information) |
| 588 | { |
| 589 | memset (&p, 0, sizeof (struct prefix_ipv4)); |
| 590 | p.family = AF_INET; |
| 591 | |
| 592 | rip->default_information = 0; |
| 593 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 594 | rip_redistribute_delete (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | return CMD_SUCCESS; |
| 598 | } |
| 599 | |
| 600 | /* RIP configuration write function. */ |
paul | dc63bfd | 2005-10-25 23:31:05 +0000 | [diff] [blame] | 601 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 602 | config_write_zebra (struct vty *vty) |
| 603 | { |
| 604 | if (! zclient->enable) |
| 605 | { |
| 606 | vty_out (vty, "no router zebra%s", VTY_NEWLINE); |
| 607 | return 1; |
| 608 | } |
| 609 | else if (! zclient->redist[ZEBRA_ROUTE_RIP]) |
| 610 | { |
| 611 | vty_out (vty, "router zebra%s", VTY_NEWLINE); |
| 612 | vty_out (vty, " no redistribute rip%s", VTY_NEWLINE); |
| 613 | return 1; |
| 614 | } |
| 615 | return 0; |
| 616 | } |
| 617 | |
| 618 | int |
| 619 | config_write_rip_redistribute (struct vty *vty, int config_mode) |
| 620 | { |
| 621 | int i; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 622 | |
| 623 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) |
| 624 | if (i != zclient->redist_default && zclient->redist[i]) |
| 625 | { |
| 626 | if (config_mode) |
| 627 | { |
| 628 | if (rip->route_map[i].metric_config) |
| 629 | { |
| 630 | if (rip->route_map[i].name) |
| 631 | vty_out (vty, " redistribute %s metric %d route-map %s%s", |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 632 | zebra_route_string(i), rip->route_map[i].metric, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 633 | rip->route_map[i].name, |
| 634 | VTY_NEWLINE); |
| 635 | else |
| 636 | vty_out (vty, " redistribute %s metric %d%s", |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 637 | zebra_route_string(i), rip->route_map[i].metric, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 638 | VTY_NEWLINE); |
| 639 | } |
| 640 | else |
| 641 | { |
| 642 | if (rip->route_map[i].name) |
| 643 | vty_out (vty, " redistribute %s route-map %s%s", |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 644 | zebra_route_string(i), rip->route_map[i].name, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 645 | VTY_NEWLINE); |
| 646 | else |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 647 | vty_out (vty, " redistribute %s%s", zebra_route_string(i), |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 648 | VTY_NEWLINE); |
| 649 | } |
| 650 | } |
| 651 | else |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame] | 652 | vty_out (vty, " %s", zebra_route_string(i)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 653 | } |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | /* Zebra node structure. */ |
Stephen Hemminger | 7fc626d | 2008-12-01 11:10:34 -0800 | [diff] [blame] | 658 | static struct cmd_node zebra_node = |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 659 | { |
| 660 | ZEBRA_NODE, |
| 661 | "%s(config-router)# ", |
| 662 | }; |
| 663 | |
| 664 | void |
| 665 | rip_zclient_init () |
| 666 | { |
| 667 | /* Set default value to the zebra client structure. */ |
| 668 | zclient = zclient_new (); |
| 669 | zclient_init (zclient, ZEBRA_ROUTE_RIP); |
| 670 | zclient->interface_add = rip_interface_add; |
| 671 | zclient->interface_delete = rip_interface_delete; |
| 672 | zclient->interface_address_add = rip_interface_address_add; |
| 673 | zclient->interface_address_delete = rip_interface_address_delete; |
| 674 | zclient->ipv4_route_add = rip_zebra_read_ipv4; |
| 675 | zclient->ipv4_route_delete = rip_zebra_read_ipv4; |
| 676 | zclient->interface_up = rip_interface_up; |
| 677 | zclient->interface_down = rip_interface_down; |
| 678 | |
| 679 | /* Install zebra node. */ |
| 680 | install_node (&zebra_node, config_write_zebra); |
| 681 | |
| 682 | /* Install command elements to zebra node. */ |
| 683 | install_element (CONFIG_NODE, &router_zebra_cmd); |
| 684 | install_element (CONFIG_NODE, &no_router_zebra_cmd); |
| 685 | install_default (ZEBRA_NODE); |
| 686 | install_element (ZEBRA_NODE, &rip_redistribute_rip_cmd); |
| 687 | install_element (ZEBRA_NODE, &no_rip_redistribute_rip_cmd); |
| 688 | |
| 689 | /* Install command elements to rip node. */ |
| 690 | install_element (RIP_NODE, &rip_redistribute_type_cmd); |
| 691 | install_element (RIP_NODE, &rip_redistribute_type_routemap_cmd); |
| 692 | install_element (RIP_NODE, &rip_redistribute_type_metric_cmd); |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 693 | install_element (RIP_NODE, &rip_redistribute_type_metric_routemap_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 694 | install_element (RIP_NODE, &no_rip_redistribute_type_cmd); |
| 695 | install_element (RIP_NODE, &no_rip_redistribute_type_routemap_cmd); |
| 696 | install_element (RIP_NODE, &no_rip_redistribute_type_metric_cmd); |
| 697 | install_element (RIP_NODE, &no_rip_redistribute_type_metric_routemap_cmd); |
| 698 | install_element (RIP_NODE, &rip_default_information_originate_cmd); |
| 699 | install_element (RIP_NODE, &no_rip_default_information_originate_cmd); |
| 700 | } |