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