net: Don't call XDP_SETUP_PROG when nothing is changed
authorMaxim Mikityanskiy <maximmi@mellanox.com>
Wed, 14 Aug 2019 14:34:06 +0000 (14:34 +0000)
committerDaniel Borkmann <daniel@iogearbox.net>
Sat, 17 Aug 2019 21:11:54 +0000 (23:11 +0200)
commitc14a9f633d9eb5c0fdd0cb4135b6be978fd538f3
tree8d73f79c672dad6f43baa35a818756160f84a850
parentc8186c8064c4c234a3d2e3d60e25c1f55ec4f8b3
net: Don't call XDP_SETUP_PROG when nothing is changed

Don't uninstall an XDP program when none is installed, and don't install
an XDP program that has the same ID as the one already installed.

dev_change_xdp_fd doesn't perform any checks in case it uninstalls an
XDP program. It means that the driver's ndo_bpf can be called with
XDP_SETUP_PROG asking to set it to NULL even if it's already NULL. This
case happens if the user runs `ip link set eth0 xdp off` when there is
no XDP program attached.

The symmetrical case is possible when the user tries to set the program
that is already set.

The drivers typically perform some heavy operations on XDP_SETUP_PROG,
so they all have to handle these cases internally to return early if
they happen. This patch puts this check into the kernel code, so that
all drivers will benefit from it.

Signed-off-by: Maxim Mikityanskiy <maximmi@mellanox.com>
Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
net/core/dev.c