Bug 1648009

Summary: NetworkManager limits the search field of resolv.conf to 6 entries in _collect_resolv_conf_data()
Product: Red Hat Enterprise Linux 7 Reporter: Kyle Walker <kwalker>
Component: NetworkManagerAssignee: Thomas Haller <thaller>
Status: CLOSED ERRATA QA Contact: Desktop QE <desktop-qa-list>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.6CC: atragler, bgalvani, fgiudici, fpokryvk, fweimer, lrintel, ptalbert, rkhan, sukulkar, thaller
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: NetworkManager-1.18.0-0.3.20190408git43d9187c14.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1649704 (view as bug list) Environment:
Last Closed: 2019-08-06 13:16:25 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1649704    

Description Kyle Walker 2018-11-08 17:47:52 UTC
Description of problem:
 The _collect_resolv_conf_data() function limits the number of search entries to 6 within the following code snippet. Taken from the 1.10.2-16 source revision:

        /* Per 'man resolv.conf', the search list is limited to 6 domains
         * totalling 256 characters.
         */
        num = MIN (rc.searches->len, 6u);
        for (i = 0, len = 0; i < num; i++) {
                len += strlen (rc.searches->pdata[i]) + 1; /* +1 for spaces */
                if (len > 256)
                        break;
        }
        g_ptr_array_set_size (rc.searches, i);

This is no longer the limit for later RHEL releases. The limit was removed with the efforts in RHBZ677316 [^1] and released in upstream glibc-2.26 [^2].

Version-Release number of selected component (if applicable):
 # rpm -q NetworkManager
 NetworkManager-1.10.2-16.el7_5.x86_64

How reproducible:
 Easily

Steps to Reproduce:
1. Set an interface to a ipv4.dns-search entry greater than 6
    # nmcli con modify System\ eth0 ipv4.dns-search $(echo {a..g}.redhat.com, | sed -e 's/ //g' -e 's/,$//g')
    
2. Verify the ipv4.dns-search field includes more than 6 entries

    # nmcli con show System\ eth0 | grep ipv4.dns-search
    ipv4.dns-search:                        a.redhat.com,b.redhat.com,c.redhat.com,d.redhat.com,e.redhat.com,f.redhat.com,g.redhat.com

3. Issue an "nmcli con up <interface>" and verify that the /etc/resolv.conf has more than 6 entries

    # nmcli con up System\ eth0
    # grep search /etc/resolv.conf

Actual results:
    search a.redhat.com b.redhat.com c.redhat.com d.redhat.com e.redhat.com f.redhat.com


Expected results:
    search a.redhat.com b.redhat.com c.redhat.com d.redhat.com e.redhat.com f.redhat.com g.redhat.com


Additional info:
 The problem is not seen when disabling NetworkManager and falling back to the underlying network initscripts.

    # systemctl stop NetworkManager && systemctl restart network && grep search 
    /etc/resolv.conf
search a.redhat.com b.redhat.com c.redhat.com d.redhat.com e.redhat.com f.redhat.com g.redhat.com

 The problem is also present with the latest available upstream NetworkManager revision [^3].

[^1]: https://bugzilla.redhat.com/show_bug.cgi?id=677316
[^2]: https://sourceware.org/ml/libc-alpha/2017-08/msg00010.html
[^3]: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/blob/master/src/dns/nm-dns-manager.c#L1132

Comment 2 Kyle Walker 2018-11-08 19:50:35 UTC
Filed an upstream issue as well:

    https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/80

- Kyle Walker

Comment 3 Kyle Walker 2018-11-13 15:13:06 UTC
Patch suggestion accepted upstream:

    https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/80

Additional patch added to avoid search entry being truncated on legacy systems. Full patch set upstream is:

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/commit/49c11a44e4e901752a81e3942efca64448fa7c53
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/commit/3f2cc579e7627f45a77f835ba2f402e1b5c600b5

- Kyle Walker

Comment 4 Thomas Haller 2018-11-13 15:30:34 UTC
fixed upstream.

Comment 6 Juan Gamba 2019-07-18 20:41:36 UTC
As a workaround the NetworkManager global-dns 'searches=' option is not limited to 6 search domains.

WORKAROUND
==========

Create a file in /etc/NetworkManager/conf.d/*.conf and add these entries:

[main]
dns=default

[global-dns]
searches=one.example.com two.example.com three.example.com four.example.com five.example.com six.example.com seven.example.com eight.example.com

[global-dns-domain-*]
servers=xxx.xxx.xxx.xxx

Comment 8 errata-xmlrpc 2019-08-06 13:16:25 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2019:2302