summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2017-09-20 11:11:30 -0400
committerQuentin Young <qlyoung@cumulusnetworks.com>2017-11-30 16:18:05 -0500
commit3fe63c291dbec89ada8f02afea89d00d75d8a62a (patch)
tree08a385d011a521ef634f6cb0b4390b5225798a30
parentca7f0cc7acd3ca51c216699c605cf4176e965a0a (diff)
bgpd: use correct byte order for notify data
Broke this when rewriting header validation. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
-rw-r--r--bgpd/bgp_io.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/bgpd/bgp_io.c b/bgpd/bgp_io.c
index fc8a474ba2..c3bc0a195d 100644
--- a/bgpd/bgp_io.c
+++ b/bgpd/bgp_io.c
@@ -529,7 +529,8 @@ static uint16_t bgp_read(struct peer *peer)
*/
static bool validate_header(struct peer *peer)
{
- uint16_t size, type;
+ uint16_t size;
+ uint8_t type;
struct stream *pkt = peer->ibuf_work;
size_t getp = stream_get_getp(pkt);
@@ -543,7 +544,7 @@ static bool validate_header(struct peer *peer)
return false;
}
- /* Get size and type. */
+ /* Get size and type in host byte order. */
size = stream_getw_from(pkt, getp + BGP_MARKER_SIZE);
type = stream_getc_from(pkt, getp + BGP_MARKER_SIZE + 2);
@@ -553,19 +554,17 @@ static bool validate_header(struct peer *peer)
&& type != BGP_MSG_ROUTE_REFRESH_NEW
&& type != BGP_MSG_ROUTE_REFRESH_OLD
&& type != BGP_MSG_CAPABILITY) {
- if (bgp_debug_neighbor_events(peer)) {
- // XXX: zlog is not MT-safe
+ if (bgp_debug_neighbor_events(peer))
zlog_debug("%s unknown message type 0x%02x", peer->host,
type);
- }
bgp_notify_send_with_data(peer, BGP_NOTIFY_HEADER_ERR,
BGP_NOTIFY_HEADER_BAD_MESTYPE,
- (u_char *) &type, 1);
+ &type, 1);
return false;
}
- /* Mimimum packet length check. */
+ /* Minimum packet length check. */
if ((size < BGP_HEADER_SIZE) || (size > BGP_MAX_PACKET_SIZE)
|| (type == BGP_MSG_OPEN && size < BGP_MSG_OPEN_MIN_SIZE)
|| (type == BGP_MSG_UPDATE && size < BGP_MSG_UPDATE_MIN_SIZE)
@@ -584,9 +583,11 @@ static bool validate_header(struct peer *peer)
: bgp_type_str[(int) type]);
}
+ uint16_t nsize = htons(size);
+
bgp_notify_send_with_data(peer, BGP_NOTIFY_HEADER_ERR,
BGP_NOTIFY_HEADER_BAD_MESLEN,
- (u_char *) &size, 2);
+ (unsigned char *) &nsize, 2);
return false;
}