mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-08 07:37:29 +00:00
bgpd: Allow using remote-as the same as local-as
As an example, Arista EOS allows this behavior. Configuration something like: ``` neighbor PG peer-group neighbor PG remote-as 65001 neighbor PG local-as 65001 neighbor 192.168.10.124 peer-group PG ``` Or without peer-group. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
This commit is contained in:
parent
5ae96447d7
commit
d6b0327c35
@ -873,9 +873,6 @@ int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
|
|||||||
case BGP_ERR_REMOVE_PRIVATE_AS:
|
case BGP_ERR_REMOVE_PRIVATE_AS:
|
||||||
str = "remove-private-AS cannot be configured for IBGP peers";
|
str = "remove-private-AS cannot be configured for IBGP peers";
|
||||||
break;
|
break;
|
||||||
case BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP:
|
|
||||||
str = "Local-AS allowed only for EBGP peers";
|
|
||||||
break;
|
|
||||||
case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
|
case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS:
|
||||||
str = "Cannot have local-as same as BGP AS number";
|
str = "Cannot have local-as same as BGP AS number";
|
||||||
break;
|
break;
|
||||||
@ -936,9 +933,6 @@ int bgp_vty_return(struct vty *vty, enum bgp_create_error_code ret)
|
|||||||
case BGP_ERR_AF_UNCONFIGURED:
|
case BGP_ERR_AF_UNCONFIGURED:
|
||||||
str = "AFI/SAFI specified is not currently configured.";
|
str = "AFI/SAFI specified is not currently configured.";
|
||||||
break;
|
break;
|
||||||
case BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS_REMOTE_AS:
|
|
||||||
str = "AS specified for local as is the same as the remote as and this is not allowed.";
|
|
||||||
break;
|
|
||||||
case BGP_ERR_INVALID_AS:
|
case BGP_ERR_INVALID_AS:
|
||||||
str = "Confederation AS specified is the same AS as our AS.";
|
str = "Confederation AS specified is the same AS as our AS.";
|
||||||
break;
|
break;
|
||||||
|
51
bgpd/bgpd.c
51
bgpd/bgpd.c
@ -997,9 +997,15 @@ void peer_af_flag_inherit(struct peer *peer, afi_t afi, safi_t safi,
|
|||||||
static inline enum bgp_peer_sort peer_calc_sort(struct peer *peer)
|
static inline enum bgp_peer_sort peer_calc_sort(struct peer *peer)
|
||||||
{
|
{
|
||||||
struct bgp *bgp;
|
struct bgp *bgp;
|
||||||
|
as_t local_as;
|
||||||
|
|
||||||
bgp = peer->bgp;
|
bgp = peer->bgp;
|
||||||
|
|
||||||
|
if (peer->change_local_as)
|
||||||
|
local_as = peer->change_local_as;
|
||||||
|
else
|
||||||
|
local_as = peer->local_as;
|
||||||
|
|
||||||
/* Peer-group */
|
/* Peer-group */
|
||||||
if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
|
if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
|
||||||
if (peer->as_type == AS_INTERNAL)
|
if (peer->as_type == AS_INTERNAL)
|
||||||
@ -1010,7 +1016,7 @@ static inline enum bgp_peer_sort peer_calc_sort(struct peer *peer)
|
|||||||
|
|
||||||
else if (peer->as_type == AS_SPECIFIED && peer->as) {
|
else if (peer->as_type == AS_SPECIFIED && peer->as) {
|
||||||
assert(bgp);
|
assert(bgp);
|
||||||
return (bgp->as == peer->as ? BGP_PEER_IBGP
|
return (local_as == peer->as ? BGP_PEER_IBGP
|
||||||
: BGP_PEER_EBGP);
|
: BGP_PEER_EBGP);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1028,17 +1034,17 @@ static inline enum bgp_peer_sort peer_calc_sort(struct peer *peer)
|
|||||||
|
|
||||||
/* Normal peer */
|
/* Normal peer */
|
||||||
if (bgp && CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)) {
|
if (bgp && CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)) {
|
||||||
if (peer->local_as == 0)
|
if (local_as == 0)
|
||||||
return BGP_PEER_INTERNAL;
|
return BGP_PEER_INTERNAL;
|
||||||
|
|
||||||
if (peer->local_as == peer->as) {
|
if (local_as == peer->as) {
|
||||||
if (bgp->as == bgp->confed_id) {
|
if (bgp->as == bgp->confed_id) {
|
||||||
if (peer->local_as == bgp->as)
|
if (local_as == bgp->as)
|
||||||
return BGP_PEER_IBGP;
|
return BGP_PEER_IBGP;
|
||||||
else
|
else
|
||||||
return BGP_PEER_EBGP;
|
return BGP_PEER_EBGP;
|
||||||
} else {
|
} else {
|
||||||
if (peer->local_as == bgp->confed_id)
|
if (local_as == bgp->confed_id)
|
||||||
return BGP_PEER_EBGP;
|
return BGP_PEER_EBGP;
|
||||||
else
|
else
|
||||||
return BGP_PEER_IBGP;
|
return BGP_PEER_IBGP;
|
||||||
@ -1056,8 +1062,7 @@ static inline enum bgp_peer_sort peer_calc_sort(struct peer *peer)
|
|||||||
&& (peer->group->conf->as_type != AS_UNSPECIFIED)) {
|
&& (peer->group->conf->as_type != AS_UNSPECIFIED)) {
|
||||||
if (peer->group->conf->as_type
|
if (peer->group->conf->as_type
|
||||||
== AS_SPECIFIED) {
|
== AS_SPECIFIED) {
|
||||||
if (peer->local_as
|
if (local_as == peer->group->conf->as)
|
||||||
== peer->group->conf->as)
|
|
||||||
return BGP_PEER_IBGP;
|
return BGP_PEER_IBGP;
|
||||||
else
|
else
|
||||||
return BGP_PEER_EBGP;
|
return BGP_PEER_EBGP;
|
||||||
@ -1073,9 +1078,8 @@ static inline enum bgp_peer_sort peer_calc_sort(struct peer *peer)
|
|||||||
return (peer->as_type == AS_INTERNAL ? BGP_PEER_IBGP
|
return (peer->as_type == AS_INTERNAL ? BGP_PEER_IBGP
|
||||||
: BGP_PEER_EBGP);
|
: BGP_PEER_EBGP);
|
||||||
|
|
||||||
return (peer->local_as == 0
|
return (local_as == 0 ? BGP_PEER_INTERNAL
|
||||||
? BGP_PEER_INTERNAL
|
: local_as == peer->as ? BGP_PEER_IBGP
|
||||||
: peer->local_as == peer->as ? BGP_PEER_IBGP
|
|
||||||
: BGP_PEER_EBGP);
|
: BGP_PEER_EBGP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1885,14 +1889,6 @@ void peer_as_change(struct peer *peer, as_t as, int as_specified)
|
|||||||
UNSET_FLAG(peer->af_flags[AFI_L2VPN][SAFI_EVPN],
|
UNSET_FLAG(peer->af_flags[AFI_L2VPN][SAFI_EVPN],
|
||||||
PEER_FLAG_REFLECTOR_CLIENT);
|
PEER_FLAG_REFLECTOR_CLIENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* local-as reset */
|
|
||||||
if (newtype != BGP_PEER_EBGP) {
|
|
||||||
peer->change_local_as = 0;
|
|
||||||
peer_flag_unset(peer, PEER_FLAG_LOCAL_AS);
|
|
||||||
peer_flag_unset(peer, PEER_FLAG_LOCAL_AS_NO_PREPEND);
|
|
||||||
peer_flag_unset(peer, PEER_FLAG_LOCAL_AS_REPLACE_AS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If peer does not exist, create new one. If peer already exists,
|
/* If peer does not exist, create new one. If peer already exists,
|
||||||
@ -3018,17 +3014,6 @@ int peer_group_bind(struct bgp *bgp, union sockunion *su, struct peer *peer,
|
|||||||
/* ebgp-multihop reset */
|
/* ebgp-multihop reset */
|
||||||
if (gtype == BGP_PEER_IBGP)
|
if (gtype == BGP_PEER_IBGP)
|
||||||
group->conf->ttl = MAXTTL;
|
group->conf->ttl = MAXTTL;
|
||||||
|
|
||||||
/* local-as reset */
|
|
||||||
if (gtype != BGP_PEER_EBGP) {
|
|
||||||
group->conf->change_local_as = 0;
|
|
||||||
peer_flag_unset(group->conf,
|
|
||||||
PEER_FLAG_LOCAL_AS);
|
|
||||||
peer_flag_unset(group->conf,
|
|
||||||
PEER_FLAG_LOCAL_AS_NO_PREPEND);
|
|
||||||
peer_flag_unset(group->conf,
|
|
||||||
PEER_FLAG_LOCAL_AS_REPLACE_AS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SET_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE);
|
SET_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE);
|
||||||
@ -6109,17 +6094,10 @@ int peer_local_as_set(struct peer *peer, as_t as, bool no_prepend,
|
|||||||
struct bgp *bgp = peer->bgp;
|
struct bgp *bgp = peer->bgp;
|
||||||
struct peer *member;
|
struct peer *member;
|
||||||
struct listnode *node, *nnode;
|
struct listnode *node, *nnode;
|
||||||
enum bgp_peer_sort ptype = peer_sort(peer);
|
|
||||||
|
|
||||||
if (ptype != BGP_PEER_EBGP && ptype != BGP_PEER_INTERNAL)
|
|
||||||
return BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP;
|
|
||||||
|
|
||||||
if (bgp->as == as)
|
if (bgp->as == as)
|
||||||
return BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS;
|
return BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS;
|
||||||
|
|
||||||
if (peer->as == as)
|
|
||||||
return BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS_REMOTE_AS;
|
|
||||||
|
|
||||||
/* Save previous flag states. */
|
/* Save previous flag states. */
|
||||||
old_no_prepend =
|
old_no_prepend =
|
||||||
!!CHECK_FLAG(peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND);
|
!!CHECK_FLAG(peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND);
|
||||||
@ -6135,6 +6113,7 @@ int peer_local_as_set(struct peer *peer, as_t as, bool no_prepend,
|
|||||||
&& old_replace_as == replace_as)
|
&& old_replace_as == replace_as)
|
||||||
return 0;
|
return 0;
|
||||||
peer->change_local_as = as;
|
peer->change_local_as = as;
|
||||||
|
(void)peer_sort(peer);
|
||||||
|
|
||||||
/* Check if handling a regular peer. */
|
/* Check if handling a regular peer. */
|
||||||
if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
|
if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
|
||||||
|
@ -2004,13 +2004,11 @@ enum bgp_create_error_code {
|
|||||||
BGP_ERR_AF_UNCONFIGURED = -15,
|
BGP_ERR_AF_UNCONFIGURED = -15,
|
||||||
BGP_ERR_SOFT_RECONFIG_UNCONFIGURED = -16,
|
BGP_ERR_SOFT_RECONFIG_UNCONFIGURED = -16,
|
||||||
BGP_ERR_INSTANCE_MISMATCH = -17,
|
BGP_ERR_INSTANCE_MISMATCH = -17,
|
||||||
BGP_ERR_LOCAL_AS_ALLOWED_ONLY_FOR_EBGP = -18,
|
|
||||||
BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS = -19,
|
BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS = -19,
|
||||||
BGP_ERR_TCPSIG_FAILED = -20,
|
BGP_ERR_TCPSIG_FAILED = -20,
|
||||||
BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK = -21,
|
BGP_ERR_NO_EBGP_MULTIHOP_WITH_TTLHACK = -21,
|
||||||
BGP_ERR_NO_IBGP_WITH_TTLHACK = -22,
|
BGP_ERR_NO_IBGP_WITH_TTLHACK = -22,
|
||||||
BGP_ERR_NO_INTERFACE_CONFIG = -23,
|
BGP_ERR_NO_INTERFACE_CONFIG = -23,
|
||||||
BGP_ERR_CANNOT_HAVE_LOCAL_AS_SAME_AS_REMOTE_AS = -24,
|
|
||||||
BGP_ERR_AS_OVERRIDE = -25,
|
BGP_ERR_AS_OVERRIDE = -25,
|
||||||
BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT = -26,
|
BGP_ERR_INVALID_DYNAMIC_NEIGHBORS_LIMIT = -26,
|
||||||
BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS = -27,
|
BGP_ERR_DYNAMIC_NEIGHBORS_RANGE_EXISTS = -27,
|
||||||
|
Loading…
Reference in New Issue
Block a user