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

feat: Handle OobData #210

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

dave-tucker
Copy link

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.

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]>
Copy link
Owner

@mdlayher mdlayher left a 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
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
OobData []byte
OOBData []byte

In canonical Go style.

if err != nil {
return nil, err
}

var rawOob []byte
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
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`.
Copy link
Owner

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)
Copy link
Owner

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 {
Copy link
Owner

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.

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