]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_encap.c
bgpd: Fix `ip as-path access-list ...` breakage
[mirror_frr.git] / bgpd / bgp_encap.c
index 2186b211225ce8b80b2ccbbf17a4873e5e01704a..dd35bb2c3ce5e52cf36fdefb2ec0485d75f69e44 100644 (file)
@@ -45,50 +45,9 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 #include "bgpd/bgp_vty.h"
 #include "bgpd/bgp_encap.h"
 
-static u_int16_t
-decode_rd_type (u_char *pnt)
-{
-  u_int16_t v;
-  
-  v = ((u_int16_t) *pnt++ << 8);
-  v |= (u_int16_t) *pnt;
-  return v;
-}
-
-
-static void
-decode_rd_as (u_char *pnt, struct rd_as *rd_as)
-{
-  rd_as->as  = (u_int16_t) *pnt++ << 8;
-  rd_as->as |= (u_int16_t) *pnt++;
-  
-  rd_as->val  = ((u_int32_t) *pnt++) << 24;
-  rd_as->val |= ((u_int32_t) *pnt++) << 16;
-  rd_as->val |= ((u_int32_t) *pnt++) << 8;
-  rd_as->val |= (u_int32_t) *pnt;
-}
-
-static void
-decode_rd_as4 (u_char *pnt, struct rd_as *rd_as)
-{
-  rd_as->as  = (u_int32_t) *pnt++ << 24;
-  rd_as->as |= (u_int32_t) *pnt++ << 16;
-  rd_as->as |= (u_int32_t) *pnt++ << 8;
-  rd_as->as |= (u_int32_t) *pnt++;
-  
-  rd_as->val  = ((u_int32_t) *pnt++ << 8);
-  rd_as->val |= (u_int32_t) *pnt;
-}
-
-static void
-decode_rd_ip (u_char *pnt, struct rd_ip *rd_ip)
-{
-  memcpy (&rd_ip->ip, pnt, 4);
-  pnt += 4;
-  
-  rd_ip->val = ((u_int16_t) *pnt++ << 8);
-  rd_ip->val |= (u_int16_t) *pnt;
-}
+#if ENABLE_BGP_VNC
+#include "bgpd/rfapi/rfapi_backend.h"
+#endif
 
 static void
 ecom2prd(struct ecommunity *ecom, struct prefix_rd *prd)
@@ -126,14 +85,13 @@ ecom2prd(struct ecommunity *ecom, struct prefix_rd *prd)
 
 int
 bgp_nlri_parse_encap(
-    afi_t              afi,
     struct peer                *peer,
-    struct attr                *attr,          /* Need even for withdraw */
-    struct bgp_nlri    *packet,
-    int                        withdraw)       /* 0=update, !0 = withdraw */
+    struct attr                *attr,
+    struct bgp_nlri    *packet)
 {
   u_char *pnt;
   u_char *lim;
+  afi_t afi = packet->afi;
   struct prefix p;
   int psize = 0;
   int prefixlen;
@@ -227,10 +185,18 @@ bgp_nlri_parse_encap(
            inet_ntop (p.family, &p.u.prefix, buf, BUFSIZ),
            p.prefixlen);
 
-      if (!withdraw) {
+      if (attr) {
        bgp_update (peer, &p, 0, attr, afi, SAFI_ENCAP,
                    ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, NULL, 0);
+#if ENABLE_BGP_VNC
+       rfapiProcessUpdate(peer, NULL, &p, &prd, attr, afi, SAFI_ENCAP,
+                           ZEBRA_ROUTE_BGP,  BGP_ROUTE_NORMAL, NULL);
+#endif
       } else {
+#if ENABLE_BGP_VNC
+       rfapiProcessWithdraw(peer, NULL, &p, &prd, attr, afi, SAFI_ENCAP,
+                             ZEBRA_ROUTE_BGP, 0);
+#endif
        bgp_withdraw (peer, &p, 0, attr, afi, SAFI_ENCAP,
                      ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, NULL);
       }
@@ -251,13 +217,16 @@ DEFUN (encap_network,
        encap_network_cmd,
        "network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
        "Specify a network to announce via BGP\n"
-       "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
+       "IPv4 prefix\n"
        "Specify Route Distinguisher\n"
        "ENCAP Route Distinguisher\n"
        "BGP tag\n"
        "tag value\n")
 {
-  return bgp_static_set_safi (SAFI_ENCAP, vty, argv[0], argv[1], argv[2], NULL);
+  int idx_ipv4 = 1;
+  int idx_rd = 3;
+  int idx_word = 5;
+  return bgp_static_set_safi (SAFI_ENCAP, vty, argv[idx_ipv4]->arg, argv[idx_rd]->arg, argv[idx_word]->arg, NULL);
 }
 
 /* For testing purpose, static route of ENCAP. */
@@ -266,13 +235,16 @@ DEFUN (no_encap_network,
        "no network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
        NO_STR
        "Specify a network to announce via BGP\n"
-       "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
+       "IPv4 prefix\n"
        "Specify Route Distinguisher\n"
        "ENCAP Route Distinguisher\n"
        "BGP tag\n"
        "tag value\n")
 {
-  return bgp_static_unset_safi (SAFI_ENCAP, vty, argv[0], argv[1], argv[2]);
+  int idx_ipv4 = 2;
+  int idx_rd = 4;
+  int idx_word = 6;
+  return bgp_static_unset_safi (SAFI_ENCAP, vty, argv[idx_ipv4]->arg, argv[idx_rd]->arg, argv[idx_word]->arg);
 }
 
 static int
@@ -534,10 +506,11 @@ DEFUN (show_bgp_ipv4_encap_rd,
        "Display information for a route distinguisher\n"
        "ENCAP Route Distinguisher\n")
 {
+  int idx_rd = 5;
   int ret;
   struct prefix_rd prd;
 
-  ret = str2prefix_rd (argv[0], &prd);
+  ret = str2prefix_rd (argv[idx_rd]->arg, &prd);
   if (! ret)
     {
       vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
@@ -557,10 +530,11 @@ DEFUN (show_bgp_ipv6_encap_rd,
        "ENCAP Route Distinguisher\n"
        "Display BGP tags for prefixes\n")
 {
+  int idx_rd = 5;
   int ret;
   struct prefix_rd prd;
 
-  ret = str2prefix_rd (argv[0], &prd);
+  ret = str2prefix_rd (argv[idx_rd]->arg, &prd);
   if (! ret)
     {
       vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
@@ -606,10 +580,11 @@ DEFUN (show_bgp_ipv4_encap_rd_tags,
        "ENCAP Route Distinguisher\n"
        "Display BGP tags for prefixes\n")
 {
+  int idx_rd = 5;
   int ret;
   struct prefix_rd prd;
 
-  ret = str2prefix_rd (argv[0], &prd);
+  ret = str2prefix_rd (argv[idx_rd]->arg, &prd);
   if (! ret)
     {
       vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
@@ -629,10 +604,11 @@ DEFUN (show_bgp_ipv6_encap_rd_tags,
        "ENCAP Route Distinguisher\n"
        "Display BGP tags for prefixes\n")
 {
+  int idx_rd = 5;
   int ret;
   struct prefix_rd prd;
 
-  ret = str2prefix_rd (argv[0], &prd);
+  ret = str2prefix_rd (argv[idx_rd]->arg, &prd);
   if (! ret)
     {
       vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
@@ -653,24 +629,24 @@ DEFUN (show_bgp_ipv4_encap_neighbor_routes,
        "Neighbor to display information about\n"
        "Display routes learned from neighbor\n")
 {
-  union sockunion *su;
+  int idx_peer = 5;
+  union sockunion su;
   struct peer *peer;
-  
-  su = sockunion_str2su (argv[0]);
-  if (su == NULL)
+
+  if (sockunion_str2su (argv[idx_peer]->arg))
     {
-      vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
+      vty_out (vty, "Malformed address: %s%s", argv[idx_peer]->arg, VTY_NEWLINE);
                return CMD_WARNING;
     }
 
-  peer = peer_lookup (NULL, su);
+  peer = peer_lookup (NULL, &su);
   if (! peer || ! peer->afc[AFI_IP][SAFI_ENCAP])
     {
       vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
       return CMD_WARNING;
     }
 
-  return bgp_show_encap (vty, AFI_IP, NULL, bgp_show_type_neighbor, su, 0);
+  return bgp_show_encap (vty, AFI_IP, NULL, bgp_show_type_neighbor, &su, 0);
 }
 #ifdef HAVE_IPV6
 DEFUN (show_bgp_ipv6_encap_neighbor_routes,
@@ -684,30 +660,30 @@ DEFUN (show_bgp_ipv6_encap_neighbor_routes,
        "Neighbor to display information about\n"
        "Display routes learned from neighbor\n")
 {
-  union sockunion *su;
+  int idx_peer = 5;
+  union sockunion su;
   struct peer *peer;
   
-  su = sockunion_str2su (argv[0]);
-  if (su == NULL)
+  if (str2sockunion(argv[idx_peer]->arg, &su))
     {
-      vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
+      vty_out (vty, "Malformed address: %s%s", argv[idx_peer]->arg, VTY_NEWLINE);
                return CMD_WARNING;
     }
 
-  peer = peer_lookup (NULL, su);
+  peer = peer_lookup (NULL, &su);
   if (! peer || ! peer->afc[AFI_IP6][SAFI_ENCAP])
     {
       vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
       return CMD_WARNING;
     }
 
-  return bgp_show_encap (vty, AFI_IP6, NULL, bgp_show_type_neighbor, su, 0);
+  return bgp_show_encap (vty, AFI_IP6, NULL, bgp_show_type_neighbor, &su, 0);
 }
 #endif
 
 DEFUN (show_bgp_ipv4_encap_rd_neighbor_routes,
        show_bgp_ipv4_encap_rd_neighbor_routes_cmd,
-       "show bgp ipv4 encap rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) routes",
+       "show bgp ipv4 encap rd ASN:nn_or_IP-address:nn neighbors <A.B.C.D|X:X::X:X> routes",
        SHOW_STR
        BGP_STR
        "Address Family\n"
@@ -719,38 +695,39 @@ DEFUN (show_bgp_ipv4_encap_rd_neighbor_routes,
        "Neighbor to display information about\n"
        "Display routes learned from neighbor\n")
 {
+  int idx_rd = 5;
+  int idx_peer = 7;
   int ret;
-  union sockunion *su;
+  union sockunion su;
   struct peer *peer;
   struct prefix_rd prd;
 
-  ret = str2prefix_rd (argv[0], &prd);
+  ret = str2prefix_rd (argv[idx_rd]->arg, &prd);
   if (! ret)
     {
       vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
       return CMD_WARNING;
     }
 
-  su = sockunion_str2su (argv[1]);
-  if (su == NULL)
+  if (str2sockunion(argv[idx_peer]->arg, &su))
     {
-      vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
+      vty_out (vty, "Malformed address: %s%s", argv[idx_peer]->arg, VTY_NEWLINE);
                return CMD_WARNING;
     }
 
-  peer = peer_lookup (NULL, su);
+  peer = peer_lookup (NULL, &su);
   if (! peer || ! peer->afc[AFI_IP][SAFI_ENCAP])
     {
       vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
       return CMD_WARNING;
     }
 
-  return bgp_show_encap (vty, AFI_IP, &prd, bgp_show_type_neighbor, su, 0);
+  return bgp_show_encap (vty, AFI_IP, &prd, bgp_show_type_neighbor, &su, 0);
 }
 #ifdef HAVE_IPV6
 DEFUN (show_bgp_ipv6_encap_rd_neighbor_routes,
        show_bgp_ipv6_encap_rd_neighbor_routes_cmd,
-       "show bgp ipv6 encap rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) routes",
+       "show bgp ipv6 encap rd ASN:nn_or_IP-address:nn neighbors <A.B.C.D|X:X::X:X> routes",
        SHOW_STR
        BGP_STR
        "Address Family\n"
@@ -762,33 +739,34 @@ DEFUN (show_bgp_ipv6_encap_rd_neighbor_routes,
        "Neighbor to display information about\n"
        "Display routes learned from neighbor\n")
 {
+  int idx_rd = 5;
+  int idx_peer = 7;
   int ret;
-  union sockunion *su;
+  union sockunion su;
   struct peer *peer;
   struct prefix_rd prd;
 
-  ret = str2prefix_rd (argv[0], &prd);
+  ret = str2prefix_rd (argv[idx_rd]->arg, &prd);
   if (! ret)
     {
       vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
       return CMD_WARNING;
     }
 
-  su = sockunion_str2su (argv[1]);
-  if (su == NULL)
+  if (str2sockunion(argv[idx_peer]->arg, &su))
     {
-      vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
+      vty_out (vty, "Malformed address: %s%s", argv[idx_peer]->arg, VTY_NEWLINE);
                return CMD_WARNING;
     }
 
-  peer = peer_lookup (NULL, su);
+  peer = peer_lookup (NULL, &su);
   if (! peer || ! peer->afc[AFI_IP6][SAFI_ENCAP])
     {
       vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
       return CMD_WARNING;
     }
 
-  return bgp_show_encap (vty, AFI_IP6, &prd, bgp_show_type_neighbor, su, 0);
+  return bgp_show_encap (vty, AFI_IP6, &prd, bgp_show_type_neighbor, &su, 0);
 }
 #endif
 
@@ -803,14 +781,15 @@ DEFUN (show_bgp_ipv4_encap_neighbor_advertised_routes,
        "Neighbor to display information about\n"
        "Display the routes advertised to a BGP neighbor\n")
 {
+  int idx_peer = 5;
   int ret;
   struct peer *peer;
   union sockunion su;
 
-  ret = str2sockunion (argv[0], &su);
+  ret = str2sockunion (argv[idx_peer]->arg, &su);
   if (ret < 0)
     {
-      vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
+      vty_out (vty, "%% Malformed address: %s%s", argv[idx_peer]->arg, VTY_NEWLINE);
       return CMD_WARNING;
     }
   peer = peer_lookup (NULL, &su);
@@ -834,14 +813,15 @@ DEFUN (show_bgp_ipv6_encap_neighbor_advertised_routes,
        "Neighbor to display information about\n"
        "Display the routes advertised to a BGP neighbor\n")
 {
+  int idx_peer = 5;
   int ret;
   struct peer *peer;
   union sockunion su;
 
-  ret = str2sockunion (argv[0], &su);
+  ret = str2sockunion (argv[idx_peer]->arg, &su);
   if (ret < 0)
     {
-      vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
+      vty_out (vty, "%% Malformed address: %s%s", argv[idx_peer]->arg, VTY_NEWLINE);
       return CMD_WARNING;
     }
   peer = peer_lookup (NULL, &su);
@@ -857,7 +837,7 @@ DEFUN (show_bgp_ipv6_encap_neighbor_advertised_routes,
 
 DEFUN (show_bgp_ipv4_encap_rd_neighbor_advertised_routes,
        show_bgp_ipv4_encap_rd_neighbor_advertised_routes_cmd,
-       "show bgp ipv4 encap rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) advertised-routes",
+       "show bgp ipv4 encap rd ASN:nn_or_IP-address:nn neighbors <A.B.C.D|X:X::X:X> advertised-routes",
        SHOW_STR
        BGP_STR
        "Address Family\n"
@@ -869,15 +849,17 @@ DEFUN (show_bgp_ipv4_encap_rd_neighbor_advertised_routes,
        "Neighbor to display information about\n"
        "Display the routes advertised to a BGP neighbor\n")
 {
+  int idx_rd = 5;
+  int idx_peer = 7;
   int ret;
   struct peer *peer;
   struct prefix_rd prd;
   union sockunion su;
 
-  ret = str2sockunion (argv[1], &su);
+  ret = str2sockunion (argv[idx_peer]->arg, &su);
   if (ret < 0)
     {
-      vty_out (vty, "%% Malformed address: %s%s", argv[1], VTY_NEWLINE);
+      vty_out (vty, "%% Malformed address: %s%s", argv[idx_peer]->arg, VTY_NEWLINE);
       return CMD_WARNING;
     }
   peer = peer_lookup (NULL, &su);
@@ -887,7 +869,7 @@ DEFUN (show_bgp_ipv4_encap_rd_neighbor_advertised_routes,
       return CMD_WARNING;
     }
 
-  ret = str2prefix_rd (argv[0], &prd);
+  ret = str2prefix_rd (argv[idx_rd]->arg, &prd);
   if (! ret)
     {
       vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
@@ -899,7 +881,7 @@ DEFUN (show_bgp_ipv4_encap_rd_neighbor_advertised_routes,
 #ifdef HAVE_IPV6
 DEFUN (show_bgp_ipv6_encap_rd_neighbor_advertised_routes,
        show_bgp_ipv6_encap_rd_neighbor_advertised_routes_cmd,
-       "show bgp ipv6 encap rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) advertised-routes",
+       "show bgp ipv6 encap rd ASN:nn_or_IP-address:nn neighbors <A.B.C.D|X:X::X:X> advertised-routes",
        SHOW_STR
        BGP_STR
        "Address Family\n"
@@ -911,15 +893,17 @@ DEFUN (show_bgp_ipv6_encap_rd_neighbor_advertised_routes,
        "Neighbor to display information about\n"
        "Display the routes advertised to a BGP neighbor\n")
 {
+  int idx_rd = 5;
+  int idx_peer = 7;
   int ret;
   struct peer *peer;
   struct prefix_rd prd;
   union sockunion su;
 
-  ret = str2sockunion (argv[1], &su);
+  ret = str2sockunion (argv[idx_peer]->arg, &su);
   if (ret < 0)
     {
-      vty_out (vty, "%% Malformed address: %s%s", argv[1], VTY_NEWLINE);
+      vty_out (vty, "%% Malformed address: %s%s", argv[idx_peer]->arg, VTY_NEWLINE);
       return CMD_WARNING;
     }
   peer = peer_lookup (NULL, &su);
@@ -929,7 +913,7 @@ DEFUN (show_bgp_ipv6_encap_rd_neighbor_advertised_routes,
       return CMD_WARNING;
     }
 
-  ret = str2prefix_rd (argv[0], &prd);
+  ret = str2prefix_rd (argv[idx_rd]->arg, &prd);
   if (! ret)
     {
       vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
@@ -943,9 +927,8 @@ DEFUN (show_bgp_ipv6_encap_rd_neighbor_advertised_routes,
 void
 bgp_encap_init (void)
 {
-  //install_element (BGP_ENCAP_NODE, &encap_network_cmd);
-  //install_element (BGP_ENCAP_NODE, &no_encap_network_cmd);
-
+  install_element (BGP_ENCAP_NODE, &encap_network_cmd);
+  install_element (BGP_ENCAP_NODE, &no_encap_network_cmd);
 
   install_element (VIEW_NODE, &show_bgp_ipv4_encap_cmd);
   install_element (VIEW_NODE, &show_bgp_ipv4_encap_rd_cmd);
@@ -966,27 +949,4 @@ bgp_encap_init (void)
   install_element (VIEW_NODE, &show_bgp_ipv6_encap_neighbor_advertised_routes_cmd);
   install_element (VIEW_NODE, &show_bgp_ipv6_encap_rd_neighbor_advertised_routes_cmd);
 #endif
-
-
-  install_element (ENABLE_NODE, &show_bgp_ipv4_encap_cmd);
-  install_element (ENABLE_NODE, &show_bgp_ipv4_encap_rd_cmd);
-  install_element (ENABLE_NODE, &show_bgp_ipv4_encap_tags_cmd);
-  install_element (ENABLE_NODE, &show_bgp_ipv4_encap_rd_tags_cmd);
-  install_element (ENABLE_NODE, &show_bgp_ipv4_encap_neighbor_routes_cmd);
-  install_element (ENABLE_NODE, &show_bgp_ipv4_encap_rd_neighbor_routes_cmd);
-  install_element (ENABLE_NODE, &show_bgp_ipv4_encap_neighbor_advertised_routes_cmd);
-  install_element (ENABLE_NODE, &show_bgp_ipv4_encap_rd_neighbor_advertised_routes_cmd);
-
-#ifdef HAVE_IPV6
-  install_element (ENABLE_NODE, &show_bgp_ipv6_encap_cmd);
-  install_element (ENABLE_NODE, &show_bgp_ipv6_encap_rd_cmd);
-  install_element (ENABLE_NODE, &show_bgp_ipv6_encap_tags_cmd);
-  install_element (ENABLE_NODE, &show_bgp_ipv6_encap_rd_tags_cmd);
-  install_element (ENABLE_NODE, &show_bgp_ipv6_encap_neighbor_routes_cmd);
-  install_element (ENABLE_NODE, &show_bgp_ipv6_encap_rd_neighbor_routes_cmd);
-  install_element (ENABLE_NODE, &show_bgp_ipv6_encap_neighbor_advertised_routes_cmd);
-  install_element (ENABLE_NODE, &show_bgp_ipv6_encap_rd_neighbor_advertised_routes_cmd);
-#endif
-
-
 }