github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/examples/tcprtt_sockops/bpf_sockops.h (about)

     1  /*
     2   * Note that this header file contains a subset of kernel 
     3   * definitions needed for the tcprtt_sockops example.
     4   */
     5  #ifndef BPF_SOCKOPS_H
     6  #define BPF_SOCKOPS_H
     7  
     8  /*
     9   * Copy of TCP states.
    10   * See: https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/bpf.h#L6347.
    11   */
    12  enum {
    13  	TCP_ESTABLISHED = 1,
    14  	TCP_SYN_SENT = 2,
    15  	TCP_SYN_RECV = 3,
    16  	TCP_FIN_WAIT1 = 4,
    17  	TCP_FIN_WAIT2 = 5,
    18  	TCP_TIME_WAIT = 6,
    19  	TCP_CLOSE = 7,
    20  	TCP_CLOSE_WAIT = 8,
    21  	TCP_LAST_ACK = 9,
    22  	TCP_LISTEN = 10,
    23  	TCP_CLOSING = 11,
    24  	TCP_NEW_SYN_RECV = 12,
    25  	TCP_MAX_STATES = 13,
    26  };
    27  
    28  /*
    29   * Copy of sock_ops operations.
    30   * See: https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/bpf.h#L6233.
    31   */
    32  enum {
    33  	BPF_SOCK_OPS_VOID                   = 0,
    34  	BPF_SOCK_OPS_TIMEOUT_INIT           = 1,
    35  	BPF_SOCK_OPS_RWND_INIT              = 2,
    36  	BPF_SOCK_OPS_TCP_CONNECT_CB         = 3,
    37  	BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB  = 4,
    38  	BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB = 5,
    39  	BPF_SOCK_OPS_NEEDS_ECN              = 6,
    40  	BPF_SOCK_OPS_BASE_RTT               = 7,
    41  	BPF_SOCK_OPS_RTO_CB                 = 8,
    42  	BPF_SOCK_OPS_RETRANS_CB             = 9,
    43  	BPF_SOCK_OPS_STATE_CB               = 10,
    44  	BPF_SOCK_OPS_TCP_LISTEN_CB          = 11,
    45  	BPF_SOCK_OPS_RTT_CB                 = 12,
    46  	BPF_SOCK_OPS_PARSE_HDR_OPT_CB       = 13,
    47  	BPF_SOCK_OPS_HDR_OPT_LEN_CB         = 14,
    48  	BPF_SOCK_OPS_WRITE_HDR_OPT_CB       = 15,
    49  };
    50  
    51  /*
    52   * Copy of definitions for bpf_sock_ops_cb_flags.
    53   * See: https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/bpf.h#L6178.
    54   */
    55  enum {
    56  	BPF_SOCK_OPS_RTO_CB_FLAG                   = 1,
    57  	BPF_SOCK_OPS_RETRANS_CB_FLAG               = 2,
    58  	BPF_SOCK_OPS_STATE_CB_FLAG                 = 4,
    59  	BPF_SOCK_OPS_RTT_CB_FLAG                   = 8,
    60  	BPF_SOCK_OPS_PARSE_ALL_HDR_OPT_CB_FLAG     = 16,
    61  	BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG = 32,
    62  	BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG         = 64,
    63  	BPF_SOCK_OPS_ALL_CB_FLAGS                  = 127,
    64  };
    65  
    66  /*
    67   * Copy of bpf.h's bpf_sock_ops with minimal subset 
    68   * of fields used by the tcprtt_sockops example.
    69   * See: https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/bpf.h#L6101.
    70   */
    71  struct bpf_sock_ops {
    72  	__u32 op;
    73  	union {
    74  		__u32 args[4];
    75  		__u32 reply;
    76  		__u32 replylong[4];
    77  	};
    78  	__u32 family;
    79  	__u32 remote_ip4;
    80  	__u32 local_ip4;
    81  	__u32 remote_port;
    82  	__u32 local_port;
    83  	__u32 srtt_us;
    84      __u32 bpf_sock_ops_cb_flags;
    85  } __attribute__((preserve_access_index));
    86  
    87  #endif