]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
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 089bbfea22443b80871a0113c2ade8a02d9398f9..a5c52bbf82473471d72aa650088d773d795b0fe4 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 684edddb5f5307a1ac25940097cebb7fce63e68a..c7058b3becbd9fe22d93999556b55600fe85c748 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 4cb2eca3d2f8bdd1007d0c36089e6e1ca44d1874..4b855ae1e1161b3d76f989b2da053dda1b1ca930 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 3cdbd9e37e776ae1dc4757fe9d08a2cdeed33a35..87345fb2d63b2493e11c6153000f45e33bf97a07 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 5553a7e3bd1b086c3cf46a3276521226328ef238..6dd7a07c32ca72f9a6affe1eb4f64535415f812e 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 2dc78622cecf9a7853b7a86271f8c100d6ae00ac..e5805ab0ea556f7fb461748168af639fe9a0d55e 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");