On 06/19/15 at 10:28am, Dave Young wrote:
On 06/18/15 at 08:34pm, Minfei Huang wrote:
> On 06/18/15 at 10:44am, Dave Young wrote:
> > On 06/13/15 at 02:51pm, Minfei Huang wrote:
> > > The ipv6 address has the special character colon ":", so we can
use the
> > > new function to pick it out.
> > > We can use the new function to parse the passed parameter. The passed
> > > parameter is hostname/domain, if it is satisfied with the condition that
> > > it is without colon ":", and contanis the [a-zA-Z].
> > >
> > > Add a new function to simplify to get the ip address, if the specified
> > > address is a domain/hostname in /etc/kdump.conf.
> > > The function will parse the passed parameter, and use the "getent
ahost"
> > > to get the ip address, if passed parameter is domain/hostname.
> > >
> > > Signed-off-by: Minfei Huang <mhuang(a)redhat.com>
> > > ---
> > > dracut-module-setup.sh | 1 +
> > > kdump-lib.sh | 45
++++++++++++++++++++++++++++++++++-----------
> > > 2 files changed, 35 insertions(+), 11 deletions(-)
> > >
> > > diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
> > > index fd60b24..657530b 100755
> > > --- a/dracut-module-setup.sh
> > > +++ b/dracut-module-setup.sh
> > > @@ -668,6 +668,7 @@ install() {
> > > inst "/bin/dd" "/bin/dd"
> > > inst "/bin/tail" "/bin/tail"
> > > inst "/bin/date" "/bin/date"
> > > + inst "/bin/getent" "/bin/getent"
> > > inst "/bin/sync" "/bin/sync"
> > > inst "/bin/cut" "/bin/cut"
> > > inst "/sbin/makedumpfile" "/sbin/makedumpfile"
> > > diff --git a/kdump-lib.sh b/kdump-lib.sh
> > > index 1fa6058..481876b 100755
> > > --- a/kdump-lib.sh
> > > +++ b/kdump-lib.sh
> > > @@ -229,23 +229,46 @@ get_remote_host()
> > > echo $_config_val
> > > }
> > >
> > > -# check the remote server ip address tpye
> > > -is_ipv6_target()
> > > +# Convert hostname to ip address, echo the original value if $1 is
already an ip address.
> > > +# $1: hostname or ip address
> > > +get_ip_address()
> > > {
> > > - local _server _server_tmp
> > > + local _ip_address
> > > +
> > > + _ip_address=`getent ahosts $1 | head -n 1 | cut -d' ' -f1`
> > > + _ip_address=${_ip_address:-$1}
> > > + echo $_ip_address
> > > +}
> > > +
> > > +is_ipv6_host()
> > > +{
> > > + local _addr=$(get_ip_address $1)
> > > + echo $_addr | grep -q ":"
> > > +}
> >
> > It is long time ago you posted the last version, I remember we discussed
> > about the issue no need to handle hostname target, only handle explict
> > ip address in kdump.conf, right?
> >
>
> Sorry. I forget it about the reason why we do not need to handle
> hostname target. Could you explain it?
I assume hostname will naturally works without any modification. So we only
need take care of ip address specifed in kdump.conf
But I suspect the static route code breaks the assumption since it will pass
route table to 2nd kernel.
We need to parse the hostname, since we shall do some specifical process
for ipv6 procotol.
You can find that we do different for ipv4 and ipv6.
308 if is_ipv6_host $_server; then
309 _netdev=`/sbin/ip -6 route get to $_server 2>&1`
310 [ $? != 0 ] && echo "Bad kdump location: $config_val"
&&
exit 1
311
312 if [ -n "`echo $_netdev | grep via`" ]; then
313 # 2001:151::112 via 2001:150::121 from :: dev eth1 src
2001:150::120 metric 0
314 _srcaddr=`echo $_netdev|awk '{print $9}'|head -n 1`
315 _netdev=`echo $_netdev|awk '{print $7;}'|head -n 1`
316 else
317 # 2001:150::11f from :: dev eth1 src 2001:150::120
metric 0
318 _srcaddr=`echo $_netdev|awk '{print $7}'|head -n 1`
319 _netdev=`echo $_netdev|awk '{print $5}'|head -n 1`
320 fi
321 else
322 _netdev=`/sbin/ip route get to $_server 2>&1`
323 [ $? != 0 ] && echo "Bad kdump location: $config_val"
&&
exit 1
324 if [ -n "`echo $_netdev | grep via`" ]; then
325 # 192.168.151.215 via 192.168.150.137 dev kdump-eth1
src 192.168.150.129
326 _srcaddr=`echo $_netdev|awk '{print $7}'|head -n 1`
327 _netdev=`echo $_netdev|awk '{print $5;}'|head -n 1`
328 else
329 # 192.168.150.137 dev eth1 src 192.168.150.129
330 _srcaddr=`echo $_netdev|awk '{print $5}'|head -n 1`
331 _netdev=`echo $_netdev|awk '{print $3}'|head -n 1`
332 fi
333 fi
We shall take care of the hostname, since the result format is different
by command "/sbin/ip -6 route get to $_server".
As you said, static route or other function may breake, if we do not
parse the hostname.
Thanks
Minfei
>
> > About getent, is it reliable to always return one type, either ipv4 or
> > ipv6, or randomly?
> >
>
> We can not confirm which ip type(maybe ipv4, maybe ipv6) will be
> returned by command getent. It depends on the configuration of domain
> service.
>
> Whatever the command getent returns, I think it is ok. If it is the ipv4
> protocol, we can walk through the ipv4 path, otherwise through ipv6 path.
>
> Thanks
> Minfei