Skip to content

Commit 659849f

Browse files
committed
Update function return types from int to i32 in various files to enforce consistency across the codebase.
Signed-off-by: Cong Wang <cwang@multikernel.io>
1 parent e267910 commit 659849f

File tree

9 files changed

+24
-24
lines changed

9 files changed

+24
-24
lines changed

SPEC.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn monitor(ctx: *xdp_md) -> xdp_action {
6969
}
7070
7171
@tc("ingress")
72-
fn analyzer(ctx: *__sk_buff) -> int {
72+
fn analyzer(ctx: *__sk_buff) -> i32 {
7373
update_counters(1) // Same kernel-shared function
7474
return 0 // TC_ACT_OK
7575
}
@@ -256,7 +256,7 @@ TC programs must specify traffic direction for proper kernel attachment point se
256256
```kernelscript
257257
// Ingress traffic control (packets entering the interface)
258258
@tc("ingress")
259-
fn ingress_filter(ctx: *__sk_buff) -> int {
259+
fn ingress_filter(ctx: *__sk_buff) -> i32 {
260260
var packet_size = ctx->len
261261
262262
// Drop oversized packets at ingress
@@ -269,7 +269,7 @@ fn ingress_filter(ctx: *__sk_buff) -> int {
269269
270270
// Egress traffic control (packets leaving the interface)
271271
@tc("egress")
272-
fn egress_shaper(ctx: *__sk_buff) -> int {
272+
fn egress_shaper(ctx: *__sk_buff) -> i32 {
273273
var protocol = ctx->protocol
274274
275275
// Shape traffic based on protocol at egress
@@ -798,7 +798,7 @@ fn packet_analyzer(ctx: *xdp_md) -> xdp_action {
798798
}
799799
800800
@tc("ingress")
801-
fn flow_tracker(ctx: *__sk_buff) -> int {
801+
fn flow_tracker(ctx: *__sk_buff) -> i32 {
802802
// Track flow information using shared config
803803
if (monitoring.enable_stats && (ctx.hash() % monitoring.sample_rate == 0)) {
804804
// Sample this flow
@@ -867,7 +867,7 @@ fn packet_filter(ctx: *xdp_md) -> xdp_action {
867867
}
868868
869869
@tc("ingress")
870-
fn flow_monitor(ctx: *__sk_buff) -> int {
870+
fn flow_monitor(ctx: *__sk_buff) -> i32 {
871871
return 0 // TC_ACT_OK
872872
}
873873
@@ -1021,7 +1021,7 @@ fn main(args: Args) -> i32 {
10211021
fn ingress_monitor(ctx: *xdp_md) -> xdp_action { return XDP_PASS }
10221022
10231023
@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
10251025
10261026
// Struct_ops example using impl block approach
10271027
struct tcp_congestion_ops {
@@ -1419,7 +1419,7 @@ fn packet_filter(ctx: *xdp_md) -> xdp_action {
14191419
}
14201420
14211421
@tc("ingress")
1422-
fn traffic_shaper(ctx: *__sk_buff) -> int {
1422+
fn traffic_shaper(ctx: *__sk_buff) -> i32 {
14231423
var packet = ctx.packet()
14241424
14251425
// Reuse the same helpers
@@ -1475,7 +1475,7 @@ fn ddos_protection(ctx: *xdp_md) -> xdp_action {
14751475
}
14761476
14771477
@tc("ingress")
1478-
fn connection_tracker(ctx: *__sk_buff) -> int {
1478+
fn connection_tracker(ctx: *__sk_buff) -> i32 {
14791479
var tcp_info = extract_tcp_info(ctx) // Reuse same helper
14801480
if (tcp_info != null) {
14811481
track_connection(tcp_info.src_port, tcp_info.dst_port)
@@ -1609,7 +1609,7 @@ fn high_level_filter(packet: *u8, len: u32) -> i32 {
16091609
16101610
// eBPF usage
16111611
@tc("ingress")
1612-
fn traffic_analyzer(ctx: *__sk_buff) -> int {
1612+
fn traffic_analyzer(ctx: *__sk_buff) -> i32 {
16131613
var packet = ctx.packet()
16141614
16151615
// Can only call the public kfunc
@@ -2516,7 +2516,7 @@ fn ingress_monitor(ctx: *xdp_md) -> xdp_action {
25162516
25172517
// Program 2: Automatically has access to the same global maps
25182518
@tc("egress")
2519-
fn egress_monitor(ctx: *__sk_buff) -> int {
2519+
fn egress_monitor(ctx: *__sk_buff) -> i32 {
25202520
var flow_key = extract_flow_key(ctx)?
25212521
25222522
// Same global map, no import needed - compound assignments work everywhere
@@ -2976,7 +2976,7 @@ fn packet_filter(ctx: *xdp_md) -> xdp_action {
29762976
}
29772977
29782978
@tc("ingress")
2979-
fn flow_monitor(ctx: *__sk_buff) -> int {
2979+
fn flow_monitor(ctx: *__sk_buff) -> i32 {
29802980
// Can call the same kernel-shared functions
29812981
if (!validate_packet(ctx.packet())) {
29822982
return 2 // TC_ACT_SHOT
@@ -3081,7 +3081,7 @@ fn main_filter(ctx: *xdp_md) -> xdp_action {
30813081
}
30823082
30833083
@tc("ingress")
3084-
fn ingress_handler(ctx: *__sk_buff) -> int {
3084+
fn ingress_handler(ctx: *__sk_buff) -> i32 {
30853085
return security_check(ctx) // ✅ Same type (@tc), return position
30863086
}
30873087
```
@@ -3670,7 +3670,7 @@ program network_monitor : xdp {
36703670
}
36713671
36723672
program flow_analyzer : tc {
3673-
fn main(ctx: *__sk_buff) -> int {
3673+
fn main(ctx: *__sk_buff) -> i32 {
36743674
return 0 // TC_ACT_OK
36753675
}
36763676
}

examples/maps_demo.ks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn get_timestamp() -> u64 {
129129

130130
// TC program demonstrating different map usage patterns
131131
@tc("ingress")
132-
fn traffic_shaper(ctx: *__sk_buff) -> int {
132+
fn traffic_shaper(ctx: *__sk_buff) -> i32 {
133133
var cpu = get_cpu_id()
134134
var bytes = get_packet_len_tc(ctx)
135135

src/type_checker.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ let rec resolve_user_type ctx = function
220220
| UserType "xdp_md" -> Xdp_md
221221
| UserType "xdp_action" -> Xdp_action
222222
| UserType "__sk_buff" -> Struct "__sk_buff"
223-
| UserType "int" -> I32
223+
224224
| UserType "usize" -> U64 (* usize maps to 64-bit unsigned integer *)
225225
| UserType name ->
226226
(* Look up type alias in the context *)

tests/test_function_scope.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ fn safe_increment(index: u32) -> bool {
419419
return 0
420420
}
421421

422-
@tc("ingress") fn counter_tc(ctx: *__sk_buff) -> int {
422+
@tc("ingress") fn counter_tc(ctx: *__sk_buff) -> i32 {
423423
var count = get_global_counter(0)
424424
safe_increment(1)
425425
return 0
@@ -495,7 +495,7 @@ fn shared_logging(message: u32) {
495495
return 0
496496
}
497497

498-
@tc("ingress") fn tc_filter(ctx: *__sk_buff) -> int {
498+
@tc("ingress") fn tc_filter(ctx: *__sk_buff) -> i32 {
499499
if (shared_validation(256)) {
500500
shared_logging(2)
501501
return 0
@@ -627,7 +627,7 @@ let test_attributed_function_cross_call_restriction () =
627627
return 2
628628
}
629629

630-
@tc("ingress") fn main_filter(ctx: *__sk_buff) -> int {
630+
@tc("ingress") fn main_filter(ctx: *__sk_buff) -> i32 {
631631
var result = helper_filter(ctx) // This should fail
632632
return result
633633
}

tests/test_map_integration.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ var xdp_stats : hash<u32, u64>(1024)
385385
("tc", {|
386386
var tc_stats : hash<u32, u64>(1024)
387387

388-
@tc("ingress") fn tc_test(ctx: *__sk_buff) -> int {
388+
@tc("ingress") fn tc_test(ctx: *__sk_buff) -> i32 {
389389
tc_stats[1] = tc_stats[2]
390390
return 0
391391
}

tests/test_program_ref.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ let test_different_program_types () =
5151
return 0
5252
}
5353

54-
@tc("ingress") fn tc_filter(ctx: *__sk_buff) -> int {
54+
@tc("ingress") fn tc_filter(ctx: *__sk_buff) -> i32 {
5555
return 0
5656
}
5757

@@ -204,7 +204,7 @@ let test_multiple_program_handles () =
204204
return 2
205205
}
206206

207-
@tc("ingress") fn tc_shaper(ctx: *__sk_buff) -> int {
207+
@tc("ingress") fn tc_shaper(ctx: *__sk_buff) -> i32 {
208208
return 0
209209
}
210210

tests/test_type_checker.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ fn convert_ip_to_u32(addr: IpAddress) -> u32 {
11991199
let test_tail_call_cross_program_type_restriction _ =
12001200
(* Test XDP -> TC tail call should fail *)
12011201
let source_code = {|
1202-
@tc("ingress") fn tc_drop_handler(ctx: *__sk_buff) -> int {
1202+
@tc("ingress") fn tc_drop_handler(ctx: *__sk_buff) -> i32 {
12031203
return 1 // TC_ACT_SHOT
12041204
}
12051205

tests/test_userspace.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ let test_multiple_programs_single_main () =
328328
return 2
329329
}
330330

331-
@tc("ingress") fn filter(ctx: *__sk_buff) -> int {
331+
@tc("ingress") fn filter(ctx: *__sk_buff) -> i32 {
332332
return 0
333333
}
334334

tests/test_userspace_maps.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ pin var shared_counter : hash<u32, u32>(1024)
428428
return XDP_PASS
429429
}
430430

431-
@tc("ingress") fn packet_filter(ctx: *__sk_buff) -> int {
431+
@tc("ingress") fn packet_filter(ctx: *__sk_buff) -> i32 {
432432
shared_counter[2] = 200
433433
return 0 // TC_ACT_OK
434434
}

0 commit comments

Comments
 (0)