@@ -26,13 +26,6 @@ struct hdr_cursor {
26
26
void * pos ;
27
27
};
28
28
29
- __u16 PORT = 5201 ;
30
-
31
- enum side {
32
- SERVER ,
33
- CLIENT ,
34
- };
35
-
36
29
/*******************************************
37
30
** parse_*hdr helpers from XDP tutorials **
38
31
*******************************************/
@@ -156,7 +149,7 @@ static __always_inline int parse_udphdr(struct hdr_cursor *nh,
156
149
157
150
static __always_inline void
158
151
udp_to_tcp (struct __sk_buff * skb , struct hdr_cursor * nh ,
159
- struct iphdr * iphdr , struct ipv6hdr * ipv6hdr , enum side side )
152
+ struct iphdr * iphdr , struct ipv6hdr * ipv6hdr )
160
153
{
161
154
void * data_end = (void * )(long )skb -> data_end ;
162
155
void * data = (void * )(long )skb -> data ;
@@ -169,17 +162,6 @@ udp_to_tcp(struct __sk_buff *skb, struct hdr_cursor *nh,
169
162
if (parse_udphdr (nh , data_end , (struct udphdr * * )& tuhdr ) < 0 )
170
163
goto out ;
171
164
172
- switch (side ) {
173
- case SERVER :
174
- if (tuhdr -> udphdr .dest != bpf_htons (PORT ))
175
- goto out ;
176
- break ;
177
- case CLIENT :
178
- if (tuhdr -> udphdr .source != bpf_htons (PORT ))
179
- goto out ;
180
- break ;
181
- }
182
-
183
165
if (skb -> gso_segs > 1 ) {
184
166
bpf_printk ("udp-tcp: WARNING, GRO/LRO should be disabled: length:%u, segs:%u, size:%u\n" ,
185
167
skb -> len , skb -> gso_segs , skb -> gso_size );
@@ -249,53 +231,14 @@ udp_to_tcp(struct __sk_buff *skb, struct hdr_cursor *nh,
249
231
return ;
250
232
}
251
233
252
- static __always_inline int
253
- tc_ingress (struct __sk_buff * skb , enum side side )
254
- {
255
- void * data_end = (void * )(long )skb -> data_end ;
256
- void * data = (void * )(long )skb -> data ;
257
- struct hdr_cursor nh = { .pos = data };
258
- int eth_type , ip_type , ret = TC_ACT_OK ;
259
- struct ipv6hdr * ipv6hdr = NULL ;
260
- struct iphdr * iphdr = NULL ;
261
- struct ethhdr * eth ;
262
-
263
- eth_type = parse_ethhdr (& nh , data_end , & eth );
264
- if (eth_type == bpf_htons (ETH_P_IP )) {
265
- ip_type = parse_iphdr (& nh , data_end , & iphdr );
266
- } else if (eth_type == bpf_htons (ETH_P_IPV6 )) {
267
- ip_type = parse_ip6hdr (& nh , data_end , & ipv6hdr );
268
- } else {
269
- goto out ;
270
- }
271
-
272
- if (ip_type == IPPROTO_UDP )
273
- udp_to_tcp (skb , & nh , iphdr , ipv6hdr , side );
274
-
275
- out :
276
- return ret ;
277
- }
278
-
279
- SEC ("tc_client_ingress" )
280
- int client_ingress (struct __sk_buff * skb )
281
- {
282
- return tc_ingress (skb , CLIENT );
283
- }
284
-
285
- SEC ("tc_server_ingress" )
286
- int server_ingress (struct __sk_buff * skb )
287
- {
288
- return tc_ingress (skb , SERVER );
289
- }
290
-
291
234
292
235
/************
293
236
** Egress **
294
237
************/
295
238
296
239
static __always_inline int
297
240
tcp_to_udp (struct __sk_buff * skb , struct hdr_cursor * nh ,
298
- struct iphdr * iphdr , struct ipv6hdr * ipv6hdr , enum side side )
241
+ struct iphdr * iphdr , struct ipv6hdr * ipv6hdr )
299
242
{
300
243
void * data_end = (void * )(long )skb -> data_end ;
301
244
void * data = (void * )(long )skb -> data ;
@@ -309,17 +252,6 @@ tcp_to_udp(struct __sk_buff *skb, struct hdr_cursor *nh,
309
252
if (parse_tcphdr (nh , data_end , & tcphdr ) < 0 )
310
253
goto out ;
311
254
312
- switch (side ) {
313
- case SERVER :
314
- if (tcphdr -> source != bpf_htons (PORT ))
315
- goto out ;
316
- break ;
317
- case CLIENT :
318
- if (tcphdr -> dest != bpf_htons (PORT ))
319
- goto out ;
320
- break ;
321
- }
322
-
323
255
if (tcphdr -> urg ) {
324
256
if (iphdr )
325
257
bpf_printk ("tcp-udp: Skip: %pI4:%u -> %pI4:%u: urgent\n" ,
@@ -386,8 +318,8 @@ tcp_to_udp(struct __sk_buff *skb, struct hdr_cursor *nh,
386
318
return TC_ACT_OK ;
387
319
}
388
320
389
- static __always_inline int
390
- tc_egress (struct __sk_buff * skb , enum side side )
321
+ SEC ( "tc" )
322
+ int tc_tcp_in_udp (struct __sk_buff * skb )
391
323
{
392
324
void * data_end = (void * )(long )skb -> data_end ;
393
325
void * data = (void * )(long )skb -> data ;
@@ -407,22 +339,12 @@ tc_egress(struct __sk_buff *skb, enum side side)
407
339
}
408
340
409
341
if (ip_type == IPPROTO_TCP )
410
- return tcp_to_udp (skb , & nh , iphdr , ipv6hdr , side );
342
+ return tcp_to_udp (skb , & nh , iphdr , ipv6hdr );
343
+ else if (ip_type == IPPROTO_UDP )
344
+ udp_to_tcp (skb , & nh , iphdr , ipv6hdr );
411
345
412
346
out :
413
347
return ret ;
414
348
}
415
349
416
- SEC ("tc_client_egress" )
417
- int client_egress (struct __sk_buff * skb )
418
- {
419
- return tc_egress (skb , CLIENT );
420
- }
421
-
422
- SEC ("tc_server_egress" )
423
- int server_egress (struct __sk_buff * skb )
424
- {
425
- return tc_egress (skb , SERVER );
426
- }
427
-
428
350
char _license [] SEC ("license" ) = "GPL" ;
0 commit comments