From d9882a62ff6e4e06e8244d5bdf9c294680981d6a Mon Sep 17 00:00:00 2001 From: Alexandr Morozov Date: Fri, 30 May 2014 13:12:02 +0400 Subject: [PATCH] Atomically increment sequence in pkg/netlink Docker-DCO-1.1-Signed-off-by: Alexandr Morozov (github: LK4D4) --- netlink/netlink_linux.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/netlink/netlink_linux.go b/netlink/netlink_linux.go index 21d4593..14e30aa 100644 --- a/netlink/netlink_linux.go +++ b/netlink/netlink_linux.go @@ -7,6 +7,7 @@ import ( "fmt" "math/rand" "net" + "sync/atomic" "syscall" "unsafe" ) @@ -22,7 +23,7 @@ const ( SIOC_BRADDIF = 0x89a2 ) -var nextSeqNr int +var nextSeqNr uint32 type ifreqHwaddr struct { IfrnName [16]byte @@ -42,11 +43,6 @@ func nativeEndian() binary.ByteOrder { return binary.LittleEndian } -func getSeq() int { - nextSeqNr = nextSeqNr + 1 - return nextSeqNr -} - func getIpFamily(ip net.IP) int { if len(ip) <= net.IPv4len { return syscall.AF_INET @@ -266,7 +262,7 @@ func newNetlinkRequest(proto, flags int) *NetlinkRequest { Len: uint32(syscall.NLMSG_HDRLEN), Type: uint16(proto), Flags: syscall.NLM_F_REQUEST | uint16(flags), - Seq: uint32(getSeq()), + Seq: atomic.AddUint32(&nextSeqNr, 1), }, } }