0001
0002 #include <vmlinux.h>
0003 #include <bpf/bpf_tracing.h>
0004 #include <bpf/bpf_helpers.h>
0005 #include <bpf/bpf_core_read.h>
0006
0007 struct nf_conn;
0008
0009 struct bpf_ct_opts___local {
0010 s32 netns_id;
0011 s32 error;
0012 u8 l4proto;
0013 u8 reserved[3];
0014 } __attribute__((preserve_access_index));
0015
0016 struct nf_conn *bpf_skb_ct_alloc(struct __sk_buff *, struct bpf_sock_tuple *, u32,
0017 struct bpf_ct_opts___local *, u32) __ksym;
0018 struct nf_conn *bpf_skb_ct_lookup(struct __sk_buff *, struct bpf_sock_tuple *, u32,
0019 struct bpf_ct_opts___local *, u32) __ksym;
0020 struct nf_conn *bpf_ct_insert_entry(struct nf_conn *) __ksym;
0021 void bpf_ct_release(struct nf_conn *) __ksym;
0022 void bpf_ct_set_timeout(struct nf_conn *, u32) __ksym;
0023 int bpf_ct_change_timeout(struct nf_conn *, u32) __ksym;
0024 int bpf_ct_set_status(struct nf_conn *, u32) __ksym;
0025 int bpf_ct_change_status(struct nf_conn *, u32) __ksym;
0026
0027 SEC("?tc")
0028 int alloc_release(struct __sk_buff *ctx)
0029 {
0030 struct bpf_ct_opts___local opts = {};
0031 struct bpf_sock_tuple tup = {};
0032 struct nf_conn *ct;
0033
0034 ct = bpf_skb_ct_alloc(ctx, &tup, sizeof(tup.ipv4), &opts, sizeof(opts));
0035 if (!ct)
0036 return 0;
0037 bpf_ct_release(ct);
0038 return 0;
0039 }
0040
0041 SEC("?tc")
0042 int insert_insert(struct __sk_buff *ctx)
0043 {
0044 struct bpf_ct_opts___local opts = {};
0045 struct bpf_sock_tuple tup = {};
0046 struct nf_conn *ct;
0047
0048 ct = bpf_skb_ct_alloc(ctx, &tup, sizeof(tup.ipv4), &opts, sizeof(opts));
0049 if (!ct)
0050 return 0;
0051 ct = bpf_ct_insert_entry(ct);
0052 if (!ct)
0053 return 0;
0054 ct = bpf_ct_insert_entry(ct);
0055 return 0;
0056 }
0057
0058 SEC("?tc")
0059 int lookup_insert(struct __sk_buff *ctx)
0060 {
0061 struct bpf_ct_opts___local opts = {};
0062 struct bpf_sock_tuple tup = {};
0063 struct nf_conn *ct;
0064
0065 ct = bpf_skb_ct_lookup(ctx, &tup, sizeof(tup.ipv4), &opts, sizeof(opts));
0066 if (!ct)
0067 return 0;
0068 bpf_ct_insert_entry(ct);
0069 return 0;
0070 }
0071
0072 SEC("?tc")
0073 int set_timeout_after_insert(struct __sk_buff *ctx)
0074 {
0075 struct bpf_ct_opts___local opts = {};
0076 struct bpf_sock_tuple tup = {};
0077 struct nf_conn *ct;
0078
0079 ct = bpf_skb_ct_alloc(ctx, &tup, sizeof(tup.ipv4), &opts, sizeof(opts));
0080 if (!ct)
0081 return 0;
0082 ct = bpf_ct_insert_entry(ct);
0083 if (!ct)
0084 return 0;
0085 bpf_ct_set_timeout(ct, 0);
0086 return 0;
0087 }
0088
0089 SEC("?tc")
0090 int set_status_after_insert(struct __sk_buff *ctx)
0091 {
0092 struct bpf_ct_opts___local opts = {};
0093 struct bpf_sock_tuple tup = {};
0094 struct nf_conn *ct;
0095
0096 ct = bpf_skb_ct_alloc(ctx, &tup, sizeof(tup.ipv4), &opts, sizeof(opts));
0097 if (!ct)
0098 return 0;
0099 ct = bpf_ct_insert_entry(ct);
0100 if (!ct)
0101 return 0;
0102 bpf_ct_set_status(ct, 0);
0103 return 0;
0104 }
0105
0106 SEC("?tc")
0107 int change_timeout_after_alloc(struct __sk_buff *ctx)
0108 {
0109 struct bpf_ct_opts___local opts = {};
0110 struct bpf_sock_tuple tup = {};
0111 struct nf_conn *ct;
0112
0113 ct = bpf_skb_ct_alloc(ctx, &tup, sizeof(tup.ipv4), &opts, sizeof(opts));
0114 if (!ct)
0115 return 0;
0116 bpf_ct_change_timeout(ct, 0);
0117 return 0;
0118 }
0119
0120 SEC("?tc")
0121 int change_status_after_alloc(struct __sk_buff *ctx)
0122 {
0123 struct bpf_ct_opts___local opts = {};
0124 struct bpf_sock_tuple tup = {};
0125 struct nf_conn *ct;
0126
0127 ct = bpf_skb_ct_alloc(ctx, &tup, sizeof(tup.ipv4), &opts, sizeof(opts));
0128 if (!ct)
0129 return 0;
0130 bpf_ct_change_status(ct, 0);
0131 return 0;
0132 }
0133
0134 char _license[] SEC("license") = "GPL";