@@ -69,7 +69,7 @@ fn monitor(ctx: *xdp_md) -> xdp_action {
69
69
}
70
70
71
71
@tc("ingress")
72
- fn analyzer(ctx: *__sk_buff) -> int {
72
+ fn analyzer(ctx: *__sk_buff) -> i32 {
73
73
update_counters(1) // Same kernel-shared function
74
74
return 0 // TC_ACT_OK
75
75
}
@@ -256,7 +256,7 @@ TC programs must specify traffic direction for proper kernel attachment point se
256
256
``` kernelscript
257
257
// Ingress traffic control (packets entering the interface)
258
258
@tc("ingress")
259
- fn ingress_filter(ctx: *__sk_buff) -> int {
259
+ fn ingress_filter(ctx: *__sk_buff) -> i32 {
260
260
var packet_size = ctx->len
261
261
262
262
// Drop oversized packets at ingress
@@ -269,7 +269,7 @@ fn ingress_filter(ctx: *__sk_buff) -> int {
269
269
270
270
// Egress traffic control (packets leaving the interface)
271
271
@tc("egress")
272
- fn egress_shaper(ctx: *__sk_buff) -> int {
272
+ fn egress_shaper(ctx: *__sk_buff) -> i32 {
273
273
var protocol = ctx->protocol
274
274
275
275
// Shape traffic based on protocol at egress
@@ -798,7 +798,7 @@ fn packet_analyzer(ctx: *xdp_md) -> xdp_action {
798
798
}
799
799
800
800
@tc("ingress")
801
- fn flow_tracker(ctx: *__sk_buff) -> int {
801
+ fn flow_tracker(ctx: *__sk_buff) -> i32 {
802
802
// Track flow information using shared config
803
803
if (monitoring.enable_stats && (ctx.hash() % monitoring.sample_rate == 0)) {
804
804
// Sample this flow
@@ -867,7 +867,7 @@ fn packet_filter(ctx: *xdp_md) -> xdp_action {
867
867
}
868
868
869
869
@tc("ingress")
870
- fn flow_monitor(ctx: *__sk_buff) -> int {
870
+ fn flow_monitor(ctx: *__sk_buff) -> i32 {
871
871
return 0 // TC_ACT_OK
872
872
}
873
873
@@ -1021,7 +1021,7 @@ fn main(args: Args) -> i32 {
1021
1021
fn ingress_monitor(ctx: *xdp_md) -> xdp_action { return XDP_PASS }
1022
1022
1023
1023
@tc("egress")
1024
- fn egress_monitor(ctx: *__sk_buff) -> int { return 0 } // TC_ACT_OK
1024
+ fn egress_monitor(ctx: *__sk_buff) -> i32 { return 0 } // TC_ACT_OK
1025
1025
1026
1026
// Struct_ops example using impl block approach
1027
1027
struct tcp_congestion_ops {
@@ -1419,7 +1419,7 @@ fn packet_filter(ctx: *xdp_md) -> xdp_action {
1419
1419
}
1420
1420
1421
1421
@tc("ingress")
1422
- fn traffic_shaper(ctx: *__sk_buff) -> int {
1422
+ fn traffic_shaper(ctx: *__sk_buff) -> i32 {
1423
1423
var packet = ctx.packet()
1424
1424
1425
1425
// Reuse the same helpers
@@ -1475,7 +1475,7 @@ fn ddos_protection(ctx: *xdp_md) -> xdp_action {
1475
1475
}
1476
1476
1477
1477
@tc("ingress")
1478
- fn connection_tracker(ctx: *__sk_buff) -> int {
1478
+ fn connection_tracker(ctx: *__sk_buff) -> i32 {
1479
1479
var tcp_info = extract_tcp_info(ctx) // Reuse same helper
1480
1480
if (tcp_info != null) {
1481
1481
track_connection(tcp_info.src_port, tcp_info.dst_port)
@@ -1609,7 +1609,7 @@ fn high_level_filter(packet: *u8, len: u32) -> i32 {
1609
1609
1610
1610
// eBPF usage
1611
1611
@tc("ingress")
1612
- fn traffic_analyzer(ctx: *__sk_buff) -> int {
1612
+ fn traffic_analyzer(ctx: *__sk_buff) -> i32 {
1613
1613
var packet = ctx.packet()
1614
1614
1615
1615
// Can only call the public kfunc
@@ -2516,7 +2516,7 @@ fn ingress_monitor(ctx: *xdp_md) -> xdp_action {
2516
2516
2517
2517
// Program 2: Automatically has access to the same global maps
2518
2518
@tc("egress")
2519
- fn egress_monitor(ctx: *__sk_buff) -> int {
2519
+ fn egress_monitor(ctx: *__sk_buff) -> i32 {
2520
2520
var flow_key = extract_flow_key(ctx)?
2521
2521
2522
2522
// Same global map, no import needed - compound assignments work everywhere
@@ -2976,7 +2976,7 @@ fn packet_filter(ctx: *xdp_md) -> xdp_action {
2976
2976
}
2977
2977
2978
2978
@tc("ingress")
2979
- fn flow_monitor(ctx: *__sk_buff) -> int {
2979
+ fn flow_monitor(ctx: *__sk_buff) -> i32 {
2980
2980
// Can call the same kernel-shared functions
2981
2981
if (!validate_packet(ctx.packet())) {
2982
2982
return 2 // TC_ACT_SHOT
@@ -3081,7 +3081,7 @@ fn main_filter(ctx: *xdp_md) -> xdp_action {
3081
3081
}
3082
3082
3083
3083
@tc("ingress")
3084
- fn ingress_handler(ctx: *__sk_buff) -> int {
3084
+ fn ingress_handler(ctx: *__sk_buff) -> i32 {
3085
3085
return security_check(ctx) // ✅ Same type (@tc), return position
3086
3086
}
3087
3087
```
@@ -3670,7 +3670,7 @@ program network_monitor : xdp {
3670
3670
}
3671
3671
3672
3672
program flow_analyzer : tc {
3673
- fn main(ctx: *__sk_buff) -> int {
3673
+ fn main(ctx: *__sk_buff) -> i32 {
3674
3674
return 0 // TC_ACT_OK
3675
3675
}
3676
3676
}
0 commit comments