]> git.proxmox.com Git - mirror_frr.git/commitdiff
Merge pull request #4970 from shikenghua/prefer_global
authorRuss White <russ@riw.us>
Tue, 17 Sep 2019 11:33:05 +0000 (07:33 -0400)
committerGitHub <noreply@github.com>
Tue, 17 Sep 2019 11:33:05 +0000 (07:33 -0400)
bgpd: prefer-global command not working on IPv4 peers

1  2 
bgpd/bgp_routemap.c

diff --combined bgpd/bgp_routemap.c
index e7521c62ff7153e9c7f004963a3a0482c294d328,18355653645c4958eaf1fdbee74b8ce524268524..cb3d79436dd1b7298b50d7f0b2714535fdcff318
@@@ -1210,26 -1210,10 +1210,26 @@@ static void route_match_community_free(
        XFREE(MTYPE_ROUTE_MAP_COMPILED, rcom);
  }
  
 +/*
 + * In routemap processing there is a need to add the
 + * name as a rule_key in the dependency table. Routemap
 + * lib is unaware of rule_key when exact-match clause
 + * is in use. routemap lib uses the compiled output to
 + * get the rule_key value.
 + */
 +static void *route_match_get_community_key(void *rule)
 +{
 +      struct rmap_community *rcom;
 +
 +      rcom = rule;
 +      return rcom->name;
 +}
 +
 +
  /* Route map commands for community matching. */
  struct route_map_rule_cmd route_match_community_cmd = {
        "community", route_match_community, route_match_community_compile,
 -      route_match_community_free};
 +      route_match_community_free, route_match_get_community_key};
  
  /* Match function for lcommunity match. */
  static enum route_map_cmd_result_t
@@@ -1300,8 -1284,7 +1300,8 @@@ static void route_match_lcommunity_free
  /* Route map commands for community matching. */
  struct route_map_rule_cmd route_match_lcommunity_cmd = {
        "large-community", route_match_lcommunity,
 -      route_match_lcommunity_compile, route_match_lcommunity_free};
 +      route_match_lcommunity_compile, route_match_lcommunity_free,
 +      route_match_get_community_key};
  
  
  /* Match function for extcommunity match. */
@@@ -2748,10 -2731,8 +2748,8 @@@ route_set_ipv6_nexthop_prefer_global(vo
                path = object;
                peer = path->peer;
  
-               if ((CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IN)
-                    || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IMPORT))
-                   && peer->su_remote
-                   && sockunion_family(peer->su_remote) == AF_INET6) {
+               if (CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IN)
+                   || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IMPORT)) {
                        /* Set next hop preference to global */
                        path->attr->mp_nexthop_prefer_global = true;
                        SET_FLAG(path->attr->rmap_change_flags,
@@@ -2873,15 -2854,12 +2871,15 @@@ route_set_ipv6_nexthop_peer(void *rule
                        /* Set next hop value and length in attribute. */
                        if (IN6_IS_ADDR_LINKLOCAL(&peer_address)) {
                                path->attr->mp_nexthop_local = peer_address;
 -                              if (path->attr->mp_nexthop_len != 32)
 -                                      path->attr->mp_nexthop_len = 32;
 +                              if (path->attr->mp_nexthop_len
 +                                  != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
 +                                      path->attr->mp_nexthop_len =
 +                                              BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL;
                        } else {
                                path->attr->mp_nexthop_global = peer_address;
                                if (path->attr->mp_nexthop_len == 0)
 -                                      path->attr->mp_nexthop_len = 16;
 +                                      path->attr->mp_nexthop_len =
 +                                              BGP_ATTR_NHLEN_IPV6_GLOBAL;
                        }
  
                } else if (CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_OUT)) {
@@@ -2946,7 -2924,7 +2944,7 @@@ route_set_vpnv4_nexthop(void *rule, con
  
                /* Set next hop value. */
                path->attr->mp_nexthop_global_in = *address;
 -              path->attr->mp_nexthop_len = 4;
 +              path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_IPV4;
        }
  
        return RMAP_OKAY;
@@@ -3093,6 -3071,11 +3091,6 @@@ static int bgp_route_match_add(struct v
                retval = CMD_WARNING_CONFIG_FAILED;
                break;
        case RMAP_COMPILE_SUCCESS:
 -              if (type != RMAP_EVENT_MATCH_ADDED) {
 -                      route_map_upd8_dependency(type, arg, index->map->name);
 -              }
 -              break;
 -      case RMAP_DUPLICATE_RULE:
                /*
                 * Intentionally doing nothing here.
                 */
@@@ -3126,7 -3109,7 +3124,7 @@@ static int bgp_route_match_delete(struc
                rmap_name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, index->map->name);
        }
  
 -      ret = route_map_delete_match(index, command, dep_name);
 +      ret = route_map_delete_match(index, command, dep_name, type);
        switch (ret) {
        case RMAP_RULE_MISSING:
                vty_out(vty, "%% BGP Can't find rule.\n");
                retval = CMD_WARNING_CONFIG_FAILED;
                break;
        case RMAP_COMPILE_SUCCESS:
 -              if (type != RMAP_EVENT_MATCH_DELETED && dep_name)
 -                      route_map_upd8_dependency(type, dep_name, rmap_name);
 -              break;
 -      case RMAP_DUPLICATE_RULE:
                /*
                 * Nothing to do here
                 */