selftests/bpf: introduce bpf_cpu_to_be64 and bpf_be64_to_cpu
test_lwt_seg6local and test_seg6_loop use custom 64-bit endianness conversion macros. Centralize their definitions in bpf_endian.h in order to reduce code duplication. This will also be useful when bpf_endian.h is promoted to an offical libbpf header. Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
This commit is contained in:

committed by
Daniel Borkmann

parent
504792e07a
commit
b963267994
@@ -12,10 +12,6 @@
|
||||
|
||||
#define SR6_FLAG_ALERT (1 << 4)
|
||||
|
||||
#define htonll(x) ((bpf_htonl(1)) == 1 ? (x) : ((uint64_t)bpf_htonl((x) & \
|
||||
0xFFFFFFFF) << 32) | bpf_htonl((x) >> 32))
|
||||
#define ntohll(x) ((bpf_ntohl(1)) == 1 ? (x) : ((uint64_t)bpf_ntohl((x) & \
|
||||
0xFFFFFFFF) << 32) | bpf_ntohl((x) >> 32))
|
||||
#define BPF_PACKET_HEADER __attribute__((packed))
|
||||
|
||||
struct ip6_t {
|
||||
@@ -276,8 +272,8 @@ int has_egr_tlv(struct __sk_buff *skb, struct ip6_srh_t *srh)
|
||||
return 0;
|
||||
|
||||
// check if egress TLV value is correct
|
||||
if (ntohll(egr_addr.hi) == 0xfd00000000000000 &&
|
||||
ntohll(egr_addr.lo) == 0x4)
|
||||
if (bpf_be64_to_cpu(egr_addr.hi) == 0xfd00000000000000 &&
|
||||
bpf_be64_to_cpu(egr_addr.lo) == 0x4)
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -308,8 +304,8 @@ int __encap_srh(struct __sk_buff *skb)
|
||||
|
||||
#pragma clang loop unroll(full)
|
||||
for (unsigned long long lo = 0; lo < 4; lo++) {
|
||||
seg->lo = htonll(4 - lo);
|
||||
seg->hi = htonll(hi);
|
||||
seg->lo = bpf_cpu_to_be64(4 - lo);
|
||||
seg->hi = bpf_cpu_to_be64(hi);
|
||||
seg = (struct ip6_addr_t *)((char *)seg + sizeof(*seg));
|
||||
}
|
||||
|
||||
@@ -349,8 +345,8 @@ int __add_egr_x(struct __sk_buff *skb)
|
||||
if (err)
|
||||
return BPF_DROP;
|
||||
|
||||
addr.lo = htonll(lo);
|
||||
addr.hi = htonll(hi);
|
||||
addr.lo = bpf_cpu_to_be64(lo);
|
||||
addr.hi = bpf_cpu_to_be64(hi);
|
||||
err = bpf_lwt_seg6_action(skb, SEG6_LOCAL_ACTION_END_X,
|
||||
(void *)&addr, sizeof(addr));
|
||||
if (err)
|
||||
|
@@ -12,10 +12,6 @@
|
||||
|
||||
#define SR6_FLAG_ALERT (1 << 4)
|
||||
|
||||
#define htonll(x) ((bpf_htonl(1)) == 1 ? (x) : ((uint64_t)bpf_htonl((x) & \
|
||||
0xFFFFFFFF) << 32) | bpf_htonl((x) >> 32))
|
||||
#define ntohll(x) ((bpf_ntohl(1)) == 1 ? (x) : ((uint64_t)bpf_ntohl((x) & \
|
||||
0xFFFFFFFF) << 32) | bpf_ntohl((x) >> 32))
|
||||
#define BPF_PACKET_HEADER __attribute__((packed))
|
||||
|
||||
struct ip6_t {
|
||||
@@ -251,8 +247,8 @@ int __add_egr_x(struct __sk_buff *skb)
|
||||
if (err)
|
||||
return BPF_DROP;
|
||||
|
||||
addr.lo = htonll(lo);
|
||||
addr.hi = htonll(hi);
|
||||
addr.lo = bpf_cpu_to_be64(lo);
|
||||
addr.hi = bpf_cpu_to_be64(hi);
|
||||
err = bpf_lwt_seg6_action(skb, SEG6_LOCAL_ACTION_END_X,
|
||||
(void *)&addr, sizeof(addr));
|
||||
if (err)
|
||||
|
Reference in New Issue
Block a user