From: Donald Sharp Date: Sat, 23 Jul 2016 03:12:06 +0000 (-0400) Subject: pimd: more source,group conversion to prefix sg X-Git-Tag: frr-3.0-branchpoint~64^2~10^2~361 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=5074a4230a11607b837fe07c7419ce5b3275f942;p=matthieu%2Ffrr.git pimd: more source,group conversion to prefix sg Convert more of the code to pass around a 'struct prefix sg' instead of individual struct addr's. Signed-off-by: Donald Sharp --- diff --git a/pimd/pim_assert.c b/pimd/pim_assert.c index 63f4e33868..e8e3549d24 100644 --- a/pimd/pim_assert.c +++ b/pimd/pim_assert.c @@ -146,16 +146,16 @@ static int dispatch_assert(struct interface *ifp, struct pim_assert_metric recv_metric) { struct pim_ifchannel *ch; + struct prefix sg; - ch = pim_ifchannel_add(ifp, source_addr, group_addr); + memset (&sg, 0, sizeof (struct prefix)); + sg.u.sg.src = source_addr; + sg.u.sg.grp = group_addr; + ch = pim_ifchannel_add(ifp, &sg); if (!ch) { - char source_str[100]; - char group_str[100]; - pim_inet4_dump("", source_addr, source_str, sizeof(source_str)); - pim_inet4_dump("", group_addr, group_str, sizeof(group_str)); - zlog_warn("%s: (S,G)=(%s,%s) failure creating channel on interface %s", + zlog_warn("%s: (S,G)=%s failure creating channel on interface %s", __PRETTY_FUNCTION__, - source_str, group_str, ifp->name); + pim_str_sg_dump (&sg), ifp->name); return -1; } @@ -212,13 +212,9 @@ static int dispatch_assert(struct interface *ifp, break; default: { - char source_str[100]; - char group_str[100]; - pim_inet4_dump("", source_addr, source_str, sizeof(source_str)); - pim_inet4_dump("", group_addr, group_str, sizeof(group_str)); - zlog_warn("%s: (S,G)=(%s,%s) invalid assert state %d on interface %s", + zlog_warn("%s: (S,G)=%s invalid assert state %d on interface %s", __PRETTY_FUNCTION__, - source_str, group_str, ch->ifassert_state, ifp->name); + pim_str_sg_dump (&sg), ch->ifassert_state, ifp->name); } return -2; } diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c index cf2cc99f58..27d51ea731 100644 --- a/pimd/pim_ifchannel.c +++ b/pimd/pim_ifchannel.c @@ -184,8 +184,7 @@ void reset_ifassert_state(struct pim_ifchannel *ch) } struct pim_ifchannel *pim_ifchannel_find(struct interface *ifp, - struct in_addr source_addr, - struct in_addr group_addr) + struct prefix *sg) { struct pim_interface *pim_ifp; struct listnode *ch_node; @@ -196,21 +195,17 @@ struct pim_ifchannel *pim_ifchannel_find(struct interface *ifp, pim_ifp = ifp->info; if (!pim_ifp) { - char src_str[100]; - char grp_str[100]; - pim_inet4_dump("", source_addr, src_str, sizeof(src_str)); - pim_inet4_dump("", group_addr, grp_str, sizeof(grp_str)); - zlog_warn("%s: (S,G)=(%s,%s): multicast not enabled on interface %s", + zlog_warn("%s: (S,G)=%s: multicast not enabled on interface %s", __PRETTY_FUNCTION__, - src_str, grp_str, + pim_str_sg_dump (sg), ifp->name); return 0; } for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_ifchannel_list, ch_node, ch)) { if ( - (source_addr.s_addr == ch->sg.u.sg.src.s_addr) && - (group_addr.s_addr == ch->sg.u.sg.grp.s_addr) + (sg->u.sg.src.s_addr == ch->sg.u.sg.src.s_addr) && + (sg->u.sg.grp.s_addr == ch->sg.u.sg.grp.s_addr) ) { return ch; } @@ -275,41 +270,32 @@ void pim_ifchannel_delete_on_noinfo(struct interface *ifp) } struct pim_ifchannel *pim_ifchannel_add(struct interface *ifp, - struct in_addr source_addr, - struct in_addr group_addr) + struct prefix *sg) { struct pim_interface *pim_ifp; struct pim_ifchannel *ch; struct pim_upstream *up; - char src_str[100]; - char grp_str[100]; - ch = pim_ifchannel_find(ifp, source_addr, group_addr); + ch = pim_ifchannel_find(ifp, sg); if (ch) return ch; pim_ifp = ifp->info; zassert(pim_ifp); - up = pim_upstream_add(source_addr, group_addr, NULL); + up = pim_upstream_add(sg, NULL); if (!up) { - char src_str[100]; - char grp_str[100]; - pim_inet4_dump("", source_addr, src_str, sizeof(src_str)); - pim_inet4_dump("", group_addr, grp_str, sizeof(grp_str)); - zlog_err("%s: could not attach upstream (S,G)=(%s,%s) on interface %s", + zlog_err("%s: could not attach upstream (S,G)=%s on interface %s", __PRETTY_FUNCTION__, - src_str, grp_str, ifp->name); + pim_str_sg_dump (sg), ifp->name); return NULL; } ch = XMALLOC(MTYPE_PIM_IFCHANNEL, sizeof(*ch)); if (!ch) { - pim_inet4_dump("", source_addr, src_str, sizeof(src_str)); - pim_inet4_dump("", group_addr, grp_str, sizeof(grp_str)); - zlog_warn("%s: pim_ifchannel_new() failure for (S,G)=(%s,%s) on interface %s", + zlog_warn("%s: pim_ifchannel_new() failure for (S,G)=%s on interface %s", __PRETTY_FUNCTION__, - src_str, grp_str, ifp->name); + pim_str_sg_dump (sg), ifp->name); return NULL; } @@ -317,8 +303,7 @@ struct pim_ifchannel *pim_ifchannel_add(struct interface *ifp, ch->flags = 0; ch->upstream = up; ch->interface = ifp; - ch->sg.u.sg.src = source_addr; - ch->sg.u.sg.grp = group_addr; + ch->sg = *sg; ch->local_ifmembership = PIM_IFMEMBERSHIP_NOINFO; ch->ifjoin_state = PIM_IFJOIN_NOINFO; @@ -420,9 +405,13 @@ static void check_recv_upstream(int is_join, int holdtime) { struct pim_upstream *up; + struct prefix sg; + memset (&sg, 0, sizeof (struct prefix)); + sg.u.sg.src = source_addr; + sg.u.sg.grp = group_addr; /* Upstream (S,G) in Joined state ? */ - up = pim_upstream_find(source_addr, group_addr); + up = pim_upstream_find(&sg); if (!up) return; if (up->join_state != PIM_UPSTREAM_JOINED) @@ -541,13 +530,17 @@ void pim_ifchannel_join_add(struct interface *ifp, { struct pim_interface *pim_ifp; struct pim_ifchannel *ch; + struct prefix sg; + memset (&sg, 0, sizeof (struct prefix)); + sg.u.sg.src = source_addr; + sg.u.sg.grp = group_addr; if (nonlocal_upstream(1 /* join */, ifp, upstream, source_addr, group_addr, source_flags, holdtime)) { return; } - ch = pim_ifchannel_add(ifp, source_addr, group_addr); + ch = pim_ifchannel_add(ifp, &sg); if (!ch) return; @@ -568,15 +561,11 @@ void pim_ifchannel_join_add(struct interface *ifp, address of the join message is our primary address. */ if (ch->ifassert_state == PIM_IFASSERT_I_AM_LOSER) { - char src_str[100]; - char grp_str[100]; char neigh_str[100]; - pim_inet4_dump("", source_addr, src_str, sizeof(src_str)); - pim_inet4_dump("", group_addr, grp_str, sizeof(grp_str)); pim_inet4_dump("", neigh_addr, neigh_str, sizeof(neigh_str)); - zlog_warn("%s: Assert Loser recv Join(%s,%s) from %s on %s", + zlog_warn("%s: Assert Loser recv Join%s from %s on %s", __PRETTY_FUNCTION__, - src_str, grp_str, neigh_str, ifp->name); + pim_str_sg_dump (&sg), neigh_str, ifp->name); assert_action_a5(ch); } @@ -648,13 +637,18 @@ void pim_ifchannel_prune(struct interface *ifp, { struct pim_ifchannel *ch; int jp_override_interval_msec; + struct prefix sg; + + memset (&sg, 0, sizeof (struct prefix)); + sg.u.sg.src = source_addr; + sg.u.sg.grp = group_addr; if (nonlocal_upstream(0 /* prune */, ifp, upstream, source_addr, group_addr, source_flags, holdtime)) { return; } - ch = pim_ifchannel_add(ifp, source_addr, group_addr); + ch = pim_ifchannel_add(ifp, &sg); if (!ch) return; @@ -705,6 +699,11 @@ void pim_ifchannel_local_membership_add(struct interface *ifp, { struct pim_ifchannel *ch; struct pim_interface *pim_ifp; + struct prefix sg; + + memset (&sg, 0, sizeof (struct prefix)); + sg.u.sg.src = source_addr; + sg.u.sg.grp = group_addr; /* PIM enabled on interface? */ pim_ifp = ifp->info; @@ -713,7 +712,7 @@ void pim_ifchannel_local_membership_add(struct interface *ifp, if (!PIM_IF_TEST_PIM(pim_ifp->options)) return; - ch = pim_ifchannel_add(ifp, source_addr, group_addr); + ch = pim_ifchannel_add(ifp, &sg); if (!ch) { return; } @@ -729,6 +728,11 @@ void pim_ifchannel_local_membership_del(struct interface *ifp, { struct pim_ifchannel *ch; struct pim_interface *pim_ifp; + struct prefix sg; + + memset (&sg, 0, sizeof (struct prefix)); + sg.u.sg.src = source_addr; + sg.u.sg.grp = group_addr; /* PIM enabled on interface? */ pim_ifp = ifp->info; @@ -737,7 +741,7 @@ void pim_ifchannel_local_membership_del(struct interface *ifp, if (!PIM_IF_TEST_PIM(pim_ifp->options)) return; - ch = pim_ifchannel_find(ifp, source_addr, group_addr); + ch = pim_ifchannel_find(ifp, &sg); if (!ch) return; diff --git a/pimd/pim_ifchannel.h b/pimd/pim_ifchannel.h index 747ee39bf2..aa8585a2b7 100644 --- a/pimd/pim_ifchannel.h +++ b/pimd/pim_ifchannel.h @@ -104,11 +104,9 @@ void pim_ifchannel_delete(struct pim_ifchannel *ch); void pim_ifchannel_membership_clear(struct interface *ifp); void pim_ifchannel_delete_on_noinfo(struct interface *ifp); struct pim_ifchannel *pim_ifchannel_find(struct interface *ifp, - struct in_addr source_addr, - struct in_addr group_addr); + struct prefix *sg); struct pim_ifchannel *pim_ifchannel_add(struct interface *ifp, - struct in_addr source_addr, - struct in_addr group_addr); + struct prefix *sg); void pim_ifchannel_join_add(struct interface *ifp, struct in_addr neigh_addr, struct in_addr upstream, diff --git a/pimd/pim_mroute.c b/pimd/pim_mroute.c index aeb49f770c..796b8cf2db 100644 --- a/pimd/pim_mroute.c +++ b/pimd/pim_mroute.c @@ -128,14 +128,15 @@ pim_mroute_msg_nocache (int fd, struct interface *ifp, const struct igmpmsg *msg __PRETTY_FUNCTION__, grp_str, src_str); } + memset (&sg, 0, sizeof (struct prefix)); sg.u.sg.src = msg->im_src; sg.u.sg.grp = msg->im_dst; - up = pim_upstream_add(msg->im_src, msg->im_dst, ifp); + up = pim_upstream_add (&sg, ifp); if (!up) { if (PIM_DEBUG_PIM_TRACE) { - zlog_debug("%s: Failure to add upstream information for (%s,%s)", + zlog_debug("%s: Failure to add upstream information for %s", __PRETTY_FUNCTION__, - src_str, grp_str); + pim_str_sg_dump (&sg)); } return 0; } @@ -154,7 +155,7 @@ pim_mroute_msg_nocache (int fd, struct interface *ifp, const struct igmpmsg *msg } up->channel_oil->cc.pktcnt++; up->fhr = 1; - ch = pim_ifchannel_add (pim_regiface, msg->im_src, msg->im_dst); + ch = pim_ifchannel_add (pim_regiface, &sg); pim_ifchannel_ifjoin_switch (__PRETTY_FUNCTION__, ch, PIM_IFJOIN_JOIN_PIMREG); up->join_state = PIM_UPSTREAM_JOINED; @@ -166,29 +167,29 @@ pim_mroute_msg_wholepkt (int fd, struct interface *ifp, const char *buf, const char *src_str, const char *grp_str) { struct pim_interface *pim_ifp; - struct in_addr group; - struct in_addr src; + struct prefix sg; struct pim_rpf *rpg; const struct ip *ip_hdr; struct pim_upstream *up; ip_hdr = (const struct ip *)buf; - src = ip_hdr->ip_src; - group = ip_hdr->ip_dst; + memset (&sg, 0, sizeof (struct prefix)); + sg.u.sg.src = ip_hdr->ip_src; + sg.u.sg.grp = ip_hdr->ip_dst; - up = pim_upstream_find(src, group); + up = pim_upstream_find(&sg); if (!up) { if (PIM_DEBUG_PIM_TRACE) { - zlog_debug("%s: Unable to find upstream channel WHOLEPKT(%s,%s)", - __PRETTY_FUNCTION__, src_str, grp_str); + zlog_debug("%s: Unable to find upstream channel WHOLEPKT%s", + __PRETTY_FUNCTION__, pim_str_sg_dump (&sg)); } return 0; } pim_ifp = up->rpf.source_nexthop.interface->info; - rpg = RP(group); + rpg = RP(sg.u.sg.grp); if ((rpg->rpf_addr.s_addr == INADDR_NONE) || (!pim_ifp) || @@ -215,6 +216,7 @@ pim_mroute_msg_wrongvif (int fd, struct interface *ifp, const struct igmpmsg *ms { struct pim_ifchannel *ch; struct pim_interface *pim_ifp; + struct prefix sg; /* Send Assert(S,G) on iif as response to WRONGVIF kernel upcall. @@ -246,7 +248,10 @@ pim_mroute_msg_wrongvif (int fd, struct interface *ifp, const struct igmpmsg *ms return -2; } - ch = pim_ifchannel_find(ifp, msg->im_src, msg->im_dst); + memset (&sg, 0, sizeof (struct prefix)); + sg.u.sg.src = msg->im_src; + sg.u.sg.grp = msg->im_dst; + ch = pim_ifchannel_find(ifp, &sg); if (!ch) { if (PIM_DEBUG_PIM_TRACE) { zlog_debug("%s: WRONGVIF (S,G)=(%s,%s) could not find channel on interface %s", diff --git a/pimd/pim_register.c b/pimd/pim_register.c index 003b8a1bd0..608b1bf300 100644 --- a/pimd/pim_register.c +++ b/pimd/pim_register.c @@ -117,6 +117,7 @@ pim_register_stop_recv (uint8_t *buf, int buf_size) struct pim_upstream *upstream = NULL; struct prefix source; struct prefix group; + struct prefix sg; int l; if (PIM_DEBUG_PIM_PACKETDUMP_RECV) @@ -126,7 +127,10 @@ pim_register_stop_recv (uint8_t *buf, int buf_size) buf += l; buf_size -= l; l = pim_parse_addr_ucast (&source, buf, buf_size); - upstream = pim_upstream_find (source.u.prefix4, group.u.prefix4); + memset (&sg, 0, sizeof (struct prefix)); + sg.u.sg.src = source.u.prefix4; + sg.u.sg.grp = group.u.prefix4; + upstream = pim_upstream_find (&sg); if (!upstream) { return 0; @@ -239,10 +243,9 @@ pim_register_recv (struct interface *ifp, { int sentRegisterStop = 0; struct ip *ip_hdr; - //size_t hlen; struct in_addr group = { .s_addr = 0 }; struct in_addr source = { .s_addr = 0 }; - //uint8_t *msg; + struct prefix sg; uint32_t *bits; if (!pim_check_is_my_ip_address (dest_addr)) { @@ -308,13 +311,16 @@ pim_register_recv (struct interface *ifp, } } - struct pim_upstream *upstream = pim_upstream_find (source, group); + memset (&sg, 0, sizeof (struct prefix)); + sg.u.sg.src = source; + sg.u.sg.grp = group; + struct pim_upstream *upstream = pim_upstream_find (&sg); /* * If we don't have a place to send ignore the packet */ if (!upstream) { - upstream = pim_upstream_add (source, group, ifp); + upstream = pim_upstream_add (&sg, ifp); pim_upstream_switch (upstream, PIM_UPSTREAM_PRUNE); } diff --git a/pimd/pim_rpf.c b/pimd/pim_rpf.c index 6802997076..6ba1b2e499 100644 --- a/pimd/pim_rpf.c +++ b/pimd/pim_rpf.c @@ -236,7 +236,7 @@ static struct in_addr pim_rpf_find_rpf_addr(struct pim_upstream *up) } rpf_ch = pim_ifchannel_find(up->rpf.source_nexthop.interface, - up->sg.u.sg.src, up->sg.u.sg.grp); + &up->sg); if (rpf_ch) { if (rpf_ch->ifassert_state == PIM_IFASSERT_I_AM_LOSER) { return rpf_ch->ifassert_winner; diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c index 2f16226f01..85f45566a4 100644 --- a/pimd/pim_upstream.c +++ b/pimd/pim_upstream.c @@ -325,8 +325,7 @@ pim_upstream_switch(struct pim_upstream *up, } } -static struct pim_upstream *pim_upstream_new(struct in_addr source_addr, - struct in_addr group_addr, +static struct pim_upstream *pim_upstream_new(struct prefix *sg, struct interface *incoming) { struct pim_upstream *up; @@ -339,8 +338,8 @@ static struct pim_upstream *pim_upstream_new(struct in_addr source_addr, return NULL; } - up->sg.u.sg.src = source_addr; - if (!pim_rp_set_upstream_addr (&up->upstream_addr, source_addr)) + up->sg = *sg; + if (!pim_rp_set_upstream_addr (&up->upstream_addr, sg->u.sg.src)) { if (PIM_DEBUG_PIM_TRACE) zlog_debug("%s: Received a (*,G) with no RP configured", __PRETTY_FUNCTION__); @@ -349,7 +348,6 @@ static struct pim_upstream *pim_upstream_new(struct in_addr source_addr, return NULL; } - up->sg.u.sg.grp = group_addr; up->flags = 0; up->ref_count = 1; up->t_join_timer = NULL; @@ -377,16 +375,15 @@ static struct pim_upstream *pim_upstream_new(struct in_addr source_addr, return up; } -struct pim_upstream *pim_upstream_find(struct in_addr source_addr, - struct in_addr group_addr) +struct pim_upstream *pim_upstream_find(struct prefix *sg) { struct listnode *up_node; struct pim_upstream *up; for (ALL_LIST_ELEMENTS_RO(qpim_upstream_list, up_node, up)) { - if (group_addr.s_addr == up->sg.u.sg.grp.s_addr) { + if (sg->u.sg.grp.s_addr == up->sg.u.sg.grp.s_addr) { if ((up->sg.u.sg.src.s_addr == INADDR_ANY) || - (source_addr.s_addr == up->sg.u.sg.src.s_addr)) { + (sg->u.sg.src.s_addr == up->sg.u.sg.src.s_addr)) { return up; } } @@ -395,18 +392,17 @@ struct pim_upstream *pim_upstream_find(struct in_addr source_addr, return NULL; } -struct pim_upstream *pim_upstream_add(struct in_addr source_addr, - struct in_addr group_addr, +struct pim_upstream *pim_upstream_add(struct prefix *sg, struct interface *incoming) { struct pim_upstream *up; - up = pim_upstream_find(source_addr, group_addr); + up = pim_upstream_find(sg); if (up) { ++up->ref_count; } else { - up = pim_upstream_new(source_addr, group_addr, incoming); + up = pim_upstream_new(sg, incoming); } return up; diff --git a/pimd/pim_upstream.h b/pimd/pim_upstream.h index 580bb945e9..7783cc4bc9 100644 --- a/pimd/pim_upstream.h +++ b/pimd/pim_upstream.h @@ -90,9 +90,7 @@ enum pim_upstream_sptbit { struct pim_upstream { int fhr; struct in_addr upstream_addr;/* Who we are talking to */ - struct prefix sg; - //struct in_addr source_addr; /* (S,G) source key */ - //struct in_addr group_addr; /* (S,G) group key */ + struct prefix sg; /* (S,G) group key */ uint32_t flags; struct channel_oil *channel_oil; @@ -124,10 +122,8 @@ struct pim_upstream { void pim_upstream_free(struct pim_upstream *up); void pim_upstream_delete(struct pim_upstream *up); -struct pim_upstream *pim_upstream_find(struct in_addr source_addr, - struct in_addr group_addr); -struct pim_upstream *pim_upstream_add(struct in_addr source_addr, - struct in_addr group_addr, +struct pim_upstream *pim_upstream_find (struct prefix *sg); +struct pim_upstream *pim_upstream_add (struct prefix *sg, struct interface *ifp); void pim_upstream_del(struct pim_upstream *up);