platform: return pointer to NMPlatformLink object for add functions

Let the link-add functions return the internal pointer to the platform
link object. Similar to link-get, which doesn't copy the link either.

Also adjust the sole users of the add-functions (create-and-realize)
to take the pointer.

Eventually we still copy the returned data, because accessing platform can
invalidate the returned pointer. Thus we don't actually safe any copying
by this (at least every use of the function currently leads to the data
being copied).
Still change it, because I think the API of NMPlatform should look like that.
This commit is contained in:
Thomas Haller
2015-12-09 15:13:57 +01:00
parent 2a14a28fe0
commit a4de9187ff
16 changed files with 92 additions and 90 deletions

View File

@@ -448,7 +448,7 @@ static gboolean
create_and_realize (NMDevice *device, create_and_realize (NMDevice *device,
NMConnection *connection, NMConnection *connection,
NMDevice *parent, NMDevice *parent,
NMPlatformLink *out_plink, const NMPlatformLink **out_plink,
GError **error) GError **error)
{ {
const char *iface = nm_device_get_iface (device); const char *iface = nm_device_get_iface (device);

View File

@@ -377,7 +377,7 @@ static gboolean
create_and_realize (NMDevice *device, create_and_realize (NMDevice *device,
NMConnection *connection, NMConnection *connection,
NMDevice *parent, NMDevice *parent,
NMPlatformLink *out_plink, const NMPlatformLink **out_plink,
GError **error) GError **error)
{ {
NMSettingBridge *s_bridge; NMSettingBridge *s_bridge;
@@ -387,7 +387,6 @@ create_and_realize (NMDevice *device,
NMPlatformError plerr; NMPlatformError plerr;
g_assert (iface); g_assert (iface);
g_assert (out_plink);
s_bridge = nm_connection_get_setting_bridge (connection); s_bridge = nm_connection_get_setting_bridge (connection);
g_assert (s_bridge); g_assert (s_bridge);

View File

@@ -236,15 +236,13 @@ static gboolean
create_and_realize (NMDevice *device, create_and_realize (NMDevice *device,
NMConnection *connection, NMConnection *connection,
NMDevice *parent, NMDevice *parent,
NMPlatformLink *out_plink, const NMPlatformLink **out_plink,
GError **error) GError **error)
{ {
NMSettingInfiniband *s_infiniband; NMSettingInfiniband *s_infiniband;
int parent_ifindex, p_key; int parent_ifindex, p_key;
NMPlatformError plerr; NMPlatformError plerr;
g_assert (out_plink);
if (!NM_IS_DEVICE_INFINIBAND (parent)) { if (!NM_IS_DEVICE_INFINIBAND (parent)) {
g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED, g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_CREATION_FAILED,
"Parent interface %s must be an InfiniBand interface", "Parent interface %s must be an InfiniBand interface",

View File

@@ -613,7 +613,7 @@ static gboolean
create_and_realize (NMDevice *device, create_and_realize (NMDevice *device,
NMConnection *connection, NMConnection *connection,
NMDevice *parent, NMDevice *parent,
NMPlatformLink *out_plink, const NMPlatformLink **out_plink,
GError **error) GError **error)
{ {
const char *iface = nm_device_get_iface (device); const char *iface = nm_device_get_iface (device);
@@ -628,7 +628,6 @@ create_and_realize (NMDevice *device,
s_ip_tunnel = nm_connection_get_setting_ip_tunnel (connection); s_ip_tunnel = nm_connection_get_setting_ip_tunnel (connection);
g_assert (s_ip_tunnel); g_assert (s_ip_tunnel);
g_assert (out_plink);
switch (nm_setting_ip_tunnel_get_mode (s_ip_tunnel)) { switch (nm_setting_ip_tunnel_get_mode (s_ip_tunnel)) {
case NM_IP_TUNNEL_MODE_GRE: case NM_IP_TUNNEL_MODE_GRE:

View File

@@ -220,7 +220,7 @@ static gboolean
create_and_realize (NMDevice *device, create_and_realize (NMDevice *device,
NMConnection *connection, NMConnection *connection,
NMDevice *parent, NMDevice *parent,
NMPlatformLink *out_plink, const NMPlatformLink **out_plink,
GError **error) GError **error)
{ {
const char *iface = nm_device_get_iface (device); const char *iface = nm_device_get_iface (device);
@@ -231,7 +231,6 @@ create_and_realize (NMDevice *device,
s_macvlan = nm_connection_get_setting_macvlan (connection); s_macvlan = nm_connection_get_setting_macvlan (connection);
g_assert (s_macvlan); g_assert (s_macvlan);
g_assert (out_plink);
parent_ifindex = nm_device_get_ifindex (parent); parent_ifindex = nm_device_get_ifindex (parent);
g_warn_if_fail (parent_ifindex > 0); g_warn_if_fail (parent_ifindex > 0);

View File

@@ -199,7 +199,7 @@ static gboolean
create_and_realize (NMDevice *device, create_and_realize (NMDevice *device,
NMConnection *connection, NMConnection *connection,
NMDevice *parent, NMDevice *parent,
NMPlatformLink *out_plink, const NMPlatformLink **out_plink,
GError **error) GError **error)
{ {
const char *iface = nm_device_get_iface (device); const char *iface = nm_device_get_iface (device);
@@ -209,7 +209,6 @@ create_and_realize (NMDevice *device,
s_tun = nm_connection_get_setting_tun (connection); s_tun = nm_connection_get_setting_tun (connection);
g_assert (s_tun); g_assert (s_tun);
g_assert (out_plink);
user = _nm_utils_ascii_str_to_int64 (nm_setting_tun_get_owner (s_tun), 10, 0, G_MAXINT32, -1); user = _nm_utils_ascii_str_to_int64 (nm_setting_tun_get_owner (s_tun), 10, 0, G_MAXINT32, -1);
group = _nm_utils_ascii_str_to_int64 (nm_setting_tun_get_group (s_tun), 10, 0, G_MAXINT32, -1); group = _nm_utils_ascii_str_to_int64 (nm_setting_tun_get_group (s_tun), 10, 0, G_MAXINT32, -1);

View File

@@ -207,7 +207,7 @@ static gboolean
create_and_realize (NMDevice *device, create_and_realize (NMDevice *device,
NMConnection *connection, NMConnection *connection,
NMDevice *parent, NMDevice *parent,
NMPlatformLink *out_plink, const NMPlatformLink **out_plink,
GError **error) GError **error)
{ {
NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (device); NMDeviceVlanPrivate *priv = NM_DEVICE_VLAN_GET_PRIVATE (device);
@@ -216,8 +216,6 @@ create_and_realize (NMDevice *device,
int parent_ifindex, vlan_id; int parent_ifindex, vlan_id;
NMPlatformError plerr; NMPlatformError plerr;
g_assert (out_plink);
s_vlan = nm_connection_get_setting_vlan (connection); s_vlan = nm_connection_get_setting_vlan (connection);
g_assert (s_vlan); g_assert (s_vlan);

View File

@@ -174,7 +174,7 @@ static gboolean
create_and_realize (NMDevice *device, create_and_realize (NMDevice *device,
NMConnection *connection, NMConnection *connection,
NMDevice *parent, NMDevice *parent,
NMPlatformLink *out_plink, const NMPlatformLink **out_plink,
GError **error) GError **error)
{ {
const char *iface = nm_device_get_iface (device); const char *iface = nm_device_get_iface (device);
@@ -186,7 +186,6 @@ create_and_realize (NMDevice *device,
s_vxlan = nm_connection_get_setting_vxlan (connection); s_vxlan = nm_connection_get_setting_vxlan (connection);
g_assert (s_vxlan); g_assert (s_vxlan);
g_assert (out_plink);
if (parent) if (parent)
props.parent_ifindex = nm_device_get_ifindex (parent); props.parent_ifindex = nm_device_get_ifindex (parent);

View File

@@ -1761,7 +1761,8 @@ nm_device_create_and_realize (NMDevice *self,
GError **error) GError **error)
{ {
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
NMPlatformLink plink = { .type = NM_LINK_TYPE_NONE }; NMPlatformLink plink_copy;
const NMPlatformLink *plink = NULL;
/* Must be set before device is realized */ /* Must be set before device is realized */
priv->is_nm_owned = !nm_platform_link_get_by_ifname (NM_PLATFORM_GET, priv->iface); priv->is_nm_owned = !nm_platform_link_get_by_ifname (NM_PLATFORM_GET, priv->iface);
@@ -1770,10 +1771,12 @@ nm_device_create_and_realize (NMDevice *self,
if (NM_DEVICE_GET_CLASS (self)->create_and_realize) { if (NM_DEVICE_GET_CLASS (self)->create_and_realize) {
if (!NM_DEVICE_GET_CLASS (self)->create_and_realize (self, connection, parent, &plink, error)) if (!NM_DEVICE_GET_CLASS (self)->create_and_realize (self, connection, parent, &plink, error))
return FALSE; return FALSE;
plink_copy = *plink;
plink = &plink_copy;
} }
NM_DEVICE_GET_CLASS (self)->setup_start (self, (plink.type != NM_LINK_TYPE_NONE) ? &plink : NULL); NM_DEVICE_GET_CLASS (self)->setup_start (self, plink);
nm_device_setup_finish (self, (plink.type != NM_LINK_TYPE_NONE) ? &plink : NULL); nm_device_setup_finish (self, plink);
g_return_val_if_fail (nm_device_check_connection_compatible (self, connection), TRUE); g_return_val_if_fail (nm_device_check_connection_compatible (self, connection), TRUE);
return TRUE; return TRUE;

View File

@@ -170,7 +170,9 @@ typedef struct {
* @self: the #NMDevice * @self: the #NMDevice
* @connection: the #NMConnection being activated * @connection: the #NMConnection being activated
* @parent: the parent #NMDevice, if any * @parent: the parent #NMDevice, if any
* @out_plink: on success, a backing kernel network device if one exists * @out_plink: on success, a backing kernel network device if one exists.
* The returned pointer is owned by platform and only valid until the
* next platform operation.
* @error: location to store error, or %NULL * @error: location to store error, or %NULL
* *
* Create any backing resources (kernel devices, etc) required for this * Create any backing resources (kernel devices, etc) required for this
@@ -183,7 +185,7 @@ typedef struct {
gboolean (*create_and_realize) (NMDevice *self, gboolean (*create_and_realize) (NMDevice *self,
NMConnection *connection, NMConnection *connection,
NMDevice *parent, NMDevice *parent,
NMPlatformLink *out_plink, const NMPlatformLink **out_plink,
GError **error); GError **error);
/** /**

View File

@@ -673,7 +673,7 @@ static gboolean
create_and_realize (NMDevice *device, create_and_realize (NMDevice *device,
NMConnection *connection, NMConnection *connection,
NMDevice *parent, NMDevice *parent,
NMPlatformLink *out_plink, const NMPlatformLink **out_plink,
GError **error) GError **error)
{ {
const char *iface = nm_device_get_iface (device); const char *iface = nm_device_get_iface (device);

View File

@@ -292,10 +292,11 @@ link_add (NMPlatform *platform,
NMLinkType type, NMLinkType type,
const void *address, const void *address,
size_t address_len, size_t address_len,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform); NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
NMFakePlatformLink device; NMFakePlatformLink device;
NMFakePlatformLink *new_device;
link_init (&device, priv->links->len, type, name); link_init (&device, priv->links->len, type, name);
@@ -306,6 +307,7 @@ link_add (NMPlatform *platform,
} }
g_array_append_val (priv->links, device); g_array_append_val (priv->links, device);
new_device = &g_array_index (priv->links, NMFakePlatformLink, priv->links->len - 1);
if (device.link.ifindex) { if (device.link.ifindex) {
g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_LINK_CHANGED, NMP_OBJECT_TYPE_LINK, device.link.ifindex, &device, NM_PLATFORM_SIGNAL_ADDED); g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_LINK_CHANGED, NMP_OBJECT_TYPE_LINK, device.link.ifindex, &device, NM_PLATFORM_SIGNAL_ADDED);
@@ -314,7 +316,7 @@ link_add (NMPlatform *platform,
} }
if (out_link) if (out_link)
*out_link = device.link; *out_link = &new_device->link;
return TRUE; return TRUE;
} }
@@ -672,11 +674,11 @@ slave_get_option (NMPlatform *platform, int slave, const char *option)
} }
static gboolean static gboolean
vlan_add (NMPlatform *platform, const char *name, int parent, int vlan_id, guint32 vlan_flags, NMPlatformLink *out_link) vlan_add (NMPlatform *platform, const char *name, int parent, int vlan_id, guint32 vlan_flags, const NMPlatformLink **out_link)
{ {
NMFakePlatformLink *device; NMFakePlatformLink *device;
if (!link_add (platform, name, NM_LINK_TYPE_VLAN, NULL, 0, NULL)) if (!link_add (platform, name, NM_LINK_TYPE_VLAN, NULL, 0, out_link))
return FALSE; return FALSE;
device = link_get (platform, nm_platform_link_get_ifindex (platform, name)); device = link_get (platform, nm_platform_link_get_ifindex (platform, name));
@@ -689,7 +691,7 @@ vlan_add (NMPlatform *platform, const char *name, int parent, int vlan_id, guint
device->link.parent = parent; device->link.parent = parent;
if (out_link) if (out_link)
*out_link = device->link; *out_link = &device->link;
return TRUE; return TRUE;
} }
@@ -712,11 +714,11 @@ static gboolean
link_vxlan_add (NMPlatform *platform, link_vxlan_add (NMPlatform *platform,
const char *name, const char *name,
NMPlatformLnkVxlan *props, NMPlatformLnkVxlan *props,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
NMFakePlatformLink *device; NMFakePlatformLink *device;
if (!link_add (platform, name, NM_LINK_TYPE_VXLAN, NULL, 0, NULL)) if (!link_add (platform, name, NM_LINK_TYPE_VXLAN, NULL, 0, out_link))
return FALSE; return FALSE;
device = link_get (platform, nm_platform_link_get_ifindex (platform, name)); device = link_get (platform, nm_platform_link_get_ifindex (platform, name));
@@ -729,12 +731,12 @@ link_vxlan_add (NMPlatform *platform,
device->link.parent = props->parent_ifindex; device->link.parent = props->parent_ifindex;
if (out_link) if (out_link)
*out_link = device->link; *out_link = &device->link;
return TRUE; return TRUE;
} }
static gboolean static gboolean
infiniband_partition_add (NMPlatform *platform, int parent, int p_key, NMPlatformLink *out_link) infiniband_partition_add (NMPlatform *platform, int parent, int p_key, const NMPlatformLink **out_link)
{ {
NMFakePlatformLink *device, *parent_device; NMFakePlatformLink *device, *parent_device;
gs_free char *name = NULL; gs_free char *name = NULL;

View File

@@ -3592,7 +3592,7 @@ do_add_link_with_lookup (NMPlatform *platform,
NMLinkType link_type, NMLinkType link_type,
const char *name, const char *name,
struct nl_msg *nlmsg, struct nl_msg *nlmsg,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
const NMPObject *obj; const NMPObject *obj;
@@ -3600,8 +3600,8 @@ do_add_link_with_lookup (NMPlatform *platform,
obj = nmp_cache_lookup_link_full (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache, obj = nmp_cache_lookup_link_full (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache,
0, name, FALSE, link_type, NULL, NULL); 0, name, FALSE, link_type, NULL, NULL);
if (out_link && obj) if (out_link)
*out_link = obj->link; *out_link = obj ? &obj->link : NULL;
return !!obj; return !!obj;
} }
@@ -3801,7 +3801,7 @@ link_add (NMPlatform *platform,
NMLinkType type, NMLinkType type,
const void *address, const void *address,
size_t address_len, size_t address_len,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
nm_auto_nlmsg struct nl_msg *nlmsg = NULL; nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
@@ -4160,7 +4160,7 @@ vlan_add (NMPlatform *platform,
int parent, int parent,
int vlan_id, int vlan_id,
guint32 vlan_flags, guint32 vlan_flags,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
nm_auto_nlmsg struct nl_msg *nlmsg = NULL; nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
@@ -4204,7 +4204,7 @@ static int
link_gre_add (NMPlatform *platform, link_gre_add (NMPlatform *platform,
const char *name, const char *name,
NMPlatformLnkGre *props, NMPlatformLnkGre *props,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
nm_auto_nlmsg struct nl_msg *nlmsg = NULL; nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
struct nlattr *info; struct nlattr *info;
@@ -4259,7 +4259,7 @@ static int
link_ip6tnl_add (NMPlatform *platform, link_ip6tnl_add (NMPlatform *platform,
const char *name, const char *name,
NMPlatformLnkIp6Tnl *props, NMPlatformLnkIp6Tnl *props,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
nm_auto_nlmsg struct nl_msg *nlmsg = NULL; nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
struct nlattr *info; struct nlattr *info;
@@ -4320,7 +4320,7 @@ static int
link_ipip_add (NMPlatform *platform, link_ipip_add (NMPlatform *platform,
const char *name, const char *name,
NMPlatformLnkIpIp *props, NMPlatformLnkIpIp *props,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
nm_auto_nlmsg struct nl_msg *nlmsg = NULL; nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
struct nlattr *info; struct nlattr *info;
@@ -4372,7 +4372,7 @@ link_macvlan_add (NMPlatform *platform,
const char *name, const char *name,
int parent, int parent,
NMPlatformLnkMacvlan *props, NMPlatformLnkMacvlan *props,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
nm_auto_nlmsg struct nl_msg *nlmsg = NULL; nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
struct nlattr *info; struct nlattr *info;
@@ -4420,7 +4420,7 @@ static int
link_sit_add (NMPlatform *platform, link_sit_add (NMPlatform *platform,
const char *name, const char *name,
NMPlatformLnkSit *props, NMPlatformLnkSit *props,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
nm_auto_nlmsg struct nl_msg *nlmsg = NULL; nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
struct nlattr *info; struct nlattr *info;
@@ -4471,7 +4471,7 @@ static gboolean
link_vxlan_add (NMPlatform *platform, link_vxlan_add (NMPlatform *platform,
const char *name, const char *name,
NMPlatformLnkVxlan *props, NMPlatformLnkVxlan *props,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
nm_auto_nlmsg struct nl_msg *nlmsg = NULL; nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
struct nlattr *info; struct nlattr *info;
@@ -4714,7 +4714,7 @@ link_vlan_change (NMPlatform *platform,
static int static int
tun_add (NMPlatform *platform, const char *name, gboolean tap, tun_add (NMPlatform *platform, const char *name, gboolean tap,
gint64 owner, gint64 group, gboolean pi, gboolean vnet_hdr, gint64 owner, gint64 group, gboolean pi, gboolean vnet_hdr,
gboolean multi_queue, NMPlatformLink *out_link) gboolean multi_queue, const NMPlatformLink **out_link)
{ {
const NMPObject *obj; const NMPObject *obj;
struct ifreq ifr = { }; struct ifreq ifr = { };
@@ -4765,8 +4765,8 @@ tun_add (NMPlatform *platform, const char *name, gboolean tap,
0, name, FALSE, 0, name, FALSE,
tap ? NM_LINK_TYPE_TAP : NM_LINK_TYPE_TUN, tap ? NM_LINK_TYPE_TAP : NM_LINK_TYPE_TUN,
NULL, NULL); NULL, NULL);
if (out_link && obj) if (out_link)
*out_link = obj->link; *out_link = obj ? &obj->link : NULL;
return !!obj; return !!obj;
} }
@@ -4887,7 +4887,7 @@ slave_get_option (NMPlatform *platform, int slave, const char *option)
/******************************************************************/ /******************************************************************/
static gboolean static gboolean
infiniband_partition_add (NMPlatform *platform, int parent, int p_key, NMPlatformLink *out_link) infiniband_partition_add (NMPlatform *platform, int parent, int p_key, const NMPlatformLink **out_link)
{ {
NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform); NMLinuxPlatformPrivate *priv = NM_LINUX_PLATFORM_GET_PRIVATE (platform);
const NMPObject *obj_parent; const NMPObject *obj_parent;
@@ -4911,8 +4911,8 @@ infiniband_partition_add (NMPlatform *platform, int parent, int p_key, NMPlatfor
obj = nmp_cache_lookup_link_full (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache, obj = nmp_cache_lookup_link_full (NM_LINUX_PLATFORM_GET_PRIVATE (platform)->cache,
0, ifname, FALSE, NM_LINK_TYPE_INFINIBAND, NULL, NULL); 0, ifname, FALSE, NM_LINK_TYPE_INFINIBAND, NULL, NULL);
if (out_link && obj) if (out_link)
*out_link = obj->link; *out_link = obj ? &obj->link : NULL;
return !!obj; return !!obj;
} }

View File

@@ -571,7 +571,7 @@ nm_platform_link_get_by_address (NMPlatform *self,
} }
static NMPlatformError static NMPlatformError
_link_add_check_existing (NMPlatform *self, const char *name, NMLinkType type, NMPlatformLink *out_link) _link_add_check_existing (NMPlatform *self, const char *name, NMLinkType type, const NMPlatformLink **out_link)
{ {
const NMPlatformLink *pllink; const NMPlatformLink *pllink;
@@ -586,11 +586,13 @@ _link_add_check_existing (NMPlatform *self, const char *name, NMLinkType type, N
wrong_type ? ", expected " : "", wrong_type ? ", expected " : "",
wrong_type ? nm_link_type_to_string (type) : ""); wrong_type ? nm_link_type_to_string (type) : "");
if (out_link) if (out_link)
*out_link = *pllink; *out_link = pllink;
if (wrong_type) if (wrong_type)
return NM_PLATFORM_ERROR_WRONG_TYPE; return NM_PLATFORM_ERROR_WRONG_TYPE;
return NM_PLATFORM_ERROR_EXISTS; return NM_PLATFORM_ERROR_EXISTS;
} }
if (out_link)
*out_link = NULL;
return NM_PLATFORM_ERROR_SUCCESS; return NM_PLATFORM_ERROR_SUCCESS;
} }
@@ -619,7 +621,7 @@ nm_platform_link_add (NMPlatform *self,
NMLinkType type, NMLinkType type,
const void *address, const void *address,
size_t address_len, size_t address_len,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
NMPlatformError plerr; NMPlatformError plerr;
@@ -648,7 +650,7 @@ nm_platform_link_add (NMPlatform *self,
* Create a software ethernet-like interface * Create a software ethernet-like interface
*/ */
NMPlatformError NMPlatformError
nm_platform_dummy_add (NMPlatform *self, const char *name, NMPlatformLink *out_link) nm_platform_dummy_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link)
{ {
return nm_platform_link_add (self, name, NM_LINK_TYPE_DUMMY, NULL, 0, out_link); return nm_platform_link_add (self, name, NM_LINK_TYPE_DUMMY, NULL, 0, out_link);
} }
@@ -1488,7 +1490,7 @@ nm_platform_bridge_add (NMPlatform *self,
const char *name, const char *name,
const void *address, const void *address,
size_t address_len, size_t address_len,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
return nm_platform_link_add (self, name, NM_LINK_TYPE_BRIDGE, address, address_len, out_link); return nm_platform_link_add (self, name, NM_LINK_TYPE_BRIDGE, address, address_len, out_link);
} }
@@ -1502,7 +1504,7 @@ nm_platform_bridge_add (NMPlatform *self,
* Create a software bonding device. * Create a software bonding device.
*/ */
NMPlatformError NMPlatformError
nm_platform_bond_add (NMPlatform *self, const char *name, NMPlatformLink *out_link) nm_platform_bond_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link)
{ {
return nm_platform_link_add (self, name, NM_LINK_TYPE_BOND, NULL, 0, out_link); return nm_platform_link_add (self, name, NM_LINK_TYPE_BOND, NULL, 0, out_link);
} }
@@ -1516,7 +1518,7 @@ nm_platform_bond_add (NMPlatform *self, const char *name, NMPlatformLink *out_li
* Create a software teaming device. * Create a software teaming device.
*/ */
NMPlatformError NMPlatformError
nm_platform_team_add (NMPlatform *self, const char *name, NMPlatformLink *out_link) nm_platform_team_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link)
{ {
return nm_platform_link_add (self, name, NM_LINK_TYPE_TEAM, NULL, 0, out_link); return nm_platform_link_add (self, name, NM_LINK_TYPE_TEAM, NULL, 0, out_link);
} }
@@ -1537,7 +1539,7 @@ nm_platform_vlan_add (NMPlatform *self,
int parent, int parent,
int vlanid, int vlanid,
guint32 vlanflags, guint32 vlanflags,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
NMPlatformError plerr; NMPlatformError plerr;
@@ -1572,7 +1574,7 @@ NMPlatformError
nm_platform_link_vxlan_add (NMPlatform *self, nm_platform_link_vxlan_add (NMPlatform *self,
const char *name, const char *name,
NMPlatformLnkVxlan *props, NMPlatformLnkVxlan *props,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
NMPlatformError plerr; NMPlatformError plerr;
@@ -1608,7 +1610,7 @@ nm_platform_link_vxlan_add (NMPlatform *self,
NMPlatformError NMPlatformError
nm_platform_tun_add (NMPlatform *self, const char *name, gboolean tap, nm_platform_tun_add (NMPlatform *self, const char *name, gboolean tap,
gint64 owner, gint64 group, gboolean pi, gboolean vnet_hdr, gint64 owner, gint64 group, gboolean pi, gboolean vnet_hdr,
gboolean multi_queue, NMPlatformLink *out_link) gboolean multi_queue, const NMPlatformLink **out_link)
{ {
NMPlatformError plerr; NMPlatformError plerr;
@@ -1779,7 +1781,7 @@ NMPlatformError
nm_platform_link_gre_add (NMPlatform *self, nm_platform_link_gre_add (NMPlatform *self,
const char *name, const char *name,
NMPlatformLnkGre *props, NMPlatformLnkGre *props,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
NMPlatformError plerr; NMPlatformError plerr;
char buffer[INET_ADDRSTRLEN]; char buffer[INET_ADDRSTRLEN];
@@ -1806,7 +1808,7 @@ nm_platform_link_gre_add (NMPlatform *self,
} }
NMPlatformError NMPlatformError
nm_platform_infiniband_partition_add (NMPlatform *self, int parent, int p_key, NMPlatformLink *out_link) nm_platform_infiniband_partition_add (NMPlatform *self, int parent, int p_key, const NMPlatformLink **out_link)
{ {
gs_free char *parent_name = NULL; gs_free char *parent_name = NULL;
gs_free char *name = NULL; gs_free char *name = NULL;
@@ -1915,7 +1917,7 @@ NMPlatformError
nm_platform_link_ip6tnl_add (NMPlatform *self, nm_platform_link_ip6tnl_add (NMPlatform *self,
const char *name, const char *name,
NMPlatformLnkIp6Tnl *props, NMPlatformLnkIp6Tnl *props,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
NMPlatformError plerr; NMPlatformError plerr;
char buffer[INET6_ADDRSTRLEN]; char buffer[INET6_ADDRSTRLEN];
@@ -1954,7 +1956,7 @@ NMPlatformError
nm_platform_link_ipip_add (NMPlatform *self, nm_platform_link_ipip_add (NMPlatform *self,
const char *name, const char *name,
NMPlatformLnkIpIp *props, NMPlatformLnkIpIp *props,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
NMPlatformError plerr; NMPlatformError plerr;
char buffer[INET_ADDRSTRLEN]; char buffer[INET_ADDRSTRLEN];
@@ -1994,7 +1996,7 @@ nm_platform_link_macvlan_add (NMPlatform *self,
const char *name, const char *name,
int parent, int parent,
NMPlatformLnkMacvlan *props, NMPlatformLnkMacvlan *props,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
NMPlatformError plerr; NMPlatformError plerr;
NMLinkType type; NMLinkType type;
@@ -2034,7 +2036,7 @@ NMPlatformError
nm_platform_link_sit_add (NMPlatform *self, nm_platform_link_sit_add (NMPlatform *self,
const char *name, const char *name,
NMPlatformLnkSit *props, NMPlatformLnkSit *props,
NMPlatformLink *out_link) const NMPlatformLink **out_link)
{ {
NMPlatformError plerr; NMPlatformError plerr;
char buffer[INET_ADDRSTRLEN]; char buffer[INET_ADDRSTRLEN];

View File

@@ -506,7 +506,7 @@ typedef struct {
NMLinkType type, NMLinkType type,
const void *address, const void *address,
size_t address_len, size_t address_len,
NMPlatformLink *out_link); const NMPlatformLink **out_link);
gboolean (*link_delete) (NMPlatform *, int ifindex); gboolean (*link_delete) (NMPlatform *, int ifindex);
const char *(*link_get_type_name) (NMPlatform *, int ifindex); const char *(*link_get_type_name) (NMPlatform *, int ifindex);
gboolean (*link_get_unmanaged) (NMPlatform *, int ifindex, gboolean *unmanaged); gboolean (*link_get_unmanaged) (NMPlatform *, int ifindex, gboolean *unmanaged);
@@ -550,7 +550,7 @@ typedef struct {
gboolean (*slave_set_option) (NMPlatform *, int ifindex, const char *option, const char *value); gboolean (*slave_set_option) (NMPlatform *, int ifindex, const char *option, const char *value);
char * (*slave_get_option) (NMPlatform *, int ifindex, const char *option); char * (*slave_get_option) (NMPlatform *, int ifindex, const char *option);
gboolean (*vlan_add) (NMPlatform *, const char *name, int parent, int vlanid, guint32 vlanflags, NMPlatformLink *out_link); gboolean (*vlan_add) (NMPlatform *, const char *name, int parent, int vlanid, guint32 vlanflags, const NMPlatformLink **out_link);
gboolean (*link_vlan_change) (NMPlatform *self, gboolean (*link_vlan_change) (NMPlatform *self,
int ifindex, int ifindex,
NMVlanFlags flags_mask, NMVlanFlags flags_mask,
@@ -562,23 +562,23 @@ typedef struct {
const NMVlanQosMapping *egress_map, const NMVlanQosMapping *egress_map,
gsize n_egress_map); gsize n_egress_map);
gboolean (*link_vxlan_add) (NMPlatform *, const char *name, NMPlatformLnkVxlan *props, gboolean (*link_vxlan_add) (NMPlatform *, const char *name, NMPlatformLnkVxlan *props,
NMPlatformLink *out_link); const NMPlatformLink **out_link);
gboolean (*link_gre_add) (NMPlatform *, const char *name, NMPlatformLnkGre *props, gboolean (*link_gre_add) (NMPlatform *, const char *name, NMPlatformLnkGre *props,
NMPlatformLink *out_link); const NMPlatformLink **out_link);
gboolean (*link_ip6tnl_add) (NMPlatform *, const char *name, NMPlatformLnkIp6Tnl *props, gboolean (*link_ip6tnl_add) (NMPlatform *, const char *name, NMPlatformLnkIp6Tnl *props,
NMPlatformLink *out_link); const NMPlatformLink **out_link);
gboolean (*link_ipip_add) (NMPlatform *, const char *name, NMPlatformLnkIpIp *props, gboolean (*link_ipip_add) (NMPlatform *, const char *name, NMPlatformLnkIpIp *props,
NMPlatformLink *out_link); const NMPlatformLink **out_link);
gboolean (*link_macvlan_add) (NMPlatform *, const char *name, int parent, NMPlatformLnkMacvlan *props, gboolean (*link_macvlan_add) (NMPlatform *, const char *name, int parent, NMPlatformLnkMacvlan *props,
NMPlatformLink *out_link); const NMPlatformLink **out_link);
gboolean (*link_sit_add) (NMPlatform *, const char *name, NMPlatformLnkSit *props, gboolean (*link_sit_add) (NMPlatform *, const char *name, NMPlatformLnkSit *props,
NMPlatformLink *out_link); const NMPlatformLink **out_link);
gboolean (*infiniband_partition_add) (NMPlatform *, int parent, int p_key, NMPlatformLink *out_link); gboolean (*infiniband_partition_add) (NMPlatform *, int parent, int p_key, const NMPlatformLink **out_link);
gboolean (*tun_add) (NMPlatform *platform, const char *name, gboolean tap, gint64 owner, gint64 group, gboolean pi, gboolean (*tun_add) (NMPlatform *platform, const char *name, gboolean tap, gint64 owner, gint64 group, gboolean pi,
gboolean vnet_hdr, gboolean multi_queue, NMPlatformLink *out_link); gboolean vnet_hdr, gboolean multi_queue, const NMPlatformLink **out_link);
gboolean (*wifi_get_capabilities) (NMPlatform *, int ifindex, NMDeviceWifiCapabilities *caps); gboolean (*wifi_get_capabilities) (NMPlatform *, int ifindex, NMDeviceWifiCapabilities *caps);
gboolean (*wifi_get_bssid) (NMPlatform *, int ifindex, guint8 *bssid); gboolean (*wifi_get_bssid) (NMPlatform *, int ifindex, guint8 *bssid);
@@ -700,10 +700,10 @@ const NMPlatformLink *nm_platform_link_get_by_ifname (NMPlatform *self, const ch
const NMPlatformLink *nm_platform_link_get_by_address (NMPlatform *self, gconstpointer address, size_t length); const NMPlatformLink *nm_platform_link_get_by_address (NMPlatform *self, gconstpointer address, size_t length);
GArray *nm_platform_link_get_all (NMPlatform *self); GArray *nm_platform_link_get_all (NMPlatform *self);
NMPlatformError nm_platform_dummy_add (NMPlatform *self, const char *name, NMPlatformLink *out_link); NMPlatformError nm_platform_dummy_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link);
NMPlatformError nm_platform_bridge_add (NMPlatform *self, const char *name, const void *address, size_t address_len, NMPlatformLink *out_link); NMPlatformError nm_platform_bridge_add (NMPlatform *self, const char *name, const void *address, size_t address_len, const NMPlatformLink **out_link);
NMPlatformError nm_platform_bond_add (NMPlatform *self, const char *name, NMPlatformLink *out_link); NMPlatformError nm_platform_bond_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link);
NMPlatformError nm_platform_team_add (NMPlatform *self, const char *name, NMPlatformLink *out_link); NMPlatformError nm_platform_team_add (NMPlatform *self, const char *name, const NMPlatformLink **out_link);
gboolean nm_platform_link_delete (NMPlatform *self, int ifindex); gboolean nm_platform_link_delete (NMPlatform *self, int ifindex);
/* convienience methods to lookup the link and access fields of NMPlatformLink. */ /* convienience methods to lookup the link and access fields of NMPlatformLink. */
@@ -773,7 +773,7 @@ const NMPlatformLnkSit *nm_platform_link_get_lnk_sit (NMPlatform *self, int ifin
const NMPlatformLnkVlan *nm_platform_link_get_lnk_vlan (NMPlatform *self, int ifindex, const NMPlatformLink **out_link); const NMPlatformLnkVlan *nm_platform_link_get_lnk_vlan (NMPlatform *self, int ifindex, const NMPlatformLink **out_link);
const NMPlatformLnkVxlan *nm_platform_link_get_lnk_vxlan (NMPlatform *self, int ifindex, const NMPlatformLink **out_link); const NMPlatformLnkVxlan *nm_platform_link_get_lnk_vxlan (NMPlatform *self, int ifindex, const NMPlatformLink **out_link);
NMPlatformError nm_platform_vlan_add (NMPlatform *self, const char *name, int parent, int vlanid, guint32 vlanflags, NMPlatformLink *out_link); NMPlatformError nm_platform_vlan_add (NMPlatform *self, const char *name, int parent, int vlanid, guint32 vlanflags, const NMPlatformLink **out_link);
gboolean nm_platform_vlan_set_ingress_map (NMPlatform *self, int ifindex, int from, int to); gboolean nm_platform_vlan_set_ingress_map (NMPlatform *self, int ifindex, int from, int to);
gboolean nm_platform_vlan_set_egress_map (NMPlatform *self, int ifindex, int from, int to); gboolean nm_platform_vlan_set_egress_map (NMPlatform *self, int ifindex, int from, int to);
gboolean nm_platform_link_vlan_change (NMPlatform *self, gboolean nm_platform_link_vlan_change (NMPlatform *self,
@@ -787,12 +787,12 @@ gboolean nm_platform_link_vlan_change (NMPlatform *self,
const NMVlanQosMapping *egress_map, const NMVlanQosMapping *egress_map,
gsize n_egress_map); gsize n_egress_map);
NMPlatformError nm_platform_link_vxlan_add (NMPlatform *self, const char *name, NMPlatformLnkVxlan *props, NMPlatformLink *out_link); NMPlatformError nm_platform_link_vxlan_add (NMPlatform *self, const char *name, NMPlatformLnkVxlan *props, const NMPlatformLink **out_link);
NMPlatformError nm_platform_tun_add (NMPlatform *self, const char *name, gboolean tap, gint64 owner, gint64 group, gboolean pi, NMPlatformError nm_platform_tun_add (NMPlatform *self, const char *name, gboolean tap, gint64 owner, gint64 group, gboolean pi,
gboolean vnet_hdr, gboolean multi_queue, NMPlatformLink *out_link); gboolean vnet_hdr, gboolean multi_queue, const NMPlatformLink **out_link);
NMPlatformError nm_platform_infiniband_partition_add (NMPlatform *self, int parent, int p_key, NMPlatformLink *out_link); NMPlatformError nm_platform_infiniband_partition_add (NMPlatform *self, int parent, int p_key, const NMPlatformLink **out_link);
gboolean nm_platform_infiniband_get_properties (NMPlatform *self, int ifindex, int *parent, int *p_key, const char **mode); gboolean nm_platform_infiniband_get_properties (NMPlatform *self, int ifindex, int *parent, int *p_key, const char **mode);
gboolean nm_platform_veth_get_properties (NMPlatform *self, int ifindex, int *out_peer_ifindex); gboolean nm_platform_veth_get_properties (NMPlatform *self, int ifindex, int *out_peer_ifindex);
@@ -821,15 +821,15 @@ const struct in6_addr *nm_platform_ip6_address_get_peer (const NMPlatformIP6Addr
const NMPlatformIP4Address *nm_platform_ip4_address_get (NMPlatform *self, int ifindex, in_addr_t address, int plen, in_addr_t peer_address); const NMPlatformIP4Address *nm_platform_ip4_address_get (NMPlatform *self, int ifindex, in_addr_t address, int plen, in_addr_t peer_address);
NMPlatformError nm_platform_link_gre_add (NMPlatform *self, const char *name, NMPlatformLnkGre *props, NMPlatformError nm_platform_link_gre_add (NMPlatform *self, const char *name, NMPlatformLnkGre *props,
NMPlatformLink *out_link); const NMPlatformLink **out_link);
NMPlatformError nm_platform_link_ip6tnl_add (NMPlatform *self, const char *name, NMPlatformLnkIp6Tnl *props, NMPlatformError nm_platform_link_ip6tnl_add (NMPlatform *self, const char *name, NMPlatformLnkIp6Tnl *props,
NMPlatformLink *out_link); const NMPlatformLink **out_link);
NMPlatformError nm_platform_link_ipip_add (NMPlatform *self, const char *name, NMPlatformLnkIpIp *props, NMPlatformError nm_platform_link_ipip_add (NMPlatform *self, const char *name, NMPlatformLnkIpIp *props,
NMPlatformLink *out_link); const NMPlatformLink **out_link);
NMPlatformError nm_platform_link_macvlan_add (NMPlatform *self, const char *name, int parent, NMPlatformLnkMacvlan *props, NMPlatformError nm_platform_link_macvlan_add (NMPlatform *self, const char *name, int parent, NMPlatformLnkMacvlan *props,
NMPlatformLink *out_link); const NMPlatformLink **out_link);
NMPlatformError nm_platform_link_sit_add (NMPlatform *self, const char *name, NMPlatformLnkSit *props, NMPlatformError nm_platform_link_sit_add (NMPlatform *self, const char *name, NMPlatformLnkSit *props,
NMPlatformLink *out_link); const NMPlatformLink **out_link);
const NMPlatformIP6Address *nm_platform_ip6_address_get (NMPlatform *self, int ifindex, struct in6_addr address, int plen); const NMPlatformIP6Address *nm_platform_ip6_address_get (NMPlatform *self, int ifindex, struct in6_addr address, int plen);
GArray *nm_platform_ip4_address_get_all (NMPlatform *self, int ifindex); GArray *nm_platform_ip4_address_get_all (NMPlatform *self, int ifindex);

View File

@@ -462,11 +462,13 @@ test_bridge_addr (void)
{ {
char addr[ETH_ALEN]; char addr[ETH_ALEN];
NMPlatformLink link; NMPlatformLink link;
const NMPlatformLink *plink; const NMPlatformLink *plink = NULL;
nm_utils_hwaddr_aton ("de:ad:be:ef:00:11", addr, sizeof (addr)); nm_utils_hwaddr_aton ("de:ad:be:ef:00:11", addr, sizeof (addr));
g_assert_cmpint (nm_platform_bridge_add (NM_PLATFORM_GET, DEVICE_NAME, addr, sizeof (addr), &link), ==, NM_PLATFORM_ERROR_SUCCESS); g_assert_cmpint (nm_platform_bridge_add (NM_PLATFORM_GET, DEVICE_NAME, addr, sizeof (addr), &plink), ==, NM_PLATFORM_ERROR_SUCCESS);
g_assert (plink);
link = *plink;
g_assert_cmpstr (link.name, ==, DEVICE_NAME); g_assert_cmpstr (link.name, ==, DEVICE_NAME);
g_assert_cmpint (link.addr.len, ==, sizeof (addr)); g_assert_cmpint (link.addr.len, ==, sizeof (addr));