network: in_addr_is_null() may return negative errno

So, do not silently cast the returned value to boolean.
Exception is the case that family is trivially AF_INET or AF_INET6.
This commit is contained in:
Yu Watanabe 2019-02-03 00:09:13 +01:00
parent c606db69ab
commit d40b01e44b
6 changed files with 14 additions and 25 deletions

View 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) {

View 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;
}

View 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");
}

View 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)

View 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)

View 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");