Browse Source

ripd: add support for route tags

Christian Franke 3 years ago
parent
commit
2bbacea824
4 changed files with 25 additions and 10 deletions
  1. 3 3
      ripd/rip_interface.c
  2. 14 3
      ripd/rip_zebra.c
  3. 5 2
      ripd/ripd.c
  4. 3 2
      ripd/ripd.h

+ 3 - 3
ripd/rip_interface.c

@@ -634,7 +634,7 @@ rip_apply_address_add (struct connected *ifc)
   if ((rip_enable_if_lookup(ifc->ifp->name) >= 0) ||
       (rip_enable_network_lookup2(ifc) >= 0))
     rip_redistribute_add(ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE,
-                         &address, ifc->ifp->ifindex, NULL, 0, 0);
+                         &address, ifc->ifp->ifindex, NULL, 0, 0, 0);
 
 }
 
@@ -945,7 +945,7 @@ rip_connect_set (struct interface *ifp, int set)
             (rip_enable_network_lookup2(connected) >= 0))
           rip_redistribute_add (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE,
                                 &address, connected->ifp->ifindex, 
-                                NULL, 0, 0);
+                                NULL, 0, 0, 0);
       } else
         {
           rip_redistribute_delete (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE,
@@ -953,7 +953,7 @@ rip_connect_set (struct interface *ifp, int set)
           if (rip_redistribute_check (ZEBRA_ROUTE_CONNECT))
             rip_redistribute_add (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_REDISTRIBUTE,
                                   &address, connected->ifp->ifindex,
-                                  NULL, 0, 0);
+                                  NULL, 0, 0, 0);
         }
     }
 }

+ 14 - 3
ripd/rip_zebra.c

@@ -90,6 +90,12 @@ rip_zebra_ipv4_send (struct route_node *rp, u_char cmd)
           api.distance = rinfo->distance;
         }
 
+      if (rinfo->tag)
+        {
+          SET_FLAG (api.message, ZAPI_MESSAGE_TAG);
+          api.tag = rinfo->tag;
+        }
+
       zapi_ipv4_route (cmd, zclient,
                        (struct prefix_ipv4 *)&rp->p, &api);
 
@@ -173,11 +179,16 @@ rip_zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length,
   else
     api.metric = 0;
 
+  if (CHECK_FLAG (api.message, ZAPI_MESSAGE_TAG))
+    api.tag = stream_getl (s);
+  else
+    api.tag = 0;
+
   /* Then fetch IPv4 prefixes. */
   if (command == ZEBRA_IPV4_ROUTE_ADD)
     rip_redistribute_add (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex, 
-                          &nexthop, api.metric, api.distance);
-  else 
+                          &nexthop, api.metric, api.distance, api.tag);
+  else
     rip_redistribute_delete (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex);
 
   return 0;
@@ -612,7 +623,7 @@ DEFUN (rip_default_information_originate,
       rip->default_information = 1;
   
       rip_redistribute_add (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0, 
-                            NULL, 0, 0);
+                            NULL, 0, 0, 0);
     }
 
   return CMD_SUCCESS;

+ 5 - 2
ripd/ripd.c

@@ -1510,7 +1510,8 @@ rip_send_packet (u_char * buf, int size, struct sockaddr_in *to,
 void
 rip_redistribute_add (int type, int sub_type, struct prefix_ipv4 *p, 
 		      ifindex_t ifindex, struct in_addr *nexthop,
-                      unsigned int metric, unsigned char distance)
+                      unsigned int metric, unsigned char distance,
+                      route_tag_t tag)
 {
   int ret;
   struct route_node *rp = NULL;
@@ -1531,6 +1532,8 @@ rip_redistribute_add (int type, int sub_type, struct prefix_ipv4 *p,
   newinfo.metric = 1;
   newinfo.external_metric = metric;
   newinfo.distance = distance;
+  if (tag <= UINT16_MAX) /* RIP only supports 16 bit tags */
+    newinfo.tag = tag;
   newinfo.rp = rp;
   if (nexthop)
     newinfo.nexthop = *nexthop;
@@ -2939,7 +2942,7 @@ DEFUN (rip_route,
 
   node->info = (char *)"static";
 
-  rip_redistribute_add (ZEBRA_ROUTE_RIP, RIP_ROUTE_STATIC, &p, 0, NULL, 0, 0);
+  rip_redistribute_add (ZEBRA_ROUTE_RIP, RIP_ROUTE_STATIC, &p, 0, NULL, 0, 0, 0);
 
   return CMD_SUCCESS;
 }

+ 3 - 2
ripd/ripd.h

@@ -400,8 +400,9 @@ extern int rip_request_send (struct sockaddr_in *, struct interface *, u_char,
 extern int rip_neighbor_lookup (struct sockaddr_in *);
 
 extern int rip_redistribute_check (int);
-extern void rip_redistribute_add (int, int, struct prefix_ipv4 *, ifindex_t, 
-			   struct in_addr *, unsigned int, unsigned char);
+extern void rip_redistribute_add (int, int, struct prefix_ipv4 *, ifindex_t,
+			   struct in_addr *, unsigned int, unsigned char,
+			   route_tag_t);
 extern void rip_redistribute_delete (int, int, struct prefix_ipv4 *, ifindex_t);
 extern void rip_redistribute_withdraw (int);
 extern void rip_zebra_ipv4_add (struct route_node *);