← Documents Documentation/networking/dns_resolver.rst GitHub 원문 ↗

Linux 6.18.37 · Networking

DNS Resolver Module

커널 DNS 질의를 dns_resolver 키 요청과 사용자 공간 업콜로 처리하고 결과를 TTL에 따라 캐시하는 방법을 설명합니다.

Source pathDocumentation/networking/dns_resolver.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

dns_resolver.rst:1-153

커널 자체가 DNS 프로토콜을 직접 처리하는 대신 키 요청 인터페이스를 통해 사용자 공간 도구에 조회를 맡기고, 받은 문자열을 `dns_resolver` 키의 페이로드로 캐시하는 구조입니다. 설정 규칙의 첫 일치 우선순위, 결과 메모리 해제 책임, 최저 TTL을 사용한 만료 설정이 운용의 핵심입니다.

DNS 질의 처리 흐름
dns_query()request_key()로컬 키링 조회캐시 미스/sbin/request-key업콜 처리 프로그램DNS 조회dns_resolver 키 인스턴스화결과 반환

캐시 적중 여부에 따라 사용자 공간 업콜과 키 인스턴스화가 이어집니다.

호출 규약 핵심
항목규약
nameNUL 종료 불필요, namelen으로 길이 전달
optionsNULL 또는 질의 종류별 옵션
_result호출자가 결과 문자열 해제
반환값성공 시 문자열 길이, 실패 시 음수 오류
_expiryNULL이 아니면 TTL 만료 시간 반환

함수 사용 시 호출자가 지켜야 할 입력·출력 규약입니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 ===================
4 DNS Resolver Module
5 ===================
6
7 .. Contents:
8
9 - Overview.
10 - Compilation.
11 - Setting up.
12 - Usage.
13 - Mechanism.
14 - Debugging.
15
16
17 Overview
18 ========
19
20 The DNS resolver module provides a way for kernel services to make DNS queries
21 by way of requesting a key of key type dns_resolver. These queries are
22 upcalled to userspace through /sbin/request-key.
23
24 These routines must be supported by userspace tools dns.upcall, cifs.upcall and
25 request-key. It is under development and does not yet provide the full feature
26 set. The features it does support include:
27
28 * Implements the dns_resolver key_type to contact userspace.
29
30 It does not yet support the following AFS features:
31
32 * DNS query support for AFSDB resource record.
33
34 This code is extracted from the CIFS filesystem.
35
36
37 Compilation
38 ===========
39
40 The module should be enabled by turning on the kernel configuration options::
41
42 CONFIG_DNS_RESOLVER - tristate "DNS Resolver support"
43
44
45 Setting up
46 ==========
47
48 To set up this facility, the /etc/request-key.conf file must be altered so that
49 /sbin/request-key can appropriately direct the upcalls. For example, to handle
50 basic dname to IPv4/IPv6 address resolution, the following line should be
51 added::
52
53
54 #OP TYPE DESC CO-INFO PROGRAM ARG1 ARG2 ARG3 ...
55 #====== ============ ======= ======= ==========================
56 create dns_resolver * * /usr/sbin/cifs.upcall %k
57
58 To direct a query for query type 'foo', a line of the following should be added
59 before the more general line given above as the first match is the one taken::
60
61 create dns_resolver foo:* * /usr/sbin/dns.foo %k
62
63
64 Usage
65 =====
66
67 To make use of this facility, first ``dns_resolver.h`` must be included::
68
69 #include <linux/dns_resolver.h>
70
71 Then queries may be made by calling::
72
73 int dns_query(const char *type, const char *name, size_t namelen,
74 const char *options, char **_result, time_t *_expiry);
75
76 This is the basic access function. It looks for a cached DNS query and if
77 it doesn't find it, it upcalls to userspace to make a new DNS query, which
78 may then be cached. The key description is constructed as a string of the
79 form::
80
81 [<type>:]<name>
82
83 where <type> optionally specifies the particular upcall program to invoke,
84 and thus the type of query, and <name> specifies the string to be looked up.
85 The default query type is a straight hostname to IP address set lookup.
86
87 The name parameter is not required to be a NUL-terminated string, and its
88 length should be given by the namelen argument.
89
90 The options parameter may be NULL or it may be a set of options
91 appropriate to the query type.
92
93 The return value is a string appropriate to the query type. For instance,
94 for the default query type it is just a list of comma-separated IPv4 and
95 IPv6 addresses. The caller must free the result.
96
97 The length of the result string is returned on success, and a negative
98 error code is returned otherwise. -EKEYREJECTED will be returned if the
99 DNS lookup failed.
100
101 If _expiry is non-NULL, the expiry time (TTL) of the result will be
102 returned also.
103
104 The kernel maintains an internal keyring in which it caches looked up keys.
105 This can be cleared by any process that has the CAP_SYS_ADMIN capability by
106 the use of KEYCTL_KEYRING_CLEAR on the keyring ID.
107
108
109 Reading DNS Keys from Userspace
110 ===============================
111
112 Keys of dns_resolver type can be read from userspace using keyctl_read() or
113 "keyctl read/print/pipe".
114
115
116 Mechanism
117 =========
118
119 The dns_resolver module registers a key type called "dns_resolver". Keys of
120 this type are used to transport and cache DNS lookup results from userspace.
121
122 When dns_query() is invoked, it calls request_key() to search the local
123 keyrings for a cached DNS result. If that fails to find one, it upcalls to
124 userspace to get a new result.
125
126 Upcalls to userspace are made through the request_key() upcall vector, and are
127 directed by means of configuration lines in /etc/request-key.conf that tell
128 /sbin/request-key what program to run to instantiate the key.
129
130 The upcall handler program is responsible for querying the DNS, processing the
131 result into a form suitable for passing to the keyctl_instantiate_key()
132 routine. This then passes the data to dns_resolver_instantiate() which strips
133 off and processes any options included in the data, and then attaches the
134 remainder of the string to the key as its payload.
135
136 The upcall handler program should set the expiry time on the key to that of the
137 lowest TTL of all the records it has extracted a result from. This means that
138 the key will be discarded and recreated when the data it holds has expired.
139
140 dns_query() returns a copy of the value attached to the key, or an error if
141 that is indicated instead.
142
143 See Documentation/security/keys/request-key.rst for further information about
144 request-key function.
145
146
147 Debugging
148 =========
149
150 Debugging messages can be turned on dynamically by writing a 1 into the
151 following file::
152
153 /sys/module/dns_resolver/parameters/debug
154

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

DNS 리졸버 모듈과 문서 구성

1-16

이 문서는 `GPL-2.0` 라이선스를 따릅니다.

DNS Resolver Module

문서는 개요, 컴파일, 설정, 사용법, 동작 메커니즘, 디버깅 순서로 구성됩니다.

.. SPDX-License-Identifier: GPL-2.0

===================
DNS Resolver Module
===================

.. Contents:

 - Overview.
 - Compilation.
 - Setting up.
 - Usage.
 - Mechanism.
 - Debugging.

커널 DNS 질의와 현재 지원 범위

17-36

개요

DNS 리졸버 모듈은 커널 서비스가 `dns_resolver` 키 형식의 키를 요청하는 방식으로 DNS 질의를 수행할 수 있게 합니다. 이 질의는 `/sbin/request-key`를 통해 사용자 공간으로 업콜됩니다.

이 루틴을 사용하려면 사용자 공간 도구 `dns.upcall`, `cifs.upcall`, `request-key`가 지원되어야 합니다. 아직 개발 중이어서 전체 기능을 제공하지는 않습니다.

현재 지원하는 기능은 사용자 공간과 접촉하기 위한 `dns_resolver` `key_type` 구현입니다.

아직 지원하지 않는 AFS 기능은 AFSDB 리소스 레코드에 대한 DNS 질의입니다.

이 코드는 CIFS 파일시스템에서 분리해 가져왔습니다.

Overview
========

The DNS resolver module provides a way for kernel services to make DNS queries
by way of requesting a key of key type dns_resolver.  These queries are
upcalled to userspace through /sbin/request-key.

These routines must be supported by userspace tools dns.upcall, cifs.upcall and
request-key.  It is under development and does not yet provide the full feature
set.  The features it does support include:

 * Implements the dns_resolver key_type to contact userspace.

It does not yet support the following AFS features:

 * DNS query support for AFSDB resource record.

This code is extracted from the CIFS filesystem.

커널 설정으로 모듈 활성화

37-44

컴파일

다음 커널 설정 옵션을 켜서 모듈을 활성화해야 합니다.

CONFIG_DNS_RESOLVER	- tristate "DNS Resolver support"
Compilation
===========

The module should be enabled by turning on the kernel configuration options::

        CONFIG_DNS_RESOLVER        - tristate "DNS Resolver support"

request-key 업콜 경로 설정

45-63

설정

이 기능을 설정하려면 `/sbin/request-key`가 업콜을 적절한 프로그램으로 전달하도록 `/etc/request-key.conf`를 수정해야 합니다. 기본 도메인 이름을 IPv4 또는 IPv6 주소로 변환하려면 다음과 같은 줄을 추가합니다.

#OP	TYPE		DESC	CO-INFO	PROGRAM ARG1 ARG2 ARG3 ...
#======	============	=======	=======	==========================
create	dns_resolver  	*	*	/usr/sbin/cifs.upcall %k

`foo` 형식의 질의를 별도 프로그램으로 전달하려면 아래 줄을 더 일반적인 규칙보다 앞에 둡니다. 설정에서는 처음 일치한 규칙을 사용합니다.

create	dns_resolver  	foo:*	*	/usr/sbin/dns.foo %k
Setting up
==========

To set up this facility, the /etc/request-key.conf file must be altered so that
/sbin/request-key can appropriately direct the upcalls.  For example, to handle
basic dname to IPv4/IPv6 address resolution, the following line should be
added::


        #OP        TYPE                DESC        CO-INFO        PROGRAM ARG1 ARG2 ARG3 ...
        #======        ============        =======        =======        ==========================
        create        dns_resolver          *        *        /usr/sbin/cifs.upcall %k

To direct a query for query type 'foo', a line of the following should be added
before the more general line given above as the first match is the one taken::

        create        dns_resolver          foo:*        *        /usr/sbin/dns.foo %k

dns_query() 호출과 반환 규약

64-108

사용법

먼저 `dns_resolver.h`를 포함합니다.

#include <linux/dns_resolver.h>

그런 다음 `dns_query()`를 호출해 질의합니다.

int dns_query(const char *type, const char *name, size_t namelen,
              const char *options, char **_result, time_t *_expiry);

이 함수는 기본 접근 함수입니다. 캐시된 DNS 질의 결과를 찾고, 없으면 사용자 공간으로 업콜하여 새 DNS 질의를 수행한 뒤 그 결과를 캐시할 수 있습니다.

키 설명 문자열은 `[<type>:]<name>` 형식입니다. 선택적인 `<type>`은 호출할 업콜 프로그램과 질의 종류를 지정하고, `<name>`은 조회할 문자열을 지정합니다. 기본 질의 종류는 호스트 이름을 IP 주소 집합으로 변환하는 조회입니다.

`name`은 NUL로 끝나는 문자열일 필요가 없으며 길이는 `namelen` 인자로 전달합니다. `options`는 `NULL`이거나 질의 종류에 맞는 옵션 집합일 수 있습니다.

반환 결과는 질의 종류에 맞는 문자열입니다. 기본 질의에서는 쉼표로 구분한 IPv4 및 IPv6 주소 목록입니다. 호출자는 결과를 해제해야 합니다.

성공하면 결과 문자열 길이를 반환하고 실패하면 음수 오류 코드를 반환합니다. DNS 조회가 실패하면 `-EKEYREJECTED`를 반환합니다.

`_expiry`가 `NULL`이 아니면 결과의 만료 시간(TTL)도 함께 반환합니다.

커널은 조회한 키를 내부 키링에 캐시합니다. `CAP_SYS_ADMIN` 권한이 있는 프로세스는 키링 ID에 `KEYCTL_KEYRING_CLEAR`를 사용하여 이 캐시를 비울 수 있습니다.

Usage
=====

To make use of this facility, first ``dns_resolver.h`` must be included::

        #include <linux/dns_resolver.h>

Then queries may be made by calling::

        int dns_query(const char *type, const char *name, size_t namelen,
                     const char *options, char **_result, time_t *_expiry);

This is the basic access function.  It looks for a cached DNS query and if
it doesn't find it, it upcalls to userspace to make a new DNS query, which
may then be cached.  The key description is constructed as a string of the
form::

                [<type>:]<name>

where <type> optionally specifies the particular upcall program to invoke,
and thus the type of query, and <name> specifies the string to be looked up.
The default query type is a straight hostname to IP address set lookup.

The name parameter is not required to be a NUL-terminated string, and its
length should be given by the namelen argument.

The options parameter may be NULL or it may be a set of options
appropriate to the query type.

The return value is a string appropriate to the query type.  For instance,
for the default query type it is just a list of comma-separated IPv4 and
IPv6 addresses.  The caller must free the result.

The length of the result string is returned on success, and a negative
error code is returned otherwise.  -EKEYREJECTED will be returned if the
DNS lookup failed.

If _expiry is non-NULL, the expiry time (TTL) of the result will be
returned also.

The kernel maintains an internal keyring in which it caches looked up keys.
This can be cleared by any process that has the CAP_SYS_ADMIN capability by
the use of KEYCTL_KEYRING_CLEAR on the keyring ID.

사용자 공간에서 DNS 키 읽기

109-115

사용자 공간에서 DNS 키 읽기

`dns_resolver` 형식의 키는 사용자 공간에서 `keyctl_read()` 또는 `keyctl read`, `keyctl print`, `keyctl pipe` 명령으로 읽을 수 있습니다.

Reading DNS Keys from Userspace
===============================

Keys of dns_resolver type can be read from userspace using keyctl_read() or
"keyctl read/print/pipe".

키 요청·업콜·캐시 수명 메커니즘

116-146

동작 메커니즘

`dns_resolver` 모듈은 이름이 `dns_resolver`인 키 형식을 등록합니다. 이 형식의 키는 사용자 공간에서 얻은 DNS 조회 결과를 전달하고 캐시하는 데 사용됩니다.

`dns_query()`가 호출되면 `request_key()`를 호출하여 로컬 키링에서 캐시된 DNS 결과를 찾습니다. 결과가 없으면 사용자 공간으로 업콜하여 새 결과를 얻습니다.

사용자 공간 업콜은 `request_key()` 업콜 벡터를 통해 이루어집니다. `/etc/request-key.conf`의 설정 줄은 `/sbin/request-key`가 키를 인스턴스화하기 위해 어떤 프로그램을 실행할지 지정합니다.

업콜 처리 프로그램은 DNS를 질의하고 결과를 `keyctl_instantiate_key()`에 전달하기 적합한 형태로 가공해야 합니다. 이 루틴은 데이터를 `dns_resolver_instantiate()`에 넘기며, 후자는 데이터에 포함된 옵션을 분리해 처리한 뒤 나머지 문자열을 키의 페이로드로 연결합니다.

업콜 처리 프로그램은 결과를 추출한 모든 레코드 중 가장 낮은 TTL을 키 만료 시간으로 설정해야 합니다. 따라서 보관 데이터가 만료되면 해당 키가 폐기되고 다시 생성됩니다.

`dns_query()`는 키에 연결된 값의 복사본을 반환하며, 키가 오류를 나타내면 그 오류를 반환합니다.

`request-key` 함수에 관한 자세한 내용은 `Documentation/security/keys/request-key.rst`를 참고하십시오.

Mechanism
=========

The dns_resolver module registers a key type called "dns_resolver".  Keys of
this type are used to transport and cache DNS lookup results from userspace.

When dns_query() is invoked, it calls request_key() to search the local
keyrings for a cached DNS result.  If that fails to find one, it upcalls to
userspace to get a new result.

Upcalls to userspace are made through the request_key() upcall vector, and are
directed by means of configuration lines in /etc/request-key.conf that tell
/sbin/request-key what program to run to instantiate the key.

The upcall handler program is responsible for querying the DNS, processing the
result into a form suitable for passing to the keyctl_instantiate_key()
routine.  This then passes the data to dns_resolver_instantiate() which strips
off and processes any options included in the data, and then attaches the
remainder of the string to the key as its payload.

The upcall handler program should set the expiry time on the key to that of the
lowest TTL of all the records it has extracted a result from.  This means that
the key will be discarded and recreated when the data it holds has expired.

dns_query() returns a copy of the value attached to the key, or an error if
that is indicated instead.

See Documentation/security/keys/request-key.rst for further information about
request-key function.

동적 디버그 메시지 활성화

147-153

디버깅

다음 파일에 `1`을 쓰면 디버그 메시지를 동적으로 활성화할 수 있습니다.

/sys/module/dns_resolver/parameters/debug
Debugging
=========

Debugging messages can be turned on dynamically by writing a 1 into the
following file::

        /sys/module/dns_resolver/parameters/debug