diff options
author | Mobashshera Rasool <mrasool@vmware.com> | 2022-04-04 13:05:07 +0200 |
---|---|---|
committer | Mobashshera Rasool <mrasool@vmware.com> | 2022-04-28 10:10:49 +0200 |
commit | 4d3b4b1851e4902512c53cd7cd8a78ccaa907573 (patch) | |
tree | d95a2817b5f409a1ea79a2eb96061a71a4514caf /zebra | |
parent | Merge pull request #11031 from AbhishekNR/v6_multicast (diff) | |
download | frr-4d3b4b1851e4902512c53cd7cd8a78ccaa907573.tar.xz frr-4d3b4b1851e4902512c53cd7cd8a78ccaa907573.zip |
zebra: Modify base code to get ipv6 stats from kernel
Modify the structure mcast_route_data to store ipv4/ipv6
addr and lastused multicast information from kernel.
Adjust the related APIs to parse ipv4/ipv6 informations.
Signed-off-by: Mobashshera Rasool <mrasool@vmware.com>
Diffstat (limited to 'zebra')
-rw-r--r-- | zebra/rt_netlink.c | 60 | ||||
-rw-r--r-- | zebra/zebra_mroute.c | 22 | ||||
-rw-r--r-- | zebra/zebra_mroute.h | 4 |
3 files changed, 60 insertions, 26 deletions
diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 7b377aad6..4e97323cf 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -1045,11 +1045,23 @@ static int netlink_route_change_read_multicast(struct nlmsghdr *h, if (tb[RTA_IIF]) iif = *(int *)RTA_DATA(tb[RTA_IIF]); - if (tb[RTA_SRC]) - m->sg.src = *(struct in_addr *)RTA_DATA(tb[RTA_SRC]); + if (tb[RTA_SRC]) { + if (rtm->rtm_family == RTNL_FAMILY_IPMR) + m->src.ipaddr_v4 = + *(struct in_addr *)RTA_DATA(tb[RTA_SRC]); + else + m->src.ipaddr_v6 = + *(struct in6_addr *)RTA_DATA(tb[RTA_SRC]); + } - if (tb[RTA_DST]) - m->sg.grp = *(struct in_addr *)RTA_DATA(tb[RTA_DST]); + if (tb[RTA_DST]) { + if (rtm->rtm_family == RTNL_FAMILY_IPMR) + m->grp.ipaddr_v4 = + *(struct in_addr *)RTA_DATA(tb[RTA_DST]); + else + m->grp.ipaddr_v6 = + *(struct in6_addr *)RTA_DATA(tb[RTA_DST]); + } if (tb[RTA_EXPIRES]) m->lastused = *(unsigned long long *)RTA_DATA(tb[RTA_EXPIRES]); @@ -1074,6 +1086,17 @@ static int netlink_route_change_read_multicast(struct nlmsghdr *h, } } + if (rtm->rtm_family == RTNL_FAMILY_IPMR) { + SET_IPADDR_V4(&m->src); + SET_IPADDR_V4(&m->grp); + } else if (rtm->rtm_family == RTNL_FAMILY_IP6MR) { + SET_IPADDR_V6(&m->src); + SET_IPADDR_V6(&m->grp); + } else { + zlog_warn("%s: Invalid rtm_family received", __func__); + return 0; + } + if (IS_ZEBRA_DEBUG_KERNEL) { struct interface *ifp = NULL; struct zebra_vrf *zvrf = NULL; @@ -1089,11 +1112,10 @@ static int netlink_route_change_read_multicast(struct nlmsghdr *h, zvrf = zebra_vrf_lookup_by_id(vrf); ifp = if_lookup_by_index(iif, vrf); zlog_debug( - "MCAST VRF: %s(%d) %s (%pI4,%pI4) IIF: %s(%d) OIF: %s jiffies: %lld", + "MCAST VRF: %s(%d) %s (%pIA,%pIA) IIF: %s(%d) OIF: %s jiffies: %lld", zvrf_name(zvrf), vrf, nl_msg_type_to_str(h->nlmsg_type), - &m->sg.src, &m->sg.grp, ifp ? ifp->name : "Unknown", - iif, oif_list, - m->lastused); + &m->src, &m->grp, ifp ? ifp->name : "Unknown", iif, + oif_list, m->lastused); } return 0; } @@ -2263,13 +2285,29 @@ int kernel_get_ipmr_sg_stats(struct zebra_vrf *zvrf, void *in) req.n.nlmsg_flags = NLM_F_REQUEST; req.n.nlmsg_pid = zns->netlink_cmd.snl.nl_pid; - req.ndm.ndm_family = RTNL_FAMILY_IPMR; req.n.nlmsg_type = RTM_GETROUTE; nl_attr_put32(&req.n, sizeof(req), RTA_IIF, mroute->ifindex); nl_attr_put32(&req.n, sizeof(req), RTA_OIF, mroute->ifindex); - nl_attr_put32(&req.n, sizeof(req), RTA_SRC, mroute->sg.src.s_addr); - nl_attr_put32(&req.n, sizeof(req), RTA_DST, mroute->sg.grp.s_addr); + + if (mroute->family == AF_INET) { + req.ndm.ndm_family = RTNL_FAMILY_IPMR; + nl_attr_put(&req.n, sizeof(req), RTA_SRC, + &mroute->src.ipaddr_v4, + sizeof(mroute->src.ipaddr_v4)); + nl_attr_put(&req.n, sizeof(req), RTA_DST, + &mroute->grp.ipaddr_v4, + sizeof(mroute->grp.ipaddr_v4)); + } else { + req.ndm.ndm_family = RTNL_FAMILY_IP6MR; + nl_attr_put(&req.n, sizeof(req), RTA_SRC, + &mroute->src.ipaddr_v6, + sizeof(mroute->src.ipaddr_v6)); + nl_attr_put(&req.n, sizeof(req), RTA_DST, + &mroute->grp.ipaddr_v6, + sizeof(mroute->grp.ipaddr_v6)); + } + /* * What? * diff --git a/zebra/zebra_mroute.c b/zebra/zebra_mroute.c index ef0f2d892..d9a94bb0c 100644 --- a/zebra/zebra_mroute.c +++ b/zebra/zebra_mroute.c @@ -39,20 +39,14 @@ void zebra_ipmr_route_stats(ZAPI_HANDLER_ARGS) int suc = -1; memset(&mroute, 0, sizeof(mroute)); - STREAM_GET(&mroute.sg.src, msg, 4); - STREAM_GET(&mroute.sg.grp, msg, 4); + STREAM_GET(&mroute.src.ipaddr_v4, msg, 4); + STREAM_GET(&mroute.grp.ipaddr_v4, msg, 4); STREAM_GETL(msg, mroute.ifindex); - if (IS_ZEBRA_DEBUG_KERNEL) { - char sbuf[40]; - char gbuf[40]; - - inet_ntop(AF_INET, &mroute.sg.src, sbuf, sizeof(sbuf)); - inet_ntop(AF_INET, &mroute.sg.grp, gbuf, sizeof(gbuf)); - - zlog_debug("Asking for (%s,%s)[%s(%u)] mroute information", - sbuf, gbuf, zvrf->vrf->name, zvrf->vrf->vrf_id); - } + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug("Asking for (%pI4,%pI4)[%s(%u)] mroute information", + &mroute.src.ipaddr_v4, &mroute.grp.ipaddr_v4, + zvrf->vrf->name, zvrf->vrf->vrf_id); suc = kernel_get_ipmr_sg_stats(zvrf, &mroute); @@ -62,8 +56,8 @@ stream_failure: stream_reset(s); zclient_create_header(s, ZEBRA_IPMR_ROUTE_STATS, zvrf_id(zvrf)); - stream_put_in_addr(s, &mroute.sg.src); - stream_put_in_addr(s, &mroute.sg.grp); + stream_put_in_addr(s, &mroute.src.ipaddr_v4); + stream_put_in_addr(s, &mroute.grp.ipaddr_v4); stream_put(s, &mroute.lastused, sizeof(mroute.lastused)); stream_putl(s, (uint32_t)suc); diff --git a/zebra/zebra_mroute.h b/zebra/zebra_mroute.h index 3c12b82da..6c56c2e41 100644 --- a/zebra/zebra_mroute.h +++ b/zebra/zebra_mroute.h @@ -29,7 +29,9 @@ extern "C" { #endif struct mcast_route_data { - struct prefix_sg sg; + int family; + struct ipaddr src; + struct ipaddr grp; unsigned int ifindex; unsigned long long lastused; }; |