bgpd: encap: add encap SAFI (RFC5512)

Adds RFC5512 and Encapsulation Attribute.

Signed-off-by: Lou Berger <lberger@labn.net>
diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c
index 302e4ce..1c2ebd6 100644
--- a/bgpd/bgp_open.c
+++ b/bgpd/bgp_open.c
@@ -97,6 +97,9 @@
 	    case SAFI_MPLS_LABELED_VPN:
 	      vty_out (vty, "SAFI MPLS-labeled VPN");
 	      break;
+	    case SAFI_ENCAP:
+	      vty_out (vty, "SAFI ENCAP");
+	      break;
 	    default:
 	      vty_out (vty, "SAFI Unknown %d ", mpc.safi);
 	      break;
@@ -137,6 +140,7 @@
 	case SAFI_UNICAST:
 	case SAFI_MULTICAST:
 	case SAFI_MPLS_VPN:
+	case SAFI_ENCAP:
 	  return 1;
 	}
       break;
@@ -841,9 +845,11 @@
       if (! peer->afc_nego[AFI_IP][SAFI_UNICAST] 
 	  && ! peer->afc_nego[AFI_IP][SAFI_MULTICAST]
 	  && ! peer->afc_nego[AFI_IP][SAFI_MPLS_VPN]
+	  && ! peer->afc_nego[AFI_IP][SAFI_ENCAP]
 	  && ! peer->afc_nego[AFI_IP6][SAFI_UNICAST]
 	  && ! peer->afc_nego[AFI_IP6][SAFI_MULTICAST]
-	  && ! peer->afc_nego[AFI_IP6][SAFI_MPLS_VPN])
+	  && ! peer->afc_nego[AFI_IP6][SAFI_MPLS_VPN]
+	  && ! peer->afc_nego[AFI_IP6][SAFI_ENCAP])
 	{
 	  plog_err (peer->log, "%s [Error] Configured AFI/SAFIs do not "
 		    "overlap with received MP capabilities",
@@ -988,6 +994,18 @@
       stream_putc (s, 0);
       stream_putc (s, SAFI_MPLS_LABELED_VPN);
     }
+  /* ENCAP */
+  if (peer->afc[AFI_IP][SAFI_ENCAP])
+    {
+      peer->afc_adv[AFI_IP][SAFI_ENCAP] = 1;
+      stream_putc (s, BGP_OPEN_OPT_CAP);
+      stream_putc (s, CAPABILITY_CODE_MP_LEN + 2);
+      stream_putc (s, CAPABILITY_CODE_MP);
+      stream_putc (s, CAPABILITY_CODE_MP_LEN);
+      stream_putw (s, AFI_IP);
+      stream_putc (s, 0);
+      stream_putc (s, SAFI_ENCAP);
+    }
 #ifdef HAVE_IPV6
   /* IPv6 unicast. */
   if (peer->afc[AFI_IP6][SAFI_UNICAST])
@@ -1025,6 +1043,18 @@
       stream_putc (s, 0);
       stream_putc (s, SAFI_MPLS_LABELED_VPN);
     }
+  /* IPv6 ENCAP. */
+  if (peer->afc[AFI_IP6][SAFI_ENCAP])
+    {
+      peer->afc_adv[AFI_IP6][SAFI_ENCAP] = 1;
+      stream_putc (s, BGP_OPEN_OPT_CAP);
+      stream_putc (s, CAPABILITY_CODE_MP_LEN + 2);
+      stream_putc (s, CAPABILITY_CODE_MP);
+      stream_putc (s, CAPABILITY_CODE_MP_LEN);
+      stream_putw (s, AFI_IP6);
+      stream_putc (s, 0);
+      stream_putc (s, SAFI_ENCAP);
+    }
 #endif /* HAVE_IPV6 */
 
   /* Route refresh. */