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