@@ -4,10 +4,10 @@ import (
4
4
"fmt"
5
5
"net"
6
6
"strings"
7
- "syscall"
8
7
9
8
"github.com/vishvananda/netlink/nl"
10
9
"github.com/vishvananda/netns"
10
+ "golang.org/x/sys/unix"
11
11
)
12
12
13
13
// IFA_FLAGS is a u32 attribute.
@@ -22,7 +22,7 @@ func AddrAdd(link Link, addr *Addr) error {
22
22
// AddrAdd will add an IP address to a link device.
23
23
// Equivalent to: `ip addr add $addr dev $link`
24
24
func (h * Handle ) AddrAdd (link Link , addr * Addr ) error {
25
- req := h .newNetlinkRequest (syscall .RTM_NEWADDR , syscall .NLM_F_CREATE | syscall .NLM_F_EXCL | syscall .NLM_F_ACK )
25
+ req := h .newNetlinkRequest (unix .RTM_NEWADDR , unix .NLM_F_CREATE | unix .NLM_F_EXCL | unix .NLM_F_ACK )
26
26
return h .addrHandle (link , addr , req )
27
27
}
28
28
@@ -35,7 +35,7 @@ func AddrReplace(link Link, addr *Addr) error {
35
35
// AddrReplace will replace (or, if not present, add) an IP address on a link device.
36
36
// Equivalent to: `ip addr replace $addr dev $link`
37
37
func (h * Handle ) AddrReplace (link Link , addr * Addr ) error {
38
- req := h .newNetlinkRequest (syscall .RTM_NEWADDR , syscall .NLM_F_CREATE | syscall .NLM_F_REPLACE | syscall .NLM_F_ACK )
38
+ req := h .newNetlinkRequest (unix .RTM_NEWADDR , unix .NLM_F_CREATE | unix .NLM_F_REPLACE | unix .NLM_F_ACK )
39
39
return h .addrHandle (link , addr , req )
40
40
}
41
41
@@ -48,7 +48,7 @@ func AddrDel(link Link, addr *Addr) error {
48
48
// AddrDel will delete an IP address from a link device.
49
49
// Equivalent to: `ip addr del $addr dev $link`
50
50
func (h * Handle ) AddrDel (link Link , addr * Addr ) error {
51
- req := h .newNetlinkRequest (syscall .RTM_DELADDR , syscall .NLM_F_ACK )
51
+ req := h .newNetlinkRequest (unix .RTM_DELADDR , unix .NLM_F_ACK )
52
52
return h .addrHandle (link , addr , req )
53
53
}
54
54
@@ -75,7 +75,7 @@ func (h *Handle) addrHandle(link Link, addr *Addr, req *nl.NetlinkRequest) error
75
75
localAddrData = addr .IP .To16 ()
76
76
}
77
77
78
- localData := nl .NewRtAttr (syscall .IFA_LOCAL , localAddrData )
78
+ localData := nl .NewRtAttr (unix .IFA_LOCAL , localAddrData )
79
79
req .AddData (localData )
80
80
var peerAddrData []byte
81
81
if addr .Peer != nil {
@@ -88,7 +88,7 @@ func (h *Handle) addrHandle(link Link, addr *Addr, req *nl.NetlinkRequest) error
88
88
peerAddrData = localAddrData
89
89
}
90
90
91
- addressData := nl .NewRtAttr (syscall .IFA_ADDRESS , peerAddrData )
91
+ addressData := nl .NewRtAttr (unix .IFA_ADDRESS , peerAddrData )
92
92
req .AddData (addressData )
93
93
94
94
if addr .Flags != 0 {
@@ -109,14 +109,14 @@ func (h *Handle) addrHandle(link Link, addr *Addr, req *nl.NetlinkRequest) error
109
109
}
110
110
addr .Broadcast = calcBroadcast
111
111
}
112
- req .AddData (nl .NewRtAttr (syscall .IFA_BROADCAST , addr .Broadcast ))
112
+ req .AddData (nl .NewRtAttr (unix .IFA_BROADCAST , addr .Broadcast ))
113
113
114
114
if addr .Label != "" {
115
- labelData := nl .NewRtAttr (syscall .IFA_LABEL , nl .ZeroTerminated (addr .Label ))
115
+ labelData := nl .NewRtAttr (unix .IFA_LABEL , nl .ZeroTerminated (addr .Label ))
116
116
req .AddData (labelData )
117
117
}
118
118
119
- _ , err := req .Execute (syscall .NETLINK_ROUTE , 0 )
119
+ _ , err := req .Execute (unix .NETLINK_ROUTE , 0 )
120
120
return err
121
121
}
122
122
@@ -131,11 +131,11 @@ func AddrList(link Link, family int) ([]Addr, error) {
131
131
// Equivalent to: `ip addr show`.
132
132
// The list can be filtered by link and ip family.
133
133
func (h * Handle ) AddrList (link Link , family int ) ([]Addr , error ) {
134
- req := h .newNetlinkRequest (syscall .RTM_GETADDR , syscall .NLM_F_DUMP )
134
+ req := h .newNetlinkRequest (unix .RTM_GETADDR , unix .NLM_F_DUMP )
135
135
msg := nl .NewIfInfomsg (family )
136
136
req .AddData (msg )
137
137
138
- msgs , err := req .Execute (syscall .NETLINK_ROUTE , syscall .RTM_NEWADDR )
138
+ msgs , err := req .Execute (unix .NETLINK_ROUTE , unix .RTM_NEWADDR )
139
139
if err != nil {
140
140
return nil , err
141
141
}
@@ -187,21 +187,21 @@ func parseAddr(m []byte) (addr Addr, family, index int, err error) {
187
187
var local , dst * net.IPNet
188
188
for _ , attr := range attrs {
189
189
switch attr .Attr .Type {
190
- case syscall .IFA_ADDRESS :
190
+ case unix .IFA_ADDRESS :
191
191
dst = & net.IPNet {
192
192
IP : attr .Value ,
193
193
Mask : net .CIDRMask (int (msg .Prefixlen ), 8 * len (attr .Value )),
194
194
}
195
195
addr .Peer = dst
196
- case syscall .IFA_LOCAL :
196
+ case unix .IFA_LOCAL :
197
197
local = & net.IPNet {
198
198
IP : attr .Value ,
199
199
Mask : net .CIDRMask (int (msg .Prefixlen ), 8 * len (attr .Value )),
200
200
}
201
201
addr .IPNet = local
202
- case syscall .IFA_BROADCAST :
202
+ case unix .IFA_BROADCAST :
203
203
addr .Broadcast = attr .Value
204
- case syscall .IFA_LABEL :
204
+ case unix .IFA_LABEL :
205
205
addr .Label = string (attr .Value [:len (attr .Value )- 1 ])
206
206
case IFA_FLAGS :
207
207
addr .Flags = int (native .Uint32 (attr .Value [0 :4 ]))
@@ -264,7 +264,7 @@ func AddrSubscribeWithOptions(ch chan<- AddrUpdate, done <-chan struct{}, option
264
264
}
265
265
266
266
func addrSubscribeAt (newNs , curNs netns.NsHandle , ch chan <- AddrUpdate , done <- chan struct {}, cberr func (error )) error {
267
- s , err := nl .SubscribeAt (newNs , curNs , syscall .NETLINK_ROUTE , syscall .RTNLGRP_IPV4_IFADDR , syscall .RTNLGRP_IPV6_IFADDR )
267
+ s , err := nl .SubscribeAt (newNs , curNs , unix .NETLINK_ROUTE , unix .RTNLGRP_IPV4_IFADDR , unix .RTNLGRP_IPV6_IFADDR )
268
268
if err != nil {
269
269
return err
270
270
}
@@ -286,7 +286,7 @@ func addrSubscribeAt(newNs, curNs netns.NsHandle, ch chan<- AddrUpdate, done <-c
286
286
}
287
287
for _ , m := range msgs {
288
288
msgType := m .Header .Type
289
- if msgType != syscall .RTM_NEWADDR && msgType != syscall .RTM_DELADDR {
289
+ if msgType != unix .RTM_NEWADDR && msgType != unix .RTM_DELADDR {
290
290
if cberr != nil {
291
291
cberr (fmt .Errorf ("bad message type: %d" , msgType ))
292
292
}
@@ -303,7 +303,7 @@ func addrSubscribeAt(newNs, curNs netns.NsHandle, ch chan<- AddrUpdate, done <-c
303
303
304
304
ch <- AddrUpdate {LinkAddress : * addr .IPNet ,
305
305
LinkIndex : ifindex ,
306
- NewAddr : msgType == syscall .RTM_NEWADDR ,
306
+ NewAddr : msgType == unix .RTM_NEWADDR ,
307
307
Flags : addr .Flags ,
308
308
Scope : addr .Scope ,
309
309
PreferedLft : addr .PreferedLft ,
0 commit comments