Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
7517f6ba
Commit
7517f6ba
authored
Sep 04, 2018
by
Lion-Wei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update vendor
parent
d1111a57
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
41 changed files
with
267 additions
and
749 deletions
+267
-749
Godeps.json
Godeps/Godeps.json
+3
-4
ipvs.go
vendor/github.com/docker/libnetwork/ipvs/ipvs.go
+25
-7
netlink.go
vendor/github.com/docker/libnetwork/ipvs/netlink.go
+13
-6
BUILD
vendor/github.com/vishvananda/netlink/BUILD
+0
-4
Makefile
vendor/github.com/vishvananda/netlink/Makefile
+2
-3
README.md
vendor/github.com/vishvananda/netlink/README.md
+0
-1
addr_linux.go
vendor/github.com/vishvananda/netlink/addr_linux.go
+18
-18
bridge_linux.go
vendor/github.com/vishvananda/netlink/bridge_linux.go
+9
-9
class_linux.go
vendor/github.com/vishvananda/netlink/class_linux.go
+12
-13
conntrack_linux.go
vendor/github.com/vishvananda/netlink/conntrack_linux.go
+7
-7
filter.go
vendor/github.com/vishvananda/netlink/filter.go
+1
-1
filter_linux.go
vendor/github.com/vishvananda/netlink/filter_linux.go
+9
-10
fou.go
vendor/github.com/vishvananda/netlink/fou.go
+0
-21
fou_linux.go
vendor/github.com/vishvananda/netlink/fou_linux.go
+0
-215
fou_unspecified.go
vendor/github.com/vishvananda/netlink/fou_unspecified.go
+0
-15
genetlink_linux.go
vendor/github.com/vishvananda/netlink/genetlink_linux.go
+3
-4
gtp_linux.go
vendor/github.com/vishvananda/netlink/gtp_linux.go
+7
-8
handle_linux.go
vendor/github.com/vishvananda/netlink/handle_linux.go
+9
-9
link.go
vendor/github.com/vishvananda/netlink/link.go
+38
-79
link_linux.go
vendor/github.com/vishvananda/netlink/link_linux.go
+0
-0
neigh.go
vendor/github.com/vishvananda/netlink/neigh.go
+0
-2
neigh_linux.go
vendor/github.com/vishvananda/netlink/neigh_linux.go
+10
-24
BUILD
vendor/github.com/vishvananda/netlink/nl/BUILD
+0
-2
addr_linux.go
vendor/github.com/vishvananda/netlink/nl/addr_linux.go
+6
-7
link_linux.go
vendor/github.com/vishvananda/netlink/nl/link_linux.go
+3
-20
nl_linux.go
vendor/github.com/vishvananda/netlink/nl/nl_linux.go
+0
-0
route_linux.go
vendor/github.com/vishvananda/netlink/nl/route_linux.go
+19
-20
seg6_linux.go
vendor/github.com/vishvananda/netlink/nl/seg6_linux.go
+0
-111
syscall.go
vendor/github.com/vishvananda/netlink/nl/syscall.go
+0
-10
protinfo_linux.go
vendor/github.com/vishvananda/netlink/protinfo_linux.go
+4
-5
qdisc_linux.go
vendor/github.com/vishvananda/netlink/qdisc_linux.go
+11
-12
route.go
vendor/github.com/vishvananda/netlink/route.go
+0
-2
route_linux.go
vendor/github.com/vishvananda/netlink/route_linux.go
+0
-0
rule.go
vendor/github.com/vishvananda/netlink/rule.go
+0
-1
rule_linux.go
vendor/github.com/vishvananda/netlink/rule_linux.go
+20
-30
socket_linux.go
vendor/github.com/vishvananda/netlink/socket_linux.go
+4
-4
xfrm.go
vendor/github.com/vishvananda/netlink/xfrm.go
+6
-7
xfrm_monitor_linux.go
vendor/github.com/vishvananda/netlink/xfrm_monitor_linux.go
+4
-3
xfrm_policy_linux.go
vendor/github.com/vishvananda/netlink/xfrm_policy_linux.go
+10
-9
xfrm_state.go
vendor/github.com/vishvananda/netlink/xfrm_state.go
+3
-24
xfrm_state_linux.go
vendor/github.com/vishvananda/netlink/xfrm_state_linux.go
+11
-22
No files found.
Godeps/Godeps.json
View file @
7517f6ba
...
...
@@ -1500,8 +1500,7 @@
},
{
"ImportPath"
:
"github.com/docker/libnetwork/ipvs"
,
"Comment"
:
"v0.8.0-dev.2-910-gba46b928"
,
"Rev"
:
"ba46b928444931e6865d8618dc03622cac79aa6f"
"Rev"
:
"a9cd636e37898226332c439363e2ed0ea185ae92"
},
{
"ImportPath"
:
"github.com/docker/spdystream"
,
...
...
@@ -3062,11 +3061,11 @@
},
{
"ImportPath"
:
"github.com/vishvananda/netlink"
,
"Rev"
:
"
f67b75edbf5e3bb7dfe70bb788610693a71be3d1
"
"Rev"
:
"
b2de5d10e38ecce8607e6b438b6d174f389a004e
"
},
{
"ImportPath"
:
"github.com/vishvananda/netlink/nl"
,
"Rev"
:
"
f67b75edbf5e3bb7dfe70bb788610693a71be3d1
"
"Rev"
:
"
b2de5d10e38ecce8607e6b438b6d174f389a004e
"
},
{
"ImportPath"
:
"github.com/vishvananda/netns"
,
...
...
vendor/github.com/docker/libnetwork/ipvs/ipvs.go
View file @
7517f6ba
...
...
@@ -5,12 +5,19 @@ package ipvs
import
(
"net"
"syscall"
"time"
"fmt"
"github.com/vishvananda/netlink/nl"
"github.com/vishvananda/netns"
)
const
(
netlinkRecvSocketsTimeout
=
3
*
time
.
Second
netlinkSendSocketTimeout
=
30
*
time
.
Second
)
// Service defines an IPVS service in its entirety.
type
Service
struct
{
// Virtual service address.
...
...
@@ -46,13 +53,15 @@ type SvcStats struct {
// Destination defines an IPVS destination (real server) in its
// entirety.
type
Destination
struct
{
Address
net
.
IP
Port
uint16
Weight
int
ConnectionFlags
uint32
AddressFamily
uint16
UpperThreshold
uint32
LowerThreshold
uint32
Address
net
.
IP
Port
uint16
Weight
int
ConnectionFlags
uint32
AddressFamily
uint16
UpperThreshold
uint32
LowerThreshold
uint32
ActiveConnections
int
InactiveConnections
int
}
// Handle provides a namespace specific ipvs handle to program ipvs
...
...
@@ -82,6 +91,15 @@ func New(path string) (*Handle, error) {
if
err
!=
nil
{
return
nil
,
err
}
// Add operation timeout to avoid deadlocks
tv
:=
syscall
.
NsecToTimeval
(
netlinkSendSocketTimeout
.
Nanoseconds
())
if
err
:=
sock
.
SetSendTimeout
(
&
tv
);
err
!=
nil
{
return
nil
,
err
}
tv
=
syscall
.
NsecToTimeval
(
netlinkRecvSocketsTimeout
.
Nanoseconds
())
if
err
:=
sock
.
SetReceiveTimeout
(
&
tv
);
err
!=
nil
{
return
nil
,
err
}
return
&
Handle
{
sock
:
sock
},
nil
}
...
...
vendor/github.com/docker/libnetwork/ipvs/netlink.go
View file @
7517f6ba
...
...
@@ -100,7 +100,7 @@ func fillService(s *Service) nl.NetlinkRequestData {
return
cmdAttr
}
func
fillDestinaton
(
d
*
Destination
)
nl
.
NetlinkRequestData
{
func
fillDestinat
i
on
(
d
*
Destination
)
nl
.
NetlinkRequestData
{
cmdAttr
:=
nl
.
NewRtAttr
(
ipvsCmdAttrDest
,
nil
)
nl
.
NewRtAttrChild
(
cmdAttr
,
ipvsDestAttrAddress
,
rawIPData
(
d
.
Address
))
...
...
@@ -134,7 +134,7 @@ func (i *Handle) doCmdwithResponse(s *Service, d *Destination, cmd uint8) ([][]b
}
}
else
{
req
.
AddData
(
fillDestinaton
(
d
))
req
.
AddData
(
fillDestinat
i
on
(
d
))
}
res
,
err
:=
execute
(
i
.
sock
,
req
,
0
)
...
...
@@ -203,10 +203,6 @@ func newGenlRequest(familyID int, cmd uint8) *nl.NetlinkRequest {
}
func
execute
(
s
*
nl
.
NetlinkSocket
,
req
*
nl
.
NetlinkRequest
,
resType
uint16
)
([][]
byte
,
error
)
{
var
(
err
error
)
if
err
:=
s
.
Send
(
req
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -222,6 +218,13 @@ done:
for
{
msgs
,
err
:=
s
.
Receive
()
if
err
!=
nil
{
if
s
.
GetFd
()
==
-
1
{
return
nil
,
fmt
.
Errorf
(
"Socket got closed on receive"
)
}
if
err
==
syscall
.
EAGAIN
{
// timeout fired
continue
}
return
nil
,
err
}
for
_
,
m
:=
range
msgs
{
...
...
@@ -436,6 +439,10 @@ func assembleDestination(attrs []syscall.NetlinkRouteAttr) (*Destination, error)
d
.
LowerThreshold
=
native
.
Uint32
(
attr
.
Value
)
case
ipvsDestAttrAddressFamily
:
d
.
AddressFamily
=
native
.
Uint16
(
attr
.
Value
)
case
ipvsDestAttrActiveConnections
:
d
.
ActiveConnections
=
int
(
native
.
Uint16
(
attr
.
Value
))
case
ipvsDestAttrInactiveConnections
:
d
.
InactiveConnections
=
int
(
native
.
Uint16
(
attr
.
Value
))
}
}
return
&
d
,
nil
...
...
vendor/github.com/vishvananda/netlink/BUILD
View file @
7517f6ba
...
...
@@ -13,9 +13,6 @@ go_library(
"conntrack_unspecified.go",
"filter.go",
"filter_linux.go",
"fou.go",
"fou_linux.go",
"fou_unspecified.go",
"genetlink_linux.go",
"genetlink_unspecified.go",
"gtp_linux.go",
...
...
@@ -54,7 +51,6 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/vishvananda/netlink/nl:go_default_library",
"//vendor/golang.org/x/sys/unix:go_default_library",
] + select({
"@io_bazel_rules_go//go/platform:android": [
"//vendor/github.com/vishvananda/netns:go_default_library",
...
...
vendor/github.com/vishvananda/netlink/Makefile
View file @
7517f6ba
...
...
@@ -3,8 +3,7 @@ DIRS := \
nl
DEPS
=
\
github.com/vishvananda/netns
\
golang.org/x/sys/unix
github.com/vishvananda/netns
uniq
=
$
(
if
$1
,
$
(
firstword
$1
)
$
(
call
uniq
,
$
(
filter-out
$
(
firstword
$1
)
,
$1
)))
testdirs
=
$
(
call
uniq
,
$
(
foreach d,
$
(
1
)
,
$
(
dir
$
(
wildcard
$(d)
/
*
_test.go
))))
...
...
@@ -19,7 +18,7 @@ $(call goroot,$(DEPS)):
.PHONY
:
$(call testdirs
,
$(DIRS))
$(call testdirs,$(DIRS))
:
go
test
-test
.exec
sudo
-test
.parallel 4
-timeout
60s
-test
.
v github.com/vishvananda/netlink/
$@
sudo
-E
go
test
-test
.parallel 4
-timeout
60s
-
v
github.com/vishvananda/netlink/
$@
$(call fmt,$(call testdirs,$(DIRS)))
:
!
gofmt
-l
$
(
subst fmt-,,
$@
)
/
*
.go |
grep
-q
.
...
...
vendor/github.com/vishvananda/netlink/README.md
View file @
7517f6ba
...
...
@@ -89,4 +89,3 @@ There are also a few pieces of low level netlink functionality that still
need to be implemented. Routing rules are not in place and some of the
more advanced link types. Hopefully there is decent structure and testing
in place to make these fairly straightforward to add.
vendor/github.com/vishvananda/netlink/addr_linux.go
View file @
7517f6ba
...
...
@@ -4,10 +4,10 @@ import (
"fmt"
"net"
"strings"
"syscall"
"github.com/vishvananda/netlink/nl"
"github.com/vishvananda/netns"
"golang.org/x/sys/unix"
)
// IFA_FLAGS is a u32 attribute.
...
...
@@ -22,7 +22,7 @@ func AddrAdd(link Link, addr *Addr) error {
// AddrAdd will add an IP address to a link device.
// Equivalent to: `ip addr add $addr dev $link`
func
(
h
*
Handle
)
AddrAdd
(
link
Link
,
addr
*
Addr
)
error
{
req
:=
h
.
newNetlinkRequest
(
unix
.
RTM_NEWADDR
,
unix
.
NLM_F_CREATE
|
unix
.
NLM_F_EXCL
|
unix
.
NLM_F_ACK
)
req
:=
h
.
newNetlinkRequest
(
syscall
.
RTM_NEWADDR
,
syscall
.
NLM_F_CREATE
|
syscall
.
NLM_F_EXCL
|
syscall
.
NLM_F_ACK
)
return
h
.
addrHandle
(
link
,
addr
,
req
)
}
...
...
@@ -35,7 +35,7 @@ func AddrReplace(link Link, addr *Addr) error {
// AddrReplace will replace (or, if not present, add) an IP address on a link device.
// Equivalent to: `ip addr replace $addr dev $link`
func
(
h
*
Handle
)
AddrReplace
(
link
Link
,
addr
*
Addr
)
error
{
req
:=
h
.
newNetlinkRequest
(
unix
.
RTM_NEWADDR
,
unix
.
NLM_F_CREATE
|
unix
.
NLM_F_REPLACE
|
unix
.
NLM_F_ACK
)
req
:=
h
.
newNetlinkRequest
(
syscall
.
RTM_NEWADDR
,
syscall
.
NLM_F_CREATE
|
syscall
.
NLM_F_REPLACE
|
syscall
.
NLM_F_ACK
)
return
h
.
addrHandle
(
link
,
addr
,
req
)
}
...
...
@@ -48,7 +48,7 @@ func AddrDel(link Link, addr *Addr) error {
// AddrDel will delete an IP address from a link device.
// Equivalent to: `ip addr del $addr dev $link`
func
(
h
*
Handle
)
AddrDel
(
link
Link
,
addr
*
Addr
)
error
{
req
:=
h
.
newNetlinkRequest
(
unix
.
RTM_DELADDR
,
unix
.
NLM_F_ACK
)
req
:=
h
.
newNetlinkRequest
(
syscall
.
RTM_DELADDR
,
syscall
.
NLM_F_ACK
)
return
h
.
addrHandle
(
link
,
addr
,
req
)
}
...
...
@@ -75,7 +75,7 @@ func (h *Handle) addrHandle(link Link, addr *Addr, req *nl.NetlinkRequest) error
localAddrData
=
addr
.
IP
.
To16
()
}
localData
:=
nl
.
NewRtAttr
(
unix
.
IFA_LOCAL
,
localAddrData
)
localData
:=
nl
.
NewRtAttr
(
syscall
.
IFA_LOCAL
,
localAddrData
)
req
.
AddData
(
localData
)
var
peerAddrData
[]
byte
if
addr
.
Peer
!=
nil
{
...
...
@@ -88,7 +88,7 @@ func (h *Handle) addrHandle(link Link, addr *Addr, req *nl.NetlinkRequest) error
peerAddrData
=
localAddrData
}
addressData
:=
nl
.
NewRtAttr
(
unix
.
IFA_ADDRESS
,
peerAddrData
)
addressData
:=
nl
.
NewRtAttr
(
syscall
.
IFA_ADDRESS
,
peerAddrData
)
req
.
AddData
(
addressData
)
if
addr
.
Flags
!=
0
{
...
...
@@ -109,14 +109,14 @@ func (h *Handle) addrHandle(link Link, addr *Addr, req *nl.NetlinkRequest) error
}
addr
.
Broadcast
=
calcBroadcast
}
req
.
AddData
(
nl
.
NewRtAttr
(
unix
.
IFA_BROADCAST
,
addr
.
Broadcast
))
req
.
AddData
(
nl
.
NewRtAttr
(
syscall
.
IFA_BROADCAST
,
addr
.
Broadcast
))
if
addr
.
Label
!=
""
{
labelData
:=
nl
.
NewRtAttr
(
unix
.
IFA_LABEL
,
nl
.
ZeroTerminated
(
addr
.
Label
))
labelData
:=
nl
.
NewRtAttr
(
syscall
.
IFA_LABEL
,
nl
.
ZeroTerminated
(
addr
.
Label
))
req
.
AddData
(
labelData
)
}
_
,
err
:=
req
.
Execute
(
unix
.
NETLINK_ROUTE
,
0
)
_
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_ROUTE
,
0
)
return
err
}
...
...
@@ -131,11 +131,11 @@ func AddrList(link Link, family int) ([]Addr, error) {
// Equivalent to: `ip addr show`.
// The list can be filtered by link and ip family.
func
(
h
*
Handle
)
AddrList
(
link
Link
,
family
int
)
([]
Addr
,
error
)
{
req
:=
h
.
newNetlinkRequest
(
unix
.
RTM_GETADDR
,
unix
.
NLM_F_DUMP
)
req
:=
h
.
newNetlinkRequest
(
syscall
.
RTM_GETADDR
,
syscall
.
NLM_F_DUMP
)
msg
:=
nl
.
NewIfInfomsg
(
family
)
req
.
AddData
(
msg
)
msgs
,
err
:=
req
.
Execute
(
unix
.
NETLINK_ROUTE
,
unix
.
RTM_NEWADDR
)
msgs
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_ROUTE
,
syscall
.
RTM_NEWADDR
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -187,21 +187,21 @@ func parseAddr(m []byte) (addr Addr, family, index int, err error) {
var
local
,
dst
*
net
.
IPNet
for
_
,
attr
:=
range
attrs
{
switch
attr
.
Attr
.
Type
{
case
unix
.
IFA_ADDRESS
:
case
syscall
.
IFA_ADDRESS
:
dst
=
&
net
.
IPNet
{
IP
:
attr
.
Value
,
Mask
:
net
.
CIDRMask
(
int
(
msg
.
Prefixlen
),
8
*
len
(
attr
.
Value
)),
}
addr
.
Peer
=
dst
case
unix
.
IFA_LOCAL
:
case
syscall
.
IFA_LOCAL
:
local
=
&
net
.
IPNet
{
IP
:
attr
.
Value
,
Mask
:
net
.
CIDRMask
(
int
(
msg
.
Prefixlen
),
8
*
len
(
attr
.
Value
)),
}
addr
.
IPNet
=
local
case
unix
.
IFA_BROADCAST
:
case
syscall
.
IFA_BROADCAST
:
addr
.
Broadcast
=
attr
.
Value
case
unix
.
IFA_LABEL
:
case
syscall
.
IFA_LABEL
:
addr
.
Label
=
string
(
attr
.
Value
[
:
len
(
attr
.
Value
)
-
1
])
case
IFA_FLAGS
:
addr
.
Flags
=
int
(
native
.
Uint32
(
attr
.
Value
[
0
:
4
]))
...
...
@@ -264,7 +264,7 @@ func AddrSubscribeWithOptions(ch chan<- AddrUpdate, done <-chan struct{}, option
}
func
addrSubscribeAt
(
newNs
,
curNs
netns
.
NsHandle
,
ch
chan
<-
AddrUpdate
,
done
<-
chan
struct
{},
cberr
func
(
error
))
error
{
s
,
err
:=
nl
.
SubscribeAt
(
newNs
,
curNs
,
unix
.
NETLINK_ROUTE
,
unix
.
RTNLGRP_IPV4_IFADDR
,
unix
.
RTNLGRP_IPV6_IFADDR
)
s
,
err
:=
nl
.
SubscribeAt
(
newNs
,
curNs
,
syscall
.
NETLINK_ROUTE
,
syscall
.
RTNLGRP_IPV4_IFADDR
,
syscall
.
RTNLGRP_IPV6_IFADDR
)
if
err
!=
nil
{
return
err
}
...
...
@@ -286,7 +286,7 @@ func addrSubscribeAt(newNs, curNs netns.NsHandle, ch chan<- AddrUpdate, done <-c
}
for
_
,
m
:=
range
msgs
{
msgType
:=
m
.
Header
.
Type
if
msgType
!=
unix
.
RTM_NEWADDR
&&
msgType
!=
unix
.
RTM_DELADDR
{
if
msgType
!=
syscall
.
RTM_NEWADDR
&&
msgType
!=
syscall
.
RTM_DELADDR
{
if
cberr
!=
nil
{
cberr
(
fmt
.
Errorf
(
"bad message type: %d"
,
msgType
))
}
...
...
@@ -303,7 +303,7 @@ func addrSubscribeAt(newNs, curNs netns.NsHandle, ch chan<- AddrUpdate, done <-c
ch
<-
AddrUpdate
{
LinkAddress
:
*
addr
.
IPNet
,
LinkIndex
:
ifindex
,
NewAddr
:
msgType
==
unix
.
RTM_NEWADDR
,
NewAddr
:
msgType
==
syscall
.
RTM_NEWADDR
,
Flags
:
addr
.
Flags
,
Scope
:
addr
.
Scope
,
PreferedLft
:
addr
.
PreferedLft
,
...
...
vendor/github.com/vishvananda/netlink/bridge_linux.go
View file @
7517f6ba
...
...
@@ -2,9 +2,9 @@ package netlink
import
(
"fmt"
"syscall"
"github.com/vishvananda/netlink/nl"
"golang.org/x/sys/unix"
)
// BridgeVlanList gets a map of device id to bridge vlan infos.
...
...
@@ -16,12 +16,12 @@ func BridgeVlanList() (map[int32][]*nl.BridgeVlanInfo, error) {
// BridgeVlanList gets a map of device id to bridge vlan infos.
// Equivalent to: `bridge vlan show`
func
(
h
*
Handle
)
BridgeVlanList
()
(
map
[
int32
][]
*
nl
.
BridgeVlanInfo
,
error
)
{
req
:=
h
.
newNetlinkRequest
(
unix
.
RTM_GETLINK
,
unix
.
NLM_F_DUMP
)
msg
:=
nl
.
NewIfInfomsg
(
unix
.
AF_BRIDGE
)
req
:=
h
.
newNetlinkRequest
(
syscall
.
RTM_GETLINK
,
syscall
.
NLM_F_DUMP
)
msg
:=
nl
.
NewIfInfomsg
(
syscall
.
AF_BRIDGE
)
req
.
AddData
(
msg
)
req
.
AddData
(
nl
.
NewRtAttr
(
nl
.
IFLA_EXT_MASK
,
nl
.
Uint32Attr
(
uint32
(
nl
.
RTEXT_FILTER_BRVLAN
))))
msgs
,
err
:=
req
.
Execute
(
unix
.
NETLINK_ROUTE
,
unix
.
RTM_NEWLINK
)
msgs
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_ROUTE
,
syscall
.
RTM_NEWLINK
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -63,7 +63,7 @@ func BridgeVlanAdd(link Link, vid uint16, pvid, untagged, self, master bool) err
// BridgeVlanAdd adds a new vlan filter entry
// Equivalent to: `bridge vlan add dev DEV vid VID [ pvid ] [ untagged ] [ self ] [ master ]`
func
(
h
*
Handle
)
BridgeVlanAdd
(
link
Link
,
vid
uint16
,
pvid
,
untagged
,
self
,
master
bool
)
error
{
return
h
.
bridgeVlanModify
(
unix
.
RTM_SETLINK
,
link
,
vid
,
pvid
,
untagged
,
self
,
master
)
return
h
.
bridgeVlanModify
(
syscall
.
RTM_SETLINK
,
link
,
vid
,
pvid
,
untagged
,
self
,
master
)
}
// BridgeVlanDel adds a new vlan filter entry
...
...
@@ -75,15 +75,15 @@ func BridgeVlanDel(link Link, vid uint16, pvid, untagged, self, master bool) err
// BridgeVlanDel adds a new vlan filter entry
// Equivalent to: `bridge vlan del dev DEV vid VID [ pvid ] [ untagged ] [ self ] [ master ]`
func
(
h
*
Handle
)
BridgeVlanDel
(
link
Link
,
vid
uint16
,
pvid
,
untagged
,
self
,
master
bool
)
error
{
return
h
.
bridgeVlanModify
(
unix
.
RTM_DELLINK
,
link
,
vid
,
pvid
,
untagged
,
self
,
master
)
return
h
.
bridgeVlanModify
(
syscall
.
RTM_DELLINK
,
link
,
vid
,
pvid
,
untagged
,
self
,
master
)
}
func
(
h
*
Handle
)
bridgeVlanModify
(
cmd
int
,
link
Link
,
vid
uint16
,
pvid
,
untagged
,
self
,
master
bool
)
error
{
base
:=
link
.
Attrs
()
h
.
ensureIndex
(
base
)
req
:=
h
.
newNetlinkRequest
(
cmd
,
unix
.
NLM_F_ACK
)
req
:=
h
.
newNetlinkRequest
(
cmd
,
syscall
.
NLM_F_ACK
)
msg
:=
nl
.
NewIfInfomsg
(
unix
.
AF_BRIDGE
)
msg
:=
nl
.
NewIfInfomsg
(
syscall
.
AF_BRIDGE
)
msg
.
Index
=
int32
(
base
.
Index
)
req
.
AddData
(
msg
)
...
...
@@ -107,7 +107,7 @@ func (h *Handle) bridgeVlanModify(cmd int, link Link, vid uint16, pvid, untagged
}
nl
.
NewRtAttrChild
(
br
,
nl
.
IFLA_BRIDGE_VLAN_INFO
,
vlanInfo
.
Serialize
())
req
.
AddData
(
br
)
_
,
err
:=
req
.
Execute
(
unix
.
NETLINK_ROUTE
,
0
)
_
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_ROUTE
,
0
)
if
err
!=
nil
{
return
err
}
...
...
vendor/github.com/vishvananda/netlink/class_linux.go
View file @
7517f6ba
...
...
@@ -5,7 +5,6 @@ import (
"syscall"
"github.com/vishvananda/netlink/nl"
"golang.org/x/sys/unix"
)
// NOTE: function is in here because it uses other linux functions
...
...
@@ -51,7 +50,7 @@ func ClassDel(class Class) error {
// ClassDel will delete a class from the system.
// Equivalent to: `tc class del $class`
func
(
h
*
Handle
)
ClassDel
(
class
Class
)
error
{
return
h
.
classModify
(
unix
.
RTM_DELTCLASS
,
0
,
class
)
return
h
.
classModify
(
syscall
.
RTM_DELTCLASS
,
0
,
class
)
}
// ClassChange will change a class in place
...
...
@@ -65,7 +64,7 @@ func ClassChange(class Class) error {
// Equivalent to: `tc class change $class`
// The parent and handle MUST NOT be changed.
func
(
h
*
Handle
)
ClassChange
(
class
Class
)
error
{
return
h
.
classModify
(
unix
.
RTM_NEWTCLASS
,
0
,
class
)
return
h
.
classModify
(
syscall
.
RTM_NEWTCLASS
,
0
,
class
)
}
// ClassReplace will replace a class to the system.
...
...
@@ -83,7 +82,7 @@ func ClassReplace(class Class) error {
// If a class already exist with this parent/handle pair, the class is changed.
// If a class does not already exist with this parent/handle, a new class is created.
func
(
h
*
Handle
)
ClassReplace
(
class
Class
)
error
{
return
h
.
classModify
(
unix
.
RTM_NEWTCLASS
,
unix
.
NLM_F_CREATE
,
class
)
return
h
.
classModify
(
syscall
.
RTM_NEWTCLASS
,
syscall
.
NLM_F_CREATE
,
class
)
}
// ClassAdd will add a class to the system.
...
...
@@ -96,14 +95,14 @@ func ClassAdd(class Class) error {
// Equivalent to: `tc class add $class`
func
(
h
*
Handle
)
ClassAdd
(
class
Class
)
error
{
return
h
.
classModify
(
unix
.
RTM_NEWTCLASS
,
unix
.
NLM_F_CREATE
|
unix
.
NLM_F_EXCL
,
syscall
.
RTM_NEWTCLASS
,
syscall
.
NLM_F_CREATE
|
syscall
.
NLM_F_EXCL
,
class
,
)
}
func
(
h
*
Handle
)
classModify
(
cmd
,
flags
int
,
class
Class
)
error
{
req
:=
h
.
newNetlinkRequest
(
cmd
,
flags
|
unix
.
NLM_F_ACK
)
req
:=
h
.
newNetlinkRequest
(
cmd
,
flags
|
syscall
.
NLM_F_ACK
)
base
:=
class
.
Attrs
()
msg
:=
&
nl
.
TcMsg
{
Family
:
nl
.
FAMILY_ALL
,
...
...
@@ -113,12 +112,12 @@ func (h *Handle) classModify(cmd, flags int, class Class) error {
}
req
.
AddData
(
msg
)
if
cmd
!=
unix
.
RTM_DELTCLASS
{
if
cmd
!=
syscall
.
RTM_DELTCLASS
{
if
err
:=
classPayload
(
req
,
class
);
err
!=
nil
{
return
err
}
}
_
,
err
:=
req
.
Execute
(
unix
.
NETLINK_ROUTE
,
0
)
_
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_ROUTE
,
0
)
return
err
}
...
...
@@ -142,12 +141,12 @@ func classPayload(req *nl.NetlinkRequest, class Class) error {
var
rtab
[
256
]
uint32
var
ctab
[
256
]
uint32
tcrate
:=
nl
.
TcRateSpec
{
Rate
:
uint32
(
htb
.
Rate
)}
if
CalcRtable
(
&
tcrate
,
rtab
[
:
]
,
cellLog
,
uint32
(
mtu
),
linklayer
)
<
0
{
if
CalcRtable
(
&
tcrate
,
rtab
,
cellLog
,
uint32
(
mtu
),
linklayer
)
<
0
{
return
errors
.
New
(
"HTB: failed to calculate rate table"
)
}
opt
.
Rate
=
tcrate
tcceil
:=
nl
.
TcRateSpec
{
Rate
:
uint32
(
htb
.
Ceil
)}
if
CalcRtable
(
&
tcceil
,
ctab
[
:
]
,
ccellLog
,
uint32
(
mtu
),
linklayer
)
<
0
{
if
CalcRtable
(
&
tcceil
,
ctab
,
ccellLog
,
uint32
(
mtu
),
linklayer
)
<
0
{
return
errors
.
New
(
"HTB: failed to calculate ceil rate table"
)
}
opt
.
Ceil
=
tcceil
...
...
@@ -170,7 +169,7 @@ func ClassList(link Link, parent uint32) ([]Class, error) {
// Equivalent to: `tc class show`.
// Generally returns nothing if link and parent are not specified.
func
(
h
*
Handle
)
ClassList
(
link
Link
,
parent
uint32
)
([]
Class
,
error
)
{
req
:=
h
.
newNetlinkRequest
(
unix
.
RTM_GETTCLASS
,
unix
.
NLM_F_DUMP
)
req
:=
h
.
newNetlinkRequest
(
syscall
.
RTM_GETTCLASS
,
syscall
.
NLM_F_DUMP
)
msg
:=
&
nl
.
TcMsg
{
Family
:
nl
.
FAMILY_ALL
,
Parent
:
parent
,
...
...
@@ -182,7 +181,7 @@ func (h *Handle) ClassList(link Link, parent uint32) ([]Class, error) {
}
req
.
AddData
(
msg
)
msgs
,
err
:=
req
.
Execute
(
unix
.
NETLINK_ROUTE
,
unix
.
RTM_NEWTCLASS
)
msgs
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_ROUTE
,
syscall
.
RTM_NEWTCLASS
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
vendor/github.com/vishvananda/netlink/conntrack_linux.go
View file @
7517f6ba
...
...
@@ -6,9 +6,9 @@ import (
"errors"
"fmt"
"net"
"syscall"
"github.com/vishvananda/netlink/nl"
"golang.org/x/sys/unix"
)
// ConntrackTableType Conntrack table for the netlink operation
...
...
@@ -85,8 +85,8 @@ func (h *Handle) ConntrackTableList(table ConntrackTableType, family InetFamily)
// conntrack -F [table] Flush table
// The flush operation applies to all the family types
func
(
h
*
Handle
)
ConntrackTableFlush
(
table
ConntrackTableType
)
error
{
req
:=
h
.
newConntrackRequest
(
table
,
unix
.
AF_INET
,
nl
.
IPCTNL_MSG_CT_DELETE
,
unix
.
NLM_F_ACK
)
_
,
err
:=
req
.
Execute
(
unix
.
NETLINK_NETFILTER
,
0
)
req
:=
h
.
newConntrackRequest
(
table
,
syscall
.
AF_INET
,
nl
.
IPCTNL_MSG_CT_DELETE
,
syscall
.
NLM_F_ACK
)
_
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_NETFILTER
,
0
)
return
err
}
...
...
@@ -102,10 +102,10 @@ func (h *Handle) ConntrackDeleteFilter(table ConntrackTableType, family InetFami
for
_
,
dataRaw
:=
range
res
{
flow
:=
parseRawData
(
dataRaw
)
if
match
:=
filter
.
MatchConntrackFlow
(
flow
);
match
{
req2
:=
h
.
newConntrackRequest
(
table
,
family
,
nl
.
IPCTNL_MSG_CT_DELETE
,
unix
.
NLM_F_ACK
)
req2
:=
h
.
newConntrackRequest
(
table
,
family
,
nl
.
IPCTNL_MSG_CT_DELETE
,
syscall
.
NLM_F_ACK
)
// skip the first 4 byte that are the netfilter header, the newConntrackRequest is adding it already
req2
.
AddRawData
(
dataRaw
[
4
:
])
req2
.
Execute
(
unix
.
NETLINK_NETFILTER
,
0
)
req2
.
Execute
(
syscall
.
NETLINK_NETFILTER
,
0
)
matched
++
}
}
...
...
@@ -127,8 +127,8 @@ func (h *Handle) newConntrackRequest(table ConntrackTableType, family InetFamily
}
func
(
h
*
Handle
)
dumpConntrackTable
(
table
ConntrackTableType
,
family
InetFamily
)
([][]
byte
,
error
)
{
req
:=
h
.
newConntrackRequest
(
table
,
family
,
nl
.
IPCTNL_MSG_CT_GET
,
unix
.
NLM_F_DUMP
)
return
req
.
Execute
(
unix
.
NETLINK_NETFILTER
,
0
)
req
:=
h
.
newConntrackRequest
(
table
,
family
,
nl
.
IPCTNL_MSG_CT_GET
,
syscall
.
NLM_F_DUMP
)
return
req
.
Execute
(
syscall
.
NETLINK_NETFILTER
,
0
)
}
// The full conntrack flow structure is very complicated and can be found in the file:
...
...
vendor/github.com/vishvananda/netlink/filter.go
View file @
7517f6ba
...
...
@@ -17,7 +17,7 @@ type FilterAttrs struct {
Handle
uint32
Parent
uint32
Priority
uint16
// lower is higher priority
Protocol
uint16
//
unix
.ETH_P_*
Protocol
uint16
//
syscall
.ETH_P_*
}
func
(
q
FilterAttrs
)
String
()
string
{
...
...
vendor/github.com/vishvananda/netlink/filter_linux.go
View file @
7517f6ba
...
...
@@ -9,7 +9,6 @@ import (
"unsafe"
"github.com/vishvananda/netlink/nl"
"golang.org/x/sys/unix"
)
// Constants used in TcU32Sel.Flags.
...
...
@@ -56,7 +55,7 @@ func NewFw(attrs FilterAttrs, fattrs FilterFwAttrs) (*Fw, error) {
if
police
.
Rate
.
Rate
!=
0
{
police
.
Rate
.
Mpu
=
fattrs
.
Mpu
police
.
Rate
.
Overhead
=
fattrs
.
Overhead
if
CalcRtable
(
&
police
.
Rate
,
rtab
[
:
]
,
rcellLog
,
fattrs
.
Mtu
,
linklayer
)
<
0
{
if
CalcRtable
(
&
police
.
Rate
,
rtab
,
rcellLog
,
fattrs
.
Mtu
,
linklayer
)
<
0
{
return
nil
,
errors
.
New
(
"TBF: failed to calculate rate table"
)
}
police
.
Burst
=
uint32
(
Xmittime
(
uint64
(
police
.
Rate
.
Rate
),
uint32
(
buffer
)))
...
...
@@ -65,7 +64,7 @@ func NewFw(attrs FilterAttrs, fattrs FilterFwAttrs) (*Fw, error) {
if
police
.
PeakRate
.
Rate
!=
0
{
police
.
PeakRate
.
Mpu
=
fattrs
.
Mpu
police
.
PeakRate
.
Overhead
=
fattrs
.
Overhead
if
CalcRtable
(
&
police
.
PeakRate
,
ptab
[
:
]
,
pcellLog
,
fattrs
.
Mtu
,
linklayer
)
<
0
{
if
CalcRtable
(
&
police
.
PeakRate
,
ptab
,
pcellLog
,
fattrs
.
Mtu
,
linklayer
)
<
0
{
return
nil
,
errors
.
New
(
"POLICE: failed to calculate peak rate table"
)
}
}
...
...
@@ -99,7 +98,7 @@ func FilterDel(filter Filter) error {
// FilterDel will delete a filter from the system.
// Equivalent to: `tc filter del $filter`
func
(
h
*
Handle
)
FilterDel
(
filter
Filter
)
error
{
req
:=
h
.
newNetlinkRequest
(
unix
.
RTM_DELTFILTER
,
unix
.
NLM_F_ACK
)
req
:=
h
.
newNetlinkRequest
(
syscall
.
RTM_DELTFILTER
,
syscall
.
NLM_F_ACK
)
base
:=
filter
.
Attrs
()
msg
:=
&
nl
.
TcMsg
{
Family
:
nl
.
FAMILY_ALL
,
...
...
@@ -110,7 +109,7 @@ func (h *Handle) FilterDel(filter Filter) error {
}
req
.
AddData
(
msg
)
_
,
err
:=
req
.
Execute
(
unix
.
NETLINK_ROUTE
,
0
)
_
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_ROUTE
,
0
)
return
err
}
...
...
@@ -124,7 +123,7 @@ func FilterAdd(filter Filter) error {
// Equivalent to: `tc filter add $filter`
func
(
h
*
Handle
)
FilterAdd
(
filter
Filter
)
error
{
native
=
nl
.
NativeEndian
()
req
:=
h
.
newNetlinkRequest
(
unix
.
RTM_NEWTFILTER
,
unix
.
NLM_F_CREATE
|
unix
.
NLM_F_EXCL
|
unix
.
NLM_F_ACK
)
req
:=
h
.
newNetlinkRequest
(
syscall
.
RTM_NEWTFILTER
,
syscall
.
NLM_F_CREATE
|
syscall
.
NLM_F_EXCL
|
syscall
.
NLM_F_ACK
)
base
:=
filter
.
Attrs
()
msg
:=
&
nl
.
TcMsg
{
Family
:
nl
.
FAMILY_ALL
,
...
...
@@ -225,7 +224,7 @@ func (h *Handle) FilterAdd(filter Filter) error {
}
req
.
AddData
(
options
)
_
,
err
:=
req
.
Execute
(
unix
.
NETLINK_ROUTE
,
0
)
_
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_ROUTE
,
0
)
return
err
}
...
...
@@ -240,7 +239,7 @@ func FilterList(link Link, parent uint32) ([]Filter, error) {
// Equivalent to: `tc filter show`.
// Generally returns nothing if link and parent are not specified.
func
(
h
*
Handle
)
FilterList
(
link
Link
,
parent
uint32
)
([]
Filter
,
error
)
{
req
:=
h
.
newNetlinkRequest
(
unix
.
RTM_GETTFILTER
,
unix
.
NLM_F_DUMP
)
req
:=
h
.
newNetlinkRequest
(
syscall
.
RTM_GETTFILTER
,
syscall
.
NLM_F_DUMP
)
msg
:=
&
nl
.
TcMsg
{
Family
:
nl
.
FAMILY_ALL
,
Parent
:
parent
,
...
...
@@ -252,7 +251,7 @@ func (h *Handle) FilterList(link Link, parent uint32) ([]Filter, error) {
}
req
.
AddData
(
msg
)
msgs
,
err
:=
req
.
Execute
(
unix
.
NETLINK_ROUTE
,
unix
.
RTM_NEWTFILTER
)
msgs
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_ROUTE
,
syscall
.
RTM_NEWTFILTER
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -563,7 +562,7 @@ func AdjustSize(sz uint, mpu uint, linklayer int) uint {
}
}
func
CalcRtable
(
rate
*
nl
.
TcRateSpec
,
rtab
[]
uint32
,
cellLog
int
,
mtu
uint32
,
linklayer
int
)
int
{
func
CalcRtable
(
rate
*
nl
.
TcRateSpec
,
rtab
[
256
]
uint32
,
cellLog
int
,
mtu
uint32
,
linklayer
int
)
int
{
bps
:=
rate
.
Rate
mpu
:=
rate
.
Mpu
var
sz
uint
...
...
vendor/github.com/vishvananda/netlink/fou.go
deleted
100644 → 0
View file @
d1111a57
package
netlink
import
(
"errors"
)
var
(
// ErrAttrHeaderTruncated is returned when a netlink attribute's header is
// truncated.
ErrAttrHeaderTruncated
=
errors
.
New
(
"attribute header truncated"
)
// ErrAttrBodyTruncated is returned when a netlink attribute's body is
// truncated.
ErrAttrBodyTruncated
=
errors
.
New
(
"attribute body truncated"
)
)
type
Fou
struct
{
Family
int
Port
int
Protocol
int
EncapType
int
}
vendor/github.com/vishvananda/netlink/fou_linux.go
deleted
100644 → 0
View file @
d1111a57
// +build linux
package
netlink
import
(
"encoding/binary"
"errors"
"github.com/vishvananda/netlink/nl"
"golang.org/x/sys/unix"
)
const
(
FOU_GENL_NAME
=
"fou"
)
const
(
FOU_CMD_UNSPEC
uint8
=
iota
FOU_CMD_ADD
FOU_CMD_DEL
FOU_CMD_GET
FOU_CMD_MAX
=
FOU_CMD_GET
)
const
(
FOU_ATTR_UNSPEC
=
iota
FOU_ATTR_PORT
FOU_ATTR_AF
FOU_ATTR_IPPROTO
FOU_ATTR_TYPE
FOU_ATTR_REMCSUM_NOPARTIAL
FOU_ATTR_MAX
=
FOU_ATTR_REMCSUM_NOPARTIAL
)
const
(
FOU_ENCAP_UNSPEC
=
iota
FOU_ENCAP_DIRECT
FOU_ENCAP_GUE
FOU_ENCAP_MAX
=
FOU_ENCAP_GUE
)
var
fouFamilyId
int
func
FouFamilyId
()
(
int
,
error
)
{
if
fouFamilyId
!=
0
{
return
fouFamilyId
,
nil
}
fam
,
err
:=
GenlFamilyGet
(
FOU_GENL_NAME
)
if
err
!=
nil
{
return
-
1
,
err
}
fouFamilyId
=
int
(
fam
.
ID
)
return
fouFamilyId
,
nil
}
func
FouAdd
(
f
Fou
)
error
{
return
pkgHandle
.
FouAdd
(
f
)
}
func
(
h
*
Handle
)
FouAdd
(
f
Fou
)
error
{
fam_id
,
err
:=
FouFamilyId
()
if
err
!=
nil
{
return
err
}
// setting ip protocol conflicts with encapsulation type GUE
if
f
.
EncapType
==
FOU_ENCAP_GUE
&&
f
.
Protocol
!=
0
{
return
errors
.
New
(
"GUE encapsulation doesn't specify an IP protocol"
)
}
req
:=
h
.
newNetlinkRequest
(
fam_id
,
unix
.
NLM_F_ACK
)
// int to byte for port
bp
:=
make
([]
byte
,
2
)
binary
.
BigEndian
.
PutUint16
(
bp
[
0
:
2
],
uint16
(
f
.
Port
))
attrs
:=
[]
*
nl
.
RtAttr
{
nl
.
NewRtAttr
(
FOU_ATTR_PORT
,
bp
),
nl
.
NewRtAttr
(
FOU_ATTR_TYPE
,
[]
byte
{
uint8
(
f
.
EncapType
)}),
nl
.
NewRtAttr
(
FOU_ATTR_AF
,
[]
byte
{
uint8
(
f
.
Family
)}),
nl
.
NewRtAttr
(
FOU_ATTR_IPPROTO
,
[]
byte
{
uint8
(
f
.
Protocol
)}),
}
raw
:=
[]
byte
{
FOU_CMD_ADD
,
1
,
0
,
0
}
for
_
,
a
:=
range
attrs
{
raw
=
append
(
raw
,
a
.
Serialize
()
...
)
}
req
.
AddRawData
(
raw
)
_
,
err
=
req
.
Execute
(
unix
.
NETLINK_GENERIC
,
0
)
if
err
!=
nil
{
return
err
}
return
nil
}
func
FouDel
(
f
Fou
)
error
{
return
pkgHandle
.
FouDel
(
f
)
}
func
(
h
*
Handle
)
FouDel
(
f
Fou
)
error
{
fam_id
,
err
:=
FouFamilyId
()
if
err
!=
nil
{
return
err
}
req
:=
h
.
newNetlinkRequest
(
fam_id
,
unix
.
NLM_F_ACK
)
// int to byte for port
bp
:=
make
([]
byte
,
2
)
binary
.
BigEndian
.
PutUint16
(
bp
[
0
:
2
],
uint16
(
f
.
Port
))
attrs
:=
[]
*
nl
.
RtAttr
{
nl
.
NewRtAttr
(
FOU_ATTR_PORT
,
bp
),
nl
.
NewRtAttr
(
FOU_ATTR_AF
,
[]
byte
{
uint8
(
f
.
Family
)}),
}
raw
:=
[]
byte
{
FOU_CMD_DEL
,
1
,
0
,
0
}
for
_
,
a
:=
range
attrs
{
raw
=
append
(
raw
,
a
.
Serialize
()
...
)
}
req
.
AddRawData
(
raw
)
_
,
err
=
req
.
Execute
(
unix
.
NETLINK_GENERIC
,
0
)
if
err
!=
nil
{
return
err
}
return
nil
}
func
FouList
(
fam
int
)
([]
Fou
,
error
)
{
return
pkgHandle
.
FouList
(
fam
)
}
func
(
h
*
Handle
)
FouList
(
fam
int
)
([]
Fou
,
error
)
{
fam_id
,
err
:=
FouFamilyId
()
if
err
!=
nil
{
return
nil
,
err
}
req
:=
h
.
newNetlinkRequest
(
fam_id
,
unix
.
NLM_F_DUMP
)
attrs
:=
[]
*
nl
.
RtAttr
{
nl
.
NewRtAttr
(
FOU_ATTR_AF
,
[]
byte
{
uint8
(
fam
)}),
}
raw
:=
[]
byte
{
FOU_CMD_GET
,
1
,
0
,
0
}
for
_
,
a
:=
range
attrs
{
raw
=
append
(
raw
,
a
.
Serialize
()
...
)
}
req
.
AddRawData
(
raw
)
msgs
,
err
:=
req
.
Execute
(
unix
.
NETLINK_GENERIC
,
0
)
if
err
!=
nil
{
return
nil
,
err
}
fous
:=
make
([]
Fou
,
0
,
len
(
msgs
))
for
_
,
m
:=
range
msgs
{
f
,
err
:=
deserializeFouMsg
(
m
)
if
err
!=
nil
{
return
fous
,
err
}
fous
=
append
(
fous
,
f
)
}
return
fous
,
nil
}
func
deserializeFouMsg
(
msg
[]
byte
)
(
Fou
,
error
)
{
// we'll skip to byte 4 to first attribute
msg
=
msg
[
3
:
]
var
shift
int
fou
:=
Fou
{}
for
{
// attribute header is at least 16 bits
if
len
(
msg
)
<
4
{
return
fou
,
ErrAttrHeaderTruncated
}
lgt
:=
int
(
binary
.
BigEndian
.
Uint16
(
msg
[
0
:
2
]))
if
len
(
msg
)
<
lgt
+
4
{
return
fou
,
ErrAttrBodyTruncated
}
attr
:=
binary
.
BigEndian
.
Uint16
(
msg
[
2
:
4
])
shift
=
lgt
+
3
switch
attr
{
case
FOU_ATTR_AF
:
fou
.
Family
=
int
(
msg
[
5
])
case
FOU_ATTR_PORT
:
fou
.
Port
=
int
(
binary
.
BigEndian
.
Uint16
(
msg
[
5
:
7
]))
// port is 2 bytes
shift
=
lgt
+
2
case
FOU_ATTR_IPPROTO
:
fou
.
Protocol
=
int
(
msg
[
5
])
case
FOU_ATTR_TYPE
:
fou
.
EncapType
=
int
(
msg
[
5
])
}
msg
=
msg
[
shift
:
]
if
len
(
msg
)
<
4
{
break
}
}
return
fou
,
nil
}
vendor/github.com/vishvananda/netlink/fou_unspecified.go
deleted
100644 → 0
View file @
d1111a57
// +build !linux
package
netlink
func
FouAdd
(
f
Fou
)
error
{
return
ErrNotImplemented
}
func
FouDel
(
f
Fou
)
error
{
return
ErrNotImplemented
}
func
FouList
(
fam
int
)
([]
Fou
,
error
)
{
return
nil
,
ErrNotImplemented
}
vendor/github.com/vishvananda/netlink/genetlink_linux.go
View file @
7517f6ba
...
...
@@ -5,7 +5,6 @@ import (
"syscall"
"github.com/vishvananda/netlink/nl"
"golang.org/x/sys/unix"
)
type
GenlOp
struct
{
...
...
@@ -131,9 +130,9 @@ func (h *Handle) GenlFamilyList() ([]*GenlFamily, error) {
Command
:
nl
.
GENL_CTRL_CMD_GETFAMILY
,
Version
:
nl
.
GENL_CTRL_VERSION
,
}
req
:=
h
.
newNetlinkRequest
(
nl
.
GENL_ID_CTRL
,
unix
.
NLM_F_DUMP
)
req
:=
h
.
newNetlinkRequest
(
nl
.
GENL_ID_CTRL
,
syscall
.
NLM_F_DUMP
)
req
.
AddData
(
msg
)
msgs
,
err
:=
req
.
Execute
(
unix
.
NETLINK_GENERIC
,
0
)
msgs
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_GENERIC
,
0
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -152,7 +151,7 @@ func (h *Handle) GenlFamilyGet(name string) (*GenlFamily, error) {
req
:=
h
.
newNetlinkRequest
(
nl
.
GENL_ID_CTRL
,
0
)
req
.
AddData
(
msg
)
req
.
AddData
(
nl
.
NewRtAttr
(
nl
.
GENL_CTRL_ATTR_FAMILY_NAME
,
nl
.
ZeroTerminated
(
name
)))
msgs
,
err
:=
req
.
Execute
(
unix
.
NETLINK_GENERIC
,
0
)
msgs
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_GENERIC
,
0
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
vendor/github.com/vishvananda/netlink/gtp_linux.go
View file @
7517f6ba
...
...
@@ -7,7 +7,6 @@ import (
"syscall"
"github.com/vishvananda/netlink/nl"
"golang.org/x/sys/unix"
)
type
PDP
struct
{
...
...
@@ -83,9 +82,9 @@ func (h *Handle) GTPPDPList() ([]*PDP, error) {
Command
:
nl
.
GENL_GTP_CMD_GETPDP
,
Version
:
nl
.
GENL_GTP_VERSION
,
}
req
:=
h
.
newNetlinkRequest
(
int
(
f
.
ID
),
unix
.
NLM_F_DUMP
)
req
:=
h
.
newNetlinkRequest
(
int
(
f
.
ID
),
syscall
.
NLM_F_DUMP
)
req
.
AddData
(
msg
)
msgs
,
err
:=
req
.
Execute
(
unix
.
NETLINK_GENERIC
,
0
)
msgs
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_GENERIC
,
0
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -97,7 +96,7 @@ func GTPPDPList() ([]*PDP, error) {
}
func
gtpPDPGet
(
req
*
nl
.
NetlinkRequest
)
(
*
PDP
,
error
)
{
msgs
,
err
:=
req
.
Execute
(
unix
.
NETLINK_GENERIC
,
0
)
msgs
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_GENERIC
,
0
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -183,7 +182,7 @@ func (h *Handle) GTPPDPAdd(link Link, pdp *PDP) error {
Command
:
nl
.
GENL_GTP_CMD_NEWPDP
,
Version
:
nl
.
GENL_GTP_VERSION
,
}
req
:=
h
.
newNetlinkRequest
(
int
(
f
.
ID
),
unix
.
NLM_F_EXCL
|
unix
.
NLM_F_ACK
)
req
:=
h
.
newNetlinkRequest
(
int
(
f
.
ID
),
syscall
.
NLM_F_EXCL
|
syscall
.
NLM_F_ACK
)
req
.
AddData
(
msg
)
req
.
AddData
(
nl
.
NewRtAttr
(
nl
.
GENL_GTP_ATTR_VERSION
,
nl
.
Uint32Attr
(
pdp
.
Version
)))
req
.
AddData
(
nl
.
NewRtAttr
(
nl
.
GENL_GTP_ATTR_LINK
,
nl
.
Uint32Attr
(
uint32
(
link
.
Attrs
()
.
Index
))))
...
...
@@ -200,7 +199,7 @@ func (h *Handle) GTPPDPAdd(link Link, pdp *PDP) error {
default
:
return
fmt
.
Errorf
(
"unsupported GTP version: %d"
,
pdp
.
Version
)
}
_
,
err
=
req
.
Execute
(
unix
.
NETLINK_GENERIC
,
0
)
_
,
err
=
req
.
Execute
(
syscall
.
NETLINK_GENERIC
,
0
)
return
err
}
...
...
@@ -217,7 +216,7 @@ func (h *Handle) GTPPDPDel(link Link, pdp *PDP) error {
Command
:
nl
.
GENL_GTP_CMD_DELPDP
,
Version
:
nl
.
GENL_GTP_VERSION
,
}
req
:=
h
.
newNetlinkRequest
(
int
(
f
.
ID
),
unix
.
NLM_F_EXCL
|
unix
.
NLM_F_ACK
)
req
:=
h
.
newNetlinkRequest
(
int
(
f
.
ID
),
syscall
.
NLM_F_EXCL
|
syscall
.
NLM_F_ACK
)
req
.
AddData
(
msg
)
req
.
AddData
(
nl
.
NewRtAttr
(
nl
.
GENL_GTP_ATTR_VERSION
,
nl
.
Uint32Attr
(
pdp
.
Version
)))
req
.
AddData
(
nl
.
NewRtAttr
(
nl
.
GENL_GTP_ATTR_LINK
,
nl
.
Uint32Attr
(
uint32
(
link
.
Attrs
()
.
Index
))))
...
...
@@ -230,7 +229,7 @@ func (h *Handle) GTPPDPDel(link Link, pdp *PDP) error {
default
:
return
fmt
.
Errorf
(
"unsupported GTP version: %d"
,
pdp
.
Version
)
}
_
,
err
=
req
.
Execute
(
unix
.
NETLINK_GENERIC
,
0
)
_
,
err
=
req
.
Execute
(
syscall
.
NETLINK_GENERIC
,
0
)
return
err
}
...
...
vendor/github.com/vishvananda/netlink/handle_linux.go
View file @
7517f6ba
...
...
@@ -2,11 +2,11 @@ package netlink
import
(
"fmt"
"syscall"
"time"
"github.com/vishvananda/netlink/nl"
"github.com/vishvananda/netns"
"golang.org/x/sys/unix"
)
// Empty handle used by the netlink package methods
...
...
@@ -43,7 +43,7 @@ func (h *Handle) SetSocketTimeout(to time.Duration) error {
if
to
<
time
.
Microsecond
{
return
fmt
.
Errorf
(
"invalid timeout, minimul value is %s"
,
time
.
Microsecond
)
}
tv
:=
unix
.
NsecToTimeval
(
to
.
Nanoseconds
())
tv
:=
syscall
.
NsecToTimeval
(
to
.
Nanoseconds
())
for
_
,
sh
:=
range
h
.
sockets
{
if
err
:=
sh
.
Socket
.
SetSendTimeout
(
&
tv
);
err
!=
nil
{
return
err
...
...
@@ -59,13 +59,13 @@ func (h *Handle) SetSocketTimeout(to time.Duration) error {
// socket in the netlink handle. The maximum value is capped by
// /proc/sys/net/core/rmem_max.
func
(
h
*
Handle
)
SetSocketReceiveBufferSize
(
size
int
,
force
bool
)
error
{
opt
:=
unix
.
SO_RCVBUF
opt
:=
syscall
.
SO_RCVBUF
if
force
{
opt
=
unix
.
SO_RCVBUFFORCE
opt
=
syscall
.
SO_RCVBUFFORCE
}
for
_
,
sh
:=
range
h
.
sockets
{
fd
:=
sh
.
Socket
.
GetFd
()
err
:=
unix
.
SetsockoptInt
(
fd
,
unix
.
SOL_SOCKET
,
opt
,
size
)
err
:=
syscall
.
SetsockoptInt
(
fd
,
syscall
.
SOL_SOCKET
,
opt
,
size
)
if
err
!=
nil
{
return
err
}
...
...
@@ -81,7 +81,7 @@ func (h *Handle) GetSocketReceiveBufferSize() ([]int, error) {
i
:=
0
for
_
,
sh
:=
range
h
.
sockets
{
fd
:=
sh
.
Socket
.
GetFd
()
size
,
err
:=
unix
.
GetsockoptInt
(
fd
,
unix
.
SOL_SOCKET
,
unix
.
SO_RCVBUF
)
size
,
err
:=
syscall
.
GetsockoptInt
(
fd
,
syscall
.
SOL_SOCKET
,
syscall
.
SO_RCVBUF
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -134,10 +134,10 @@ func (h *Handle) newNetlinkRequest(proto, flags int) *nl.NetlinkRequest {
return
nl
.
NewNetlinkRequest
(
proto
,
flags
)
}
return
&
nl
.
NetlinkRequest
{
NlMsghdr
:
unix
.
NlMsghdr
{
Len
:
uint32
(
unix
.
SizeofNlMsghdr
),
NlMsghdr
:
syscall
.
NlMsghdr
{
Len
:
uint32
(
syscall
.
SizeofNlMsghdr
),
Type
:
uint16
(
proto
),
Flags
:
unix
.
NLM_F_REQUEST
|
uint16
(
flags
),
Flags
:
syscall
.
NLM_F_REQUEST
|
uint16
(
flags
),
},
Sockets
:
h
.
sockets
,
}
...
...
vendor/github.com/vishvananda/netlink/link.go
View file @
7517f6ba
...
...
@@ -3,7 +3,6 @@ package netlink
import
(
"fmt"
"net"
"os"
)
// Link represents a link device from netlink. Shared link attributes
...
...
@@ -39,8 +38,6 @@ type LinkAttrs struct {
Protinfo
*
Protinfo
OperState
LinkOperState
NetNsID
int
NumTxQueues
int
NumRxQueues
int
}
// LinkOperState represents the values of the IFLA_OPERSTATE link
...
...
@@ -262,9 +259,6 @@ const (
type
Macvlan
struct
{
LinkAttrs
Mode
MacvlanMode
// MACAddrs is only populated for Macvlan SOURCE links
MACAddrs
[]
net
.
HardwareAddr
}
func
(
macvlan
*
Macvlan
)
Attrs
()
*
LinkAttrs
{
...
...
@@ -290,10 +284,8 @@ type TuntapFlag uint16
// Tuntap links created via /dev/tun/tap, but can be destroyed via netlink
type
Tuntap
struct
{
LinkAttrs
Mode
TuntapMode
Flags
TuntapFlag
Queues
int
Fds
[]
*
os
.
File
Mode
TuntapMode
Flags
TuntapFlag
}
func
(
tuntap
*
Tuntap
)
Attrs
()
*
LinkAttrs
{
...
...
@@ -335,28 +327,26 @@ func (generic *GenericLink) Type() string {
type
Vxlan
struct
{
LinkAttrs
VxlanId
int
VtepDevIndex
int
SrcAddr
net
.
IP
Group
net
.
IP
TTL
int
TOS
int
Learning
bool
Proxy
bool
RSC
bool
L2miss
bool
L3miss
bool
UDPCSum
bool
UDP6ZeroCSumTx
bool
UDP6ZeroCSumRx
bool
NoAge
bool
GBP
bool
FlowBased
bool
Age
int
Limit
int
Port
int
PortLow
int
PortHigh
int
VxlanId
int
VtepDevIndex
int
SrcAddr
net
.
IP
Group
net
.
IP
TTL
int
TOS
int
Learning
bool
Proxy
bool
RSC
bool
L2miss
bool
L3miss
bool
UDPCSum
bool
NoAge
bool
GBP
bool
FlowBased
bool
Age
int
Limit
int
Port
int
PortLow
int
PortHigh
int
}
func
(
vxlan
*
Vxlan
)
Attrs
()
*
LinkAttrs
{
...
...
@@ -710,17 +700,12 @@ func (gretap *Gretap) Type() string {
type
Iptun
struct
{
LinkAttrs
Ttl
uint8
Tos
uint8
PMtuDisc
uint8
Link
uint32
Local
net
.
IP
Remote
net
.
IP
EncapSport
uint16
EncapDport
uint16
EncapType
uint16
EncapFlags
uint16
FlowBased
bool
Ttl
uint8
Tos
uint8
PMtuDisc
uint8
Link
uint32
Local
net
.
IP
Remote
net
.
IP
}
func
(
iptun
*
Iptun
)
Attrs
()
*
LinkAttrs
{
...
...
@@ -731,28 +716,6 @@ func (iptun *Iptun) Type() string {
return
"ipip"
}
type
Sittun
struct
{
LinkAttrs
Link
uint32
Local
net
.
IP
Remote
net
.
IP
Ttl
uint8
Tos
uint8
PMtuDisc
uint8
EncapType
uint16
EncapFlags
uint16
EncapSport
uint16
EncapDport
uint16
}
func
(
sittun
*
Sittun
)
Attrs
()
*
LinkAttrs
{
return
&
sittun
.
LinkAttrs
}
func
(
sittun
*
Sittun
)
Type
()
string
{
return
"sit"
}
type
Vti
struct
{
LinkAttrs
IKey
uint32
...
...
@@ -772,20 +735,16 @@ func (iptun *Vti) Type() string {
type
Gretun
struct
{
LinkAttrs
Link
uint32
IFlags
uint16
OFlags
uint16
IKey
uint32
OKey
uint32
Local
net
.
IP
Remote
net
.
IP
Ttl
uint8
Tos
uint8
PMtuDisc
uint8
EncapType
uint16
EncapFlags
uint16
EncapSport
uint16
EncapDport
uint16
Link
uint32
IFlags
uint16
OFlags
uint16
IKey
uint32
OKey
uint32
Local
net
.
IP
Remote
net
.
IP
Ttl
uint8
Tos
uint8
PMtuDisc
uint8
}
func
(
gretun
*
Gretun
)
Attrs
()
*
LinkAttrs
{
...
...
vendor/github.com/vishvananda/netlink/link_linux.go
View file @
7517f6ba
This diff is collapsed.
Click to expand it.
vendor/github.com/vishvananda/netlink/neigh.go
View file @
7517f6ba
...
...
@@ -15,8 +15,6 @@ type Neigh struct {
IP
net
.
IP
HardwareAddr
net
.
HardwareAddr
LLIPAddr
net
.
IP
//Used in the case of NHRP
Vlan
int
VNI
int
}
// String returns $ip/$hwaddr $label
...
...
vendor/github.com/vishvananda/netlink/neigh_linux.go
View file @
7517f6ba
...
...
@@ -2,10 +2,10 @@ package netlink
import
(
"net"
"syscall"
"unsafe"
"github.com/vishvananda/netlink/nl"
"golang.org/x/sys/unix"
)
const
(
...
...
@@ -73,7 +73,7 @@ func NeighAdd(neigh *Neigh) error {
// NeighAdd will add an IP to MAC mapping to the ARP table
// Equivalent to: `ip neigh add ....`
func
(
h
*
Handle
)
NeighAdd
(
neigh
*
Neigh
)
error
{
return
h
.
neighAdd
(
neigh
,
unix
.
NLM_F_CREATE
|
unix
.
NLM_F_EXCL
)
return
h
.
neighAdd
(
neigh
,
syscall
.
NLM_F_CREATE
|
syscall
.
NLM_F_EXCL
)
}
// NeighSet will add or replace an IP to MAC mapping to the ARP table
...
...
@@ -85,7 +85,7 @@ func NeighSet(neigh *Neigh) error {
// NeighSet will add or replace an IP to MAC mapping to the ARP table
// Equivalent to: `ip neigh replace....`
func
(
h
*
Handle
)
NeighSet
(
neigh
*
Neigh
)
error
{
return
h
.
neighAdd
(
neigh
,
unix
.
NLM_F_CREATE
|
unix
.
NLM_F_REPLACE
)
return
h
.
neighAdd
(
neigh
,
syscall
.
NLM_F_CREATE
|
syscall
.
NLM_F_REPLACE
)
}
// NeighAppend will append an entry to FDB
...
...
@@ -97,7 +97,7 @@ func NeighAppend(neigh *Neigh) error {
// NeighAppend will append an entry to FDB
// Equivalent to: `bridge fdb append...`
func
(
h
*
Handle
)
NeighAppend
(
neigh
*
Neigh
)
error
{
return
h
.
neighAdd
(
neigh
,
unix
.
NLM_F_CREATE
|
unix
.
NLM_F_APPEND
)
return
h
.
neighAdd
(
neigh
,
syscall
.
NLM_F_CREATE
|
syscall
.
NLM_F_APPEND
)
}
// NeighAppend will append an entry to FDB
...
...
@@ -109,7 +109,7 @@ func neighAdd(neigh *Neigh, mode int) error {
// NeighAppend will append an entry to FDB
// Equivalent to: `bridge fdb append...`
func
(
h
*
Handle
)
neighAdd
(
neigh
*
Neigh
,
mode
int
)
error
{
req
:=
h
.
newNetlinkRequest
(
unix
.
RTM_NEWNEIGH
,
mode
|
unix
.
NLM_F_ACK
)
req
:=
h
.
newNetlinkRequest
(
syscall
.
RTM_NEWNEIGH
,
mode
|
syscall
.
NLM_F_ACK
)
return
neighHandle
(
neigh
,
req
)
}
...
...
@@ -122,7 +122,7 @@ func NeighDel(neigh *Neigh) error {
// NeighDel will delete an IP address from a link device.
// Equivalent to: `ip addr del $addr dev $link`
func
(
h
*
Handle
)
NeighDel
(
neigh
*
Neigh
)
error
{
req
:=
h
.
newNetlinkRequest
(
unix
.
RTM_DELNEIGH
,
unix
.
NLM_F_ACK
)
req
:=
h
.
newNetlinkRequest
(
syscall
.
RTM_DELNEIGH
,
syscall
.
NLM_F_ACK
)
return
neighHandle
(
neigh
,
req
)
}
...
...
@@ -160,17 +160,7 @@ func neighHandle(neigh *Neigh, req *nl.NetlinkRequest) error {
req
.
AddData
(
hwData
)
}
if
neigh
.
Vlan
!=
0
{
vlanData
:=
nl
.
NewRtAttr
(
NDA_VLAN
,
nl
.
Uint16Attr
(
uint16
(
neigh
.
Vlan
)))
req
.
AddData
(
vlanData
)
}
if
neigh
.
VNI
!=
0
{
vniData
:=
nl
.
NewRtAttr
(
NDA_VNI
,
nl
.
Uint32Attr
(
uint32
(
neigh
.
VNI
)))
req
.
AddData
(
vniData
)
}
_
,
err
:=
req
.
Execute
(
unix
.
NETLINK_ROUTE
,
0
)
_
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_ROUTE
,
0
)
return
err
}
...
...
@@ -203,7 +193,7 @@ func (h *Handle) NeighProxyList(linkIndex, family int) ([]Neigh, error) {
}
func
(
h
*
Handle
)
neighList
(
linkIndex
,
family
,
flags
int
)
([]
Neigh
,
error
)
{
req
:=
h
.
newNetlinkRequest
(
unix
.
RTM_GETNEIGH
,
unix
.
NLM_F_DUMP
)
req
:=
h
.
newNetlinkRequest
(
syscall
.
RTM_GETNEIGH
,
syscall
.
NLM_F_DUMP
)
msg
:=
Ndmsg
{
Family
:
uint8
(
family
),
Index
:
uint32
(
linkIndex
),
...
...
@@ -211,7 +201,7 @@ func (h *Handle) neighList(linkIndex, family, flags int) ([]Neigh, error) {
}
req
.
AddData
(
&
msg
)
msgs
,
err
:=
req
.
Execute
(
unix
.
NETLINK_ROUTE
,
unix
.
RTM_NEWNEIGH
)
msgs
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_ROUTE
,
syscall
.
RTM_NEWNEIGH
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -267,7 +257,7 @@ func NeighDeserialize(m []byte) (*Neigh, error) {
// BUG: Is this a bug in the netlink library?
// #define RTA_LENGTH(len) (RTA_ALIGN(sizeof(struct rtattr)) + (len))
// #define RTA_PAYLOAD(rta) ((int)((rta)->rta_len) - RTA_LENGTH(0))
attrLen
:=
attr
.
Attr
.
Len
-
unix
.
SizeofRtAttr
attrLen
:=
attr
.
Attr
.
Len
-
syscall
.
SizeofRtAttr
if
attrLen
==
4
&&
(
encapType
==
"ipip"
||
encapType
==
"sit"
||
encapType
==
"gre"
)
{
...
...
@@ -278,10 +268,6 @@ func NeighDeserialize(m []byte) (*Neigh, error) {
}
else
{
neigh
.
HardwareAddr
=
net
.
HardwareAddr
(
attr
.
Value
)
}
case
NDA_VLAN
:
neigh
.
Vlan
=
int
(
native
.
Uint16
(
attr
.
Value
[
0
:
2
]))
case
NDA_VNI
:
neigh
.
VNI
=
int
(
native
.
Uint32
(
attr
.
Value
[
0
:
4
]))
}
}
...
...
vendor/github.com/vishvananda/netlink/nl/BUILD
View file @
7517f6ba
...
...
@@ -12,7 +12,6 @@ go_library(
"nl_linux.go",
"nl_unspecified.go",
"route_linux.go",
"seg6_linux.go",
"syscall.go",
"tc_linux.go",
"xfrm_linux.go",
...
...
@@ -26,7 +25,6 @@ go_library(
deps = select({
"@io_bazel_rules_go//go/platform:linux": [
"//vendor/github.com/vishvananda/netns:go_default_library",
"//vendor/golang.org/x/sys/unix:go_default_library",
],
"//conditions:default": [],
}),
...
...
vendor/github.com/vishvananda/netlink/nl/addr_linux.go
View file @
7517f6ba
package
nl
import
(
"syscall"
"unsafe"
"golang.org/x/sys/unix"
)
type
IfAddrmsg
struct
{
unix
.
IfAddrmsg
syscall
.
IfAddrmsg
}
func
NewIfAddrmsg
(
family
int
)
*
IfAddrmsg
{
return
&
IfAddrmsg
{
IfAddrmsg
:
unix
.
IfAddrmsg
{
IfAddrmsg
:
syscall
.
IfAddrmsg
{
Family
:
uint8
(
family
),
},
}
...
...
@@ -36,15 +35,15 @@ func NewIfAddrmsg(family int) *IfAddrmsg {
// SizeofIfAddrmsg = 0x8
func
DeserializeIfAddrmsg
(
b
[]
byte
)
*
IfAddrmsg
{
return
(
*
IfAddrmsg
)(
unsafe
.
Pointer
(
&
b
[
0
:
unix
.
SizeofIfAddrmsg
][
0
]))
return
(
*
IfAddrmsg
)(
unsafe
.
Pointer
(
&
b
[
0
:
syscall
.
SizeofIfAddrmsg
][
0
]))
}
func
(
msg
*
IfAddrmsg
)
Serialize
()
[]
byte
{
return
(
*
(
*
[
unix
.
SizeofIfAddrmsg
]
byte
)(
unsafe
.
Pointer
(
msg
)))[
:
]
return
(
*
(
*
[
syscall
.
SizeofIfAddrmsg
]
byte
)(
unsafe
.
Pointer
(
msg
)))[
:
]
}
func
(
msg
*
IfAddrmsg
)
Len
()
int
{
return
unix
.
SizeofIfAddrmsg
return
syscall
.
SizeofIfAddrmsg
}
// struct ifa_cacheinfo {
...
...
vendor/github.com/vishvananda/netlink/nl/link_linux.go
View file @
7517f6ba
package
nl
import
(
"syscall"
"unsafe"
"golang.org/x/sys/unix"
)
const
(
DEFAULT_CHANGE
=
0xFFFFFFFF
// doesn't exist in syscall
IFLA_VFINFO_LIST
=
unix
.
IFLA_IFALIAS
+
1
+
iota
IFLA_VFINFO_LIST
=
syscall
.
IFLA_IFALIAS
+
1
+
iota
IFLA_STATS64
IFLA_VF_PORTS
IFLA_PORT_SELF
...
...
@@ -119,10 +118,6 @@ const (
IFLA_MACVLAN_UNSPEC
=
iota
IFLA_MACVLAN_MODE
IFLA_MACVLAN_FLAGS
IFLA_MACVLAN_MACADDR_MODE
IFLA_MACVLAN_MACADDR
IFLA_MACVLAN_MACADDR_DATA
IFLA_MACVLAN_MACADDR_COUNT
IFLA_MACVLAN_MAX
=
IFLA_MACVLAN_FLAGS
)
...
...
@@ -135,13 +130,6 @@ const (
)
const
(
MACVLAN_MACADDR_ADD
=
iota
MACVLAN_MACADDR_DEL
MACVLAN_MACADDR_FLUSH
MACVLAN_MACADDR_SET
)
const
(
IFLA_BOND_UNSPEC
=
iota
IFLA_BOND_MODE
IFLA_BOND_ACTIVE_SLAVE
...
...
@@ -487,12 +475,7 @@ const (
IFLA_IPTUN_6RD_RELAY_PREFIX
IFLA_IPTUN_6RD_PREFIXLEN
IFLA_IPTUN_6RD_RELAY_PREFIXLEN
IFLA_IPTUN_ENCAP_TYPE
IFLA_IPTUN_ENCAP_FLAGS
IFLA_IPTUN_ENCAP_SPORT
IFLA_IPTUN_ENCAP_DPORT
IFLA_IPTUN_COLLECT_METADATA
IFLA_IPTUN_MAX
=
IFLA_IPTUN_COLLECT_METADATA
IFLA_IPTUN_MAX
=
IFLA_IPTUN_6RD_RELAY_PREFIXLEN
)
const
(
...
...
vendor/github.com/vishvananda/netlink/nl/nl_linux.go
View file @
7517f6ba
This diff is collapsed.
Click to expand it.
vendor/github.com/vishvananda/netlink/nl/route_linux.go
View file @
7517f6ba
package
nl
import
(
"syscall"
"unsafe"
"golang.org/x/sys/unix"
)
type
RtMsg
struct
{
unix
.
RtMsg
syscall
.
RtMsg
}
func
NewRtMsg
()
*
RtMsg
{
return
&
RtMsg
{
RtMsg
:
unix
.
RtMsg
{
Table
:
unix
.
RT_TABLE_MAIN
,
Scope
:
unix
.
RT_SCOPE_UNIVERSE
,
Protocol
:
unix
.
RTPROT_BOOT
,
Type
:
unix
.
RTN_UNICAST
,
RtMsg
:
syscall
.
RtMsg
{
Table
:
syscall
.
RT_TABLE_MAIN
,
Scope
:
syscall
.
RT_SCOPE_UNIVERSE
,
Protocol
:
syscall
.
RTPROT_BOOT
,
Type
:
syscall
.
RTN_UNICAST
,
},
}
}
func
NewRtDelMsg
()
*
RtMsg
{
return
&
RtMsg
{
RtMsg
:
unix
.
RtMsg
{
Table
:
unix
.
RT_TABLE_MAIN
,
Scope
:
unix
.
RT_SCOPE_NOWHERE
,
RtMsg
:
syscall
.
RtMsg
{
Table
:
syscall
.
RT_TABLE_MAIN
,
Scope
:
syscall
.
RT_SCOPE_NOWHERE
,
},
}
}
func
(
msg
*
RtMsg
)
Len
()
int
{
return
unix
.
SizeofRtMsg
return
syscall
.
SizeofRtMsg
}
func
DeserializeRtMsg
(
b
[]
byte
)
*
RtMsg
{
return
(
*
RtMsg
)(
unsafe
.
Pointer
(
&
b
[
0
:
unix
.
SizeofRtMsg
][
0
]))
return
(
*
RtMsg
)(
unsafe
.
Pointer
(
&
b
[
0
:
syscall
.
SizeofRtMsg
][
0
]))
}
func
(
msg
*
RtMsg
)
Serialize
()
[]
byte
{
return
(
*
(
*
[
unix
.
SizeofRtMsg
]
byte
)(
unsafe
.
Pointer
(
msg
)))[
:
]
return
(
*
(
*
[
syscall
.
SizeofRtMsg
]
byte
)(
unsafe
.
Pointer
(
msg
)))[
:
]
}
type
RtNexthop
struct
{
unix
.
RtNexthop
syscall
.
RtNexthop
Children
[]
NetlinkRequestData
}
func
DeserializeRtNexthop
(
b
[]
byte
)
*
RtNexthop
{
return
(
*
RtNexthop
)(
unsafe
.
Pointer
(
&
b
[
0
:
unix
.
SizeofRtNexthop
][
0
]))
return
(
*
RtNexthop
)(
unsafe
.
Pointer
(
&
b
[
0
:
syscall
.
SizeofRtNexthop
][
0
]))
}
func
(
msg
*
RtNexthop
)
Len
()
int
{
if
len
(
msg
.
Children
)
==
0
{
return
unix
.
SizeofRtNexthop
return
syscall
.
SizeofRtNexthop
}
l
:=
0
for
_
,
child
:=
range
msg
.
Children
{
l
+=
rtaAlignOf
(
child
.
Len
())
}
l
+=
unix
.
SizeofRtNexthop
l
+=
syscall
.
SizeofRtNexthop
return
rtaAlignOf
(
l
)
}
...
...
@@ -68,8 +67,8 @@ func (msg *RtNexthop) Serialize() []byte {
length
:=
msg
.
Len
()
msg
.
RtNexthop
.
Len
=
uint16
(
length
)
buf
:=
make
([]
byte
,
length
)
copy
(
buf
,
(
*
(
*
[
unix
.
SizeofRtNexthop
]
byte
)(
unsafe
.
Pointer
(
msg
)))[
:
])
next
:=
rtaAlignOf
(
unix
.
SizeofRtNexthop
)
copy
(
buf
,
(
*
(
*
[
syscall
.
SizeofRtNexthop
]
byte
)(
unsafe
.
Pointer
(
msg
)))[
:
])
next
:=
rtaAlignOf
(
syscall
.
SizeofRtNexthop
)
if
len
(
msg
.
Children
)
>
0
{
for
_
,
child
:=
range
msg
.
Children
{
childBuf
:=
child
.
Serialize
()
...
...
vendor/github.com/vishvananda/netlink/nl/seg6_linux.go
deleted
100644 → 0
View file @
d1111a57
package
nl
import
(
"errors"
"fmt"
"net"
)
type
IPv6SrHdr
struct
{
nextHdr
uint8
hdrLen
uint8
routingType
uint8
segmentsLeft
uint8
firstSegment
uint8
flags
uint8
reserved
uint16
Segments
[]
net
.
IP
}
func
(
s1
*
IPv6SrHdr
)
Equal
(
s2
IPv6SrHdr
)
bool
{
if
len
(
s1
.
Segments
)
!=
len
(
s2
.
Segments
)
{
return
false
}
for
i
:=
range
s1
.
Segments
{
if
s1
.
Segments
[
i
]
.
Equal
(
s2
.
Segments
[
i
])
!=
true
{
return
false
}
}
return
s1
.
nextHdr
==
s2
.
nextHdr
&&
s1
.
hdrLen
==
s2
.
hdrLen
&&
s1
.
routingType
==
s2
.
routingType
&&
s1
.
segmentsLeft
==
s2
.
segmentsLeft
&&
s1
.
firstSegment
==
s2
.
firstSegment
&&
s1
.
flags
==
s2
.
flags
// reserved doesn't need to be identical.
}
// seg6 encap mode
const
(
SEG6_IPTUN_MODE_INLINE
=
iota
SEG6_IPTUN_MODE_ENCAP
)
// number of nested RTATTR
// from include/uapi/linux/seg6_iptunnel.h
const
(
SEG6_IPTUNNEL_UNSPEC
=
iota
SEG6_IPTUNNEL_SRH
__SEG6_IPTUNNEL_MAX
)
const
(
SEG6_IPTUNNEL_MAX
=
__SEG6_IPTUNNEL_MAX
-
1
)
func
EncodeSEG6Encap
(
mode
int
,
segments
[]
net
.
IP
)
([]
byte
,
error
)
{
nsegs
:=
len
(
segments
)
// nsegs: number of segments
if
nsegs
==
0
{
return
nil
,
errors
.
New
(
"EncodeSEG6Encap: No Segment in srh"
)
}
b
:=
make
([]
byte
,
12
,
12
+
len
(
segments
)
*
16
)
native
:=
NativeEndian
()
native
.
PutUint32
(
b
,
uint32
(
mode
))
b
[
4
]
=
0
// srh.nextHdr (0 when calling netlink)
b
[
5
]
=
uint8
(
16
*
nsegs
>>
3
)
// srh.hdrLen (in 8-octets unit)
b
[
6
]
=
IPV6_SRCRT_TYPE_4
// srh.routingType (assigned by IANA)
b
[
7
]
=
uint8
(
nsegs
-
1
)
// srh.segmentsLeft
b
[
8
]
=
uint8
(
nsegs
-
1
)
// srh.firstSegment
b
[
9
]
=
0
// srh.flags (SR6_FLAG1_HMAC for srh_hmac)
// srh.reserved: Defined as "Tag" in draft-ietf-6man-segment-routing-header-07
native
.
PutUint16
(
b
[
10
:
],
0
)
// srh.reserved
for
_
,
netIP
:=
range
segments
{
b
=
append
(
b
,
netIP
...
)
// srh.Segments
}
return
b
,
nil
}
func
DecodeSEG6Encap
(
buf
[]
byte
)
(
int
,
[]
net
.
IP
,
error
)
{
native
:=
NativeEndian
()
mode
:=
int
(
native
.
Uint32
(
buf
))
srh
:=
IPv6SrHdr
{
nextHdr
:
buf
[
4
],
hdrLen
:
buf
[
5
],
routingType
:
buf
[
6
],
segmentsLeft
:
buf
[
7
],
firstSegment
:
buf
[
8
],
flags
:
buf
[
9
],
reserved
:
native
.
Uint16
(
buf
[
10
:
12
]),
}
buf
=
buf
[
12
:
]
if
len
(
buf
)
%
16
!=
0
{
err
:=
fmt
.
Errorf
(
"DecodeSEG6Encap: error parsing Segment List (buf len: %d)
\n
"
,
len
(
buf
))
return
mode
,
nil
,
err
}
for
len
(
buf
)
>
0
{
srh
.
Segments
=
append
(
srh
.
Segments
,
net
.
IP
(
buf
[
:
16
]))
buf
=
buf
[
16
:
]
}
return
mode
,
srh
.
Segments
,
nil
}
// Helper functions
func
SEG6EncapModeString
(
mode
int
)
string
{
switch
mode
{
case
SEG6_IPTUN_MODE_INLINE
:
return
"inline"
case
SEG6_IPTUN_MODE_ENCAP
:
return
"encap"
}
return
"unknown"
}
vendor/github.com/vishvananda/netlink/nl/syscall.go
View file @
7517f6ba
...
...
@@ -65,14 +65,4 @@ const (
LWTUNNEL_ENCAP_IP
LWTUNNEL_ENCAP_ILA
LWTUNNEL_ENCAP_IP6
LWTUNNEL_ENCAP_SEG6
LWTUNNEL_ENCAP_BPF
)
// routing header types
const
(
IPV6_SRCRT_STRICT
=
0x01
// Deprecated; will be removed
IPV6_SRCRT_TYPE_0
=
0
// Deprecated; will be removed
IPV6_SRCRT_TYPE_2
=
2
// IPv6 type 2 Routing Header
IPV6_SRCRT_TYPE_4
=
4
// Segment Routing with IPv6
)
vendor/github.com/vishvananda/netlink/protinfo_linux.go
View file @
7517f6ba
...
...
@@ -5,7 +5,6 @@ import (
"syscall"
"github.com/vishvananda/netlink/nl"
"golang.org/x/sys/unix"
)
func
LinkGetProtinfo
(
link
Link
)
(
Protinfo
,
error
)
{
...
...
@@ -16,10 +15,10 @@ func (h *Handle) LinkGetProtinfo(link Link) (Protinfo, error) {
base
:=
link
.
Attrs
()
h
.
ensureIndex
(
base
)
var
pi
Protinfo
req
:=
h
.
newNetlinkRequest
(
unix
.
RTM_GETLINK
,
unix
.
NLM_F_DUMP
)
msg
:=
nl
.
NewIfInfomsg
(
unix
.
AF_BRIDGE
)
req
:=
h
.
newNetlinkRequest
(
syscall
.
RTM_GETLINK
,
syscall
.
NLM_F_DUMP
)
msg
:=
nl
.
NewIfInfomsg
(
syscall
.
AF_BRIDGE
)
req
.
AddData
(
msg
)
msgs
,
err
:=
req
.
Execute
(
unix
.
NETLINK_ROUTE
,
0
)
msgs
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_ROUTE
,
0
)
if
err
!=
nil
{
return
pi
,
err
}
...
...
@@ -34,7 +33,7 @@ func (h *Handle) LinkGetProtinfo(link Link) (Protinfo, error) {
return
pi
,
err
}
for
_
,
attr
:=
range
attrs
{
if
attr
.
Attr
.
Type
!=
unix
.
IFLA_PROTINFO
|
unix
.
NLA_F_NESTED
{
if
attr
.
Attr
.
Type
!=
syscall
.
IFLA_PROTINFO
|
syscall
.
NLA_F_NESTED
{
continue
}
infos
,
err
:=
nl
.
ParseRouteAttr
(
attr
.
Value
)
...
...
vendor/github.com/vishvananda/netlink/qdisc_linux.go
View file @
7517f6ba
...
...
@@ -8,7 +8,6 @@ import (
"syscall"
"github.com/vishvananda/netlink/nl"
"golang.org/x/sys/unix"
)
// NOTE function is here because it uses other linux functions
...
...
@@ -85,7 +84,7 @@ func QdiscDel(qdisc Qdisc) error {
// QdiscDel will delete a qdisc from the system.
// Equivalent to: `tc qdisc del $qdisc`
func
(
h
*
Handle
)
QdiscDel
(
qdisc
Qdisc
)
error
{
return
h
.
qdiscModify
(
unix
.
RTM_DELQDISC
,
0
,
qdisc
)
return
h
.
qdiscModify
(
syscall
.
RTM_DELQDISC
,
0
,
qdisc
)
}
// QdiscChange will change a qdisc in place
...
...
@@ -99,7 +98,7 @@ func QdiscChange(qdisc Qdisc) error {
// Equivalent to: `tc qdisc change $qdisc`
// The parent and handle MUST NOT be changed.
func
(
h
*
Handle
)
QdiscChange
(
qdisc
Qdisc
)
error
{
return
h
.
qdiscModify
(
unix
.
RTM_NEWQDISC
,
0
,
qdisc
)
return
h
.
qdiscModify
(
syscall
.
RTM_NEWQDISC
,
0
,
qdisc
)
}
// QdiscReplace will replace a qdisc to the system.
...
...
@@ -114,8 +113,8 @@ func QdiscReplace(qdisc Qdisc) error {
// The handle MUST change.
func
(
h
*
Handle
)
QdiscReplace
(
qdisc
Qdisc
)
error
{
return
h
.
qdiscModify
(
unix
.
RTM_NEWQDISC
,
unix
.
NLM_F_CREATE
|
unix
.
NLM_F_REPLACE
,
syscall
.
RTM_NEWQDISC
,
syscall
.
NLM_F_CREATE
|
syscall
.
NLM_F_REPLACE
,
qdisc
)
}
...
...
@@ -129,13 +128,13 @@ func QdiscAdd(qdisc Qdisc) error {
// Equivalent to: `tc qdisc add $qdisc`
func
(
h
*
Handle
)
QdiscAdd
(
qdisc
Qdisc
)
error
{
return
h
.
qdiscModify
(
unix
.
RTM_NEWQDISC
,
unix
.
NLM_F_CREATE
|
unix
.
NLM_F_EXCL
,
syscall
.
RTM_NEWQDISC
,
syscall
.
NLM_F_CREATE
|
syscall
.
NLM_F_EXCL
,
qdisc
)
}
func
(
h
*
Handle
)
qdiscModify
(
cmd
,
flags
int
,
qdisc
Qdisc
)
error
{
req
:=
h
.
newNetlinkRequest
(
cmd
,
flags
|
unix
.
NLM_F_ACK
)
req
:=
h
.
newNetlinkRequest
(
cmd
,
flags
|
syscall
.
NLM_F_ACK
)
base
:=
qdisc
.
Attrs
()
msg
:=
&
nl
.
TcMsg
{
Family
:
nl
.
FAMILY_ALL
,
...
...
@@ -146,13 +145,13 @@ func (h *Handle) qdiscModify(cmd, flags int, qdisc Qdisc) error {
req
.
AddData
(
msg
)
// When deleting don't bother building the rest of the netlink payload
if
cmd
!=
unix
.
RTM_DELQDISC
{
if
cmd
!=
syscall
.
RTM_DELQDISC
{
if
err
:=
qdiscPayload
(
req
,
qdisc
);
err
!=
nil
{
return
err
}
}
_
,
err
:=
req
.
Execute
(
unix
.
NETLINK_ROUTE
,
0
)
_
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_ROUTE
,
0
)
return
err
}
...
...
@@ -249,7 +248,7 @@ func QdiscList(link Link) ([]Qdisc, error) {
// Equivalent to: `tc qdisc show`.
// The list can be filtered by link.
func
(
h
*
Handle
)
QdiscList
(
link
Link
)
([]
Qdisc
,
error
)
{
req
:=
h
.
newNetlinkRequest
(
unix
.
RTM_GETQDISC
,
unix
.
NLM_F_DUMP
)
req
:=
h
.
newNetlinkRequest
(
syscall
.
RTM_GETQDISC
,
syscall
.
NLM_F_DUMP
)
index
:=
int32
(
0
)
if
link
!=
nil
{
base
:=
link
.
Attrs
()
...
...
@@ -262,7 +261,7 @@ func (h *Handle) QdiscList(link Link) ([]Qdisc, error) {
}
req
.
AddData
(
msg
)
msgs
,
err
:=
req
.
Execute
(
unix
.
NETLINK_ROUTE
,
unix
.
RTM_NEWQDISC
)
msgs
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_ROUTE
,
syscall
.
RTM_NEWQDISC
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
vendor/github.com/vishvananda/netlink/route.go
View file @
7517f6ba
...
...
@@ -45,8 +45,6 @@ type Route struct {
MPLSDst
*
int
NewDst
Destination
Encap
Encap
MTU
int
AdvMSS
int
}
func
(
r
Route
)
String
()
string
{
...
...
vendor/github.com/vishvananda/netlink/route_linux.go
View file @
7517f6ba
This diff is collapsed.
Click to expand it.
vendor/github.com/vishvananda/netlink/rule.go
View file @
7517f6ba
...
...
@@ -21,7 +21,6 @@ type Rule struct {
OifName
string
SuppressIfgroup
int
SuppressPrefixlen
int
Invert
bool
}
func
(
r
Rule
)
String
()
string
{
...
...
vendor/github.com/vishvananda/netlink/rule_linux.go
View file @
7517f6ba
...
...
@@ -3,13 +3,11 @@ package netlink
import
(
"fmt"
"net"
"syscall"
"github.com/vishvananda/netlink/nl"
"golang.org/x/sys/unix"
)
const
FibRuleInvert
=
0x2
// RuleAdd adds a rule to the system.
// Equivalent to: ip rule add
func
RuleAdd
(
rule
*
Rule
)
error
{
...
...
@@ -19,7 +17,7 @@ func RuleAdd(rule *Rule) error {
// RuleAdd adds a rule to the system.
// Equivalent to: ip rule add
func
(
h
*
Handle
)
RuleAdd
(
rule
*
Rule
)
error
{
req
:=
h
.
newNetlinkRequest
(
unix
.
RTM_NEWRULE
,
unix
.
NLM_F_CREATE
|
unix
.
NLM_F_EXCL
|
unix
.
NLM_F_ACK
)
req
:=
h
.
newNetlinkRequest
(
syscall
.
RTM_NEWRULE
,
syscall
.
NLM_F_CREATE
|
syscall
.
NLM_F_EXCL
|
syscall
.
NLM_F_ACK
)
return
ruleHandle
(
rule
,
req
)
}
...
...
@@ -32,31 +30,18 @@ func RuleDel(rule *Rule) error {
// RuleDel deletes a rule from the system.
// Equivalent to: ip rule del
func
(
h
*
Handle
)
RuleDel
(
rule
*
Rule
)
error
{
req
:=
h
.
newNetlinkRequest
(
unix
.
RTM_DELRULE
,
unix
.
NLM_F_ACK
)
req
:=
h
.
newNetlinkRequest
(
syscall
.
RTM_DELRULE
,
syscall
.
NLM_F_CREATE
|
syscall
.
NLM_F_EXCL
|
syscall
.
NLM_F_ACK
)
return
ruleHandle
(
rule
,
req
)
}
func
ruleHandle
(
rule
*
Rule
,
req
*
nl
.
NetlinkRequest
)
error
{
msg
:=
nl
.
NewRtMsg
()
msg
.
Family
=
unix
.
AF_INET
msg
.
Protocol
=
unix
.
RTPROT_BOOT
msg
.
Scope
=
unix
.
RT_SCOPE_UNIVERSE
msg
.
Table
=
unix
.
RT_TABLE_UNSPEC
msg
.
Type
=
unix
.
RTN_UNSPEC
if
req
.
NlMsghdr
.
Flags
&
unix
.
NLM_F_CREATE
>
0
{
msg
.
Type
=
unix
.
RTN_UNICAST
}
if
rule
.
Invert
{
msg
.
Flags
|=
FibRuleInvert
}
msg
.
Family
=
syscall
.
AF_INET
if
rule
.
Family
!=
0
{
msg
.
Family
=
uint8
(
rule
.
Family
)
}
if
rule
.
Table
>=
0
&&
rule
.
Table
<
256
{
msg
.
Table
=
uint8
(
rule
.
Table
)
}
var
dstFamily
uint8
var
rtAttrs
[]
*
nl
.
RtAttr
if
rule
.
Dst
!=
nil
&&
rule
.
Dst
.
IP
!=
nil
{
dstLen
,
_
:=
rule
.
Dst
.
Mask
.
Size
()
...
...
@@ -64,12 +49,12 @@ func ruleHandle(rule *Rule, req *nl.NetlinkRequest) error {
msg
.
Family
=
uint8
(
nl
.
GetIPFamily
(
rule
.
Dst
.
IP
))
dstFamily
=
msg
.
Family
var
dstData
[]
byte
if
msg
.
Family
==
unix
.
AF_INET
{
if
msg
.
Family
==
syscall
.
AF_INET
{
dstData
=
rule
.
Dst
.
IP
.
To4
()
}
else
{
dstData
=
rule
.
Dst
.
IP
.
To16
()
}
rtAttrs
=
append
(
rtAttrs
,
nl
.
NewRtAttr
(
unix
.
RTA_DST
,
dstData
))
rtAttrs
=
append
(
rtAttrs
,
nl
.
NewRtAttr
(
syscall
.
RTA_DST
,
dstData
))
}
if
rule
.
Src
!=
nil
&&
rule
.
Src
.
IP
!=
nil
{
...
...
@@ -80,12 +65,19 @@ func ruleHandle(rule *Rule, req *nl.NetlinkRequest) error {
srcLen
,
_
:=
rule
.
Src
.
Mask
.
Size
()
msg
.
Src_len
=
uint8
(
srcLen
)
var
srcData
[]
byte
if
msg
.
Family
==
unix
.
AF_INET
{
if
msg
.
Family
==
syscall
.
AF_INET
{
srcData
=
rule
.
Src
.
IP
.
To4
()
}
else
{
srcData
=
rule
.
Src
.
IP
.
To16
()
}
rtAttrs
=
append
(
rtAttrs
,
nl
.
NewRtAttr
(
unix
.
RTA_SRC
,
srcData
))
rtAttrs
=
append
(
rtAttrs
,
nl
.
NewRtAttr
(
syscall
.
RTA_SRC
,
srcData
))
}
if
rule
.
Table
>=
0
{
msg
.
Table
=
uint8
(
rule
.
Table
)
if
rule
.
Table
>=
256
{
msg
.
Table
=
syscall
.
RT_TABLE_UNSPEC
}
}
req
.
AddData
(
msg
)
...
...
@@ -150,7 +142,7 @@ func ruleHandle(rule *Rule, req *nl.NetlinkRequest) error {
req
.
AddData
(
nl
.
NewRtAttr
(
nl
.
FRA_GOTO
,
b
))
}
_
,
err
:=
req
.
Execute
(
unix
.
NETLINK_ROUTE
,
0
)
_
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_ROUTE
,
0
)
return
err
}
...
...
@@ -163,11 +155,11 @@ func RuleList(family int) ([]Rule, error) {
// RuleList lists rules in the system.
// Equivalent to: ip rule list
func
(
h
*
Handle
)
RuleList
(
family
int
)
([]
Rule
,
error
)
{
req
:=
h
.
newNetlinkRequest
(
unix
.
RTM_GETRULE
,
unix
.
NLM_F_DUMP
|
unix
.
NLM_F_REQUEST
)
req
:=
h
.
newNetlinkRequest
(
syscall
.
RTM_GETRULE
,
syscall
.
NLM_F_DUMP
|
syscall
.
NLM_F_REQUEST
)
msg
:=
nl
.
NewIfInfomsg
(
family
)
req
.
AddData
(
msg
)
msgs
,
err
:=
req
.
Execute
(
unix
.
NETLINK_ROUTE
,
unix
.
RTM_NEWRULE
)
msgs
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_ROUTE
,
syscall
.
RTM_NEWRULE
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -183,11 +175,9 @@ func (h *Handle) RuleList(family int) ([]Rule, error) {
rule
:=
NewRule
()
rule
.
Invert
=
msg
.
Flags
&
FibRuleInvert
>
0
for
j
:=
range
attrs
{
switch
attrs
[
j
]
.
Attr
.
Type
{
case
unix
.
RTA_TABLE
:
case
syscall
.
RTA_TABLE
:
rule
.
Table
=
int
(
native
.
Uint32
(
attrs
[
j
]
.
Value
[
0
:
4
]))
case
nl
.
FRA_SRC
:
rule
.
Src
=
&
net
.
IPNet
{
...
...
vendor/github.com/vishvananda/netlink/socket_linux.go
View file @
7517f6ba
...
...
@@ -4,9 +4,9 @@ import (
"errors"
"fmt"
"net"
"syscall"
"github.com/vishvananda/netlink/nl"
"golang.org/x/sys/unix"
)
const
(
...
...
@@ -123,15 +123,15 @@ func SocketGet(local, remote net.Addr) (*Socket, error) {
return
nil
,
ErrNotImplemented
}
s
,
err
:=
nl
.
Subscribe
(
unix
.
NETLINK_INET_DIAG
)
s
,
err
:=
nl
.
Subscribe
(
syscall
.
NETLINK_INET_DIAG
)
if
err
!=
nil
{
return
nil
,
err
}
defer
s
.
Close
()
req
:=
nl
.
NewNetlinkRequest
(
nl
.
SOCK_DIAG_BY_FAMILY
,
0
)
req
.
AddData
(
&
socketRequest
{
Family
:
unix
.
AF_INET
,
Protocol
:
unix
.
IPPROTO_TCP
,
Family
:
syscall
.
AF_INET
,
Protocol
:
syscall
.
IPPROTO_TCP
,
ID
:
SocketID
{
SourcePort
:
uint16
(
localTCP
.
Port
),
DestinationPort
:
uint16
(
remoteTCP
.
Port
),
...
...
vendor/github.com/vishvananda/netlink/xfrm.go
View file @
7517f6ba
...
...
@@ -2,20 +2,19 @@ package netlink
import
(
"fmt"
"golang.org/x/sys/unix"
"syscall"
)
// Proto is an enum representing an ipsec protocol.
type
Proto
uint8
const
(
XFRM_PROTO_ROUTE2
Proto
=
unix
.
IPPROTO_ROUTING
XFRM_PROTO_ESP
Proto
=
unix
.
IPPROTO_ESP
XFRM_PROTO_AH
Proto
=
unix
.
IPPROTO_AH
XFRM_PROTO_HAO
Proto
=
unix
.
IPPROTO_DSTOPTS
XFRM_PROTO_ROUTE2
Proto
=
syscall
.
IPPROTO_ROUTING
XFRM_PROTO_ESP
Proto
=
syscall
.
IPPROTO_ESP
XFRM_PROTO_AH
Proto
=
syscall
.
IPPROTO_AH
XFRM_PROTO_HAO
Proto
=
syscall
.
IPPROTO_DSTOPTS
XFRM_PROTO_COMP
Proto
=
0x6c
// NOTE not defined on darwin
XFRM_PROTO_IPSEC_ANY
Proto
=
unix
.
IPPROTO_RAW
XFRM_PROTO_IPSEC_ANY
Proto
=
syscall
.
IPPROTO_RAW
)
func
(
p
Proto
)
String
()
string
{
...
...
vendor/github.com/vishvananda/netlink/xfrm_monitor_linux.go
View file @
7517f6ba
...
...
@@ -2,10 +2,11 @@ package netlink
import
(
"fmt"
"syscall"
"github.com/vishvananda/netlink/nl"
"github.com/vishvananda/netns"
"golang.org/x/sys/unix"
"github.com/vishvananda/netlink/nl"
)
type
XfrmMsg
interface
{
...
...
@@ -38,7 +39,7 @@ func XfrmMonitor(ch chan<- XfrmMsg, done <-chan struct{}, errorChan chan<- error
if
err
!=
nil
{
return
nil
}
s
,
err
:=
nl
.
SubscribeAt
(
netns
.
None
(),
netns
.
None
(),
unix
.
NETLINK_XFRM
,
groups
...
)
s
,
err
:=
nl
.
SubscribeAt
(
netns
.
None
(),
netns
.
None
(),
syscall
.
NETLINK_XFRM
,
groups
...
)
if
err
!=
nil
{
return
err
}
...
...
vendor/github.com/vishvananda/netlink/xfrm_policy_linux.go
View file @
7517f6ba
package
netlink
import
(
"syscall"
"github.com/vishvananda/netlink/nl"
"golang.org/x/sys/unix"
)
func
selFromPolicy
(
sel
*
nl
.
XfrmSelector
,
policy
*
XfrmPolicy
)
{
...
...
@@ -54,7 +55,7 @@ func (h *Handle) XfrmPolicyUpdate(policy *XfrmPolicy) error {
}
func
(
h
*
Handle
)
xfrmPolicyAddOrUpdate
(
policy
*
XfrmPolicy
,
nlProto
int
)
error
{
req
:=
h
.
newNetlinkRequest
(
nlProto
,
unix
.
NLM_F_CREATE
|
unix
.
NLM_F_EXCL
|
unix
.
NLM_F_ACK
)
req
:=
h
.
newNetlinkRequest
(
nlProto
,
syscall
.
NLM_F_CREATE
|
syscall
.
NLM_F_EXCL
|
syscall
.
NLM_F_ACK
)
msg
:=
&
nl
.
XfrmUserpolicyInfo
{}
selFromPolicy
(
&
msg
.
Sel
,
policy
)
...
...
@@ -90,7 +91,7 @@ func (h *Handle) xfrmPolicyAddOrUpdate(policy *XfrmPolicy, nlProto int) error {
req
.
AddData
(
out
)
}
_
,
err
:=
req
.
Execute
(
unix
.
NETLINK_XFRM
,
0
)
_
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_XFRM
,
0
)
return
err
}
...
...
@@ -120,12 +121,12 @@ func XfrmPolicyList(family int) ([]XfrmPolicy, error) {
// Equivalent to: `ip xfrm policy show`.
// The list can be filtered by ip family.
func
(
h
*
Handle
)
XfrmPolicyList
(
family
int
)
([]
XfrmPolicy
,
error
)
{
req
:=
h
.
newNetlinkRequest
(
nl
.
XFRM_MSG_GETPOLICY
,
unix
.
NLM_F_DUMP
)
req
:=
h
.
newNetlinkRequest
(
nl
.
XFRM_MSG_GETPOLICY
,
syscall
.
NLM_F_DUMP
)
msg
:=
nl
.
NewIfInfomsg
(
family
)
req
.
AddData
(
msg
)
msgs
,
err
:=
req
.
Execute
(
unix
.
NETLINK_XFRM
,
nl
.
XFRM_MSG_NEWPOLICY
)
msgs
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_XFRM
,
nl
.
XFRM_MSG_NEWPOLICY
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -164,13 +165,13 @@ func XfrmPolicyFlush() error {
// XfrmPolicyFlush will flush the policies on the system.
// Equivalent to: `ip xfrm policy flush`
func
(
h
*
Handle
)
XfrmPolicyFlush
()
error
{
req
:=
h
.
newNetlinkRequest
(
nl
.
XFRM_MSG_FLUSHPOLICY
,
unix
.
NLM_F_ACK
)
_
,
err
:=
req
.
Execute
(
unix
.
NETLINK_XFRM
,
0
)
req
:=
h
.
newNetlinkRequest
(
nl
.
XFRM_MSG_FLUSHPOLICY
,
syscall
.
NLM_F_ACK
)
_
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_XFRM
,
0
)
return
err
}
func
(
h
*
Handle
)
xfrmPolicyGetOrDelete
(
policy
*
XfrmPolicy
,
nlProto
int
)
(
*
XfrmPolicy
,
error
)
{
req
:=
h
.
newNetlinkRequest
(
nlProto
,
unix
.
NLM_F_ACK
)
req
:=
h
.
newNetlinkRequest
(
nlProto
,
syscall
.
NLM_F_ACK
)
msg
:=
&
nl
.
XfrmUserpolicyId
{}
selFromPolicy
(
&
msg
.
Sel
,
policy
)
...
...
@@ -188,7 +189,7 @@ func (h *Handle) xfrmPolicyGetOrDelete(policy *XfrmPolicy, nlProto int) (*XfrmPo
resType
=
0
}
msgs
,
err
:=
req
.
Execute
(
unix
.
NETLINK_XFRM
,
uint16
(
resType
))
msgs
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_XFRM
,
uint16
(
resType
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
vendor/github.com/vishvananda/netlink/xfrm_state.go
View file @
7517f6ba
...
...
@@ -3,7 +3,6 @@ package netlink
import
(
"fmt"
"net"
"time"
)
// XfrmStateAlgo represents the algorithm to use for the ipsec encryption.
...
...
@@ -68,19 +67,6 @@ type XfrmStateLimits struct {
TimeUseHard
uint64
}
// XfrmStateStats represents the current number of bytes/packets
// processed by this State, the State's installation and first use
// time and the replay window counters.
type
XfrmStateStats
struct
{
ReplayWindow
uint32
Replay
uint32
Failed
uint32
Bytes
uint64
Packets
uint64
AddTime
uint64
UseTime
uint64
}
// XfrmState represents the state of an ipsec policy. It optionally
// contains an XfrmStateAlgo for encryption and one for authentication.
type
XfrmState
struct
{
...
...
@@ -92,7 +78,6 @@ type XfrmState struct {
Reqid
int
ReplayWindow
int
Limits
XfrmStateLimits
Statistics
XfrmStateStats
Mark
*
XfrmMark
Auth
*
XfrmStateAlgo
Crypt
*
XfrmStateAlgo
...
...
@@ -109,16 +94,10 @@ func (sa XfrmState) Print(stats bool) string {
if
!
stats
{
return
sa
.
String
()
}
at
:=
time
.
Unix
(
int64
(
sa
.
Statistics
.
AddTime
),
0
)
.
Format
(
time
.
UnixDate
)
ut
:=
"-"
if
sa
.
Statistics
.
UseTime
>
0
{
ut
=
time
.
Unix
(
int64
(
sa
.
Statistics
.
UseTime
),
0
)
.
Format
(
time
.
UnixDate
)
}
return
fmt
.
Sprintf
(
"%s, ByteSoft: %s, ByteHard: %s, PacketSoft: %s, PacketHard: %s, TimeSoft: %d, TimeHard: %d, TimeUseSoft: %d, TimeUseHard: %d, Bytes: %d, Packets: %d, "
+
"AddTime: %s, UseTime: %s, ReplayWindow: %d, Replay: %d, Failed: %d"
,
return
fmt
.
Sprintf
(
"%s, ByteSoft: %s, ByteHard: %s, PacketSoft: %s, PacketHard: %s, TimeSoft: %d, TimeHard: %d, TimeUseSoft: %d, TimeUseHard: %d"
,
sa
.
String
(),
printLimit
(
sa
.
Limits
.
ByteSoft
),
printLimit
(
sa
.
Limits
.
ByteHard
),
printLimit
(
sa
.
Limits
.
PacketSoft
),
printLimit
(
sa
.
Limits
.
PacketHard
),
sa
.
Limits
.
TimeSoft
,
sa
.
Limits
.
TimeHard
,
sa
.
Limits
.
TimeUseSoft
,
sa
.
Limits
.
TimeUseHard
,
sa
.
Statistics
.
Bytes
,
sa
.
Statistics
.
Packets
,
at
,
ut
,
sa
.
Statistics
.
ReplayWindow
,
sa
.
Statistics
.
Replay
,
sa
.
Statistics
.
Failed
)
sa
.
Limits
.
TimeSoft
,
sa
.
Limits
.
TimeHard
,
sa
.
Limits
.
TimeUseSoft
,
sa
.
Limits
.
TimeUseHard
)
}
func
printLimit
(
lmt
uint64
)
string
{
...
...
vendor/github.com/vishvananda/netlink/xfrm_state_linux.go
View file @
7517f6ba
...
...
@@ -2,10 +2,10 @@ package netlink
import
(
"fmt"
"syscall"
"unsafe"
"github.com/vishvananda/netlink/nl"
"golang.org/x/sys/unix"
)
func
writeStateAlgo
(
a
*
XfrmStateAlgo
)
[]
byte
{
...
...
@@ -111,7 +111,7 @@ func (h *Handle) xfrmStateAddOrUpdate(state *XfrmState, nlProto int) error {
if
state
.
Spi
==
0
{
return
fmt
.
Errorf
(
"Spi must be set when adding xfrm state."
)
}
req
:=
h
.
newNetlinkRequest
(
nlProto
,
unix
.
NLM_F_CREATE
|
unix
.
NLM_F_EXCL
|
unix
.
NLM_F_ACK
)
req
:=
h
.
newNetlinkRequest
(
nlProto
,
syscall
.
NLM_F_CREATE
|
syscall
.
NLM_F_EXCL
|
syscall
.
NLM_F_ACK
)
msg
:=
xfrmUsersaInfoFromXfrmState
(
state
)
...
...
@@ -157,13 +157,13 @@ func (h *Handle) xfrmStateAddOrUpdate(state *XfrmState, nlProto int) error {
req
.
AddData
(
out
)
}
_
,
err
:=
req
.
Execute
(
unix
.
NETLINK_XFRM
,
0
)
_
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_XFRM
,
0
)
return
err
}
func
(
h
*
Handle
)
xfrmStateAllocSpi
(
state
*
XfrmState
)
(
*
XfrmState
,
error
)
{
req
:=
h
.
newNetlinkRequest
(
nl
.
XFRM_MSG_ALLOCSPI
,
unix
.
NLM_F_CREATE
|
unix
.
NLM_F_EXCL
|
unix
.
NLM_F_ACK
)
syscall
.
NLM_F_CREATE
|
syscall
.
NLM_F_EXCL
|
syscall
.
NLM_F_ACK
)
msg
:=
&
nl
.
XfrmUserSpiInfo
{}
msg
.
XfrmUsersaInfo
=
*
(
xfrmUsersaInfoFromXfrmState
(
state
))
...
...
@@ -177,7 +177,7 @@ func (h *Handle) xfrmStateAllocSpi(state *XfrmState) (*XfrmState, error) {
req
.
AddData
(
out
)
}
msgs
,
err
:=
req
.
Execute
(
unix
.
NETLINK_XFRM
,
0
)
msgs
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_XFRM
,
0
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -216,9 +216,9 @@ func XfrmStateList(family int) ([]XfrmState, error) {
// Equivalent to: `ip xfrm state show`.
// The list can be filtered by ip family.
func
(
h
*
Handle
)
XfrmStateList
(
family
int
)
([]
XfrmState
,
error
)
{
req
:=
h
.
newNetlinkRequest
(
nl
.
XFRM_MSG_GETSA
,
unix
.
NLM_F_DUMP
)
req
:=
h
.
newNetlinkRequest
(
nl
.
XFRM_MSG_GETSA
,
syscall
.
NLM_F_DUMP
)
msgs
,
err
:=
req
.
Execute
(
unix
.
NETLINK_XFRM
,
nl
.
XFRM_MSG_NEWSA
)
msgs
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_XFRM
,
nl
.
XFRM_MSG_NEWSA
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -255,7 +255,7 @@ func (h *Handle) XfrmStateGet(state *XfrmState) (*XfrmState, error) {
}
func
(
h
*
Handle
)
xfrmStateGetOrDelete
(
state
*
XfrmState
,
nlProto
int
)
(
*
XfrmState
,
error
)
{
req
:=
h
.
newNetlinkRequest
(
nlProto
,
unix
.
NLM_F_ACK
)
req
:=
h
.
newNetlinkRequest
(
nlProto
,
syscall
.
NLM_F_ACK
)
msg
:=
&
nl
.
XfrmUsersaId
{}
msg
.
Family
=
uint16
(
nl
.
GetIPFamily
(
state
.
Dst
))
...
...
@@ -278,7 +278,7 @@ func (h *Handle) xfrmStateGetOrDelete(state *XfrmState, nlProto int) (*XfrmState
resType
=
0
}
msgs
,
err
:=
req
.
Execute
(
unix
.
NETLINK_XFRM
,
uint16
(
resType
))
msgs
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_XFRM
,
uint16
(
resType
))
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -308,7 +308,6 @@ func xfrmStateFromXfrmUsersaInfo(msg *nl.XfrmUsersaInfo) *XfrmState {
state
.
Reqid
=
int
(
msg
.
Reqid
)
state
.
ReplayWindow
=
int
(
msg
.
ReplayWindow
)
lftToLimits
(
&
msg
.
Lft
,
&
state
.
Limits
)
curToStats
(
&
msg
.
Curlft
,
&
msg
.
Stats
,
&
state
.
Statistics
)
return
&
state
}
...
...
@@ -387,11 +386,11 @@ func XfrmStateFlush(proto Proto) error {
// proto = 0 means any transformation protocols
// Equivalent to: `ip xfrm state flush [ proto XFRM-PROTO ]`
func
(
h
*
Handle
)
XfrmStateFlush
(
proto
Proto
)
error
{
req
:=
h
.
newNetlinkRequest
(
nl
.
XFRM_MSG_FLUSHSA
,
unix
.
NLM_F_ACK
)
req
:=
h
.
newNetlinkRequest
(
nl
.
XFRM_MSG_FLUSHSA
,
syscall
.
NLM_F_ACK
)
req
.
AddData
(
&
nl
.
XfrmUsersaFlush
{
Proto
:
uint8
(
proto
)})
_
,
err
:=
req
.
Execute
(
unix
.
NETLINK_XFRM
,
0
)
_
,
err
:=
req
.
Execute
(
syscall
.
NETLINK_XFRM
,
0
)
if
err
!=
nil
{
return
err
}
...
...
@@ -430,16 +429,6 @@ func lftToLimits(lft *nl.XfrmLifetimeCfg, lmts *XfrmStateLimits) {
*
lmts
=
*
(
*
XfrmStateLimits
)(
unsafe
.
Pointer
(
lft
))
}
func
curToStats
(
cur
*
nl
.
XfrmLifetimeCur
,
wstats
*
nl
.
XfrmStats
,
stats
*
XfrmStateStats
)
{
stats
.
Bytes
=
cur
.
Bytes
stats
.
Packets
=
cur
.
Packets
stats
.
AddTime
=
cur
.
AddTime
stats
.
UseTime
=
cur
.
UseTime
stats
.
ReplayWindow
=
wstats
.
ReplayWindow
stats
.
Replay
=
wstats
.
Replay
stats
.
Failed
=
wstats
.
IntegrityFailed
}
func
xfrmUsersaInfoFromXfrmState
(
state
*
XfrmState
)
*
nl
.
XfrmUsersaInfo
{
msg
:=
&
nl
.
XfrmUsersaInfo
{}
msg
.
Family
=
uint16
(
nl
.
GetIPFamily
(
state
.
Dst
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment