New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Auto-detect DHCP client with systemd-networkd (closes #2375) #2376
Auto-detect DHCP client with systemd-networkd (closes #2375) #2376
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot really review it because I know nothing about
how that things work on Ubuntu (in general am not a Ubuntu user
and in particulare I am neither a DHCP nor a systemd expert)
but as far as I see this is purely additional code
so there cannot be regressions for existing use cases and
the additional code looks good to me from plain looking at it
so that I can "almost blindly" approve it in particular
because in general code from @OliverO2 is "just right".
I would appreciate it if another ReaR maintainer |
After doing some more testing with overrides, I found a bug: The present code will accept an enabled DHCP client on any network connection. However, with Docker there may be additional network connections configured with DHCP enabled. These should be ignored. Fix upcoming. |
@OliverO2
to
cf. #2364 |
Also fixes: Accept symbolic links as network configuration files.
@jsmeix |
@OliverO2 |
ARRAY+=( additional elements ) see rear#2364
Done. I wanted to clean up the entire For me it looks like that the
|
I think @gdha is our DHCP expert here ;-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch! It seems this issue gets nasty because
it looks as if a more general cleanup is needed.
As fas as I see now it seems the dhclients variable
is used inconsistently both as an array and as a string
according to those code excerpts:
define_dhclients_variable()
{ ...
dhclients=()
...
for d in "${dhclients[@]}" ; do
...
dhclients+=("$x")
...
dhclients="${dhclients[*]}"
}
...
for x in ${dhclients} ; do
...
PROGS+=( arping ipcalc usleep "${dhclients[@]}" )
@OliverO2
I know this messed up dhclients variable usage is not your fault.
But now I noticed it and because you are working on that code
I would very much appreciate it if you could also
clean up the messed up dhclients variable usage
to be consistently either an array or a string.
Or do I perhaps somehow misunderstand the current
dhclients variable usage and actually it is ok?
Even if it is technically ok at least to me its usage
looks weird.
@jsmeix |
* Apply uniform array variable use * Simplify code which relies on known dhclient binaries anyway * Avoid side effects in functions (variable setting) * Introduce additional checks for errors, improve logging
@jsmeix The old code was a bit too messy for my taste that I re-wrote it to what I think was really intended. Also added a few checks which were not there originally. See commit remarks and code. What still remains: The distinction between |
According to
DHCLIENT_BIN and DHCLIENT6_BIN are internal variables. In general what is not documented in default.conf We have tons of internal variables with uppercase names
Of course we also have globally used variables
:-( |
@jsmeix The problem is that configuring |
@OliverO2 Personally I was too often completely confused With a more straightforward code we could much more @gdha |
@OliverO2 |
usr/share/rear/skel/default/etc/scripts/system-setup.d/58-start-dhclient.sh
Show resolved
Hide resolved
# FIXME: DHCLIENT_BIN could be documented in default.conf as needed. | ||
if [[ -n "$DHCLIENT_BIN" ]]; then | ||
has_binary "$DHCLIENT_BIN" || Error "DHCLIENT_BIN='$DHCLIENT_BIN' but such a binary could not be found" | ||
[[ "${dhcp_clients[*]}" == *" $DHCLIENT_BIN "* ]] || Error "DHCLIENT_BIN='$DHCLIENT_BIN' is not among known DHCP clients (${dhcp_clients[*]})" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test does not work:
# dhcp_clients=(dhcpcd dhclient dhcp6c dhclient6)
# for DHCLIENT_BIN in ${dhcp_clients[*]} ; do [[ "${dhcp_clients[*]}" == *" $DHCLIENT_BIN "* ]] || echo "DHCLIENT_BIN='$DHCLIENT_BIN' is not among known DHCP clients (${dhcp_clients[*]})" ; done
DHCLIENT_BIN='dhcpcd' is not among known DHCP clients (dhcpcd dhclient dhcp6c dhclient6)
DHCLIENT_BIN='dhclient6' is not among known DHCP clients (dhcpcd dhclient dhcp6c dhclient6)
because it tests with leading and trailing blanks which is magic characters coding.
I suggest the more straifgtforward test:
IsInArray "$DHCLIENT_BIN" "${dhcp_clients[@]}" || Error "..."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I forgot to add blanks: [[ " ${dhcp_clients[*]} " == *" $DHCLIENT_BIN "* ]]
Anyway, I've changed it to use IsInArray
. Occasionally, I miss a rear library function because I'm just a casual user and there would be so many lib
sources to look at. In this case, I just didn't remember. However, I may deliberately choose not to use a lib function if it does not add sufficient value to compensate a major downside: These functions make manual unit testing harder. I tend to write test beds like this and it can be hard to pull in ReaR lib files due to dependency hell:
#!/bin/bash
. usr/share/rear/lib/global-functions.sh
function has_binary () {
for bin in $@ ; do
# Suppress success output via stdout which is crucial when has_binary is called
# in other functions that provide their intended function results via stdout
# to not pollute intended function results with intermixed has_binary stdout
# (e.g. the RequiredSharedObjects function) but keep failure output via stderr:
type $bin 1>/dev/null && return 0
done
return 1
}
function IsInArray() {
element="$1"
shift
[[ " $* " == *" $element "* ]]
}
function Log() {
echo "Log: $*"
}
function Error() {
echo "Error: $*"
exit 1
}
function test() {
. usr/share/rear/prep/GNU/Linux/210_include_dhclient.sh
}
#set -x
ROOTFS_DIR=.
test
echo "$ROOTFS_DIR/etc/rear/rescue.conf:"
cat "$ROOTFS_DIR/etc/rear/rescue.conf"
rm "$ROOTFS_DIR/etc/rear/rescue.conf"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now all looks OK to me from plain looking at the code so I approve it.
@rear/contributors
I would appreciate it if another ReaR maintainer could also have a look
and either also approve it or request changes.
If there are no objections I would like to merge it tomorrow afternoon.
@OliverO2
thank you very much for your continuous improvements of ReaR!
@jsmeix |
Pull Request Details:
Type: Enhancement
Impact: Normal
Reference to related issue (URL): Add auto-detection of DHCP client with systemd-networkd #2375
How was this pull request tested? On Ubuntu 18.04.4 LTS
Brief description of the changes in this pull request: See issue.