mirror of
https://github.com/rancher/plugins.git
synced 2025-09-16 19:30:01 +00:00
vendor folder bump.
This commit is contained in:
76
vendor/golang.org/x/net/ipv4/control.go
generated
vendored
76
vendor/golang.org/x/net/ipv4/control.go
generated
vendored
@@ -1,4 +1,4 @@
|
||||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Copyright 2012 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
@@ -8,6 +8,9 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
|
||||
"golang.org/x/net/internal/iana"
|
||||
"golang.org/x/net/internal/socket"
|
||||
)
|
||||
|
||||
type rawOpt struct {
|
||||
@@ -51,6 +54,77 @@ func (cm *ControlMessage) String() string {
|
||||
return fmt.Sprintf("ttl=%d src=%v dst=%v ifindex=%d", cm.TTL, cm.Src, cm.Dst, cm.IfIndex)
|
||||
}
|
||||
|
||||
// Marshal returns the binary encoding of cm.
|
||||
func (cm *ControlMessage) Marshal() []byte {
|
||||
if cm == nil {
|
||||
return nil
|
||||
}
|
||||
var m socket.ControlMessage
|
||||
if ctlOpts[ctlPacketInfo].name > 0 && (cm.Src.To4() != nil || cm.IfIndex > 0) {
|
||||
m = socket.NewControlMessage([]int{ctlOpts[ctlPacketInfo].length})
|
||||
}
|
||||
if len(m) > 0 {
|
||||
ctlOpts[ctlPacketInfo].marshal(m, cm)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// Parse parses b as a control message and stores the result in cm.
|
||||
func (cm *ControlMessage) Parse(b []byte) error {
|
||||
ms, err := socket.ControlMessage(b).Parse()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, m := range ms {
|
||||
lvl, typ, l, err := m.ParseHeader()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if lvl != iana.ProtocolIP {
|
||||
continue
|
||||
}
|
||||
switch {
|
||||
case typ == ctlOpts[ctlTTL].name && l >= ctlOpts[ctlTTL].length:
|
||||
ctlOpts[ctlTTL].parse(cm, m.Data(l))
|
||||
case typ == ctlOpts[ctlDst].name && l >= ctlOpts[ctlDst].length:
|
||||
ctlOpts[ctlDst].parse(cm, m.Data(l))
|
||||
case typ == ctlOpts[ctlInterface].name && l >= ctlOpts[ctlInterface].length:
|
||||
ctlOpts[ctlInterface].parse(cm, m.Data(l))
|
||||
case typ == ctlOpts[ctlPacketInfo].name && l >= ctlOpts[ctlPacketInfo].length:
|
||||
ctlOpts[ctlPacketInfo].parse(cm, m.Data(l))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewControlMessage returns a new control message.
|
||||
//
|
||||
// The returned message is large enough for options specified by cf.
|
||||
func NewControlMessage(cf ControlFlags) []byte {
|
||||
opt := rawOpt{cflags: cf}
|
||||
var l int
|
||||
if opt.isset(FlagTTL) && ctlOpts[ctlTTL].name > 0 {
|
||||
l += socket.ControlMessageSpace(ctlOpts[ctlTTL].length)
|
||||
}
|
||||
if ctlOpts[ctlPacketInfo].name > 0 {
|
||||
if opt.isset(FlagSrc | FlagDst | FlagInterface) {
|
||||
l += socket.ControlMessageSpace(ctlOpts[ctlPacketInfo].length)
|
||||
}
|
||||
} else {
|
||||
if opt.isset(FlagDst) && ctlOpts[ctlDst].name > 0 {
|
||||
l += socket.ControlMessageSpace(ctlOpts[ctlDst].length)
|
||||
}
|
||||
if opt.isset(FlagInterface) && ctlOpts[ctlInterface].name > 0 {
|
||||
l += socket.ControlMessageSpace(ctlOpts[ctlInterface].length)
|
||||
}
|
||||
}
|
||||
var b []byte
|
||||
if l > 0 {
|
||||
b = make([]byte, l)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// Ancillary data socket options
|
||||
const (
|
||||
ctlTTL = iota // header field
|
||||
|
Reference in New Issue
Block a user