]> git.proxmox.com Git - mirror_frr.git/commitdiff
*: unify if_is_loopback/if_is_loopback_or_vrf
authorIgor Ryzhov <iryzhov@nfware.com>
Tue, 16 Nov 2021 15:01:03 +0000 (18:01 +0300)
committerIgor Ryzhov <iryzhov@nfware.com>
Tue, 16 Nov 2021 15:07:11 +0000 (18:07 +0300)
We should always treat the VRF interface as a loopback. Currently, this
is not the case, because in some old pre-VRF code we use if_is_loopback
instead of if_is_loopback_or_vrf. To avoid any future problems, the
proposal is to rename if_is_loopback_or_vrf to if_is_loopback and use it
everywhere. if_is_loopback is renamed to if_is_loopback_exact in case
it's ever needed, but currently it's not used anywhere.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
13 files changed:
bgpd/bgp_zebra.c
isisd/isis_circuit.c
lib/if.c
lib/if.h
ospf6d/ospf6_interface.c
ospfd/ospf_interface.c
pimd/pim_jp_agg.c
pimd/pim_pim.c
pimd/pim_vxlan.c
pimd/pim_vxlan.h
zebra/connected.c
zebra/rtadv.c
zebra/zebra_rib.c

index a98168d4649449f5ebd1a00fb07c42997e2b61a4..bedd480c161f0c805850dd63515efc3d515f6e4b 100644 (file)
@@ -875,7 +875,7 @@ bool bgp_zebra_nexthop_set(union sockunion *local, union sockunion *remote,
                         * It's fine to not have a v6 LL when using
                         * update-source loopback/vrf
                         */
-                       if (!v6_ll_avail && if_is_loopback_or_vrf(ifp))
+                       if (!v6_ll_avail && if_is_loopback(ifp))
                                v6_ll_avail = true;
                } else
                /* Link-local address. */
index 8810d6107d77cbfb6086e9fce59a389fe2c472f5..59212db3eb549d95bd04bc4f81addfabe0fed511 100644 (file)
@@ -505,7 +505,7 @@ void isis_circuit_if_add(struct isis_circuit *circuit, struct interface *ifp)
                        circuit->circ_type = CIRCUIT_T_BROADCAST;
        } else if (if_is_pointopoint(ifp)) {
                circuit->circ_type = CIRCUIT_T_P2P;
-       } else if (if_is_loopback_or_vrf(ifp)) {
+       } else if (if_is_loopback(ifp)) {
                circuit->circ_type = CIRCUIT_T_LOOPBACK;
                circuit->is_passive = 1;
        } else {
@@ -1332,7 +1332,7 @@ ferr_r isis_circuit_passive_set(struct isis_circuit *circuit, bool passive)
        if (circuit->is_passive == passive)
                return ferr_ok();
 
-       if (if_is_loopback_or_vrf(circuit->interface) && !passive)
+       if (if_is_loopback(circuit->interface) && !passive)
                return ferr_cfg_invalid("loopback is always passive");
 
        if (circuit->state != C_STATE_UP) {
index a40f04f5a250230c4c49ff46cd1aabbf91906afb..268dc7454b8bef3f3dffb2c76d28dee9ad8831d9 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -698,7 +698,7 @@ int if_is_no_ptm_operative(const struct interface *ifp)
 }
 
 /* Is this loopback interface ? */
-int if_is_loopback(const struct interface *ifp)
+int if_is_loopback_exact(const struct interface *ifp)
 {
        /* XXX: Do this better, eg what if IFF_WHATEVER means X on platform M
         * but Y on platform N?
@@ -712,9 +712,10 @@ int if_is_vrf(const struct interface *ifp)
        return CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_VRF_LOOPBACK);
 }
 
-bool if_is_loopback_or_vrf(const struct interface *ifp)
+/* Should this interface be treated as a loopback? */
+bool if_is_loopback(const struct interface *ifp)
 {
-       if (if_is_loopback(ifp) || if_is_vrf(ifp))
+       if (if_is_loopback_exact(ifp) || if_is_vrf(ifp))
                return true;
 
        return false;
index 1012bf5557ea22eb56b3dc40a2b988516feeaa12..2a3ef0680ef033b7dee07d544da546286ec59991 100644 (file)
--- a/lib/if.h
+++ b/lib/if.h
@@ -542,9 +542,9 @@ extern int if_is_up(const struct interface *ifp);
 extern int if_is_running(const struct interface *ifp);
 extern int if_is_operative(const struct interface *ifp);
 extern int if_is_no_ptm_operative(const struct interface *ifp);
-extern int if_is_loopback(const struct interface *ifp);
+extern int if_is_loopback_exact(const struct interface *ifp);
 extern int if_is_vrf(const struct interface *ifp);
-extern bool if_is_loopback_or_vrf(const struct interface *ifp);
+extern bool if_is_loopback(const struct interface *ifp);
 extern int if_is_broadcast(const struct interface *ifp);
 extern int if_is_pointopoint(const struct interface *ifp);
 extern int if_is_multicast(const struct interface *ifp);
index 4205be38ba62c9cb138a3e2c54fba7bc60e7a620..e83dc9c21f95655d44e3bfcfbf0a13b2347dc0d8 100644 (file)
@@ -127,7 +127,7 @@ static uint8_t ospf6_default_iftype(struct interface *ifp)
 {
        if (if_is_pointopoint(ifp))
                return OSPF_IFTYPE_POINTOPOINT;
-       else if (if_is_loopback_or_vrf(ifp))
+       else if (if_is_loopback(ifp))
                return OSPF_IFTYPE_LOOPBACK;
        else
                return OSPF_IFTYPE_BROADCAST;
@@ -387,7 +387,7 @@ void ospf6_interface_state_update(struct interface *ifp)
 
        if (if_is_operative(ifp)
            && (ospf6_interface_get_linklocal_address(oi->interface)
-               || if_is_loopback_or_vrf(oi->interface)))
+               || if_is_loopback(oi->interface)))
                thread_execute(master, interface_up, oi, 0);
        else
                thread_execute(master, interface_down, oi, 0);
@@ -750,7 +750,7 @@ int interface_up(struct thread *thread)
 
        /* check interface has a link-local address */
        if (!(ospf6_interface_get_linklocal_address(oi->interface)
-             || if_is_loopback_or_vrf(oi->interface))) {
+             || if_is_loopback(oi->interface))) {
                zlog_warn(
                        "Interface %s has no link local address, can't execute [InterfaceUp]",
                        oi->interface->name);
@@ -819,7 +819,7 @@ int interface_up(struct thread *thread)
 
        /* Schedule Hello */
        if (!CHECK_FLAG(oi->flag, OSPF6_INTERFACE_PASSIVE)
-           && !if_is_loopback_or_vrf(oi->interface)) {
+           && !if_is_loopback(oi->interface)) {
                thread_add_event(master, ospf6_hello_send, oi, 0,
                                 &oi->thread_send_hello);
        }
@@ -2315,7 +2315,7 @@ DEFUN (no_ipv6_ospf6_passive,
        THREAD_OFF(oi->thread_sso);
 
        /* don't send hellos over loopback interface */
-       if (!if_is_loopback_or_vrf(oi->interface))
+       if (!if_is_loopback(oi->interface))
                thread_add_event(master, ospf6_hello_send, oi, 0,
                                 &oi->thread_send_hello);
 
index 42d31414f546a122815af316a472b9dfaa04dcf7..e2994a13c08b9fdb0a10babf5e0bb639f46aa4d5 100644 (file)
@@ -477,7 +477,7 @@ struct ospf_interface *ospf_if_lookup_recv_if(struct ospf *ospf,
                if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
                        continue;
 
-               if (if_is_loopback_or_vrf(oi->ifp))
+               if (if_is_loopback(oi->ifp))
                        continue;
 
                if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED))
@@ -719,7 +719,7 @@ static int ospf_if_delete_hook(struct interface *ifp)
 
 int ospf_if_is_enable(struct ospf_interface *oi)
 {
-       if (!(if_is_loopback_or_vrf(oi->ifp)))
+       if (!(if_is_loopback(oi->ifp)))
                if (if_is_up(oi->ifp))
                        return 1;
 
@@ -1294,7 +1294,7 @@ uint8_t ospf_default_iftype(struct interface *ifp)
 {
        if (if_is_pointopoint(ifp))
                return OSPF_IFTYPE_POINTOPOINT;
-       else if (if_is_loopback_or_vrf(ifp))
+       else if (if_is_loopback(ifp))
                return OSPF_IFTYPE_LOOPBACK;
        else
                return OSPF_IFTYPE_BROADCAST;
index d95d9dd25dccae3ef08c0feb96907be88dc309db..5c6f55e99d59648141cd9cebc556ac5e50ad1b05 100644 (file)
@@ -368,7 +368,7 @@ void pim_jp_agg_single_upstream_send(struct pim_rpf *rpf,
        if (!up || !rpf->source_nexthop.interface ||
                pim_if_connected_to_source(rpf->source_nexthop.interface,
                        up->sg.src) ||
-               if_is_loopback_or_vrf(rpf->source_nexthop.interface))
+               if_is_loopback(rpf->source_nexthop.interface))
                return;
 
        memset(&groups, 0, sizeof(groups));
index 3df7dc41ce318845f89f674d4fb444e3a383e050..30dc6b3e92fdf699e5e2eeb27b2b5becf9ad9035 100644 (file)
@@ -692,7 +692,7 @@ int pim_hello_send(struct interface *ifp, uint16_t holdtime)
 {
        struct pim_interface *pim_ifp = ifp->info;
 
-       if (if_is_loopback_or_vrf(ifp))
+       if (if_is_loopback(ifp))
                return 0;
 
        if (hello_send(ifp, holdtime)) {
@@ -794,7 +794,7 @@ void pim_hello_restart_triggered(struct interface *ifp)
        /*
         * No need to ever start loopback or vrf device hello's
         */
-       if (if_is_loopback_or_vrf(ifp))
+       if (if_is_loopback(ifp))
                return;
 
        /*
index 5d5ea1bfe6c027eeec01eb675a4719d2b1e5aa94..2299f97ebd7425ff3a1a6c52d94cc198b2b91f74 100644 (file)
@@ -1079,7 +1079,7 @@ void pim_vxlan_add_vif(struct interface *ifp)
        if (pim->vrf->vrf_id != VRF_DEFAULT)
                return;
 
-       if (if_is_loopback_or_vrf(ifp))
+       if (if_is_loopback(ifp))
                pim_vxlan_set_default_iif(pim, ifp);
 
        if (vxlan_mlag.flags & PIM_VXLAN_MLAGF_ENABLED &&
index ce9054cd267089d203790c6b50957d486433a8f0..d17de8e3d0e9b6fd6471bcc3a98c39bcb23be167 100644 (file)
@@ -116,7 +116,7 @@ static inline bool pim_vxlan_is_local_sip(struct pim_upstream *up)
 {
        return (up->sg.src.s_addr != INADDR_ANY) &&
                up->rpf.source_nexthop.interface &&
-               if_is_loopback_or_vrf(up->rpf.source_nexthop.interface);
+               if_is_loopback(up->rpf.source_nexthop.interface);
 }
 
 static inline bool pim_vxlan_is_term_dev_cfg(struct pim_instance *pim,
index 80d434bafc7d45d17856dde3852b1de7dd86c531..80b6bf83200febcc0ec033a13faaeff5d5a1ed8b 100644 (file)
@@ -73,7 +73,7 @@ static void connected_announce(struct interface *ifp, struct connected *ifc)
        if (!ifc)
                return;
 
-       if (!if_is_loopback_or_vrf(ifp) && ifc->address->family == AF_INET) {
+       if (!if_is_loopback(ifp) && ifc->address->family == AF_INET) {
                if (ifc->address->prefixlen == IPV4_MAX_BITLEN)
                        SET_FLAG(ifc->flags, ZEBRA_IFA_UNNUMBERED);
                else
index ab3e55d1003e2348c5b31541c80cc9f8c42326d9..4d97c3c234aa578696ff4648f8fd3b9f106ef807 100644 (file)
@@ -493,7 +493,7 @@ static int rtadv_timer(struct thread *thread)
 
        RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id)
                FOR_ALL_INTERFACES (vrf, ifp) {
-                       if (if_is_loopback_or_vrf(ifp) || !if_is_operative(ifp)
+                       if (if_is_loopback(ifp) || !if_is_operative(ifp)
                                || (vrf_is_backend_netns() && ifp->vrf_id != zvrf->vrf->vrf_id))
                                continue;
 
@@ -726,7 +726,7 @@ static void rtadv_process_packet(uint8_t *buf, unsigned int len,
                           VRF_LOGNAME(vrf), ifp->ifindex, len, addr_str);
        }
 
-       if (if_is_loopback_or_vrf(ifp))
+       if (if_is_loopback(ifp))
                return;
 
        /* Check interface configuration. */
@@ -1462,7 +1462,7 @@ DEFUN (ipv6_nd_ra_fast_retrans,
        VTY_DECLVAR_CONTEXT(interface, ifp);
        struct zebra_if *zif = ifp->info;
 
-       if (if_is_loopback_or_vrf(ifp)) {
+       if (if_is_loopback(ifp)) {
                vty_out(vty,
                        "Cannot configure IPv6 Router Advertisements on this  interface\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -1484,7 +1484,7 @@ DEFUN (no_ipv6_nd_ra_fast_retrans,
        VTY_DECLVAR_CONTEXT(interface, ifp);
        struct zebra_if *zif = ifp->info;
 
-       if (if_is_loopback_or_vrf(ifp)) {
+       if (if_is_loopback(ifp)) {
                vty_out(vty,
                        "Cannot configure IPv6 Router Advertisements on this  interface\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -1506,7 +1506,7 @@ DEFPY (ipv6_nd_ra_hop_limit,
        VTY_DECLVAR_CONTEXT(interface, ifp);
        struct zebra_if *zif = ifp->info;
 
-       if (if_is_loopback_or_vrf(ifp)) {
+       if (if_is_loopback(ifp)) {
                vty_out(vty,
                        "Cannot configure IPv6 Router Advertisements on this interface\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -1529,7 +1529,7 @@ DEFPY (no_ipv6_nd_ra_hop_limit,
        VTY_DECLVAR_CONTEXT(interface, ifp);
        struct zebra_if *zif = ifp->info;
 
-       if (if_is_loopback_or_vrf(ifp)) {
+       if (if_is_loopback(ifp)) {
                vty_out(vty,
                        "Cannot configure IPv6 Router Advertisements on this interface\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -1551,7 +1551,7 @@ DEFPY (ipv6_nd_ra_retrans_interval,
        VTY_DECLVAR_CONTEXT(interface, ifp);
        struct zebra_if *zif = ifp->info;
 
-       if (if_is_loopback_or_vrf(ifp)) {
+       if (if_is_loopback(ifp)) {
                vty_out(vty,
                        "Cannot configure IPv6 Router Advertisements on loopback interface\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -1574,7 +1574,7 @@ DEFPY (no_ipv6_nd_ra_retrans_interval,
        VTY_DECLVAR_CONTEXT(interface, ifp);
        struct zebra_if *zif = ifp->info;
 
-       if (if_is_loopback_or_vrf(ifp)) {
+       if (if_is_loopback(ifp)) {
                vty_out(vty,
                        "Cannot remove IPv6 Router Advertisements on loopback interface\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -1595,7 +1595,7 @@ DEFUN (ipv6_nd_suppress_ra,
        VTY_DECLVAR_CONTEXT(interface, ifp);
        struct zebra_if *zif = ifp->info;
 
-       if (if_is_loopback_or_vrf(ifp)) {
+       if (if_is_loopback(ifp)) {
                vty_out(vty,
                        "Cannot configure IPv6 Router Advertisements on this  interface\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -1619,7 +1619,7 @@ DEFUN (no_ipv6_nd_suppress_ra,
        VTY_DECLVAR_CONTEXT(interface, ifp);
        struct zebra_if *zif = ifp->info;
 
-       if (if_is_loopback_or_vrf(ifp)) {
+       if (if_is_loopback(ifp)) {
                vty_out(vty,
                        "Cannot configure IPv6 Router Advertisements on this interface\n");
                return CMD_WARNING_CONFIG_FAILED;
@@ -2608,7 +2608,7 @@ static int rtadv_config_write(struct vty *vty, struct interface *ifp)
 
        zif = ifp->info;
 
-       if (!if_is_loopback_or_vrf(ifp)) {
+       if (!if_is_loopback(ifp)) {
                if (zif->rtadv.AdvSendAdvertisements
                    && CHECK_FLAG(zif->rtadv.ra_configured, VTY_RA_CONFIGURED))
                        vty_out(vty, " no ipv6 nd suppress-ra\n");
index 42fa927d9e42e2768c15986b42322d278d8f59b5..3df70a3b56660b0a4cddb429c5e52a97e68100f8 100644 (file)
@@ -1026,7 +1026,7 @@ static struct route_entry *rib_choose_best(struct route_entry *current,
                        struct interface *ifp = if_lookup_by_index(
                                nexthop->ifindex, alternate->vrf_id);
 
-                       if (ifp && if_is_loopback_or_vrf(ifp))
+                       if (ifp && if_is_loopback(ifp))
                                return alternate;
                }
 
@@ -1034,7 +1034,7 @@ static struct route_entry *rib_choose_best(struct route_entry *current,
                        struct interface *ifp = if_lookup_by_index(
                                nexthop->ifindex, current->vrf_id);
 
-                       if (ifp && if_is_loopback_or_vrf(ifp))
+                       if (ifp && if_is_loopback(ifp))
                                return current;
                }