]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_route.c
Merge pull request #624 "Babel"
[mirror_frr.git] / bgpd / bgp_route.c
index 41966192d89327194176394fe15f7f17f8afa8ee..31c1dd8c101d0fa82574bc2061d94eeac7e9e465 100644 (file)
@@ -54,7 +54,6 @@
 #include "bgpd/bgp_filter.h"
 #include "bgpd/bgp_fsm.h"
 #include "bgpd/bgp_mplsvpn.h"
-#include "bgpd/bgp_encap.h"
 #include "bgpd/bgp_nexthop.h"
 #include "bgpd/bgp_damp.h"
 #include "bgpd/bgp_advertise.h"
@@ -1456,7 +1455,7 @@ subgroup_announce_check (struct bgp_node *rn, struct bgp_info *ri,
 
 #define NEXTHOP_IS_V6 (\
     (safi != SAFI_ENCAP && safi != SAFI_MPLS_VPN &&\
-     (p->family == AF_INET6 || peer_cap_enhe(peer, AFI_IP6, safi))) || \
+     (p->family == AF_INET6 || peer_cap_enhe(peer, afi, safi))) || \
     ((safi == SAFI_ENCAP || safi == SAFI_MPLS_VPN) &&\
      attr->extra->mp_nexthop_len >= IPV6_MAX_BYTELEN))
 
@@ -2839,7 +2838,7 @@ bgp_update (struct peer *peer, struct prefix *p, u_int32_t addpath_id,
           peer->rcvd_attr_printed = 1;
         }
 
-      zlog_debug ("%s rcvd %s%s ", peer->host,
+      zlog_debug ("%s rcvd %s %s ", peer->host,
                   bgp_debug_rdpfxpath2str (prd, p, addpath_id ? 1 : 0,
                                  addpath_id, pfx_buf, sizeof (pfx_buf)), label_buf);
     }
@@ -3902,10 +3901,9 @@ bgp_static_update (struct bgp *bgp, struct prefix *p,
 
          /* Nexthop reachability check. */
          if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK) &&
-              safi == SAFI_UNICAST)
+             (safi == SAFI_UNICAST || safi == SAFI_LABELED_UNICAST))
            {
-             if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0) &&
-                  safi == SAFI_UNICAST)
+             if (bgp_find_or_add_nexthop (bgp, afi, ri, NULL, 0))
                bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
              else
                {
@@ -3943,7 +3941,8 @@ bgp_static_update (struct bgp *bgp, struct prefix *p,
   new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_STATIC, 0, bgp->peer_self, attr_new,
                  rn);
   /* Nexthop reachability check. */
-  if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
+  if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK) &&
+      (safi == SAFI_UNICAST || safi == SAFI_LABELED_UNICAST))
     {
       if (bgp_find_or_add_nexthop (bgp, afi, new, NULL, 0))
        bgp_info_set_flag (rn, new, BGP_INFO_VALID);
@@ -4086,7 +4085,7 @@ bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
 
   if ((safi == SAFI_EVPN) || (safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
     {
-      if (bgp_static->igpnexthop.s_addr)
+      if (afi == AFI_IP)
         {
           bgp_attr_extra_get (&attr)->mp_nexthop_global_in = bgp_static->igpnexthop;
           bgp_attr_extra_get (&attr)->mp_nexthop_len = IPV4_MAX_BYTELEN;
@@ -4540,8 +4539,8 @@ bgp_purge_static_redist_routes (struct bgp *bgp)
  * I think it can probably be factored with bgp_static_set.
  */
 int
-bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
-                     const char *rd_str, const char *tag_str,
+bgp_static_set_safi (afi_t afi, safi_t safi, struct vty *vty, const char *ip_str,
+                     const char *rd_str, const char *label_str,
                      const char *rmap_str, int evpn_type, const char *esi, const char *gwip,
                      const char *ethtag, const char *routermac)
 {
@@ -4554,14 +4553,8 @@ bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
   struct bgp_table *table;
   struct bgp_static *bgp_static;
   u_char tag[3];
-  afi_t afi;
   struct prefix gw_ip;
 
-  if(safi == SAFI_EVPN)
-    afi = AFI_L2VPN;
-  else
-    afi = AFI_IP;
-
   /* validate ip prefix */
   ret = str2prefix (ip_str, &p);
   if (! ret)
@@ -4584,18 +4577,15 @@ bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
       return CMD_WARNING;
     }
 
-  if (tag_str)
+  if (label_str)
     {
-      ret = str2tag (tag_str, tag);
-      if (! ret)
-        {
-          vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
-          return CMD_WARNING;
-        }
+      unsigned long label_val;
+      VTY_GET_INTEGER_RANGE("Label/tag", label_val, label_str, 0, 16777215);
+      encode_label (label_val, tag);
     }
   else
     {
-      encode_label (0, tag);
+      memset (tag, 0, sizeof(tag)); /* empty, not even BoS */
     }
   if (safi == SAFI_EVPN)
     {
@@ -4655,8 +4645,8 @@ bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
       if (rmap_str)
        {
          if (bgp_static->rmap.name)
-           free (bgp_static->rmap.name);
-         bgp_static->rmap.name = strdup (rmap_str);
+           XFREE(MTYPE_ROUTE_MAP_NAME, bgp_static->rmap.name);
+         bgp_static->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, rmap_str);
          bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
        }
 
@@ -4686,8 +4676,8 @@ bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
 
 /* Configure static BGP network. */
 int
-bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
-                      const char *rd_str, const char *tag_str,
+bgp_static_unset_safi(afi_t afi, safi_t safi, struct vty *vty, const char *ip_str,
+                      const char *rd_str, const char *label_str,
                       int evpn_type, const char *esi, const char *gwip, const char *ethtag)
 {
   VTY_DECLVAR_CONTEXT(bgp, bgp);
@@ -4699,12 +4689,6 @@ bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
   struct bgp_table *table;
   struct bgp_static *bgp_static;
   u_char tag[3];
-  afi_t afi;
-
-  if(safi == SAFI_EVPN)
-    afi = AFI_L2VPN;
-  else
-    afi = AFI_IP;
 
   /* Convert IP prefix string to struct prefix. */
   ret = str2prefix (ip_str, &p);
@@ -4727,11 +4711,15 @@ bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
       return CMD_WARNING;
     }
 
-  ret = str2tag (tag_str, tag);
-  if (! ret)
+  if (label_str)
     {
-      vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
-      return CMD_WARNING;
+      unsigned long label_val;
+      VTY_GET_INTEGER_RANGE("Label/tag", label_val, label_str, 0, MPLS_LABEL_MAX);
+      encode_label (label_val, tag);
+    }
+  else
+    {
+      memset (tag, 0, sizeof(tag)); /* empty, not even BoS */
     }
 
   prn = bgp_node_get (bgp->route[afi][safi],
@@ -5029,7 +5017,7 @@ DEFUN (bgp_network_mask_natural_backdoor,
 
 DEFUN (bgp_network_label_index,
        bgp_network_label_index_cmd,
-       "network A.B.C.D/M label-index (0-4294967294)",
+       "network A.B.C.D/M label-index (0-1048560)",
        "Specify a network to announce via BGP\n"
        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
        "Label index to associate with the prefix\n"
@@ -5044,7 +5032,7 @@ DEFUN (bgp_network_label_index,
 
 DEFUN (bgp_network_label_index_route_map,
        bgp_network_label_index_route_map_cmd,
-       "network A.B.C.D/M label-index (0-4294967294) route-map WORD",
+       "network A.B.C.D/M label-index (0-1048560) route-map WORD",
        "Specify a network to announce via BGP\n"
        "IP prefix\n"
        "Label index to associate with the prefix\n"
@@ -5129,7 +5117,7 @@ DEFUN (no_bgp_network_mask_natural,
 
 ALIAS (no_bgp_network,
        no_bgp_network_label_index_cmd,
-       "no network A.B.C.D/M label-index (0-4294967294)",
+       "no network A.B.C.D/M label-index (0-1048560)",
        NO_STR
        "Specify a network to announce via BGP\n"
        "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
@@ -5138,7 +5126,7 @@ ALIAS (no_bgp_network,
 
 ALIAS (no_bgp_network,
        no_bgp_network_label_index_route_map_cmd,
-       "no network A.B.C.D/M label-index (0-4294967294) route-map WORD",
+       "no network A.B.C.D/M label-index (0-1048560) route-map WORD",
        NO_STR
        "Specify a network to announce via BGP\n"
        "IP prefix\n"
@@ -5176,7 +5164,7 @@ DEFUN (ipv6_bgp_network_route_map,
 
 DEFUN (ipv6_bgp_network_label_index,
        ipv6_bgp_network_label_index_cmd,
-       "network X:X::X:X/M label-index (0-4294967294)",
+       "network X:X::X:X/M label-index (0-1048560)",
        "Specify a network to announce via BGP\n"
        "IPv6 prefix <network>/<length>\n"
        "Label index to associate with the prefix\n"
@@ -5191,7 +5179,7 @@ DEFUN (ipv6_bgp_network_label_index,
 
 DEFUN (ipv6_bgp_network_label_index_route_map,
        ipv6_bgp_network_label_index_route_map_cmd,
-       "network X:X::X:X/M label-index (0-4294967294) route-map WORD",
+       "network X:X::X:X/M label-index (0-1048560) route-map WORD",
        "Specify a network to announce via BGP\n"
        "IPv6 prefix\n"
        "Label index to associate with the prefix\n"
@@ -5221,7 +5209,7 @@ DEFUN (no_ipv6_bgp_network,
 
 ALIAS (no_ipv6_bgp_network,
        no_ipv6_bgp_network_label_index_cmd,
-       "no network X:X::X:X/M label-index (0-4294967294)",
+       "no network X:X::X:X/M label-index (0-1048560)",
        NO_STR
        "Specify a network to announce via BGP\n"
        "IPv6 prefix <network>/<length>\n"
@@ -5230,7 +5218,7 @@ ALIAS (no_ipv6_bgp_network,
 
 ALIAS (no_ipv6_bgp_network,
        no_ipv6_bgp_network_label_index_route_map_cmd,
-       "no network X:X::X:X/M label-index (0-4294967294) route-map WORD",
+       "no network X:X::X:X/M label-index (0-1048560) route-map WORD",
        NO_STR
        "Specify a network to announce via BGP\n"
        "IPv6 prefix\n"
@@ -8070,12 +8058,6 @@ bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
       return bgp_show_mpls_vpn(vty, afi, NULL, type, output_arg,
                                0, use_json);
     }
-  if (safi == SAFI_ENCAP) 
-    {
-      return bgp_show_encap(vty, afi, NULL, type, output_arg,
-                            0);
-    }
-
 
   table = bgp->rib[afi][safi];
 
@@ -8089,7 +8071,6 @@ bgp_show_all_instances_routes_vty (struct vty *vty, afi_t afi, safi_t safi,
 {
   struct listnode *node, *nnode;
   struct bgp *bgp;
-  struct bgp_table *table;
   int is_first = 1;
 
   if (use_json)
@@ -8115,9 +8096,7 @@ bgp_show_all_instances_routes_vty (struct vty *vty, afi_t afi, safi_t safi,
                    ? "Default" : bgp->name,
                    VTY_NEWLINE);
         }
-      table = bgp->rib[afi][safi];
-      bgp_show_table (vty, bgp, table,
-                      bgp_show_type_normal, NULL, use_json);
+      bgp_show (vty, bgp, afi, safi, bgp_show_type_normal, NULL, use_json);
 
     }
 
@@ -8459,7 +8438,7 @@ bgp_show_lcommunity_list (struct vty *vty, struct bgp *bgp, const char *lcom,
 
 DEFUN (show_ip_bgp_large_community_list,
        show_ip_bgp_large_community_list_cmd,
-       "show [ip] bgp [<view|vrf> WORD] [<ipv4|ipv6> [<unicast|multicast|vpn|encap|labeled-unicast>]] large-community-list <(1-500)|WORD> [json]",
+       "show [ip] bgp [<view|vrf> WORD] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]] large-community-list <(1-500)|WORD> [json]",
        SHOW_STR
        IP_STR
        BGP_STR
@@ -8470,7 +8449,6 @@ DEFUN (show_ip_bgp_large_community_list,
        "Address Family modifier\n"
        "Address Family modifier\n"
        "Address Family modifier\n"
-       "Address Family modifier\n"
        "Display routes matching the large-community-list\n"
        "large-community-list number\n"
        "large-community-list name\n"
@@ -8506,7 +8484,7 @@ DEFUN (show_ip_bgp_large_community_list,
 }
 DEFUN (show_ip_bgp_large_community,
        show_ip_bgp_large_community_cmd,
-       "show [ip] bgp [<view|vrf> WORD] [<ipv4|ipv6> [<unicast|multicast|vpn|encap|labeled-unicast>]] large-community [AA:BB:CC] [json]",
+       "show [ip] bgp [<view|vrf> WORD] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]] large-community [AA:BB:CC] [json]",
        SHOW_STR
        IP_STR
        BGP_STR
@@ -8517,7 +8495,6 @@ DEFUN (show_ip_bgp_large_community,
        "Address Family modifier\n"
        "Address Family modifier\n"
        "Address Family modifier\n"
-       "Address Family modifier\n"
        "Display routes matching the large-communities\n"
        "List of large-community numbers\n"
        JSON_STR)
@@ -8673,8 +8650,6 @@ DEFUN (show_ip_bgp,
 
   if (safi == SAFI_MPLS_VPN)
     return bgp_show_mpls_vpn (vty, afi, NULL, bgp_show_type_normal, NULL, 0, uj);
-  else if (safi == SAFI_ENCAP)
-    return bgp_show_encap (vty, afi, NULL, bgp_show_type_normal, NULL, 0);
   else
     return bgp_show (vty, bgp, afi, safi, sh_type, NULL, uj);
 }
@@ -9462,7 +9437,7 @@ bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, u_c
 
 DEFUN (show_ip_bgp_instance_neighbor_prefix_counts,
        show_ip_bgp_instance_neighbor_prefix_counts_cmd,
-       "show [ip] bgp [<view|vrf> WORD] [<ipv4|ipv6> [<unicast|multicast|vpn|encap|labeled-unicast>]] "
+       "show [ip] bgp [<view|vrf> WORD] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]] "
        "neighbors <A.B.C.D|X:X::X:X|WORD> prefix-counts [json]",
        SHOW_STR
        IP_STR
@@ -10683,10 +10658,19 @@ bgp_config_write_network_vpn (struct vty *vty, struct bgp *bgp,
            prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
            label = decode_label (bgp_static->tag);
 
-           vty_out (vty, "  network %s/%d rd %s tag %d",
+           vty_out (vty, "  network %s/%d rd %s",
                     inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), 
-                    p->prefixlen,
-                    rdbuf, label);
+                    p->prefixlen, rdbuf);
+           if (safi == SAFI_MPLS_VPN)
+             vty_out (vty, " label %u", label);
+
+            if (bgp_static->rmap.name)
+              vty_out (vty, " route-map %s", bgp_static->rmap.name);
+            else
+              {
+                if (bgp_static->backdoor)
+                  vty_out (vty, " backdoor");
+              }
            vty_out (vty, "%s", VTY_NEWLINE);
          }
   return 0;
@@ -11004,10 +10988,10 @@ bgp_route_init (void)
   install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
   install_element (BGP_IPV6_NODE, &no_bgp_table_map_cmd);
   install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
-  install_element (BGP_IPV6_NODE, &ipv6_bgp_network_label_index_cmd);
-  install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_label_index_cmd);
-  install_element (BGP_IPV6_NODE, &ipv6_bgp_network_label_index_route_map_cmd);
-  install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_label_index_route_map_cmd);
+  install_element (BGP_IPV6L_NODE, &ipv6_bgp_network_label_index_cmd);
+  install_element (BGP_IPV6L_NODE, &no_ipv6_bgp_network_label_index_cmd);
+  install_element (BGP_IPV6L_NODE, &ipv6_bgp_network_label_index_route_map_cmd);
+  install_element (BGP_IPV6L_NODE, &no_ipv6_bgp_network_label_index_route_map_cmd);
 
   install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
   install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);