Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenBMP support #73

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

OpenBMP support #73

wants to merge 6 commits into from

Conversation

luminshi
Copy link

Hello,

I added OpenBMP parsing feature to libparsebgp, and it parses messages from raw_bmp topic.
The parsing procedures are copied from libbgpstream.

@luminshi
Copy link
Author

Forgot to exclude the .clang-format file in my commits, please ignore the file.

Copy link
Member

@alistairking alistairking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall the structure looks great.

i've left a few comments about some problems that are repeated elsewhere, but you should be able to generalize and fix other occurrences.

if (memcmp(buf, "OBMP", 4) != 0) {
// it's not a known OpenBMP header, assume that it is raw BMP
*buf_len = 0;
printf("it's not a known OpenBMP header, assume that it is raw BMP\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think you just want a printf here.
this code was originally supposed to allow the caller to handle either openbmp-formatted data or raw BMP.
i'm not sure how to support that use case in the libparsebgp model. we could just try parsing the BMP content at this stage, but then we'd need a flag in the openbmp message structure that indicates that only the bmp field is valid. i guess that could work.

}

// is this an OpenBMP ASCII header (either "text" or "legacy-text")?
if (*buf == 'V') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's not support the v1 openbmp headers.

// we want at least a few bytes to do header checks
if (len < 4) {
*buf_len = 0;
printf("we want at least a few bytes to do header checks\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't use printf's. there are a bunch of utility macros for handling these kinds of parsing failures. in this case you probably just want to return PARSEBGP_PARTIAL_MSG without any kind of logging since this will be a normal failure in the case that the caller hasn't buffered a full message.

if (len < 4) {
*buf_len = 0;
printf("we want at least a few bytes to do header checks\n");
return 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return codes should be one of the parsebgp_error_t values

if (msg->ver_maj != 1 || msg->ver_min != 7) {
printf("Unrecognized OpenBMP header version (%" PRIu8 ".%" PRIu8 ")",
msg->ver_maj, msg->ver_min);
return 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you should be returning an error here, no?
this is probably an instance where you want to use one of the INVALID message macros

@luminshi
Copy link
Author

luminshi commented Sep 3, 2019

@alistairking I have made the corresponding changes for all comments above. Please review again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants