]> git.proxmox.com Git - mirror_ifupdown2.git/commitdiff
addons: address: new l3_intf_default_gateway_set_onlink policy closes #54
authorJulien Fortin <julien@cumulusnetworks.com>
Tue, 30 Oct 2018 10:31:11 +0000 (11:31 +0100)
committerJulien Fortin <julien@cumulusnetworks.com>
Thu, 13 Dec 2018 22:43:57 +0000 (14:43 -0800)
As shown in the following example, ifupdown1 sets the default route with the
onlink attribute. This patch will add this capability to ifupdown2 controlled
by a policy variable in the address module: "l3_intf_default_gateway_set_onlink"
default to on

[19:16:07] root:~ # cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto enp0s3
iface enp0s3 inet static
      address 78.46.193.234/32
      gateway 172.31.1.1
[19:16:19] root:~ # ifup -a -v
ifup: configuring interface enp0s3=enp0s3 (inet)
...
/bin/ip addr add 78.46.193.234/255.255.255.255 broadcast 78.46.193.234   dev enp0s3 label enp0s3
/bin/ip link set dev enp0s3   up
/bin/ip route add default via 172.31.1.1  dev enp0s3 onlink
...
[19:16:21] root:~ # ip route show
default via 172.31.1.1 dev enp0s3 onlink
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15
169.254.0.0/16 dev enp0s3 scope link metric 1000
[19:16:21] root:~ #

$ cat /etc/network/ifupdown2/policy.d/address.json
{
    "address": {
"module_globals": {
    "l3_intf_default_gateway_set_onlink": "yes"
}
    }
}
$ ifquery swp1
auto swp1
iface swp1 inet static
address 78.46.193.234/32
gateway 172.31.1.1

$ ifreload -av |& grep "route add default"
info: executing /bin/ip route add default via 172.31.1.1 proto kernel dev swp1 onlink
$
$
$ emacs -nw /etc/network/ifupdown2/policy.d/address.json
$ cat /etc/network/ifupdown2/policy.d/address.json
{
    "address": {
"module_globals": {
    "l3_intf_default_gateway_set_onlink": "no"
}
    }
}
$ ifdown -a -X eth0
$ ifreload -av |& grep "route add default"
info: executing /bin/ip route add default via 172.31.1.1 proto kernel dev swp1
$

Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
debian/changelog
ifupdown2/addons/address.py
ifupdown2/ifupdownaddons/LinkUtils.py

index 3abe144be13593c24f6274281fe2dcdcd0061659..a191f72a2f9069456a15df3f9dfce54308d94b04 100644 (file)
@@ -1,5 +1,6 @@
 ifupdown2 (1.2.1) unstable; urgency=medium
 
+  * Fix #54: address module new l3_intf_default_gateway_set_onlink policy
   * Fix: Link down does not work on any intf configured in a VRF
   * Add: ethtool: add link-speed 10 to valid values array
   * Add: address: add l3_intf_arp_accept policy to control ARP_ACCEPT
index eeae1ab6e695235780a18ef5c7e3e153db4e5335..d3a76cf714e54b341d647714cd2c637bb251f8dd 100644 (file)
@@ -156,6 +156,14 @@ class address(moduleBase):
             default=False
         )
 
+        self.l3_intf_default_gateway_set_onlink = utils.get_boolean_from_string(
+            policymanager.policymanager_api.get_module_globals(
+                module_name=self.__class__.__name__,
+                attr='l3_intf_default_gateway_set_onlink'
+            ),
+            default=True
+        )
+
     def syntax_check(self, ifaceobj, ifaceobj_getfunc=None):
         return (self.syntax_check_multiple_gateway(ifaceobj)
                 and self.syntax_check_addr_allowed_on(ifaceobj, True)
@@ -498,7 +506,7 @@ class address(moduleBase):
                              vrf, metric)
         for add_gw in gateways:
             try:
-                self.ipcmd.route_add_gateway(ifaceobj.name, add_gw, vrf, metric)
+                self.ipcmd.route_add_gateway(ifaceobj.name, add_gw, vrf, metric, onlink=self.l3_intf_default_gateway_set_onlink)
             except Exception as e:
                 self.log_error('%s: %s' % (ifaceobj.name, str(e)))
 
index ad6871fceab4fb2359055bd4d0230c52b8e1aaf9..0866b238ab434635974d26a9e3b6e03b4063f1ec 100644 (file)
@@ -1113,7 +1113,7 @@ class LinkUtils(utilsBase):
         return self._cache_get('link', [ifacename, 'ifflag'], refresh=True)
 
     @staticmethod
-    def route_add_gateway(ifacename, gateway, vrf=None, metric=None):
+    def route_add_gateway(ifacename, gateway, vrf=None, metric=None, onlink=True):
         if not gateway:
             return
         if not vrf:
@@ -1126,6 +1126,10 @@ class LinkUtils(utilsBase):
         if metric:
             cmd += 'metric %s' % metric
         cmd += ' dev %s' % ifacename
+
+        if onlink:
+            cmd += " onlink"
+
         utils.exec_command(cmd)
 
     @staticmethod