]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: Fully decode mcast messages
authorDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 10 Aug 2016 12:54:58 +0000 (08:54 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 22 Dec 2016 01:26:06 +0000 (20:26 -0500)
Fully decode mcast messages from the kernel.  We are not
doing anything with this at the moment, but that will
change.

Additionally convert over to using lookup for
displaying the route type.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
lib/zebra.h
zebra/if_netlink.c
zebra/kernel_netlink.c
zebra/kernel_netlink.h
zebra/rt_netlink.c

index 5bb3590abde04f7a31bd72fa9a21fd71599f8694..1fc643d597eb5ecc7642d7f52c0a4775960ea4c3 100644 (file)
@@ -476,6 +476,24 @@ typedef enum {
 #define SAFI_ENCAP               7 /* per IANA */
 #define SAFI_MAX                  8
 
+/*
+ * The above AFI and SAFI definitions are for internal use. The protocol
+ * definitions (IANA values) as for example used in BGP protocol packets
+ * are defined below and these will get mapped to/from the internal values
+ * in the appropriate places.
+ * The rationale is that the protocol (IANA) values may be sparse and are
+ * not optimal for use in data-structure sizing.
+ * Note: Only useful (i.e., supported) values are defined below.
+ */
+typedef enum {
+  IANA_AFI_RESERVED = 0,
+  IANA_AFI_IPV4 = 1,
+  IANA_AFI_IPV6 = 2,
+  IANA_AFI_L2VPN = 25,
+  IANA_AFI_IPMR = 128,
+  IANA_AFI_IP6MR = 129
+} iana_afi_t;
+
 /* Default Administrative Distance of each protocol. */
 #define ZEBRA_KERNEL_DISTANCE_DEFAULT      0
 #define ZEBRA_CONNECT_DISTANCE_DEFAULT     0
index c5fd16b9cdd62fe072fc130b545ee282951547e1..180e8c5de6e2f6302abe4c03b8dec877b39b3fa8 100644 (file)
@@ -435,7 +435,7 @@ netlink_address (int cmd, int family, struct interface *ifp,
     addattr_l (&req.n, sizeof req, IFA_LABEL, ifc->label,
                strlen (ifc->label) + 1);
 
-  return netlink_talk (&req.n, &zns->netlink_cmd, zns);
+  return netlink_talk (netlink_talk_filter, &req.n, &zns->netlink_cmd, zns);
 }
 
 int
index 9142d4d151074736d784419d71915d1a4ed55983..20c4b5afe2d8fe1c48d6f6cafd2f535276cd25f1 100644 (file)
@@ -95,6 +95,21 @@ static const struct message rtproto_str[] = {
   {0,               NULL}
 };
 
+static const struct message family_str[] = {
+  {AF_INET,           "ipv4"},
+  {AF_INET6,          "ipv6"},
+  {AF_BRIDGE,         "bridge"},
+  {RTNL_FAMILY_IPMR,  "ipv4MR"},
+  {RTNL_FAMILY_IP6MR, "ipv6MR"},
+  {0,                 NULL},
+};
+
+static const struct message rttype_str[] = {
+  {RTN_UNICAST,   "unicast"},
+  {RTN_MULTICAST, "multicast"},
+  {0,             NULL},
+};
+
 extern struct thread_master *master;
 extern u_int32_t nl_rcvbufsize;
 
@@ -398,6 +413,19 @@ nl_rtproto_to_str (u_char rtproto)
 {
   return lookup (rtproto_str, rtproto);
 }
+
+const char *
+nl_family_to_str (u_char family)
+{
+  return lookup (family_str, family);
+}
+
+const char *
+nl_rttype_to_str (u_char rttype)
+{
+  return lookup (rttype_str, rttype);
+}
+
 /* Receive message from netlink interface and pass those information
    to the given function. */
 int
index f97e6e8ccc045442a434d0ea2ee2073dd75221a9..f17f1380c25c3aaf6ba59f20e771bd00dabdd3fc 100644 (file)
@@ -40,6 +40,8 @@ extern struct rtattr * rta_nest(struct rtattr *rta, int maxlen, int type);
 extern int rta_nest_end(struct rtattr *rta, struct rtattr *nest);
 extern const char * nl_msg_type_to_str (uint16_t msg_type);
 extern const char * nl_rtproto_to_str (u_char rtproto);
+extern const char * nl_family_to_str (u_char family);
+extern const char * nl_rttype_to_str (u_char rttype);
 
 extern int netlink_parse_info (int (*filter) (struct sockaddr_nl *,
                                struct nlmsghdr *, ns_id_t), struct nlsock *nl,
index b032c2a31c5291564740c248b781dd18b4e6a32c..ff907bb8784f05077976bd27192dd59a2affe9ac 100644 (file)
@@ -303,14 +303,6 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h,
   return 0;
 }
 
-static const struct message family_str[] = {
-  {AF_INET,           "ipv4"},
-  {AF_INET6,          "ipv6"},
-  {RTNL_FAMILY_IPMR,  "ipv4MR"},
-  {RTNL_FAMILY_IP6MR, "ipv6MR"},
-  {0,                 NULL},
-};
-
 /* Routing information change from the kernel. */
 static int
 netlink_route_change_read_unicast (struct sockaddr_nl *snl, struct nlmsghdr *h,
@@ -421,7 +413,7 @@ netlink_route_change_read_unicast (struct sockaddr_nl *snl, struct nlmsghdr *h,
         {
           char buf[PREFIX_STRLEN];
           zlog_debug ("%s %s vrf %u",
-                      h->nlmsg_type == RTM_NEWROUTE ? "RTM_NEWROUTE" : "RTM_DELROUTE",
+                      nl_msg_type_to_str (h->nlmsg_type),
                       prefix2str (&p, buf, sizeof(buf)), vrf_id);
         }
 
@@ -508,7 +500,7 @@ netlink_route_change_read_unicast (struct sockaddr_nl *snl, struct nlmsghdr *h,
         {
          char buf[PREFIX_STRLEN];
           zlog_debug ("%s %s vrf %u",
-                      h->nlmsg_type == RTM_NEWROUTE ? "RTM_NEWROUTE" : "RTM_DELROUTE",
+                      nl_msg_type_to_str (h->nlmsg_type),
                       prefix2str (&p, buf, sizeof(buf)), vrf_id);
         }
 
@@ -529,8 +521,20 @@ netlink_route_change_read_multicast (struct sockaddr_nl *snl, struct nlmsghdr *h
                                     ns_id_t ns_id)
 {
   int len;
+  unsigned long long lastused = 0;
   struct rtmsg *rtm;
   struct rtattr *tb[RTA_MAX + 1];
+  struct prefix_sg sg;
+  int iif = 0;
+  int count;
+  int oif[256];
+  int oif_count = 0;
+  char sbuf[40];
+  char gbuf[40];
+  char oif_list[256] = "\0";
+  memset (&sg, 0, sizeof (sg));
+  sg.family = IANA_AFI_IPMR;
+  vrf_id_t vrf = ns_id;
 
   rtm = NLMSG_DATA (h);
 
@@ -539,6 +543,52 @@ netlink_route_change_read_multicast (struct sockaddr_nl *snl, struct nlmsghdr *h
   memset (tb, 0, sizeof tb);
   netlink_parse_rtattr (tb, RTA_MAX, RTM_RTA (rtm), len);
 
+  if (tb[RTA_IIF])
+    iif = *(int *)RTA_DATA (tb[RTA_IIF]);
+
+  if (tb[RTA_SRC])
+    sg.src = *(struct in_addr *)RTA_DATA (tb[RTA_SRC]);
+
+  if (tb[RTA_DST])
+    sg.grp = *(struct in_addr *)RTA_DATA (tb[RTA_DST]);
+
+  if (tb[RTA_EXPIRES])
+    lastused = *(unsigned long long *)RTA_DATA (tb[RTA_EXPIRES]);
+
+  if (tb[RTA_MULTIPATH])
+    {
+      struct rtnexthop *rtnh =
+        (struct rtnexthop *)RTA_DATA (tb[RTA_MULTIPATH]);
+
+      len = RTA_PAYLOAD (tb[RTA_MULTIPATH]);
+      for (;;)
+        {
+          if (len < (int) sizeof (*rtnh) || rtnh->rtnh_len > len)
+           break;
+
+         oif[oif_count] = rtnh->rtnh_ifindex;
+          oif_count++;
+
+         len -= NLMSG_ALIGN (rtnh->rtnh_len);
+         rtnh = RTNH_NEXT (rtnh);
+        }
+    }
+
+  if (IS_ZEBRA_DEBUG_KERNEL)
+    {
+      strcpy (sbuf, inet_ntoa (sg.src));
+      strcpy (gbuf, inet_ntoa (sg.grp));
+      for (count = 0; count < oif_count; count++)
+       {
+         struct interface *ifp = if_lookup_by_index_vrf (oif[count], vrf);
+         char temp[256];
+
+         sprintf (temp, "%s ", ifp->name);
+         strcat (oif_list, temp);
+       }
+      zlog_debug ("MCAST %s (%s,%s) IIF: %d OIF: %s jiffies: %lld",
+                 nl_msg_type_to_str (h->nlmsg_type), sbuf, gbuf, iif, oif_list, lastused);
+    }
   return 0;
 }
 
@@ -562,12 +612,11 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h,
   /* Connected route. */
   if (IS_ZEBRA_DEBUG_KERNEL)
     zlog_debug ("%s %s %s proto %s vrf %u",
-               h->nlmsg_type ==
-               RTM_NEWROUTE ? "RTM_NEWROUTE" : "RTM_DELROUTE",
-               lookup (family_str, rtm->rtm_family),
-               rtm->rtm_type == RTN_UNICAST ? "unicast" : "multicast",
+               nl_msg_type_to_str (h->nlmsg_type),
+               nl_family_to_str (rtm->rtm_family),
+               nl_rttype_to_str (rtm->rtm_type),
                nl_rtproto_to_str (rtm->rtm_protocol),
-               vrf_id);
+               vrf_id);
 
   /* We don't care about change notifications for the MPLS table. */
   /* TODO: Revisit this. */