network: in_addr_is_null() may return negative errno
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 2 Feb 2019 23:09:13 +0000 (00:09 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 10 Feb 2019 16:28:09 +0000 (01:28 +0900)
So, do not silently cast the returned value to boolean.
Exception is the case that family is trivially AF_INET or AF_INET6.

src/network/netdev/geneve.c
src/network/netdev/tunnel.c
src/network/netdev/vxlan.c
src/network/networkd-address.c
src/network/networkd-route.c
src/network/networkd-routing-policy-rule.c

index 089bbfe..a5c52bb 100644 (file)
@@ -83,16 +83,13 @@ static int netdev_geneve_create(NetDev *netdev) {
                         return log_netdev_error_errno(netdev, r, "Could not append IFLA_GENEVE_ID attribute: %m");
         }
 
-        if (!in_addr_is_null(v->remote_family, &v->remote)) {
-
+        if (in_addr_is_null(v->remote_family, &v->remote) == 0) {
                 if (v->remote_family == AF_INET)
                         r = sd_netlink_message_append_in_addr(m, IFLA_GENEVE_REMOTE, &v->remote.in);
                 else
                         r = sd_netlink_message_append_in6_addr(m, IFLA_GENEVE_REMOTE6, &v->remote.in6);
-
                 if (r < 0)
                         return log_netdev_error_errno(netdev, r, "Could not append IFLA_GENEVE_GROUP attribute: %m");
-
         }
 
         if (v->ttl) {
index 684eddd..c7058b3 100644 (file)
@@ -578,8 +578,8 @@ int config_parse_tunnel_address(const char *unit,
                  * unspecified, also clear the address family.
                  */
                 if (t->family != AF_UNSPEC &&
-                    in_addr_is_null(t->family, &t->local) &&
-                    in_addr_is_null(t->family, &t->remote))
+                    in_addr_is_null(t->family, &t->local) != 0 &&
+                    in_addr_is_null(t->family, &t->remote) != 0)
                         t->family = AF_UNSPEC;
                 return 0;
         }
index 4cb2eca..4b855ae 100644 (file)
@@ -33,24 +33,20 @@ static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_netli
                         return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_ID attribute: %m");
         }
 
-        if (!in_addr_is_null(v->remote_family, &v->remote)) {
-
+        if (in_addr_is_null(v->remote_family, &v->remote) == 0) {
                 if (v->remote_family == AF_INET)
                         r = sd_netlink_message_append_in_addr(m, IFLA_VXLAN_GROUP, &v->remote.in);
                 else
                         r = sd_netlink_message_append_in6_addr(m, IFLA_VXLAN_GROUP6, &v->remote.in6);
-
                 if (r < 0)
                         return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_GROUP attribute: %m");
         }
 
-        if (!in_addr_is_null(v->local_family, &v->local)) {
-
+        if (in_addr_is_null(v->local_family, &v->local) == 0) {
                 if (v->local_family == AF_INET)
                         r = sd_netlink_message_append_in_addr(m, IFLA_VXLAN_LOCAL, &v->local.in);
                 else
                         r = sd_netlink_message_append_in6_addr(m, IFLA_VXLAN_LOCAL6, &v->local.in6);
-
                 if (r < 0)
                         return log_netdev_error_errno(netdev, r, "Could not append IFLA_VXLAN_LOCAL attribute: %m");
         }
index 3cdbd9e..87345fb 100644 (file)
@@ -625,7 +625,7 @@ int address_configure(
         if (r < 0)
                 return log_error_errno(r, "Could not append IFA_LOCAL attribute: %m");
 
-        if (!in_addr_is_null(address->family, &address->in_addr_peer)) {
+        if (in_addr_is_null(address->family, &address->in_addr_peer) == 0) {
                 if (address->family == AF_INET)
                         r = sd_netlink_message_append_in_addr(req, IFA_ADDRESS, &address->in_addr_peer.in);
                 else if (address->family == AF_INET6)
index 5553a7e..6dd7a07 100644 (file)
@@ -408,7 +408,7 @@ int route_remove(Route *route, Link *link,
         if (r < 0)
                 return log_error_errno(r, "Could not create RTM_DELROUTE message: %m");
 
-        if (!in_addr_is_null(route->family, &route->gw)) {
+        if (in_addr_is_null(route->family, &route->gw) == 0) {
                 if (route->family == AF_INET)
                         r = sd_netlink_message_append_in_addr(req, RTA_GATEWAY, &route->gw.in);
                 else if (route->family == AF_INET6)
@@ -443,7 +443,7 @@ int route_remove(Route *route, Link *link,
                         return log_error_errno(r, "Could not set source prefix length: %m");
         }
 
-        if (!in_addr_is_null(route->family, &route->prefsrc)) {
+        if (in_addr_is_null(route->family, &route->prefsrc) == 0) {
                 if (route->family == AF_INET)
                         r = sd_netlink_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc.in);
                 else if (route->family == AF_INET6)
@@ -519,7 +519,7 @@ int route_configure(
         if (r < 0)
                 return log_error_errno(r, "Could not create RTM_NEWROUTE message: %m");
 
-        if (!in_addr_is_null(route->family, &route->gw)) {
+        if (in_addr_is_null(route->family, &route->gw) == 0) {
                 if (route->family == AF_INET)
                         r = sd_netlink_message_append_in_addr(req, RTA_GATEWAY, &route->gw.in);
                 else if (route->family == AF_INET6)
@@ -558,7 +558,7 @@ int route_configure(
                         return log_error_errno(r, "Could not set source prefix length: %m");
         }
 
-        if (!in_addr_is_null(route->family, &route->prefsrc)) {
+        if (in_addr_is_null(route->family, &route->prefsrc) == 0) {
                 if (route->family == AF_INET)
                         r = sd_netlink_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc.in);
                 else if (route->family == AF_INET6)
index 2dc7862..e5805ab 100644 (file)
@@ -369,12 +369,11 @@ int routing_policy_rule_remove(RoutingPolicyRule *routing_policy_rule, Link *lin
         if (r < 0)
                 return log_error_errno(r, "Could not allocate RTM_DELRULE message: %m");
 
-        if (!in_addr_is_null(routing_policy_rule->family, &routing_policy_rule->from)) {
+        if (in_addr_is_null(routing_policy_rule->family, &routing_policy_rule->from) == 0) {
                 if (routing_policy_rule->family == AF_INET)
                         r = sd_netlink_message_append_in_addr(m, FRA_SRC, &routing_policy_rule->from.in);
                 else
                         r = sd_netlink_message_append_in6_addr(m, FRA_SRC, &routing_policy_rule->from.in6);
-
                 if (r < 0)
                         return log_error_errno(r, "Could not append FRA_SRC attribute: %m");
 
@@ -383,12 +382,11 @@ int routing_policy_rule_remove(RoutingPolicyRule *routing_policy_rule, Link *lin
                         return log_error_errno(r, "Could not set source prefix length: %m");
         }
 
-        if (!in_addr_is_null(routing_policy_rule->family, &routing_policy_rule->to)) {
+        if (in_addr_is_null(routing_policy_rule->family, &routing_policy_rule->to) == 0) {
                 if (routing_policy_rule->family == AF_INET)
                         r = sd_netlink_message_append_in_addr(m, FRA_DST, &routing_policy_rule->to.in);
                 else
                         r = sd_netlink_message_append_in6_addr(m, FRA_DST, &routing_policy_rule->to.in6);
-
                 if (r < 0)
                         return log_error_errno(r, "Could not append FRA_DST attribute: %m");
 
@@ -496,12 +494,11 @@ int routing_policy_rule_configure(RoutingPolicyRule *rule, Link *link, link_netl
         if (r < 0)
                 return log_error_errno(r, "Could not allocate RTM_NEWRULE message: %m");
 
-        if (!in_addr_is_null(rule->family, &rule->from)) {
+        if (in_addr_is_null(rule->family, &rule->from) == 0) {
                 if (rule->family == AF_INET)
                         r = sd_netlink_message_append_in_addr(m, FRA_SRC, &rule->from.in);
                 else
                         r = sd_netlink_message_append_in6_addr(m, FRA_SRC, &rule->from.in6);
-
                 if (r < 0)
                         return log_error_errno(r, "Could not append FRA_SRC attribute: %m");
 
@@ -510,12 +507,11 @@ int routing_policy_rule_configure(RoutingPolicyRule *rule, Link *link, link_netl
                         return log_error_errno(r, "Could not set source prefix length: %m");
         }
 
-        if (!in_addr_is_null(rule->family, &rule->to)) {
+        if (in_addr_is_null(rule->family, &rule->to) == 0) {
                 if (rule->family == AF_INET)
                         r = sd_netlink_message_append_in_addr(m, FRA_DST, &rule->to.in);
                 else
                         r = sd_netlink_message_append_in6_addr(m, FRA_DST, &rule->to.in6);
-
                 if (r < 0)
                         return log_error_errno(r, "Could not append FRA_DST attribute: %m");