CumulusNetworks / ifupdown2

GNU General Public License v2.0
161 stars 76 forks source link

Useless dhclient -6 when inet dhcp and inet6 static #174

Open RomainMou opened 4 years ago

RomainMou commented 4 years ago

Hi.

Context :

When I use DHCP for IPv4, it seems ifupdown2 launch an IPv6 dhclient, for no reason. For example with this configuration:

auto lo
iface lo inet loopback

auto eno1
iface eno1 inet dhcp
iface eno1 inet6 static
  address 2001:xx::xx
  netmask 64
~# ifup --debug eno1
[...]
debug: eno1: up : running module dhcp
info: eno1: enabling syslog for dhcp configuration
debug: reading '/run/dhclient.eno1.pid'
info: executing /sbin/dhclient -x -pf /run/dhclient.eno1.pid -lf /var/lib/dhcp/dhclient.eno1.leases eno1
Removed stale PID file
info: executing ip -o addr show eno1
info: executing /sbin/dhclient -pf /run/dhclient.eno1.pid -lf /var/lib/dhcp/dhclient.eno1.leases eno1
info: executing ip -o addr show eno1
info: eno1: dhclient: new address detected: xxx.xxx.xxx.xxx
info: executing /bin/ip -6 addr show eno1
info: executing /sbin/dhclient -6 -pf /run/dhclient6.eno1.pid -lf /var/lib/dhcp/dhclient6.eno1.leases eno1

The problem is that systemctl reload networking hang indefinitely, except if I kill the useless dhclient -6.

julienfortin commented 4 years ago

Hi @RomainMou, you don't need to specify iface eno1 inet6 static on the stanza.

I see what the issue is but it's not critical and it might require a lot of important changes in the code (change ifaceobj addr_method to a list and make sure everything still works).

Since there's a work around, i won't be fixing it for now (i'm already busy on other things at the moment). If you feel like it you can submit a PR to fix this issue.

Cheers

RomainMou commented 4 years ago

Hi, @julienfortin, thank for your answer.

Without iface eno1 inet6 static, the static iPv6 address is not set, but there is no more dhclient -6! So no more blocking reload. So the full work around looks something like:

auto eno1
iface eno1 inet dhcp
  post-up ip -6 addr add 2001:dad:beef::3/64 dev $IFACE

I'll try to look if I can understand how this work, but I'm not sure to know enough python for it.

julienfortin commented 4 years ago

hi @RomainMou

Seems to work pretty well on my system. Can you please reproduce the following steps and paste the output of those commands?

[1:21:10] root:~ # ifquery swp1   
auto swp1
iface swp1
        address 2001:0db8:85a3:0000:0000:8a2e:0370:7334
        netmask 64

[1:21:16] root:~ # ip addr show swp1
3: swp1: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether 08:00:27:04:d8:2e brd ff:ff:ff:ff:ff:ff
[1:21:20] root:~ # ifup swp1 -v
info: requesting link dump
info: requesting address dump
info: requesting netconf dump
info: loading builtin modules from ['/root/ifupdown2/ifupdown2/addons', '/usr/share/ifupdown2/addons']
info: executing /var/lib/ifupdown2/hooks/get_reserved_vlan_range.sh
info: executing /sbin/sysctl net.bridge.bridge-allow-multiple-vlans
info: executing /bin/pidof mstpd
info: executing /bin/ip rule show
info: executing /bin/ip -6 rule show
info: address: using default mtu 1500
info: address: max_mtu undefined
info: executing /usr/sbin/ip vrf id
info: mgmt vrf_context = False
info: dhclient: dhclient_retry_on_failure set to 0
info: executing /bin/ip addr help
info: address metric support: OK
info: using mgmt iface default prefix eth
info: processing interfaces file /etc/network/interfaces
info: swp1: running ops ...
info: executing /sbin/ethtool swp1
info: reading '/sys/class/net/swp1/speed'
info: reading '/sys/class/net/swp1/duplex'
info: executing /sbin/ethtool -s swp1  speed 1000 duplex full
info: swp1: netlink: ip addr add 2001:db8:85a3::8a2e:370:7334/64 dev swp1
info: swp1: netlink: ip link set dev swp1 up
info: exit status 0
[1:21:24] root:~ # ifquery swp1 -c
auto swp1
iface swp1                                                          [pass]
        address 2001:db8:85a3::8a2e:370:7334/64                     [pass]

[1:21:29] root:~ # ip addr show swp1
3: swp1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:04:d8:2e brd ff:ff:ff:ff:ff:ff
    inet6 2001:db8:85a3::8a2e:370:7334/64 scope global 
       valid_lft forever preferred_lft forever
RomainMou commented 4 years ago

Hi @julienfortin.

The problem only occurs when IPv4 use DHCP and IPv6 static. When both are static or when there is no IPv4, it's working.

root@hv0:~# ifquery eno1
auto eno1
iface eno1 inet dhcp
    address 2001:dad:beef::3
    netmask 56

root@hv0:~# ip addr show eno1
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 20:47:47:90:4f:ec brd ff:ff:ff:ff:ff:ff
    inet 123.123.123.123/24 brd 195.154.170.255 scope global eno1
       valid_lft forever preferred_lft forever
    inet6 fe80::2247:47ff:fe90:4fec/64 scope link 
       valid_lft forever preferred_lft forever

root@hv0:~# ifup eno1 -v
info: requesting link dump
info: requesting address dump
info: requesting netconf dump
info: loading builtin modules from ['/usr/share/ifupdown2/addons']
info: module openvswitch not loaded (module init failed: no /usr/bin/ovs-vsctl found)
info: module openvswitch_port not loaded (module init failed: no /usr/bin/ovs-vsctl found)
info: module ppp not loaded (module init failed: no /usr/bin/pon found)
info: module batman_adv not loaded (module init failed: no /usr/sbin/batctl found)
info: executing /sbin/sysctl net.bridge.bridge-allow-multiple-vlans
info: module mstpctl not loaded (module init failed: no /sbin/mstpctl found)
info: executing /bin/ip rule show
info: executing /bin/ip -6 rule show
info: module ethtool not loaded (module init failed: /sbin/ethtool: not found)
info: address: using default mtu 1500
info: address: max_mtu undefined
info: executing /usr/sbin/ip vrf id
info: mgmt vrf_context = False
info: dhclient: dhclient_retry_on_failure set to 0
info: executing /bin/ip addr help
info: address metric support: OK
info: module ethtool not loaded (module init failed: /sbin/ethtool: not found)
info: module ppp not loaded (module init failed: no /usr/bin/pon found)
info: module mstpctl not loaded (module init failed: no /sbin/mstpctl found)
info: module batman_adv not loaded (module init failed: no /usr/sbin/batctl found)
info: module openvswitch_port not loaded (module init failed: no /usr/bin/ovs-vsctl found)
info: module openvswitch not loaded (module init failed: no /usr/bin/ovs-vsctl found)
info: looking for user scripts under /etc/network
info: loading scripts under /etc/network/if-pre-up.d ...
info: loading scripts under /etc/network/if-up.d ...
info: loading scripts under /etc/network/if-post-up.d ...
info: loading scripts under /etc/network/if-pre-down.d ...
info: loading scripts under /etc/network/if-down.d ...
info: loading scripts under /etc/network/if-post-down.d ...
info: using mgmt iface default prefix eth
info: processing interfaces file /etc/network/interfaces
info: eno1: running ops ...
info: executing /sbin/sysctl net.mpls.conf.eno1.input=0
info: eno1: enabling syslog for dhcp configuration
info: dhclient4 already running on eno1. Not restarting.
info: executing /etc/network/if-up.d/bind9
info: executing /etc/network/if-up.d/openntpd
info: executing /etc/network/if-up.d/postfix
info: exit status 0
root@hv0:~# ifquery eno1 -c
auto eno1
iface eno1 inet dhcp                                                [pass]

root@hv0:~# ip addr show eno1
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 20:47:47:90:4f:ec brd ff:ff:ff:ff:ff:ff
    inet 123.123.123.123/24 brd 195.154.170.255 scope global eno1
       valid_lft forever preferred_lft forever
    inet6 fe80::2247:47ff:fe90:4fec/64 scope link 
       valid_lft forever preferred_lft forever
n0emis commented 3 years ago

Is there any possibility that this issue might get fixed?

When using ifupdown2 on most VMs that use cloud-init, this blocks the VM from correctly booting, when no dhcpv6-server is active in the network.

The config provided by cloud init might look as follows:

auto eth0
iface eth0 inet dhcp
    dns-nameservers 213.133.100.100 213.133.98.98 213.133.99.99

# control-alias eth0.
iface eth0:0 inet6 static
    address 2a01:cafe:f00:ba1::1/64
    gateway fe80::1

And this config get's parsed to the following JSON by ifquery:

[
    {
        "name": "eth0",
        "addr_method": "dhcp",
        "addr_family": "inet",
        "auto": true,
        "config": {
            "dns-nameservers": "213.133.100.100 213.133.98.98 213.133.99.99"
        }
    },
    {
        "name": "eth0",
        "addr_method": "static",
        "addr_family": "inet6",
        "auto": true,
        "config": {
            "address": "2a01:cafe:f00:ba1::1/64",
            "gateway": "fe80::1"
        }
    }
]

But somehow the resulting iface-object contains both address-families in one instace, ob which dhcp is enabled. When disableing the IPv4-block everything works fine.

Would it be possible to seperate this? Because it would be very good to not have to mess around with the cloudinit provided config...

julienfortin commented 3 years ago

@n0emis @RomainMou having a mix of both "static" and "dhcp" stanza is currently not supported. The work around is to add your static ip using pre-up / up / post-up attributes and use iproute2 to set your static ip.

Not ideal I know but to support both type some adjustment are needed to a core object (ifaceobj) - basically the addr_method need to become a list, but this attribute is used in many places so it's won't be a trivial change.

Feel free to have a look and maybe write a patch for it if you have free cycles. I think the workaround would be enough for now for your use case.

sbraz commented 2 years ago

Hi @julienfortin

@n0emis @RomainMou having a mix of both "static" and "dhcp" stanza is currently not supported.

Could you please fix this? As other users pointed out, we don't always have control over the configuration, especially when it's generated by cloud-init.

lexxxel commented 1 year ago

I ran into this one on my netcup vps (running proxmox). It gets its ipv4 via DHCP, but ipv6 has to be static. A fix/ working config would be appreciated.

aderumier commented 12 months ago

Hi, I'm working on it (for proxmox), I have a almost working patch, I'll try to send it next week.

nomaster commented 7 months ago

Hey, curious about a solution for this... I just had a long evening after upgrading a Proxmox host that automatically installed ifupdown2. The host blocked on boot indefinitely, since we obviously don't have a DHVPv6 server. Our work-around is to configure both IPv4 and IPv6 addresses statically.

GoetzGoerisch commented 2 months ago

Hi, I'm working on it (for proxmox), I have a almost working patch, I'll try to send it next week.

@aderumier any news on this?

QinHuasong commented 2 months ago

I ran into this similar case when inet with static method and inet6 with dhcp. I tried to change iface squash only when inet and inet6 has the same address method, it works. What I did just as follow: in ifupdown2/ifupdown/iface.py, squash() method

def squash(self, newifaceobj):
        """ This squashes the iface object """
        for attrname, attrlist in newifaceobj.config.items():
            # if allready present add it to the list
            # else add it to the end of the dictionary
            # We need to maintain order.
            if self.config.get(attrname):
                self.config[attrname].extend(attrlist)
            else:
                self.config.update([(attrname, attrlist)])
        # we now support inet and inet6 together
        # only if ifaceobj share same address method                   <--
        if self.addr_method == newifaceobj.addr_method:           <--
            self.addr_family.extend(newifaceobj.addr_family)        <--
        # if auto ifacename is not part of the first stanza
        # we need to squash it
        if not self.auto and newifaceobj.auto:
            self.auto = True
QinHuasong commented 2 months ago

Hi, I'm working on it (for proxmox), I have a almost working patch, I'll try to send it next week.

@aderumier any news on this?

maybe useful to you as I tried above