[PATCH] core: fix route metric set to -1 on DHCP renewal



The first DHCP renew after setting back Ethernet metric to default (-1)
applies a metric of 4294967295 (uint16 -1) instead of the default metric.

The route becomes:
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref Use Iface
0.0.0.0         0.0.0.0         0.0.0.0         U     700    0     0 ppp0
0.0.0.0         192.168.19.193  0.0.0.0         UG    -1     0     0 eth0
10.64.64.64     0.0.0.0         255.255.255.255 UH    0      0     0 ppp0
10.64.64.64     0.0.0.0         255.255.255.255 UH    700    0     0 ppp0
10.250.0.0      0.0.0.0         255.255.0.0     U     50     0     0 tun0
192.168.19.0    0.0.0.0         255.255.255.0   U     100    0     0 eth0
192.168.19.193  0.0.0.0         255.255.255.255 UH    100    0     0 eth0
217.114.201.194 192.168.19.193  255.255.255.255 UGH   100    0     0 eth0

Route update traces:
Sep 20 09:53:11.869027 tap-0FB1 NetworkManager[762]: <debug> libsystemd: DHCP CLIENT (0xfd5eaeb9): REQUEST 
(renewing)
Sep 20 09:53:11.873766 tap-0FB1 NetworkManager[762]: <debug> libsystemd: DHCP CLIENT (0xfd5eaeb9): ACK
Sep 20 09:53:11.873792 tap-0FB1 NetworkManager[762]: <debug> libsystemd: DHCP CLIENT (0xfd5eaeb9): lease 
expires in 1min 58s
Sep 20 09:53:11.873800 tap-0FB1 NetworkManager[762]: <debug> libsystemd: DHCP CLIENT (0xfd5eaeb9): T2 expires 
in 1min 35s
Sep 20 09:53:11.873808 tap-0FB1 NetworkManager[762]: <debug> libsystemd: DHCP CLIENT (0xfd5eaeb9): T1 expires 
in 50s
Sep 20 09:53:11.873845 tap-0FB1 NetworkManager[762]: <debug> dhcp4 (eth0): client event 4
Sep 20 09:53:11.873853 tap-0FB1 NetworkManager[762]: <debug> dhcp4 (eth0): lease available
Sep 20 09:53:11.873881 tap-0FB1 NetworkManager[762]: <info>  dhcp4 (eth0):   address 192.168.19.100
Sep 20 09:53:11.873890 tap-0FB1 NetworkManager[762]: <info>  dhcp4 (eth0):   plen 24
Sep 20 09:53:11.873899 tap-0FB1 NetworkManager[762]: <info>  dhcp4 (eth0):   expires in 120 seconds
Sep 20 09:53:11.873916 tap-0FB1 NetworkManager[762]: <info>  dhcp4 (eth0):   nameserver '192.168.19.193'
Sep 20 09:53:11.873925 tap-0FB1 NetworkManager[762]: <info>  dhcp4 (eth0):   hostname 'TAPOFB1'
Sep 20 09:53:11.873932 tap-0FB1 NetworkManager[762]: <info>  dhcp4 (eth0):   gateway 192.168.19.193
Sep 20 09:53:11.874064 tap-0FB1 NetworkManager[762]: <info>  dhcp4 (eth0): state changed bound -> bound
Sep 20 09:53:11.874082 tap-0FB1 NetworkManager[762]: <debug> device[0x558dc60b3140] (eth0): new DHCPv4 client 
state 1
Sep 20 09:53:11.874535 tap-0FB1 NetworkManager[762]: <debug> device[0x558dc60b3140] (eth0): ip4-config: 
update (commit=1, new-config=0x558dc6110be0)
Sep 20 09:53:11.874569 tap-0FB1 NetworkManager[762]: <debug> platform: address: adding or updating IPv4 
address: 192.168.19.100/24 lft 120sec pref 120sec lifetime 237-0[120,120] dev 2 flags noprefixroute src unkn
Sep 20 09:53:11.874626 tap-0FB1 NetworkManager[762]: <trace> platform-linux: event-notification: RTM_NEWADDR, 
flags 0, seq 141: 192.168.19.100/24 lft 120sec pref 120sec lifetime 237-237[120,120] dev 2 flags noprl
Sep 20 09:53:11.874653 tap-0FB1 NetworkManager[762]: <debug> platform: signal: address 4 changed: 
192.168.19.100/24 lft 120sec pref 120sec lifetime 237-237[120,120] dev 2 flags noprefixroute src kernel
Sep 20 09:53:11.874671 tap-0FB1 NetworkManager[762]: <debug> device[0x558dc60b3140] (eth0): queued IP4 config 
change
Sep 20 09:53:11.874699 tap-0FB1 NetworkManager[762]: <debug> platform-linux: do-add-ip4-address[2: 
192.168.19.100/24]: success
Sep 20 09:53:11.874723 tap-0FB1 NetworkManager[762]: <debug> platform: route: append     IPv4 route: 
0.0.0.0/0 via 192.168.19.193 dev 2 metric 4294967295 mss 0 rt-src dhcp
Sep 20 09:53:11.874778 tap-0FB1 NetworkManager[762]: <trace> platform-linux: event-notification: 
RTM_NEWROUTE, flags excl,create, seq 142: 0.0.0.0/0 via 192.168.19.193 dev 2 metric 4294967295 mss 0 rt-src 
rt-dhcl
Sep 20 09:53:11.874809 tap-0FB1 NetworkManager[762]: <debug> platform: signal: route   4   added: 0.0.0.0/0 
via 192.168.19.193 dev 2 metric 4294967295 mss 0 rt-src rt-dhcp scope global
Sep 20 09:53:11.874846 tap-0FB1 NetworkManager[762]: <debug> platform-linux: do-add-ip4-route[0.0.0.0/0 via 
192.168.19.193 dev 2 metric 4294967295 mss 0 rt-src rt-dhcp scope global]: success
Sep 20 09:53:11.874867 tap-0FB1 NetworkManager[762]: <debug> platform: ip4-route: delete 0.0.0.0/0 via 
192.168.19.193 dev 2 metric 100 mss 0 rt-src rt-dhcp scope global
Sep 20 09:53:11.874904 tap-0FB1 NetworkManager[762]: <trace> platform-linux: event-notification: 
RTM_DELROUTE, flags 0, seq 143: 0.0.0.0/0 via 192.168.19.193 dev 2 metric 100 mss 0 rt-src rt-dhcp scope 
global
Sep 20 09:53:11.874930 tap-0FB1 NetworkManager[762]: <debug> platform: signal: route   4 removed: 0.0.0.0/0 
via 192.168.19.193 dev 2 metric 100 mss 0 rt-src rt-dhcp scope global
Sep 20 09:53:11.874961 tap-0FB1 NetworkManager[762]: <debug> platform-linux: do-delete-ip4-route[0.0.0.0/0 
via 192.168.19.193 dev 2 metric 100 mss 0 rt-src rt-dhcp scope global]: success
Sep 20 09:53:11.874983 tap-0FB1 NetworkManager[762]: <trace> platform: ip4-dev-route: register 
192.168.19.0/24 via 0.0.0.0 dev 2 metric 0 mss 0 rt-src rt-kernel scope link pref-src 192.168.19.100 (update)

Fixes: ca0f147bf45e291914b4ec3c6afbc812dd8010b1
---
 src/devices/nm-device.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index 33dd5e5..fa010ae 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -10362,8 +10362,10 @@ nm_device_reactivate_ip4_config (NMDevice *self,
                                        nm_ip4_config_update_routes_metric ((NMIP4Config *) 
priv->wwan_ip_config_4.orig,
                                                                            nm_device_get_route_metric (self, 
AF_INET));
                                }
-                               if (priv->dhcp4.client)
-                                       nm_dhcp_client_set_route_metric (priv->dhcp4.client, metric_new);
+                               if (priv->dhcp4.client) {
+                                       nm_dhcp_client_set_route_metric (priv->dhcp4.client,
+                                                                        nm_device_get_route_metric (self, 
AF_INET));
+                               }
                        }
                }
 
@@ -10433,8 +10435,10 @@ nm_device_reactivate_ip6_config (NMDevice *self,
                                        nm_ip6_config_update_routes_metric ((NMIP6Config *) 
priv->wwan_ip_config_6.orig,
                                                                            nm_device_get_route_metric (self, 
AF_INET6));
                                }
-                               if (priv->dhcp6.client)
-                                       nm_dhcp_client_set_route_metric (priv->dhcp6.client, metric_new);
+                               if (priv->dhcp6.client) {
+                                       nm_dhcp_client_set_route_metric (priv->dhcp6.client,
+                                                                        nm_device_get_route_metric (self, 
AF_INET6));
+                               }
                        }
                }
 
-- 
2.7.4



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]