create error type for unsupported SO_MARK socket option

Signed-off-by: Jeremiah Millay <jmillay@fastly.com>
This commit is contained in:
Jeremiah Millay 2023-05-19 10:43:31 -04:00 committed by Kaj Niemi
parent 089e6a92cb
commit 877239a18a
3 changed files with 9 additions and 13 deletions

View File

@ -83,6 +83,8 @@ const (
var ( var (
ipv4Proto = map[string]string{"icmp": "ip4:icmp", "udp": "udp4"} ipv4Proto = map[string]string{"icmp": "ip4:icmp", "udp": "udp4"}
ipv6Proto = map[string]string{"icmp": "ip6:ipv6-icmp", "udp": "udp6"} ipv6Proto = map[string]string{"icmp": "ip6:ipv6-icmp", "udp": "udp6"}
ErrMarkNotSupported = errors.New("setting SO_MARK socket option is not supported on this platform")
) )
// New returns a new Pinger struct pointer. // New returns a new Pinger struct pointer.
@ -191,7 +193,7 @@ type Pinger struct {
ipaddr *net.IPAddr ipaddr *net.IPAddr
addr string addr string
// Mark is a mark (fwmark) set on outgoing icmp packets // mark is a SO_MARK (fwmark) set on outgoing icmp packets
mark uint mark uint
// trackerUUIDs is the list of UUIDs being used for sending packets. // trackerUUIDs is the list of UUIDs being used for sending packets.

View File

@ -3,10 +3,6 @@
package ping package ping
import (
"errors"
)
// Returns the length of an ICMP message. // Returns the length of an ICMP message.
func (p *Pinger) getMessageLength() int { func (p *Pinger) getMessageLength() int {
return p.Size + 8 return p.Size + 8
@ -20,17 +16,17 @@ func (p *Pinger) matchID(ID int) bool {
// SetMark sets the SO_MARK socket option on outgoing ICMP packets. // SetMark sets the SO_MARK socket option on outgoing ICMP packets.
// Setting this option requires CAP_NET_ADMIN. // Setting this option requires CAP_NET_ADMIN.
func (c *icmpConn) SetMark(mark uint) error { func (c *icmpConn) SetMark(mark uint) error {
return errors.New("setting SO_MARK socket option is not supported on this platform") return ErrMarkNotSupported
} }
// SetMark sets the SO_MARK socket option on outgoing ICMP packets. // SetMark sets the SO_MARK socket option on outgoing ICMP packets.
// Setting this option requires CAP_NET_ADMIN. // Setting this option requires CAP_NET_ADMIN.
func (c *icmpv4Conn) SetMark(mark uint) error { func (c *icmpv4Conn) SetMark(mark uint) error {
return errors.New("setting SO_MARK socket option is not supported on this platform") return ErrMarkNotSupported
} }
// SetMark sets the SO_MARK socket option on outgoing ICMP packets. // SetMark sets the SO_MARK socket option on outgoing ICMP packets.
// Setting this option requires CAP_NET_ADMIN. // Setting this option requires CAP_NET_ADMIN.
func (c *icmpV6Conn) SetMark(mark uint) error { func (c *icmpV6Conn) SetMark(mark uint) error {
return errors.New("setting SO_MARK socket option is not supported on this platform") return ErrMarkNotSupported
} }

View File

@ -4,8 +4,6 @@
package ping package ping
import ( import (
"errors"
"golang.org/x/net/ipv4" "golang.org/x/net/ipv4"
"golang.org/x/net/ipv6" "golang.org/x/net/ipv6"
) )
@ -29,17 +27,17 @@ func (p *Pinger) matchID(ID int) bool {
// SetMark sets the SO_MARK socket option on outgoing ICMP packets. // SetMark sets the SO_MARK socket option on outgoing ICMP packets.
// Setting this option requires CAP_NET_ADMIN. // Setting this option requires CAP_NET_ADMIN.
func (c *icmpConn) SetMark(mark uint) error { func (c *icmpConn) SetMark(mark uint) error {
return errors.New("setting SO_MARK socket option is not supported on this platform") return ErrMarkNotSupported
} }
// SetMark sets the SO_MARK socket option on outgoing ICMP packets. // SetMark sets the SO_MARK socket option on outgoing ICMP packets.
// Setting this option requires CAP_NET_ADMIN. // Setting this option requires CAP_NET_ADMIN.
func (c *icmpv4Conn) SetMark(mark uint) error { func (c *icmpv4Conn) SetMark(mark uint) error {
return errors.New("setting SO_MARK socket option is not supported on this platform") return ErrMarkNotSupported
} }
// SetMark sets the SO_MARK socket option on outgoing ICMP packets. // SetMark sets the SO_MARK socket option on outgoing ICMP packets.
// Setting this option requires CAP_NET_ADMIN. // Setting this option requires CAP_NET_ADMIN.
func (c *icmpV6Conn) SetMark(mark uint) error { func (c *icmpV6Conn) SetMark(mark uint) error {
return errors.New("setting SO_MARK socket option is not supported on this platform") return ErrMarkNotSupported
} }