diff options
author | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2018-12-16 23:44:24 +0100 |
---|---|---|
committer | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2018-12-16 23:44:24 +0100 |
commit | 1cab2b4a7cffb7ad604dcbd200267733ef079973 (patch) | |
tree | 0874fe2787c5b05fc0d8259963a65960e6d816eb /proto/bgp/packets.c | |
parent | 337165959c5a556d6556fb2acbba5e7f2b1c35a5 (diff) |
BGP: Extend 'next hop keep' and 'next hop self' options
Extend 'next hop keep' and 'next hop self' options to have boolean values
(enabled / disabled) and also values 'ibgp'/ 'ebgp' to restrict it to
routes received from IBGP / EBGP. This allows to have it enabled by
default in some cases, matches features of other implementations, and
allows to handle some strange cases like EBGP border router with 'next
hop self' also doing IBGP route reflecting.
Change default of 'next hop keep' to enabled for route servers, and
'ibgp' for route reflectors.
Update documentation for these options.
Diffstat (limited to 'proto/bgp/packets.c')
-rw-r--r-- | proto/bgp/packets.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c index e7089eba..26716573 100644 --- a/proto/bgp/packets.c +++ b/proto/bgp/packets.c @@ -851,6 +851,19 @@ bgp_apply_mpls_labels(struct bgp_parse_state *s, rta *a, u32 *labels, uint lnum) } +static int +bgp_match_src(struct bgp_export_state *s, int mode) +{ + switch (mode) + { + case NH_NO: return 0; + case NH_ALL: return 1; + case NH_IBGP: return s->src && s->src->is_internal; + case NH_EBGP: return s->src && !s->src->is_internal; + default: return 0; + } +} + static inline int bgp_use_next_hop(struct bgp_export_state *s, eattr *a) { @@ -858,10 +871,12 @@ bgp_use_next_hop(struct bgp_export_state *s, eattr *a) struct bgp_channel *c = s->channel; ip_addr *nh = (void *) a->u.ptr->data; - if (s->channel->cf->next_hop_self) + /* Handle next hop self option */ + if (c->cf->next_hop_self && bgp_match_src(s, c->cf->next_hop_self)) return 0; - if (s->channel->cf->next_hop_keep) + /* Handle next hop keep option */ + if (c->cf->next_hop_keep && bgp_match_src(s, c->cf->next_hop_keep)) return 1; /* Keep it when explicitly set in export filter */ @@ -888,7 +903,8 @@ bgp_use_gateway(struct bgp_export_state *s) struct bgp_channel *c = s->channel; rta *ra = s->route->attrs; - if (s->channel->cf->next_hop_self) + /* Handle next hop self option - also applies to gateway */ + if (c->cf->next_hop_self && bgp_match_src(s, c->cf->next_hop_self)) return 0; /* We need one valid global gateway */ |