Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.
Bug 1086425 - dhclient-script: hard-wired /etc/resolv.conf
Summary: dhclient-script: hard-wired /etc/resolv.conf
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: dhcp
Version: 21
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Jiri Popelka
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-04-10 21:05 UTC by Dale R. Worley
Modified: 2015-07-14 17:24 UTC (History)
3 users (show)

Fixed In Version: dhcp-4.3.2-11.fc23
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-07-14 17:23:42 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Dale R. Worley 2014-04-10 21:05:52 UTC
Description of problem:  Various problems in coding DHCP make customization harder.


Version-Release number of selected component (if applicable):
dhclient-4.2.5-23.fc19.x86_64
initscripts-9.47-1.fc19.x86_64


See the list of issues below.


Additional info:

Background:  I was installing dnsmasq to provide local DNS caching capability, and having dnsmasq forward requests upstream to the servers provided by DHCP.  As described in the dnsmasq manual page:

       In order to configure dnsmasq to act as cache for the host on which  it
       is  running,  put  "nameserver  127.0.0.1" in /etc/resolv.conf to force
       local processes to send queries to dnsmasq.  Then  either  specify  the
       upstream  servers  directly  to  dnsmasq  using --server options or put
       their addresses real in another file, say /etc/resolv.dnsmasq  and  run
       dnsmasq  with  the -r /etc/resolv.dnsmasq option. This second technique
       allows for dynamic update of the server addresses by PPP or DHCP.

The DNS server addresses received by dhclient are normally written into /etc/resolv.conf by /usr/sbin/dhclient-script.  The manual page for dhclient-script says:

       This  script  is  not meant to be customized by the end user.  If local
       customizations are needed, they should be possible using the enter  and
       exit  hooks  provided (see HOOKS for details).   These hooks will allow
       the user to override the default behaviour of the client in creating  a
       /etc/resolv.conf  file,  and  to  handle  DHCP  options  not handled by
       default.

So I set out to write /etc/dhcp/dhclient-enter-hooks to customize dhclient-script to place the DNS server addresses into /etc/resolv.conf.dhcp rather than /etc/resolv.conf.  While doing this customization, I ran into a number of things which could be done much better.

- In dhclient-script, a number of values are configured by variable assignment:  SAVEDIR, LOGFACILITY, LOGLEVEL, ETCDIR.  But the location of the resolv.conf file is not configurable; its name appears in the script three separate times.  Because of this, I had to include in /etc/dhcp/dhclient-enter-hooks the entirety of make_resolv_conf, rather than just "RESOLV=/etc/resolv.conf.dhcp".  Unfortunately, make_resolv_conf calls eventually_add_hostnames_domain_to_search and change_resolv_conf (in /etc/sysconfig/network-scripts/network-functions), both of which also hard-code /etc/resolv.conf, so I had to include customized copies of those functions as well (under different names, for fear of disrupting some other user of those functions.

- The partitioning of responsibilities between make_resolv_conf and change_resolv_conf is not well done.  One would expect that make_resolv_conf would write the new resolv.conf file and that change_resolv_conf would notify whatever services need to be notified.

(And that would allow me to improve the logical structure of my customization, because resolv.conf itself (which the services presumably pay attention to) doesn't change; only resolv.conf.dhcp changes.  So change_resolv_conf would not need to be called.)

But it turns out that make_resolv_conf computes the new contents for resolv.conf.dhcp, but does not write them into the file.  The writing is done by change_resolv_conf.  This is despite that the comment at the top of change_resolv_conf is "# Invoke this when /etc/resolv.conf has changed:".

- It would also help if there were configuration variables for "After writing resolv.conf, do we need to call change_resolv_conf?" and "Do we copy the domain name provided by DHCP into resolv.conf?".

- It is not clear which function, make_resolv_conf or change_resolv_conf, is responsible for setting the security context of the new resolv.conf.  make_resolv_conf calls "fix_context /etc/resolv.conf" but change_resolv_conf calls "/sbin/restorecon /etc/resolv.conf".  The fact that both functions seem to do the same thing suggests that there is no clear assignment of responsibilities here.

- change_resolv_conf is quite poorly documented.  I've noted that its actions are not at all described by its comment.  Worse, its treatment of its arguments is complex and not documented *at all*:  If there is one argument, it is the name of a file whose contents are to be inserted into resolv.conf, after any "option" lines in the file which already appear in the old resolv.conf are moved to the beginning of the file.  If there is more than one argument, the processing is quite complicated and I haven't figured it out, but I know that the arguments aren't file names.

- change_resolv_conf uses some excessively complex constructions.  The test '[ "x$s" != "x" ]' is used where '[ -n "$s" ]' would be clearer. The test 'case "$s" in *$1*)' is used where 'if [[ "$s" == *"$1"* ]]' would be clearer.

Comment 1 Tomáš Hozza 2014-04-11 06:25:27 UTC
Hi.

Thank you for your suggestions.

Did you considered using NetworkManager and its dnsmasq DNS plugin?
It will do everything you want automatically...

Comment 2 Jiri Popelka 2014-04-11 11:15:25 UTC
Thanks for the investigation and description.

I have nothing against removing the hard-wired /etc/resolv.conf from dhclient-script. The problem here is that initscripts (where change_resolv_conf resides) package is in "maintenance" mode (since we've had systemd) and I'm quite sure the maintainer is not willing to do such changes (I already tried some time ago with bug #679445).

Comment 3 Dale R. Worley 2014-04-11 15:44:31 UTC
(In reply to Tomas Hozza from comment #1)
> Did you considered using NetworkManager and its dnsmasq DNS plugin?
> It will do everything you want automatically...

I've looked at NetworkManager once or twice, but a number of factors discouraged me from using it:

- I dislike systems that guess for me what I probably want done.  I prefer tight control over not having to be aware of the details.  (That's why I run Linux!)

- I've never found good documentation for NetworkManager.

- I've never been able to run the NetworkManager GUI.  This seems to be due to the fact that my window manager is vtwm, and the NM GUI seems to not be a standard X client application.

Comment 4 Fedora End Of Life 2015-01-09 21:17:56 UTC
This message is a notice that Fedora 19 is now at end of life. Fedora 
has stopped maintaining and issuing updates for Fedora 19. It is 
Fedora's policy to close all bug reports from releases that are no 
longer maintained. Approximately 4 (four) weeks from now this bug will
be closed as EOL if it remains open with a Fedora 'version' of '19'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version.

Thank you for reporting this issue and we are sorry that we were not 
able to fix it before Fedora 19 is end of life. If you would still like 
to see this bug fixed and are able to reproduce it against a later version 
of Fedora, you are encouraged  change the 'version' to a later Fedora 
version prior this bug is closed as described in the policy above.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

Comment 5 Jiri Popelka 2015-07-14 17:23:42 UTC
(In reply to Dale R. Worley from comment #0)
> - In dhclient-script, a number of values are configured by variable
> assignment:  SAVEDIR, LOGFACILITY, LOGLEVEL, ETCDIR.  But the location of
> the resolv.conf file is not configurable; its name appears in the script
> three separate times.  Because of this, I had to include in
> /etc/dhcp/dhclient-enter-hooks the entirety of make_resolv_conf, rather than
> just "RESOLV=/etc/resolv.conf.dhcp".  Unfortunately, make_resolv_conf calls
> eventually_add_hostnames_domain_to_search and change_resolv_conf (in
> /etc/sysconfig/network-scripts/network-functions), both of which also
> hard-code /etc/resolv.conf, so I had to include customized copies of those
> functions as well (under different names, for fear of disrupting some other
> user of those functions.

I've copied ([1]) change_resolv_conf() from initscripts into dhclient-script and created ([2]) new RESOLVCONF variable, which all the code uses.

> - change_resolv_conf is quite poorly documented.  I've noted that its
> actions are not at all described by its comment.  Worse, its treatment of
> its arguments is complex and not documented *at all*:  If there is one
> argument, it is the name of a file whose contents are to be inserted into
> resolv.conf, after any "option" lines in the file which already appear in
> the old resolv.conf are moved to the beginning of the file.  If there is
> more than one argument, the processing is quite complicated and I haven't
> figured it out, but I know that the arguments aren't file names.
> 
> - change_resolv_conf uses some excessively complex constructions.  The test
> '[ "x$s" != "x" ]' is used where '[ -n "$s" ]' would be clearer. The test
> 'case "$s" in *$1*)' is used where 'if [[ "$s" == *"$1"* ]]' would be
> clearer.

I hope it looks ([3]) better now.

> - It is not clear which function, make_resolv_conf or change_resolv_conf, is
> responsible for setting the security context of the new resolv.conf. 
> make_resolv_conf calls "fix_context /etc/resolv.conf" but change_resolv_conf
> calls "/sbin/restorecon /etc/resolv.conf".  The fact that both functions
> seem to do the same thing suggests that there is no clear assignment of
> responsibilities here.

Restoring security context has been removed ([4]) some time ago.
 
> - The partitioning of responsibilities between make_resolv_conf and
> change_resolv_conf is not well done.  One would expect that make_resolv_conf
> would write the new resolv.conf file and that change_resolv_conf would
> notify whatever services need to be notified.
> 
> (And that would allow me to improve the logical structure of my
> customization, because resolv.conf itself (which the services presumably pay
> attention to) doesn't change; only resolv.conf.dhcp changes.  So
> change_resolv_conf would not need to be called.)
> 
> But it turns out that make_resolv_conf computes the new contents for
> resolv.conf.dhcp, but does not write them into the file.  The writing is
> done by change_resolv_conf.  This is despite that the comment at the top of
> change_resolv_conf is "# Invoke this when /etc/resolv.conf has changed:".
> 
> - It would also help if there were configuration variables for "After
> writing resolv.conf, do we need to call change_resolv_conf?" and "Do we copy
> the domain name provided by DHCP into resolv.conf?".

I'm closing this ticket for now as the main 'hardwired /etc/resolv.conf' should be fixed with [2]. If you'd still (it's been a year since your report) like to see those improvements feel free to attach patch(es) and re-open it.

[1] http://pkgs.fedoraproject.org/cgit/dhcp.git/commit/?id=27892ea741e2a7fa82bbba07077fd3606e517c7d
[2] http://pkgs.fedoraproject.org/cgit/dhcp.git/commit/?id=4f66445ebac4ae09f36f7c766569427db88e88e6
[3] http://pkgs.fedoraproject.org/cgit/dhcp.git/tree/dhclient-script#n674
[4] http://pkgs.fedoraproject.org/cgit/dhcp.git/commit/?id=81262d499a5963b4d0df97866ba18038ba7685c7


Note You need to log in before you can comment on or make changes to this bug.