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

Add support for setting SO_MARK socket option on outgoing ICMP packets #36

Merged
merged 3 commits into from
May 20, 2023

Conversation

floatingstatic
Copy link
Contributor

The standard ping utility in linux has a flag that can be used to set a mark on outgoing packets which is used in tandem with linux policy routing.

-m mark
           use mark to tag the packets going out. This is useful for variety of reasons within the kernel such as
           using policy routing to select specific outbound processing.

Setting a mark can be achieved in linux by setting the SO_MARK socket option:

       SO_MARK (since Linux 2.6.25)
              Set the mark for each packet sent through this socket
              (similar to the netfilter MARK target but socket-based).
              Changing the mark can be used for mark-based routing
              without netfilter or for packet filtering.  Setting this
              option requires the CAP_NET_ADMIN capability.

This PR attempts to adds support for this feature. Given a socket has to first exist before we can set the mark we add a SetMark() and Mark() options to set and read the intended mark to be set once the icmp conn exists. In addition to this we add a SetMark() method to the packetconn interface to actually set the socket option after the conn is created. This PR only attempts to set this option under linux. Other environments (windows, etc.) will throw an error if attempting to set a mark on the socket. I'm not sure if this is supported outside of linux or not.

Signed-off-by: Jeremiah Millay <jmillay@fastly.com>
Copy link
Contributor

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

Thanks, a few minor issues.

README.md Outdated Show resolved Hide resolved
utils_windows.go Outdated Show resolved Hide resolved
ping.go Outdated Show resolved Hide resolved
Co-authored-by: Ben Kochie <superq@gmail.com>
Signed-off-by: Jeremiah Millay <5504449+floatingstatic@users.noreply.github.com>
@SuperQ
Copy link
Contributor

SuperQ commented May 19, 2023

This needs a DCO sign-off. You can use git commit -s --amend to add it.

Signed-off-by: Jeremiah Millay <jmillay@fastly.com>
Copy link
Contributor

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

Thanks!

@SuperQ SuperQ merged commit 33a3973 into prometheus-community:main May 20, 2023
3 checks passed
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.

None yet

2 participants