]> git.proxmox.com Git - mirror_frr.git/commitdiff
*: Add source of route as protocol string in ip route pushed into kernel
authorDinesh G Dutt <ddutt@cumulusnetworks.com>
Wed, 11 Jan 2017 22:33:39 +0000 (14:33 -0800)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Mon, 30 Jan 2017 18:40:53 +0000 (13:40 -0500)
Ticket: CM-14313
Reviewed By:
Testing Done: bgpmin, ospfmin, bgp_kitchen_sink_test

'ip route show' displays all routes as belonging to protocol zebra.
The user has to run an additional command (in vtysh) to get the actual
source of a route (bgp/ospf/static etc.). This patch addresses that by
pushing the appropriate protocol string into the protocol field of the
netlink route update message. Now you can see routes with the correct
origin as well as filter on them (ip route show proto ospf).

'ospf' is used for both IPv4 and IPv6 routes, even though the OSPF
version is different in both cases.

Sample output (old):
9.9.12.13 via 69.254.2.38 dev swp3.2  proto zebra  metric 20
9.9.13.3  proto zebra  metric 20
        nexthop via 69.254.2.30  dev swp1.2 weight 1
        nexthop via 69.254.2.34  dev swp2.2 weight 1
        nexthop via 69.254.2.38  dev swp3.2 weight 1

Sample output (new):
9.9.12.13 via 69.254.2.38 dev swp3.2  proto bgp  metric 20
9.9.13.3  proto bgp  metric 20
        nexthop via 69.254.2.30  dev swp1.2 weight 1
        nexthop via 69.254.2.34  dev swp2.2 weight 1
        nexthop via 69.254.2.38  dev swp3.2 weight 1

Signed-off-by: Dinesh Dutt <ddutt@cumulusnetworks.com>
cumulus/etc/iproute2/rt_protos.d/frr.conf [new file with mode: 0644]
debian/frr.dirs
tools/frr
zebra/kernel_netlink.c
zebra/rt_netlink.c
zebra/rt_netlink.h

diff --git a/cumulus/etc/iproute2/rt_protos.d/frr.conf b/cumulus/etc/iproute2/rt_protos.d/frr.conf
new file mode 100644 (file)
index 0000000..883782e
--- /dev/null
@@ -0,0 +1,8 @@
+# Additional protocol strings defined by quagga for each of its daemons
+
+186  bgp
+187  isis
+188  ospf
+189  rip
+190  ripng
+191  static
index 58290080d00d9e510983ee466d8db3d636406a6d..56699b2daa261c39d5e82d9f840beee7f7df4b6e 100644 (file)
@@ -1,5 +1,6 @@
 etc/logrotate.d/
 etc/frr/
+etc/iproute2/rt_protos.d/
 usr/share/doc/frr/
 usr/share/doc/frr/examples/
 usr/share/lintian/overrides/
index 2ecaadbb5382a848edd438b3d5896bebc1ee683e..a6d99feaf652bcb5512bef6d84fb4415a7f5aefd 100755 (executable)
--- a/tools/frr
+++ b/tools/frr
@@ -532,8 +532,15 @@ case "$1" in
         fi
 
         if [ -z "$dmn" -o "$dmn" = "zebra" ]; then
-          echo "Removing all routes made by zebra."
+          echo "Removing all routes made by quagga."
+          ip route flush proto bgp
+          ip route flush proto ospf
+          ip route flush proto static
+          ip route flush proto rip
+          ip route flush proto ripng
           ip route flush proto zebra
+          ip route flush proto isis
+
        else
          [ -n "$dmn" ] && eval "${dmn/-/_}=0"
          start_watchfrr
index 9f9a62f384654bd4bf08fe5ce8405539cd6b2779..20cb62e3183afbf0fd2e4c9b6a26f063fe9f406b 100644 (file)
@@ -91,6 +91,11 @@ static const struct message rtproto_str[] = {
 #ifdef RTPROT_BIRD
   {RTPROT_BIRD,     "BIRD"},
 #endif /* RTPROT_BIRD */
+  {RTPROT_BGP,      "BGP"},
+  {RTPROT_OSPF,     "OSPF"},
+  {RTPROT_ISIS,     "IS-IS"},
+  {RTPROT_RIP,      "RIP"},
+  {RTPROT_RIPNG,    "RIPNG"},
   {0,               NULL}
 };
 
index c04f9188fab183206e16d9565cdf9f5abc6ab2a7..01922e1ad59032fa145e7c4f3b2fc72eea4a9045 100644 (file)
@@ -92,6 +92,47 @@ struct gw_family_t
   union g_addr  gate;
 };
 
+static inline int is_selfroute(int proto)
+{
+  if ((proto == RTPROT_BGP) || (proto == RTPROT_OSPF) ||
+      (proto == RTPROT_STATIC) || (proto == RTPROT_ZEBRA) ||
+      (proto == RTPROT_ISIS) || (proto == RTPROT_RIPNG)) {
+    return 1;
+  }
+
+  return 0;
+}
+
+static inline int get_rt_proto(int proto)
+{
+  switch (proto) {
+  case ZEBRA_ROUTE_BGP:
+    proto = RTPROT_BGP;
+    break;
+  case ZEBRA_ROUTE_OSPF:
+  case ZEBRA_ROUTE_OSPF6:
+    proto = RTPROT_OSPF;
+    break;
+  case ZEBRA_ROUTE_STATIC:
+    proto = RTPROT_STATIC;
+    break;
+  case ZEBRA_ROUTE_ISIS:
+    proto = RTPROT_ISIS;
+    break;
+  case ZEBRA_ROUTE_RIP:
+    proto = RTPROT_RIP;
+    break;
+  case ZEBRA_ROUTE_RIPNG:
+    proto = RTPROT_RIPNG;
+    break;
+  default:
+    proto = RTPROT_ZEBRA;
+    break;
+  }
+
+  return proto;
+}
+
 /*
 Pending: create an efficient table_id (in a tree/hash) based lookup)
  */
@@ -181,7 +222,7 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h,
     }
 
   /* Route which inserted by Zebra. */
-  if (rtm->rtm_protocol == RTPROT_ZEBRA)
+  if (is_selfroute(rtm->rtm_protocol))
     flags |= ZEBRA_FLAG_SELFROUTE;
 
   index = 0;
@@ -367,9 +408,9 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h,
   if (rtm->rtm_protocol == RTPROT_KERNEL)
     return 0;
 
-  if (rtm->rtm_protocol == RTPROT_ZEBRA && h->nlmsg_type == RTM_NEWROUTE)
+  if (is_selfroute(rtm->rtm_protocol) && h->nlmsg_type == RTM_NEWROUTE)
     return 0;
-  if (rtm->rtm_protocol == RTPROT_ZEBRA)
+  if (is_selfroute(rtm->rtm_protocol))
     SET_FLAG(zebra_flags, ZEBRA_FLAG_SELFROUTE);
 
   if (rtm->rtm_src_len != 0)
@@ -1151,7 +1192,7 @@ netlink_route_multipath (int cmd, struct prefix *p, struct rib *rib,
   req.n.nlmsg_type = cmd;
   req.r.rtm_family = family;
   req.r.rtm_dst_len = p->prefixlen;
-  req.r.rtm_protocol = RTPROT_ZEBRA;
+  req.r.rtm_protocol = get_rt_proto(rib->type);
   req.r.rtm_scope = RT_SCOPE_UNIVERSE;
 
   if ((rib->flags & ZEBRA_FLAG_BLACKHOLE) || (rib->flags & ZEBRA_FLAG_REJECT))
index 7183525fba6ec8c48052afb6893f78833233cdbb..d1f01bda4c2cbf8cb3cbb21adb6f9b91a513db9c 100644 (file)
 
 #define NL_DEFAULT_ROUTE_METRIC 20
 
+/* Additional protocol strings to push into routes */
+#define RTPROT_BGP         186
+#define RTPROT_ISIS        187
+#define RTPROT_OSPF        188
+#define RTPROT_RIP         189
+#define RTPROT_RIPNG       190
+
+
 extern void
 clear_nhlfe_installed (zebra_lsp_t *lsp);
 extern int