bgpd: more SAFI fixes

Two macros resolving to the same integer constant broke a case block and
a more thorough merge of BGP_SAFI_VPNV4 and BGP_SAFI_VPNV6 was
performed.

* bgpd.h: MPLS-labeled VPN SAFI is AFI-independent, switch to single
* macro
* bgp_capability_test.c: update test data
* bgp_mp_attr_test.c: idem
* bgp_route.c: (bgp_maximum_prefix_overflow, bgp_table_stats_vty) update
  macro and check conditions (where appropriate)
* bgp_packet.c: (bgp_route_refresh_send, bgp_capability_send,
  bgp_update_receive, bgp_route_refresh_receive): idem
* bgp_open.c: (bgp_capability_vty_out, bgp_afi_safi_valid_indices,
  bgp_open_capability_orf, bgp_open_capability): idem
* bgp_attr.c: (bgp_mp_reach_parse, bgp_packet_attribute,
  bgp_packet_withdraw): idem
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index 3f4b3ce..f34a756 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -1367,7 +1367,7 @@
       return -1;
     }
  
-  if (safi != BGP_SAFI_VPNV4)
+  if (safi != SAFI_MPLS_LABELED_VPN)
     {
       ret = bgp_nlri_sanity_check (peer, afi, stream_pnt (s), nlri_len);
       if (ret < 0) 
@@ -1411,7 +1411,7 @@
   
   withdraw_len = length - BGP_MP_UNREACH_MIN_SIZE;
 
-  if (safi != BGP_SAFI_VPNV4)
+  if (safi != SAFI_MPLS_LABELED_VPN)
     {
       ret = bgp_nlri_sanity_check (peer, afi, stream_pnt (s), withdraw_len);
       if (ret < 0)
@@ -2094,7 +2094,7 @@
       sizep = stream_get_endp (s);
       stream_putc (s, 0);	/* Length of this attribute. */
       stream_putw (s, AFI_IP);	/* AFI */
-      stream_putc (s, BGP_SAFI_VPNV4);	/* SAFI */
+      stream_putc (s, SAFI_MPLS_LABELED_VPN);	/* SAFI */
 
       stream_putc (s, 12);
       stream_putl (s, 0);
@@ -2257,7 +2257,7 @@
   if (safi == SAFI_MPLS_VPN)
     {
       /* SAFI */
-      stream_putc (s, BGP_SAFI_VPNV4);
+      stream_putc (s, SAFI_MPLS_LABELED_VPN);
 
       /* prefix. */
       stream_putc (s, p->prefixlen + 88);
diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c
index 3759581..21c7e36 100644
--- a/bgpd/bgp_open.c
+++ b/bgpd/bgp_open.c
@@ -96,8 +96,8 @@
 	    case SAFI_UNICAST_MULTICAST:
 	      vty_out (vty, "SAFI Unicast Multicast");
 	      break;
-	    case BGP_SAFI_VPNV4:
-	      vty_out (vty, "SAFI MPLS-VPN");
+	    case SAFI_MPLS_LABELED_VPN:
+	      vty_out (vty, "SAFI MPLS-labeled VPN");
 	      break;
 	    default:
 	      vty_out (vty, "SAFI Unknown %d ", mpc.safi);
@@ -127,14 +127,6 @@
 int
 bgp_afi_safi_valid_indices (afi_t afi, safi_t *safi)
 {
-  /* VPNvX are AFI specific */
-  if ((afi == AFI_IP6 && *safi == BGP_SAFI_VPNV4)
-      || (afi == AFI_IP && *safi == BGP_SAFI_VPNV6))
-    {
-      zlog_warn ("Invalid afi/safi combination (%u/%u)", afi, *safi);
-      return 0;
-    }
-  
   switch (afi)
     {
       case AFI_IP:
@@ -143,9 +135,8 @@
 #endif
         switch (*safi)
           {
-            /* BGP VPNvX SAFI isn't contigious with others, remap */
-            case BGP_SAFI_VPNV4:
-            case BGP_SAFI_VPNV6:
+            /* BGP MPLS-labeled VPN SAFI isn't contigious with others, remap */
+            case SAFI_MPLS_LABELED_VPN:
               *safi = SAFI_MPLS_VPN;
             case SAFI_UNICAST:
             case SAFI_MULTICAST:
@@ -859,7 +850,7 @@
   int number_of_orfs = 0;
 
   if (safi == SAFI_MPLS_VPN)
-    safi = BGP_SAFI_VPNV4;
+    safi = SAFI_MPLS_LABELED_VPN;
 
   stream_putc (s, BGP_OPEN_OPT_CAP);
   capp = stream_get_endp (s);           /* Set Capability Len Pointer */
@@ -967,7 +958,7 @@
       stream_putc (s, CAPABILITY_CODE_MP_LEN);
       stream_putw (s, AFI_IP);
       stream_putc (s, 0);
-      stream_putc (s, BGP_SAFI_VPNV4);
+      stream_putc (s, SAFI_MPLS_LABELED_VPN);
     }
 #ifdef HAVE_IPV6
   /* IPv6 unicast. */
diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c
index 9102add..6c170ab 100644
--- a/bgpd/bgp_packet.c
+++ b/bgpd/bgp_packet.c
@@ -939,7 +939,7 @@
 
   /* Adjust safi code. */
   if (safi == SAFI_MPLS_VPN)
-    safi = BGP_SAFI_VPNV4;
+    safi = SAFI_MPLS_LABELED_VPN;
   
   s = stream_new (BGP_MAX_PACKET_SIZE);
 
@@ -1029,7 +1029,7 @@
 
   /* Adjust safi code. */
   if (safi == SAFI_MPLS_VPN)
-    safi = BGP_SAFI_VPNV4;
+    safi = SAFI_MPLS_LABELED_VPN;
 
   s = stream_new (BGP_MAX_PACKET_SIZE);
 
@@ -1761,17 +1761,17 @@
     {
       if (mp_update.length 
 	  && mp_update.afi == AFI_IP 
-	  && mp_update.safi == BGP_SAFI_VPNV4)
+	  && mp_update.safi == SAFI_MPLS_LABELED_VPN)
 	bgp_nlri_parse_vpnv4 (peer, &attr, &mp_update);
 
       if (mp_withdraw.length 
 	  && mp_withdraw.afi == AFI_IP 
-	  && mp_withdraw.safi == BGP_SAFI_VPNV4)
+	  && mp_withdraw.safi == SAFI_MPLS_LABELED_VPN)
 	bgp_nlri_parse_vpnv4 (peer, NULL, &mp_withdraw);
 
       if (! withdraw_len
 	  && mp_withdraw.afi == AFI_IP
-	  && mp_withdraw.safi == BGP_SAFI_VPNV4
+	  && mp_withdraw.safi == SAFI_MPLS_LABELED_VPN
 	  && mp_withdraw.length == 0)
 	{
 	  /* End-of-RIB received */
@@ -1942,7 +1942,7 @@
   /* Check AFI and SAFI. */
   if ((afi != AFI_IP && afi != AFI_IP6)
       || (safi != SAFI_UNICAST && safi != SAFI_MULTICAST
-	  && safi != BGP_SAFI_VPNV4))
+	  && safi != SAFI_MPLS_LABELED_VPN))
     {
       if (BGP_DEBUG (normal, NORMAL))
 	{
@@ -1953,7 +1953,7 @@
     }
 
   /* Adjust safi code. */
-  if (safi == BGP_SAFI_VPNV4)
+  if (safi == SAFI_MPLS_LABELED_VPN)
     safi = SAFI_MPLS_VPN;
 
   if (size != BGP_MSG_ROUTE_REFRESH_MIN_SIZE - BGP_HEADER_SIZE)
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index 1da5d1d..7a57e13 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -1660,7 +1660,7 @@
        u_int8_t ndata[7];
 
        if (safi == SAFI_MPLS_VPN)
-         safi = BGP_SAFI_VPNV4;
+         safi = SAFI_MPLS_LABELED_VPN;
          
        ndata[0] = (afi >>  8);
        ndata[1] = afi;
@@ -9088,10 +9088,8 @@
         safi = SAFI_MULTICAST;
       else if (strncmp (safi_str, "u", 1) == 0)
         safi = SAFI_UNICAST;
-      else if (strncmp (safi_str, "vpnv4", 5) == 0)
-        safi = BGP_SAFI_VPNV4;
-      else if (strncmp (safi_str, "vpnv6", 5) == 0)
-        safi = BGP_SAFI_VPNV6;
+      else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
+        safi = SAFI_MPLS_LABELED_VPN;
       else
         {
           vty_out (vty, "%% Invalid subsequent address family %s%s",
@@ -9106,13 +9104,6 @@
       return CMD_WARNING;
     }
 
-  if ((afi == AFI_IP && safi ==  BGP_SAFI_VPNV6)
-      || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
-    {
-      vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
-               afi_str, safi_str, VTY_NEWLINE);
-      return CMD_WARNING;
-    }
   return bgp_table_stats (vty, bgp, afi, safi);
 }
 
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index 73a9ea1..759d257 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -724,9 +724,8 @@
 #define BGP_DEFAULT_RESTART_TIME               120
 #define BGP_DEFAULT_STALEPATH_TIME             360
 
-/* SAFI which used in open capability negotiation.  */
-#define BGP_SAFI_VPNV4                         128
-#define BGP_SAFI_VPNV6                         128
+/* RFC4364 */
+#define SAFI_MPLS_LABELED_VPN                  128
 
 /* Max TTL value.  */
 #define TTL_MAX                                255
diff --git a/tests/bgp_capability_test.c b/tests/bgp_capability_test.c
index 0dbf4fb..9b43159 100644
--- a/tests/bgp_capability_test.c
+++ b/tests/bgp_capability_test.c
@@ -96,10 +96,10 @@
   },
   /* 6 */
   { "MP3",
-    "MP IP6/VPNv4",
+    "MP IP6/MPLS-labeled VPN",
     { CAPABILITY_CODE_MP, 0x4, 0x0, 0x2, 0x0, 0x80 },
-    6, SHOULD_PARSE, 0, /* parses, but invalid afi,safi */
-    1, AFI_IP6, BGP_SAFI_VPNV4, INVALID_AFI,
+    6, SHOULD_PARSE, 0,
+    1, AFI_IP6, SAFI_MPLS_LABELED_VPN, VALID_AFI,
   },
   /* 7 */
   { "MP5",
@@ -110,21 +110,14 @@
   },
   /* 8 */
   { "MP6",
-    "MP IP4/VPNv4",
+    "MP IP4/MPLS-laveled VPN",
     { CAPABILITY_CODE_MP, 0x4, 0x0, 0x1, 0x0, 0x80 },
     6, SHOULD_PARSE, 0,
-    1, AFI_IP, BGP_SAFI_VPNV4, VALID_AFI,
+    1, AFI_IP, SAFI_MPLS_LABELED_VPN, VALID_AFI,
   },  
-  /* 9 */
-  { "MP7",
-    "MP IP4/VPNv6",
-    { CAPABILITY_CODE_MP, 0x4, 0x0, 0x1, 0x0, 0x81 },
-    6, SHOULD_PARSE, 0, /* parses, but invalid afi,safi tuple */
-    1, AFI_IP, BGP_SAFI_VPNV6, INVALID_AFI,
-  },
   /* 10 */
   { "MP8",
-    "MP unknown AFI",
+    "MP unknown AFI/SAFI",
     { CAPABILITY_CODE_MP, 0x4, 0x0, 0xa, 0x0, 0x81 },
     6, SHOULD_PARSE, 0,
     1, 0xa, 0x81, INVALID_AFI, /* parses, but unknown */
diff --git a/tests/bgp_mp_attr_test.c b/tests/bgp_mp_attr_test.c
index dde0df2..d6e9f0c 100644
--- a/tests/bgp_mp_attr_test.c
+++ b/tests/bgp_mp_attr_test.c
@@ -286,10 +286,10 @@
     SHOULD_ERR,
     AFI_IP, SAFI_UNICAST, VALID_AFI,
   },
-  { "IPv4-vpnv4",
-    "IPv4/VPNv4 MP Reach, RD, Nexthop, 3 NLRIs", 
+  { "IPv4-MLVPN",
+    "IPv4/MPLS-labeled VPN MP Reach, RD, Nexthop, 3 NLRIs", 
     {
-      /* AFI / SAFI */		0x0, AFI_IP, BGP_SAFI_VPNV4,
+      /* AFI / SAFI */		0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
       /* nexthop bytes */	12,
       /* RD */			0, 0, 1, 2,
                                 0, 0xff, 3, 4,
@@ -409,10 +409,10 @@
     SHOULD_ERR,
     AFI_IP, SAFI_UNICAST, VALID_AFI,
   },
-  { "IPv4-unreach-vpnv4",
-    "IPv4/VPNv4 MP Unreach, RD, 3 NLRIs", 
+  { "IPv4-unreach-MLVPN",
+    "IPv4/MPLS-labeled VPN MP Unreach, RD, 3 NLRIs", 
     {
-      /* AFI / SAFI */		0x0, AFI_IP, BGP_SAFI_VPNV4,
+      /* AFI / SAFI */		0x0, AFI_IP, SAFI_MPLS_LABELED_VPN,
       /* nexthop bytes */	12,
       /* RD */			0, 0, 1, 2,
                                 0, 0xff, 3, 4,