Skip to content

Commit

Permalink
create error type for unsupported SO_MARK socket option
Browse files Browse the repository at this point in the history
Signed-off-by: Jeremiah Millay <jmillay@fastly.com>
  • Loading branch information
floatingstatic committed May 19, 2023
1 parent a3b14d9 commit 13de065
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
4 changes: 3 additions & 1 deletion ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ const (
var (
ipv4Proto = map[string]string{"icmp": "ip4:icmp", "udp": "udp4"}
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.
Expand Down Expand Up @@ -189,7 +191,7 @@ type Pinger struct {
ipaddr *net.IPAddr
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

// trackerUUIDs is the list of UUIDs being used for sending packets.
Expand Down
10 changes: 3 additions & 7 deletions utils_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@

package probing

import (
"errors"
)

// Returns the length of an ICMP message.
func (p *Pinger) getMessageLength() int {
return p.Size + 8
Expand All @@ -20,17 +16,17 @@ func (p *Pinger) matchID(ID int) bool {
// SetMark sets the SO_MARK socket option on outgoing ICMP packets.
// Setting this option requires CAP_NET_ADMIN.
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.
// Setting this option requires CAP_NET_ADMIN.
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.
// Setting this option requires CAP_NET_ADMIN.
func (c *icmpV6Conn) SetMark(mark uint) error {
return errors.New("setting SO_MARK socket option is not supported on this platform")
return ErrMarkNotSupported
}
8 changes: 3 additions & 5 deletions utils_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
package probing

import (
"errors"

"golang.org/x/net/ipv4"
"golang.org/x/net/ipv6"
)
Expand All @@ -29,17 +27,17 @@ func (p *Pinger) matchID(ID int) bool {
// SetMark sets the SO_MARK socket option on outgoing ICMP packets.
// Setting this option requires CAP_NET_ADMIN.
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.
// Setting this option requires CAP_NET_ADMIN.
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.
// Setting this option requires CAP_NET_ADMIN.
func (c *icmpV6Conn) SetMark(mark uint) error {
return errors.New("setting SO_MARK socket option is not supported on this platform")
return ErrMarkNotSupported
}

0 comments on commit 13de065

Please sign in to comment.