bpf: Use LINUX_KERNEL_VERSION extern variable

This commit is contained in:
Tatsuhiro Tsujikawa 2021-09-19 20:58:30 +09:00
parent d276ca0adc
commit 0264847a37
1 changed files with 19 additions and 13 deletions

View File

@ -24,7 +24,6 @@
*/ */
#include <linux/udp.h> #include <linux/udp.h>
#include <linux/bpf.h> #include <linux/bpf.h>
#include <linux/version.h>
#include <bpf/bpf_helpers.h> #include <bpf/bpf_helpers.h>
@ -235,22 +234,29 @@ static void InvMixColumns(state_t *state) {
} }
} }
extern __u32 LINUX_KERNEL_VERSION __kconfig;
/* The SubBytes Function Substitutes the values in the state matrix /* The SubBytes Function Substitutes the values in the state matrix
with values in an S-box. */ with values in an S-box. */
static void InvSubBytes(state_t *state) { static void InvSubBytes(state_t *state) {
__u8 i, j; __u8 i, j;
for (i = 0; i < 4; ++i) { if (LINUX_KERNEL_VERSION < KERNEL_VERSION(5, 10, 0)) {
for (j = 0; j < 4; ++j) { for (i = 0; i < 4; ++i) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0) for (j = 0; j < 4; ++j) {
/* Ubuntu 20.04 LTS kernel 5.4.0 needs this workaround otherwise /* Ubuntu 20.04 LTS kernel 5.4.0 needs this workaround
"math between map_value pointer and register with unbounded otherwise "math between map_value pointer and register with
min value is not allowed". 5.10.0 is a kernel version that unbounded min value is not allowed". 5.10.0 is a kernel
works but it might not be a minimum version. */ version that works but it might not be the minimum
__u8 k = (*state)[j][i]; version. */
(*state)[j][i] = k ? getSBoxInvert(k) : getSBoxInvert(0); __u8 k = (*state)[j][i];
#else /* !(LINUX_VERSION_CDOE < KERNEL_VERSION(5, 10, 0)) */ (*state)[j][i] = k ? getSBoxInvert(k) : getSBoxInvert(0);
(*state)[j][i] = getSBoxInvert((*state)[j][i]); }
#endif /* !(LINUX_VERSION_CDOE < KERNEL_VERSION(5, 10, 0)) */ }
} else {
for (i = 0; i < 4; ++i) {
for (j = 0; j < 4; ++j) {
(*state)[j][i] = getSBoxInvert((*state)[j][i]);
}
} }
} }
} }