While it is currently possible for userspace to specify that an existing XDP program should not be replaced when attaching to an interface, there is no mechanism to safely replace a specific XDP program with another. This patch adds a new netlink attribute, IFLA_XDP_EXPECTED_FD, which can be set along with IFLA_XDP_FD. If set, the kernel will check that the program currently loaded on the interface matches the expected one, and fail the operation if it does not. This corresponds to a 'cmpxchg' memory operation. Setting the new attribute with a negative value means that no program is expected to be attached, which corresponds to setting the UPDATE_IF_NOEXIST flag. A new companion flag, XDP_FLAGS_REPLACE, is also added to explicitly request checking of the EXPECTED_FD attribute. This is needed for userspace to discover whether the kernel supports the new attribute.
Showing the changes to include/uapi/linux (1 of 4 files). Show all
Unified · Split
| @@ -972,11 +972,12 @@ enum { · 971 unmodified lines | ||
| 972 | 972 | #define XDP_FLAGS_SKB_MODE (1U << 1) |
| 973 | 973 | #define XDP_FLAGS_DRV_MODE (1U << 2) |
| 974 | 974 | #define XDP_FLAGS_HW_MODE (1U << 3) |
| 975 | +#define XDP_FLAGS_REPLACE (1U << 4) | |
| 975 | 976 | #define XDP_FLAGS_MODES (XDP_FLAGS_SKB_MODE | \ |
| 976 | 977 | XDP_FLAGS_DRV_MODE | \ |
| 977 | 978 | XDP_FLAGS_HW_MODE) |
| 978 | 979 | #define XDP_FLAGS_MASK (XDP_FLAGS_UPDATE_IF_NOEXIST | \ |
| 979 | − XDP_FLAGS_MODES) | |
| 980 | + XDP_FLAGS_MODES | XDP_FLAGS_REPLACE) | |
| 980 | 981 | |
| 981 | 982 | /* These are stored into IFLA_XDP_ATTACHED on dump. */ |
| 982 | 983 | enum { |
| @@ -996,6 +997,7 @@ enum { · 13 unmodified lines | ||
| 996 | 997 | IFLA_XDP_DRV_PROG_ID, |
| 997 | 998 | IFLA_XDP_SKB_PROG_ID, |
| 998 | 999 | IFLA_XDP_HW_PROG_ID, |
| 1000 | + IFLA_XDP_EXPECTED_FD, | |
| 999 | 1001 | __IFLA_XDP_MAX, |
| 1000 | 1002 | }; |
| 1001 | 1003 | |