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