~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/golang.org/x/net/ipv6/control.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
4
 
 
5
package ipv6
 
6
 
 
7
import (
 
8
        "errors"
 
9
        "fmt"
 
10
        "net"
 
11
        "sync"
 
12
)
 
13
 
 
14
var (
 
15
        errMissingAddress  = errors.New("missing address")
 
16
        errInvalidConnType = errors.New("invalid conn type")
 
17
        errNoSuchInterface = errors.New("no such interface")
 
18
)
 
19
 
 
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.
 
24
 
 
25
type rawOpt struct {
 
26
        sync.RWMutex
 
27
        cflags ControlFlags
 
28
}
 
29
 
 
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 }
 
33
 
 
34
// A ControlFlags represents per packet basis IP-level socket option
 
35
// control flags.
 
36
type ControlFlags uint
 
37
 
 
38
const (
 
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
 
45
)
 
46
 
 
47
const flagPacketInfo = FlagDst | FlagInterface
 
48
 
 
49
// A ControlMessage represents per packet basis IP-level socket
 
50
// options.
 
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.
 
55
        //
 
56
        // Specifying socket options: ControlMessage for WriteTo
 
57
        // method of PacketConn allows to send the options to the
 
58
        // protocol stack.
 
59
        //
 
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
 
67
}
 
68
 
 
69
func (cm *ControlMessage) String() string {
 
70
        if cm == nil {
 
71
                return "<nil>"
 
72
        }
 
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)
 
74
}
 
75
 
 
76
// Ancillary data socket options
 
77
const (
 
78
        ctlTrafficClass = iota // header field
 
79
        ctlHopLimit            // header field
 
80
        ctlPacketInfo          // inbound or outbound packet path
 
81
        ctlNextHop             // nexthop
 
82
        ctlPathMTU             // path mtu
 
83
        ctlMax
 
84
)
 
85
 
 
86
// A ctlOpt represents a binding for ancillary data socket option.
 
87
type ctlOpt struct {
 
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)
 
92
}