-/* $OpenBSD: rde.c,v 1.387 2018/07/10 08:00:09 benno Exp $ */
+/* $OpenBSD: rde.c,v 1.388 2018/07/10 09:12:52 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
int
rde_update_dispatch(struct imsg *imsg)
{
+ struct rde_aspath asp;
struct bgpd_addr prefix;
struct mpattr mpa;
struct rde_peer *peer;
- struct rde_aspath *asp = NULL;
u_char *p, *mpp = NULL;
int error = -1, pos = 0;
u_int16_t afi, len, mplen;
imsg->hdr.len - IMSG_HEADER_SIZE - 4 - withdrawn_len - attrpath_len;
bzero(&mpa, sizeof(mpa));
+ path_prep(&asp);
if (attrpath_len != 0) { /* 0 = no NLRI information in this message */
/* parse path attributes */
- asp = path_get();
while (len > 0) {
- if ((pos = rde_attr_parse(p, len, peer, asp,
+ if ((pos = rde_attr_parse(p, len, peer, &asp,
&mpa)) < 0)
goto done;
p += pos;
}
/* check for missing but necessary attributes */
- if ((subtype = rde_attr_missing(asp, peer->conf.ebgp,
+ if ((subtype = rde_attr_missing(&asp, peer->conf.ebgp,
nlri_len))) {
rde_update_err(peer, ERR_UPDATE, ERR_UPD_MISSNG_WK_ATTR,
&subtype, sizeof(u_int8_t));
goto done;
}
- rde_as4byte_fixup(peer, asp);
+ rde_as4byte_fixup(peer, &asp);
/* enforce remote AS if requested */
- if (asp->flags & F_ATTR_ASPATH &&
+ if (asp.flags & F_ATTR_ASPATH &&
peer->conf.enforce_as == ENFORCE_AS_ON) {
- fas = aspath_neighbor(asp->aspath);
+ fas = aspath_neighbor(asp.aspath);
if (peer->conf.remote_as != fas) {
log_peer_warnx(&peer->conf, "bad path, "
"starting with %s, "
}
}
- rde_reflector(peer, asp);
+ rde_reflector(peer, &asp);
}
p = imsg->data;
goto done;
}
- if ((asp->flags & ~F_ATTR_MP_UNREACH) == 0 && mplen == 0) {
+ if ((asp.flags & ~F_ATTR_MP_UNREACH) == 0 && mplen == 0) {
/* EoR marker */
peer_recv_eor(peer, aid);
}
break;
}
- if ((asp->flags & ~F_ATTR_MP_UNREACH) == 0) {
+ if ((asp.flags & ~F_ATTR_MP_UNREACH) == 0) {
error = 0;
goto done;
}
/* aspath needs to be loop free nota bene this is not a hard error */
if (peer->conf.ebgp &&
peer->conf.enforce_local_as == ENFORCE_AS_ON &&
- !aspath_loopfree(asp->aspath, peer->conf.local_as))
- asp->flags |= F_ATTR_LOOP;
+ !aspath_loopfree(asp.aspath, peer->conf.local_as))
+ asp.flags |= F_ATTR_LOOP;
/* parse nlri prefix */
while (nlri_len > 0) {
goto done;
}
- if (rde_update_update(peer, asp, &prefix, prefixlen) == -1)
+ if (rde_update_update(peer, &asp, &prefix, prefixlen) == -1)
goto done;
}
* this works because asp is not linked.
* But first unlock the previously locked nexthop.
*/
- if (asp->nexthop) {
- (void)nexthop_put(asp->nexthop);
- asp->nexthop = NULL;
+ if (asp.nexthop) {
+ (void)nexthop_put(asp.nexthop);
+ asp.nexthop = NULL;
}
- if ((pos = rde_get_mp_nexthop(mpp, mplen, aid, asp)) == -1) {
+ if ((pos = rde_get_mp_nexthop(mpp, mplen, aid, &asp)) == -1) {
log_peer_warnx(&peer->conf, "bad nlri prefix");
rde_update_err(peer, ERR_UPDATE, ERR_UPD_OPTATTR,
mpa.reach, mpa.reach_len);
mpp += pos;
mplen -= pos;
- if (rde_update_update(peer, asp, &prefix,
+ if (rde_update_update(peer, &asp, &prefix,
prefixlen) == -1)
goto done;
}
mpp += pos;
mplen -= pos;
- if (rde_update_update(peer, asp, &prefix,
+ if (rde_update_update(peer, &asp, &prefix,
prefixlen) == -1)
goto done;
}
}
done:
- if (attrpath_len != 0) {
- /* free allocated attribute memory that is no longer used */
- path_put(asp);
- }
+ path_clean(&asp);
return (error);
}