summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2022-01-05 15:56:18 +0100
committerDavid Lamparter <equinox@opensourcerouting.org>2022-01-17 14:08:58 +0100
commit62f59b58ba4c0fa2a5763bccaade47d6b070438b (patch)
tree7174d035faddc37f9c8b78b25cd9e6b05892a822
parentpimd: remove pim_addr_copy (diff)
downloadfrr-62f59b58ba4c0fa2a5763bccaade47d6b070438b.tar.xz
frr-62f59b58ba4c0fa2a5763bccaade47d6b070438b.zip
pimd: deploy pim_sgaddr_* helpers
Use _cmp/_hash/_match helpers for operations on pim_sgaddr to prepare IPv6 support. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
-rw-r--r--pimd/pim_br.c9
-rw-r--r--pimd/pim_cmd.c20
-rw-r--r--pimd/pim_ifchannel.c14
-rw-r--r--pimd/pim_msdp.c19
-rw-r--r--pimd/pim_upstream.c22
-rw-r--r--pimd/pim_vxlan.c6
6 files changed, 22 insertions, 68 deletions
diff --git a/pimd/pim_br.c b/pimd/pim_br.c
index b3fc8969b..3e64296de 100644
--- a/pimd/pim_br.c
+++ b/pimd/pim_br.c
@@ -43,8 +43,7 @@ struct in_addr pim_br_get_pmbr(pim_sgaddr *sg)
struct pim_br *pim_br;
for (ALL_LIST_ELEMENTS_RO(pim_br_list, node, pim_br)) {
- if (sg->src.s_addr == pim_br->sg.src.s_addr
- && sg->grp.s_addr == pim_br->sg.grp.s_addr)
+ if (!pim_sgaddr_cmp(*sg, pim_br->sg))
return pim_br->pmbr;
}
@@ -57,8 +56,7 @@ void pim_br_set_pmbr(pim_sgaddr *sg, struct in_addr br)
struct pim_br *pim_br;
for (ALL_LIST_ELEMENTS(pim_br_list, node, next, pim_br)) {
- if (sg->src.s_addr == pim_br->sg.src.s_addr
- && sg->grp.s_addr == pim_br->sg.grp.s_addr)
+ if (!pim_sgaddr_cmp(*sg, pim_br->sg))
break;
}
@@ -81,8 +79,7 @@ void pim_br_clear_pmbr(pim_sgaddr *sg)
struct pim_br *pim_br;
for (ALL_LIST_ELEMENTS(pim_br_list, node, next, pim_br)) {
- if (sg->src.s_addr == pim_br->sg.src.s_addr
- && sg->grp.s_addr == pim_br->sg.grp.s_addr)
+ if (!pim_sgaddr_cmp(*sg, pim_br->sg))
break;
}
diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c
index 2a50a54a7..6b74c9250 100644
--- a/pimd/pim_cmd.c
+++ b/pimd/pim_cmd.c
@@ -79,6 +79,14 @@ static struct cmd_node debug_node = {
.config_write = pim_debug_config_write,
};
+static inline bool pim_sgaddr_match(pim_sgaddr item, pim_sgaddr match)
+{
+ return (pim_addr_is_any(match.grp) ||
+ !pim_addr_cmp(match.grp, item.grp)) &&
+ (pim_addr_is_any(match.src) ||
+ !pim_addr_cmp(match.src, item.src));
+}
+
static struct vrf *pim_cmd_lookup_vrf(struct vty *vty, struct cmd_token *argv[],
const int argc, int *idx)
{
@@ -1762,11 +1770,7 @@ static void pim_show_join(struct pim_instance *pim, struct vty *vty,
continue;
RB_FOREACH (ch, pim_ifchannel_rb, &pim_ifp->ifchannel_rb) {
- if (sg->grp.s_addr != INADDR_ANY
- && sg->grp.s_addr != ch->sg.grp.s_addr)
- continue;
- if (sg->src.s_addr != INADDR_ANY
- && sg->src.s_addr != ch->sg.src.s_addr)
+ if (!pim_sgaddr_match(ch->sg, *sg))
continue;
pim_show_join_helper(vty, pim_ifp, ch, json, now, uj);
} /* scan interface channels */
@@ -2464,11 +2468,7 @@ static void pim_show_upstream(struct pim_instance *pim, struct vty *vty,
char msdp_reg_timer[10];
char state_str[PIM_REG_STATE_STR_LEN];
- if (sg->grp.s_addr != INADDR_ANY
- && sg->grp.s_addr != up->sg.grp.s_addr)
- continue;
- if (sg->src.s_addr != INADDR_ANY
- && sg->src.s_addr != up->sg.src.s_addr)
+ if (!pim_sgaddr_match(up->sg, *sg))
continue;
pim_inet4_dump("<src?>", up->sg.src, src_str, sizeof(src_str));
diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c
index 7a98e693e..5b650e6e3 100644
--- a/pimd/pim_ifchannel.c
+++ b/pimd/pim_ifchannel.c
@@ -62,19 +62,7 @@ int pim_ifchannel_compare(const struct pim_ifchannel *ch1,
if (pim_ifp1->mroute_vif_index > pim_ifp2->mroute_vif_index)
return 1;
- if (ntohl(ch1->sg.grp.s_addr) < ntohl(ch2->sg.grp.s_addr))
- return -1;
-
- if (ntohl(ch1->sg.grp.s_addr) > ntohl(ch2->sg.grp.s_addr))
- return 1;
-
- if (ntohl(ch1->sg.src.s_addr) < ntohl(ch2->sg.src.s_addr))
- return -1;
-
- if (ntohl(ch1->sg.src.s_addr) > ntohl(ch2->sg.src.s_addr))
- return 1;
-
- return 0;
+ return pim_sgaddr_cmp(ch1->sg, ch2->sg);
}
/*
diff --git a/pimd/pim_msdp.c b/pimd/pim_msdp.c
index 63cdc9214..8c4d2293c 100644
--- a/pimd/pim_msdp.c
+++ b/pimd/pim_msdp.c
@@ -680,7 +680,7 @@ static unsigned int pim_msdp_sa_hash_key_make(const void *p)
{
const struct pim_msdp_sa *sa = p;
- return (jhash_2words(sa->sg.src.s_addr, sa->sg.grp.s_addr, 0));
+ return pim_sgaddr_hash(sa->sg, 0);
}
static bool pim_msdp_sa_hash_eq(const void *p1, const void *p2)
@@ -688,8 +688,7 @@ static bool pim_msdp_sa_hash_eq(const void *p1, const void *p2)
const struct pim_msdp_sa *sa1 = p1;
const struct pim_msdp_sa *sa2 = p2;
- return ((sa1->sg.src.s_addr == sa2->sg.src.s_addr)
- && (sa1->sg.grp.s_addr == sa2->sg.grp.s_addr));
+ return !pim_sgaddr_cmp(sa1->sg, sa2->sg);
}
static int pim_msdp_sa_comp(const void *p1, const void *p2)
@@ -697,19 +696,7 @@ static int pim_msdp_sa_comp(const void *p1, const void *p2)
const struct pim_msdp_sa *sa1 = p1;
const struct pim_msdp_sa *sa2 = p2;
- if (ntohl(sa1->sg.grp.s_addr) < ntohl(sa2->sg.grp.s_addr))
- return -1;
-
- if (ntohl(sa1->sg.grp.s_addr) > ntohl(sa2->sg.grp.s_addr))
- return 1;
-
- if (ntohl(sa1->sg.src.s_addr) < ntohl(sa2->sg.src.s_addr))
- return -1;
-
- if (ntohl(sa1->sg.src.s_addr) > ntohl(sa2->sg.src.s_addr))
- return 1;
-
- return 0;
+ return pim_sgaddr_cmp(sa1->sg, sa2->sg);
}
/* RFC-3618:Sec-10.1.3 - Peer-RPF forwarding */
diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c
index e3d0db1bf..400714237 100644
--- a/pimd/pim_upstream.c
+++ b/pimd/pim_upstream.c
@@ -824,19 +824,7 @@ void pim_upstream_switch(struct pim_instance *pim, struct pim_upstream *up,
int pim_upstream_compare(const struct pim_upstream *up1,
const struct pim_upstream *up2)
{
- if (ntohl(up1->sg.grp.s_addr) < ntohl(up2->sg.grp.s_addr))
- return -1;
-
- if (ntohl(up1->sg.grp.s_addr) > ntohl(up2->sg.grp.s_addr))
- return 1;
-
- if (ntohl(up1->sg.src.s_addr) < ntohl(up2->sg.src.s_addr))
- return -1;
-
- if (ntohl(up1->sg.src.s_addr) > ntohl(up2->sg.src.s_addr))
- return 1;
-
- return 0;
+ return pim_sgaddr_cmp(up1->sg, up2->sg);
}
void pim_upstream_fill_static_iif(struct pim_upstream *up,
@@ -1958,7 +1946,7 @@ unsigned int pim_upstream_hash_key(const void *arg)
{
const struct pim_upstream *up = arg;
- return jhash_2words(up->sg.src.s_addr, up->sg.grp.s_addr, 0);
+ return pim_sgaddr_hash(up->sg, 0);
}
void pim_upstream_terminate(struct pim_instance *pim)
@@ -1981,11 +1969,7 @@ bool pim_upstream_equal(const void *arg1, const void *arg2)
const struct pim_upstream *up1 = (const struct pim_upstream *)arg1;
const struct pim_upstream *up2 = (const struct pim_upstream *)arg2;
- if ((up1->sg.grp.s_addr == up2->sg.grp.s_addr)
- && (up1->sg.src.s_addr == up2->sg.src.s_addr))
- return true;
-
- return false;
+ return !pim_sgaddr_cmp(up1->sg, up2->sg);
}
/* rfc4601:section-4.2:"Data Packet Forwarding Rules" defines
diff --git a/pimd/pim_vxlan.c b/pimd/pim_vxlan.c
index fe7d358ee..c1e7be587 100644
--- a/pimd/pim_vxlan.c
+++ b/pimd/pim_vxlan.c
@@ -720,8 +720,7 @@ static unsigned int pim_vxlan_sg_hash_key_make(const void *p)
{
const struct pim_vxlan_sg *vxlan_sg = p;
- return (jhash_2words(vxlan_sg->sg.src.s_addr,
- vxlan_sg->sg.grp.s_addr, 0));
+ return pim_sgaddr_hash(vxlan_sg->sg, 0);
}
static bool pim_vxlan_sg_hash_eq(const void *p1, const void *p2)
@@ -729,8 +728,7 @@ static bool pim_vxlan_sg_hash_eq(const void *p1, const void *p2)
const struct pim_vxlan_sg *sg1 = p1;
const struct pim_vxlan_sg *sg2 = p2;
- return ((sg1->sg.src.s_addr == sg2->sg.src.s_addr)
- && (sg1->sg.grp.s_addr == sg2->sg.grp.s_addr));
+ return !pim_sgaddr_cmp(sg1->sg, sg2->sg);
}
static struct pim_vxlan_sg *pim_vxlan_sg_new(struct pim_instance *pim,