38
38
* @l4proto - Layer 4 protocol
39
39
* Values:
40
40
* IPPROTO_TCP, IPPROTO_UDP
41
+ * @dir: - connection tracking tuple direction.
41
42
* @reserved - Reserved member, will be reused for more options in future
42
43
* Values:
43
44
* 0
@@ -46,7 +47,8 @@ struct bpf_ct_opts {
46
47
s32 netns_id ;
47
48
s32 error ;
48
49
u8 l4proto ;
49
- u8 reserved [3 ];
50
+ u8 dir ;
51
+ u8 reserved [2 ];
50
52
};
51
53
52
54
enum {
@@ -56,10 +58,11 @@ enum {
56
58
static struct nf_conn * __bpf_nf_ct_lookup (struct net * net ,
57
59
struct bpf_sock_tuple * bpf_tuple ,
58
60
u32 tuple_len , u8 protonum ,
59
- s32 netns_id )
61
+ s32 netns_id , u8 * dir )
60
62
{
61
63
struct nf_conntrack_tuple_hash * hash ;
62
64
struct nf_conntrack_tuple tuple ;
65
+ struct nf_conn * ct ;
63
66
64
67
if (unlikely (protonum != IPPROTO_TCP && protonum != IPPROTO_UDP ))
65
68
return ERR_PTR (- EPROTO );
@@ -99,7 +102,12 @@ static struct nf_conn *__bpf_nf_ct_lookup(struct net *net,
99
102
put_net (net );
100
103
if (!hash )
101
104
return ERR_PTR (- ENOENT );
102
- return nf_ct_tuplehash_to_ctrack (hash );
105
+
106
+ ct = nf_ct_tuplehash_to_ctrack (hash );
107
+ if (dir )
108
+ * dir = NF_CT_DIRECTION (hash );
109
+
110
+ return ct ;
103
111
}
104
112
105
113
__diag_push ();
@@ -135,13 +143,13 @@ bpf_xdp_ct_lookup(struct xdp_md *xdp_ctx, struct bpf_sock_tuple *bpf_tuple,
135
143
if (!opts )
136
144
return NULL ;
137
145
if (!bpf_tuple || opts -> reserved [0 ] || opts -> reserved [1 ] ||
138
- opts -> reserved [ 2 ] || opts__sz != NF_BPF_CT_OPTS_SZ ) {
146
+ opts__sz != NF_BPF_CT_OPTS_SZ ) {
139
147
opts -> error = - EINVAL ;
140
148
return NULL ;
141
149
}
142
150
caller_net = dev_net (ctx -> rxq -> dev );
143
151
nfct = __bpf_nf_ct_lookup (caller_net , bpf_tuple , tuple__sz , opts -> l4proto ,
144
- opts -> netns_id );
152
+ opts -> netns_id , & opts -> dir );
145
153
if (IS_ERR (nfct )) {
146
154
opts -> error = PTR_ERR (nfct );
147
155
return NULL ;
@@ -178,13 +186,13 @@ bpf_skb_ct_lookup(struct __sk_buff *skb_ctx, struct bpf_sock_tuple *bpf_tuple,
178
186
if (!opts )
179
187
return NULL ;
180
188
if (!bpf_tuple || opts -> reserved [0 ] || opts -> reserved [1 ] ||
181
- opts -> reserved [ 2 ] || opts__sz != NF_BPF_CT_OPTS_SZ ) {
189
+ opts__sz != NF_BPF_CT_OPTS_SZ ) {
182
190
opts -> error = - EINVAL ;
183
191
return NULL ;
184
192
}
185
193
caller_net = skb -> dev ? dev_net (skb -> dev ) : sock_net (skb -> sk );
186
194
nfct = __bpf_nf_ct_lookup (caller_net , bpf_tuple , tuple__sz , opts -> l4proto ,
187
- opts -> netns_id );
195
+ opts -> netns_id , & opts -> dir );
188
196
if (IS_ERR (nfct )) {
189
197
opts -> error = PTR_ERR (nfct );
190
198
return NULL ;
0 commit comments