Commit 65a652f
committed
CA-323523: Ensure that dhclients get restarted when gateway/DNS changes
Recent commit 75a4c5d changed the `options` argument to
`Dhclient.write_conf_file`, but failed to update one of its callers, in
`set_gateway_interface`. This meant that dhclient did not get restarted when
necessary as a result of configuration changes. Rather than fixing the bad
function call, this patch changes the code to be more robust.
When starting a `dhclient` process for an interface that requires configuration
by DHCP, the function `Dhclient.ensure_running` writes a configuration file to
disk and passes its path to `dhclient` as a command line argument. The purpose
of saving the configuration is to make `Dhclient.ensure_running` idempotent.
When called, the function checks if a `dhclient` process is already running for
the given interface, and if the last used configuration is identical to the
newly requested one. If so, it leaves the process alone to cause minimal
disturbance to the system.
An interesting use case is changing the default gateway to another interface,
and then back to the original interface (using `set_gateway_interface` and
`Interface.make_config` twice). The first change properly updates the gateway,
but the change back to the original interface doesn't end up restarting
`dhclient` to switch the gateway back. This was addressed by rewriting the conf
file of the gateway interface when changing it, in `set_gateway_interface` (see
637db58).
Now, is seems wrong that `set_dns_interface`, which is a function with a very
similar purpose to `set_gateway_interface`, does not rewrite conf files like
`set_gateway_interface` does. Fixing that, however, could lead to the two
functions interfering with each other. Therefore, rather than trying to update
the conf file, we just delete it so that it will definitely be correctly
regenerated later (and do this for both `set_*_interface` functions).
Signed-off-by: Rob Hoes <[email protected]>1 parent b547737 commit 65a652f
2 files changed
+21
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
759 | 759 | | |
760 | 760 | | |
761 | 761 | | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
762 | 768 | | |
763 | 769 | | |
764 | 770 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
78 | | - | |
79 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
80 | 80 | | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
88 | 84 | | |
89 | 85 | | |
90 | 86 | | |
91 | 87 | | |
92 | 88 | | |
93 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
94 | 99 | | |
95 | 100 | | |
96 | 101 | | |
| |||
0 commit comments