1
// Copyright 2013 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
15
errMissingAddress = errors.New("missing address")
16
errInvalidConnType = errors.New("invalid conn type")
17
errNoSuchInterface = errors.New("no such interface")
20
// Note that RFC 3542 obsoletes RFC 2292 but OS X Snow Leopard and the
21
// former still support RFC 2292 only. Please be aware that almost
22
// all protocol implementations prohibit using a combination of RFC
23
// 2292 and RFC 3542 for some practical reasons.
30
func (c *rawOpt) set(f ControlFlags) { c.cflags |= f }
31
func (c *rawOpt) clear(f ControlFlags) { c.cflags &^= f }
32
func (c *rawOpt) isset(f ControlFlags) bool { return c.cflags&f != 0 }
34
// A ControlFlags represents per packet basis IP-level socket option
36
type ControlFlags uint
39
FlagTrafficClass ControlFlags = 1 << iota // pass the traffic class on the received packet
40
FlagHopLimit // pass the hop limit on the received packet
41
FlagSrc // pass the source address on the received packet
42
FlagDst // pass the destination address on the received packet
43
FlagInterface // pass the interface index on the received packet
44
FlagPathMTU // pass the path MTU on the received packet path
47
const flagPacketInfo = FlagDst | FlagInterface
49
// A ControlMessage represents per packet basis IP-level socket
51
type ControlMessage struct {
52
// Receiving socket options: SetControlMessage allows to
53
// receive the options from the protocol stack using ReadFrom
54
// method of PacketConn.
56
// Specifying socket options: ControlMessage for WriteTo
57
// method of PacketConn allows to send the options to the
60
TrafficClass int // traffic class, must be 1 <= value <= 255 when specifying
61
HopLimit int // hop limit, must be 1 <= value <= 255 when specifying
62
Src net.IP // source address, specifying only
63
Dst net.IP // destination address, receiving only
64
IfIndex int // interface index, must be 1 <= value when specifying
65
NextHop net.IP // next hop address, specifying only
66
MTU int // path MTU, receiving only
69
func (cm *ControlMessage) String() string {
73
return fmt.Sprintf("tclass: %#x, hoplim: %v, src: %v, dst: %v, ifindex: %v, nexthop: %v, mtu: %v", cm.TrafficClass, cm.HopLimit, cm.Src, cm.Dst, cm.IfIndex, cm.NextHop, cm.MTU)
76
// Ancillary data socket options
78
ctlTrafficClass = iota // header field
79
ctlHopLimit // header field
80
ctlPacketInfo // inbound or outbound packet path
82
ctlPathMTU // path mtu
86
// A ctlOpt represents a binding for ancillary data socket option.
88
name int // option name, must be equal or greater than 1
89
length int // option length
90
marshal func([]byte, *ControlMessage) []byte
91
parse func(*ControlMessage, []byte)