Skip to content

Commit

Permalink
Use IFLA_* constants from x/sys/unix
Browse files Browse the repository at this point in the history
The IFLA_* constants in in x/sys/unix were updated to Linux 4.15 in
golang/sys@88d2dcc51026, so use these instead of locally duplicating
them.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
  • Loading branch information
tklauser authored and Flavio Crisciani committed Feb 23, 2018
1 parent 25d2c79 commit 5236321
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 42 deletions.
6 changes: 3 additions & 3 deletions bridge_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ 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.AddData(msg)
req.AddData(nl.NewRtAttr(nl.IFLA_EXT_MASK, nl.Uint32Attr(uint32(nl.RTEXT_FILTER_BRVLAN))))
req.AddData(nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(uint32(nl.RTEXT_FILTER_BRVLAN))))

msgs, err := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWLINK)
if err != nil {
Expand All @@ -35,7 +35,7 @@ func (h *Handle) BridgeVlanList() (map[int32][]*nl.BridgeVlanInfo, error) {
}
for _, attr := range attrs {
switch attr.Attr.Type {
case nl.IFLA_AF_SPEC:
case unix.IFLA_AF_SPEC:
//nested attr
nestAttrs, err := nl.ParseRouteAttr(attr.Value)
if err != nil {
Expand Down Expand Up @@ -87,7 +87,7 @@ func (h *Handle) bridgeVlanModify(cmd int, link Link, vid uint16, pvid, untagged
msg.Index = int32(base.Index)
req.AddData(msg)

br := nl.NewRtAttr(nl.IFLA_AF_SPEC, nil)
br := nl.NewRtAttr(unix.IFLA_AF_SPEC, nil)
var flags uint16
if self {
flags |= nl.BRIDGE_FLAGS_SELF
Expand Down
27 changes: 13 additions & 14 deletions link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
const (
SizeofLinkStats32 = 0x5c
SizeofLinkStats64 = 0xd8
IFLA_STATS64 = 0x17 // syscall pkg does not contain this one
)

const (
Expand Down Expand Up @@ -378,7 +377,7 @@ func (h *Handle) LinkSetVfHardwareAddr(link Link, vf int, hwaddr net.HardwareAdd
msg.Index = int32(base.Index)
req.AddData(msg)

data := nl.NewRtAttr(nl.IFLA_VFINFO_LIST, nil)
data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil)
info := nl.NewRtAttrChild(data, nl.IFLA_VF_INFO, nil)
vfmsg := nl.VfMac{
Vf: uint32(vf),
Expand Down Expand Up @@ -408,7 +407,7 @@ func (h *Handle) LinkSetVfVlan(link Link, vf, vlan int) error {
msg.Index = int32(base.Index)
req.AddData(msg)

data := nl.NewRtAttr(nl.IFLA_VFINFO_LIST, nil)
data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil)
info := nl.NewRtAttrChild(data, nl.IFLA_VF_INFO, nil)
vfmsg := nl.VfVlan{
Vf: uint32(vf),
Expand Down Expand Up @@ -438,7 +437,7 @@ func (h *Handle) LinkSetVfTxRate(link Link, vf, rate int) error {
msg.Index = int32(base.Index)
req.AddData(msg)

data := nl.NewRtAttr(nl.IFLA_VFINFO_LIST, nil)
data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil)
info := nl.NewRtAttrChild(data, nl.IFLA_VF_INFO, nil)
vfmsg := nl.VfTxRate{
Vf: uint32(vf),
Expand Down Expand Up @@ -469,7 +468,7 @@ func (h *Handle) LinkSetVfSpoofchk(link Link, vf int, check bool) error {
msg.Index = int32(base.Index)
req.AddData(msg)

data := nl.NewRtAttr(nl.IFLA_VFINFO_LIST, nil)
data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil)
info := nl.NewRtAttrChild(data, nl.IFLA_VF_INFO, nil)
if check {
setting = 1
Expand Down Expand Up @@ -503,7 +502,7 @@ func (h *Handle) LinkSetVfTrust(link Link, vf int, state bool) error {
msg.Index = int32(base.Index)
req.AddData(msg)

data := nl.NewRtAttr(nl.IFLA_VFINFO_LIST, nil)
data := nl.NewRtAttr(unix.IFLA_VFINFO_LIST, nil)
info := nl.NewRtAttrChild(data, nl.IFLA_VF_INFO, nil)
if state {
setting = 1
Expand Down Expand Up @@ -630,7 +629,7 @@ func (h *Handle) LinkSetNsFd(link Link, fd int) error {
b := make([]byte, 4)
native.PutUint32(b, uint32(fd))

data := nl.NewRtAttr(nl.IFLA_NET_NS_FD, b)
data := nl.NewRtAttr(unix.IFLA_NET_NS_FD, b)
req.AddData(data)

_, err := req.Execute(unix.NETLINK_ROUTE, 0)
Expand Down Expand Up @@ -1002,12 +1001,12 @@ func (h *Handle) linkModify(link Link, flags int) error {
}

if base.NumTxQueues > 0 {
txqueues := nl.NewRtAttr(nl.IFLA_NUM_TX_QUEUES, nl.Uint32Attr(uint32(base.NumTxQueues)))
txqueues := nl.NewRtAttr(unix.IFLA_NUM_TX_QUEUES, nl.Uint32Attr(uint32(base.NumTxQueues)))
req.AddData(txqueues)
}

if base.NumRxQueues > 0 {
rxqueues := nl.NewRtAttr(nl.IFLA_NUM_RX_QUEUES, nl.Uint32Attr(uint32(base.NumRxQueues)))
rxqueues := nl.NewRtAttr(unix.IFLA_NUM_RX_QUEUES, nl.Uint32Attr(uint32(base.NumRxQueues)))
req.AddData(rxqueues)
}

Expand All @@ -1019,7 +1018,7 @@ func (h *Handle) linkModify(link Link, flags int) error {
attr = nl.NewRtAttr(unix.IFLA_NET_NS_PID, val)
case NsFd:
val := nl.Uint32Attr(uint32(base.Namespace.(NsFd)))
attr = nl.NewRtAttr(nl.IFLA_NET_NS_FD, val)
attr = nl.NewRtAttr(unix.IFLA_NET_NS_FD, val)
}

req.AddData(attr)
Expand Down Expand Up @@ -1394,9 +1393,9 @@ func LinkDeserialize(hdr *unix.NlMsghdr, m []byte) (Link, error) {
base.Alias = string(attr.Value[:len(attr.Value)-1])
case unix.IFLA_STATS:
stats32 = attr.Value[:]
case IFLA_STATS64:
case unix.IFLA_STATS64:
stats64 = attr.Value[:]
case nl.IFLA_XDP:
case unix.IFLA_XDP:
xdp, err := parseLinkXdp(attr.Value[:])
if err != nil {
return nil, err
Expand All @@ -1413,7 +1412,7 @@ func LinkDeserialize(hdr *unix.NlMsghdr, m []byte) (Link, error) {
}
case unix.IFLA_OPERSTATE:
base.OperState = LinkOperState(uint8(attr.Value[0]))
case nl.IFLA_LINK_NETNSID:
case unix.IFLA_LINK_NETNSID:
base.NetNsID = int(native.Uint32(attr.Value[0:4]))
}
}
Expand Down Expand Up @@ -2048,7 +2047,7 @@ func parseLinkStats64(data []byte) *LinkStatistics {
}

func addXdpAttrs(xdp *LinkXdp, req *nl.NetlinkRequest) {
attrs := nl.NewRtAttr(nl.IFLA_XDP|unix.NLA_F_NESTED, nil)
attrs := nl.NewRtAttr(unix.IFLA_XDP|unix.NLA_F_NESTED, nil)
b := make([]byte, 4)
native.PutUint32(b, uint32(xdp.Fd))
nl.NewRtAttrChild(attrs, nl.IFLA_XDP_FD, b)
Expand Down
25 changes: 0 additions & 25 deletions nl/link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,10 @@ package nl

import (
"unsafe"

"golang.org/x/sys/unix"
)

const (
DEFAULT_CHANGE = 0xFFFFFFFF
// doesn't exist in syscall
IFLA_VFINFO_LIST = unix.IFLA_IFALIAS + 1 + iota
IFLA_STATS64
IFLA_VF_PORTS
IFLA_PORT_SELF
IFLA_AF_SPEC
IFLA_GROUP
IFLA_NET_NS_FD
IFLA_EXT_MASK
IFLA_PROMISCUITY
IFLA_NUM_TX_QUEUES
IFLA_NUM_RX_QUEUES
IFLA_CARRIER
IFLA_PHYS_PORT_ID
IFLA_CARRIER_CHANGES
IFLA_PHYS_SWITCH_ID
IFLA_LINK_NETNSID
IFLA_PHYS_PORT_NAME
IFLA_PROTO_DOWN
IFLA_GSO_MAX_SEGS
IFLA_GSO_MAX_SIZE
IFLA_PAD
IFLA_XDP
)

const (
Expand Down

0 comments on commit 5236321

Please sign in to comment.