diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2004-10-07 13:39:15 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2004-10-07 13:39:15 +0000 |
commit | b1e9ac644a1d5938de923d4578c7cc83502ac532 (patch) | |
tree | a40b53ca79b923176231373d08607b16ecf4c51b /usr.sbin/bgpd | |
parent | 251ebf50a51d57dd7436a3921a5b8e6cd1f69603 (diff) |
use a static, const and prefilled u_int8_t[16] to check wether the marker
at the beginning of each BGP message is all 1s instead of looping and
comparing one by one
Diffstat (limited to 'usr.sbin/bgpd')
-rw-r--r-- | usr.sbin/bgpd/session.c | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c index d0f2184e976..37ff59a7764 100644 --- a/usr.sbin/bgpd/session.c +++ b/usr.sbin/bgpd/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.194 2004/10/05 11:47:41 henning Exp $ */ +/* $OpenBSD: session.c,v 1.195 2004/10/07 13:39:14 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -1527,22 +1527,21 @@ parse_header(struct peer *peer, u_char *data, u_int16_t *len, u_int8_t *type) { struct mrt *mrt; u_char *p; - u_char one = 0xff; - int i; u_int16_t olen; + static const u_int8_t marker[MSGSIZE_HEADER_MARKER] = { 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; /* caller MUST make sure we are getting 19 bytes! */ p = data; - for (i = 0; i < 16; i++) { - if (memcmp(p, &one, 1)) { - log_peer_warnx(&peer->conf, "sync error"); - session_notification(peer, ERR_HEADER, ERR_HDR_SYNC, - NULL, 0); - bgp_fsm(peer, EVNT_CON_FATAL); - return (-1); - } - p++; + if (memcmp(p, marker, sizeof(marker))) { + log_peer_warnx(&peer->conf, "sync error"); + session_notification(peer, ERR_HEADER, ERR_HDR_SYNC, NULL, 0); + bgp_fsm(peer, EVNT_CON_FATAL); + return (-1); } + p += MSGSIZE_HEADER_MARKER; + memcpy(&olen, p, 2); *len = ntohs(olen); p += 2; |