Skip to content

Commit

Permalink
Fix parsing of packets and bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
corny committed Oct 31, 2018
1 parent be087d3 commit 5e41be0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ipset_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 9 additions & 0 deletions nl/parse_attr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 5e41be0

Please sign in to comment.