authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-15 21:08:42-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:20:50-07:00
log90fdd21df6663d0ad99379cd056c8940e3a3e267
tree1ba9c0a0c77a37c2999ec690829881c5eeb0f933
parentbf841bb4ae6d6c7cf9494ccc45282b704b40e7f6

std: move DNS record enum to a better namespace


5 files changed, 19 insertions(+), 18 deletions(-)

lib/std/Io/Threaded.zig+9-9
...@@ -3130,9 +3130,9 @@ fn lookupDns(...@@ -3130,9 +3130,9 @@ fn lookupDns(
3130 options: HostName.LookupOptions,3130 options: HostName.LookupOptions,
3131) HostName.LookupError!void {3131) HostName.LookupError!void {
3132 const t_io = t.io();3132 const t_io = t.io();
3133 const family_records: [2]struct { af: IpAddress.Family, rr: u8 } = .{3133 const family_records: [2]struct { af: IpAddress.Family, rr: HostName.DnsRecord } = .{
3134 .{ .af = .ip6, .rr = std.posix.RR.A },3134 .{ .af = .ip6, .rr = .A },
3135 .{ .af = .ip4, .rr = std.posix.RR.AAAA },3135 .{ .af = .ip4, .rr = .AAAA },
3136 };3136 };
3137 var query_buffers: [2][280]u8 = undefined;3137 var query_buffers: [2][280]u8 = undefined;
3138 var answer_buffer: [2 * 512]u8 = undefined;3138 var answer_buffer: [2 * 512]u8 = undefined;
...@@ -3280,7 +3280,7 @@ fn lookupDns(...@@ -3280,7 +3280,7 @@ fn lookupDns(
3280 // Here we could potentially add diagnostics to the results queue.3280 // Here we could potentially add diagnostics to the results queue.
3281 continue;3281 continue;
3282 }) |record| switch (record.rr) {3282 }) |record| switch (record.rr) {
3283 std.posix.RR.A => {3283 .A => {
3284 const data = record.packet[record.data_off..][0..record.data_len];3284 const data = record.packet[record.data_off..][0..record.data_len];
3285 if (data.len != 4) return error.InvalidDnsARecord;3285 if (data.len != 4) return error.InvalidDnsARecord;
3286 try resolved.putOne(t_io, .{ .address = .{ .ip4 = .{3286 try resolved.putOne(t_io, .{ .address = .{ .ip4 = .{
...@@ -3289,7 +3289,7 @@ fn lookupDns(...@@ -3289,7 +3289,7 @@ fn lookupDns(
3289 } } });3289 } } });
3290 addresses_len += 1;3290 addresses_len += 1;
3291 },3291 },
3292 std.posix.RR.AAAA => {3292 .AAAA => {
3293 const data = record.packet[record.data_off..][0..record.data_len];3293 const data = record.packet[record.data_off..][0..record.data_len];
3294 if (data.len != 16) return error.InvalidDnsAAAARecord;3294 if (data.len != 16) return error.InvalidDnsAAAARecord;
3295 try resolved.putOne(t_io, .{ .address = .{ .ip6 = .{3295 try resolved.putOne(t_io, .{ .address = .{ .ip6 = .{
...@@ -3298,11 +3298,11 @@ fn lookupDns(...@@ -3298,11 +3298,11 @@ fn lookupDns(
3298 } } });3298 } } });
3299 addresses_len += 1;3299 addresses_len += 1;
3300 },3300 },
3301 std.posix.RR.CNAME => {3301 .CNAME => {
3302 _, canonical_name = HostName.expand(record.packet, record.data_off, options.canonical_name_buffer) catch3302 _, canonical_name = HostName.expand(record.packet, record.data_off, options.canonical_name_buffer) catch
3303 return error.InvalidDnsCnameRecord;3303 return error.InvalidDnsCnameRecord;
3304 },3304 },
3305 else => continue,3305 _ => continue,
3306 };3306 };
3307 }3307 }
33083308
...@@ -3413,7 +3413,7 @@ fn lookupHostsReader(...@@ -3413,7 +3413,7 @@ fn lookupHostsReader(
3413}3413}
34143414
3415/// Writes DNS resolution query packet data to `w`; at most 280 bytes.3415/// Writes DNS resolution query packet data to `w`; at most 280 bytes.
3416fn writeResolutionQuery(q: *[280]u8, op: u4, dname: []const u8, class: u8, ty: u8, entropy: [2]u8) usize {3416fn writeResolutionQuery(q: *[280]u8, op: u4, dname: []const u8, class: u8, ty: HostName.DnsRecord, entropy: [2]u8) usize {
3417 // This implementation is ported from musl libc.3417 // This implementation is ported from musl libc.
3418 // A more idiomatic "ziggy" implementation would be welcome.3418 // A more idiomatic "ziggy" implementation would be welcome.
3419 var name = dname;3419 var name = dname;
...@@ -3437,7 +3437,7 @@ fn writeResolutionQuery(q: *[280]u8, op: u4, dname: []const u8, class: u8, ty: u...@@ -3437,7 +3437,7 @@ fn writeResolutionQuery(q: *[280]u8, op: u4, dname: []const u8, class: u8, ty: u
3437 if (j - i - 1 > 62) unreachable;3437 if (j - i - 1 > 62) unreachable;
3438 q[i - 1] = @intCast(j - i);3438 q[i - 1] = @intCast(j - i);
3439 }3439 }
3440 q[i + 1] = ty;3440 q[i + 1] = @intFromEnum(ty);
3441 q[i + 3] = class;3441 q[i + 3] = class;
3442 return n;3442 return n;
3443}3443}
lib/std/Io/net/HostName.zig+9-2
...@@ -147,13 +147,20 @@ pub fn expand(noalias packet: []const u8, start_i: usize, noalias dest_buffer: [...@@ -147,13 +147,20 @@ pub fn expand(noalias packet: []const u8, start_i: usize, noalias dest_buffer: [
147 return error.InvalidDnsPacket;147 return error.InvalidDnsPacket;
148}148}
149149
150pub const DnsRecord = enum(u8) {
151 A = 1,
152 CNAME = 5,
153 AAAA = 28,
154 _,
155};
156
150pub const DnsResponse = struct {157pub const DnsResponse = struct {
151 bytes: []const u8,158 bytes: []const u8,
152 bytes_index: u32,159 bytes_index: u32,
153 answers_remaining: u16,160 answers_remaining: u16,
154161
155 pub const Answer = struct {162 pub const Answer = struct {
156 rr: u8,163 rr: DnsRecord,
157 packet: []const u8,164 packet: []const u8,
158 data_off: u32,165 data_off: u32,
159 data_len: u16,166 data_len: u16,
...@@ -190,7 +197,7 @@ pub const DnsResponse = struct {...@@ -190,7 +197,7 @@ pub const DnsResponse = struct {
190 if (i + 10 + len > r.len) return error.InvalidDnsPacket;197 if (i + 10 + len > r.len) return error.InvalidDnsPacket;
191 defer dr.bytes_index = i + 10 + len;198 defer dr.bytes_index = i + 10 + len;
192 return .{199 return .{
193 .rr = r[i + 1],200 .rr = @enumFromInt(r[i + 1]),
194 .packet = r,201 .packet = r,
195 .data_off = i + 10,202 .data_off = i + 10,
196 .data_len = len,203 .data_len = len,
lib/std/os/linux.zig-6
...@@ -7096,12 +7096,6 @@ pub const IPPROTO = struct {...@@ -7096,12 +7096,6 @@ pub const IPPROTO = struct {
7096 pub const MAX = 256;7096 pub const MAX = 256;
7097};7097};
70987098
7099pub const RR = struct {
7100 pub const A = 1;
7101 pub const CNAME = 5;
7102 pub const AAAA = 28;
7103};
7104
7105pub const tcp_repair_opt = extern struct {7099pub const tcp_repair_opt = extern struct {
7106 opt_code: u32,7100 opt_code: u32,
7107 opt_val: u32,7101 opt_val: u32,
lib/std/posix.zig-1
...@@ -98,7 +98,6 @@ pub const POSIX_FADV = system.POSIX_FADV;...@@ -98,7 +98,6 @@ pub const POSIX_FADV = system.POSIX_FADV;
98pub const PR = system.PR;98pub const PR = system.PR;
99pub const PROT = system.PROT;99pub const PROT = system.PROT;
100pub const RLIM = system.RLIM;100pub const RLIM = system.RLIM;
101pub const RR = system.RR;
102pub const S = system.S;101pub const S = system.S;
103pub const SA = system.SA;102pub const SA = system.SA;
104pub const SC = system.SC;103pub const SC = system.SC;
src/main.zig+1
...@@ -5062,6 +5062,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)...@@ -5062,6 +5062,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8)
5062 // Prevents bootstrap from depending on a bunch of unnecessary stuff.5062 // Prevents bootstrap from depending on a bunch of unnecessary stuff.
5063 var http_client: if (dev.env.supports(.fetch_command)) std.http.Client else struct {5063 var http_client: if (dev.env.supports(.fetch_command)) std.http.Client else struct {
5064 allocator: Allocator,5064 allocator: Allocator,
5065 io: Io,
5065 fn deinit(_: @This()) void {}5066 fn deinit(_: @This()) void {}
5066 } = .{ .allocator = gpa, .io = io };5067 } = .{ .allocator = gpa, .io = io };
5067 defer http_client.deinit();5068 defer http_client.deinit();