]> git.ipfire.org Git - thirdparty/xtables-addons.git/commit
xt_geoip: fix in6_addr little-endian byte swapping
authorJeremy Sowden <jeremy@azazel.net>
Sat, 30 Nov 2019 17:58:45 +0000 (18:58 +0100)
committerJan Engelhardt <jengelh@inai.de>
Sun, 1 Dec 2019 10:29:40 +0000 (11:29 +0100)
commitbf1ca298ae608883a5c108cdb2dfd8cc8525ccb6
treeaf82becf13a2fab9062bb68b20c962dcd68d111a
parent6e5edc8372daa680b5f0a08176f4f7e86dbb50a7
xt_geoip: fix in6_addr little-endian byte swapping

The Perl script that builds the GeoIP DBs uses inet_pton(3) to convert
the addresses to network byte order. This converts

  "1234:5678::90ab:cdef"

to:

  0x12 0x34 0x56 0x78 .. 0xcd 0xef, interpreted by an LE machine
  accessing this in uint32_t-sized chunks as
  8765:4321::fedc:ba09

The kernel module compares the addresses in packets with the ranges from
the DB in host byte order using binary search. It uses 32-bit swaps
when converting the addresses.

libxt_geoip, however, which the module uses to load the ranges from the
DB and convert them from NBO to HBO, uses 16-bit swaps to do so, and
this means that:

  1234:5678::90ab:cdef

becomes:

  4321:8765::ba09:fedc

Obviously, this is inconsistent with the kernel module and DB build
script and breaks the binary search.

Fixes: b91dbd03c717 ("geoip: store database in network byte order")
Reported-by: "Thomas B. Clark" <kernel@clark.bz>
Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
extensions/libxt_geoip.c