Commit 7573594a authored by Thomas Haller's avatar Thomas Haller Committed by Lubomir Rintel

platform: merge nm_platform_*_delete() delete functions

It only makes sense to call delete() with NMPObjects that
we obtained from the platform cache. Otherwise, if we didn't
get it from the cache in the first place, we wouldn't know
what to delete.

Hence, the input argument is (almost) always an NMPObject
in the first place. That is different from add(), where
we might create a new specific NMPlatform* instance on the
stack. For add() it makes slightly more sense to have different
functions depending on the type. For delete(), it doesn't.
parent 44be0dfc
......@@ -38,7 +38,7 @@ NM-colorize() {
GREP_COLOR='01;31' grep -a --color=always '^\|^\(.* \)\?<\(warn> \|error>\) \[[0-9.]*\]' | \
GREP_COLOR='01;33' grep -a --color=always '^\|^\(.* \)\?<info> \[[0-9.]*\]\( .*\<is starting\>.*$\)\?' | \
GREP_COLOR='01;37' grep -a --color=always '^\|\<platform: signal: .*$' | \
GREP_COLOR='01;34' grep -a --color=always '^\|\<platform\(-linux\)\?: link: \(add\|adding\|change\|setting\|deleting\) \|\<platform: address: \(deleting\|adding or updating\) IPv. address:\? \|\<platform: route: \([a-z]\+\|adding or updating\|new\[0x[0-9A-Za-z]*\]\) \+IPv. route:\? \|\<platform-linux: sysctl: setting ' | \
GREP_COLOR='01;34' grep -a --color=always '^\|\<platform\(-linux\)\?: link: \(add\|adding\|change\|setting\|deleting\) \|\<platform: address: \(deleting\|adding or updating\) IPv. address:\? \|\<platform: \(route\|ip4-route\|ip6-route\|qdisc\|tfilter\): \([a-z]\+\|adding or updating\|new\[0x[0-9A-Za-z]*\]\) \|\<platform-linux: sysctl: setting ' | \
GREP_COLOR='01;35' grep -a --color=always '^\|\<audit: .*$' | \
GREP_COLOR='01;32' grep -a --color=always '^\|\<device (.*): state change: '
else
......
......@@ -1190,7 +1190,7 @@ ipx_route_delete (NMPlatform *platform,
}
static gboolean
ip_route_delete (NMPlatform *platform, const NMPObject *obj)
object_delete (NMPlatform *platform, const NMPObject *obj)
{
g_assert (NM_IS_FAKE_PLATFORM (platform));
g_assert (NM_IN_SET (NMP_OBJECT_GET_TYPE (obj), NMP_OBJECT_TYPE_IP4_ROUTE,
......@@ -1462,5 +1462,5 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass)
platform_class->ip6_address_delete = ip6_address_delete;
platform_class->ip_route_add = ip_route_add;
platform_class->ip_route_delete = ip_route_delete;
platform_class->object_delete = object_delete;
}
......@@ -6116,19 +6116,24 @@ ip_route_add (NMPlatform *platform,
}
static gboolean
ip_route_delete (NMPlatform *platform,
const NMPObject *obj)
object_delete (NMPlatform *platform,
const NMPObject *obj)
{
nm_auto_nmpobj const NMPObject *obj_keep_alive = NULL;
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
nm_assert (NM_IN_SET (NMP_OBJECT_GET_TYPE (obj), NMP_OBJECT_TYPE_IP4_ROUTE,
NMP_OBJECT_TYPE_IP6_ROUTE));
if (!NMP_OBJECT_IS_STACKINIT (obj))
obj_keep_alive = nmp_object_ref (obj);
nlmsg = _nl_msg_new_route (RTM_DELROUTE, 0, obj);
switch (NMP_OBJECT_GET_TYPE (obj)) {
case NMP_OBJECT_TYPE_IP4_ROUTE:
case NMP_OBJECT_TYPE_IP6_ROUTE:
nlmsg = _nl_msg_new_route (RTM_DELROUTE, 0, obj);
break;
default:
break;
}
if (!nlmsg)
g_return_val_if_reached (FALSE);
return do_delete_object (platform, obj, nlmsg);
......@@ -6937,13 +6942,13 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
platform_class->link_ipip_add = link_ipip_add;
platform_class->link_sit_add = link_sit_add;
platform_class->object_delete = object_delete;
platform_class->ip4_address_add = ip4_address_add;
platform_class->ip6_address_add = ip6_address_add;
platform_class->ip4_address_delete = ip4_address_delete;
platform_class->ip6_address_delete = ip6_address_delete;
platform_class->ip_route_add = ip_route_add;
platform_class->ip_route_delete = ip_route_delete;
platform_class->ip_route_get = ip_route_get;
platform_class->check_kernel_support = check_kernel_support;
......
......@@ -3732,7 +3732,7 @@ nm_platform_ip_route_sync (NMPlatform *self,
/* we need to replace the existing route with a (slightly) differnt
* one. Delete it first. */
if (!nm_platform_ip_route_delete (self, plat_o)) {
if (!nm_platform_object_delete (self, plat_o)) {
/* ignore error. */
}
}
......@@ -3813,7 +3813,7 @@ nm_platform_ip_route_sync (NMPlatform *self,
prune_o))
continue;
if (!nm_platform_ip_route_delete (self, prune_o)) {
if (!nm_platform_object_delete (self, prune_o)) {
/* ignore error... */
}
}
......@@ -3991,8 +3991,8 @@ nm_platform_ip6_route_add (NMPlatform *self,
}
gboolean
nm_platform_ip_route_delete (NMPlatform *self,
const NMPObject *obj)
nm_platform_object_delete (NMPlatform *self,
const NMPObject *obj)
{
_CHECK_SELF (self, klass, FALSE);
......@@ -4000,11 +4000,11 @@ nm_platform_ip_route_delete (NMPlatform *self,
NMP_OBJECT_TYPE_IP6_ROUTE))
g_return_val_if_reached (FALSE);
_LOGD ("route: delete IPv%c route %s",
NMP_OBJECT_GET_TYPE (obj) == NMP_OBJECT_TYPE_IP4_ROUTE ? '4' : '6',
_LOGD ("%s: delete %s",
NMP_OBJECT_GET_CLASS (obj)->obj_type_name,
nmp_object_to_string (obj, NMP_OBJECT_TO_STRING_PUBLIC, NULL, 0));
return klass->ip_route_delete (self, obj);
return klass->object_delete (self, obj);
}
/*****************************************************************************/
......@@ -4115,7 +4115,7 @@ again:
_LOGT ("ip4-dev-route: delete %s",
nmp_object_to_string (p_obj, NMP_OBJECT_TO_STRING_PUBLIC, NULL, 0));
nm_platform_ip_route_delete (self, p_obj);
nm_platform_object_delete (self, p_obj);
goto again;
}
......
......@@ -15,7 +15,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2009 - 2010 Red Hat, Inc.
* Copyright (C) 2009 - 2017 Red Hat, Inc.
*/
#ifndef __NETWORKMANAGER_PLATFORM_H__
......@@ -800,6 +800,8 @@ typedef struct {
gboolean (*mesh_set_channel) (NMPlatform *, int ifindex, guint32 channel);
gboolean (*mesh_set_ssid) (NMPlatform *, int ifindex, const guint8 *ssid, gsize len);
gboolean (*object_delete) (NMPlatform *, const NMPObject *obj);
gboolean (*ip4_address_add) (NMPlatform *,
int ifindex,
in_addr_t address,
......@@ -824,8 +826,6 @@ typedef struct {
NMPNlmFlags flags,
int addr_family,
const NMPlatformIPRoute *route);
gboolean (*ip_route_delete) (NMPlatform *, const NMPObject *obj);
NMPlatformError (*ip_route_get) (NMPlatform *self,
int addr_family,
gconstpointer address,
......@@ -1189,6 +1189,8 @@ NMPlatformError nm_platform_link_sit_add (NMPlatform *self,
const NMPlatformIP6Address *nm_platform_ip6_address_get (NMPlatform *self, int ifindex, struct in6_addr address);
gboolean nm_platform_object_delete (NMPlatform *self, const NMPObject *route);
gboolean nm_platform_ip4_address_add (NMPlatform *self,
int ifindex,
in_addr_t address,
......@@ -1223,8 +1225,6 @@ NMPlatformError nm_platform_ip_route_add (NMPlatform *self,
NMPlatformError nm_platform_ip4_route_add (NMPlatform *self, NMPNlmFlags flags, const NMPlatformIP4Route *route);
NMPlatformError nm_platform_ip6_route_add (NMPlatform *self, NMPNlmFlags flags, const NMPlatformIP6Route *route);
gboolean nm_platform_ip_route_delete (NMPlatform *self, const NMPObject *route);
GPtrArray *nm_platform_ip_route_get_prune_list (NMPlatform *self,
int addr_family,
int ifindex,
......
......@@ -119,7 +119,7 @@ nmtstp_platform_ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t n
continue;
}
return nm_platform_ip_route_delete (platform, NMP_OBJECT_UP_CAST (r));
return nm_platform_object_delete (platform, NMP_OBJECT_UP_CAST (r));
}
return TRUE;
......@@ -145,7 +145,7 @@ nmtstp_platform_ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_
continue;
}
return nm_platform_ip_route_delete (platform, NMP_OBJECT_UP_CAST (r));
return nm_platform_object_delete (platform, NMP_OBJECT_UP_CAST (r));
}
return TRUE;
......
......@@ -793,7 +793,7 @@ again_find_idx:
order_len--;
r->ifindex = iface_data[idx].ifindex;
g_assert (nm_platform_ip_route_delete (platform, &o));
g_assert (nm_platform_object_delete (platform, &o));
}
head_entry = nm_platform_lookup (platform,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment