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

Method parseNotify

Server/src/bgp/NotificationMsg.cpp:45–189  ·  view source on GitHub ↗

* Parses a notification message stored in a byte parsed_msg.error_textfer * * \details * Reads the notification message from buffer. The parsed data will be * returned via parsed_msg. * * \param [in] data Pointer to raw bgp payload data, starting at the notification message * \param [in] size Size of the data available to read; prevent overrun when reading

Source from the content-addressed store, hash-verified

43 * \return True if error, false if no error reading/parsing the notification message
44 */
45bool NotificationMsg::parseNotify(u_char *data, size_t size, parsed_notify_msg &parsed_msg) {
46 u_char *dataPtr = data;
47 size_t read_size = 0;
48
49 // Reset the storage buffer for parsed data
50 bzero(&parsed_msg, sizeof(parsed_msg));
51
52 if (read_size < size)
53 parsed_msg.error_code = *dataPtr++, size++;
54 else {
55 LOG_ERR("Could not read the BGP error code from notify message");
56 return true;
57 }
58
59 if (read_size < size)
60 parsed_msg.error_subcode = *dataPtr++,size++;
61 else {
62 LOG_ERR("Could not read the BGP sub code from notify message");
63 return true;
64 }
65
66 // Update the error text to be meaningful
67 switch (parsed_msg.error_code) {
68 case NOTIFY_MSG_HDR_ERR : {
69 if (parsed_msg.error_subcode == MSG_HDR_BAD_MSG_LEN)
70 snprintf(parsed_msg.error_text, sizeof(parsed_msg.error_text), "Bad message header length");
71 else
72 snprintf(parsed_msg.error_text, sizeof(parsed_msg.error_text), "Bad message header type");
73 break;
74 }
75
76 case NOTIFY_OPEN_MSG_ERR : {
77 switch (parsed_msg.error_subcode) {
78 case OPEN_BAD_BGP_ID :
79 snprintf(parsed_msg.error_text, sizeof(parsed_msg.error_text), "Bad BGP ID");
80 break;
81 case OPEN_BAD_PEER_AS :
82 snprintf(parsed_msg.error_text, sizeof(parsed_msg.error_text), "Incorrect peer AS");
83 break;
84 case OPEN_UNACCEPTABLE_HOLD_TIME :
85 snprintf(parsed_msg.error_text, sizeof(parsed_msg.error_text), "Unacceptable hold time");
86 break;
87 case OPEN_UNSUPPORTED_OPT_PARAM :
88 snprintf(parsed_msg.error_text, sizeof(parsed_msg.error_text), "Unsupported optional parameter");
89 break;
90 case OPEN_UNSUPPORTED_VER :
91 snprintf(parsed_msg.error_text, sizeof(parsed_msg.error_text), "Unsupported BGP version");
92 break;
93 default :
94 snprintf(parsed_msg.error_text, sizeof(parsed_msg.error_text), "Open message error - unknown subcode [%d]",
95 parsed_msg.error_subcode);
96 break;
97 }
98 break;
99 }
100
101 case NOTIFY_UPDATE_MSG_ERR : {
102 switch (parsed_msg.error_subcode) {

Callers 1

handleDownEventMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected