*: 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.
diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h
index 0bbb912..0cd0b77 100644
--- a/bgpd/bgp_attr.h
+++ b/bgpd/bgp_attr.h
@@ -94,7 +94,7 @@
   struct bgp_attr_encap_subtlv *encap_subtlvs;		/* rfc5512 */
 
   /* route tag */
-  u_short tag;
+  route_tag_t tag;
 };
 
 /* BGP core attribute structure. */
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index bab9961..78cd53b 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -5605,7 +5605,7 @@
 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;
diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h
index 324e006..2a72daa 100644
--- a/bgpd/bgp_route.h
+++ b/bgpd/bgp_route.h
@@ -221,7 +221,7 @@
 
 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);
 
diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c
index 204644a..87f0543 100644
--- a/bgpd/bgp_routemap.c
+++ b/bgpd/bgp_routemap.c
@@ -1009,7 +1009,7 @@
 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 @@
 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 @@
 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 @@
 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))
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c
index 6c57a6f..38fecd9 100644
--- a/bgpd/bgp_zebra.c
+++ b/bgpd/bgp_zebra.c
@@ -279,7 +279,7 @@
     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 @@
     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 @@
   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;
diff --git a/lib/zclient.c b/lib/zclient.c
index a1de831..eb8de1a 100644
--- a/lib/zclient.c
+++ b/lib/zclient.c
@@ -591,7 +591,7 @@
   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 @@
   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));
diff --git a/lib/zclient.h b/lib/zclient.h
index 810c927..d46728d 100644
--- a/lib/zclient.h
+++ b/lib/zclient.h
@@ -133,7 +133,7 @@
 
   u_char distance;
 
-  u_short tag;
+  route_tag_t tag;
 
   u_int32_t metric;
 
@@ -213,7 +213,7 @@
 
   u_char distance;
 
-  u_short tag;
+  route_tag_t tag;
 
   u_int32_t metric;
 
diff --git a/lib/zebra.h b/lib/zebra.h
index a75eb6d..a405d46 100644
--- a/lib/zebra.h
+++ b/lib/zebra.h
@@ -535,4 +535,7 @@
 /* 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 */
diff --git a/ospfd/ospf_asbr.c b/ospfd/ospf_asbr.c
index 4b53690..0a411e4 100644
--- a/ospfd/ospf_asbr.c
+++ b/ospfd/ospf_asbr.c
@@ -136,7 +136,7 @@
 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;
diff --git a/ospfd/ospf_asbr.h b/ospfd/ospf_asbr.h
index 2709a6c..bc41a14 100644
--- a/ospfd/ospf_asbr.h
+++ b/ospfd/ospf_asbr.h
@@ -63,7 +63,7 @@
                                               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 *);
diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c
index 4341cd9..d795439 100644
--- a/ospfd/ospf_lsa.c
+++ b/ospfd/ospf_lsa.c
@@ -1649,7 +1649,7 @@
   /* 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);
 }
 
diff --git a/ospfd/ospf_routemap.c b/ospfd/ospf_routemap.c
index 7bd6c3d..f044e38 100644
--- a/ospfd/ospf_routemap.c
+++ b/ospfd/ospf_routemap.c
@@ -422,7 +422,7 @@
 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 @@
 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 @@
 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 @@
 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))
diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c
index ce268cd..60d9852 100644
--- a/ospfd/ospf_zebra.c
+++ b/ospfd/ospf_zebra.c
@@ -370,10 +370,10 @@
       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 @@
         }
 
       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 @@
   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;
 
diff --git a/ospfd/ospfd.h b/ospfd/ospfd.h
index 4181d11..0315164 100644
--- a/ospfd/ospfd.h
+++ b/ospfd/ospfd.h
@@ -239,7 +239,7 @@
   } 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
diff --git a/ripd/rip_routemap.c b/ripd/rip_routemap.c
index cc0ed61..9bb9638 100644
--- a/ripd/rip_routemap.c
+++ b/ripd/rip_routemap.c
@@ -463,7 +463,7 @@
 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 @@
 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 @@
 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 @@
 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);
diff --git a/zebra/rib.h b/zebra/rib.h
index d31db55..0191f57 100644
--- a/zebra/rib.h
+++ b/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 @@
   /* Refrence count. */
   unsigned long refcnt;
   
+  /* Tag */
+  route_tag_t tag;
+
   /* Uptime. */
   time_t uptime;
 
@@ -65,9 +69,6 @@
   /* 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 @@
   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 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 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);
diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c
index e57d1af..405528c 100644
--- a/zebra/zebra_rib.c
+++ b/zebra/zebra_rib.c
@@ -2314,8 +2314,8 @@
 
 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 @@
 
 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 @@
 /* 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 @@
 /* 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;
diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c
index a14f68b..38f61e9 100644
--- a/zebra/zebra_vty.c
+++ b/zebra/zebra_vty.c
@@ -54,7 +54,7 @@
   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 @@
   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 @@
   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 @@
   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])
diff --git a/zebra/zserv.c b/zebra/zserv.c
index 89232c2..2319a06 100644
--- a/zebra/zserv.c
+++ b/zebra/zserv.c
@@ -498,7 +498,7 @@
       if (rib->tag)
         {
           SET_FLAG(zapi_flags, ZAPI_MESSAGE_TAG);
-          stream_putw(s, rib->tag);
+          stream_putl (s, rib->tag);
         }
     }
   
@@ -1011,7 +1011,7 @@
     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 @@
     
   /* 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 @@
 
   /* 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 @@
     
   /* tag */
   if (CHECK_FLAG (api.message, ZAPI_MESSAGE_TAG))
-    api.tag = stream_getw (s);
+    api.tag = stream_getl (s);
   else
     api.tag = 0;