Skip to content

Commit cb3a0a5

Browse files
authored
Fix: Map /etc/resolv.conf file in device quirks (#3808)
The initial approach to DNS client on Linux containers blindly mapped /etc/resolv.conf file and used the Docker DNS forwarder as the DNS resolver. That broke on Podman (see #3803). This fix maps the /etc/resolv.conf file into the container only when we need to set our own DNS servers; otherwise it leaves the container management system to do its job. The mapping is done in device quirks and has to be applied to Linux, FRR, and all daemons.
1 parent b1c4797 commit cb3a0a5

23 files changed

Lines changed: 30 additions & 150 deletions

netsim/devices/bird.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from . import _Quirks
77
from ._common import check_daemon_dataplane_config
8+
from .linux import etc_resolv_mapping
89

910

1011
def bird_transform_rt(rt: str) -> str:
@@ -46,6 +47,7 @@ class Bird(_Quirks):
4647

4748
@classmethod
4849
def device_quirks(self, node: Box, topology: Box) -> None:
50+
etc_resolv_mapping(node,topology)
4951
check_daemon_dataplane_config(node,topology)
5052
bird_vrf_rt(node)
5153
bird_vlan_evpn_rt(node)

netsim/devices/dnsmasq.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# dnsmasq quirks
3+
#
4+
from box import Box
5+
6+
from . import _Quirks
7+
from .linux import etc_resolv_mapping
8+
9+
10+
class Dnsmasq(_Quirks):
11+
12+
@classmethod
13+
def device_quirks(self, node: Box, topology: Box) -> None:
14+
etc_resolv_mapping(node,topology)

netsim/devices/frr.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from ..utils import log
77
from . import _Quirks, report_quirk
8+
from .linux import etc_resolv_mapping
89

910
"""
1011
Because FRR uses a 'bridge per VLAN' model, STP BPDUs are sent as tagged packets, not untagged.
@@ -28,6 +29,7 @@ class FRR(_Quirks):
2829

2930
@classmethod
3031
def device_quirks(self, node: Box, topology: Box) -> None:
32+
etc_resolv_mapping(node,topology)
3133
mods = node.get('module',[])
3234
if 'stp' in mods and node.get('stp.enable',True):
3335
if log.debug_active('quirks'):

netsim/devices/frr.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ clab:
5656
config_templates:
5757
daemons: /etc/frr/daemons
5858
hosts: /etc/hosts:shared
59-
resolv: /etc/resolv.conf
6059

6160
libvirt:
6261
image: debian/bookworm64

netsim/devices/linux.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,23 @@ def check_extra_loopbacks(node: Box, topology: Box) -> None:
3030
category=log.IncorrectType,
3131
quirk='ubuntu_dummy')
3232

33+
def etc_resolv_mapping(node: Box, topology: Box) -> None:
34+
"""
35+
Add /etc/resolv.conf mapping for Linux-based containers using DNS services
36+
"""
37+
if devices.get_provider(node,topology) != 'clab':
38+
return
39+
if 'services.dns._server_list' not in node:
40+
return
41+
if 'clab.config_templates.resolv' not in node:
42+
node.clab.config_templates.resolv = '/etc/resolv.conf'
43+
3344
class Linux(_Quirks):
3445

3546
@classmethod
3647
def device_quirks(self, node: Box, topology: Box) -> None:
3748
check_indirect_static_routes(node)
49+
etc_resolv_mapping(node,topology)
3850

3951
if devices.get_provider(node,topology) != 'clab':
4052
check_vm_modules(node,topology)

netsim/devices/linux.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ clab:
7373
kind: linux
7474
config_templates:
7575
hosts: /etc/hosts:shared
76-
resolv: /etc/resolv.conf
7776
group_vars:
7877
ansible_connection: docker
7978
ansible_user: root

tests/coverage/expected/check-config-files.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ nodes:
4040
- mode: ro
4141
source: node_files/-shared-hosts
4242
target: /etc/hosts
43-
- source: node_files/r1/resolv
44-
target: /etc/resolv.conf
4543
config_templates:
4644
- mode: sh
4745
source: initial
@@ -54,8 +52,6 @@ nodes:
5452
- mode: shared
5553
source: hosts
5654
target: /etc/hosts
57-
- source: resolv
58-
target: /etc/resolv.conf
5955
exec:
6056
- sleep 1
6157
kind: linux
@@ -108,8 +104,6 @@ nodes:
108104
- mode: ro
109105
source: node_files/-shared-hosts
110106
target: /etc/hosts
111-
- source: node_files/r2/resolv
112-
target: /etc/resolv.conf
113107
config_templates:
114108
- mode: sh
115109
source: initial
@@ -119,8 +113,6 @@ nodes:
119113
- mode: shared
120114
source: hosts
121115
target: /etc/hosts
122-
- source: resolv
123-
target: /etc/resolv.conf
124116
exec:
125117
- sleep 1
126118
kind: linux

tests/coverage/expected/device-module-defaults.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ nodes:
8383
- mode: ro
8484
source: node_files/-shared-hosts
8585
target: /etc/hosts
86-
- source: node_files/l1/resolv
87-
target: /etc/resolv.conf
8886
config_templates:
8987
- mode: sh
9088
source: initial
@@ -97,8 +95,6 @@ nodes:
9795
- mode: shared
9896
source: hosts
9997
target: /etc/hosts
100-
- source: resolv
101-
target: /etc/resolv.conf
10298
exec:
10399
- sleep 1
104100
kind: linux

tests/coverage/expected/device-node-defaults.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ nodes:
6262
- mode: ro
6363
source: node_files/-shared-hosts
6464
target: /etc/hosts
65-
- source: node_files/h1/resolv
66-
target: /etc/resolv.conf
6765
config_templates:
6866
- mode: ns
6967
source: initial
@@ -74,8 +72,6 @@ nodes:
7472
- mode: shared
7573
source: hosts
7674
target: /etc/hosts
77-
- source: resolv
78-
target: /etc/resolv.conf
7975
kind: linux
8076
device: linux
8177
hostname: clab-input-h1
@@ -142,8 +138,6 @@ nodes:
142138
- mode: ro
143139
source: node_files/-shared-hosts
144140
target: /etc/hosts
145-
- source: node_files/h2/resolv
146-
target: /etc/resolv.conf
147141
config_templates:
148142
- mode: ns
149143
source: initial
@@ -154,8 +148,6 @@ nodes:
154148
- mode: shared
155149
source: hosts
156150
target: /etc/hosts
157-
- source: resolv
158-
target: /etc/resolv.conf
159151
kind: linux
160152
device: linux
161153
hostname: clab-input-h2
@@ -228,8 +220,6 @@ nodes:
228220
- mode: ro
229221
source: node_files/-shared-hosts
230222
target: /etc/hosts
231-
- source: node_files/rtr/resolv
232-
target: /etc/resolv.conf
233223
config_templates:
234224
- mode: sh
235225
source: initial
@@ -242,8 +232,6 @@ nodes:
242232
- mode: shared
243233
source: hosts
244234
target: /etc/hosts
245-
- source: resolv
246-
target: /etc/resolv.conf
247235
exec:
248236
- sleep 1
249237
image: none

tests/topology/expected/bridge-module-attr.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ nodes:
7373
- mode: ro
7474
source: node_files/-shared-hosts
7575
target: /etc/hosts
76-
- source: node_files/br/resolv
77-
target: /etc/resolv.conf
7876
config_templates:
7977
- mode: ns
8078
source: initial
@@ -85,8 +83,6 @@ nodes:
8583
- mode: shared
8684
source: hosts
8785
target: /etc/hosts
88-
- source: resolv
89-
target: /etc/resolv.conf
9086
kind: linux
9187
device: linux
9288
hostname: clab-input-br
@@ -187,8 +183,6 @@ nodes:
187183
- mode: ro
188184
source: node_files/-shared-hosts
189185
target: /etc/hosts
190-
- source: node_files/r1/resolv
191-
target: /etc/resolv.conf
192186
config_templates:
193187
- mode: sh
194188
source: initial
@@ -201,8 +195,6 @@ nodes:
201195
- mode: shared
202196
source: hosts
203197
target: /etc/hosts
204-
- source: resolv
205-
target: /etc/resolv.conf
206198
exec:
207199
- sleep 1
208200
kind: linux
@@ -283,8 +275,6 @@ nodes:
283275
- mode: ro
284276
source: node_files/-shared-hosts
285277
target: /etc/hosts
286-
- source: node_files/r2/resolv
287-
target: /etc/resolv.conf
288278
config_templates:
289279
- mode: sh
290280
source: initial
@@ -297,8 +287,6 @@ nodes:
297287
- mode: shared
298288
source: hosts
299289
target: /etc/hosts
300-
- source: resolv
301-
target: /etc/resolv.conf
302290
exec:
303291
- sleep 1
304292
kind: linux

0 commit comments

Comments
 (0)