back to topotato report
topotato coverage report
Current view: top level - zebra - router-id.c (source / functions) Hit Total Coverage
Test: test_bgp_set_aspath_replace.py::BGPSetAspathReplace Lines: 147 292 50.3 %
Date: 2023-02-24 18:37:49 Functions: 8 19 42.1 %

          Line data    Source code
       1             : /*
       2             :  * Router ID for zebra daemon.
       3             :  *
       4             :  * Copyright (C) 2004 James R. Leu
       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             :  *
      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
      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"
      38             : #include "vrf.h"
      39             : 
      40             : #include "zebra/zebra_router.h"
      41             : #include "zebra/zapi_msg.h"
      42             : #include "zebra/zebra_vrf.h"
      43             : #include "zebra/router-id.h"
      44             : #include "zebra/redistribute.h"
      45             : 
      46          37 : static struct connected *router_id_find_node(struct list *l,
      47             :                                              struct connected *ifc)
      48             : {
      49          37 :         struct listnode *node;
      50          37 :         struct connected *c;
      51             : 
      52          85 :         for (ALL_LIST_ELEMENTS_RO(l, node, c))
      53          21 :                 if (prefix_same(ifc->address, c->address))
      54          10 :                         return c;
      55             : 
      56             :         return NULL;
      57             : }
      58             : 
      59          42 : static int router_id_bad_address(struct connected *ifc)
      60             : {
      61             :         /* non-redistributable addresses shouldn't be used for RIDs either */
      62          42 :         if (!zebra_check_addr(ifc->address))
      63             :                 return 1;
      64             : 
      65             :         return 0;
      66             : }
      67             : 
      68          36 : static bool router_id_v6_is_any(struct prefix *p)
      69             : {
      70          36 :         return memcmp(&p->u.prefix6, &in6addr_any, sizeof(struct in6_addr))
      71             :                == 0;
      72             : }
      73             : 
      74          77 : int router_id_get(afi_t afi, struct prefix *p, struct zebra_vrf *zvrf)
      75             : {
      76          77 :         struct listnode *node;
      77          77 :         struct connected *c;
      78          77 :         struct in6_addr *addr = NULL;
      79             : 
      80          77 :         switch (afi) {
      81          41 :         case AFI_IP:
      82          41 :                 p->u.prefix4.s_addr = INADDR_ANY;
      83          41 :                 p->family = AF_INET;
      84          41 :                 p->prefixlen = IPV4_MAX_BITLEN;
      85          41 :                 if (zvrf->rid_user_assigned.u.prefix4.s_addr != INADDR_ANY)
      86           0 :                         p->u.prefix4.s_addr =
      87             :                                 zvrf->rid_user_assigned.u.prefix4.s_addr;
      88          41 :                 else if (!list_isempty(zvrf->rid_lo_sorted_list)) {
      89          38 :                         node = listtail(zvrf->rid_lo_sorted_list);
      90          38 :                         c = listgetdata(node);
      91          38 :                         p->u.prefix4.s_addr = c->address->u.prefix4.s_addr;
      92           3 :                 } else if (!list_isempty(zvrf->rid_all_sorted_list)) {
      93           0 :                         node = listtail(zvrf->rid_all_sorted_list);
      94           0 :                         c = listgetdata(node);
      95           0 :                         p->u.prefix4.s_addr = c->address->u.prefix4.s_addr;
      96             :                 }
      97             :                 return 0;
      98          36 :         case AFI_IP6:
      99          36 :                 p->u.prefix6 = in6addr_any;
     100          36 :                 p->family = AF_INET6;
     101          36 :                 p->prefixlen = IPV6_MAX_BITLEN;
     102          36 :                 if (!router_id_v6_is_any(&zvrf->rid6_user_assigned))
     103             :                         addr = &zvrf->rid6_user_assigned.u.prefix6;
     104          36 :                 else if (!list_isempty(zvrf->rid6_lo_sorted_list)) {
     105          33 :                         node = listtail(zvrf->rid6_lo_sorted_list);
     106          33 :                         c = listgetdata(node);
     107          33 :                         addr = &c->address->u.prefix6;
     108           3 :                 } else if (!list_isempty(zvrf->rid6_all_sorted_list)) {
     109           0 :                         node = listtail(zvrf->rid6_all_sorted_list);
     110           0 :                         c = listgetdata(node);
     111           0 :                         addr = &c->address->u.prefix6;
     112             :                 }
     113          33 :                 if (addr)
     114          33 :                         memcpy(&p->u.prefix6, addr, sizeof(struct in6_addr));
     115             :                 return 0;
     116             :         case AFI_UNSPEC:
     117             :         case AFI_L2VPN:
     118             :         case AFI_MAX:
     119             :                 return -1;
     120             :         }
     121             : 
     122           0 :         assert(!"Reached end of function we should never hit");
     123             : }
     124             : 
     125           0 : static int router_id_set(afi_t afi, struct prefix *p, struct zebra_vrf *zvrf)
     126             : {
     127           0 :         struct prefix after, before;
     128           0 :         struct listnode *node;
     129           0 :         struct zserv *client;
     130             : 
     131           0 :         router_id_get(afi, &before, zvrf);
     132             : 
     133           0 :         switch (afi) {
     134           0 :         case AFI_IP:
     135           0 :                 zvrf->rid_user_assigned.u.prefix4.s_addr = p->u.prefix4.s_addr;
     136           0 :                 break;
     137           0 :         case AFI_IP6:
     138           0 :                 zvrf->rid6_user_assigned.u.prefix6 = p->u.prefix6;
     139           0 :                 break;
     140             :         case AFI_UNSPEC:
     141             :         case AFI_L2VPN:
     142             :         case AFI_MAX:
     143             :                 return -1;
     144             :         }
     145             : 
     146           0 :         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           0 :         if (prefix_same(&before, &after))
     153             :                 return 0;
     154             : 
     155           0 :         for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client))
     156           0 :                 zsend_router_id_update(client, afi, &after, zvrf->vrf->vrf_id);
     157             : 
     158             :         return 0;
     159             : }
     160             : 
     161          32 : void router_id_add_address(struct connected *ifc)
     162             : {
     163          32 :         struct list *l = NULL;
     164          32 :         struct listnode *node;
     165          32 :         struct prefix before;
     166          32 :         struct prefix after;
     167          32 :         struct zserv *client;
     168          32 :         struct zebra_vrf *zvrf = ifc->ifp->vrf->info;
     169          32 :         afi_t afi;
     170          32 :         struct list *rid_lo;
     171          32 :         struct list *rid_all;
     172             : 
     173          32 :         if (router_id_bad_address(ifc))
     174          25 :                 return;
     175             : 
     176          27 :         switch (ifc->address->family) {
     177          14 :         case AF_INET:
     178          14 :                 afi = AFI_IP;
     179          14 :                 rid_lo = zvrf->rid_lo_sorted_list;
     180          14 :                 rid_all = zvrf->rid_all_sorted_list;
     181          14 :                 break;
     182          13 :         case AF_INET6:
     183          13 :                 afi = AFI_IP6;
     184          13 :                 rid_lo = zvrf->rid6_lo_sorted_list;
     185          13 :                 rid_all = zvrf->rid6_all_sorted_list;
     186          13 :                 break;
     187             :         default:
     188             :                 return;
     189             :         }
     190             : 
     191          27 :         router_id_get(afi, &before, zvrf);
     192             : 
     193          27 :         l = if_is_loopback(ifc->ifp) ? rid_lo : rid_all;
     194             : 
     195          27 :         if (!router_id_find_node(l, ifc))
     196          27 :                 listnode_add_sort(l, ifc);
     197             : 
     198          27 :         router_id_get(afi, &after, zvrf);
     199             : 
     200          27 :         if (prefix_same(&before, &after))
     201             :                 return;
     202             : 
     203          14 :         for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client))
     204           0 :                 zsend_router_id_update(client, afi, &after, zvrf_id(zvrf));
     205             : }
     206             : 
     207          10 : void router_id_del_address(struct connected *ifc)
     208             : {
     209          10 :         struct connected *c;
     210          10 :         struct list *l;
     211          10 :         struct prefix after;
     212          10 :         struct prefix before;
     213          10 :         struct listnode *node;
     214          10 :         struct zserv *client;
     215          10 :         struct zebra_vrf *zvrf = ifc->ifp->vrf->info;
     216          10 :         afi_t afi;
     217          10 :         struct list *rid_lo;
     218          10 :         struct list *rid_all;
     219             : 
     220          10 :         if (router_id_bad_address(ifc))
     221          10 :                 return;
     222             : 
     223          10 :         switch (ifc->address->family) {
     224           5 :         case AF_INET:
     225           5 :                 afi = AFI_IP;
     226           5 :                 rid_lo = zvrf->rid_lo_sorted_list;
     227           5 :                 rid_all = zvrf->rid_all_sorted_list;
     228           5 :                 break;
     229           5 :         case AF_INET6:
     230           5 :                 afi = AFI_IP6;
     231           5 :                 rid_lo = zvrf->rid6_lo_sorted_list;
     232           5 :                 rid_all = zvrf->rid6_all_sorted_list;
     233           5 :                 break;
     234             :         default:
     235             :                 return;
     236             :         }
     237             : 
     238          10 :         router_id_get(afi, &before, zvrf);
     239             : 
     240          10 :         if (if_is_loopback(ifc->ifp))
     241             :                 l = rid_lo;
     242             :         else
     243          10 :                 l = rid_all;
     244             : 
     245          10 :         if ((c = router_id_find_node(l, ifc)))
     246          10 :                 listnode_delete(l, c);
     247             : 
     248          10 :         router_id_get(afi, &after, zvrf);
     249             : 
     250          10 :         if (prefix_same(&before, &after))
     251             :                 return;
     252             : 
     253           0 :         for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, node, client))
     254           0 :                 zsend_router_id_update(client, afi, &after, zvrf_id(zvrf));
     255             : }
     256             : 
     257           0 : void router_id_write(struct vty *vty, struct zebra_vrf *zvrf)
     258             : {
     259           0 :         char space[2];
     260             : 
     261           0 :         memset(space, 0, sizeof(space));
     262             : 
     263           0 :         if (zvrf_id(zvrf) != VRF_DEFAULT)
     264           0 :                 snprintf(space, sizeof(space), "%s", " ");
     265             : 
     266           0 :         if (zvrf->rid_user_assigned.u.prefix4.s_addr != INADDR_ANY) {
     267           0 :                 vty_out(vty, "%sip router-id %pI4\n", space,
     268             :                         &zvrf->rid_user_assigned.u.prefix4);
     269             :         }
     270           0 :         if (!router_id_v6_is_any(&zvrf->rid6_user_assigned)) {
     271           0 :                 vty_out(vty, "%sipv6 router-id %pI6\n", space,
     272             :                         &zvrf->rid_user_assigned.u.prefix6);
     273             :         }
     274           0 : }
     275             : 
     276           0 : DEFUN (ip_router_id,
     277             :        ip_router_id_cmd,
     278             :        "ip router-id A.B.C.D vrf NAME",
     279             :        IP_STR
     280             :        "Manually set the router-id\n"
     281             :        "IP address to use for router-id\n"
     282             :        VRF_CMD_HELP_STR)
     283             : {
     284           0 :         int idx = 0;
     285           0 :         struct prefix rid;
     286           0 :         vrf_id_t vrf_id;
     287           0 :         struct zebra_vrf *zvrf;
     288             : 
     289           0 :         argv_find(argv, argc, "A.B.C.D", &idx);
     290             : 
     291           0 :         if (!inet_pton(AF_INET, argv[idx]->arg, &rid.u.prefix4))
     292             :                 return CMD_WARNING_CONFIG_FAILED;
     293             : 
     294           0 :         rid.prefixlen = IPV4_MAX_BITLEN;
     295           0 :         rid.family = AF_INET;
     296             : 
     297           0 :         argv_find(argv, argc, "NAME", &idx);
     298           0 :         VRF_GET_ID(vrf_id, argv[idx]->arg, false);
     299             : 
     300           0 :         zvrf = vrf_info_lookup(vrf_id);
     301           0 :         router_id_set(AFI_IP, &rid, zvrf);
     302             : 
     303           0 :         return CMD_SUCCESS;
     304             : }
     305             : 
     306             : ALIAS (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             : 
     313           0 : DEFUN (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           0 :         int idx = 0;
     322           0 :         struct prefix rid;
     323           0 :         vrf_id_t vrf_id;
     324           0 :         struct zebra_vrf *zvrf;
     325             : 
     326           0 :         argv_find(argv, argc, "X:X::X:X", &idx);
     327             : 
     328           0 :         if (!inet_pton(AF_INET6, argv[idx]->arg, &rid.u.prefix6))
     329             :                 return CMD_WARNING_CONFIG_FAILED;
     330             : 
     331           0 :         rid.prefixlen = IPV6_MAX_BITLEN;
     332           0 :         rid.family = AF_INET6;
     333             : 
     334           0 :         argv_find(argv, argc, "NAME", &idx);
     335           0 :         VRF_GET_ID(vrf_id, argv[idx]->arg, false);
     336             : 
     337           0 :         zvrf = vrf_info_lookup(vrf_id);
     338           0 :         router_id_set(AFI_IP6, &rid, zvrf);
     339             : 
     340           0 :         return CMD_SUCCESS;
     341             : }
     342             : 
     343             : 
     344           0 : DEFUN (ip_router_id_in_vrf,
     345             :        ip_router_id_in_vrf_cmd,
     346             :        "ip router-id A.B.C.D",
     347             :        IP_STR
     348             :        "Manually set the router-id\n"
     349             :        "IP address to use for router-id\n")
     350             : {
     351           0 :         ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf);
     352           0 :         int idx = 0;
     353           0 :         struct prefix rid;
     354             : 
     355           0 :         argv_find(argv, argc, "A.B.C.D", &idx);
     356             : 
     357           0 :         if (!inet_pton(AF_INET, argv[idx]->arg, &rid.u.prefix4))
     358             :                 return CMD_WARNING_CONFIG_FAILED;
     359             : 
     360           0 :         rid.prefixlen = IPV4_MAX_BITLEN;
     361           0 :         rid.family = AF_INET;
     362             : 
     363           0 :         router_id_set(AFI_IP, &rid, zvrf);
     364             : 
     365           0 :         return CMD_SUCCESS;
     366             : }
     367             : 
     368             : ALIAS (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             : 
     374           0 : DEFUN (ipv6_router_id_in_vrf,
     375             :        ipv6_router_id_in_vrf_cmd,
     376             :        "ipv6 router-id X:X::X:X",
     377             :        IP6_STR
     378             :        "Manually set the IPv6 router-id\n"
     379             :        "IPV6 address to use for router-id\n")
     380             : {
     381           0 :         ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf);
     382           0 :         int idx = 0;
     383           0 :         struct prefix rid;
     384             : 
     385           0 :         argv_find(argv, argc, "X:X::X:X", &idx);
     386             : 
     387           0 :         if (!inet_pton(AF_INET6, argv[idx]->arg, &rid.u.prefix6))
     388             :                 return CMD_WARNING_CONFIG_FAILED;
     389             : 
     390           0 :         rid.prefixlen = IPV6_MAX_BITLEN;
     391           0 :         rid.family = AF_INET6;
     392             : 
     393           0 :         router_id_set(AFI_IP6, &rid, zvrf);
     394             : 
     395           0 :         return CMD_SUCCESS;
     396             : }
     397             : 
     398           0 : DEFUN (no_ip_router_id,
     399             :        no_ip_router_id_cmd,
     400             :        "no ip router-id [A.B.C.D vrf NAME]",
     401             :        NO_STR
     402             :        IP_STR
     403             :        "Remove the manually configured router-id\n"
     404             :        "IP address to use for router-id\n"
     405             :        VRF_CMD_HELP_STR)
     406             : {
     407           0 :         int idx = 0;
     408           0 :         struct prefix rid;
     409           0 :         vrf_id_t vrf_id = VRF_DEFAULT;
     410           0 :         struct zebra_vrf *zvrf;
     411             : 
     412           0 :         rid.u.prefix4.s_addr = 0;
     413           0 :         rid.prefixlen = 0;
     414           0 :         rid.family = AF_INET;
     415             : 
     416           0 :         if (argv_find(argv, argc, "NAME", &idx))
     417           0 :                 VRF_GET_ID(vrf_id, argv[idx]->arg, false);
     418             : 
     419           0 :         zvrf = vrf_info_lookup(vrf_id);
     420           0 :         router_id_set(AFI_IP, &rid, zvrf);
     421             : 
     422           0 :         return CMD_SUCCESS;
     423             : }
     424             : 
     425             : ALIAS (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             : 
     433           0 : DEFUN (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           0 :         int idx = 0;
     443           0 :         struct prefix rid;
     444           0 :         vrf_id_t vrf_id = VRF_DEFAULT;
     445           0 :         struct zebra_vrf *zvrf;
     446             : 
     447           0 :         memset(&rid, 0, sizeof(rid));
     448           0 :         rid.family = AF_INET;
     449             : 
     450           0 :         if (argv_find(argv, argc, "NAME", &idx))
     451           0 :                 VRF_GET_ID(vrf_id, argv[idx]->arg, false);
     452             : 
     453           0 :         zvrf = vrf_info_lookup(vrf_id);
     454           0 :         router_id_set(AFI_IP6, &rid, zvrf);
     455             : 
     456           0 :         return CMD_SUCCESS;
     457             : }
     458             : 
     459           0 : DEFUN (no_ip_router_id_in_vrf,
     460             :        no_ip_router_id_in_vrf_cmd,
     461             :        "no ip router-id [A.B.C.D]",
     462             :        NO_STR
     463             :        IP_STR
     464             :        "Remove the manually configured router-id\n"
     465             :        "IP address to use for router-id\n")
     466             : {
     467           0 :         ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf);
     468             : 
     469           0 :         struct prefix rid;
     470             : 
     471           0 :         rid.u.prefix4.s_addr = 0;
     472           0 :         rid.prefixlen = 0;
     473           0 :         rid.family = AF_INET;
     474             : 
     475           0 :         router_id_set(AFI_IP, &rid, zvrf);
     476             : 
     477           0 :         return CMD_SUCCESS;
     478             : }
     479             : 
     480             : ALIAS (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             : 
     487           0 : DEFUN (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             : {
     495           0 :         ZEBRA_DECLVAR_CONTEXT_VRF(vrf, zvrf);
     496             : 
     497           0 :         struct prefix rid;
     498             : 
     499           0 :         memset(&rid, 0, sizeof(rid));
     500           0 :         rid.family = AF_INET;
     501             : 
     502           0 :         router_id_set(AFI_IP6, &rid, zvrf);
     503             : 
     504           0 :         return CMD_SUCCESS;
     505             : }
     506             : 
     507           0 : DEFUN (show_ip_router_id,
     508             :        show_ip_router_id_cmd,
     509             :        "show [ip|ipv6] router-id [vrf NAME]",
     510             :        SHOW_STR
     511             :        IP_STR
     512             :        IPV6_STR
     513             :        "Show the configured router-id\n"
     514             :        VRF_CMD_HELP_STR)
     515             : {
     516           0 :         int idx = 0;
     517           0 :         vrf_id_t vrf_id = VRF_DEFAULT;
     518           0 :         struct zebra_vrf *zvrf;
     519           0 :         const char *vrf_name = "default";
     520           0 :         char addr_name[INET6_ADDRSTRLEN];
     521           0 :         int is_ipv6 = 0;
     522             : 
     523           0 :         is_ipv6 = argv_find(argv, argc, "ipv6", &idx);
     524             : 
     525           0 :         if (argv_find(argv, argc, "NAME", &idx)) {
     526           0 :                 VRF_GET_ID(vrf_id, argv[idx]->arg, false);
     527           0 :                 vrf_name = argv[idx]->arg;
     528             :         }
     529             : 
     530           0 :         zvrf = vrf_info_lookup(vrf_id);
     531             : 
     532           0 :         if (zvrf != NULL) {
     533           0 :                 if (is_ipv6) {
     534           0 :                         if (router_id_v6_is_any(&zvrf->rid6_user_assigned))
     535             :                                 return CMD_SUCCESS;
     536           0 :                         inet_ntop(AF_INET6, &zvrf->rid6_user_assigned.u.prefix6,
     537             :                                   addr_name, sizeof(addr_name));
     538             :                 } else {
     539           0 :                         if (zvrf->rid_user_assigned.u.prefix4.s_addr
     540             :                             == INADDR_ANY)
     541             :                                 return CMD_SUCCESS;
     542           0 :                         inet_ntop(AF_INET, &zvrf->rid_user_assigned.u.prefix4,
     543             :                                   addr_name, sizeof(addr_name));
     544             :                 }
     545             : 
     546           0 :                 vty_out(vty, "zebra:\n");
     547           0 :                 vty_out(vty, "     router-id %s vrf %s\n", addr_name, vrf_name);
     548             :         }
     549             : 
     550             :         return CMD_SUCCESS;
     551             : }
     552             : 
     553           5 : static int router_id_cmp(void *a, void *b)
     554             : {
     555           5 :         const struct connected *ifa = (const struct connected *)a;
     556           5 :         const struct connected *ifb = (const struct connected *)b;
     557             : 
     558           5 :         return IPV4_ADDR_CMP(&ifa->address->u.prefix4.s_addr,
     559             :                              &ifb->address->u.prefix4.s_addr);
     560             : }
     561             : 
     562           4 : static int router_id_v6_cmp(void *a, void *b)
     563             : {
     564           4 :         const struct connected *ifa = (const struct connected *)a;
     565           4 :         const struct connected *ifb = (const struct connected *)b;
     566             : 
     567           4 :         return IPV6_ADDR_CMP(&ifa->address->u.prefix6,
     568             :                              &ifb->address->u.prefix6);
     569             : }
     570             : 
     571           3 : void router_id_cmd_init(void)
     572             : {
     573           3 :         install_element(CONFIG_NODE, &ip_router_id_cmd);
     574           3 :         install_element(CONFIG_NODE, &router_id_cmd);
     575           3 :         install_element(CONFIG_NODE, &ipv6_router_id_cmd);
     576           3 :         install_element(CONFIG_NODE, &no_ip_router_id_cmd);
     577           3 :         install_element(CONFIG_NODE, &no_router_id_cmd);
     578           3 :         install_element(CONFIG_NODE, &ip_router_id_in_vrf_cmd);
     579           3 :         install_element(VRF_NODE, &ip_router_id_in_vrf_cmd);
     580           3 :         install_element(CONFIG_NODE, &router_id_in_vrf_cmd);
     581           3 :         install_element(VRF_NODE, &router_id_in_vrf_cmd);
     582           3 :         install_element(CONFIG_NODE, &ipv6_router_id_in_vrf_cmd);
     583           3 :         install_element(VRF_NODE, &ipv6_router_id_in_vrf_cmd);
     584           3 :         install_element(CONFIG_NODE, &no_ipv6_router_id_cmd);
     585           3 :         install_element(CONFIG_NODE, &no_ip_router_id_in_vrf_cmd);
     586           3 :         install_element(VRF_NODE, &no_ip_router_id_in_vrf_cmd);
     587           3 :         install_element(CONFIG_NODE, &no_router_id_in_vrf_cmd);
     588           3 :         install_element(VRF_NODE, &no_router_id_in_vrf_cmd);
     589           3 :         install_element(CONFIG_NODE, &no_ipv6_router_id_in_vrf_cmd);
     590           3 :         install_element(VRF_NODE, &no_ipv6_router_id_in_vrf_cmd);
     591           3 :         install_element(VIEW_NODE, &show_ip_router_id_cmd);
     592           3 : }
     593             : 
     594           3 : void router_id_init(struct zebra_vrf *zvrf)
     595             : {
     596           3 :         zvrf->rid_all_sorted_list = &zvrf->_rid_all_sorted_list;
     597           3 :         zvrf->rid_lo_sorted_list = &zvrf->_rid_lo_sorted_list;
     598           3 :         zvrf->rid6_all_sorted_list = &zvrf->_rid6_all_sorted_list;
     599           3 :         zvrf->rid6_lo_sorted_list = &zvrf->_rid6_lo_sorted_list;
     600             : 
     601           3 :         memset(zvrf->rid_all_sorted_list, 0,
     602             :                sizeof(zvrf->_rid_all_sorted_list));
     603           3 :         memset(zvrf->rid_lo_sorted_list, 0, sizeof(zvrf->_rid_lo_sorted_list));
     604           3 :         memset(&zvrf->rid_user_assigned, 0, sizeof(zvrf->rid_user_assigned));
     605           3 :         memset(zvrf->rid6_all_sorted_list, 0,
     606             :                sizeof(zvrf->_rid6_all_sorted_list));
     607           3 :         memset(zvrf->rid6_lo_sorted_list, 0,
     608             :                sizeof(zvrf->_rid6_lo_sorted_list));
     609           3 :         memset(&zvrf->rid6_user_assigned, 0, sizeof(zvrf->rid6_user_assigned));
     610             : 
     611           3 :         zvrf->rid_all_sorted_list->cmp = router_id_cmp;
     612           3 :         zvrf->rid_lo_sorted_list->cmp = router_id_cmp;
     613           3 :         zvrf->rid6_all_sorted_list->cmp = router_id_v6_cmp;
     614           3 :         zvrf->rid6_lo_sorted_list->cmp = router_id_v6_cmp;
     615             : 
     616           3 :         zvrf->rid_user_assigned.family = AF_INET;
     617           3 :         zvrf->rid_user_assigned.prefixlen = IPV4_MAX_BITLEN;
     618           3 :         zvrf->rid6_user_assigned.family = AF_INET6;
     619           3 :         zvrf->rid6_user_assigned.prefixlen = IPV6_MAX_BITLEN;
     620           3 : }

Generated by: LCOV version v1.16-topotato