From b3cb197b949759ba51666900651f4a2b8b1a73ca Mon Sep 17 00:00:00 2001 From: Claudio Jeker Date: Thu, 28 Jun 2018 08:55:57 +0000 Subject: Instead of passing the rde_aspath to nexthop_modify() pass pointers to the nexthop and the flags. --- usr.sbin/bgpd/rde.h | 6 +++--- usr.sbin/bgpd/rde_filter.c | 8 ++++++-- usr.sbin/bgpd/rde_rib.c | 32 ++++++++++++++++---------------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/usr.sbin/bgpd/rde.h b/usr.sbin/bgpd/rde.h index 6bb7f7b8c0d..c85551b1764 100644 --- a/usr.sbin/bgpd/rde.h +++ b/usr.sbin/bgpd/rde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.h,v 1.172 2018/06/28 08:07:21 claudio Exp $ */ +/* $OpenBSD: rde.h,v 1.173 2018/06/28 08:55:56 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker and @@ -507,8 +507,8 @@ prefix_peer(struct prefix *p) void nexthop_init(u_int32_t); void nexthop_shutdown(void); -void nexthop_modify(struct rde_aspath *, struct nexthop *, - enum action_types, u_int8_t); +void nexthop_modify(struct nexthop *, enum action_types, u_int8_t, + struct nexthop **, u_int32_t *); void nexthop_link(struct rde_aspath *); void nexthop_unlink(struct rde_aspath *); void nexthop_update(struct kroute_nexthop *); diff --git a/usr.sbin/bgpd/rde_filter.c b/usr.sbin/bgpd/rde_filter.c index 08de8583921..ed236ec691a 100644 --- a/usr.sbin/bgpd/rde_filter.c +++ b/usr.sbin/bgpd/rde_filter.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_filter.c,v 1.91 2018/06/28 08:07:21 claudio Exp $ */ +/* $OpenBSD: rde_filter.c,v 1.92 2018/06/28 08:55:56 claudio Exp $ */ /* * Copyright (c) 2004 Claudio Jeker @@ -49,6 +49,9 @@ rde_apply_set(struct filter_set_head *sh, struct rde_aspath *asp, if (asp == NULL) return; + if (asp->flags & F_ATTR_LINKED) + fatalx("rde_apply_set: trying to modify linked asp"); + TAILQ_FOREACH(set, sh, entry) { switch (set->type) { case ACTION_SET_LOCALPREF: @@ -130,7 +133,8 @@ rde_apply_set(struct filter_set_head *sh, struct rde_aspath *asp, case ACTION_SET_NEXTHOP_BLACKHOLE: case ACTION_SET_NEXTHOP_NOMODIFY: case ACTION_SET_NEXTHOP_SELF: - nexthop_modify(asp, set->action.nh, set->type, aid); + nexthop_modify(set->action.nh, set->type, aid, + &asp->nexthop, &asp->flags); break; case ACTION_SET_COMMUNITY: switch (set->action.community.as) { diff --git a/usr.sbin/bgpd/rde_rib.c b/usr.sbin/bgpd/rde_rib.c index 7e51e58a793..6ba15e94998 100644 --- a/usr.sbin/bgpd/rde_rib.c +++ b/usr.sbin/bgpd/rde_rib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_rib.c,v 1.163 2018/06/28 08:07:21 claudio Exp $ */ +/* $OpenBSD: rde_rib.c,v 1.164 2018/06/28 08:55:56 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker @@ -1227,32 +1227,32 @@ nexthop_update(struct kroute_nexthop *msg) } void -nexthop_modify(struct rde_aspath *asp, struct nexthop *nh, - enum action_types type, u_int8_t aid) +nexthop_modify(struct nexthop *setnh, enum action_types type, u_int8_t aid, + struct nexthop **nexthop, u_int32_t *flags) { - if (asp->flags & F_ATTR_LINKED) - fatalx("nexthop_modify: trying to modify linked asp"); - - if (type == ACTION_SET_NEXTHOP && aid != nh->exit_nexthop.aid) - return; - - asp->flags &= ~F_NEXTHOP_MASK; + *flags &= ~F_NEXTHOP_MASK; switch (type) { case ACTION_SET_NEXTHOP_REJECT: - asp->flags |= F_NEXTHOP_REJECT; + *flags |= F_NEXTHOP_REJECT; break; case ACTION_SET_NEXTHOP_BLACKHOLE: - asp->flags |= F_NEXTHOP_BLACKHOLE; + *flags |= F_NEXTHOP_BLACKHOLE; break; case ACTION_SET_NEXTHOP_NOMODIFY: - asp->flags |= F_NEXTHOP_NOMODIFY; + *flags |= F_NEXTHOP_NOMODIFY; break; case ACTION_SET_NEXTHOP_SELF: - asp->flags |= F_NEXTHOP_SELF; + *flags |= F_NEXTHOP_SELF; break; case ACTION_SET_NEXTHOP: - nexthop_put(asp->nexthop); - asp->nexthop = nexthop_ref(nh); + /* + * it is possible that a prefix matches but has the wrong + * address family for the set nexthop. In this case ignore it. + */ + if (aid != setnh->exit_nexthop.aid) + break; + nexthop_put(*nexthop); + *nexthop = nexthop_ref(setnh); break; default: break; -- cgit v1.2.3