Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bgpd: do not accept a host route that matches a local address #17976

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bgpd/bgp_nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,14 @@ bool bgp_nexthop_self(struct bgp *bgp, afi_t afi, uint8_t type,
return false;
}

bool bgp_hostroute_self(struct bgp *bgp, const struct prefix *p)
{
struct bgp_addr tmp;

tmp.p = *p;
return hash_lookup(bgp->address_hash, &tmp) ? true : false;
}

bool bgp_multiaccess_check_v4(struct in_addr nexthop, struct peer *peer)
{
struct bgp_dest *dest1;
Expand Down
1 change: 1 addition & 0 deletions bgpd/bgp_nexthop.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ extern int bgp_config_write_scan_time(struct vty *);
extern bool bgp_nexthop_self(struct bgp *bgp, afi_t afi, uint8_t type,
uint8_t sub_type, struct attr *attr,
struct bgp_dest *dest);
extern bool bgp_hostroute_self(struct bgp *bgp, const struct prefix *p);
extern struct bgp_nexthop_cache *bnc_new(struct bgp_nexthop_cache_head *tree,
struct prefix *prefix,
uint32_t srte_color,
Expand Down
8 changes: 8 additions & 0 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -5103,6 +5103,14 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
goto filtered;
}

/* Do not accept a host route that matches a local address. */
if (((safi == SAFI_UNICAST) || (safi == SAFI_LABELED_UNICAST)) && is_host_route(p)) {
if (bgp_hostroute_self(bgp, p)) {
reason = "host route matches a local address";
goto filtered;
}
}

/* Apply incoming filter. */
if (bgp_input_filter(peer, p, attr, afi, orig_safi) == FILTER_DENY) {
peer->stat_pfx_filter++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
luCommand(
"ce1",
'vtysh -c "show bgp ipv4 uni"',
"7 routes and 7",
"6 routes and 6",
"wait",
"Local and remote routes",
)
luCommand(
"ce2",
'vtysh -c "show bgp ipv4 uni"',
"7 routes and 9",
"6 routes and 8",
"wait",
"Local and remote routes",
)
luCommand(
"ce3",
'vtysh -c "show bgp ipv4 uni"',
"7 routes and 7",
"6 routes and 6",
"wait",
"Local and remote routes",
)
Expand Down
Loading