]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_route.c
Merge remote-tracking branch 'origin/stable/3.0'
[mirror_frr.git] / bgpd / bgp_route.c
index 140003cef0bd33736ef96a7807033a9b8afd6f8f..834b9e073e24a7226983eb1fb0f6d4e39bfe826b 100644 (file)
@@ -301,16 +301,7 @@ bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
 static int
 bgp_label_index_differs (struct bgp_info *ri1, struct bgp_info *ri2)
 {
-  u_int32_t ri1_label_index = BGP_INVALID_LABEL_INDEX;
-  u_int32_t ri2_label_index = BGP_INVALID_LABEL_INDEX;
-
-  if (ri1->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LABEL_INDEX))
-    ri1_label_index = ri1->attr->extra->label_index;
-
-  if (ri2->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LABEL_INDEX))
-    ri2_label_index = ri2->attr->extra->label_index;
-
-  return (!(ri1_label_index == ri2_label_index));
+  return (!(ri1->attr->extra->label_index == ri2->attr->extra->label_index));
 }
 
 /* Set/unset bgp_info flags, adjusting any other state as needed.
@@ -1465,7 +1456,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))) || \
+     (p->family == AF_INET6 || peer_cap_enhe(peer, AFI_IP6, safi))) || \
     ((safi == SAFI_ENCAP || safi == SAFI_MPLS_VPN) &&\
      attr->extra->mp_nexthop_len >= IPV6_MAX_BYTELEN))
 
@@ -1567,7 +1558,7 @@ subgroup_announce_check (struct bgp_node *rn, struct bgp_info *ri,
           if (!reflect ||
               CHECK_FLAG (peer->af_flags[afi][safi],
                           PEER_FLAG_FORCE_NEXTHOP_SELF))
-            subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ?
+            subgroup_announce_reset_nhop ((peer_cap_enhe(peer, afi, safi) ?
                           AF_INET6 : p->family), attr);
         }
       else if (peer->sort == BGP_PEER_EBGP)
@@ -1582,14 +1573,14 @@ subgroup_announce_check (struct bgp_node *rn, struct bgp_info *ri,
                 break;
             }
           if (!paf)
-            subgroup_announce_reset_nhop ((peer_cap_enhe(peer) ? AF_INET6 : p->family), attr);
+            subgroup_announce_reset_nhop ((peer_cap_enhe(peer, afi, safi) ? AF_INET6 : p->family), attr);
         }
       /* If IPv6/MP and nexthop does not have any override and happens to
        * be a link-local address, reset it so that we don't pass along the
        * source's link-local IPv6 address to recipients who may not be on
        * the same interface.
        */
-      if (p->family == AF_INET6 || peer_cap_enhe(peer))
+      if (p->family == AF_INET6 || peer_cap_enhe(peer, afi, safi))
         {
           if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global))
             subgroup_announce_reset_nhop (AF_INET6, attr);
@@ -1960,7 +1951,8 @@ bgp_process_main (struct work_queue *wq, void *data)
               new_select->sub_type != old_select->sub_type)
             {
               if (new_select->sub_type == BGP_ROUTE_STATIC &&
-                  new_select->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LABEL_INDEX))
+                  new_select->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_PREFIX_SID) &&
+                  new_select->attr->extra->label_index != BGP_INVALID_LABEL_INDEX)
                 {
                   if (CHECK_FLAG (rn->flags, BGP_NODE_REGISTERED_FOR_LABEL))
                     bgp_unregister_for_label (rn);
@@ -2025,9 +2017,10 @@ bgp_process_main (struct work_queue *wq, void *data)
       if (!bgp->t_rmap_def_originate_eval)
         {
           bgp_lock (bgp);
-          THREAD_TIMER_ON(bm->master, bgp->t_rmap_def_originate_eval,
-                          update_group_refresh_default_originate_route_map,
-                          bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER);
+          thread_add_timer(bm->master,
+                           update_group_refresh_default_originate_route_map,
+                           bgp, RMAP_DEFAULT_ORIGINATE_EVAL_TIMER,
+                           &bgp->t_rmap_def_originate_eval);
         }
     }
 
@@ -3096,9 +3089,6 @@ bgp_announce_route_timer_expired (struct thread *t)
   paf = THREAD_ARG (t);
   peer = paf->peer;
 
-  assert (paf->t_announce_route);
-  paf->t_announce_route = NULL;
-
   if (peer->status != Established)
     return 0;
 
@@ -3138,11 +3128,9 @@ bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
    * multiple peers and the announcement doesn't happen in the
    * vty context.
    */
-  THREAD_TIMER_MSEC_ON (bm->master, paf->t_announce_route,
-                       bgp_announce_route_timer_expired, paf,
-                        (subgrp->peer_count == 1) ?
-                       BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS :
-                       BGP_ANNOUNCE_ROUTE_DELAY_MS);
+  thread_add_timer_msec(bm->master, bgp_announce_route_timer_expired, paf,
+                        (subgrp->peer_count == 1) ? BGP_ANNOUNCE_ROUTE_SHORT_DELAY_MS : BGP_ANNOUNCE_ROUTE_DELAY_MS,
+                        &paf->t_announce_route);
 }
 
 /*
@@ -3824,7 +3812,7 @@ bgp_static_update (struct bgp *bgp, struct prefix *p,
   if (bgp_static->label_index != BGP_INVALID_LABEL_INDEX)
     {
       (bgp_attr_extra_get (&attr))->label_index = bgp_static->label_index;
-      attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_LABEL_INDEX);
+      attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_PREFIX_SID);
     }
 
   /* Apply route-map. */
@@ -4413,7 +4401,7 @@ bgp_static_add (struct bgp *bgp)
 
                for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
                  {
-                   bgp_static = rn->info;
+                   bgp_static = rm->info;
                     bgp_static_update_safi (bgp, &rm->p, bgp_static, afi, safi);
                  }
              }
@@ -4447,7 +4435,7 @@ bgp_static_delete (struct bgp *bgp)
 
                for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
                  {
-                   bgp_static = rn->info;
+                   bgp_static = rm->info;
                    bgp_static_withdraw_safi (bgp, &rm->p,
                                               AFI_IP, safi,
                                               (struct prefix_rd *)&rn->p,
@@ -4474,6 +4462,8 @@ bgp_static_redo_import_check (struct bgp *bgp)
   afi_t afi;
   safi_t safi;
   struct bgp_node *rn;
+  struct bgp_node *rm;
+  struct bgp_table *table;
   struct bgp_static *bgp_static;
 
   /* Use this flag to force reprocessing of the route */
@@ -4483,8 +4473,21 @@ bgp_static_redo_import_check (struct bgp *bgp)
       for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
        if (rn->info != NULL)
          {
-           bgp_static = rn->info;
-           bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
+           if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP) || (safi == SAFI_EVPN))
+             {
+               table = rn->info;
+
+               for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
+                 {
+                   bgp_static = rm->info;
+                   bgp_static_update_safi (bgp, &rm->p, bgp_static, afi, safi);
+                 }
+             }
+           else
+             {
+               bgp_static = rn->info;
+               bgp_static_update (bgp, &rn->p, bgp_static, afi, safi);
+             }
          }
   bgp_flag_unset(bgp, BGP_FLAG_FORCE_STATIC_PROCESS);
 }
@@ -5765,11 +5768,11 @@ bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
     }
 
   aggregate = rn->info;
-  if (aggregate->safi & SAFI_UNICAST)
+  if (aggregate->safi == SAFI_UNICAST)
     bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
-  if (aggregate->safi & SAFI_LABELED_UNICAST)
+  if (aggregate->safi == SAFI_LABELED_UNICAST)
     bgp_aggregate_delete (bgp, &p, afi, SAFI_LABELED_UNICAST, aggregate);
-  if (aggregate->safi & SAFI_MULTICAST)
+  if (aggregate->safi == SAFI_MULTICAST)
     bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
 
   /* Unlock aggregate address configuration. */
@@ -5825,11 +5828,11 @@ bgp_aggregate_set (struct vty *vty, const char *prefix_str,
   rn->info = aggregate;
 
   /* Aggregate address insert into BGP routing table. */
-  if (safi & SAFI_UNICAST)
+  if (safi == SAFI_UNICAST)
     bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
-  if (safi & SAFI_LABELED_UNICAST)
+  if (safi == SAFI_LABELED_UNICAST)
     bgp_aggregate_add (bgp, &p, afi, SAFI_LABELED_UNICAST, aggregate);
-  if (safi & SAFI_MULTICAST)
+  if (safi == SAFI_MULTICAST)
     bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
 
   return CMD_SUCCESS;
@@ -5868,9 +5871,8 @@ DEFUN (aggregate_address_mask,
 {
   int idx = 0;
   argv_find (argv, argc, "A.B.C.D", &idx);
-  char *prefix = argv[idx++]->arg;
-  argv_find (argv, argc, "A.B.C.D", &idx);
-  char *mask = argv[idx]->arg;
+  char *prefix = argv[idx]->arg;
+  char *mask = argv[idx+1]->arg;
   int as_set = argv_find (argv, argc, "as-set", &idx) ? AGGREGATE_AS_SET : 0;
   idx = 0;
   int summary_only = argv_find (argv, argc, "summary-only", &idx) ? AGGREGATE_SUMMARY_ONLY : 0;
@@ -5918,9 +5920,8 @@ DEFUN (no_aggregate_address_mask,
 {
   int idx = 0;
   argv_find (argv, argc, "A.B.C.D", &idx);
-  char *prefix = argv[idx++]->arg;
-  argv_find (argv, argc, "A.B.C.D", &idx);
-  char *mask = argv[idx]->arg;
+  char *prefix = argv[idx]->arg;
+  char *mask = argv[idx+1]->arg;
 
   char prefix_str[BUFSIZ];
   int ret = netmask_str2prefix_str (prefix, mask, prefix_str);
@@ -7653,32 +7654,24 @@ route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
       if (binfo->extra && binfo->extra->damp_info)
        bgp_damp_info_vty (vty, binfo, json_path);
 
-      if ((bgp_labeled_safi(safi) && binfo->extra) ||
-          (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_LABEL_INDEX))))
+      /* Remove Label */
+      if (bgp_labeled_safi(safi) && binfo->extra)
         {
-          if (!json_paths)
-            vty_out (vty, "%s      ", VTY_NEWLINE);
-
-          if (bgp_labeled_safi(safi) && binfo->extra)
-            {
-              uint32_t label = label_pton(binfo->extra->tag);
-              if (json_paths)
-                json_object_int_add(json_path, "remote-label", label);
-              else
-                vty_out(vty, "Remote label: %d, ", label);
-            }
-
-          if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_LABEL_INDEX)))
-            {
-              if (json_paths)
-                json_object_int_add(json_path, "label-index", attr->extra->label_index);
-              else
-                vty_out(vty, "Label Index: %d", attr->extra->label_index);
-            }
+          uint32_t label = label_pton(binfo->extra->tag);
+          if (json_paths)
+            json_object_int_add(json_path, "remoteLabel", label);
+          else
+            vty_out(vty, "      Remote label: %d%s", label, VTY_NEWLINE);
         }
 
-      if (!json_paths)
-        vty_out (vty, "%s", VTY_NEWLINE);
+      /* Label Index */
+      if (attr->extra->label_index != BGP_INVALID_LABEL_INDEX)
+        {
+          if (json_paths)
+            json_object_int_add(json_path, "labelIndex", attr->extra->label_index);
+          else
+            vty_out(vty, "      Label Index: %d%s", attr->extra->label_index, VTY_NEWLINE);
+        }
 
       /* Line 8 display Addpath IDs */
       if (binfo->addpath_rx_id || binfo->addpath_tx_id)
@@ -8676,7 +8669,7 @@ DEFUN (show_ip_bgp,
     }
   /* prefix-longer */
   if (argv_find(argv, argc, "A.B.C.D/M", &idx) || argv_find(argv, argc, "X:X::X:X/M", &idx))
-    return bgp_show_prefix_longer (vty, bgp, argv[idx + 1]->arg, afi, safi, bgp_show_type_prefix_longer);
+    return bgp_show_prefix_longer (vty, bgp, argv[idx]->arg, afi, safi, bgp_show_type_prefix_longer);
 
   if (safi == SAFI_MPLS_VPN)
     return bgp_show_mpls_vpn (vty, afi, NULL, bgp_show_type_normal, NULL, 0, uj);
@@ -9553,8 +9546,17 @@ DEFUN (show_ip_bgp_vpn_all_route_prefix,
       vty_out (vty, "Can't find default instance%s", VTY_NEWLINE);
       return CMD_WARNING;
     }
-  network = argv_find (argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
-  network = argv_find (argv, argc, "A.B.C.D/M", &idx) ? argv[idx]->arg : NULL;
+
+  if (argv_find (argv, argc, "A.B.C.D", &idx))
+    network = argv[idx]->arg;
+  else if (argv_find (argv, argc, "A.B.C.D/M", &idx))
+    network = argv[idx]->arg;
+  else
+    {
+      vty_out (vty, "Unable to figure out Network%s", VTY_NEWLINE);
+      return CMD_WARNING;
+    }
+
   return bgp_show_route (vty, bgp, network, AFI_IP, SAFI_MPLS_VPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
 }
 #endif /* KEEP_OLD_VPN_COMMANDS */
@@ -9574,8 +9576,16 @@ DEFUN (show_ip_bgp_l2vpn_evpn_all_route_prefix,
 {
   int idx = 0;
   char *network = NULL;
-  network = argv_find (argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
-  network = argv_find (argv, argc, "A.B.C.D/M", &idx) ? argv[idx]->arg : NULL;
+
+  if (argv_find (argv, argc, "A.B.C.D", &idx))
+    network = argv[idx]->arg;
+  else if (argv_find (argv, argc, "A.B.C.D/M", &idx))
+    network = argv[idx]->arg;
+  else
+    {
+      vty_out (vty, "Unable to figure out Network%s", VTY_NEWLINE);
+      return CMD_WARNING;
+    }
   return bgp_show_route (vty, NULL, network, AFI_L2VPN, SAFI_EVPN, NULL, 0, BGP_PATH_ALL, use_json(argc, argv));
 }