Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 #ifndef __NETCNT_COMMON_H
0003 #define __NETCNT_COMMON_H
0004 
0005 #include <linux/types.h>
0006 
0007 #define MAX_PERCPU_PACKETS 32
0008 
0009 /* sizeof(struct bpf_local_storage_elem):
0010  *
0011  * It really is about 128 bytes on x86_64, but allocate more to account for
0012  * possible layout changes, different architectures, etc.
0013  * The kernel will wrap up to PAGE_SIZE internally anyway.
0014  */
0015 #define SIZEOF_BPF_LOCAL_STORAGE_ELEM       256
0016 
0017 /* Try to estimate kernel's BPF_LOCAL_STORAGE_MAX_VALUE_SIZE: */
0018 #define BPF_LOCAL_STORAGE_MAX_VALUE_SIZE    (0xFFFF - \
0019                          SIZEOF_BPF_LOCAL_STORAGE_ELEM)
0020 
0021 #define PCPU_MIN_UNIT_SIZE          32768
0022 
0023 union percpu_net_cnt {
0024     struct {
0025         __u64 packets;
0026         __u64 bytes;
0027 
0028         __u64 prev_ts;
0029 
0030         __u64 prev_packets;
0031         __u64 prev_bytes;
0032     };
0033     __u8 data[PCPU_MIN_UNIT_SIZE];
0034 };
0035 
0036 union net_cnt {
0037     struct {
0038         __u64 packets;
0039         __u64 bytes;
0040     };
0041     __u8 data[BPF_LOCAL_STORAGE_MAX_VALUE_SIZE];
0042 };
0043 
0044 #endif