]> git.baikalelectronics.ru Git - kernel.git/commit
netfilter: ipset: Copy the right MAC address in hash:ip,mac IPv6 sets
authorStefano Brivio <sbrivio@redhat.com>
Thu, 10 Oct 2019 17:18:14 +0000 (19:18 +0200)
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Mon, 4 Nov 2019 19:45:53 +0000 (20:45 +0100)
commitef85c51d2e10e6be53de844b1213d6383fc6f4bd
tree2baaf162f1c758118ef47485e258df98c9e988c2
parent7579d7919f0b404cd20e4e12d8bd4d97c6dd0d7f
netfilter: ipset: Copy the right MAC address in hash:ip,mac IPv6 sets

Same as commit 780c72999354 ("netfilter: ipset: Copy the right MAC
address in bitmap:ip,mac and hash:ip,mac sets"), another copy and paste
went wrong in commit 21288f7f2840 ("netfilter: ipset: Allow matching on
destination MAC address for mac and ipmac sets").

When I fixed this for IPv4 in 780c72999354, I didn't realise that
hash:ip,mac sets also support IPv6 as family, and this is covered by a
separate function, hash_ipmac6_kadt().

In hash:ip,mac sets, the first dimension is the IP address, and the
second dimension is the MAC address: check the IPSET_DIM_TWO_SRC flag
in flags while deciding which MAC address to copy, destination or
source.

This way, mixing source and destination matches for the two dimensions
of ip,mac hash type works as expected, also for IPv6. With this setup:

  ip netns add A
  ip link add veth1 type veth peer name veth2 netns A
  ip addr add 2001:db8::1/64 dev veth1
  ip -net A addr add 2001:db8::2/64 dev veth2
  ip link set veth1 up
  ip -net A link set veth2 up

  dst=$(ip netns exec A cat /sys/class/net/veth2/address)

  ip netns exec A ipset create test_hash hash:ip,mac family inet6
  ip netns exec A ipset add test_hash 2001:db8::1,${dst}
  ip netns exec A ip6tables -A INPUT -p icmpv6 --icmpv6-type 135 -j ACCEPT
  ip netns exec A ip6tables -A INPUT -m set ! --match-set test_hash src,dst -j DROP

ipset now correctly matches a test packet:

  # ping -c1 2001:db8::2 >/dev/null
  # echo $?
  0

Reported-by: Chen, Yi <yiche@redhat.com>
Fixes: 21288f7f2840 ("netfilter: ipset: Allow matching on destination MAC address for mac and ipmac sets")
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
net/netfilter/ipset/ip_set_hash_ipmac.c