aboutgitcodebugslistschat
path: root/conf.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-08-03 17:19:55 +1000
committerStefano Brivio <sbrivio@redhat.com>2023-08-04 01:30:41 +0200
commit5103811e2df397c2f3165ac065e1e92cfa4eae31 (patch)
treec51c1be5b2c94e4d4eaf8575873e4601c2bcdd6b /conf.c
parent4d6e9d0816e2b28da1ed87b2d3d6bac40433dde4 (diff)
downloadpasst-5103811e2df397c2f3165ac065e1e92cfa4eae31.tar
passt-5103811e2df397c2f3165ac065e1e92cfa4eae31.tar.gz
passt-5103811e2df397c2f3165ac065e1e92cfa4eae31.tar.bz2
passt-5103811e2df397c2f3165ac065e1e92cfa4eae31.tar.lz
passt-5103811e2df397c2f3165ac065e1e92cfa4eae31.tar.xz
passt-5103811e2df397c2f3165ac065e1e92cfa4eae31.tar.zst
passt-5103811e2df397c2f3165ac065e1e92cfa4eae31.zip
netlink: Propagate errors for "dump" operations
Currently if we receive any netlink errors while discovering network configuration from the host, we'll just ignore it and carry on. This might lead to cryptic error messages later on, or even silent misconfiguration. We now have the mechanisms to detect errors from get/dump netlink operations. Propgate these errors up to the callers and report them usefully. Link: https://bugs.passt.top/show_bug.cgi?id=60 Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'conf.c')
-rw-r--r--conf.c65
1 files changed, 51 insertions, 14 deletions
diff --git a/conf.c b/conf.c
index 7286f92..0631b00 100644
--- a/conf.c
+++ b/conf.c
@@ -648,12 +648,24 @@ static unsigned int conf_ip4(unsigned int ifi,
return 0;
}
- if (IN4_IS_ADDR_UNSPECIFIED(&ip4->gw))
- nl_route_get_def(nl_sock, ifi, AF_INET, &ip4->gw);
+ if (IN4_IS_ADDR_UNSPECIFIED(&ip4->gw)) {
+ int rc = nl_route_get_def(nl_sock, ifi, AF_INET, &ip4->gw);
+ if (rc < 0) {
+ err("Couldn't discover IPv4 gateway address: %s",
+ strerror(-rc));
+ return 0;
+ }
+ }
- if (IN4_IS_ADDR_UNSPECIFIED(&ip4->addr))
- nl_addr_get(nl_sock, ifi, AF_INET,
- &ip4->addr, &ip4->prefix_len, NULL);
+ if (IN4_IS_ADDR_UNSPECIFIED(&ip4->addr)) {
+ int rc = nl_addr_get(nl_sock, ifi, AF_INET,
+ &ip4->addr, &ip4->prefix_len, NULL);
+ if (rc < 0) {
+ err("Couldn't discover IPv4 address: %s",
+ strerror(-rc));
+ return 0;
+ }
+ }
if (!ip4->prefix_len) {
in_addr_t addr = ntohl(ip4->addr.s_addr);
@@ -669,8 +681,15 @@ static unsigned int conf_ip4(unsigned int ifi,
memcpy(&ip4->addr_seen, &ip4->addr, sizeof(ip4->addr_seen));
- if (MAC_IS_ZERO(mac))
- nl_link_get_mac(nl_sock, ifi, mac);
+ if (MAC_IS_ZERO(mac)) {
+ int rc = nl_link_get_mac(nl_sock, ifi, mac);
+ if (rc < 0) {
+ char ifname[IFNAMSIZ];
+ err("Couldn't discover MAC for %s: %s",
+ if_indextoname(ifi, ifname), strerror(-rc));
+ return 0;
+ }
+ }
if (IN4_IS_ADDR_UNSPECIFIED(&ip4->addr) ||
MAC_IS_ZERO(mac))
@@ -691,6 +710,7 @@ static unsigned int conf_ip6(unsigned int ifi,
struct ip6_ctx *ip6, unsigned char *mac)
{
int prefix_len = 0;
+ int rc;
if (!ifi)
ifi = nl_get_ext_if(nl_sock, AF_INET6);
@@ -700,18 +720,35 @@ static unsigned int conf_ip6(unsigned int ifi,
return 0;
}
- if (IN6_IS_ADDR_UNSPECIFIED(&ip6->gw))
- nl_route_get_def(nl_sock, ifi, AF_INET6, &ip6->gw);
+ if (IN6_IS_ADDR_UNSPECIFIED(&ip6->gw)) {
+ rc = nl_route_get_def(nl_sock, ifi, AF_INET6, &ip6->gw);
+ if (rc < 0) {
+ err("Couldn't discover IPv6 gateway address: %s",
+ strerror(-rc));
+ return 0;
+ }
+ }
- nl_addr_get(nl_sock, ifi, AF_INET6,
- IN6_IS_ADDR_UNSPECIFIED(&ip6->addr) ? &ip6->addr : NULL,
- &prefix_len, &ip6->addr_ll);
+ rc = nl_addr_get(nl_sock, ifi, AF_INET6,
+ IN6_IS_ADDR_UNSPECIFIED(&ip6->addr) ? &ip6->addr : NULL,
+ &prefix_len, &ip6->addr_ll);
+ if (rc < 0) {
+ err("Couldn't discover IPv6 address: %s", strerror(-rc));
+ return 0;
+ }
memcpy(&ip6->addr_seen, &ip6->addr, sizeof(ip6->addr));
memcpy(&ip6->addr_ll_seen, &ip6->addr_ll, sizeof(ip6->addr_ll));
- if (MAC_IS_ZERO(mac))
- nl_link_get_mac(0, ifi, mac);
+ if (MAC_IS_ZERO(mac)) {
+ rc = nl_link_get_mac(nl_sock, ifi, mac);
+ if (rc < 0) {
+ char ifname[IFNAMSIZ];
+ err("Couldn't discover MAC for %s: %s",
+ if_indextoname(ifi, ifname), strerror(-rc));
+ return 0;
+ }
+ }
if (IN6_IS_ADDR_UNSPECIFIED(&ip6->addr) ||
IN6_IS_ADDR_UNSPECIFIED(&ip6->addr_ll) ||