From 5e41be0666fc2bf14eecbe6bebcd2b124f5f179e Mon Sep 17 00:00:00 2001 From: Julian Kornberger Date: Wed, 31 Oct 2018 13:30:13 +0100 Subject: [PATCH] Fix parsing of packets and bytes --- ipset_linux.go | 10 ++++++++-- nl/parse_attr.go | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/ipset_linux.go b/ipset_linux.go index bec5e2dc..8543762d 100644 --- a/ipset_linux.go +++ b/ipset_linux.go @@ -15,8 +15,8 @@ type IPSetEntry struct { MAC net.HardwareAddr IP net.IP Timeout *uint32 - Packets *uint32 - Bytes *uint32 + Packets *uint64 + Bytes *uint64 Replace bool // replace existing entry } @@ -303,6 +303,12 @@ func parseIPSetEntry(data []byte) (entry IPSetEntry) { case nl.IPSET_ATTR_TIMEOUT | nl.NLA_F_NET_BYTEORDER: val := attr.Uint32() entry.Timeout = &val + case nl.IPSET_ATTR_BYTES | nl.NLA_F_NET_BYTEORDER: + val := attr.Uint64() + entry.Bytes = &val + case nl.IPSET_ATTR_PACKETS | nl.NLA_F_NET_BYTEORDER: + val := attr.Uint64() + entry.Packets = &val case nl.IPSET_ATTR_ETHER: entry.MAC = net.HardwareAddr(attr.Value) case nl.IPSET_ATTR_COMMENT: diff --git a/nl/parse_attr.go b/nl/parse_attr.go index dcec2981..19eb8f28 100644 --- a/nl/parse_attr.go +++ b/nl/parse_attr.go @@ -56,3 +56,12 @@ func (attr *Attribute) Uint32() uint32 { return NativeEndian().Uint32(attr.Value) } } + +// Uint64 returns the uint64 value respecting the NET_BYTEORDER flag +func (attr *Attribute) Uint64() uint64 { + if attr.Type&NLA_F_NET_BYTEORDER != 0 { + return binary.BigEndian.Uint64(attr.Value) + } else { + return NativeEndian().Uint64(attr.Value) + } +}