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