diff options
author | Jordan Rife <jrife@google.com> | 2024-04-29 16:45:18 -0500 |
---|---|---|
committer | Martin KaFai Lau <martin.lau@kernel.org> | 2024-05-02 12:09:22 -0700 |
commit | 8e667a065daa6f4c01eadc20f3815f7bf13255bc (patch) | |
tree | c318b7d5d6a1964bf818346968d62112856a9c5b /tools/testing/selftests/bpf/progs/bind_prog.h | |
parent | 08e90da6872a9f9f63ca2911bbce6883b6fc1a19 (diff) |
selftests/bpf: Fix bind program for big endian systems
Without this fix, the bind4 and bind6 programs will reject bind attempts
on big endian systems. This patch ensures that CI tests pass for the
s390x architecture.
Signed-off-by: Jordan Rife <jrife@google.com>
Link: https://lore.kernel.org/r/20240429214529.2644801-2-jrife@google.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/progs/bind_prog.h')
-rw-r--r-- | tools/testing/selftests/bpf/progs/bind_prog.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/bind_prog.h b/tools/testing/selftests/bpf/progs/bind_prog.h new file mode 100644 index 000000000000..e830caa940c3 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/bind_prog.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __BIND_PROG_H__ +#define __BIND_PROG_H__ + +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#define load_byte(src, b, s) \ + (((volatile __u8 *)&(src))[b] << 8 * b) +#define load_word(src, w, s) \ + (((volatile __u16 *)&(src))[w] << 16 * w) +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#define load_byte(src, b, s) \ + (((volatile __u8 *)&(src))[(b) + (sizeof(src) - (s))] << 8 * ((s) - (b) - 1)) +#define load_word(src, w, s) \ + (((volatile __u16 *)&(src))[w] << 16 * (((s) / 2) - (w) - 1)) +#else +# error "Fix your compiler's __BYTE_ORDER__?!" +#endif + +#endif |