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.
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.
Setting a mark can be achieved in linux by setting the
SO_MARK
socket option: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()
andMark()
options to set and read the intended mark to be set once the icmp conn exists. In addition to this we add aSetMark()
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.