From 7f432a28e08bef5aaa75a830161f893adb9b3577 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 30 Apr 2018 07:50:08 -0400 Subject: [PATCH 1/2] pimd: Cleanup pim_if_is_loopback The interface itself knows if it is a vrf device or not, so let's just use a check for that in the decision if a interface is a loopback or not. Additionally modify function to return a bool. Signed-off-by: Donald Sharp --- pimd/pim_iface.c | 11 ++++------- pimd/pim_iface.h | 2 +- pimd/pim_pim.c | 4 ++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index ff7238ae97..e58d81591d 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -1547,15 +1547,12 @@ int pim_if_connected_to_source(struct interface *ifp, struct in_addr src) return 0; } -int pim_if_is_loopback(struct pim_instance *pim, struct interface *ifp) +bool pim_if_is_loopback(struct interface *ifp) { - if (if_is_loopback(ifp)) - return 1; + if (if_is_loopback(ifp) || if_is_vrf(ifp)) + return true; - if (strcmp(ifp->name, pim->vrf->name) == 0) - return 1; - - return 0; + return false; } int pim_if_is_vrf_device(struct interface *ifp) diff --git a/pimd/pim_iface.h b/pimd/pim_iface.h index 5ecd07d227..12098fde29 100644 --- a/pimd/pim_iface.h +++ b/pimd/pim_iface.h @@ -207,7 +207,7 @@ void pim_if_create_pimreg(struct pim_instance *pim); int pim_if_connected_to_source(struct interface *ifp, struct in_addr src); int pim_update_source_set(struct interface *ifp, struct in_addr source); -int pim_if_is_loopback(struct pim_instance *pim, struct interface *ifp); +bool pim_if_is_loopback(struct interface *ifp); int pim_if_is_vrf_device(struct interface *ifp); diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c index ffe5d52a15..de09b070f4 100644 --- a/pimd/pim_pim.c +++ b/pimd/pim_pim.c @@ -653,7 +653,7 @@ static int pim_hello_send(struct interface *ifp, uint16_t holdtime) { struct pim_interface *pim_ifp = ifp->info; - if (pim_if_is_loopback(pim_ifp->pim, ifp)) + if (pim_if_is_loopback(ifp)) return 0; if (hello_send(ifp, holdtime)) { @@ -755,7 +755,7 @@ void pim_hello_restart_triggered(struct interface *ifp) /* * No need to ever start loopback or vrf device hello's */ - if (pim_if_is_loopback(pim_ifp->pim, ifp)) + if (pim_if_is_loopback(ifp)) return; /* From e55a43d491c8423feceb6c37b8d42d8b1637a0e5 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 30 Apr 2018 07:56:24 -0400 Subject: [PATCH 2/2] pimd: Remove expensive lookup for if a device is a vrf device Interfaces know if they are a vrf device or not and this data is passed up to the protocol. Signed-off-by: Donald Sharp --- pimd/pim_iface.c | 12 ++++-------- pimd/pim_iface.h | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index e58d81591d..5996a3ac96 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -1555,16 +1555,12 @@ bool pim_if_is_loopback(struct interface *ifp) return false; } -int pim_if_is_vrf_device(struct interface *ifp) +bool pim_if_is_vrf_device(struct interface *ifp) { - struct vrf *vrf; + if (if_is_vrf(ifp)) + return true; - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (strncmp(ifp->name, vrf->name, strlen(ifp->name)) == 0) - return 1; - } - - return 0; + return false; } int pim_if_ifchannel_count(struct pim_interface *pim_ifp) diff --git a/pimd/pim_iface.h b/pimd/pim_iface.h index 12098fde29..cf025cbd4a 100644 --- a/pimd/pim_iface.h +++ b/pimd/pim_iface.h @@ -209,7 +209,7 @@ int pim_update_source_set(struct interface *ifp, struct in_addr source); bool pim_if_is_loopback(struct interface *ifp); -int pim_if_is_vrf_device(struct interface *ifp); +bool pim_if_is_vrf_device(struct interface *ifp); int pim_if_ifchannel_count(struct pim_interface *pim_ifp); #endif /* PIM_IFACE_H */