]> git.proxmox.com Git - mirror_frr.git/blame - zebra/router-id.c
zebra: Add missing enums to switch statements
[mirror_frr.git] / zebra / router-id.c
CommitLineData
18a6dce6 1/*
2 * Router ID for zebra daemon.
3 *
d62a17ae 4 * Copyright (C) 2004 James R. Leu
18a6dce6 5 *
6 * This file is part of Quagga routing suite.
7 *
8 * Quagga is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * Quagga is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
896014f4
DL
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18a6dce6 21 */
22
23#include <zebra.h>
24
25#include "if.h"
26#include "vty.h"
27#include "sockunion.h"
28#include "prefix.h"
29#include "stream.h"
30#include "command.h"
31#include "memory.h"
32#include "ioctl.h"
33#include "connected.h"
34#include "network.h"
35#include "log.h"
36#include "table.h"
37#include "rib.h"
c6ffe645 38#include "vrf.h"
18a6dce6 39
161e9ab7 40#include "zebra/zebra_router.h"
bf094f69 41#include "zebra/zapi_msg.h"
7c551956 42#include "zebra/zebra_vrf.h"
a1ac18c4 43#include "zebra/router-id.h"
6dc686a2 44#include "zebra/redistribute.h"
18a6dce6 45
d62a17ae 46static struct connected *router_id_find_node(struct list *l,
47 struct connected *ifc)
18a6dce6 48{
d62a17ae 49 struct listnode *node;
50 struct connected *c;
18a6dce6 51
d62a17ae 52 for (ALL_LIST_ELEMENTS_RO(l, node, c))
53 if (prefix_same(ifc->address, c->address))
54 return c;
1eb8ef25 55
d62a17ae 56 return NULL;
18a6dce6 57}
58
d62a17ae 59static int router_id_bad_address(struct connected *ifc)
18a6dce6 60{
d62a17ae 61 /* non-redistributable addresses shouldn't be used for RIDs either */
62 if (!zebra_check_addr(ifc->address))
63 return 1;
64
65 return 0;
18a6dce6 66}
67
98a3fb0a
SM
68static bool router_id_v6_is_any(struct prefix *p)
69{
70 return memcmp(&p->u.prefix6, &in6addr_any, sizeof(struct in6_addr))
71 == 0;
72}
73
74int router_id_get(afi_t afi, struct prefix *p, struct zebra_vrf *zvrf)
18a6dce6 75{
d62a17ae 76 struct listnode *node;
77 struct connected *c;
98a3fb0a
SM
78 struct in6_addr *addr = NULL;
79
80 switch (afi) {
81 case AFI_IP:
82 p->u.prefix4.s_addr = INADDR_ANY;
83 p->family = AF_INET;
12256b84 84 p->prefixlen = IPV4_MAX_BITLEN;
98a3fb0a
SM
85 if (zvrf->rid_user_assigned.u.prefix4.s_addr != INADDR_ANY)
86 p->u.prefix4.s_addr =
87 zvrf->rid_user_assigned.u.prefix4.s_addr;
88 else if (!list_isempty(zvrf->rid_lo_sorted_list)) {
89 node = listtail(zvrf->rid_lo_sorted_list);
90 c = listgetdata(node);
91 p->u.prefix4.s_addr = c->address->u.prefix4.s_addr;
92 } else if (!list_isempty(zvrf->rid_all_sorted_list)) {
93 node = listtail(zvrf->rid_all_sorted_list);
94 c = listgetdata(node);
95 p->u.prefix4.s_addr = c->address->u.prefix4.s_addr;
96 }
97 return 0;
98 case AFI_IP6:
99 p->u.prefix6 = in6addr_any;
100 p->family = AF_INET6;
13ccce6e 101 p->prefixlen = IPV6_MAX_BITLEN;
98a3fb0a
SM
102 if (!router_id_v6_is_any(&zvrf->rid6_user_assigned))
103 addr = &zvrf->rid6_user_assigned.u.prefix6;
104 else if (!list_isempty(zvrf->rid6_lo_sorted_list)) {
105 node = listtail(zvrf->rid6_lo_sorted_list);
106 c = listgetdata(node);
107 addr = &c->address->u.prefix6;
108 } else if (!list_isempty(zvrf->rid6_all_sorted_list)) {
109 node = listtail(zvrf->rid6_all_sorted_list);
110 c = listgetdata(node);
111 addr = &c->address->u.prefix6;
112 }
113 if (addr)
114 memcpy(&p->u.prefix6, addr, sizeof(struct in6_addr));
115 return 0;
a98701f0
DS
116 case AFI_UNSPEC:
117 case AFI_L2VPN:
118 case AFI_MAX:
98a3fb0a 119 return -1;
d62a17ae 120 }
a98701f0
DS
121
122 assert(!"Reached end of function we should never hit");
18a6dce6 123}
124
98a3fb0a 125static int router_id_set(afi_t afi, struct prefix *p, struct zebra_vrf *zvrf)
18a6dce6 126{
a1f35d7e 127 struct prefix after, before;
d62a17ae 128 struct listnode *node;
129 struct zserv *client;
d62a17ae 130
a1f35d7e
DS
131 router_id_get(afi, &before, zvrf);
132
98a3fb0a
SM
133 switch (afi) {
134 case AFI_IP:
135 zvrf->rid_user_assigned.u.prefix4.s_addr = p->u.prefix4.s_addr;
136 break;
137 case AFI_IP6:
138 zvrf->rid6_user_assigned.u.prefix6 = p->u.prefix6;
139 break;
a98701f0
DS
140 case AFI_UNSPEC:
141 case AFI_L2VPN:
142 case AFI_MAX:
98a3fb0a
SM
143 return -1;
144 }
d62a17ae 145
a1f35d7e
DS
146 router_id_get(afi, &after, zvrf);
147
148 /*
149 * If we've been told that the router-id is exactly the same
150 * do we need to really do anything here?
151 */
152 if (prefix_same(&before, &after))
153 return 0;
d62a17ae 154
161e9ab7 155 for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client))
a1f35d7e 156 zsend_router_id_update(client, afi, &after, zvrf->vrf->vrf_id);
98a3fb0a
SM
157
158 return 0;
18a6dce6 159}
160
d62a17ae 161void router_id_add_address(struct connected *ifc)
18a6dce6 162{
d62a17ae 163 struct list *l = NULL;
164 struct listnode *node;
165 struct prefix before;
166 struct prefix after;
167 struct zserv *client;
096f7609 168 struct zebra_vrf *zvrf = ifc->ifp->vrf->info;
98a3fb0a
SM
169 afi_t afi;
170 struct list *rid_lo;
171 struct list *rid_all;
d62a17ae 172
173 if (router_id_bad_address(ifc))
174 return;
175
98a3fb0a
SM
176 switch (ifc->address->family) {
177 case AF_INET:
178 afi = AFI_IP;
179 rid_lo = zvrf->rid_lo_sorted_list;
180 rid_all = zvrf->rid_all_sorted_list;
181 break;
182 case AF_INET6:
183 afi = AFI_IP6;
184 rid_lo = zvrf->rid6_lo_sorted_list;
185 rid_all = zvrf->rid6_all_sorted_list;
186 break;
187 default:
188 return;
189 }
d62a17ae 190
98a3fb0a
SM
191 router_id_get(afi, &before, zvrf);
192
193 l = if_is_loopback(ifc->ifp) ? rid_lo : rid_all;
d62a17ae 194
195 if (!router_id_find_node(l, ifc))
196 listnode_add_sort(l, ifc);
197
98a3fb0a 198 router_id_get(afi, &after, zvrf);
d62a17ae 199
200 if (prefix_same(&before, &after))
201 return;
202
161e9ab7 203 for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client))
98a3fb0a 204 zsend_router_id_update(client, afi, &after, zvrf_id(zvrf));
18a6dce6 205}
206
d62a17ae 207void router_id_del_address(struct connected *ifc)
18a6dce6 208{
d62a17ae 209 struct connected *c;
210 struct list *l;
211 struct prefix after;
212 struct prefix before;
213 struct listnode *node;
214 struct zserv *client;
096f7609 215 struct zebra_vrf *zvrf = ifc->ifp->vrf->info;
98a3fb0a
SM
216 afi_t afi;
217 struct list *rid_lo;
218 struct list *rid_all;
18a6dce6 219
d62a17ae 220 if (router_id_bad_address(ifc))
221 return;
18a6dce6 222
98a3fb0a
SM
223 switch (ifc->address->family) {
224 case AF_INET:
225 afi = AFI_IP;
226 rid_lo = zvrf->rid_lo_sorted_list;
227 rid_all = zvrf->rid_all_sorted_list;
228 break;
229 case AF_INET6:
230 afi = AFI_IP6;
231 rid_lo = zvrf->rid6_lo_sorted_list;
232 rid_all = zvrf->rid6_all_sorted_list;
233 break;
234 default:
235 return;
236 }
237
238 router_id_get(afi, &before, zvrf);
18a6dce6 239
106935f6 240 if (if_is_loopback(ifc->ifp))
98a3fb0a 241 l = rid_lo;
d62a17ae 242 else
98a3fb0a 243 l = rid_all;
18a6dce6 244
d62a17ae 245 if ((c = router_id_find_node(l, ifc)))
246 listnode_delete(l, c);
18a6dce6 247
98a3fb0a 248 router_id_get(afi, &after, zvrf);
18a6dce6 249
d62a17ae 250 if (prefix_same(&before, &after))
251 return;
18a6dce6 252
161e9ab7 253 for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client))
98a3fb0a 254 zsend_router_id_update(client, afi, &after, zvrf_id(zvrf));
18a6dce6 255}
256
03fba42e 257void router_id_write(struct vty *vty, struct zebra_vrf *zvrf)
18a6dce6 258{
03fba42e
DS
259 char space[2];
260
261 memset(space, 0, sizeof(space));
262
263 if (zvrf_id(zvrf) != VRF_DEFAULT)
264 snprintf(space, sizeof(space), "%s", " ");
d62a17ae 265
03fba42e 266 if (zvrf->rid_user_assigned.u.prefix4.s_addr != INADDR_ANY) {
98a3fb0a
SM
267 vty_out(vty, "%sip router-id %pI4\n", space,
268 &zvrf->rid_user_assigned.u.prefix4);
269 }
270 if (!router_id_v6_is_any(&zvrf->rid6_user_assigned)) {
271 vty_out(vty, "%sipv6 router-id %pI6\n", space,
272 &zvrf->rid_user_assigned.u.prefix6);
03fba42e 273 }
18a6dce6 274}
275
98a3fb0a
SM
276DEFUN (ip_router_id,
277 ip_router_id_cmd,
278 "ip router-id A.B.C.D vrf NAME",
279 IP_STR
18a6dce6 280 "Manually set the router-id\n"
98a3fb0a
SM
281 "IP address to use for router-id\n"
282 VRF_CMD_HELP_STR)
18a6dce6 283{
98a3fb0a
SM
284 int idx = 0;
285 struct prefix rid;
286 vrf_id_t vrf_id;
03fba42e 287 struct zebra_vrf *zvrf;
92300491 288
98a3fb0a 289 argv_find(argv, argc, "A.B.C.D", &idx);
18a6dce6 290
98a3fb0a 291 if (!inet_pton(AF_INET, argv[idx]->arg, &rid.u.prefix4))
d62a17ae 292 return CMD_WARNING_CONFIG_FAILED;
18a6dce6 293
12256b84 294 rid.prefixlen = IPV4_MAX_BITLEN;
d62a17ae 295 rid.family = AF_INET;
18a6dce6 296
98a3fb0a
SM
297 argv_find(argv, argc, "NAME", &idx);
298 VRF_GET_ID(vrf_id, argv[idx]->arg, false);
c6ffe645 299
03fba42e 300 zvrf = vrf_info_lookup(vrf_id);
98a3fb0a 301 router_id_set(AFI_IP, &rid, zvrf);
03fba42e
DS
302
303 return CMD_SUCCESS;
304}
305
98a3fb0a
SM
306ALIAS (ip_router_id,
307 router_id_cmd,
308 "router-id A.B.C.D vrf NAME",
309 "Manually set the router-id\n"
310 "IP address to use for router-id\n"
311 VRF_CMD_HELP_STR);
312
313DEFUN (ipv6_router_id,
314 ipv6_router_id_cmd,
315 "ipv6 router-id X:X::X:X vrf NAME",
316 IPV6_STR
317 "Manually set the router-id\n"
318 "IPv6 address to use for router-id\n"
319 VRF_CMD_HELP_STR)
320{
321 int idx = 0;
322 struct prefix rid;
323 vrf_id_t vrf_id;
324 struct zebra_vrf *zvrf;
325
326 argv_find(argv, argc, "X:X::X:X", &idx);
327
328 if (!inet_pton(AF_INET6, argv[idx]->arg, &rid.u.prefix6))
329 return CMD_WARNING_CONFIG_FAILED;
330
13ccce6e 331 rid.prefixlen = IPV6_MAX_BITLEN;
98a3fb0a
SM
332 rid.family = AF_INET6;
333
334 argv_find(argv, argc, "NAME", &idx);
335 VRF_GET_ID(vrf_id, argv[idx]->arg, false);
336
337 zvrf = vrf_info_lookup(vrf_id);
338 router_id_set(AFI_IP6, &rid, zvrf);
339
340 return CMD_SUCCESS;
341}
342
343
344DEFUN (ip_router_id_in_vrf,
345 ip_router_id_in_vrf_cmd,
346 "ip router-id A.B.C.D",
347 IP_STR
02c671af 348 "Manually set the router-id\n"
03fba42e
DS
349 "IP address to use for router-id\n")
350{
0cbed951 351 ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf);
98a3fb0a 352 int idx = 0;
03fba42e
DS
353 struct prefix rid;
354
98a3fb0a
SM
355 argv_find(argv, argc, "A.B.C.D", &idx);
356
357 if (!inet_pton(AF_INET, argv[idx]->arg, &rid.u.prefix4))
03fba42e
DS
358 return CMD_WARNING_CONFIG_FAILED;
359
12256b84 360 rid.prefixlen = IPV4_MAX_BITLEN;
03fba42e
DS
361 rid.family = AF_INET;
362
98a3fb0a 363 router_id_set(AFI_IP, &rid, zvrf);
18a6dce6 364
d62a17ae 365 return CMD_SUCCESS;
18a6dce6 366}
367
98a3fb0a
SM
368ALIAS (ip_router_id_in_vrf,
369 router_id_in_vrf_cmd,
370 "router-id A.B.C.D",
371 "Manually set the router-id\n"
372 "IP address to use for router-id\n");
373
374DEFUN (ipv6_router_id_in_vrf,
375 ipv6_router_id_in_vrf_cmd,
376 "ipv6 router-id X:X::X:X",
377 IP6_STR
02c671af 378 "Manually set the IPv6 router-id\n"
98a3fb0a
SM
379 "IPV6 address to use for router-id\n")
380{
0cbed951 381 ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf);
98a3fb0a
SM
382 int idx = 0;
383 struct prefix rid;
384
385 argv_find(argv, argc, "X:X::X:X", &idx);
386
387 if (!inet_pton(AF_INET6, argv[idx]->arg, &rid.u.prefix6))
388 return CMD_WARNING_CONFIG_FAILED;
389
13ccce6e 390 rid.prefixlen = IPV6_MAX_BITLEN;
98a3fb0a
SM
391 rid.family = AF_INET6;
392
393 router_id_set(AFI_IP6, &rid, zvrf);
394
395 return CMD_SUCCESS;
396}
397
398DEFUN (no_ip_router_id,
399 no_ip_router_id_cmd,
400 "no ip router-id [A.B.C.D vrf NAME]",
18a6dce6 401 NO_STR
98a3fb0a 402 IP_STR
92300491 403 "Remove the manually configured router-id\n"
98a3fb0a
SM
404 "IP address to use for router-id\n"
405 VRF_CMD_HELP_STR)
18a6dce6 406{
98a3fb0a 407 int idx = 0;
d62a17ae 408 struct prefix rid;
409 vrf_id_t vrf_id = VRF_DEFAULT;
03fba42e 410 struct zebra_vrf *zvrf;
18a6dce6 411
d62a17ae 412 rid.u.prefix4.s_addr = 0;
413 rid.prefixlen = 0;
414 rid.family = AF_INET;
18a6dce6 415
98a3fb0a
SM
416 if (argv_find(argv, argc, "NAME", &idx))
417 VRF_GET_ID(vrf_id, argv[idx]->arg, false);
c6ffe645 418
98a3fb0a
SM
419 zvrf = vrf_info_lookup(vrf_id);
420 router_id_set(AFI_IP, &rid, zvrf);
03fba42e
DS
421
422 return CMD_SUCCESS;
423}
424
98a3fb0a
SM
425ALIAS (no_ip_router_id,
426 no_router_id_cmd,
427 "no router-id [A.B.C.D vrf NAME]",
428 NO_STR
429 "Remove the manually configured router-id\n"
430 "IP address to use for router-id\n"
431 VRF_CMD_HELP_STR);
432
433DEFUN (no_ipv6_router_id,
434 no_ipv6_router_id_cmd,
435 "no ipv6 router-id [X:X::X:X vrf NAME]",
436 NO_STR
437 IPV6_STR
438 "Remove the manually configured IPv6 router-id\n"
439 "IPv6 address to use for router-id\n"
440 VRF_CMD_HELP_STR)
441{
442 int idx = 0;
443 struct prefix rid;
444 vrf_id_t vrf_id = VRF_DEFAULT;
445 struct zebra_vrf *zvrf;
446
447 memset(&rid, 0, sizeof(rid));
448 rid.family = AF_INET;
449
450 if (argv_find(argv, argc, "NAME", &idx))
451 VRF_GET_ID(vrf_id, argv[idx]->arg, false);
452
453 zvrf = vrf_info_lookup(vrf_id);
454 router_id_set(AFI_IP6, &rid, zvrf);
455
456 return CMD_SUCCESS;
457}
458
459DEFUN (no_ip_router_id_in_vrf,
460 no_ip_router_id_in_vrf_cmd,
461 "no ip router-id [A.B.C.D]",
03fba42e 462 NO_STR
98a3fb0a 463 IP_STR
03fba42e
DS
464 "Remove the manually configured router-id\n"
465 "IP address to use for router-id\n")
466{
0cbed951 467 ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf);
03fba42e
DS
468
469 struct prefix rid;
470
471 rid.u.prefix4.s_addr = 0;
472 rid.prefixlen = 0;
473 rid.family = AF_INET;
474
98a3fb0a 475 router_id_set(AFI_IP, &rid, zvrf);
18a6dce6 476
d62a17ae 477 return CMD_SUCCESS;
18a6dce6 478}
479
98a3fb0a
SM
480ALIAS (no_ip_router_id_in_vrf,
481 no_router_id_in_vrf_cmd,
482 "no router-id [A.B.C.D]",
483 NO_STR
484 "Remove the manually configured router-id\n"
485 "IP address to use for router-id\n");
486
487DEFUN (no_ipv6_router_id_in_vrf,
488 no_ipv6_router_id_in_vrf_cmd,
489 "no ipv6 router-id [X:X::X:X]",
490 NO_STR
491 IP6_STR
492 "Remove the manually configured IPv6 router-id\n"
493 "IPv6 address to use for router-id\n")
494{
0cbed951 495 ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf);
98a3fb0a
SM
496
497 struct prefix rid;
498
499 memset(&rid, 0, sizeof(rid));
500 rid.family = AF_INET;
501
502 router_id_set(AFI_IP6, &rid, zvrf);
503
504 return CMD_SUCCESS;
505}
506
507DEFUN (show_ip_router_id,
508 show_ip_router_id_cmd,
509 "show [ip|ipv6] router-id [vrf NAME]",
13b01f2f 510 SHOW_STR
98a3fb0a
SM
511 IP_STR
512 IPV6_STR
13b01f2f
JAG
513 "Show the configured router-id\n"
514 VRF_CMD_HELP_STR)
515{
98a3fb0a
SM
516 int idx = 0;
517 vrf_id_t vrf_id = VRF_DEFAULT;
518 struct zebra_vrf *zvrf;
519 const char *vrf_name = "default";
520 char addr_name[INET6_ADDRSTRLEN];
521 int is_ipv6 = 0;
13b01f2f 522
98a3fb0a 523 is_ipv6 = argv_find(argv, argc, "ipv6", &idx);
13b01f2f 524
98a3fb0a
SM
525 if (argv_find(argv, argc, "NAME", &idx)) {
526 VRF_GET_ID(vrf_id, argv[idx]->arg, false);
527 vrf_name = argv[idx]->arg;
528 }
13b01f2f 529
096f7609 530 zvrf = vrf_info_lookup(vrf_id);
13b01f2f 531
98a3fb0a
SM
532 if (zvrf != NULL) {
533 if (is_ipv6) {
534 if (router_id_v6_is_any(&zvrf->rid6_user_assigned))
535 return CMD_SUCCESS;
536 inet_ntop(AF_INET6, &zvrf->rid6_user_assigned.u.prefix6,
537 addr_name, sizeof(addr_name));
538 } else {
3a6290bd
DA
539 if (zvrf->rid_user_assigned.u.prefix4.s_addr
540 == INADDR_ANY)
98a3fb0a
SM
541 return CMD_SUCCESS;
542 inet_ntop(AF_INET, &zvrf->rid_user_assigned.u.prefix4,
543 addr_name, sizeof(addr_name));
544 }
545
546 vty_out(vty, "zebra:\n");
547 vty_out(vty, " router-id %s vrf %s\n", addr_name, vrf_name);
548 }
13b01f2f 549
98a3fb0a 550 return CMD_SUCCESS;
13b01f2f 551}
813d4307 552
d62a17ae 553static int router_id_cmp(void *a, void *b)
18a6dce6 554{
d62a17ae 555 const struct connected *ifa = (const struct connected *)a;
556 const struct connected *ifb = (const struct connected *)b;
18a6dce6 557
d62a17ae 558 return IPV4_ADDR_CMP(&ifa->address->u.prefix4.s_addr,
559 &ifb->address->u.prefix4.s_addr);
18a6dce6 560}
561
98a3fb0a
SM
562static int router_id_v6_cmp(void *a, void *b)
563{
564 const struct connected *ifa = (const struct connected *)a;
565 const struct connected *ifb = (const struct connected *)b;
566
567 return IPV6_ADDR_CMP(&ifa->address->u.prefix6,
568 &ifb->address->u.prefix6);
569}
570
d62a17ae 571void router_id_cmd_init(void)
18a6dce6 572{
98a3fb0a 573 install_element(CONFIG_NODE, &ip_router_id_cmd);
d62a17ae 574 install_element(CONFIG_NODE, &router_id_cmd);
98a3fb0a
SM
575 install_element(CONFIG_NODE, &ipv6_router_id_cmd);
576 install_element(CONFIG_NODE, &no_ip_router_id_cmd);
d62a17ae 577 install_element(CONFIG_NODE, &no_router_id_cmd);
98a3fb0a
SM
578 install_element(CONFIG_NODE, &ip_router_id_in_vrf_cmd);
579 install_element(VRF_NODE, &ip_router_id_in_vrf_cmd);
03fba42e
DS
580 install_element(CONFIG_NODE, &router_id_in_vrf_cmd);
581 install_element(VRF_NODE, &router_id_in_vrf_cmd);
98a3fb0a
SM
582 install_element(CONFIG_NODE, &ipv6_router_id_in_vrf_cmd);
583 install_element(VRF_NODE, &ipv6_router_id_in_vrf_cmd);
584 install_element(CONFIG_NODE, &no_ipv6_router_id_cmd);
585 install_element(CONFIG_NODE, &no_ip_router_id_in_vrf_cmd);
586 install_element(VRF_NODE, &no_ip_router_id_in_vrf_cmd);
03fba42e
DS
587 install_element(CONFIG_NODE, &no_router_id_in_vrf_cmd);
588 install_element(VRF_NODE, &no_router_id_in_vrf_cmd);
98a3fb0a
SM
589 install_element(CONFIG_NODE, &no_ipv6_router_id_in_vrf_cmd);
590 install_element(VRF_NODE, &no_ipv6_router_id_in_vrf_cmd);
591 install_element(VIEW_NODE, &show_ip_router_id_cmd);
c6ffe645
FL
592}
593
d62a17ae 594void router_id_init(struct zebra_vrf *zvrf)
c6ffe645 595{
d62a17ae 596 zvrf->rid_all_sorted_list = &zvrf->_rid_all_sorted_list;
597 zvrf->rid_lo_sorted_list = &zvrf->_rid_lo_sorted_list;
98a3fb0a
SM
598 zvrf->rid6_all_sorted_list = &zvrf->_rid6_all_sorted_list;
599 zvrf->rid6_lo_sorted_list = &zvrf->_rid6_lo_sorted_list;
18a6dce6 600
d62a17ae 601 memset(zvrf->rid_all_sorted_list, 0,
602 sizeof(zvrf->_rid_all_sorted_list));
603 memset(zvrf->rid_lo_sorted_list, 0, sizeof(zvrf->_rid_lo_sorted_list));
604 memset(&zvrf->rid_user_assigned, 0, sizeof(zvrf->rid_user_assigned));
98a3fb0a
SM
605 memset(zvrf->rid6_all_sorted_list, 0,
606 sizeof(zvrf->_rid6_all_sorted_list));
607 memset(zvrf->rid6_lo_sorted_list, 0,
608 sizeof(zvrf->_rid6_lo_sorted_list));
609 memset(&zvrf->rid6_user_assigned, 0, sizeof(zvrf->rid6_user_assigned));
18a6dce6 610
d62a17ae 611 zvrf->rid_all_sorted_list->cmp = router_id_cmp;
612 zvrf->rid_lo_sorted_list->cmp = router_id_cmp;
98a3fb0a
SM
613 zvrf->rid6_all_sorted_list->cmp = router_id_v6_cmp;
614 zvrf->rid6_lo_sorted_list->cmp = router_id_v6_cmp;
18a6dce6 615
d62a17ae 616 zvrf->rid_user_assigned.family = AF_INET;
12256b84 617 zvrf->rid_user_assigned.prefixlen = IPV4_MAX_BITLEN;
98a3fb0a 618 zvrf->rid6_user_assigned.family = AF_INET6;
13ccce6e 619 zvrf->rid6_user_assigned.prefixlen = IPV6_MAX_BITLEN;
18a6dce6 620}