11// SPDX-License-Identifier: GPL-2.0
22#include <vmlinux.h>
33#include <bpf/bpf_helpers.h>
4+ #include <bpf/bpf_endian.h>
45
56#define EAFNOSUPPORT 97
67#define EPROTO 71
78#define ENONET 64
89#define EINVAL 22
910#define ENOENT 2
1011
12+ extern unsigned long CONFIG_HZ __kconfig ;
13+
1114int test_einval_bpf_tuple = 0 ;
1215int test_einval_reserved = 0 ;
1316int test_einval_netns_id = 0 ;
@@ -16,6 +19,8 @@ int test_eproto_l4proto = 0;
1619int test_enonet_netns_id = 0 ;
1720int test_enoent_lookup = 0 ;
1821int test_eafnosupport = 0 ;
22+ int test_succ_lookup = 0 ;
23+ u32 test_delta_timeout = 0 ;
1924
2025struct nf_conn ;
2126
@@ -31,6 +36,7 @@ struct nf_conn *bpf_xdp_ct_lookup(struct xdp_md *, struct bpf_sock_tuple *, u32,
3136struct nf_conn * bpf_skb_ct_lookup (struct __sk_buff * , struct bpf_sock_tuple * , u32 ,
3237 struct bpf_ct_opts___local * , u32 ) __ksym ;
3338void bpf_ct_release (struct nf_conn * ) __ksym ;
39+ void bpf_ct_refresh_timeout (struct nf_conn * , u32 ) __ksym ;
3440
3541static __always_inline void
3642nf_ct_test (struct nf_conn * (* func )(void * , struct bpf_sock_tuple * , u32 ,
@@ -99,6 +105,22 @@ nf_ct_test(struct nf_conn *(*func)(void *, struct bpf_sock_tuple *, u32,
99105 bpf_ct_release (ct );
100106 else
101107 test_eafnosupport = opts_def .error ;
108+
109+ bpf_tuple .ipv4 .saddr = 0x01010101 ; /* src IP 1.1.1.1 */
110+ bpf_tuple .ipv4 .daddr = 0x02020202 ; /* dst IP 2.2.2.2 */
111+ bpf_tuple .ipv4 .sport = bpf_htons (12345 ); /* src port */
112+ bpf_tuple .ipv4 .dport = bpf_htons (1000 ); /* dst port */
113+ ct = func (ctx , & bpf_tuple , sizeof (bpf_tuple .ipv4 ), & opts_def ,
114+ sizeof (opts_def ));
115+ if (ct ) {
116+ /* update ct entry timeout */
117+ bpf_ct_refresh_timeout (ct , 10000 );
118+ test_delta_timeout = ct -> timeout - bpf_jiffies64 ();
119+ test_delta_timeout /= CONFIG_HZ ;
120+ bpf_ct_release (ct );
121+ } else {
122+ test_succ_lookup = opts_def .error ;
123+ }
102124}
103125
104126SEC ("xdp" )
0 commit comments