diff options
| author | Robby Zambito <contact@robbyzambito.me> | 2026-02-01 14:29:53 -0500 |
|---|---|---|
| committer | Robby Zambito <contact@robbyzambito.me> | 2026-02-01 19:16:22 -0500 |
| commit | 558f40213b895810a78b2bbcbdbb95e88a301fde (patch) | |
| tree | 6f164c0d109e7cfeff7db6a0a89f2baa2c8091f3 /src/Client.zig | |
| parent | daf18d35526870e39f3009b6bf9a64d0b4859b9f (diff) | |
Update to Saprus 0.2.1
Handle management messages instead of letting them bubble up through the
connection to the consumer.
Right now, this just means handling ping messages by sending a pong.
Also updated to follow the new handshake flow.
The sentinel will mirror the ports instead of matching them.
Now filters on the full source and dest ports, which are less likely to
have erroneous matches.
Diffstat (limited to 'src/Client.zig')
| -rw-r--r-- | src/Client.zig | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/Client.zig b/src/Client.zig index a8170a5..1709cab 100644 --- a/src/Client.zig +++ b/src/Client.zig @@ -100,7 +100,7 @@ pub fn connect(self: Client, io: Io, payload: []const u8) !SaprusConnection { var connection: SaprusMessage = .{ .connection = .{ .src = rand.intRangeAtMost(u16, 1025, std.math.maxInt(u16)), - .dest = rand.intRangeAtMost(u16, 1025, std.math.maxInt(u16)), + .dest = rand.intRangeAtMost(u16, 1025, std.math.maxInt(u16)), // Ignored, but good noise .seq = undefined, .id = undefined, .payload = payload, @@ -108,7 +108,7 @@ pub fn connect(self: Client, io: Io, payload: []const u8) !SaprusConnection { }; log.debug("Setting bpf filter to port {}", .{connection.connection.src}); - self.socket.attachSaprusPortFilter(connection.connection.src) catch |err| { + self.socket.attachSaprusPortFilter(null, connection.connection.src) catch |err| { log.err("Failed to set port filter: {t}", .{err}); return err; }; @@ -131,7 +131,17 @@ pub fn connect(self: Client, io: Io, payload: []const u8) !SaprusConnection { log.debug("Awaiting handshake response", .{}); // Ignore response from sentinel, just accept that we got one. - _ = try self.socket.receive(&res_buf); + const full_handshake_res = try self.socket.receive(&res_buf); + const handshake_res = saprusParse(full_handshake_res[42..]) catch |err| { + log.err("Parse error: {t}", .{err}); + return err; + }; + self.socket.attachSaprusPortFilter(handshake_res.connection.src, handshake_res.connection.dest) catch |err| { + log.err("Failed to set port filter: {t}", .{err}); + return err; + }; + connection.connection.dest = handshake_res.connection.src; + connection_bytes = connection.toBytes(&connection_buf); headers.udp.dst_port = udp_dest_port; headers.ip.id = rand.int(u16); @@ -153,6 +163,7 @@ pub fn connect(self: Client, io: Io, payload: []const u8) !SaprusConnection { const RawSocket = @import("./RawSocket.zig"); const SaprusMessage = @import("message.zig").Message; +const saprusParse = @import("message.zig").parse; const SaprusConnection = @import("Connection.zig"); const EthIpUdp = @import("./EthIpUdp.zig").EthIpUdp; |
