Atomically increment sequence in pkg/netlink
Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)
This commit is contained in:
parent
c7135d73d3
commit
d9882a62ff
1 changed files with 3 additions and 7 deletions
|
@ -7,6 +7,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
|
"sync/atomic"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
@ -22,7 +23,7 @@ const (
|
||||||
SIOC_BRADDIF = 0x89a2
|
SIOC_BRADDIF = 0x89a2
|
||||||
)
|
)
|
||||||
|
|
||||||
var nextSeqNr int
|
var nextSeqNr uint32
|
||||||
|
|
||||||
type ifreqHwaddr struct {
|
type ifreqHwaddr struct {
|
||||||
IfrnName [16]byte
|
IfrnName [16]byte
|
||||||
|
@ -42,11 +43,6 @@ func nativeEndian() binary.ByteOrder {
|
||||||
return binary.LittleEndian
|
return binary.LittleEndian
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSeq() int {
|
|
||||||
nextSeqNr = nextSeqNr + 1
|
|
||||||
return nextSeqNr
|
|
||||||
}
|
|
||||||
|
|
||||||
func getIpFamily(ip net.IP) int {
|
func getIpFamily(ip net.IP) int {
|
||||||
if len(ip) <= net.IPv4len {
|
if len(ip) <= net.IPv4len {
|
||||||
return syscall.AF_INET
|
return syscall.AF_INET
|
||||||
|
@ -266,7 +262,7 @@ func newNetlinkRequest(proto, flags int) *NetlinkRequest {
|
||||||
Len: uint32(syscall.NLMSG_HDRLEN),
|
Len: uint32(syscall.NLMSG_HDRLEN),
|
||||||
Type: uint16(proto),
|
Type: uint16(proto),
|
||||||
Flags: syscall.NLM_F_REQUEST | uint16(flags),
|
Flags: syscall.NLM_F_REQUEST | uint16(flags),
|
||||||
Seq: uint32(getSeq()),
|
Seq: atomic.AddUint32(&nextSeqNr, 1),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue