Repository navigation
Commit 038b24d
authored
utils: do not require an IPv4 default route to find the default NIC (#14060)
A management server does not need an IPv4 default route. It can be
IPv6-first, or reach its POD network and KVM agents over IPv4 without
having a default gateway on that family at all.
getDefaultEthDevice() only looked at the IPv4 routing table and picked
column 5 of the route as the device name:
ip route show default 0.0.0.0/0 | head -1 | awk '{print $5}'
That has two problems:
* Anything the shell or 'ip' writes on stderr ends up in the captured
output (Script merges stderr into stdout), so the method can return a
string that is not a device name at all. getAllDefaultNicIps() then
passes it to NetworkInterface.getByName(), which returns null, and the
unchecked dereference throws a NullPointerException. On a host without
an IPv4 default route this aborts the boot of the management server:
ERROR [o.a.c.s.l.CloudStackExtendedLifeCycle] Error on configuring
bean RootCAProvider - Cannot invoke
"java.net.NetworkInterface.getInterfaceAddresses()" because "nic" is
null
at com.cloud.utils.net.NetUtils.getAllDefaultNicIps(NetUtils.java:298)
at o.a.c.ca.provider.RootCAProvider.loadManagementKeyStore(RootCAProvider.java:409)
ERROR [o.a.c.s.m.m.i.DefaultModuleDefinitionSet] Failed to load
module [root-ca]
* Column 5 is only the device for routes of the form
"default via <gw> dev <name> ...". For an on-link default route such as
"default dev eth0 scope link" or "default dev eno1 proto kernel metric
256" it returns "link" or "kernel".
The device name is now taken from the token following "dev", which is
correct for every route layout including multipath routes, and the IPv6
routing table is consulted when there is no IPv4 default route. The
results of NetworkInterface.getByName() are null checked in both
getDefaultHostIp() and getAllDefaultNicIps() so an unresolvable device
name degrades to "no default NIC" instead of an exception.1 parent 2737087 commit 038b24d
2 files changed
Lines changed: 67 additions & 1 deletion
File tree
- utils/src
- main/java/com/cloud/utils/net
- test/java/com/cloud/utils/net
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
270 | 275 | | |
271 | 276 | | |
272 | 277 | | |
| |||
295 | 300 | | |
296 | 301 | | |
297 | 302 | | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
298 | 308 | | |
299 | 309 | | |
300 | 310 | | |
| |||
306 | 316 | | |
307 | 317 | | |
308 | 318 | | |
309 | | - | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
310 | 338 | | |
311 | 339 | | |
312 | 340 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
| 48 | + | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| 54 | + | |
52 | 55 | | |
53 | 56 | | |
54 | 57 | | |
| |||
748 | 751 | | |
749 | 752 | | |
750 | 753 | | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
751 | 789 | | |
752 | 790 | | |
753 | 791 | | |
| |||
0 commit comments