-/* $OpenBSD: rde.c,v 1.584 2023/01/11 17:10:25 claudio Exp $ */
+/* $OpenBSD: rde.c,v 1.585 2023/01/12 17:35:51 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
}
memcpy(&netconf_s, imsg.data, sizeof(netconf_s));
TAILQ_INIT(&netconf_s.attrset);
- rde_filterstate_prep(&netconf_state, NULL, NULL, NULL,
- 0, 0);
+ rde_filterstate_init(&netconf_state);
asp = &netconf_state.aspath;
asp->aspath = aspath_get(NULL, 0);
asp->origin = ORIGIN_IGP;
case IMSG_NETWORK_DONE:
TAILQ_CONCAT(&netconf_p.attrset, &parent_set, entry);
- rde_filterstate_prep(&state, NULL, NULL, NULL, 0, 0);
+ rde_filterstate_init(&state);
asp = &state.aspath;
asp->aspath = aspath_get(NULL, 0);
asp->origin = ORIGIN_IGP;
}
memset(&mpa, 0, sizeof(mpa));
- rde_filterstate_prep(&state, NULL, NULL, NULL, 0, 0);
+ rde_filterstate_init(&state);
if (attrpath_len != 0) { /* 0 = no NLRI information in this message */
/* parse path attributes */
while (len > 0) {
struct rib *rib = rib_byid(i);
if (rib == NULL)
continue;
- rde_filterstate_prep(&state, &in->aspath, &in->communities,
- in->nexthop, in->nhflags, in->vstate);
+ rde_filterstate_copy(&state, in);
/* input filter */
action = rde_filter(rib->in_rules, peer, peer, prefix,
prefixlen, &state);
if (rib->state != RECONF_RELOAD)
continue;
- rde_filterstate_prep(&state, asp, prefix_communities(p),
- prefix_nexthop(p), prefix_nhflags(p),
- prefix_roa_vstate(p));
+ rde_filterstate_prep(&state, p);
action = rde_filter(rib->in_rules, peer, peer, &prefix,
pt->prefixlen, &state);
if (rib == NULL)
continue;
- rde_filterstate_prep(&state, asp, prefix_communities(p),
- prefix_nexthop(p), prefix_nhflags(p),
- prefix_roa_vstate(p));
+ rde_filterstate_prep(&state, p);
action = rde_filter(rib->in_rules, peer, peer, &prefix,
pt->prefixlen, &state);
-/* $OpenBSD: rde.h,v 1.277 2023/01/11 17:10:26 claudio Exp $ */
+/* $OpenBSD: rde.h,v 1.278 2023/01/12 17:35:51 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> and
/* rde_filter.c */
void rde_apply_set(struct filter_set_head *, struct rde_peer *,
struct rde_peer *, struct filterstate *, uint8_t);
-void rde_filterstate_prep(struct filterstate *, struct rde_aspath *,
- struct rde_community *, struct nexthop *, uint8_t, uint8_t);
+void rde_filterstate_init(struct filterstate *);
+void rde_filterstate_prep(struct filterstate *, struct prefix *);
+void rde_filterstate_copy(struct filterstate *, struct filterstate *);
void rde_filterstate_clean(struct filterstate *);
int rde_filter_equal(struct filter_head *, struct filter_head *,
struct rde_peer *);
-/* $OpenBSD: rde_filter.c,v 1.130 2023/01/11 17:10:26 claudio Exp $ */
+/* $OpenBSD: rde_filter.c,v 1.131 2023/01/12 17:35:51 claudio Exp $ */
/*
* Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
}
void
-rde_filterstate_prep(struct filterstate *state, struct rde_aspath *asp,
+rde_filterstate_init(struct filterstate *state)
+{
+ memset(state, 0, sizeof(*state));
+ path_prep(&state->aspath);
+}
+
+static void
+rde_filterstate_set(struct filterstate *state, struct rde_aspath *asp,
struct rde_community *communities, struct nexthop *nh, uint8_t nhflags,
uint8_t vstate)
{
- memset(state, 0, sizeof(*state));
+ rde_filterstate_init(state);
- path_prep(&state->aspath);
if (asp)
path_copy(&state->aspath, asp);
if (communities)
state->vstate = vstate;
}
+void
+rde_filterstate_prep(struct filterstate *state, struct prefix *p)
+{
+ rde_filterstate_set(state, prefix_aspath(p), prefix_communities(p),
+ prefix_nexthop(p), prefix_nhflags(p), prefix_roa_vstate(p));
+}
+
+void
+rde_filterstate_copy(struct filterstate *state, struct filterstate *src)
+{
+ rde_filterstate_set(state, &src->aspath, &src->communities,
+ src->nexthop, src->nhflags, src->vstate);
+}
+
void
rde_filterstate_clean(struct filterstate *state)
{
-/* $OpenBSD: rde_update.c,v 1.150 2023/01/11 17:10:26 claudio Exp $ */
+/* $OpenBSD: rde_update.c,v 1.151 2023/01/12 17:35:51 claudio Exp $ */
/*
* Copyright (c) 2004 Claudio Jeker <claudio@openbsd.org>
!(peer->flags & PEERFLAG_EVALUATE_ALL))
break;
- rde_filterstate_prep(&state, prefix_aspath(new),
- prefix_communities(new), prefix_nexthop(new),
- prefix_nhflags(new), prefix_roa_vstate(new));
+ rde_filterstate_prep(&state, new);
if (rde_filter(rules, peer, prefix_peer(new), &addr,
prefixlen, &state) == ACTION_DENY) {
rde_filterstate_clean(&state);
if (!up_test_update(peer, new))
continue;
- rde_filterstate_prep(&state, prefix_aspath(new),
- prefix_communities(new), prefix_nexthop(new),
- prefix_nhflags(new), prefix_roa_vstate(new));
+ rde_filterstate_prep(&state, new);
if (rde_filter(rules, peer, prefix_peer(new), &addr,
prefixlen, &state) == ACTION_DENY) {
rde_filterstate_clean(&state);
if (!up_test_update(peer, new))
continue;
- rde_filterstate_prep(&state, prefix_aspath(new),
- prefix_communities(new), prefix_nexthop(new),
- prefix_nhflags(new), prefix_roa_vstate(new));
+ rde_filterstate_prep(&state, new);
if (rde_filter(rules, peer, prefix_peer(new), &addr,
prefixlen, &state) == ACTION_DENY) {
rde_filterstate_clean(&state);
if (peer->capa.mp[aid] == 0)
return;
- rde_filterstate_prep(&state, NULL, NULL, NULL, 0, ROA_NOTFOUND);
+ rde_filterstate_init(&state);
asp = &state.aspath;
asp->aspath = aspath_get(NULL, 0);
asp->origin = ORIGIN_IGP;
if (p == NULL)
goto done;
- rde_filterstate_prep(&state, prefix_aspath(p), prefix_communities(p),
- prefix_nexthop(p), prefix_nhflags(p), prefix_roa_vstate(p));
+ rde_filterstate_prep(&state, p);
r = up_generate_attr(buf + 2, len - 2, peer, &state, AID_INET);
rde_filterstate_clean(&state);
wpos = 4; /* reserve space for length fields */
- rde_filterstate_prep(&state, prefix_aspath(p), prefix_communities(p),
- prefix_nexthop(p), prefix_nhflags(p), prefix_roa_vstate(p));
+ rde_filterstate_prep(&state, p);
/* write regular path attributes */
r = up_generate_attr(buf + wpos, len - wpos, peer, &state, aid);