mirror of
https://github.com/openbsd/src.git
synced 2024-12-22 16:42:56 -08:00
Teach mrt_dump_bgp_msg() to use ibufs
OK tb@
This commit is contained in:
parent
c9c4d4e441
commit
eaff30a2cd
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: mrt.c,v 1.121 2024/11/21 13:29:52 claudio Exp $ */
|
||||
/* $OpenBSD: mrt.c,v 1.122 2024/11/21 13:34:01 claudio Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
|
||||
@ -56,33 +56,27 @@ static int mrt_open(struct mrt *, time_t);
|
||||
)
|
||||
|
||||
static uint8_t
|
||||
mrt_update_msg_guess_aid(uint8_t *pkg, uint16_t pkglen)
|
||||
mrt_update_msg_guess_aid(struct ibuf *pkg)
|
||||
{
|
||||
struct ibuf buf;
|
||||
uint16_t wlen, alen, len, afi;
|
||||
uint8_t type, aid;
|
||||
uint8_t type, flags, aid, safi;
|
||||
|
||||
pkg += MSGSIZE_HEADER;
|
||||
pkglen -= MSGSIZE_HEADER;
|
||||
ibuf_from_ibuf(&buf, pkg);
|
||||
|
||||
if (pkglen < 4)
|
||||
if (ibuf_skip(&buf, MSGSIZE_HEADER) == -1 ||
|
||||
ibuf_get_n16(&buf, &wlen) == -1)
|
||||
goto bad;
|
||||
|
||||
memcpy(&wlen, pkg, 2);
|
||||
wlen = ntohs(wlen);
|
||||
pkg += 2;
|
||||
pkglen -= 2;
|
||||
|
||||
if (wlen > 0) {
|
||||
/* UPDATE has withdraw routes, therefore IPv4 */
|
||||
return AID_INET;
|
||||
}
|
||||
|
||||
memcpy(&alen, pkg, 2);
|
||||
alen = ntohs(alen);
|
||||
pkg += 2;
|
||||
pkglen -= 2;
|
||||
if (ibuf_get_n16(&buf, &alen) == -1)
|
||||
goto bad;
|
||||
|
||||
if (alen < pkglen) {
|
||||
if (alen < ibuf_size(&buf)) {
|
||||
/* UPDATE has NLRI prefixes, therefore IPv4 */
|
||||
return AID_INET;
|
||||
}
|
||||
@ -93,42 +87,37 @@ mrt_update_msg_guess_aid(uint8_t *pkg, uint16_t pkglen)
|
||||
}
|
||||
|
||||
/* bad attribute length */
|
||||
if (alen > pkglen)
|
||||
if (alen > ibuf_size(&buf))
|
||||
goto bad;
|
||||
|
||||
/* try to extract AFI/SAFI from the MP attributes */
|
||||
while (alen > 0) {
|
||||
if (alen < 3)
|
||||
while (ibuf_size(&buf) > 0) {
|
||||
if (ibuf_get_n8(&buf, &flags) == -1 ||
|
||||
ibuf_get_n8(&buf, &type) == -1)
|
||||
goto bad;
|
||||
type = pkg[1];
|
||||
if (pkg[0] & ATTR_EXTLEN) {
|
||||
if (alen < 4)
|
||||
if (flags & ATTR_EXTLEN) {
|
||||
if (ibuf_get_n16(&buf, &len) == -1)
|
||||
goto bad;
|
||||
memcpy(&len, pkg + 2, 2);
|
||||
len = ntohs(len);
|
||||
pkg += 4;
|
||||
alen -= 4;
|
||||
} else {
|
||||
len = pkg[2];
|
||||
pkg += 3;
|
||||
alen -= 3;
|
||||
uint8_t tmp;
|
||||
if (ibuf_get_n8(&buf, &tmp) == -1)
|
||||
goto bad;
|
||||
len = tmp;
|
||||
}
|
||||
if (len > alen)
|
||||
if (len > ibuf_size(&buf))
|
||||
goto bad;
|
||||
|
||||
if (type == ATTR_MP_REACH_NLRI ||
|
||||
type == ATTR_MP_UNREACH_NLRI) {
|
||||
if (alen < 3)
|
||||
if (ibuf_get_n16(&buf, &afi) == -1 ||
|
||||
ibuf_get_n8(&buf, &safi) == -1)
|
||||
goto bad;
|
||||
memcpy(&afi, pkg, 2);
|
||||
afi = ntohs(afi);
|
||||
if (afi2aid(afi, pkg[2], &aid) == -1)
|
||||
if (afi2aid(afi, safi, &aid) == -1)
|
||||
goto bad;
|
||||
return aid;
|
||||
}
|
||||
|
||||
pkg += len;
|
||||
alen -= len;
|
||||
if (ibuf_skip(&buf, len) == -1)
|
||||
goto bad;
|
||||
}
|
||||
|
||||
bad:
|
||||
@ -136,8 +125,8 @@ bad:
|
||||
}
|
||||
|
||||
static uint16_t
|
||||
mrt_bgp_msg_subtype(struct mrt *mrt, void *pkg, uint16_t pkglen,
|
||||
struct peer *peer, enum msg_type msgtype, int in)
|
||||
mrt_bgp_msg_subtype(struct mrt *mrt, struct ibuf *pkg, struct peer *peer,
|
||||
enum msg_type msgtype, int in)
|
||||
{
|
||||
uint16_t subtype = BGP4MP_MESSAGE;
|
||||
uint8_t aid, mask;
|
||||
@ -158,7 +147,7 @@ mrt_bgp_msg_subtype(struct mrt *mrt, void *pkg, uint16_t pkglen,
|
||||
mask = in ? CAPA_AP_RECV : CAPA_AP_SEND;
|
||||
/* only guess if add-path could be active */
|
||||
if (peer->capa.neg.add_path[0] & mask) {
|
||||
aid = mrt_update_msg_guess_aid(pkg, pkglen);
|
||||
aid = mrt_update_msg_guess_aid(pkg);
|
||||
if (aid != AID_UNSPEC &&
|
||||
(peer->capa.neg.add_path[aid] & mask)) {
|
||||
if (peer->capa.neg.as4byte)
|
||||
@ -172,8 +161,8 @@ mrt_bgp_msg_subtype(struct mrt *mrt, void *pkg, uint16_t pkglen,
|
||||
}
|
||||
|
||||
void
|
||||
mrt_dump_bgp_msg(struct mrt *mrt, void *pkg, uint16_t pkglen,
|
||||
struct peer *peer, enum msg_type msgtype)
|
||||
mrt_dump_bgp_msg(struct mrt *mrt, struct ibuf *pkg, struct peer *peer,
|
||||
enum msg_type msgtype)
|
||||
{
|
||||
struct ibuf *buf;
|
||||
int in = 0;
|
||||
@ -183,13 +172,13 @@ mrt_dump_bgp_msg(struct mrt *mrt, void *pkg, uint16_t pkglen,
|
||||
if (mrt->type == MRT_ALL_IN || mrt->type == MRT_UPDATE_IN)
|
||||
in = 1;
|
||||
|
||||
subtype = mrt_bgp_msg_subtype(mrt, pkg, pkglen, peer, msgtype, in);
|
||||
subtype = mrt_bgp_msg_subtype(mrt, pkg, peer, msgtype, in);
|
||||
|
||||
if (mrt_dump_hdr_se(&buf, peer, MSG_PROTOCOL_BGP4MP_ET, subtype,
|
||||
pkglen, in) == -1)
|
||||
ibuf_size(pkg), in) == -1)
|
||||
goto fail;
|
||||
|
||||
if (ibuf_add(buf, pkg, pkglen) == -1)
|
||||
if (ibuf_add_ibuf(buf, pkg) == -1)
|
||||
goto fail;
|
||||
|
||||
ibuf_close(mrt->wbuf, buf);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: session.c,v 1.495 2024/11/21 13:33:41 claudio Exp $ */
|
||||
/* $OpenBSD: session.c,v 1.496 2024/11/21 13:34:01 claudio Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org>
|
||||
@ -1418,8 +1418,7 @@ session_sendmsg(struct ibuf *msg, struct peer *p, enum msg_type msgtype)
|
||||
if ((mrt->peer_id == 0 && mrt->group_id == 0) ||
|
||||
mrt->peer_id == p->conf.id || (mrt->group_id != 0 &&
|
||||
mrt->group_id == p->conf.groupid))
|
||||
mrt_dump_bgp_msg(mrt, ibuf_data(msg), ibuf_size(msg),
|
||||
p, msgtype);
|
||||
mrt_dump_bgp_msg(mrt, msg, p, msgtype);
|
||||
}
|
||||
|
||||
ibuf_close(p->wbuf, msg);
|
||||
@ -1988,8 +1987,7 @@ session_process_msg(struct peer *p)
|
||||
if ((mrt->peer_id == 0 && mrt->group_id == 0) ||
|
||||
mrt->peer_id == p->conf.id || (mrt->group_id != 0 &&
|
||||
mrt->group_id == p->conf.groupid))
|
||||
mrt_dump_bgp_msg(mrt, ibuf_data(msg),
|
||||
ibuf_size(msg), p, msgtype);
|
||||
mrt_dump_bgp_msg(mrt, msg, p, msgtype);
|
||||
}
|
||||
|
||||
ibuf_skip(msg, MSGSIZE_HEADER);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: session.h,v 1.178 2024/11/21 13:33:41 claudio Exp $ */
|
||||
/* $OpenBSD: session.h,v 1.179 2024/11/21 13:34:01 claudio Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
|
||||
@ -272,8 +272,8 @@ void log_conn_attempt(const struct peer *, struct sockaddr *,
|
||||
socklen_t);
|
||||
|
||||
/* mrt.c */
|
||||
void mrt_dump_bgp_msg(struct mrt *, void *, uint16_t,
|
||||
struct peer *, enum msg_type);
|
||||
void mrt_dump_bgp_msg(struct mrt *, struct ibuf *, struct peer *,
|
||||
enum msg_type);
|
||||
void mrt_dump_state(struct mrt *, uint16_t, uint16_t,
|
||||
struct peer *);
|
||||
void mrt_done(struct mrt *);
|
||||
|
Loading…
Reference in New Issue
Block a user