mirror of
https://github.com/jsimonetti/rtnetlink.git
synced 2026-03-28 07:21:07 +01:00
conn: remove constants
This commit is contained in:
parent
c6cbc0b2e8
commit
0fde162496
26
conn.go
26
conn.go
@ -4,11 +4,7 @@ import (
|
||||
"encoding"
|
||||
|
||||
"github.com/mdlayher/netlink"
|
||||
)
|
||||
|
||||
const (
|
||||
// Protocol is the netlink protocol constant used to specify rtnetlink.
|
||||
Protocol = 0x0
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// A Conn is a route netlink connection. A Conn can be used to send and
|
||||
@ -34,7 +30,7 @@ type conn interface {
|
||||
// configuration for the underlying netlink connection. If config is
|
||||
// nil, a default configuration will be used.
|
||||
func Dial(config *netlink.Config) (*Conn, error) {
|
||||
c, err := netlink.Dial(Protocol, config)
|
||||
c, err := netlink.Dial(unix.NETLINK_ROUTE, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -162,23 +158,23 @@ func unpackMessages(msgs []netlink.Message) ([]Message, error) {
|
||||
for _, nm := range msgs {
|
||||
var m Message
|
||||
switch nm.Header.Type {
|
||||
case RTM_GETLINK:
|
||||
case unix.RTM_GETLINK:
|
||||
fallthrough
|
||||
case RTM_NEWLINK:
|
||||
case unix.RTM_NEWLINK:
|
||||
fallthrough
|
||||
case RTM_DELLINK:
|
||||
case unix.RTM_DELLINK:
|
||||
m = &LinkMessage{}
|
||||
case RTM_GETADDR:
|
||||
case unix.RTM_GETADDR:
|
||||
fallthrough
|
||||
case RTM_NEWADDR:
|
||||
case unix.RTM_NEWADDR:
|
||||
fallthrough
|
||||
case RTM_DELADDR:
|
||||
case unix.RTM_DELADDR:
|
||||
m = &AddressMessage{}
|
||||
case RTM_GETROUTE:
|
||||
case unix.RTM_GETROUTE:
|
||||
fallthrough
|
||||
case RTM_NEWROUTE:
|
||||
case unix.RTM_NEWROUTE:
|
||||
fallthrough
|
||||
case RTM_DELROUTE:
|
||||
case unix.RTM_DELROUTE:
|
||||
m = &RouteMessage{}
|
||||
default:
|
||||
continue
|
||||
|
||||
15
conn_test.go
15
conn_test.go
@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/mdlayher/netlink"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func TestConnExecute(t *testing.T) {
|
||||
@ -15,7 +16,7 @@ func TestConnExecute(t *testing.T) {
|
||||
|
||||
wantnl := netlink.Message{
|
||||
Header: netlink.Header{
|
||||
Type: RTM_GETLINK,
|
||||
Type: unix.RTM_GETLINK,
|
||||
Flags: netlink.Request,
|
||||
// Sequence and PID not set because we are mocking the underlying
|
||||
// netlink connection.
|
||||
@ -36,7 +37,7 @@ func TestConnExecute(t *testing.T) {
|
||||
tc.receive = []netlink.Message{{
|
||||
Header: netlink.Header{
|
||||
Length: 16,
|
||||
Type: RTM_GETLINK,
|
||||
Type: unix.RTM_GETLINK,
|
||||
// Sequence and PID not set because we are mocking the underlying
|
||||
// netlink connection.
|
||||
},
|
||||
@ -46,7 +47,7 @@ func TestConnExecute(t *testing.T) {
|
||||
},
|
||||
}}
|
||||
|
||||
msgs, err := c.Execute(req, RTM_GETLINK, netlink.Request)
|
||||
msgs, err := c.Execute(req, unix.RTM_GETLINK, netlink.Request)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to execute: %v", err)
|
||||
}
|
||||
@ -72,7 +73,7 @@ func TestConnSend(t *testing.T) {
|
||||
|
||||
c, tc := testConn(t)
|
||||
|
||||
nlreq, err := c.Send(req, RTM_GETLINK, netlink.Request)
|
||||
nlreq, err := c.Send(req, unix.RTM_GETLINK, netlink.Request)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to send: %v", err)
|
||||
}
|
||||
@ -84,7 +85,7 @@ func TestConnSend(t *testing.T) {
|
||||
|
||||
want := netlink.Message{
|
||||
Header: netlink.Header{
|
||||
Type: RTM_GETLINK,
|
||||
Type: unix.RTM_GETLINK,
|
||||
Flags: netlink.Request,
|
||||
},
|
||||
Data: reqb,
|
||||
@ -107,7 +108,7 @@ func TestConnReceive(t *testing.T) {
|
||||
Header: netlink.Header{
|
||||
Length: 16,
|
||||
Sequence: 1,
|
||||
Type: RTM_GETLINK,
|
||||
Type: unix.RTM_GETLINK,
|
||||
PID: uint32(os.Getpid()),
|
||||
},
|
||||
Data: []byte{
|
||||
@ -119,7 +120,7 @@ func TestConnReceive(t *testing.T) {
|
||||
Header: netlink.Header{
|
||||
Length: 16,
|
||||
Sequence: 1,
|
||||
Type: RTM_GETLINK,
|
||||
Type: unix.RTM_GETLINK,
|
||||
PID: uint32(os.Getpid()),
|
||||
},
|
||||
Data: []byte{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user