Browse Source

*: Widen width of Zserv routing tag field.

* lib/zebra.h: Introduce a route_tag_t type for route tags generally,
  and make it 4 bytes wide - so it can directly hold things like an ASN, or
  the OSPF ASE-LSA tag.
* zebra/rib.h: Use route_tag_t instead of u_short.
* *: Update 'u_short (*)?(tag|tmp)' to use route_tag_t instead of u_short.
  Update stream_{get,put} to l instead of w.
* ospf_zebra.c: (ospf_zebra_add) test OSPF tag within range of ROUTE_TAG_MAX.
Paul Jakma 3 years ago
parent
commit
96d1060a70

+ 1 - 1
bgpd/bgp_attr.h

@@ -94,7 +94,7 @@ struct attr_extra
   struct bgp_attr_encap_subtlv *encap_subtlvs;		/* rfc5512 */
 
   /* route tag */
-  u_short tag;
+  route_tag_t tag;
 };
 
 /* BGP core attribute structure. */

+ 1 - 1
bgpd/bgp_route.c

@@ -5605,7 +5605,7 @@ ALIAS (no_ipv6_aggregate_address_summary_only,
 void
 bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
 		      const struct in6_addr *nexthop6,
-		      u_int32_t metric, u_char type, u_short tag)
+		      u_int32_t metric, u_char type, route_tag_t tag)
 {
   struct bgp *bgp;
   struct listnode *node, *nnode;

+ 1 - 1
bgpd/bgp_route.h

@@ -221,7 +221,7 @@ extern int bgp_maximum_prefix_overflow (struct peer *, afi_t, safi_t, int);
 
 extern void bgp_redistribute_add (struct prefix *, const struct in_addr *,
 				  const struct in6_addr *,
-				  u_int32_t, u_char, u_short);
+				  u_int32_t, u_char, route_tag_t);
 extern void bgp_redistribute_delete (struct prefix *, u_char);
 extern void bgp_redistribute_withdraw (struct bgp *, afi_t, int);
 

+ 6 - 6
bgpd/bgp_routemap.c

@@ -1009,7 +1009,7 @@ static route_map_result_t
 route_match_tag (void *rule, struct prefix *prefix,
                  route_map_object_t type, void *object)
 {
-  u_short *tag;
+  route_tag_t *tag;
   struct bgp_info *bgp_info;
 
   if (type == RMAP_BGP)
@@ -1031,8 +1031,8 @@ route_match_tag (void *rule, struct prefix *prefix,
 static void *
 route_match_tag_compile (const char *arg)
 {
-  u_short *tag;
-  u_short tmp;
+  route_tag_t *tag;
+  route_tag_t tmp;
 
   /* tag value shoud be integer. */
   if (! all_digit (arg))
@@ -1848,7 +1848,7 @@ static route_map_result_t
 route_set_tag (void *rule, struct prefix *prefix,
                route_map_object_t type, void *object)
 {
-  u_short *tag;
+  route_tag_t *tag;
   struct bgp_info *bgp_info;
   struct attr_extra *ae;
 
@@ -1870,8 +1870,8 @@ route_set_tag (void *rule, struct prefix *prefix,
 static void *
 route_set_tag_compile (const char *arg)
 {
-  u_short *tag;
-  u_short tmp;
+  route_tag_t *tag;
+  route_tag_t tmp;
 
   /* tag value shoud be integer. */
   if (! all_digit (arg))

+ 3 - 3
bgpd/bgp_zebra.c

@@ -279,7 +279,7 @@ zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length,
     api.metric = 0;
 
   if (CHECK_FLAG (api.message, ZAPI_MESSAGE_TAG))
-    api.tag = stream_getw (s);
+    api.tag = stream_getl (s);
   else
     api.tag = 0;
 
@@ -366,7 +366,7 @@ zebra_read_ipv6 (int command, struct zclient *zclient, zebra_size_t length,
     api.metric = 0;
 
   if (CHECK_FLAG (api.message, ZAPI_MESSAGE_TAG))
-    api.tag = stream_getw (s);
+    api.tag = stream_getl (s);
   else
     api.tag = 0;
 
@@ -694,7 +694,7 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, sa
   struct bgp_info *mpinfo;
   size_t oldsize, newsize;
   u_int32_t nhcount;
-  u_short tag = 0;
+  route_tag_t tag = 0;
 
   if (zclient->sock < 0)
     return;

+ 2 - 2
lib/zclient.c

@@ -591,7 +591,7 @@ zapi_ipv4_route (u_char cmd, struct zclient *zclient, struct prefix_ipv4 *p,
   if (CHECK_FLAG (api->message, ZAPI_MESSAGE_MTU))
     stream_putl (s, api->mtu);
   if (CHECK_FLAG (api->message, ZAPI_MESSAGE_TAG))
-    stream_putw (s, api->tag);
+    stream_putl (s, api->tag);
 
   /* Put length at the first point of the stream. */
   stream_putw_at (s, 0, stream_get_endp (s));
@@ -649,7 +649,7 @@ zapi_ipv6_route (u_char cmd, struct zclient *zclient, struct prefix_ipv6 *p,
   if (CHECK_FLAG (api->message, ZAPI_MESSAGE_MTU))
     stream_putl (s, api->mtu);
   if (CHECK_FLAG (api->message, ZAPI_MESSAGE_TAG))
-    stream_putw (s, api->tag);
+    stream_putl (s, api->tag);
 
   /* Put length at the first point of the stream. */
   stream_putw_at (s, 0, stream_get_endp (s));

+ 2 - 2
lib/zclient.h

@@ -133,7 +133,7 @@ struct zapi_ipv4
 
   u_char distance;
 
-  u_short tag;
+  route_tag_t tag;
 
   u_int32_t metric;
 
@@ -213,7 +213,7 @@ struct zapi_ipv6
 
   u_char distance;
 
-  u_short tag;
+  route_tag_t tag;
 
   u_int32_t metric;
 

+ 3 - 0
lib/zebra.h

@@ -535,4 +535,7 @@ typedef u_int16_t zebra_command_t;
 /* VRF ID type. */
 typedef u_int16_t vrf_id_t;
 
+typedef uint32_t route_tag_t;
+#define ROUTE_TAG_MAX UINT32_MAX
+
 #endif /* _ZEBRA_H */

+ 1 - 1
ospfd/ospf_asbr.c

@@ -136,7 +136,7 @@ ospf_route_map_set_compare (struct route_map_set_values *values1,
 struct external_info *
 ospf_external_info_add (u_char type, struct prefix_ipv4 p,
 			ifindex_t ifindex, struct in_addr nexthop,
-                        u_short tag)
+                        route_tag_t tag)
 {
   struct external_info *new;
   struct route_node *rn;

+ 1 - 1
ospfd/ospf_asbr.h

@@ -63,7 +63,7 @@ extern struct external_info *ospf_external_info_add (u_char,
                                               struct prefix_ipv4,
 					      ifindex_t, 
 					      struct in_addr,
-					      u_short);
+					      route_tag_t);
 extern void ospf_external_info_delete (u_char, struct prefix_ipv4);
 extern struct external_info *ospf_external_info_lookup (u_char, 
                                                  struct prefix_ipv4 *);

+ 1 - 1
ospfd/ospf_lsa.c

@@ -1649,7 +1649,7 @@ ospf_external_lsa_body_set (struct stream *s, struct external_info *ei,
   /* Put forwarding address. */
   stream_put_ipv4 (s, fwd_addr.s_addr);
   
-  /* Put route tag -- only first 16bits are used for compatibility */
+  /* Put route tag */
   stream_putl (s, ei->tag);
 }
 

+ 6 - 6
ospfd/ospf_routemap.c

@@ -422,7 +422,7 @@ static route_map_result_t
 route_match_tag (void *rule, struct prefix *prefix,
                  route_map_object_t type, void *object)
 {
-  u_short *tag;
+  route_tag_t *tag;
   struct external_info *ei;
 
   if (type == RMAP_OSPF)
@@ -440,8 +440,8 @@ route_match_tag (void *rule, struct prefix *prefix,
 static void *
 route_match_tag_compile (const char *arg)
 {
-  u_short *tag;
-  u_short tmp;
+  route_tag_t *tag;
+  route_tag_t tmp;
 
   /* tag value shoud be integer. */
   if (! all_digit (arg))
@@ -596,7 +596,7 @@ static route_map_result_t
 route_set_tag (void *rule, struct prefix *prefix,
                route_map_object_t type, void *object)
 {
-  u_short *tag;
+  route_tag_t *tag;
   struct external_info *ei;
 
   if (type == RMAP_OSPF)
@@ -615,8 +615,8 @@ route_set_tag (void *rule, struct prefix *prefix,
 static void *
 route_set_tag_compile (const char *arg)
 {
-  u_short *tag;
-  u_short tmp;
+  route_tag_t *tag;
+  route_tag_t tmp;
 
   /* tag value shoud be integer. */
   if (! all_digit (arg))

+ 4 - 4
ospfd/ospf_zebra.c

@@ -370,10 +370,10 @@ ospf_zebra_add (struct prefix_ipv4 *p, struct ospf_route *or)
       if (distance)
         SET_FLAG (message, ZAPI_MESSAGE_DISTANCE);
 
-      /* Check if path type is ASE and use only 16bit tags */
+      /* Check if path type is ASE */
       if (((or->path_type == OSPF_PATH_TYPE1_EXTERNAL) ||
           (or->path_type == OSPF_PATH_TYPE2_EXTERNAL)) &&
-           (or->u.ext.tag > 0) && (or->u.ext.tag < UINT16_MAX))
+           (or->u.ext.tag > 0) && (or->u.ext.tag <= ROUTE_TAG_MAX))
         SET_FLAG (message, ZAPI_MESSAGE_TAG);
 
       /* Make packet. */
@@ -444,7 +444,7 @@ ospf_zebra_add (struct prefix_ipv4 *p, struct ospf_route *or)
         }
 
       if (CHECK_FLAG (message, ZAPI_MESSAGE_TAG))
-         stream_putw (s, (u_short)or->u.ext.tag);
+         stream_putl (s, or->u.ext.tag);
 
       stream_putw_at (s, 0, stream_get_endp (s));
 
@@ -900,7 +900,7 @@ ospf_zebra_read_ipv4 (int command, struct zclient *zclient,
   if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
     api.metric = stream_getl (s);
   if (CHECK_FLAG (api.message, ZAPI_MESSAGE_TAG))
-    api.tag = stream_getw (s);
+    api.tag = stream_getl (s);
   else
     api.tag = 0;
 

+ 1 - 1
ospfd/ospfd.h

@@ -239,7 +239,7 @@ struct ospf
   } dmetric [ZEBRA_ROUTE_MAX + 1];
 
   /* Redistribute tag info. */
-  u_short dtag [ZEBRA_ROUTE_MAX + 1];
+  route_tag_t dtag [ZEBRA_ROUTE_MAX + 1];
 
   /* For redistribute route map. */
   struct

+ 5 - 5
ripd/rip_routemap.c

@@ -463,7 +463,7 @@ static route_map_result_t
 route_match_tag (void *rule, struct prefix *prefix, 
 		    route_map_object_t type, void *object)
 {
-  u_short *tag;
+  route_tag_t *tag;
   struct rip_info *rinfo;
 
   if (type == RMAP_RIP)
@@ -484,8 +484,8 @@ route_match_tag (void *rule, struct prefix *prefix,
 static void *
 route_match_tag_compile (const char *arg)
 {
-  u_short *tag;
-  u_short tmp;
+  route_tag_t *tag;
+  route_tag_t tmp;
 
   /* tag value shoud be integer. */
   if (! all_digit (arg))
@@ -687,7 +687,7 @@ static route_map_result_t
 route_set_tag (void *rule, struct prefix *prefix, 
 		      route_map_object_t type, void *object)
 {
-  u_short *tag;
+  route_tag_t *tag;
   struct rip_info *rinfo;
 
   if(type == RMAP_RIP)
@@ -708,7 +708,7 @@ route_set_tag (void *rule, struct prefix *prefix,
 static void *
 route_set_tag_compile (const char *arg)
 {
-  u_short *tag;
+  route_tag_t *tag;
 
   tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_short));
   *tag = atoi (arg);

+ 13 - 10
zebra/rib.h

@@ -23,6 +23,7 @@
 #ifndef _ZEBRA_RIB_H
 #define _ZEBRA_RIB_H
 
+#include "zebra.h"
 #include "linklist.h"
 #include "prefix.h"
 #include "table.h"
@@ -43,6 +44,9 @@ struct rib
   /* Refrence count. */
   unsigned long refcnt;
   
+  /* Tag */
+  route_tag_t tag;
+
   /* Uptime. */
   time_t uptime;
 
@@ -65,9 +69,6 @@ struct rib
   /* Distance. */
   u_char distance;
 
-  /* Tag */
-  u_short tag;
-
   /* Flags of this route.
    * This flag's definition is in lib/zebra.h ZEBRA_FLAG_* and is exposed
    * to clients via Zserv
@@ -182,7 +183,7 @@ struct static_route
   u_char distance;
 
   /* Tag */
-  u_short tag;
+  route_tag_t tag;
 
   /* Flag for this static route's type. */
   u_char type;
@@ -450,11 +451,12 @@ extern unsigned long rib_score_proto (u_char proto);
 
 extern int
 static_add_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
-		      const char *ifname, u_char flags, u_short tag, u_char distance,
-		      vrf_id_t vrf_id);
+		      const char *ifname, u_char flags, route_tag_t, 
+		      u_char distance, vrf_id_t vrf_id);
 extern int
 static_delete_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
-			 const char *ifname, u_short tag, u_char distance, vrf_id_t vrf_id);
+			 const char *ifname, route_tag_t tag, u_char distance,
+			 vrf_id_t vrf_id);
 
 extern int
 rib_add_ipv6 (int type, int flags, struct prefix_ipv6 *p,
@@ -474,15 +476,16 @@ extern struct route_table *rib_table_ipv6;
 
 extern int
 static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
-		 const char *ifname, u_char flags, u_short tag, u_char distance,
-		 vrf_id_t vrf_id);
+		 const char *ifname, u_char flags, route_tag_t, 
+		 u_char distance, vrf_id_t vrf_id);
 
 extern int
 rib_add_ipv6_multipath (struct prefix_ipv6 *, struct rib *, safi_t);
 
 extern int
 static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
-		    const char *ifname, u_short tag, u_char distance, vrf_id_t vrf_id);
+		    const char *ifname, route_tag_t, u_char distance, 
+		    vrf_id_t vrf_id);
 
 extern int rib_gc_dest (struct route_node *rn);
 extern struct route_table *rib_tables_iter_next (rib_tables_iter_t *iter);

+ 7 - 5
zebra/zebra_rib.c

@@ -2314,8 +2314,8 @@ static_uninstall_route (afi_t afi, safi_t safi, struct prefix *p, struct static_
 
 int
 static_add_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
-		      const char *ifname, u_char flags, u_short tag, u_char distance,
-		      vrf_id_t vrf_id)
+		      const char *ifname, u_char flags, route_tag_t tag,
+		      u_char distance, vrf_id_t vrf_id)
 {
   u_char type = 0;
   struct route_node *rn;
@@ -2411,7 +2411,8 @@ static_add_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
 
 int
 static_delete_ipv4_safi (safi_t safi, struct prefix *p, struct in_addr *gate,
-			 const char *ifname, u_short tag, u_char distance, vrf_id_t vrf_id)
+			 const char *ifname, route_tag_t tag, u_char distance,
+			 vrf_id_t vrf_id)
 {
   u_char type = 0;
   struct route_node *rn;
@@ -2797,7 +2798,7 @@ rib_delete_ipv6 (int type, int flags, struct prefix_ipv6 *p,
 /* Add static route into static route configuration. */
 int
 static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
-		 const char *ifname, u_char flags, u_short tag,
+		 const char *ifname, u_char flags, route_tag_t tag,
 		 u_char distance, vrf_id_t vrf_id)
 {
   struct route_node *rn;
@@ -2895,7 +2896,8 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
 /* Delete static route from static route configuration. */
 int
 static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
-		    const char *ifname, u_short tag, u_char distance, vrf_id_t vrf_id)
+		    const char *ifname, route_tag_t tag, u_char distance,
+		    vrf_id_t vrf_id)
 {
   struct route_node *rn;
   struct static_route *si;

+ 4 - 4
zebra/zebra_vty.c

@@ -54,7 +54,7 @@ zebra_static_ipv4_safi (struct vty *vty, safi_t safi, int add_cmd,
   struct in_addr mask;
   const char *ifname;
   u_char flag = 0;
-  u_short tag = 0;
+  route_tag_t tag = 0;
   vrf_id_t vrf_id = VRF_DEFAULT;
   
   ret = str2prefix (dest_str, &p);
@@ -2451,7 +2451,7 @@ DEFUN (show_ip_route_tag,
   struct route_node *rn;
   struct rib *rib;
   int first = 1;
-  u_short tag = 0;
+  route_tag_t tag = 0;
   vrf_id_t vrf_id = VRF_DEFAULT;
 
   if (argv[0])
@@ -3386,7 +3386,7 @@ static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str,
   u_char type = 0;
   vrf_id_t vrf_id = VRF_DEFAULT;
   u_char flag = 0;
-  u_short tag = 0;
+  route_tag_t tag = 0;
   
   ret = str2prefix (dest_str, &p);
   if (ret <= 0)
@@ -4496,7 +4496,7 @@ DEFUN (show_ipv6_route_tag,
   struct route_node *rn;
   struct rib *rib;
   int first = 1;
-  u_short tag = 0;
+  route_tag_t tag = 0;
   vrf_id_t vrf_id = VRF_DEFAULT;
 
   if (argv[0])

+ 5 - 5
zebra/zserv.c

@@ -498,7 +498,7 @@ zsend_route_multipath (int cmd, struct zserv *client, struct prefix *p,
       if (rib->tag)
         {
           SET_FLAG(zapi_flags, ZAPI_MESSAGE_TAG);
-          stream_putw(s, rib->tag);
+          stream_putl (s, rib->tag);
         }
     }
   
@@ -1011,7 +1011,7 @@ zread_ipv4_add (struct zserv *client, u_short length, vrf_id_t vrf_id)
     rib->mtu = stream_getl (s);
   /* Tag */
   if (CHECK_FLAG (message, ZAPI_MESSAGE_TAG))
-    rib->tag = stream_getw (s);
+    rib->tag = stream_getl (s);
 
   /* Table */
   rib->table=zebrad.rtm_table_default;
@@ -1098,7 +1098,7 @@ zread_ipv4_delete (struct zserv *client, u_short length, vrf_id_t vrf_id)
     
   /* tag */
   if (CHECK_FLAG (api.message, ZAPI_MESSAGE_TAG))
-    api.tag = stream_getw (s);
+    api.tag = stream_getl (s);
   else
     api.tag = 0;
 
@@ -1251,7 +1251,7 @@ zread_ipv6_add (struct zserv *client, u_short length, vrf_id_t vrf_id)
 
   /* Tag */
   if (CHECK_FLAG (message, ZAPI_MESSAGE_TAG))
-    rib->tag = stream_getw (s);
+    rib->tag = stream_getl (s);
 
   /* Table */
   rib->table=zebrad.rtm_table_default;
@@ -1322,7 +1322,7 @@ zread_ipv6_delete (struct zserv *client, u_short length, vrf_id_t vrf_id)
     
   /* tag */
   if (CHECK_FLAG (api.message, ZAPI_MESSAGE_TAG))
-    api.tag = stream_getw (s);
+    api.tag = stream_getl (s);
   else
     api.tag = 0;