ripd, ripngd: add support for route tags

[Forward ported by Cumulus]

Documentation
-------------
All ipv4 and ipv6 static route commands now have a "tag" option
which allows the user to set a tag between 1 and 65535.

quagga(config)# ip route 1.1.1.1/32 10.1.1.1 tag ?
  <1-65535>  Tag value
quagga(config)# ip route 1.1.1.1/32 10.1.1.1 tag 40
quagga(config)#

quagga# show ip route 1.1.1.1/32
Routing entry for 1.1.1.1/32
  Known via "static", distance 1, metric 0, tag 40, best
  * 10.1.1.1, via swp1

quagga#

The route-map parser supports matching on tags and setting tags
!
route-map MATCH_TAG_18 permit 10
  match tag 18
!

!
route-map SET_TAG_22 permit 10
  set tag 22
!

BGP and OSPF support:
- matching on tags when redistribing routes from the RIB into BGP/OSPF.
- setting tags when redistribing routes from the RIB into BGP/OSPF.

BGP also supports setting a tag via a table-map, when installing BGP
routes into the RIB.

Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com>
Signed-off-by: Piotr Chytla <pch@packetconsulting.pl>
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
diff --git a/ripd/rip_routemap.c b/ripd/rip_routemap.c
index 9bafdcd..cc0ed61 100644
--- a/ripd/rip_routemap.c
+++ b/ripd/rip_routemap.c
@@ -485,9 +485,22 @@
 route_match_tag_compile (const char *arg)
 {
   u_short *tag;
+  u_short tmp;
+
+  /* tag value shoud be integer. */
+  if (! all_digit (arg))
+    return NULL;
+
+  tmp = atoi(arg);
+  if (tmp < 1)
+    return NULL;
 
   tag = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (u_short));
-  *tag = atoi (arg);
+
+  if (!tag)
+    return tag;
+
+  *tag = tmp;
 
   return tag;
 }
@@ -937,7 +950,7 @@
 
 DEFUN (match_tag, 
        match_tag_cmd,
-       "match tag <0-65535>",
+       "match tag <1-65535>",
        MATCH_STR
        "Match tag of route\n"
        "Metric value\n")
@@ -960,7 +973,7 @@
 
 ALIAS (no_match_tag,
        no_match_tag_val_cmd,
-       "no match tag <0-65535>",
+       "no match tag <1-65535>",
        NO_STR
        MATCH_STR
        "Match tag of route\n"
@@ -1060,7 +1073,7 @@
 
 DEFUN (set_tag,
        set_tag_cmd,
-       "set tag <0-65535>",
+       "set tag <1-65535>",
        SET_STR
        "Tag value for routing protocol\n"
        "Tag value\n")
@@ -1083,7 +1096,7 @@
 
 ALIAS (no_set_tag,
        no_set_tag_val_cmd,
-       "no set tag <0-65535>",
+       "no set tag <1-65535>",
        NO_STR
        SET_STR
        "Tag value for routing protocol\n"
diff --git a/ripngd/ripng_routemap.c b/ripngd/ripng_routemap.c
index f4fadb6..a316301 100644
--- a/ripngd/ripng_routemap.c
+++ b/ripngd/ripng_routemap.c
@@ -564,7 +564,7 @@
 
 DEFUN (match_tag,
        match_tag_cmd,
-       "match tag <0-65535>",
+       "match tag <1-65535>",
        MATCH_STR
        "Match tag of route\n"
        "Metric value\n")
@@ -587,7 +587,7 @@
 
 ALIAS (no_match_tag,
        no_match_tag_val_cmd,
-       "no match tag <0-65535>",
+       "no match tag <1-65535>",
        NO_STR
        MATCH_STR
        "Match tag of route\n"
@@ -675,7 +675,7 @@
 
 DEFUN (set_tag,
        set_tag_cmd,
-       "set tag <0-65535>",
+       "set tag <1-65535>",
        SET_STR
        "Tag value for routing protocol\n"
        "Tag value\n")
@@ -698,7 +698,7 @@
 
 ALIAS (no_set_tag,
        no_set_tag_val_cmd,
-       "no set tag <0-65535>",
+       "no set tag <1-65535>",
        NO_STR
        SET_STR
        "Tag value for routing protocol\n"