/* Not testing the egress traffic or the listening socket, * which are covered by the cgroup_skb/ingress test program.
*/ if (sk->family != AF_INET6 || !is_loopback6(sk->src_ip6) ||
sk->state == BPF_TCP_LISTEN) return CG_OK;
/* It must be a fullsock for cgroup_skb/egress prog */
sk = bpf_sk_fullsock(sk); if (!sk)
RET_LOG();
/* Not the testing egress traffic */ if (sk->protocol != IPPROTO_TCP) return CG_OK;
tp = bpf_tcp_sock(sk); if (!tp)
RET_LOG();
skcpy(sk_ret, sk);
tpcpy(tp_ret, tp);
if (sk_ret == &srv_sk) {
ktp = bpf_skc_to_tcp_sock(sk);
if (!ktp)
RET_LOG();
lsndtime = ktp->lsndtime;
child_cg_id = bpf_sk_cgroup_id(ktp); if (!child_cg_id)
RET_LOG();
parent_cg_id = bpf_sk_ancestor_cgroup_id(ktp, 2); if (!parent_cg_id)
RET_LOG();
/* The userspace has created it for srv sk */
pkt_out_cnt = bpf_sk_storage_get(&sk_pkt_out_cnt, ktp, 0, 0);
pkt_out_cnt10 = bpf_sk_storage_get(&sk_pkt_out_cnt10, ktp,
0, 0);
} else {
pkt_out_cnt = bpf_sk_storage_get(&sk_pkt_out_cnt, sk,
&cli_cnt_init,
BPF_SK_STORAGE_GET_F_CREATE);
pkt_out_cnt10 = bpf_sk_storage_get(&sk_pkt_out_cnt10,
sk, &cli_cnt_init,
BPF_SK_STORAGE_GET_F_CREATE);
}
if (!pkt_out_cnt || !pkt_out_cnt10)
RET_LOG();
/* Even both cnt and cnt10 have lock defined in their BTF, * intentionally one cnt takes lock while one does not * as a test for the spinlock support in BPF_MAP_TYPE_SK_STORAGE.
*/
pkt_out_cnt->cnt += 1;
bpf_spin_lock(&pkt_out_cnt10->lock);
pkt_out_cnt10->cnt += 10;
bpf_spin_unlock(&pkt_out_cnt10->lock);
/* Not the testing ingress traffic to the server */ if (sk->family != AF_INET6 || !is_loopback6(sk->src_ip6) ||
sk->src_port != bpf_ntohs(srv_sa6.sin6_port)) return CG_OK;
/* Only interested in the listening socket */ if (sk->state != BPF_TCP_LISTEN) return CG_OK;
/* It must be a fullsock for cgroup_skb/ingress prog */
sk = bpf_sk_fullsock(sk); if (!sk)
RET_LOG();
tp = bpf_tcp_sock(sk); if (!tp)
RET_LOG();
skcpy(&listen_sk, sk);
tpcpy(&listen_tp, tp);
return CG_OK;
}
/* * NOTE: 4-byte load from bpf_sock at dst_port offset is quirky. It * gets rewritten by the access converter to a 2-byte load for * backward compatibility. Treating the load result as a be16 value * makes the code portable across little- and big-endian platforms.
*/ static __noinline bool sk_dst_port__load_word(struct bpf_sock *sk)
{
__u32 *word = (__u32 *)&sk->dst_port; return word[0] == bpf_htons(0xcafe);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.