mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-04 15:04:25 +01:00
The netlink dep needs to be updated to get logic for the tuntap
link. It is fixing a bug that uses a generic link instead.
This also requires the golang/x/sys package to be updated
for the IFLA_* constraints.
Commits for github.com/vishvananda/netlink
c8c507c fix: fix ip rule goto bug
db99c04 tuntap: Return TunTapLink instead of GenericLink
e993616 Fix unit test failure: TestNeighAddDelLLIPAddr
fb5fbae Mirred and connmark clobber their ActionAttrs
1187dc9 Fix tests
00009fb Add support for TC_ACT_CONNMARK
fafc1e7 support vlan protocol
fd97bf4 Add command to set devlink device switchdev mode
bcb80b2 Add devlink command by to get specific device name
f504738 Fix function comments based on best practices from Effective Go
e281812 Fix typos
adb577d Add support for IFLA_GSO_*
aa950f2 travis: run tests with Go 1.12.x
b64d7bc travis: specify go_import_path
b9cafe4 remove redundant type assertions in type switch
1e2e7ab Add Support for Virtual XFRM Interfaces
48a75e0 Fix Race Condition in TestXfrmMonitorExpire
e37f4b4 Avoid 64K allocation on the heap with each Receive
332a698 Add devlink commands for devlink device information
cb78b18 neigh_linux: Fix failure on deleted link neighs updates
2bc5004 Replace redundant copied u32 types with type aliases
093e80f Pass Ndmsg to NeighListExecute
78a3099 Make test suite more deterministic
2529893 genetlink: Add missing error check
91b013f code simplification
023a6da Make go vet happier
aa5b058 Simplify code
e137ed6 Replace nl.NewRtAttrChild with method on struct
3b1c596 Run TravisCI with Go 1.10 and 1.11
d741264 Reduce allocations
b48eed5 Add an API to rename rdma device name
02a3831 Adjust conntrack filters
d3a23fd Make AddChild more generic
1404979 Add support for hoplimit metric in routes
6d53654 Add support for neighbor subscription
531df7a Avoid serializing empty TCA_OPTIONS in qdisc messages
56b1bd2 fix: BRIDGE_FLAGS_* constants off-by-one
8aa85bf Add support for action and ifindex in XFRM policy
9eab419 Netlink: Fix Darwin build
2cbcf73 Add a test for Vlan filtering support for bridges.
0bbc55b Initial support for vlan aware bridges.
3ac69fd Add network namespace ID management.
d68dce4 Ingress qdisc add/del Test case
1006cf4 Implementation of HFSC
d85e18e Allow Tuntap non-persist, allow empty tuntap name
d77c86a protinfo: Check if object is nil
a06dabf Increase size of receive buffer
3e48e44 Revert "RTEXT_FILTER_VF doesn't always work with dump request, fixes #354"
028453c RTEXT_FILTER_VF doesn't always work with dump request, fixes #354
ee06b1d add vti6 support
b1cc70d fix prefixlen/local IP, incl. PtP addresses
7c0b594 Implemented String() for netem, fq and fq_codel in qdisc
769bb84 Adjust flags values
5f662e0 Add info about VFs on link
985ab95 Add support for link flag allmulticast
16769db Support LWTUNNEL_ENCAP_SEG6_LOCAL (including tests)
b7f0669 Add test to Add/Del IPv6 route.
55d3a80 Added tests for Gretap/Gretun devices
f07d9d5 Run both Inline/Encap mode in TestSEG6RouteAddDel
1970aef Add RDMA netlink socket for RDMA device information
dc00cf9 Add Hash to U32
23a36f2 Add Divisor to U32
85aa3b7 Add statistics to class attributes
aa0edbe Add support for setting InfininBand Node and Port GUID of a VF
41009d5 Read conntrack flow statistics
a2ad57a Add changelog file, initial release tagging
5236321 Use IFLA_* constants from x/sys/unix
25d2c79 Use IFF_MULTI_QUEUE from x/sys/unix to define TUNTAP_MULTI_QUEUE
d35d6b5 Clarify ESN bitmap length construction logic
a2af46a Add FQ Codel
465b5fe Add Fq Qdisc support
c27b7f7 Run gofmt -s -w on the project
5f5d5cd Add a 'ListExisting' option to get the existing entries in the route/addr/link tables as part of RouteSubscribeWithOptions, AddrSubscribeWithOptions, and LinkSubscribeWithOptions.
5a988e8 Support IPv6 GRE Tun and Tap
7291c36 addr_linux: Implement CacheInfo installation
422ffe6 addr_linux: Skip BROADCAST and LABEL for non-ipv4
1882fa9 Add Matchall filter
7b4c063 Update bpf_linux.go
ad19ca1 netlink: allow non linux builds to pass.
3ff4c21 Don't overwrite the XDP file descriptor with flags
d4235bf Eliminate cgo from netlink.
54ad9e3 Two new functions: LinkSetBondSlave and VethPeerIndex
f67b75e Properly tear down netns at the end of test
016ba6f Add support for managing source MACVLANs
6e7bb56 Run TestSocketGet in dedicated netns
a5d066d Fix LinkAdd for sit tunnel on 3.10 kernel
8bead6f Add requirements to conntrack tests
9ce265f Retrieve VLAN and VNI when listing neighbour
fad79cb Fix go build issue for fou code
Commits for golang/x/sys
88d2dcc unix: add IFLA_* constants for Linux 4.15
c1138c8 unix: update to Linux 4.15, glibc 2.27 and Go 1.10
37707fd unix: move gccgo redeclared *SyscallNoError functions to a separate file
8f27ce8 unix: fix cpuset size argument in sched_affinity syscall
3dbebcf unix: use SyscallNoError and RawSyscallNoError on Linux only
ff2a66f unix: fix godoc comment for clen
0346725 unix: add godoc for Sockaddr* types
90f0fdc plan9: add arm support
ef80224 unix: add sockaddr_l2 definitions
af9a212 unix: don't export padding fields on all platforms
af50095 unix: use ParseDirent from syscall
2c42eef unix: adjust replacement regex for removed struct fields for linux/s390x
fff93fa unix: add Statx on Linux
52ba35d unix: check error return of os.Symlink in tests on Linux
810d700 unix: match seek argument size to signature on linux/arm
b9cf5f9 unix: add cgroupstats type and constants
d38bf78 unix: restore gccgo support
2493af8 plan9: move Unsetenv into env_plan9.go
3ca7571 windows: move Unsetenv into env_windows.go
1792d66 unix: move Unsetenv into env_unix.go
dd9ec17 unix: fix build on Go 1.8
12d9d5b unix: add SchedGetaffinity and SchedSetaffinity on Linux
a3f2cbd unix: fix typo in unix/asm_linux_arm64.s made in 28a7276
28a7276 unix: add SyscallNoError and RawSyscallNoError on Linux
8380141 unix: simplify error handling in *listxattr on FreeBSD
df29b91 unix: add TestSelect for *BSD
801364e unix: add Select on Solaris
d818ba1 unix: remove syscall constants on Solaris
236baca unix: add timeout tests for Select and Pselect on Linux
571f7bb unix: simplify TestGetwd
d5840ad unix: add GetsockoptString for Darwin, *BSD and Solaris
Signed-off-by: Gabi Beyer <gabrielle.n.beyer@intel.com>
457 lines
13 KiB
Go
457 lines
13 KiB
Go
package netlink
|
|
|
|
import (
|
|
"fmt"
|
|
"unsafe"
|
|
|
|
"github.com/vishvananda/netlink/nl"
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func writeStateAlgo(a *XfrmStateAlgo) []byte {
|
|
algo := nl.XfrmAlgo{
|
|
AlgKeyLen: uint32(len(a.Key) * 8),
|
|
AlgKey: a.Key,
|
|
}
|
|
end := len(a.Name)
|
|
if end > 64 {
|
|
end = 64
|
|
}
|
|
copy(algo.AlgName[:end], a.Name)
|
|
return algo.Serialize()
|
|
}
|
|
|
|
func writeStateAlgoAuth(a *XfrmStateAlgo) []byte {
|
|
algo := nl.XfrmAlgoAuth{
|
|
AlgKeyLen: uint32(len(a.Key) * 8),
|
|
AlgTruncLen: uint32(a.TruncateLen),
|
|
AlgKey: a.Key,
|
|
}
|
|
end := len(a.Name)
|
|
if end > 64 {
|
|
end = 64
|
|
}
|
|
copy(algo.AlgName[:end], a.Name)
|
|
return algo.Serialize()
|
|
}
|
|
|
|
func writeStateAlgoAead(a *XfrmStateAlgo) []byte {
|
|
algo := nl.XfrmAlgoAEAD{
|
|
AlgKeyLen: uint32(len(a.Key) * 8),
|
|
AlgICVLen: uint32(a.ICVLen),
|
|
AlgKey: a.Key,
|
|
}
|
|
end := len(a.Name)
|
|
if end > 64 {
|
|
end = 64
|
|
}
|
|
copy(algo.AlgName[:end], a.Name)
|
|
return algo.Serialize()
|
|
}
|
|
|
|
func writeMark(m *XfrmMark) []byte {
|
|
mark := &nl.XfrmMark{
|
|
Value: m.Value,
|
|
Mask: m.Mask,
|
|
}
|
|
if mark.Mask == 0 {
|
|
mark.Mask = ^uint32(0)
|
|
}
|
|
return mark.Serialize()
|
|
}
|
|
|
|
func writeReplayEsn(replayWindow int) []byte {
|
|
replayEsn := &nl.XfrmReplayStateEsn{
|
|
OSeq: 0,
|
|
Seq: 0,
|
|
OSeqHi: 0,
|
|
SeqHi: 0,
|
|
ReplayWindow: uint32(replayWindow),
|
|
}
|
|
|
|
// Linux stores the bitmap to identify the already received sequence packets in blocks of uint32 elements.
|
|
// Therefore bitmap length is the minimum number of uint32 elements needed. The following is a ceiling operation.
|
|
bytesPerElem := int(unsafe.Sizeof(replayEsn.BmpLen)) // Any uint32 variable is good for this
|
|
replayEsn.BmpLen = uint32((replayWindow + (bytesPerElem * 8) - 1) / (bytesPerElem * 8))
|
|
|
|
return replayEsn.Serialize()
|
|
}
|
|
|
|
// XfrmStateAdd will add an xfrm state to the system.
|
|
// Equivalent to: `ip xfrm state add $state`
|
|
func XfrmStateAdd(state *XfrmState) error {
|
|
return pkgHandle.XfrmStateAdd(state)
|
|
}
|
|
|
|
// XfrmStateAdd will add an xfrm state to the system.
|
|
// Equivalent to: `ip xfrm state add $state`
|
|
func (h *Handle) XfrmStateAdd(state *XfrmState) error {
|
|
return h.xfrmStateAddOrUpdate(state, nl.XFRM_MSG_NEWSA)
|
|
}
|
|
|
|
// XfrmStateAllocSpi will allocate an xfrm state in the system.
|
|
// Equivalent to: `ip xfrm state allocspi`
|
|
func XfrmStateAllocSpi(state *XfrmState) (*XfrmState, error) {
|
|
return pkgHandle.xfrmStateAllocSpi(state)
|
|
}
|
|
|
|
// XfrmStateUpdate will update an xfrm state to the system.
|
|
// Equivalent to: `ip xfrm state update $state`
|
|
func XfrmStateUpdate(state *XfrmState) error {
|
|
return pkgHandle.XfrmStateUpdate(state)
|
|
}
|
|
|
|
// XfrmStateUpdate will update an xfrm state to the system.
|
|
// Equivalent to: `ip xfrm state update $state`
|
|
func (h *Handle) XfrmStateUpdate(state *XfrmState) error {
|
|
return h.xfrmStateAddOrUpdate(state, nl.XFRM_MSG_UPDSA)
|
|
}
|
|
|
|
func (h *Handle) xfrmStateAddOrUpdate(state *XfrmState, nlProto int) error {
|
|
|
|
// A state with spi 0 can't be deleted so don't allow it to be set
|
|
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)
|
|
|
|
msg := xfrmUsersaInfoFromXfrmState(state)
|
|
|
|
if state.ESN {
|
|
if state.ReplayWindow == 0 {
|
|
return fmt.Errorf("ESN flag set without ReplayWindow")
|
|
}
|
|
msg.Flags |= nl.XFRM_STATE_ESN
|
|
msg.ReplayWindow = 0
|
|
}
|
|
|
|
limitsToLft(state.Limits, &msg.Lft)
|
|
req.AddData(msg)
|
|
|
|
if state.Auth != nil {
|
|
out := nl.NewRtAttr(nl.XFRMA_ALG_AUTH_TRUNC, writeStateAlgoAuth(state.Auth))
|
|
req.AddData(out)
|
|
}
|
|
if state.Crypt != nil {
|
|
out := nl.NewRtAttr(nl.XFRMA_ALG_CRYPT, writeStateAlgo(state.Crypt))
|
|
req.AddData(out)
|
|
}
|
|
if state.Aead != nil {
|
|
out := nl.NewRtAttr(nl.XFRMA_ALG_AEAD, writeStateAlgoAead(state.Aead))
|
|
req.AddData(out)
|
|
}
|
|
if state.Encap != nil {
|
|
encapData := make([]byte, nl.SizeofXfrmEncapTmpl)
|
|
encap := nl.DeserializeXfrmEncapTmpl(encapData)
|
|
encap.EncapType = uint16(state.Encap.Type)
|
|
encap.EncapSport = nl.Swap16(uint16(state.Encap.SrcPort))
|
|
encap.EncapDport = nl.Swap16(uint16(state.Encap.DstPort))
|
|
encap.EncapOa.FromIP(state.Encap.OriginalAddress)
|
|
out := nl.NewRtAttr(nl.XFRMA_ENCAP, encapData)
|
|
req.AddData(out)
|
|
}
|
|
if state.Mark != nil {
|
|
out := nl.NewRtAttr(nl.XFRMA_MARK, writeMark(state.Mark))
|
|
req.AddData(out)
|
|
}
|
|
if state.ESN {
|
|
out := nl.NewRtAttr(nl.XFRMA_REPLAY_ESN_VAL, writeReplayEsn(state.ReplayWindow))
|
|
req.AddData(out)
|
|
}
|
|
|
|
ifId := nl.NewRtAttr(nl.XFRMA_IF_ID, nl.Uint32Attr(uint32(state.Ifid)))
|
|
req.AddData(ifId)
|
|
|
|
_, err := req.Execute(unix.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)
|
|
|
|
msg := &nl.XfrmUserSpiInfo{}
|
|
msg.XfrmUsersaInfo = *(xfrmUsersaInfoFromXfrmState(state))
|
|
// 1-255 is reserved by IANA for future use
|
|
msg.Min = 0x100
|
|
msg.Max = 0xffffffff
|
|
req.AddData(msg)
|
|
|
|
if state.Mark != nil {
|
|
out := nl.NewRtAttr(nl.XFRMA_MARK, writeMark(state.Mark))
|
|
req.AddData(out)
|
|
}
|
|
|
|
msgs, err := req.Execute(unix.NETLINK_XFRM, 0)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return parseXfrmState(msgs[0], FAMILY_ALL)
|
|
}
|
|
|
|
// XfrmStateDel will delete an xfrm state from the system. Note that
|
|
// the Algos are ignored when matching the state to delete.
|
|
// Equivalent to: `ip xfrm state del $state`
|
|
func XfrmStateDel(state *XfrmState) error {
|
|
return pkgHandle.XfrmStateDel(state)
|
|
}
|
|
|
|
// XfrmStateDel will delete an xfrm state from the system. Note that
|
|
// the Algos are ignored when matching the state to delete.
|
|
// Equivalent to: `ip xfrm state del $state`
|
|
func (h *Handle) XfrmStateDel(state *XfrmState) error {
|
|
_, err := h.xfrmStateGetOrDelete(state, nl.XFRM_MSG_DELSA)
|
|
return err
|
|
}
|
|
|
|
// XfrmStateList gets a list of xfrm states in the system.
|
|
// Equivalent to: `ip [-4|-6] xfrm state show`.
|
|
// The list can be filtered by ip family.
|
|
func XfrmStateList(family int) ([]XfrmState, error) {
|
|
return pkgHandle.XfrmStateList(family)
|
|
}
|
|
|
|
// XfrmStateList gets a list of xfrm states in the system.
|
|
// 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)
|
|
|
|
msgs, err := req.Execute(unix.NETLINK_XFRM, nl.XFRM_MSG_NEWSA)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var res []XfrmState
|
|
for _, m := range msgs {
|
|
if state, err := parseXfrmState(m, family); err == nil {
|
|
res = append(res, *state)
|
|
} else if err == familyError {
|
|
continue
|
|
} else {
|
|
return nil, err
|
|
}
|
|
}
|
|
return res, nil
|
|
}
|
|
|
|
// XfrmStateGet gets the xfrm state described by the ID, if found.
|
|
// Equivalent to: `ip xfrm state get ID [ mark MARK [ mask MASK ] ]`.
|
|
// Only the fields which constitue the SA ID must be filled in:
|
|
// ID := [ src ADDR ] [ dst ADDR ] [ proto XFRM-PROTO ] [ spi SPI ]
|
|
// mark is optional
|
|
func XfrmStateGet(state *XfrmState) (*XfrmState, error) {
|
|
return pkgHandle.XfrmStateGet(state)
|
|
}
|
|
|
|
// XfrmStateGet gets the xfrm state described by the ID, if found.
|
|
// Equivalent to: `ip xfrm state get ID [ mark MARK [ mask MASK ] ]`.
|
|
// Only the fields which constitue the SA ID must be filled in:
|
|
// ID := [ src ADDR ] [ dst ADDR ] [ proto XFRM-PROTO ] [ spi SPI ]
|
|
// mark is optional
|
|
func (h *Handle) XfrmStateGet(state *XfrmState) (*XfrmState, error) {
|
|
return h.xfrmStateGetOrDelete(state, nl.XFRM_MSG_GETSA)
|
|
}
|
|
|
|
func (h *Handle) xfrmStateGetOrDelete(state *XfrmState, nlProto int) (*XfrmState, error) {
|
|
req := h.newNetlinkRequest(nlProto, unix.NLM_F_ACK)
|
|
|
|
msg := &nl.XfrmUsersaId{}
|
|
msg.Family = uint16(nl.GetIPFamily(state.Dst))
|
|
msg.Daddr.FromIP(state.Dst)
|
|
msg.Proto = uint8(state.Proto)
|
|
msg.Spi = nl.Swap32(uint32(state.Spi))
|
|
req.AddData(msg)
|
|
|
|
if state.Mark != nil {
|
|
out := nl.NewRtAttr(nl.XFRMA_MARK, writeMark(state.Mark))
|
|
req.AddData(out)
|
|
}
|
|
if state.Src != nil {
|
|
out := nl.NewRtAttr(nl.XFRMA_SRCADDR, state.Src.To16())
|
|
req.AddData(out)
|
|
}
|
|
|
|
ifId := nl.NewRtAttr(nl.XFRMA_IF_ID, nl.Uint32Attr(uint32(state.Ifid)))
|
|
req.AddData(ifId)
|
|
|
|
resType := nl.XFRM_MSG_NEWSA
|
|
if nlProto == nl.XFRM_MSG_DELSA {
|
|
resType = 0
|
|
}
|
|
|
|
msgs, err := req.Execute(unix.NETLINK_XFRM, uint16(resType))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if nlProto == nl.XFRM_MSG_DELSA {
|
|
return nil, nil
|
|
}
|
|
|
|
s, err := parseXfrmState(msgs[0], FAMILY_ALL)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return s, nil
|
|
}
|
|
|
|
var familyError = fmt.Errorf("family error")
|
|
|
|
func xfrmStateFromXfrmUsersaInfo(msg *nl.XfrmUsersaInfo) *XfrmState {
|
|
var state XfrmState
|
|
|
|
state.Dst = msg.Id.Daddr.ToIP()
|
|
state.Src = msg.Saddr.ToIP()
|
|
state.Proto = Proto(msg.Id.Proto)
|
|
state.Mode = Mode(msg.Mode)
|
|
state.Spi = int(nl.Swap32(msg.Id.Spi))
|
|
state.Reqid = int(msg.Reqid)
|
|
state.ReplayWindow = int(msg.ReplayWindow)
|
|
lftToLimits(&msg.Lft, &state.Limits)
|
|
curToStats(&msg.Curlft, &msg.Stats, &state.Statistics)
|
|
|
|
return &state
|
|
}
|
|
|
|
func parseXfrmState(m []byte, family int) (*XfrmState, error) {
|
|
msg := nl.DeserializeXfrmUsersaInfo(m)
|
|
|
|
// This is mainly for the state dump
|
|
if family != FAMILY_ALL && family != int(msg.Family) {
|
|
return nil, familyError
|
|
}
|
|
|
|
state := xfrmStateFromXfrmUsersaInfo(msg)
|
|
|
|
attrs, err := nl.ParseRouteAttr(m[nl.SizeofXfrmUsersaInfo:])
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for _, attr := range attrs {
|
|
switch attr.Attr.Type {
|
|
case nl.XFRMA_ALG_AUTH, nl.XFRMA_ALG_CRYPT:
|
|
var resAlgo *XfrmStateAlgo
|
|
if attr.Attr.Type == nl.XFRMA_ALG_AUTH {
|
|
if state.Auth == nil {
|
|
state.Auth = new(XfrmStateAlgo)
|
|
}
|
|
resAlgo = state.Auth
|
|
} else {
|
|
state.Crypt = new(XfrmStateAlgo)
|
|
resAlgo = state.Crypt
|
|
}
|
|
algo := nl.DeserializeXfrmAlgo(attr.Value[:])
|
|
(*resAlgo).Name = nl.BytesToString(algo.AlgName[:])
|
|
(*resAlgo).Key = algo.AlgKey
|
|
case nl.XFRMA_ALG_AUTH_TRUNC:
|
|
if state.Auth == nil {
|
|
state.Auth = new(XfrmStateAlgo)
|
|
}
|
|
algo := nl.DeserializeXfrmAlgoAuth(attr.Value[:])
|
|
state.Auth.Name = nl.BytesToString(algo.AlgName[:])
|
|
state.Auth.Key = algo.AlgKey
|
|
state.Auth.TruncateLen = int(algo.AlgTruncLen)
|
|
case nl.XFRMA_ALG_AEAD:
|
|
state.Aead = new(XfrmStateAlgo)
|
|
algo := nl.DeserializeXfrmAlgoAEAD(attr.Value[:])
|
|
state.Aead.Name = nl.BytesToString(algo.AlgName[:])
|
|
state.Aead.Key = algo.AlgKey
|
|
state.Aead.ICVLen = int(algo.AlgICVLen)
|
|
case nl.XFRMA_ENCAP:
|
|
encap := nl.DeserializeXfrmEncapTmpl(attr.Value[:])
|
|
state.Encap = new(XfrmStateEncap)
|
|
state.Encap.Type = EncapType(encap.EncapType)
|
|
state.Encap.SrcPort = int(nl.Swap16(encap.EncapSport))
|
|
state.Encap.DstPort = int(nl.Swap16(encap.EncapDport))
|
|
state.Encap.OriginalAddress = encap.EncapOa.ToIP()
|
|
case nl.XFRMA_MARK:
|
|
mark := nl.DeserializeXfrmMark(attr.Value[:])
|
|
state.Mark = new(XfrmMark)
|
|
state.Mark.Value = mark.Value
|
|
state.Mark.Mask = mark.Mask
|
|
case nl.XFRMA_IF_ID:
|
|
state.Ifid = int(native.Uint32(attr.Value))
|
|
}
|
|
}
|
|
|
|
return state, nil
|
|
}
|
|
|
|
// XfrmStateFlush will flush the xfrm state on the system.
|
|
// proto = 0 means any transformation protocols
|
|
// Equivalent to: `ip xfrm state flush [ proto XFRM-PROTO ]`
|
|
func XfrmStateFlush(proto Proto) error {
|
|
return pkgHandle.XfrmStateFlush(proto)
|
|
}
|
|
|
|
// XfrmStateFlush will flush the xfrm state on the system.
|
|
// 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.AddData(&nl.XfrmUsersaFlush{Proto: uint8(proto)})
|
|
|
|
_, err := req.Execute(unix.NETLINK_XFRM, 0)
|
|
return err
|
|
}
|
|
|
|
func limitsToLft(lmts XfrmStateLimits, lft *nl.XfrmLifetimeCfg) {
|
|
if lmts.ByteSoft != 0 {
|
|
lft.SoftByteLimit = lmts.ByteSoft
|
|
} else {
|
|
lft.SoftByteLimit = nl.XFRM_INF
|
|
}
|
|
if lmts.ByteHard != 0 {
|
|
lft.HardByteLimit = lmts.ByteHard
|
|
} else {
|
|
lft.HardByteLimit = nl.XFRM_INF
|
|
}
|
|
if lmts.PacketSoft != 0 {
|
|
lft.SoftPacketLimit = lmts.PacketSoft
|
|
} else {
|
|
lft.SoftPacketLimit = nl.XFRM_INF
|
|
}
|
|
if lmts.PacketHard != 0 {
|
|
lft.HardPacketLimit = lmts.PacketHard
|
|
} else {
|
|
lft.HardPacketLimit = nl.XFRM_INF
|
|
}
|
|
lft.SoftAddExpiresSeconds = lmts.TimeSoft
|
|
lft.HardAddExpiresSeconds = lmts.TimeHard
|
|
lft.SoftUseExpiresSeconds = lmts.TimeUseSoft
|
|
lft.HardUseExpiresSeconds = lmts.TimeUseHard
|
|
}
|
|
|
|
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))
|
|
msg.Id.Daddr.FromIP(state.Dst)
|
|
msg.Saddr.FromIP(state.Src)
|
|
msg.Id.Proto = uint8(state.Proto)
|
|
msg.Mode = uint8(state.Mode)
|
|
msg.Id.Spi = nl.Swap32(uint32(state.Spi))
|
|
msg.Reqid = uint32(state.Reqid)
|
|
msg.ReplayWindow = uint8(state.ReplayWindow)
|
|
|
|
return msg
|
|
}
|