On 2016/04/25 at 13:24, Baoquan He wrote:
On 04/25/16 at 10:56am, Xunlei Pang wrote:
> On 2016/04/22 at 22:53, Xunlei Pang wrote:
>> On 2016/04/22 at 16:58, Minfei Huang wrote:
>>> On 04/21/16 at 03:44pm, Xunlei Pang wrote:
>>>> Current implementation of kdump_setup_dns() get the dns
>>>> from interface's ifcfg file first, then parse those in
>>>> "/etc/resolv.conf". For example, DNS1 in ifcfg file along
>>>> with dhcp, the final dns(/etc/resolv.conf) in 1st system
>>>> will be like(dhcp first, then ifcfg file appending end):
>>>> dhcp dns1
>>>> dhcp dns2
>>>> dhcp dns3
>>>> DNS1 in ifcfg
>>>>
>>>> After parsing, the dns(/etc/cmdline.d/42dns.conf) in kdump
>>>> system will be like:
>>>> DNS1 in ifcfg
>>>> dhcp dns1
>>>> dhcp dns2
>>>> dhcp dns3
>>>> DNS1 in ifcfg
>>> Hi.
>>>
>>> I have some confusion about the dns order in /etc/resolv.conf. From my
>>> test, I found that dns client would append DNS entry to /etc/resolv.conf
>>> in kdump kernel. Following is my test result.
>>>
>>> kdump:/# cat /sysroot/etc/resolv.conf
>>> # Generated by NetworkManager
>>> search
nay.redhat.com redhat.com
>>> nameserver 10.72.17.5
>>> nameserver 10.68.5.26
>>> nameserver 192.168.122.1
>>> nameserver 8.8.8.8
>>>
>>> kdump:/# cat /etc/resolv.conf
>>> nameserver 10.72.17.5
>>> nameserver 10.68.5.26
>>> nameserver 192.168.122.1
>>> nameserver 8.8.8.8
>>> nameserver 192.168.122.1
>>>
>>> The last dns entry "nameserver 192.168.122.1" is appended in kdump
>>> kernel by DNS client. So the order may be like this:
>>> dhcp dns1
>>> DNS1
>>> dhcp dns1
>> Thanks for the test, the Dracut's dhcp order may have problems,
>> it should be like network-manager: dhcp firstly, then append DNS<n> in
ifcfg files.
>>
>> I will double confirm this later.
> I checked the implementation of /etc/sysconfig/network-scripts/ and the actual
effect
> of network-manager, they are differently implemented. Seems there is no standard to
> follow. I'd rather leave this alone(only improve the duplicated items) for safety
as we
> discussed last week, since there are no bugs related to this reported.
I think we can summarize the knowing we have discussed about
the behaviour of Netowrkmanager, network-scripts and dracut
implementation on dns. Then ask network expert to help to check this,
which one is reasonable. After making this clear proper fix can be done.
Hereby I only summarize dhcp cases for specific $netif about the main process of dns
handling, static cases is similar.
============= 1. The DNS handling in 1st kernel after the dracut stage =============
There are two network methods available in 1st kernel:
network-manager(nmcli) and
network-scripts(without network-manager by using scripts under
/etc/sysconfig/network-scripts/,
such as "if-eth", "ifup-post", etc).
a) The general entry is "/usr/sbin/ifup":
need_config // find the right ifcfg file of the $config
source_config // load the ifcfg file contents
b) Then if it is network-manager controlled, bring it up firstly via nmcli:
if [ "$_use_nm" = "true" -a -n "$UUID" -a
"$DEVICE" != "lo" ]; then
if [ "foo$2" = "fooboot" ] && [ "${TYPE}" =
"Wireless" ]; then
exit 0
fi
[ -n "${DEVICE}" ] && is_nm_handling ${DEVICE} && exit
0
nmcli con up uuid "$UUID"
exit $?
fi
All things are done by nmcli which is an ELF file, I didn't get its detail.
All the knowledge if through experiments:
-) Generate dhcp firstly
-) Append the DNS1&DNS2 info in ifcfg to /etc/resolv.conf
-) From my experiment, seems "PEERDNS=yes" and "PEERDNS=no" have
the same effect.
c) Otherwise(without network-manager), it will generally use scripts under
"/etc/sysconfig/network-scripts/" to do the job:
OTHERSCRIPT="/etc/sysconfig/network-scripts/ifup-${DEVICETYPE}"
if [ ! -x ${OTHERSCRIPT} ]; then
OTHERSCRIPT="/etc/sysconfig/network-scripts/ifup-${TYPE}"
fi
if [ ! -x ${OTHERSCRIPT} ]; then
OTHERSCRIPT="/etc/sysconfig/network-scripts/ifup-eth"
fi
exec ${OTHERSCRIPT} ${CONFIG} $2
d) Suppose we have ethernet type, ${OTHERSCRIPTS} is "ifup-eth", we enter
"ifup-eth":
After some specific type-parsing(bridge, vlan, team, etc), it will generally call
"dhclient" to do the dhcp firstly.
"/usr/sbin/dhclient-script" is called by "dhclient" to generate the
initial "/etc/resolv.conf" file,
can refer to function "make_resolv_conf" in dhclient-script for details.
make_resolv_conf() {
[ "${PEERDNS}" = "no" ] && return // handle PEERDNS
generate dns information to file ${rscf} using the contents provided by
"dhclient"
change_resolv_conf ${rscf}
e) Finally, "ifup-post" script is called, it does mainly(omit some detail
here):
if [ "$PEERDNS" != "no" ] ; then // handle PEERDNS
if [ -n "$DNS1" ] && ! grep -q "^nameserver $DNS1"
/etc/resolv.conf &&
tr=$(mktemp /tmp/XXXXXX) ; then
current_replacement="$DNS1"
next_replacement="$DNS2"
search=
(cat /etc/resolv.conf ; echo EOF ; echo EOF) | while read answer ; do
case $answer in
nameserver*|EOF)
if [ -n "$current_replacement" ] ; then
echo "nameserver $current_replacement" >> $tr
if [ -n "$next_replacement" ] ; then
current_replacement="$next_replacement"
next_replacement=
else
current_replacement=
fi
else
if [ "$answer" != EOF ] ; then
echo "$answer" >> $tr
fi
fi
;;
<snip>
esac
done
change_resolv_conf $tr
fi
fi
============= 2. The DNS handling in dump kernel by dracut =============
Using scripts under modules.d/40network/
a) The general entry is "ifup":
b) do nameserver and dns1/dns2 firstly, which is acquired from "nameserver=" and
"ip="
cmdline of dracut setup in 1st kernel when making kdump initramfs.
# Specific configuration, spin through the kernel command line
# looking for ip= lines
for p in $(getargs ip=); do
ip_to_var $p
<snip>
# setup nameserver
for s in "$dns1" "$dns2" $(getargs nameserver); do
[ -n "$s" ] || continue
echo nameserver $s >> /tmp/net.$netif.resolv.conf // Apparently, not
deal with rd.peerdns
done
c) "do_dhcp -4 ;;"
This will trigger dhclient and "modules.d/40network/dhclient-script.sh",
in setup_interface(), dracut will append dhcp-generated DNS information
into "/tmp/net.$netif.resolv.conf":
if getargbool 1 rd.peerdns; then // handle rd.peerdns globally
[ -n "${search}${domain}" ] && echo "search $search
$domain" > /tmp/net.$netif.resolv.conf
if [ -n "$namesrv" ] ; then
for s in $namesrv; do
echo nameserver $s
done
fi >> /tmp/net.$netif.resolv.conf // append dhcp dns
fi
d) execute setup_net through initqueue scripts
[ -e /tmp/net.$netif.resolv.conf ] && \
cp -f /tmp/net.$netif.resolv.conf /etc/resolv.conf
============= 3. Conclusion =============
Dracut, network-manager, and "network-scripts" all have different hehavior
in handling DNS.
As a dhcp example:
Suppose enp0s25, the dhcped DNSes are stable: 10.72.17.5 and 10.68.5.26
In ifcfg-enp0s25:
DNS1: 8.8.8.8
1) For 1st kernel's network-manager, the final nameservers in /etc/resolv.conf
-) If PEERDNS=yes(default is yes if PEERDNS doesn't exist) in ifcfg-enp0s25
nameserver 10.72.17.5
nameserver 10.68.5.26
nameserver 8.8.8.8
-) If PEERDNS=no in ifcfg-enp0s25
nameserver 10.72.17.5
nameserver 10.68.5.26
nameserver 8.8.8.8
2) For 1st kernel's scripts under /etc/sysconfig/network-scripts/ without
network-manager
-) If PEERDNS=yes in ifcfg-enp0s25
nameserver 8.8.8.8
nameserver 10.68.5.26
-) If PEERDNS=no in ifcfg-enp0s25
Not touch /etc/resolv.conf
(i.e. /etc/resolv.conf is left unchanged as that before calling "ifup
<config>")
3) For dracut in latest fedora kexec-tools(1st kernel using network-manager)
"${initdir}/etc/cmdline.d/42dns.conf" will contain:
nameserver=8.8.8.8
nameserver=10.72.17.5
nameserver=10.68.5.26
nameserver=8.8.8.8
-) If "rd.peerdns=1"(default is "1" if "rd.peerdns"
doesn't exist) is passed which is the default case
nameserver 8.8.8.8
nameserver 10.72.17.5
nameserver 10.68.5.26
nameserver 8.8.8.8
nameserver 10.72.17.5 // the last two are drauct' dhcp generated items
nameserver 10.68.5.26
-) If "rd.peerdns=0" is passed
nameserver 8.8.8.8
nameserver 10.72.17.5
nameserver 10.68.5.26
nameserver 8.8.8.8
Regards,
Xunlei
> Regards,
> Xunlei
>
>> Regards,
>> Xunlei
>>
>>> Thanks
>>> Minfei
>>>
>>>> There are two issues by doing this:
>>>> 1) The dns sequence is different from that in 1st system.
>>>> 2) There are some duplicated items.
>>>> NOTE: kdump_setup_dns() meant to avoid the duplication,
>>>> but the original shell command is actually disfunctional:
>>>> "[ ! $(cat $_dnsfile | grep -q $_dns) ]" (always true)
>>>>
>>>> Fix the issues by firstly parsing "/etc/resolv.conf", then
>>>> parsing ifcfg file, finally delete the duplicated items.
>>>>
>>>> Signed-off-by: Xunlei Pang <xlpang(a)redhat.com>
>>>> ---
>>>> dracut-module-setup.sh | 27 ++++++++++++++++-----------
>>>> 1 file changed, 16 insertions(+), 11 deletions(-)
>>>>
>>>> diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
>>>> index 350864e..b7763f7 100755
>>>> --- a/dracut-module-setup.sh
>>>> +++ b/dracut-module-setup.sh
>>>> @@ -68,14 +68,6 @@ kdump_setup_dns() {
>>>> local _dnsfile=${initdir}/etc/cmdline.d/42dns.conf
>>>> local ifcfg_file
>>>>
>>>> - ifcfg_file=$(get_ifcfg_filename $1)
>>>> - if [ -f "${ifcfg_file}" ]; then
>>>> - . ${ifcfg_file}
>>>> - fi
>>>> -
>>>> - [ -n "$DNS1" ] && echo
"nameserver=$DNS1" > "$_dnsfile"
>>>> - [ -n "$DNS2" ] && echo
"nameserver=$DNS2" >> "$_dnsfile"
>>>> -
>>>> while read content;
>>>> do
>>>> _nameserver=$(echo $content | grep ^nameserver)
>>>> @@ -84,10 +76,23 @@ kdump_setup_dns() {
>>>> _dns=$(echo $_nameserver | cut -d' ' -f2)
>>>> [ -z "$_dns" ] && continue
>>>>
>>>> - if [ ! -f $_dnsfile ] || [ ! $(cat $_dnsfile | grep -q $_dns) ];
then
>>>> - echo "nameserver=$_dns" >>
"$_dnsfile"
>>>> - fi
>>>> + echo "nameserver=$_dns" >>
"$_dnsfile"
>>>> done < "/etc/resolv.conf"
>>>> +
>>>> + unset DNS1 DNS2
>>>> + ifcfg_file=$(get_ifcfg_filename $1)
>>>> + if [ -f "${ifcfg_file}" ]; then
>>>> + . ${ifcfg_file}
>>>> + fi
>>>> +
>>>> + [ -n "$DNS1" ] && echo
"nameserver=$DNS1" >> "$_dnsfile"
>>>> + [ -n "$DNS2" ] && echo
"nameserver=$DNS2" >> "$_dnsfile"
>>>> +
>>>> + # Delete duplicated lines
>>>> + if [ -f "$_dnsfile" ]; then
>>>> + awk '!a[$0]++' $_dnsfile > $_dnsfile.tmp
>>>> + mv -f $_dnsfile.tmp $_dnsfile
>>>> + fi
>>>> }
>>>>
>>>> #$1: netdev name
>>>> --
>>>> 1.8.3.1
>>>> _______________________________________________
>>>> kexec mailing list
>>>> kexec(a)lists.fedoraproject.org
>>>>
http://lists.fedoraproject.org/admin/lists/kexec@lists.fedoraproject.org
>> _______________________________________________
>> kexec mailing list
>> kexec(a)lists.fedoraproject.org
>>
http://lists.fedoraproject.org/admin/lists/kexec@lists.fedoraproject.org
> _______________________________________________
> kexec mailing list
> kexec(a)lists.fedoraproject.org
>
http://lists.fedoraproject.org/admin/lists/kexec@lists.fedoraproject.org