@@ -52,34 +52,120 @@ const struct tcphdr l4 = {
5252};
5353const char body [20 ] = "Should not change!!" ;
5454
55- PKTGEN ("tc" , "tc_mark_decrypt" )
55+ // Test Case 1: TCP protocol, mark 0x00a0, expect mark to be 0x0
56+ PKTGEN ("tc" , "tc_mark_decrypt_case1" )
5657int test1_pktgen (struct __sk_buff * ctx )
5758{
5859 return build_tc_packet (ctx , & l2 , & l3 , & l4 , body , (uint )sizeof (body ));
5960}
6061
61- JUMP ("tc" , "tc_mark_decrypt " )
62+ JUMP ("tc" , "tc_mark_decrypt_case1 " )
6263int test1_jump (struct __sk_buff * ctx )
6364{
64- // build context
65- struct lpm_key key = {0 };
66- key .trie_key .prefixlen = 32 ;
67- key .ip .ip4 = SRC_IP ;
68- __u32 value = 1 ;
69- bpf_map_update_elem (& map_of_nodeinfo , & key , & value , BPF_ANY );
65+ // Set initial mark to 0x00a0
66+ ctx -> mark = 0x00a0 ;
7067
7168 bpf_tail_call (ctx , & entry_call_map , 0 );
7269 return TEST_ERROR ;
7370}
7471
75- CHECK ("tc" , "tc_mark_decrypt " )
72+ CHECK ("tc" , "tc_mark_decrypt_case1 " )
7673int test1_check (struct __sk_buff * ctx )
7774{
7875 const __u32 expected_status_code = TC_ACT_OK ;
7976
8077 test_init ();
8178
8279 check_tc_packet (ctx , & expected_status_code , & l2 , & l3 , & l4 , body , (uint )sizeof (body ));
80+ if (ctx -> mark != 0x0 )
81+ test_fatal ("ctx->mark mismatch, expected 0x0, got %u" , ctx -> mark );
82+
83+ test_finish ();
84+ }
85+
86+ // Test Case 2: TCP protocol, mark 0x00d0, expect mark to remain 0x00d0
87+ PKTGEN ("tc" , "tc_mark_decrypt_case2" )
88+ int test2_pktgen (struct __sk_buff * ctx )
89+ {
90+ return build_tc_packet (ctx , & l2 , & l3 , & l4 , body , (uint )sizeof (body ));
91+ }
92+
93+ JUMP ("tc" , "tc_mark_decrypt_case2" )
94+ int test2_jump (struct __sk_buff * ctx )
95+ {
96+ // Set initial mark to 0x00d0 (already decrypted)
97+ ctx -> mark = 0x00d0 ;
98+
99+ bpf_tail_call (ctx , & entry_call_map , 0 );
100+ return TEST_ERROR ;
101+ }
102+
103+ CHECK ("tc" , "tc_mark_decrypt_case2" )
104+ int test2_check (struct __sk_buff * ctx )
105+ {
106+ const __u32 expected_status_code = TC_ACT_OK ;
107+
108+ test_init ();
109+
110+ check_tc_packet (ctx , & expected_status_code , & l2 , & l3 , & l4 , body , (uint )sizeof (body ));
111+ if (ctx -> mark != 0x00d0 )
112+ test_fatal ("ctx->mark mismatch, expected 0x00d0, got %u" , ctx -> mark );
113+
114+ test_finish ();
115+ }
116+
117+ // Test Case 3: ESP protocol, mark 0x00d0, expect mark to remain 0x00d0
118+ PKTGEN ("tc" , "tc_mark_decrypt_case3" )
119+ int test3_pktgen (struct __sk_buff * ctx )
120+ {
121+ // Use ESP protocol header for this test
122+ struct iphdr l3_esp = {
123+ .version = 4 ,
124+ .ihl = 5 ,
125+ .tot_len = 40 ,
126+ .id = 0x5438 ,
127+ .frag_off = bpf_htons (IP_DF ),
128+ .ttl = 64 ,
129+ .protocol = IPPROTO_ESP ,
130+ .saddr = SRC_IP ,
131+ .daddr = DEST_IP ,
132+ };
133+
134+ return build_tc_packet (ctx , & l2 , & l3_esp , & l4 , body , (uint )sizeof (body ));
135+ }
136+
137+ JUMP ("tc" , "tc_mark_decrypt_case3" )
138+ int test3_jump (struct __sk_buff * ctx )
139+ {
140+ // Set initial mark to 0x00d0
141+ ctx -> mark = 0x00d0 ;
142+
143+ // build context - no need for nodeinfo map for ESP packets
144+ bpf_tail_call (ctx , & entry_call_map , 0 );
145+ return TEST_ERROR ;
146+ }
147+
148+ CHECK ("tc" , "tc_mark_decrypt_case3" )
149+ int test3_check (struct __sk_buff * ctx )
150+ {
151+ const __u32 expected_status_code = TC_ACT_OK ;
152+
153+ test_init ();
154+
155+ // Use ESP protocol header for verification
156+ struct iphdr l3_esp = {
157+ .version = 4 ,
158+ .ihl = 5 ,
159+ .tot_len = 40 ,
160+ .id = 0x5438 ,
161+ .frag_off = bpf_htons (IP_DF ),
162+ .ttl = 64 ,
163+ .protocol = IPPROTO_ESP ,
164+ .saddr = SRC_IP ,
165+ .daddr = DEST_IP ,
166+ };
167+
168+ check_tc_packet (ctx , & expected_status_code , & l2 , & l3_esp , & l4 , body , (uint )sizeof (body ));
83169 if (ctx -> mark != 0x00d0 )
84170 test_fatal ("ctx->mark mismatch, expected 0x00d0, got %u" , ctx -> mark );
85171
0 commit comments