-/* $OpenBSD: rde.c,v 1.531 2021/07/27 07:50:01 claudio Exp $ */
+/* $OpenBSD: rde.c,v 1.532 2021/08/09 08:15:34 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
void rde_dispatch_imsg_rtr(struct imsgbuf *);
void rde_dispatch_imsg_peer(struct rde_peer *, void *);
void rde_update_dispatch(struct rde_peer *, struct imsg *);
-int rde_update_update(struct rde_peer *, struct filterstate *,
+int rde_update_update(struct rde_peer *, u_int32_t,
+ struct filterstate *, struct bgpd_addr *, u_int8_t);
+void rde_update_withdraw(struct rde_peer *, u_int32_t,
struct bgpd_addr *, u_int8_t);
-void rde_update_withdraw(struct rde_peer *, struct bgpd_addr *,
- u_int8_t);
int rde_attr_parse(u_char *, u_int16_t, struct rde_peer *,
struct filterstate *, struct mpattr *);
int rde_attr_add(struct filterstate *, u_char *, u_int16_t);
u_int16_t attrpath_len;
u_int16_t nlri_len;
u_int8_t aid, prefixlen, safi, subtype;
- u_int32_t fas;
+ u_int32_t fas, pathid;
p = imsg->data;
goto done;
}
+ if (peer_has_add_path(peer, AID_INET, CAPA_AP_RECV)) {
+ if (len <= sizeof(pathid)) {
+ log_peer_warnx(&peer->conf,
+ "bad withdraw prefix");
+ rde_update_err(peer, ERR_UPDATE,
+ ERR_UPD_NETWORK, NULL, 0);
+ goto done;
+ }
+ memcpy(&pathid, p, sizeof(pathid));
+ pathid = ntohl(pathid);
+ p += sizeof(pathid);
+ len -= sizeof(pathid);
+ } else
+ pathid = 0;
+
if ((pos = nlri_get_prefix(p, len, &prefix,
&prefixlen)) == -1) {
/*
p += pos;
len -= pos;
- rde_update_withdraw(peer, &prefix, prefixlen);
+ rde_update_withdraw(peer, pathid, &prefix, prefixlen);
}
/* withdraw MP_UNREACH_NLRI if available */
}
while (mplen > 0) {
+ if (peer_has_add_path(peer, aid, CAPA_AP_RECV)) {
+ if (mplen <= sizeof(pathid)) {
+ log_peer_warnx(&peer->conf,
+ "bad %s withdraw prefix",
+ aid2str(aid));
+ rde_update_err(peer, ERR_UPDATE,
+ ERR_UPD_OPTATTR,
+ mpa.unreach, mpa.unreach_len);
+ goto done;
+ }
+ memcpy(&pathid, mpp, sizeof(pathid));
+ pathid = ntohl(pathid);
+ mpp += sizeof(pathid);
+ mplen -= sizeof(pathid);
+ } else
+ pathid = 0;
+
switch (aid) {
case AID_INET6:
if ((pos = nlri_get_prefix6(mpp, mplen,
mpp += pos;
mplen -= pos;
- rde_update_withdraw(peer, &prefix, prefixlen);
+ rde_update_withdraw(peer, pathid, &prefix, prefixlen);
}
if ((state.aspath.flags & ~F_ATTR_MP_UNREACH) == 0)
goto done;
}
+ if (peer_has_add_path(peer, AID_INET, CAPA_AP_RECV)) {
+ if (nlri_len <= sizeof(pathid)) {
+ log_peer_warnx(&peer->conf,
+ "bad nlri prefix");
+ rde_update_err(peer, ERR_UPDATE,
+ ERR_UPD_NETWORK, NULL, 0);
+ goto done;
+ }
+ memcpy(&pathid, p, sizeof(pathid));
+ pathid = ntohl(pathid);
+ p += sizeof(pathid);
+ nlri_len -= sizeof(pathid);
+ } else
+ pathid = 0;
+
if ((pos = nlri_get_prefix(p, nlri_len, &prefix,
&prefixlen)) == -1) {
log_peer_warnx(&peer->conf, "bad nlri prefix");
p += pos;
nlri_len -= pos;
- if (rde_update_update(peer, &state, &prefix, prefixlen) == -1)
+ if (rde_update_update(peer, pathid, &state,
+ &prefix, prefixlen) == -1)
goto done;
}
mplen -= pos;
while (mplen > 0) {
+ if (peer_has_add_path(peer, aid, CAPA_AP_RECV)) {
+ if (mplen <= sizeof(pathid)) {
+ log_peer_warnx(&peer->conf,
+ "bad %s nlri prefix", aid2str(aid));
+ rde_update_err(peer, ERR_UPDATE,
+ ERR_UPD_OPTATTR,
+ mpa.reach, mpa.reach_len);
+ goto done;
+ }
+ memcpy(&pathid, mpp, sizeof(pathid));
+ pathid = ntohl(pathid);
+ mpp += sizeof(pathid);
+ mplen -= sizeof(pathid);
+ } else
+ pathid = 0;
+
switch (aid) {
case AID_INET6:
if ((pos = nlri_get_prefix6(mpp, mplen,
mpp += pos;
mplen -= pos;
- if (rde_update_update(peer, &state,
+ if (rde_update_update(peer, pathid, &state,
&prefix, prefixlen) == -1)
goto done;
}
}
int
-rde_update_update(struct rde_peer *peer, struct filterstate *in,
- struct bgpd_addr *prefix, u_int8_t prefixlen)
+rde_update_update(struct rde_peer *peer, u_int32_t path_id,
+ struct filterstate *in, struct bgpd_addr *prefix, u_int8_t prefixlen)
{
struct filterstate state;
enum filter_actions action;
aspath_origin(in->aspath.aspath));
/* add original path to the Adj-RIB-In */
- if (prefix_update(rib_byid(RIB_ADJ_IN), peer, in, prefix, prefixlen,
- vstate) == 1)
+ if (prefix_update(rib_byid(RIB_ADJ_IN), peer, path_id, in,
+ prefix, prefixlen, vstate) == 1)
peer->prefix_cnt++;
/* max prefix checker */
rde_update_log("update", i, peer,
&state.nexthop->exit_nexthop, prefix,
prefixlen);
- prefix_update(rib, peer, &state, prefix,
+ prefix_update(rib, peer, path_id, &state, prefix,
prefixlen, vstate);
- } else if (prefix_withdraw(rib, peer, prefix,
+ } else if (prefix_withdraw(rib, peer, path_id, prefix,
prefixlen)) {
rde_update_log(wmsg, i, peer,
NULL, prefix, prefixlen);
}
void
-rde_update_withdraw(struct rde_peer *peer, struct bgpd_addr *prefix,
- u_int8_t prefixlen)
+rde_update_withdraw(struct rde_peer *peer, u_int32_t path_id,
+ struct bgpd_addr *prefix, u_int8_t prefixlen)
{
u_int16_t i;
struct rib *rib = rib_byid(i);
if (rib == NULL)
continue;
- if (prefix_withdraw(rib, peer, prefix, prefixlen))
+ if (prefix_withdraw(rib, peer, path_id, prefix, prefixlen))
rde_update_log("withdraw", i, peer, NULL, prefix,
prefixlen);
}
/* remove original path form the Adj-RIB-In */
- if (prefix_withdraw(rib_byid(RIB_ADJ_IN), peer, prefix, prefixlen))
+ if (prefix_withdraw(rib_byid(RIB_ADJ_IN), peer, path_id,
+ prefix, prefixlen))
peer->prefix_cnt--;
peer->prefix_rcvd_withdraw++;
* control specific functions
*/
static void
-rde_dump_rib_as(struct prefix *p, struct rde_aspath *asp, pid_t pid, int flags)
+rde_dump_rib_as(struct prefix *p, struct rde_aspath *asp, pid_t pid, int flags,
+ int adjout)
{
struct ctl_show_rib rib;
struct ibuf *wbuf;
struct attr *a;
struct nexthop *nexthop;
struct rib_entry *re;
+ struct rde_peer *peer;
void *bp;
time_t staletime;
size_t aslen;
u_int8_t l;
nexthop = prefix_nexthop(p);
+ peer = prefix_peer(p);
bzero(&rib, sizeof(rib));
rib.age = getmonotime() - p->lastchange;
rib.local_pref = asp->lpref;
rib.med = asp->med;
rib.weight = asp->weight;
- strlcpy(rib.descr, prefix_peer(p)->conf.descr, sizeof(rib.descr));
- memcpy(&rib.remote_addr, &prefix_peer(p)->remote_addr,
+ strlcpy(rib.descr, peer->conf.descr, sizeof(rib.descr));
+ memcpy(&rib.remote_addr, &peer->remote_addr,
sizeof(rib.remote_addr));
- rib.remote_id = prefix_peer(p)->remote_bgpid;
+ rib.remote_id = peer->remote_bgpid;
if (nexthop != NULL) {
memcpy(&rib.true_nexthop, &nexthop->true_nexthop,
sizeof(rib.true_nexthop));
re = prefix_re(p);
if (re != NULL && re->active == p)
rib.flags |= F_PREF_ACTIVE;
- if (!prefix_peer(p)->conf.ebgp)
+ if (!peer->conf.ebgp)
rib.flags |= F_PREF_INTERNAL;
if (asp->flags & F_PREFIX_ANNOUNCED)
rib.flags |= F_PREF_ANNOUNCE;
rib.flags &= ~F_PREF_ELIGIBLE;
if (asp->flags & F_ATTR_PARSE_ERR)
rib.flags |= F_PREF_INVALID;
- staletime = prefix_peer(p)->staletime[p->pt->aid];
+ staletime = peer->staletime[p->pt->aid];
if (staletime && p->lastchange <= staletime)
rib.flags |= F_PREF_STALE;
+ if (!adjout) {
+ if (peer_has_add_path(peer, p->pt->aid, CAPA_AP_RECV)) {
+ rib.path_id = p->path_id;
+ rib.flags |= F_PREF_PATH_ID;
+ }
+ } else {
+ if (peer_has_add_path(peer, p->pt->aid, CAPA_AP_SEND)) {
+ rib.path_id = 0; /* XXX add-path send */
+ rib.flags |= F_PREF_PATH_ID;
+ }
+ }
aslen = aspath_length(asp->aspath);
if ((wbuf = imsg_create(ibuf_se_ctl, IMSG_CTL_SHOW_RIB, 0, pid,
}
static void
-rde_dump_filter(struct prefix *p, struct ctl_show_rib_request *req)
+rde_dump_filter(struct prefix *p, struct ctl_show_rib_request *req, int adjout)
{
struct rde_aspath *asp;
struct rib_entry *re;
if ((req->flags & F_CTL_INVALID) &&
(asp->flags & F_ATTR_PARSE_ERR) == 0)
return;
+ /*
+ * XXX handle out specially since then we want to match against our
+ * path ids.
+ */
+ if ((req->flags & F_CTL_HAS_PATHID) && req->path_id != p->path_id)
+ return;
if (req->as.type != AS_UNDEF &&
!aspath_match(asp->aspath, &req->as, 0))
return;
}
if (!ovs_match(p, req->flags))
return;
- rde_dump_rib_as(p, asp, req->pid, req->flags);
+ rde_dump_rib_as(p, asp, req->pid, req->flags, adjout);
}
static void
struct prefix *p;
LIST_FOREACH(p, &re->prefix_h, entry.list.rib)
- rde_dump_filter(p, &ctx->req);
+ rde_dump_filter(p, &ctx->req, 0);
}
static void
if (!prefix_compare(&ctx->req.prefix, &addr,
ctx->req.prefixlen))
LIST_FOREACH(p, &re->prefix_h, entry.list.rib)
- rde_dump_filter(p, &ctx->req);
+ rde_dump_filter(p, &ctx->req, 0);
} else {
if (ctx->req.prefixlen < pt->prefixlen)
return;
if (!prefix_compare(&addr, &ctx->req.prefix,
pt->prefixlen))
LIST_FOREACH(p, &re->prefix_h, entry.list.rib)
- rde_dump_filter(p, &ctx->req);
+ rde_dump_filter(p, &ctx->req, 0);
}
}
if (p->flags & (PREFIX_FLAG_WITHDRAW | PREFIX_FLAG_DEAD))
return;
- rde_dump_filter(p, &ctx->req);
+ rde_dump_filter(p, &ctx->req, 1);
}
static void
return;
if (!prefix_compare(&ctx->req.prefix, &addr,
ctx->req.prefixlen))
- rde_dump_filter(p, &ctx->req);
+ rde_dump_filter(p, &ctx->req, 1);
} else {
if (ctx->req.prefixlen < p->pt->prefixlen)
return;
if (!prefix_compare(&addr, &ctx->req.prefix,
p->pt->prefixlen))
- rde_dump_filter(p, &ctx->req);
+ rde_dump_filter(p, &ctx->req, 1);
}
}
if (action == ACTION_ALLOW) {
/* update Local-RIB */
- prefix_update(rib, peer, &state, &prefix,
- pt->prefixlen, p->validation_state);
+ prefix_update(rib, peer, p->path_id, &state,
+ &prefix, pt->prefixlen,
+ p->validation_state);
} else if (action == ACTION_DENY) {
/* remove from Local-RIB */
- prefix_withdraw(rib, peer, &prefix,
+ prefix_withdraw(rib, peer, p->path_id, &prefix,
pt->prefixlen);
}
if (action == ACTION_ALLOW) {
/* update Local-RIB */
- prefix_update(rib, peer, &state, &prefix,
- pt->prefixlen, p->validation_state);
+ prefix_update(rib, peer, p->path_id, &state,
+ &prefix, pt->prefixlen,
+ p->validation_state);
} else if (action == ACTION_DENY) {
/* remove from Local-RIB */
- prefix_withdraw(rib, peer, &prefix,
+ prefix_withdraw(rib, peer, p->path_id, &prefix,
pt->prefixlen);
}
vstate = rde_roa_validity(&rde_roa, &nc->prefix,
nc->prefixlen, aspath_origin(state->aspath.aspath));
- if (prefix_update(rib_byid(RIB_ADJ_IN), peerself, state, &nc->prefix,
+ if (prefix_update(rib_byid(RIB_ADJ_IN), peerself, 0, state, &nc->prefix,
nc->prefixlen, vstate) == 1)
peerself->prefix_cnt++;
for (i = RIB_LOC_START; i < rib_size; i++) {
rde_update_log("announce", i, peerself,
state->nexthop ? &state->nexthop->exit_nexthop : NULL,
&nc->prefix, nc->prefixlen);
- prefix_update(rib, peerself, state, &nc->prefix,
+ prefix_update(rib, peerself, 0, state, &nc->prefix,
nc->prefixlen, vstate);
}
filterset_free(&nc->attrset);
struct rib *rib = rib_byid(i);
if (rib == NULL)
continue;
- if (prefix_withdraw(rib, peerself, &nc->prefix,
+ if (prefix_withdraw(rib, peerself, 0, &nc->prefix,
nc->prefixlen))
rde_update_log("withdraw announce", i, peerself,
NULL, &nc->prefix, nc->prefixlen);
}
- if (prefix_withdraw(rib_byid(RIB_ADJ_IN), peerself, &nc->prefix,
+ if (prefix_withdraw(rib_byid(RIB_ADJ_IN), peerself, 0, &nc->prefix,
nc->prefixlen))
peerself->prefix_cnt--;
}
u_int32_t i;
u_int8_t prefixlen;
- p = prefix_bypeer(re, peerself);
+ p = prefix_bypeer(re, peerself, 0);
if (p == NULL)
return;
if ((prefix_aspath(p)->flags & F_ANN_DYNAMIC) != F_ANN_DYNAMIC)
struct rib *rib = rib_byid(i);
if (rib == NULL)
continue;
- if (prefix_withdraw(rib, peerself, &addr, prefixlen) == 1)
+ if (prefix_withdraw(rib, peerself, 0, &addr, prefixlen) == 1)
rde_update_log("flush announce", i, peerself,
NULL, &addr, prefixlen);
}
- if (prefix_withdraw(rib_byid(RIB_ADJ_IN), peerself, &addr,
+ if (prefix_withdraw(rib_byid(RIB_ADJ_IN), peerself, 0, &addr,
prefixlen) == 1)
peerself->prefix_cnt--;
}
-/* $OpenBSD: rde_rib.c,v 1.223 2021/07/27 07:50:02 claudio Exp $ */
+/* $OpenBSD: rde_rib.c,v 1.224 2021/08/09 08:15:35 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
/* prefix specific functions */
static int prefix_add(struct bgpd_addr *, int, struct rib *,
- struct rde_peer *, struct rde_aspath *,
+ struct rde_peer *, u_int32_t, struct rde_aspath *,
struct rde_community *, struct nexthop *,
u_int8_t, u_int8_t);
static int prefix_move(struct prefix *, struct rde_peer *,
struct nexthop *, u_int8_t, u_int8_t);
static void prefix_link(struct prefix *, struct rib_entry *,
- struct rde_peer *, struct rde_aspath *,
+ struct rde_peer *, u_int32_t, struct rde_aspath *,
struct rde_community *, struct nexthop *,
u_int8_t, u_int8_t);
static void prefix_unlink(struct prefix *);
return (a->nexthop > b->nexthop ? 1 : -1);
if (a->nhflags != b->nhflags)
return (a->nhflags > b->nhflags ? 1 : -1);
+ /* XXX path_id ??? */
return pt_prefix_cmp(a->pt, b->pt);
}
static inline int
prefix_index_cmp(struct prefix *a, struct prefix *b)
{
+ /* XXX path_id ??? */
return pt_prefix_cmp(a->pt, b->pt);
}
* search for specified prefix of a peer. Returns NULL if not found.
*/
struct prefix *
-prefix_get(struct rib *rib, struct rde_peer *peer, struct bgpd_addr *prefix,
- int prefixlen)
+prefix_get(struct rib *rib, struct rde_peer *peer, u_int32_t path_id,
+ struct bgpd_addr *prefix, int prefixlen)
{
struct rib_entry *re;
re = rib_get(rib, prefix, prefixlen);
if (re == NULL)
return (NULL);
- return (prefix_bypeer(re, peer));
+ return (prefix_bypeer(re, peer, path_id));
}
/*
* Return 1 if prefix was newly added, 0 if it was just changed.
*/
int
-prefix_update(struct rib *rib, struct rde_peer *peer, struct filterstate *state,
- struct bgpd_addr *prefix, int prefixlen, u_int8_t vstate)
+prefix_update(struct rib *rib, struct rde_peer *peer, u_int32_t path_id,
+ struct filterstate *state, struct bgpd_addr *prefix, int prefixlen,
+ u_int8_t vstate)
{
struct rde_aspath *asp, *nasp = &state->aspath;
struct rde_community *comm, *ncomm = &state->communities;
/*
* First try to find a prefix in the specified RIB.
*/
- if ((p = prefix_get(rib, peer, prefix, prefixlen)) != NULL) {
+ if ((p = prefix_get(rib, peer, path_id, prefix, prefixlen)) != NULL) {
if (prefix_nexthop(p) == state->nexthop &&
prefix_nhflags(p) == state->nhflags &&
communities_equal(ncomm, prefix_communities(p)) &&
return (prefix_move(p, peer, asp, comm, state->nexthop,
state->nhflags, vstate));
else
- return (prefix_add(prefix, prefixlen, rib, peer, asp, comm,
- state->nexthop, state->nhflags, vstate));
+ return (prefix_add(prefix, prefixlen, rib, peer, path_id, asp,
+ comm, state->nexthop, state->nhflags, vstate));
}
/*
*/
static int
prefix_add(struct bgpd_addr *prefix, int prefixlen, struct rib *rib,
- struct rde_peer *peer, struct rde_aspath *asp, struct rde_community *comm,
- struct nexthop *nexthop, u_int8_t nhflags, u_int8_t vstate)
+ struct rde_peer *peer, u_int32_t path_id, struct rde_aspath *asp,
+ struct rde_community *comm, struct nexthop *nexthop, u_int8_t nhflags,
+ u_int8_t vstate)
{
struct prefix *p;
struct rib_entry *re;
re = rib_add(rib, prefix, prefixlen);
p = prefix_alloc();
- prefix_link(p, re, peer, asp, comm, nexthop, nhflags, vstate);
+ prefix_link(p, re, peer, path_id, asp, comm, nexthop, nhflags, vstate);
return (1);
}
np->peer = peer;
np->entry.list.re = prefix_re(p);
np->pt = p->pt; /* skip refcnt update since ref is moved */
+ np->path_id = p->path_id;
np->validation_state = vstate;
np->nhflags = nhflags;
np->nexthop = nexthop_ref(nexthop);
* or pt_entry -- become empty remove them too.
*/
int
-prefix_withdraw(struct rib *rib, struct rde_peer *peer,
+prefix_withdraw(struct rib *rib, struct rde_peer *peer, u_int32_t path_id,
struct bgpd_addr *prefix, int prefixlen)
{
struct prefix *p;
struct rde_aspath *asp;
- p = prefix_get(rib, peer, prefix, prefixlen);
+ p = prefix_get(rib, peer, path_id, prefix, prefixlen);
if (p == NULL) /* Got a dummy withdrawn request. */
return (0);
* belonging to the peer peer. Returns NULL if no match found.
*/
struct prefix *
-prefix_bypeer(struct rib_entry *re, struct rde_peer *peer)
+prefix_bypeer(struct rib_entry *re, struct rde_peer *peer, u_int32_t path_id)
{
struct prefix *p;
LIST_FOREACH(p, &re->prefix_h, entry.list.rib)
- if (prefix_peer(p) == peer)
+ if (prefix_peer(p) == peer && p->path_id == path_id)
return (p);
return (NULL);
}
*/
static void
prefix_link(struct prefix *p, struct rib_entry *re, struct rde_peer *peer,
- struct rde_aspath *asp, struct rde_community *comm,
+ u_int32_t path_id, struct rde_aspath *asp, struct rde_community *comm,
struct nexthop *nexthop, u_int8_t nhflags, u_int8_t vstate)
{
if (p->flags & PREFIX_FLAG_ADJOUT)
p->communities = communities_ref(comm);
p->peer = peer;
p->pt = pt_ref(re->prefix);
+ p->path_id = path_id;
p->validation_state = vstate;
p->nhflags = nhflags;
p->nexthop = nexthop_ref(nexthop);