Loading...
Note: File does not exist in v6.8.
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright Amazon.com Inc. or its affiliates */
3#include <linux/types.h>
4#include <linux/bpf.h>
5#include <bpf/bpf_helpers.h>
6#include <bpf/bpf_tracing.h>
7
8#define BUFF_SZ 512
9
10/* Will be updated by benchmark before program loading */
11char to_buff[BUFF_SZ];
12const volatile unsigned int to_buff_len = 0;
13char from_buff[BUFF_SZ];
14const volatile unsigned int from_buff_len = 0;
15unsigned short seed = 0;
16
17short result;
18
19char _license[] SEC("license") = "GPL";
20
21SEC("tc")
22int compute_checksum(void *ctx)
23{
24 int to_len_half = to_buff_len / 2;
25 int from_len_half = from_buff_len / 2;
26 short result2;
27
28 /* Calculate checksum in one go */
29 result2 = bpf_csum_diff((void *)from_buff, from_buff_len,
30 (void *)to_buff, to_buff_len, seed);
31
32 /* Calculate checksum by concatenating bpf_csum_diff()*/
33 result = bpf_csum_diff((void *)from_buff, from_buff_len - from_len_half,
34 (void *)to_buff, to_buff_len - to_len_half, seed);
35
36 result = bpf_csum_diff((void *)from_buff + (from_buff_len - from_len_half), from_len_half,
37 (void *)to_buff + (to_buff_len - to_len_half), to_len_half, result);
38
39 result = (result == result2) ? result : 0;
40
41 return 0;
42}