1169689Skan/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
2169689Skan/* DNS resolver interface definitions.
3169689Skan *
4169689Skan * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
5169689Skan * Written by David Howells (dhowells@redhat.com)
6169689Skan *
7169689Skan * This program is free software; you can redistribute it and/or
8169689Skan * modify it under the terms of the GNU General Public Licence
9169689Skan * as published by the Free Software Foundation; either version
10169689Skan * 2 of the Licence, or (at your option) any later version.
11169689Skan */
12169689Skan
13169689Skan#ifndef _UAPI_LINUX_DNS_RESOLVER_H
14169689Skan#define _UAPI_LINUX_DNS_RESOLVER_H
15169689Skan
16169689Skan#include <linux/types.h>
17169689Skan
18169689Skan/*
19169689Skan * Type of payload.
20169689Skan */
21169689Skanenum dns_payload_content_type {
22169689Skan	DNS_PAYLOAD_IS_SERVER_LIST	= 0, /* List of servers, requested by srv=1 */
23169689Skan};
24169689Skan
25169689Skan/*
26169689Skan * Type of address that might be found in an address record.
27169689Skan */
28169689Skanenum dns_payload_address_type {
29169689Skan	DNS_ADDRESS_IS_IPV4		= 0, /* 4-byte AF_INET address */
30169689Skan	DNS_ADDRESS_IS_IPV6		= 1, /* 16-byte AF_INET6 address */
31169689Skan};
32169689Skan
33169689Skan/*
34169689Skan * Type of protocol used to access a server.
35169689Skan */
36169689Skanenum dns_payload_protocol_type {
37169689Skan	DNS_SERVER_PROTOCOL_UNSPECIFIED	= 0,
38169689Skan	DNS_SERVER_PROTOCOL_UDP		= 1, /* Use UDP to talk to the server */
39169689Skan	DNS_SERVER_PROTOCOL_TCP		= 2, /* Use TCP to talk to the server */
40169689Skan};
41169689Skan
42169689Skan/*
43169689Skan * Source of record included in DNS resolver payload.
44169689Skan */
45169689Skanenum dns_record_source {
46169689Skan	DNS_RECORD_UNAVAILABLE		= 0, /* No source available (empty record) */
47169689Skan	DNS_RECORD_FROM_CONFIG		= 1, /* From local configuration data */
48169689Skan	DNS_RECORD_FROM_DNS_A		= 2, /* From DNS A or AAAA record */
49169689Skan	DNS_RECORD_FROM_DNS_AFSDB	= 3, /* From DNS AFSDB record */
50169689Skan	DNS_RECORD_FROM_DNS_SRV		= 4, /* From DNS SRV record */
51169689Skan	DNS_RECORD_FROM_NSS		= 5, /* From NSS */
52169689Skan	NR__dns_record_source
53169689Skan};
54169689Skan
55169689Skan/*
56169689Skan * Status of record included in DNS resolver payload.
57169689Skan */
58169689Skanenum dns_lookup_status {
59169689Skan	DNS_LOOKUP_NOT_DONE		= 0, /* No lookup has been made */
60169689Skan	DNS_LOOKUP_GOOD			= 1, /* Good records obtained */
61169689Skan	DNS_LOOKUP_GOOD_WITH_BAD	= 2, /* Good records, some decoding errors */
62169689Skan	DNS_LOOKUP_BAD			= 3, /* Couldn't decode results */
63169689Skan	DNS_LOOKUP_GOT_NOT_FOUND	= 4, /* Got a "Not Found" result */
64169689Skan	DNS_LOOKUP_GOT_LOCAL_FAILURE	= 5, /* Local failure during lookup */
65169689Skan	DNS_LOOKUP_GOT_TEMP_FAILURE	= 6, /* Temporary failure during lookup */
66169689Skan	DNS_LOOKUP_GOT_NS_FAILURE	= 7, /* Name server failure */
67169689Skan	NR__dns_lookup_status
68169689Skan};
69169689Skan
70169689Skan/*
71169689Skan * Header at the beginning of binary format payload.
72169689Skan */
73169689Skanstruct dns_payload_header {
74169689Skan	__u8		zero;		/* Zero byte: marks this as not being text */
75169689Skan	__u8		content;	/* enum dns_payload_content_type */
76169689Skan	__u8		version;	/* Encoding version */
77169689Skan} __packed;
78169689Skan
79169689Skan/*
80169689Skan * Header at the beginning of a V1 server list.  This is followed directly by
81169689Skan * the server records.  Each server records begins with a struct of type
82169689Skan * dns_server_list_v1_server.
83169689Skan */
84169689Skanstruct dns_server_list_v1_header {
85169689Skan	struct dns_payload_header hdr;
86169689Skan	__u8		source;		/* enum dns_record_source */
87169689Skan	__u8		status;		/* enum dns_lookup_status */
88169689Skan	__u8		nr_servers;	/* Number of server records following this */
89169689Skan} __packed;
90169689Skan
91169689Skan/*
92169689Skan * Header at the beginning of each V1 server record.  This is followed by the
93169689Skan * characters of the name with no NUL-terminator, followed by the address
94169689Skan * records for that server.  Each address record begins with a struct of type
95169689Skan * struct dns_server_list_v1_address.
96169689Skan */
97169689Skanstruct dns_server_list_v1_server {
98169689Skan	__u16		name_len;	/* Length of name (LE) */
99169689Skan	__u16		priority;	/* Priority (as SRV record) (LE) */
100169689Skan	__u16		weight;		/* Weight (as SRV record) (LE) */
101169689Skan	__u16		port;		/* UDP/TCP port number (LE) */
102169689Skan	__u8		source;		/* enum dns_record_source */
103169689Skan	__u8		status;		/* enum dns_lookup_status */
104169689Skan	__u8		protocol;	/* enum dns_payload_protocol_type */
105169689Skan	__u8		nr_addrs;
106169689Skan} __packed;
107169689Skan
108169689Skan/*
109169689Skan * Header at the beginning of each V1 address record.  This is followed by the
110169689Skan * bytes of the address, 4 for IPV4 and 16 for IPV6.
111169689Skan */
112169689Skanstruct dns_server_list_v1_address {
113169689Skan	__u8		address_type;	/* enum dns_payload_address_type */
114169689Skan} __packed;
115169689Skan
116169689Skan#endif /* _UAPI_LINUX_DNS_RESOLVER_H */
117169689Skan