MCPcopy Create free account
hub / github.com/SNAS/openbmp / parseBgpHeader

Method parseBgpHeader

Server/src/bgp/parseBGP.cpp:288–340  ·  view source on GitHub ↗

* Parses the BGP common header * * \details * This method will parse the bgp common header and will upload the global * c_hdr structure, instance data pointer, and remaining bytes of message. * The return value of this method will be the BGP message type. * * \param [in] data Pointer to the raw BGP message header * \param [in] size length of t

Source from the content-addressed store, hash-verified

286 * \returns BGP message type
287 */
288u_char parseBGP::parseBgpHeader(u_char *data, size_t size) {
289 bzero(&common_hdr, sizeof(common_hdr));
290
291 /*
292 * Error out if data size is not large enough for common header
293 */
294 if (size < BGP_MSG_HDR_LEN) {
295 LOG_WARN("%s: rtr=%s: BGP message is being parsed is %d but expected at least %d in size",
296 p_entry->peer_addr, router_addr.c_str(), size, BGP_MSG_HDR_LEN);
297 return 0;
298 }
299
300 memcpy(&common_hdr, data, BGP_MSG_HDR_LEN);
301
302 // Change length to host byte order
303 bgp::SWAP_BYTES(&common_hdr.len);
304
305 // Update remaining bytes left of the message
306 data_bytes_remaining = common_hdr.len - BGP_MSG_HDR_LEN;
307
308 /*
309 * Error out if the remaining size of the BGP message is grater than passed bgp message buffer
310 * It is expected that the passed bgp message buffer holds the complete BGP message to be parsed
311 */
312 if (common_hdr.len > size) {
313 LOG_WARN("%s: rtr=%s: BGP message size of %hu is greater than passed data buffer, cannot parse the BGP message",
314 p_entry->peer_addr, router_addr.c_str(), common_hdr.len, size);
315 }
316
317 SELF_DEBUG("%s: rtr=%s: BGP hdr len = %u, type = %d", p_entry->peer_addr, router_addr.c_str(), common_hdr.len, common_hdr.type);
318
319 /*
320 * Validate the message type as being allowed/accepted
321 */
322 switch (common_hdr.type) {
323 case BGP_MSG_UPDATE : // Update Message
324 case BGP_MSG_NOTIFICATION : // Notification message
325 case BGP_MSG_OPEN : // OPEN message
326 // Message(s) are allowed - calling method will request further parsing of the bgp message type
327 break;
328
329 case BGP_MSG_ROUTE_REFRESH: // Route Refresh message
330 LOG_NOTICE("%s: rtr=%s: Received route refresh, nothing to do with this message currently.",
331 p_entry->peer_addr, router_addr.c_str());
332 break;
333
334 default :
335 SELF_DEBUG("%s: rtr=%s: Unsupported BGP message type = %d", p_entry->peer_addr, router_addr.c_str(), common_hdr.type);
336 break;
337 }
338
339 return common_hdr.type;
340}
341
342/**
343 * Update the Database with the parsed updated data

Callers

nothing calls this directly

Calls 1

SWAP_BYTESFunction · 0.85

Tested by

no test coverage detected