From: Igor Putovny Date: Thu, 29 May 2025 15:55:49 +0000 (+0200) Subject: BGP: Add option "next hop prefer local" and use it in direct mode of next hop computation X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=39258c09c4a1fed80a6e4d2af29295817755f047;p=thirdparty%2Fbird.git BGP: Add option "next hop prefer local" and use it in direct mode of next hop computation --- diff --git a/proto/bgp/config.Y b/proto/bgp/config.Y index d73c0317c..4a98df69e 100644 --- a/proto/bgp/config.Y +++ b/proto/bgp/config.Y @@ -423,6 +423,7 @@ bgp_channel_item: | NEXT HOP SELF bgp_nh { BGP_CC->next_hop_self = $4; } | NEXT HOP KEEP bgp_nh { BGP_CC->next_hop_keep = $4; } | NEXT HOP PREFER GLOBAL { BGP_CC->next_hop_prefer = NHP_GLOBAL; } + | NEXT HOP PREFER LOCAL { BGP_CC->next_hop_prefer = NHP_LOCAL; } | LINK LOCAL NEXT HOP FORMAT bgp_llnh { BGP_CC->llnh_format = $6; } | MANDATORY bool { BGP_CC->mandatory = $2; } | MISSING LLADDR bgp_lladdr { cf_warn("%s.%s: Missing lladdr option is deprecated and ignored, remove it", this_proto->name, this_channel->name); } diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c index 2eabe6ec1..f6744ec70 100644 --- a/proto/bgp/packets.c +++ b/proto/bgp/packets.c @@ -1086,10 +1086,12 @@ bgp_apply_next_hop(struct bgp_parse_state *s, rta *a, ip_addr gw, ip_addr ll) neighbor *nbr = NULL; /* GW_DIRECT -> single_hop -> p->neigh != NULL */ - if (ipa_nonzero2(gw)) + if ((c->cf->next_hop_prefer == NHP_GLOBAL) && ipa_nonzero2(gw)) nbr = neigh_find(&p->p, gw, NULL, 0); else if (ipa_nonzero(ll)) nbr = neigh_find(&p->p, ll, p->neigh->iface, 0); + else if (ipa_nonzero2(gw)) + nbr = neigh_find(&p->p, gw, NULL, 0); else WITHDRAW(BAD_NEXT_HOP " - zero address");