-
Notifications
You must be signed in to change notification settings - Fork 97
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
feat: Handle OobData #210
base: main
Are you sure you want to change the base?
feat: Handle OobData #210
Conversation
Adds OobData []byte to the Message struct. During the Recieve() function, this field is populated with the raw bytes of any control messages recieved from the recvmsg call. An example of how to process the OobData field has been included. This feature requires the user to set EnableControlMessages in the Config. This is to avoid allocating an additional page per recvmsg call unless it's absolutely necessary. Signed-off-by: Dave Tucker <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable overall, some code nits. I'll pull this locally and play around too.
Data []byte | ||
Header Header | ||
Data []byte | ||
OobData []byte |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OobData []byte | |
OOBData []byte |
In canonical Go style.
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var rawOob []byte |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var rawOob []byte | |
var rawOOB []byte |
// EnableControlMessages enables the use of control messages for | ||
// netlink. This option is intended for advanced use cases where the | ||
// caller needs to receive control messages that contain ancillary data. | ||
// For example, when using options like `ListenAllNSID`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add another sentence like:
// When enabled, the Message.OOBData field will be populated with control message data.
log.Fatalf("failed to dial netlink: %v", err) | ||
} | ||
defer c.Close() | ||
c.SetOption(netlink.ListenAllNSID, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check error.
// Iterate over recieved messages and print them | ||
for _, msg := range msgs { | ||
// If the message contains oob data, parse it and print the netnsid | ||
if msg.OobData != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invert conditional and continue if nil rather than adding indentation.
Adds OobData []byte to the Message struct.
During the Recieve() function, this field is populated with the raw bytes of any control messages recieved from the recvmsg call.
An example of how to process the OobData field has been included.