mirror of
https://github.com/jsimonetti/rtnetlink.git
synced 2026-04-02 10:51:18 +02:00
Add XDP encode/decoder (#91)
Signed-off-by: Lehner Florian <dev@der-flo.net>
This commit is contained in:
parent
7196e82636
commit
b76ef30e43
2
go.mod
2
go.mod
@ -5,5 +5,5 @@ go 1.12
|
||||
require (
|
||||
github.com/google/go-cmp v0.5.2
|
||||
github.com/mdlayher/netlink v1.1.1
|
||||
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634
|
||||
golang.org/x/sys v0.0.0-20201101102859-da207088b7d1
|
||||
)
|
||||
|
||||
2
go.sum
2
go.sum
@ -34,6 +34,8 @@ golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634 h1:bNEHhJCnrwMKNMmOx3yAynp5vs5/gRy+XWFtZFu7NBM=
|
||||
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201101102859-da207088b7d1 h1:a/mKvvZr9Jcc8oKfcmgzyp7OwF73JPWsQLvH1z2Kxck=
|
||||
golang.org/x/sys v0.0.0-20201101102859-da207088b7d1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
|
||||
@ -59,6 +59,12 @@ const (
|
||||
IFLA_INFO_SLAVE_KIND = linux.IFLA_INFO_SLAVE_KIND
|
||||
IFLA_INFO_DATA = linux.IFLA_INFO_DATA
|
||||
IFLA_INFO_SLAVE_DATA = linux.IFLA_INFO_SLAVE_DATA
|
||||
IFLA_XDP = linux.IFLA_XDP
|
||||
IFLA_XDP_FD = linux.IFLA_XDP_FD
|
||||
IFLA_XDP_ATTACHED = linux.IFLA_XDP_ATTACHED
|
||||
IFLA_XDP_FLAGS = linux.IFLA_XDP_FLAGS
|
||||
IFLA_XDP_PROG_ID = linux.IFLA_XDP_PROG_ID
|
||||
IFLA_XDP_EXPECTED_FD = linux.IFLA_XDP_EXPECTED_FD
|
||||
NDA_UNSPEC = linux.NDA_UNSPEC
|
||||
NDA_DST = linux.NDA_DST
|
||||
NDA_LLADDR = linux.NDA_LLADDR
|
||||
|
||||
@ -55,6 +55,12 @@ const (
|
||||
IFLA_INFO_SLAVE_KIND = 0x4
|
||||
IFLA_INFO_DATA = 0x2
|
||||
IFLA_INFO_SLAVE_DATA = 0x5
|
||||
IFLA_XDP = 0x2b
|
||||
IFLA_XDP_FD = 0x1
|
||||
IFLA_XDP_ATTACHED = 0x2
|
||||
IFLA_XDP_FLAGS = 0x3
|
||||
IFLA_XDP_PROG_ID = 0x4
|
||||
IFLA_XDP_EXPECTED_FD = 0x8
|
||||
NDA_UNSPEC = 0x0
|
||||
NDA_DST = 0x1
|
||||
NDA_LLADDR = 0x2
|
||||
|
||||
59
link.go
59
link.go
@ -221,6 +221,7 @@ type LinkAttributes struct {
|
||||
Stats *LinkStats // Interface Statistics
|
||||
Stats64 *LinkStats64 // Interface Statistics (64 bits version)
|
||||
Info *LinkInfo // Detailed Interface Information
|
||||
XDP *LinkXDP // Express Data Patch Information
|
||||
}
|
||||
|
||||
// OperationalState represents an interface's operational state.
|
||||
@ -286,6 +287,9 @@ func (a *LinkAttributes) decode(ad *netlink.AttributeDecoder) error {
|
||||
case unix.IFLA_MASTER:
|
||||
v := ad.Uint32()
|
||||
a.Master = &v
|
||||
case unix.IFLA_XDP:
|
||||
a.XDP = &LinkXDP{}
|
||||
ad.Nested(a.XDP.decode)
|
||||
}
|
||||
}
|
||||
|
||||
@ -330,6 +334,22 @@ func (a *LinkAttributes) encode(ae *netlink.AttributeEncoder) error {
|
||||
ae.Bytes(unix.IFLA_LINKINFO, b)
|
||||
}
|
||||
|
||||
if a.XDP != nil {
|
||||
nae := netlink.NewAttributeEncoder()
|
||||
nae.ByteOrder = ae.ByteOrder
|
||||
|
||||
err := a.XDP.encode(nae)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b, err := nae.Encode()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ae.Bytes(unix.IFLA_XDP, b)
|
||||
}
|
||||
|
||||
if a.Master != nil {
|
||||
ae.Uint32(unix.IFLA_MASTER, *a.Master)
|
||||
}
|
||||
@ -526,3 +546,42 @@ func (i *LinkInfo) encode(ae *netlink.AttributeEncoder) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LinkXDP holds Express Data Path specific information
|
||||
type LinkXDP struct {
|
||||
FD uint32
|
||||
ExpectedFD uint32
|
||||
Attached uint8
|
||||
Flags uint32
|
||||
ProgID uint32
|
||||
}
|
||||
|
||||
func (xdp *LinkXDP) decode(ad *netlink.AttributeDecoder) error {
|
||||
|
||||
for ad.Next() {
|
||||
switch ad.Type() {
|
||||
case unix.IFLA_XDP_FD:
|
||||
xdp.FD = ad.Uint32()
|
||||
case unix.IFLA_XDP_EXPECTED_FD:
|
||||
xdp.ExpectedFD = ad.Uint32()
|
||||
case unix.IFLA_XDP_ATTACHED:
|
||||
xdp.Attached = ad.Uint8()
|
||||
case unix.IFLA_XDP_FLAGS:
|
||||
xdp.Flags = ad.Uint32()
|
||||
case unix.IFLA_XDP_PROG_ID:
|
||||
xdp.ProgID = ad.Uint32()
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (xdp *LinkXDP) encode(ae *netlink.AttributeEncoder) error {
|
||||
|
||||
ae.Uint32(unix.IFLA_XDP_FD, xdp.FD)
|
||||
ae.Uint32(unix.IFLA_XDP_EXPECTED_FD, xdp.ExpectedFD)
|
||||
ae.Uint8(unix.IFLA_XDP_ATTACHED, xdp.Attached)
|
||||
ae.Uint32(unix.IFLA_XDP_FLAGS, xdp.Flags)
|
||||
ae.Uint32(unix.IFLA_XDP_PROG_ID, xdp.ProgID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user