1 /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 #ifndef __BPF_TRACING_NET_H__ 3 #define __BPF_TRACING_NET_H__ 4 5 #include <vmlinux.h> 6 #include <bpf/bpf_core_read.h> 7 8 #define AF_INET 2 9 #define AF_INET6 10 10 11 #define SOL_SOCKET 1 12 #define SO_REUSEADDR 2 13 #define SO_SNDBUF 7 14 #define SO_RCVBUF 8 15 #define SO_KEEPALIVE 9 16 #define SO_PRIORITY 12 17 #define SO_REUSEPORT 15 18 #define SO_RCVLOWAT 18 19 #define SO_BINDTODEVICE 25 20 #define SO_MARK 36 21 #define SO_MAX_PACING_RATE 47 22 #define SO_BINDTOIFINDEX 62 23 #define SO_TXREHASH 74 24 #define __SO_ACCEPTCON (1 << 16) 25 26 #define IP_TOS 1 27 28 #define SOL_IPV6 41 29 #define IPV6_TCLASS 67 30 #define IPV6_AUTOFLOWLABEL 70 31 32 #define TC_ACT_UNSPEC (-1) 33 #define TC_ACT_OK 0 34 #define TC_ACT_SHOT 2 35 36 #define SOL_TCP 6 37 #define TCP_NODELAY 1 38 #define TCP_MAXSEG 2 39 #define TCP_KEEPIDLE 4 40 #define TCP_KEEPINTVL 5 41 #define TCP_KEEPCNT 6 42 #define TCP_SYNCNT 7 43 #define TCP_WINDOW_CLAMP 10 44 #define TCP_CONGESTION 13 45 #define TCP_THIN_LINEAR_TIMEOUTS 16 46 #define TCP_USER_TIMEOUT 18 47 #define TCP_NOTSENT_LOWAT 25 48 #define TCP_SAVE_SYN 27 49 #define TCP_SAVED_SYN 28 50 #define TCP_CA_NAME_MAX 16 51 #define TCP_NAGLE_OFF 1 52 53 #define TCP_ECN_OK 1 54 #define TCP_ECN_QUEUE_CWR 2 55 #define TCP_ECN_DEMAND_CWR 4 56 #define TCP_ECN_SEEN 8 57 58 #define TCP_CONG_NEEDS_ECN 0x2 59 60 #define ICSK_TIME_RETRANS 1 61 #define ICSK_TIME_PROBE0 3 62 #define ICSK_TIME_LOSS_PROBE 5 63 #define ICSK_TIME_REO_TIMEOUT 6 64 65 #define ETH_ALEN 6 66 #define ETH_HLEN 14 67 #define ETH_P_IP 0x0800 68 #define ETH_P_IPV6 0x86DD 69 70 #define NEXTHDR_TCP 6 71 72 #define TCPOPT_NOP 1 73 #define TCPOPT_EOL 0 74 #define TCPOPT_MSS 2 75 #define TCPOPT_WINDOW 3 76 #define TCPOPT_TIMESTAMP 8 77 #define TCPOPT_SACK_PERM 4 78 79 #define TCPOLEN_MSS 4 80 #define TCPOLEN_WINDOW 3 81 #define TCPOLEN_TIMESTAMP 10 82 #define TCPOLEN_SACK_PERM 2 83 84 #define CHECKSUM_NONE 0 85 #define CHECKSUM_PARTIAL 3 86 87 #define IFNAMSIZ 16 88 89 #define RTF_GATEWAY 0x0002 90 91 #define TCP_INFINITE_SSTHRESH 0x7fffffff 92 #define TCP_PINGPONG_THRESH 3 93 94 #define FLAG_DATA_ACKED 0x04 /* This ACK acknowledged new data. */ 95 #define FLAG_SYN_ACKED 0x10 /* This ACK acknowledged SYN. */ 96 #define FLAG_DATA_SACKED 0x20 /* New SACK. */ 97 #define FLAG_SND_UNA_ADVANCED \ 98 0x400 /* Snd_una was changed (!= FLAG_DATA_ACKED) */ 99 #define FLAG_ACKED (FLAG_DATA_ACKED | FLAG_SYN_ACKED) 100 #define FLAG_FORWARD_PROGRESS (FLAG_ACKED | FLAG_DATA_SACKED) 101 102 #define fib_nh_dev nh_common.nhc_dev 103 #define fib_nh_gw_family nh_common.nhc_gw_family 104 #define fib_nh_gw6 nh_common.nhc_gw.ipv6 105 106 #define inet_daddr sk.__sk_common.skc_daddr 107 #define inet_rcv_saddr sk.__sk_common.skc_rcv_saddr 108 #define inet_dport sk.__sk_common.skc_dport 109 110 #define udp_portaddr_hash inet.sk.__sk_common.skc_u16hashes[1] 111 112 #define ir_loc_addr req.__req_common.skc_rcv_saddr 113 #define ir_num req.__req_common.skc_num 114 #define ir_rmt_addr req.__req_common.skc_daddr 115 #define ir_rmt_port req.__req_common.skc_dport 116 #define ir_v6_rmt_addr req.__req_common.skc_v6_daddr 117 #define ir_v6_loc_addr req.__req_common.skc_v6_rcv_saddr 118 119 #define sk_num __sk_common.skc_num 120 #define sk_dport __sk_common.skc_dport 121 #define sk_family __sk_common.skc_family 122 #define sk_rmem_alloc sk_backlog.rmem_alloc 123 #define sk_refcnt __sk_common.skc_refcnt 124 #define sk_state __sk_common.skc_state 125 #define sk_net __sk_common.skc_net 126 #define sk_v6_daddr __sk_common.skc_v6_daddr 127 #define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr 128 #define sk_flags __sk_common.skc_flags 129 #define sk_reuse __sk_common.skc_reuse 130 #define sk_cookie __sk_common.skc_cookie 131 132 #define s6_addr32 in6_u.u6_addr32 133 134 #define tw_daddr __tw_common.skc_daddr 135 #define tw_rcv_saddr __tw_common.skc_rcv_saddr 136 #define tw_dport __tw_common.skc_dport 137 #define tw_refcnt __tw_common.skc_refcnt 138 #define tw_v6_daddr __tw_common.skc_v6_daddr 139 #define tw_v6_rcv_saddr __tw_common.skc_v6_rcv_saddr 140 141 #define tcp_jiffies32 ((__u32)bpf_jiffies64()) 142 143 static inline struct inet_connection_sock *inet_csk(const struct sock *sk) 144 { 145 return (struct inet_connection_sock *)sk; 146 } 147 148 static inline void *inet_csk_ca(const struct sock *sk) 149 { 150 return (void *)inet_csk(sk)->icsk_ca_priv; 151 } 152 153 static inline struct tcp_sock *tcp_sk(const struct sock *sk) 154 { 155 return (struct tcp_sock *)sk; 156 } 157 158 static inline bool tcp_in_slow_start(const struct tcp_sock *tp) 159 { 160 return tp->snd_cwnd < tp->snd_ssthresh; 161 } 162 163 static inline bool tcp_is_cwnd_limited(const struct sock *sk) 164 { 165 const struct tcp_sock *tp = tcp_sk(sk); 166 167 /* If in slow start, ensure cwnd grows to twice what was ACKed. */ 168 if (tcp_in_slow_start(tp)) 169 return tp->snd_cwnd < 2 * tp->max_packets_out; 170 171 return !!BPF_CORE_READ_BITFIELD(tp, is_cwnd_limited); 172 } 173 174 #endif 175
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.