mirror of
https://github.com/systemd/systemd.git
synced 2025-03-11 20:58:27 +03:00
Merge pull request #11636 from yuwata/network-in-addr-is-null
network, sd-netlink: unify several functions and fixes coding style
This commit is contained in:
commit
8e6b3f49fe
@ -751,8 +751,9 @@
|
||||
<literal>ip6gre</literal>,
|
||||
<literal>ip6gretap</literal>,
|
||||
<literal>vti</literal>,
|
||||
<literal>vti6</literal>, and
|
||||
<literal>ip6tnl</literal> and accepts
|
||||
<literal>vti6</literal>,
|
||||
<literal>ip6tnl</literal>, and
|
||||
<literal>erspan</literal> and accepts
|
||||
the following keys:</para>
|
||||
|
||||
<variablelist class='network-directives'>
|
||||
|
@ -334,36 +334,46 @@ int sd_netlink_message_append_data(sd_netlink_message *m, unsigned short type, c
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sd_netlink_message_append_in_addr(sd_netlink_message *m, unsigned short type, const struct in_addr *data) {
|
||||
int netlink_message_append_in_addr_union(sd_netlink_message *m, unsigned short type, int family, const union in_addr_union *data) {
|
||||
int r;
|
||||
|
||||
assert_return(m, -EINVAL);
|
||||
assert_return(!m->sealed, -EPERM);
|
||||
assert_return(data, -EINVAL);
|
||||
assert_return(IN_SET(family, AF_INET, AF_INET6), -EINVAL);
|
||||
|
||||
r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_IN_ADDR);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = add_rtattr(m, type, data, sizeof(struct in_addr));
|
||||
r = add_rtattr(m, type, data, FAMILY_ADDRESS_SIZE(family));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sd_netlink_message_append_in_addr(sd_netlink_message *m, unsigned short type, const struct in_addr *data) {
|
||||
return netlink_message_append_in_addr_union(m, type, AF_INET, (const union in_addr_union *) data);
|
||||
}
|
||||
|
||||
int sd_netlink_message_append_in6_addr(sd_netlink_message *m, unsigned short type, const struct in6_addr *data) {
|
||||
return netlink_message_append_in_addr_union(m, type, AF_INET6, (const union in_addr_union *) data);
|
||||
}
|
||||
|
||||
int netlink_message_append_sockaddr_union(sd_netlink_message *m, unsigned short type, const union sockaddr_union *data) {
|
||||
int r;
|
||||
|
||||
assert_return(m, -EINVAL);
|
||||
assert_return(!m->sealed, -EPERM);
|
||||
assert_return(data, -EINVAL);
|
||||
assert_return(IN_SET(data->sa.sa_family, AF_INET, AF_INET6), -EINVAL);
|
||||
|
||||
r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_IN_ADDR);
|
||||
r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_SOCKADDR);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = add_rtattr(m, type, data, sizeof(struct in6_addr));
|
||||
r = add_rtattr(m, type, data, data->sa.sa_family == AF_INET ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@ -371,41 +381,14 @@ int sd_netlink_message_append_in6_addr(sd_netlink_message *m, unsigned short typ
|
||||
}
|
||||
|
||||
int sd_netlink_message_append_sockaddr_in(sd_netlink_message *m, unsigned short type, const struct sockaddr_in *data) {
|
||||
int r;
|
||||
|
||||
assert_return(m, -EINVAL);
|
||||
assert_return(!m->sealed, -EPERM);
|
||||
assert_return(data, -EINVAL);
|
||||
|
||||
r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_SOCKADDR);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = add_rtattr(m, type, data, sizeof(struct sockaddr_in));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
return netlink_message_append_sockaddr_union(m, type, (const union sockaddr_union *) data);
|
||||
}
|
||||
|
||||
int sd_netlink_message_append_sockaddr_in6(sd_netlink_message *m, unsigned short type, const struct sockaddr_in6 *data) {
|
||||
int r;
|
||||
|
||||
assert_return(m, -EINVAL);
|
||||
assert_return(!m->sealed, -EPERM);
|
||||
assert_return(data, -EINVAL);
|
||||
|
||||
r = message_attribute_has_type(m, NULL, type, NETLINK_TYPE_SOCKADDR);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = add_rtattr(m, type, data, sizeof(struct sockaddr_in6));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
return netlink_message_append_sockaddr_union(m, type, (const union sockaddr_union *) data);
|
||||
}
|
||||
|
||||
|
||||
int sd_netlink_message_append_ether_addr(sd_netlink_message *m, unsigned short type, const struct ether_addr *data) {
|
||||
int r;
|
||||
|
||||
|
@ -3,6 +3,8 @@
|
||||
|
||||
#include "sd-netlink.h"
|
||||
|
||||
#include "in-addr-util.h"
|
||||
#include "socket-util.h"
|
||||
#include "util.h"
|
||||
|
||||
int rtnl_message_new_synthetic_error(sd_netlink *rtnl, int error, uint32_t serial, sd_netlink_message **ret);
|
||||
@ -58,3 +60,6 @@ int rtnl_log_create_error(int r);
|
||||
(sd_netlink_destroy_t) _destroy_, \
|
||||
userdata, __func__); \
|
||||
})
|
||||
|
||||
int netlink_message_append_in_addr_union(sd_netlink_message *m, unsigned short type, int family, const union in_addr_union *data);
|
||||
int netlink_message_append_sockaddr_union(sd_netlink_message *m, unsigned short type, const union sockaddr_union *data);
|
||||
|
@ -177,22 +177,21 @@ static int netdev_bond_fill_message_create(NetDev *netdev, Link *link, sd_netlin
|
||||
assert(b);
|
||||
|
||||
if (b->mode != _NETDEV_BOND_MODE_INVALID) {
|
||||
r = sd_netlink_message_append_u8(m, IFLA_BOND_MODE,
|
||||
bond_mode_to_kernel(b->mode));
|
||||
r = sd_netlink_message_append_u8(m, IFLA_BOND_MODE, bond_mode_to_kernel(b->mode));
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_MODE attribute: %m");
|
||||
}
|
||||
|
||||
if (b->xmit_hash_policy != _NETDEV_BOND_XMIT_HASH_POLICY_INVALID) {
|
||||
r = sd_netlink_message_append_u8(m, IFLA_BOND_XMIT_HASH_POLICY,
|
||||
bond_xmit_hash_policy_to_kernel(b->xmit_hash_policy));
|
||||
bond_xmit_hash_policy_to_kernel(b->xmit_hash_policy));
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_XMIT_HASH_POLICY attribute: %m");
|
||||
}
|
||||
|
||||
if (b->lacp_rate != _NETDEV_BOND_LACP_RATE_INVALID &&
|
||||
b->mode == NETDEV_BOND_MODE_802_3AD) {
|
||||
r = sd_netlink_message_append_u8(m, IFLA_BOND_AD_LACP_RATE, b->lacp_rate );
|
||||
r = sd_netlink_message_append_u8(m, IFLA_BOND_AD_LACP_RATE, b->lacp_rate);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_AD_LACP_RATE attribute: %m");
|
||||
}
|
||||
@ -220,8 +219,8 @@ static int netdev_bond_fill_message_create(NetDev *netdev, Link *link, sd_netlin
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_INTERVAL attribute: %m");
|
||||
|
||||
if ((b->lp_interval >= LEARNING_PACKETS_INTERVAL_MIN_SEC) &&
|
||||
(b->lp_interval <= LEARNING_PACKETS_INTERVAL_MAX_SEC)) {
|
||||
if (b->lp_interval >= LEARNING_PACKETS_INTERVAL_MIN_SEC &&
|
||||
b->lp_interval <= LEARNING_PACKETS_INTERVAL_MAX_SEC) {
|
||||
r = sd_netlink_message_append_u32(m, IFLA_BOND_LP_INTERVAL, b->lp_interval / USEC_PER_SEC);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_LP_INTERVAL attribute: %m");
|
||||
@ -313,23 +312,20 @@ static int netdev_bond_fill_message_create(NetDev *netdev, Link *link, sd_netlin
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_TLB_DYNAMIC_LB attribute: %m");
|
||||
}
|
||||
|
||||
if (b->arp_interval > 0) {
|
||||
if (b->n_arp_ip_targets > 0) {
|
||||
if (b->arp_interval > 0 && b->n_arp_ip_targets > 0) {
|
||||
r = sd_netlink_message_open_container(m, IFLA_BOND_ARP_IP_TARGET);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not open contaniner IFLA_BOND_ARP_IP_TARGET : %m");
|
||||
|
||||
r = sd_netlink_message_open_container(m, IFLA_BOND_ARP_IP_TARGET);
|
||||
LIST_FOREACH(arp_ip_target, target, b->arp_ip_targets) {
|
||||
r = sd_netlink_message_append_u32(m, i++, target->ip.in.s_addr);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not open contaniner IFLA_BOND_ARP_IP_TARGET : %m");
|
||||
|
||||
LIST_FOREACH(arp_ip_target, target, b->arp_ip_targets) {
|
||||
r = sd_netlink_message_append_u32(m, i++, target->ip.in.s_addr);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_ALL_TARGETS attribute: %m");
|
||||
}
|
||||
|
||||
r = sd_netlink_message_close_container(m);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not close contaniner IFLA_BOND_ARP_IP_TARGET : %m");
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_BOND_ARP_ALL_TARGETS attribute: %m");
|
||||
}
|
||||
|
||||
r = sd_netlink_message_close_container(m);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not close contaniner IFLA_BOND_ARP_IP_TARGET : %m");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -83,19 +83,16 @@ 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");
|
||||
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GENEVE_REMOTE/IFLA_GENEVE_REMOTE6 attribute: %m");
|
||||
}
|
||||
|
||||
if (v->ttl) {
|
||||
if (v->ttl > 0) {
|
||||
r = sd_netlink_message_append_u8(m, IFLA_GENEVE_TTL, v->ttl);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_GENEVE_TTL attribute: %m");
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include "conf-parser.h"
|
||||
#include "missing.h"
|
||||
#include "netlink-util.h"
|
||||
#include "networkd-link.h"
|
||||
#include "netdev/tunnel.h"
|
||||
#include "parse-util.h"
|
||||
@ -34,63 +35,20 @@ static const char* const ip6tnl_mode_table[_NETDEV_IP6_TNL_MODE_MAX] = {
|
||||
DEFINE_STRING_TABLE_LOOKUP(ip6tnl_mode, Ip6TnlMode);
|
||||
DEFINE_CONFIG_PARSE_ENUM(config_parse_ip6tnl_mode, ip6tnl_mode, Ip6TnlMode, "Failed to parse ip6 tunnel Mode");
|
||||
|
||||
static int netdev_ipip_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
|
||||
Tunnel *t = IPIP(netdev);
|
||||
static int netdev_ipip_sit_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
|
||||
Tunnel *t;
|
||||
int r;
|
||||
|
||||
assert(netdev);
|
||||
|
||||
if (netdev->kind == NETDEV_KIND_IPIP)
|
||||
t = IPIP(netdev);
|
||||
else
|
||||
t = SIT(netdev);
|
||||
|
||||
assert(m);
|
||||
assert(t);
|
||||
assert(IN_SET(t->family, AF_INET, AF_UNSPEC));
|
||||
|
||||
if (link) {
|
||||
r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
|
||||
}
|
||||
|
||||
r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_LOCAL, &t->local.in);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m");
|
||||
|
||||
r = sd_netlink_message_append_in_addr(m, IFLA_IPTUN_REMOTE, &t->remote.in);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m");
|
||||
|
||||
r = sd_netlink_message_append_u8(m, IFLA_IPTUN_TTL, t->ttl);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_TTL attribute: %m");
|
||||
|
||||
r = sd_netlink_message_append_u8(m, IFLA_IPTUN_PMTUDISC, t->pmtudisc);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_PMTUDISC attribute: %m");
|
||||
|
||||
if (t->fou_tunnel) {
|
||||
|
||||
r = sd_netlink_message_append_u16(m, IFLA_IPTUN_ENCAP_TYPE, t->fou_encap_type);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_ENCAP_TYPE attribute: %m");
|
||||
|
||||
r = sd_netlink_message_append_u16(m, IFLA_IPTUN_ENCAP_SPORT, htobe16(t->encap_src_port));
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_ENCAP_SPORT attribute: %m");
|
||||
|
||||
r = sd_netlink_message_append_u16(m, IFLA_IPTUN_ENCAP_DPORT, htobe16(t->fou_destination_port));
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_ENCAP_DPORT attribute: %m");
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int netdev_sit_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
|
||||
Tunnel *t = SIT(netdev);
|
||||
int r;
|
||||
|
||||
assert(netdev);
|
||||
assert(m);
|
||||
assert(t);
|
||||
assert(IN_SET(t->family, AF_INET, AF_UNSPEC));
|
||||
assert(t->family == AF_INET);
|
||||
|
||||
if (link) {
|
||||
r = sd_netlink_message_append_u32(m, IFLA_IPTUN_LINK, link->ifindex);
|
||||
@ -114,27 +72,43 @@ static int netdev_sit_fill_message_create(NetDev *netdev, Link *link, sd_netlink
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_PMTUDISC attribute: %m");
|
||||
|
||||
if (t->sixrd_prefixlen > 0) {
|
||||
r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_6RD_PREFIX, &t->sixrd_prefix);
|
||||
if (netdev->kind == NETDEV_KIND_IPIP && t->fou_tunnel) {
|
||||
r = sd_netlink_message_append_u16(m, IFLA_IPTUN_ENCAP_TYPE, t->fou_encap_type);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_6RD_PREFIX attribute: %m");
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_ENCAP_TYPE attribute: %m");
|
||||
|
||||
/* u16 is deliberate here, even though we're passing a netmask that can never be >128. The kernel is
|
||||
* expecting to receive the prefixlen as a u16.
|
||||
*/
|
||||
r = sd_netlink_message_append_u16(m, IFLA_IPTUN_6RD_PREFIXLEN, t->sixrd_prefixlen);
|
||||
r = sd_netlink_message_append_u16(m, IFLA_IPTUN_ENCAP_SPORT, htobe16(t->encap_src_port));
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_6RD_PREFIXLEN attribute: %m");
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_ENCAP_SPORT attribute: %m");
|
||||
|
||||
r = sd_netlink_message_append_u16(m, IFLA_IPTUN_ENCAP_DPORT, htobe16(t->fou_destination_port));
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_ENCAP_DPORT attribute: %m");
|
||||
}
|
||||
|
||||
if (t->isatap >= 0) {
|
||||
uint16_t flags = 0;
|
||||
if (netdev->kind == NETDEV_KIND_SIT) {
|
||||
if (t->sixrd_prefixlen > 0) {
|
||||
r = sd_netlink_message_append_in6_addr(m, IFLA_IPTUN_6RD_PREFIX, &t->sixrd_prefix);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_6RD_PREFIX attribute: %m");
|
||||
|
||||
SET_FLAG(flags, SIT_ISATAP, t->isatap);
|
||||
/* u16 is deliberate here, even though we're passing a netmask that can never be >128. The kernel is
|
||||
* expecting to receive the prefixlen as a u16.
|
||||
*/
|
||||
r = sd_netlink_message_append_u16(m, IFLA_IPTUN_6RD_PREFIXLEN, t->sixrd_prefixlen);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_6RD_PREFIXLEN attribute: %m");
|
||||
}
|
||||
|
||||
r = sd_netlink_message_append_u16(m, IFLA_IPTUN_FLAGS, flags);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_FLAGS attribute: %m");
|
||||
if (t->isatap >= 0) {
|
||||
uint16_t flags = 0;
|
||||
|
||||
SET_FLAG(flags, SIT_ISATAP, t->isatap);
|
||||
|
||||
r = sd_netlink_message_append_u16(m, IFLA_IPTUN_FLAGS, flags);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_FLAGS attribute: %m");
|
||||
}
|
||||
}
|
||||
|
||||
return r;
|
||||
@ -152,7 +126,7 @@ static int netdev_gre_fill_message_create(NetDev *netdev, Link *link, sd_netlink
|
||||
t = GRETAP(netdev);
|
||||
|
||||
assert(t);
|
||||
assert(IN_SET(t->family, AF_INET, AF_UNSPEC));
|
||||
assert(t->family == AF_INET);
|
||||
assert(m);
|
||||
|
||||
if (link) {
|
||||
@ -197,7 +171,7 @@ static int netdev_erspan_fill_message_create(NetDev *netdev, Link *link, sd_netl
|
||||
t = ERSPAN(netdev);
|
||||
|
||||
assert(t);
|
||||
assert(IN_SET(t->family, AF_INET, AF_UNSPEC));
|
||||
assert(t->family == AF_INET);
|
||||
assert(m);
|
||||
|
||||
r = sd_netlink_message_append_u32(m, IFLA_GRE_ERSPAN_INDEX, t->erspan_index);
|
||||
@ -301,11 +275,12 @@ static int netdev_ip6gre_fill_message_create(NetDev *netdev, Link *link, sd_netl
|
||||
return r;
|
||||
}
|
||||
|
||||
static int netdev_vti_fill_message_key(NetDev *netdev, Link *link, sd_netlink_message *m) {
|
||||
static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
|
||||
uint32_t ikey, okey;
|
||||
Tunnel *t;
|
||||
int r;
|
||||
|
||||
assert(netdev);
|
||||
assert(m);
|
||||
|
||||
if (netdev->kind == NETDEV_KIND_VTI)
|
||||
@ -314,6 +289,14 @@ static int netdev_vti_fill_message_key(NetDev *netdev, Link *link, sd_netlink_me
|
||||
t = VTI6(netdev);
|
||||
|
||||
assert(t);
|
||||
assert((netdev->kind == NETDEV_KIND_VTI && t->family == AF_INET) ||
|
||||
(netdev->kind == NETDEV_KIND_VTI6 && t->family == AF_INET6));
|
||||
|
||||
if (link) {
|
||||
r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_VTI_LINK attribute: %m");
|
||||
}
|
||||
|
||||
if (t->key != 0)
|
||||
ikey = okey = htobe32(t->key);
|
||||
@ -330,65 +313,13 @@ static int netdev_vti_fill_message_key(NetDev *netdev, Link *link, sd_netlink_me
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_VTI_OKEY attribute: %m");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int netdev_vti_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
|
||||
Tunnel *t = VTI(netdev);
|
||||
int r;
|
||||
|
||||
assert(netdev);
|
||||
assert(m);
|
||||
assert(t);
|
||||
assert(t->family == AF_INET);
|
||||
|
||||
if (link) {
|
||||
r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
|
||||
}
|
||||
|
||||
r = netdev_vti_fill_message_key(netdev, link, m);
|
||||
r = netlink_message_append_in_addr_union(m, IFLA_VTI_LOCAL, t->family, &t->local);
|
||||
if (r < 0)
|
||||
return r;
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_VTI_LOCAL attribute: %m");
|
||||
|
||||
r = sd_netlink_message_append_in_addr(m, IFLA_VTI_LOCAL, &t->local.in);
|
||||
r = netlink_message_append_in_addr_union(m, IFLA_VTI_REMOTE, t->family, &t->remote);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m");
|
||||
|
||||
r = sd_netlink_message_append_in_addr(m, IFLA_VTI_REMOTE, &t->remote.in);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int netdev_vti6_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
|
||||
Tunnel *t = VTI6(netdev);
|
||||
int r;
|
||||
|
||||
assert(netdev);
|
||||
assert(m);
|
||||
assert(t);
|
||||
assert(t->family == AF_INET6);
|
||||
|
||||
if (link) {
|
||||
r = sd_netlink_message_append_u32(m, IFLA_VTI_LINK, link->ifindex);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LINK attribute: %m");
|
||||
}
|
||||
|
||||
r = netdev_vti_fill_message_key(netdev, link, m);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_netlink_message_append_in6_addr(m, IFLA_VTI_LOCAL, &t->local.in6);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_LOCAL attribute: %m");
|
||||
|
||||
r = sd_netlink_message_append_in6_addr(m, IFLA_VTI_REMOTE, &t->remote.in6);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_REMOTE attribute: %m");
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_VTI_REMOTE attribute: %m");
|
||||
|
||||
return r;
|
||||
}
|
||||
@ -430,7 +361,7 @@ static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netl
|
||||
if (t->copy_dscp)
|
||||
t->flags |= IP6_TNL_F_RCV_DSCP_COPY;
|
||||
|
||||
if (t->allow_localremote != -1)
|
||||
if (t->allow_localremote >= 0)
|
||||
SET_FLAG(t->flags, IP6_TNL_F_ALLOW_LOCAL_REMOTE, t->allow_localremote);
|
||||
|
||||
if (t->encap_limit != IPV6_DEFAULT_TNL_ENCAP_LIMIT) {
|
||||
@ -458,7 +389,7 @@ static int netdev_ip6tnl_fill_message_create(NetDev *netdev, Link *link, sd_netl
|
||||
|
||||
r = sd_netlink_message_append_u8(m, IFLA_IPTUN_PROTO, proto);
|
||||
if (r < 0)
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_MODE attribute: %m");
|
||||
return log_netdev_error_errno(netdev, r, "Could not append IFLA_IPTUN_PROTO attribute: %m");
|
||||
|
||||
return r;
|
||||
}
|
||||
@ -506,42 +437,27 @@ static int netdev_tunnel_verify(NetDev *netdev, const char *filename) {
|
||||
|
||||
assert(t);
|
||||
|
||||
if (!IN_SET(t->family, AF_INET, AF_INET6, AF_UNSPEC)) {
|
||||
log_netdev_error(netdev,
|
||||
"Tunnel with invalid address family configured in %s. Ignoring", filename);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (IN_SET(netdev->kind, NETDEV_KIND_VTI, NETDEV_KIND_IPIP, NETDEV_KIND_SIT, NETDEV_KIND_GRE, NETDEV_KIND_GRETAP, NETDEV_KIND_ERSPAN) &&
|
||||
(t->family != AF_INET || in_addr_is_null(t->family, &t->local))) {
|
||||
log_netdev_error(netdev,
|
||||
"vti/ipip/sit/gre/gretap/erspan tunnel without a local IPv4 address configured in %s. Ignoring", filename);
|
||||
return -EINVAL;
|
||||
}
|
||||
(t->family != AF_INET || in_addr_is_null(t->family, &t->local)))
|
||||
return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
|
||||
"vti/ipip/sit/gre/gretap/erspan tunnel without a local IPv4 address configured in %s. Ignoring", filename);
|
||||
|
||||
if (IN_SET(netdev->kind, NETDEV_KIND_VTI6, NETDEV_KIND_IP6TNL, NETDEV_KIND_IP6GRE, NETDEV_KIND_IP6GRETAP) &&
|
||||
(t->family != AF_INET6 || in_addr_is_null(t->family, &t->local))) {
|
||||
log_netdev_error(netdev,
|
||||
"vti6/ip6tnl/ip6gre/ip6gretap tunnel without a local IPv6 address configured in %s. Ignoring", filename);
|
||||
return -EINVAL;
|
||||
}
|
||||
(t->family != AF_INET6 || in_addr_is_null(t->family, &t->local)))
|
||||
return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
|
||||
"vti6/ip6tnl/ip6gre/ip6gretap tunnel without a local IPv6 address configured in %s. Ignoring", filename);
|
||||
|
||||
if (netdev->kind == NETDEV_KIND_IP6TNL &&
|
||||
t->ip6tnl_mode == _NETDEV_IP6_TNL_MODE_INVALID) {
|
||||
log_netdev_error(netdev,
|
||||
"ip6tnl without mode configured in %s. Ignoring", filename);
|
||||
return -EINVAL;
|
||||
}
|
||||
t->ip6tnl_mode == _NETDEV_IP6_TNL_MODE_INVALID)
|
||||
return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
|
||||
"ip6tnl without mode configured in %s. Ignoring", filename);
|
||||
|
||||
if (t->fou_tunnel && t->fou_destination_port <= 0) {
|
||||
log_netdev_error(netdev, "FooOverUDP missing port configured in %s. Ignoring", filename);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (t->fou_tunnel && t->fou_destination_port <= 0)
|
||||
return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
|
||||
"FooOverUDP missing port configured in %s. Ignoring", filename);
|
||||
|
||||
if (netdev->kind == NETDEV_KIND_ERSPAN && (t->erspan_index >= (1 << 20) || t->erspan_index == 0)) {
|
||||
log_netdev_error(netdev, "Invalid erspan index %d. Ignoring", t->erspan_index);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (netdev->kind == NETDEV_KIND_ERSPAN && (t->erspan_index >= (1 << 20) || t->erspan_index == 0))
|
||||
return log_netdev_error_errno(netdev, SYNTHETIC_ERRNO(EINVAL), "Invalid erspan index %d. Ignoring", t->erspan_index);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -578,8 +494,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;
|
||||
}
|
||||
@ -849,7 +765,7 @@ const NetDevVTable ipip_vtable = {
|
||||
.object_size = sizeof(Tunnel),
|
||||
.init = ipip_init,
|
||||
.sections = "Match\0NetDev\0Tunnel\0",
|
||||
.fill_message_create = netdev_ipip_fill_message_create,
|
||||
.fill_message_create = netdev_ipip_sit_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
.config_verify = netdev_tunnel_verify,
|
||||
};
|
||||
@ -858,7 +774,7 @@ const NetDevVTable sit_vtable = {
|
||||
.object_size = sizeof(Tunnel),
|
||||
.init = sit_init,
|
||||
.sections = "Match\0NetDev\0Tunnel\0",
|
||||
.fill_message_create = netdev_sit_fill_message_create,
|
||||
.fill_message_create = netdev_ipip_sit_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
.config_verify = netdev_tunnel_verify,
|
||||
};
|
||||
@ -876,7 +792,7 @@ const NetDevVTable vti6_vtable = {
|
||||
.object_size = sizeof(Tunnel),
|
||||
.init = vti_init,
|
||||
.sections = "Match\0NetDev\0Tunnel\0",
|
||||
.fill_message_create = netdev_vti6_fill_message_create,
|
||||
.fill_message_create = netdev_vti_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
.config_verify = netdev_tunnel_verify,
|
||||
};
|
||||
|
@ -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");
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "alloc-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "netlink-util.h"
|
||||
#include "networkd-link.h"
|
||||
#include "networkd-manager.h"
|
||||
#include "networkd-util.h"
|
||||
@ -62,10 +63,7 @@ static int wireguard_set_ipmask_one(NetDev *netdev, sd_netlink_message *message,
|
||||
if (r < 0)
|
||||
goto cancel;
|
||||
|
||||
if (mask->family == AF_INET)
|
||||
r = sd_netlink_message_append_in_addr(message, WGALLOWEDIP_A_IPADDR, &mask->ip.in);
|
||||
else if (mask->family == AF_INET6)
|
||||
r = sd_netlink_message_append_in6_addr(message, WGALLOWEDIP_A_IPADDR, &mask->ip.in6);
|
||||
r = netlink_message_append_in_addr_union(message, WGALLOWEDIP_A_IPADDR, mask->family, &mask->ip);
|
||||
if (r < 0)
|
||||
goto cancel;
|
||||
|
||||
@ -122,12 +120,11 @@ static int wireguard_set_peer_one(NetDev *netdev, sd_netlink_message *message, c
|
||||
if (r < 0)
|
||||
goto cancel;
|
||||
|
||||
if (peer->endpoint.sa.sa_family == AF_INET)
|
||||
r = sd_netlink_message_append_sockaddr_in(message, WGPEER_A_ENDPOINT, &peer->endpoint.in);
|
||||
else if (peer->endpoint.sa.sa_family == AF_INET6)
|
||||
r = sd_netlink_message_append_sockaddr_in6(message, WGPEER_A_ENDPOINT, &peer->endpoint.in6);
|
||||
if (r < 0)
|
||||
goto cancel;
|
||||
if (IN_SET(peer->endpoint.sa.sa_family, AF_INET, AF_INET6)) {
|
||||
r = netlink_message_append_sockaddr_union(message, WGPEER_A_ENDPOINT, &peer->endpoint);
|
||||
if (r < 0)
|
||||
goto cancel;
|
||||
}
|
||||
}
|
||||
|
||||
r = sd_netlink_message_open_container(message, WGPEER_A_ALLOWEDIPS);
|
||||
|
@ -469,10 +469,7 @@ int address_remove(
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not set prefixlen: %m");
|
||||
|
||||
if (address->family == AF_INET)
|
||||
r = sd_netlink_message_append_in_addr(req, IFA_LOCAL, &address->in_addr.in);
|
||||
else if (address->family == AF_INET6)
|
||||
r = sd_netlink_message_append_in6_addr(req, IFA_LOCAL, &address->in_addr.in6);
|
||||
r = netlink_message_append_in_addr_union(req, IFA_LOCAL, address->family, &address->in_addr);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append IFA_LOCAL attribute: %m");
|
||||
|
||||
@ -618,18 +615,12 @@ int address_configure(
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not set scope: %m");
|
||||
|
||||
if (address->family == AF_INET)
|
||||
r = sd_netlink_message_append_in_addr(req, IFA_LOCAL, &address->in_addr.in);
|
||||
else if (address->family == AF_INET6)
|
||||
r = sd_netlink_message_append_in6_addr(req, IFA_LOCAL, &address->in_addr.in6);
|
||||
r = netlink_message_append_in_addr_union(req, IFA_LOCAL, address->family, &address->in_addr);
|
||||
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 (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)
|
||||
r = sd_netlink_message_append_in6_addr(req, IFA_ADDRESS, &address->in_addr_peer.in6);
|
||||
if (in_addr_is_null(address->family, &address->in_addr_peer) == 0) {
|
||||
r = netlink_message_append_in_addr_union(req, IFA_ADDRESS, address->family, &address->in_addr_peer);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append IFA_ADDRESS attribute: %m");
|
||||
} else if (address->family == AF_INET && address->prefixlen <= 30) {
|
||||
|
@ -122,9 +122,8 @@ int config_parse_ipv6_proxy_ndp_address(
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = in_addr_is_null(AF_INET6, &buffer);
|
||||
if (r != 0) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, r,
|
||||
if (in_addr_is_null(AF_INET6, &buffer)) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, 0,
|
||||
"IPv6 proxy NDP address cannot be the ANY address, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
@ -881,9 +881,9 @@ void link_check_ready(Link *link) {
|
||||
|
||||
if (!link->network->bridge) {
|
||||
|
||||
if (link_ipv6ll_enabled(link))
|
||||
if (in_addr_is_null(AF_INET6, (const union in_addr_union*) &link->ipv6ll_address) > 0)
|
||||
return;
|
||||
if (link_ipv6ll_enabled(link) &&
|
||||
in_addr_is_null(AF_INET6, (const union in_addr_union*) &link->ipv6ll_address))
|
||||
return;
|
||||
|
||||
if ((link_dhcp4_enabled(link) && !link_dhcp6_enabled(link) &&
|
||||
!link->dhcp4_configured) ||
|
||||
@ -1734,7 +1734,7 @@ static int link_acquire_conf(Link *link) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (in_addr_is_null(AF_INET6, (const union in_addr_union*) &link->ipv6ll_address) == 0) {
|
||||
if (!in_addr_is_null(AF_INET6, (const union in_addr_union*) &link->ipv6ll_address)) {
|
||||
r = link_acquire_ipv6_conf(link);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
@ -137,20 +137,9 @@ int neighbor_configure(Neighbor *neighbor, Link *link, link_netlink_message_hand
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append NDA_LLADDR attribute: %m");
|
||||
|
||||
switch (neighbor->family) {
|
||||
case AF_INET6:
|
||||
r = sd_netlink_message_append_in6_addr(req, NDA_DST, &neighbor->in_addr.in6);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append NDA_DST attribute: %m");
|
||||
break;
|
||||
case AF_INET:
|
||||
r = sd_netlink_message_append_in_addr(req, NDA_DST, &neighbor->in_addr.in);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append NDA_DST attribute: %m");
|
||||
break;
|
||||
default:
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Neighbor with invalid address family");
|
||||
}
|
||||
r = netlink_message_append_in_addr_union(req, NDA_DST, neighbor->family, &neighbor->in_addr);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append NDA_DST attribute: %m");
|
||||
|
||||
r = netlink_call_async(link->manager->rtnl, NULL, req, callback ?: neighbor_handler,
|
||||
link_netlink_destroy_callback, link);
|
||||
|
@ -857,9 +857,8 @@ int config_parse_ipv6token(
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = in_addr_is_null(AF_INET6, &buffer);
|
||||
if (r != 0) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, r, "IPv6 token cannot be the ANY address, ignoring: %s", rvalue);
|
||||
if (in_addr_is_null(AF_INET6, &buffer)) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, 0, "IPv6 token cannot be the ANY address, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -408,20 +408,14 @@ 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 (route->family == AF_INET)
|
||||
r = sd_netlink_message_append_in_addr(req, RTA_GATEWAY, &route->gw.in);
|
||||
else if (route->family == AF_INET6)
|
||||
r = sd_netlink_message_append_in6_addr(req, RTA_GATEWAY, &route->gw.in6);
|
||||
if (in_addr_is_null(route->family, &route->gw) == 0) {
|
||||
r = netlink_message_append_in_addr_union(req, RTA_GATEWAY, route->family, &route->gw);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_GATEWAY attribute: %m");
|
||||
}
|
||||
|
||||
if (route->dst_prefixlen) {
|
||||
if (route->family == AF_INET)
|
||||
r = sd_netlink_message_append_in_addr(req, RTA_DST, &route->dst.in);
|
||||
else if (route->family == AF_INET6)
|
||||
r = sd_netlink_message_append_in6_addr(req, RTA_DST, &route->dst.in6);
|
||||
r = netlink_message_append_in_addr_union(req, RTA_DST, route->family, &route->dst);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_DST attribute: %m");
|
||||
|
||||
@ -431,10 +425,7 @@ int route_remove(Route *route, Link *link,
|
||||
}
|
||||
|
||||
if (route->src_prefixlen) {
|
||||
if (route->family == AF_INET)
|
||||
r = sd_netlink_message_append_in_addr(req, RTA_SRC, &route->src.in);
|
||||
else if (route->family == AF_INET6)
|
||||
r = sd_netlink_message_append_in6_addr(req, RTA_SRC, &route->src.in6);
|
||||
r = netlink_message_append_in_addr_union(req, RTA_SRC, route->family, &route->src);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_SRC attribute: %m");
|
||||
|
||||
@ -443,11 +434,8 @@ 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 (route->family == AF_INET)
|
||||
r = sd_netlink_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc.in);
|
||||
else if (route->family == AF_INET6)
|
||||
r = sd_netlink_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc.in6);
|
||||
if (in_addr_is_null(route->family, &route->prefsrc) == 0) {
|
||||
r = netlink_message_append_in_addr_union(req, RTA_PREFSRC, route->family, &route->prefsrc);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_PREFSRC attribute: %m");
|
||||
}
|
||||
@ -519,11 +507,8 @@ 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 (route->family == AF_INET)
|
||||
r = sd_netlink_message_append_in_addr(req, RTA_GATEWAY, &route->gw.in);
|
||||
else if (route->family == AF_INET6)
|
||||
r = sd_netlink_message_append_in6_addr(req, RTA_GATEWAY, &route->gw.in6);
|
||||
if (in_addr_is_null(route->family, &route->gw) == 0) {
|
||||
r = netlink_message_append_in_addr_union(req, RTA_GATEWAY, route->family, &route->gw);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_GATEWAY attribute: %m");
|
||||
|
||||
@ -533,10 +518,7 @@ int route_configure(
|
||||
}
|
||||
|
||||
if (route->dst_prefixlen) {
|
||||
if (route->family == AF_INET)
|
||||
r = sd_netlink_message_append_in_addr(req, RTA_DST, &route->dst.in);
|
||||
else if (route->family == AF_INET6)
|
||||
r = sd_netlink_message_append_in6_addr(req, RTA_DST, &route->dst.in6);
|
||||
r = netlink_message_append_in_addr_union(req, RTA_DST, route->family, &route->dst);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_DST attribute: %m");
|
||||
|
||||
@ -546,10 +528,7 @@ int route_configure(
|
||||
}
|
||||
|
||||
if (route->src_prefixlen) {
|
||||
if (route->family == AF_INET)
|
||||
r = sd_netlink_message_append_in_addr(req, RTA_SRC, &route->src.in);
|
||||
else if (route->family == AF_INET6)
|
||||
r = sd_netlink_message_append_in6_addr(req, RTA_SRC, &route->src.in6);
|
||||
r = netlink_message_append_in_addr_union(req, RTA_SRC, route->family, &route->src);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_SRC attribute: %m");
|
||||
|
||||
@ -558,11 +537,8 @@ 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 (route->family == AF_INET)
|
||||
r = sd_netlink_message_append_in_addr(req, RTA_PREFSRC, &route->prefsrc.in);
|
||||
else if (route->family == AF_INET6)
|
||||
r = sd_netlink_message_append_in6_addr(req, RTA_PREFSRC, &route->prefsrc.in6);
|
||||
if (in_addr_is_null(route->family, &route->prefsrc) == 0) {
|
||||
r = netlink_message_append_in_addr_union(req, RTA_PREFSRC, route->family, &route->prefsrc);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append RTA_PREFSRC attribute: %m");
|
||||
}
|
||||
|
@ -369,12 +369,8 @@ 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 (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 (in_addr_is_null(routing_policy_rule->family, &routing_policy_rule->from) == 0) {
|
||||
r = netlink_message_append_in_addr_union(m, FRA_SRC, routing_policy_rule->family, &routing_policy_rule->from);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append FRA_SRC attribute: %m");
|
||||
|
||||
@ -383,12 +379,8 @@ 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 (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 (in_addr_is_null(routing_policy_rule->family, &routing_policy_rule->to) == 0) {
|
||||
r = netlink_message_append_in_addr_union(m, FRA_DST, routing_policy_rule->family, &routing_policy_rule->to);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append FRA_DST attribute: %m");
|
||||
|
||||
@ -496,12 +488,8 @@ 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 (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 (in_addr_is_null(rule->family, &rule->from) == 0) {
|
||||
r = netlink_message_append_in_addr_union(m, FRA_SRC, rule->family, &rule->from);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append FRA_SRC attribute: %m");
|
||||
|
||||
@ -510,12 +498,8 @@ 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 (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 (in_addr_is_null(rule->family, &rule->to) == 0) {
|
||||
r = netlink_message_append_in_addr_union(m, FRA_DST, rule->family, &rule->to);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not append FRA_DST attribute: %m");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user