Merge pull request #1336 from donaldsharp/peer_name

Peer name
This commit is contained in:
Lou Berger 2017-10-31 11:40:44 -04:00 committed by GitHub
commit 4053d45064
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 16 deletions

View File

@ -222,7 +222,12 @@ static void route_aspath_free(void *rule)
aspath_free(aspath); aspath_free(aspath);
} }
/* 'match peer (A.B.C.D|X:X::X:X)' */ struct bgp_match_peer_compiled {
char *interface;
union sockunion su;
};
/* 'match peer (A.B.C.D|X:X::X:X|WORD)' */
/* Compares the peer specified in the 'match peer' clause with the peer /* Compares the peer specified in the 'match peer' clause with the peer
received in bgp_info->peer. If it is the same, or if the peer structure received in bgp_info->peer. If it is the same, or if the peer structure
@ -231,6 +236,7 @@ static route_map_result_t route_match_peer(void *rule, struct prefix *prefix,
route_map_object_t type, route_map_object_t type,
void *object) void *object)
{ {
struct bgp_match_peer_compiled *pc;
union sockunion *su; union sockunion *su;
union sockunion su_def = { union sockunion su_def = {
.sin = {.sin_family = AF_INET, .sin_addr.s_addr = INADDR_ANY}}; .sin = {.sin_family = AF_INET, .sin_addr.s_addr = INADDR_ANY}};
@ -239,13 +245,20 @@ static route_map_result_t route_match_peer(void *rule, struct prefix *prefix,
struct listnode *node, *nnode; struct listnode *node, *nnode;
if (type == RMAP_BGP) { if (type == RMAP_BGP) {
su = rule; pc = rule;
su = &pc->su;
peer = ((struct bgp_info *)object)->peer; peer = ((struct bgp_info *)object)->peer;
if (!CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IMPORT) if (pc->interface) {
&& !CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_EXPORT)) if (!peer->conf_if)
return RMAP_NOMATCH; return RMAP_NOMATCH;
if (strcmp(peer->conf_if, pc->interface) == 0)
return RMAP_MATCH;
return RMAP_NOMATCH;
}
/* If su='0.0.0.0' (command 'match peer local'), and it's a /* If su='0.0.0.0' (command 'match peer local'), and it's a
NETWORK, NETWORK,
REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH REDISTRIBUTE or DEFAULT_GENERATED route => return RMAP_MATCH
@ -283,23 +296,29 @@ static route_map_result_t route_match_peer(void *rule, struct prefix *prefix,
static void *route_match_peer_compile(const char *arg) static void *route_match_peer_compile(const char *arg)
{ {
union sockunion *su; struct bgp_match_peer_compiled *pc;
int ret; int ret;
su = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(union sockunion)); pc = XMALLOC(MTYPE_ROUTE_MAP_COMPILED,
sizeof(struct bgp_match_peer_compiled));
ret = str2sockunion(strcmp(arg, "local") ? arg : "0.0.0.0", su); ret = str2sockunion(strcmp(arg, "local") ? arg : "0.0.0.0", &pc->su);
if (ret < 0) { if (ret < 0) {
XFREE(MTYPE_ROUTE_MAP_COMPILED, su); pc->interface = XSTRDUP(MTYPE_ROUTE_MAP_COMPILED, arg);
return NULL; return pc;
} }
return su; return pc;
} }
/* Free route map's compiled `ip address' value. */ /* Free route map's compiled `ip address' value. */
static void route_match_peer_free(void *rule) static void route_match_peer_free(void *rule)
{ {
struct bgp_match_peer_compiled *pc = rule;
if (pc->interface)
XFREE(MTYPE_ROUTE_MAP_COMPILED, pc->interface);
XFREE(MTYPE_ROUTE_MAP_COMPILED, rule); XFREE(MTYPE_ROUTE_MAP_COMPILED, rule);
} }
@ -3148,11 +3167,12 @@ DEFUN (no_match_evpn_vni,
DEFUN (match_peer, DEFUN (match_peer,
match_peer_cmd, match_peer_cmd,
"match peer <A.B.C.D|X:X::X:X>", "match peer <A.B.C.D|X:X::X:X|WORD>",
MATCH_STR MATCH_STR
"Match peer address\n" "Match peer address\n"
"IP address of peer\n" "IP address of peer\n"
"IPv6 address of peer\n") "IPv6 address of peer\n"
"Interface name of peer\n")
{ {
int idx_ip = 2; int idx_ip = 2;
return bgp_route_match_add(vty, "peer", argv[idx_ip]->arg, return bgp_route_match_add(vty, "peer", argv[idx_ip]->arg,
@ -3172,13 +3192,14 @@ DEFUN (match_peer_local,
DEFUN (no_match_peer, DEFUN (no_match_peer,
no_match_peer_cmd, no_match_peer_cmd,
"no match peer [<local|A.B.C.D|X:X::X:X>]", "no match peer [<local|A.B.C.D|X:X::X:X|WORD>]",
NO_STR NO_STR
MATCH_STR MATCH_STR
"Match peer address\n" "Match peer address\n"
"Static or Redistributed routes\n" "Static or Redistributed routes\n"
"IP address of peer\n" "IP address of peer\n"
"IPv6 address of peer\n") "IPv6 address of peer\n"
"Interface name of peer\n")
{ {
int idx_peer = 3; int idx_peer = 3;

View File

@ -11334,6 +11334,7 @@ static void bgp_ac_neighbor(vector comps, struct cmd_token *token)
static const struct cmd_variable_handler bgp_var_neighbor[] = { static const struct cmd_variable_handler bgp_var_neighbor[] = {
{.varname = "neighbor", .completions = bgp_ac_neighbor}, {.varname = "neighbor", .completions = bgp_ac_neighbor},
{.varname = "neighbors", .completions = bgp_ac_neighbor}, {.varname = "neighbors", .completions = bgp_ac_neighbor},
{.varname = "peer", .completions = bgp_ac_neighbor},
{.completions = NULL}}; {.completions = NULL}};
void bgp_vty_init(void) void bgp_vty_init(void)

View File

@ -159,6 +159,22 @@ Matches the specified @var{local-preference}.
Matches the specified @var{community_list} Matches the specified @var{community_list}
@end deffn @end deffn
@deffn {Route-map Command} {match peer @var{ipv4_addr}} {}
This is a BGP specific match command. Matches the peer ip address
if the neighbor was specified in this manner.
@end deffn
@deffn {Route-map Command} {match peer @var{ipv6_addr}} {}
This is a BGP specific match command. Matches the peer ipv6
address if the neighbor was specified in this manner.
@end deffn
@deffn {Route-map Command} {match peer @var{interface_name}} {}
This is a BGP specific match command. Matches the peer
interface name specified if the neighbor was specified
in this manner.
@end deffn
@node Route Map Set Command @node Route Map Set Command
@section Route Map Set Command @section Route Map Set Command