2013-03-27 22:23:24 +01:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
|
|
|
|
/* nm-platform.c - Handle runtime kernel networking configuration
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2012 Red Hat, Inc.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-02-19 14:57:48 +01:00
|
|
|
#include "nm-default.h"
|
2014-11-13 10:07:02 -05:00
|
|
|
|
2016-03-01 09:56:51 +01:00
|
|
|
#include "nm-platform.h"
|
|
|
|
|
|
2013-03-27 22:23:24 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <netinet/in.h>
|
2013-03-27 22:23:24 +01:00
|
|
|
#include <arpa/inet.h>
|
2013-04-03 16:10:38 +02:00
|
|
|
#include <string.h>
|
2013-10-15 20:44:59 +02:00
|
|
|
#include <netlink/route/addr.h>
|
2015-05-03 10:47:41 +02:00
|
|
|
#include <netlink/route/rtnl.h>
|
2015-10-12 15:15:21 +02:00
|
|
|
#include <linux/ip.h>
|
2015-10-13 16:08:30 +02:00
|
|
|
#include <linux/if_tun.h>
|
2015-10-12 15:15:21 +02:00
|
|
|
#include <linux/if_tunnel.h>
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2014-01-30 20:31:29 +01:00
|
|
|
#include "nm-utils.h"
|
2016-03-01 09:56:51 +01:00
|
|
|
#include "nm-core-internal.h"
|
|
|
|
|
|
|
|
|
|
#include "nm-core-utils.h"
|
|
|
|
|
#include "nm-enum-types.h"
|
2015-06-22 15:45:10 +02:00
|
|
|
#include "nm-platform-utils.h"
|
2015-10-29 11:27:55 +01:00
|
|
|
#include "nmp-object.h"
|
2016-02-19 01:06:28 +01:00
|
|
|
#include "nmp-netns.h"
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2016-02-18 20:21:27 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
const NMIPAddr nm_ip_addr_zero = NMIPAddrInit;
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-04-27 18:06:59 +02:00
|
|
|
G_STATIC_ASSERT (sizeof ( ((NMPlatformLink *) NULL)->addr.data ) == NM_UTILS_HWADDR_LEN_MAX);
|
2015-10-20 14:08:04 +02:00
|
|
|
G_STATIC_ASSERT (G_STRUCT_OFFSET (NMPlatformIPAddress, address_ptr) == G_STRUCT_OFFSET (NMPlatformIP4Address, address));
|
|
|
|
|
G_STATIC_ASSERT (G_STRUCT_OFFSET (NMPlatformIPAddress, address_ptr) == G_STRUCT_OFFSET (NMPlatformIP6Address, address));
|
|
|
|
|
G_STATIC_ASSERT (G_STRUCT_OFFSET (NMPlatformIPRoute, network_ptr) == G_STRUCT_OFFSET (NMPlatformIP4Route, network));
|
|
|
|
|
G_STATIC_ASSERT (G_STRUCT_OFFSET (NMPlatformIPRoute, network_ptr) == G_STRUCT_OFFSET (NMPlatformIP6Route, network));
|
2015-04-27 18:06:59 +02:00
|
|
|
|
2015-08-20 00:07:14 +02:00
|
|
|
#define _NMLOG_DOMAIN LOGD_PLATFORM
|
|
|
|
|
#define _NMLOG_PREFIX_NAME "platform"
|
|
|
|
|
#define _NMLOG(level, ...) \
|
2015-07-02 14:33:37 +02:00
|
|
|
G_STMT_START { \
|
|
|
|
|
const NMLogLevel __level = (level); \
|
|
|
|
|
\
|
2015-08-20 00:07:14 +02:00
|
|
|
if (nm_logging_enabled (__level, _NMLOG_DOMAIN)) { \
|
2015-07-02 14:33:37 +02:00
|
|
|
char __prefix[32]; \
|
2015-08-20 00:07:14 +02:00
|
|
|
const char *__p_prefix = _NMLOG_PREFIX_NAME; \
|
2015-07-02 14:33:37 +02:00
|
|
|
const void *const __self = (self); \
|
|
|
|
|
\
|
|
|
|
|
if (__self && __self != nm_platform_try_get ()) { \
|
2015-08-20 00:07:14 +02:00
|
|
|
g_snprintf (__prefix, sizeof (__prefix), "%s[%p]", _NMLOG_PREFIX_NAME, __self); \
|
2015-07-02 14:33:37 +02:00
|
|
|
__p_prefix = __prefix; \
|
|
|
|
|
} \
|
2015-08-20 00:07:14 +02:00
|
|
|
_nm_log (__level, _NMLOG_DOMAIN, 0, \
|
2015-07-02 14:33:37 +02:00
|
|
|
"%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \
|
|
|
|
|
__p_prefix _NM_UTILS_MACRO_REST (__VA_ARGS__)); \
|
|
|
|
|
} \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
2015-09-01 22:11:47 +02:00
|
|
|
#define LOG_FMT_IP_TUNNEL "adding %s '%s' parent %u local %s remote %s"
|
|
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2013-03-27 22:23:24 +01:00
|
|
|
#define NM_PLATFORM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_PLATFORM, NMPlatformPrivate))
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (NMPlatform, nm_platform, G_TYPE_OBJECT)
|
|
|
|
|
|
2015-11-27 12:54:31 +01:00
|
|
|
static guint signals[_NM_PLATFORM_SIGNAL_ID_LAST] = { 0 };
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-05-12 07:34:56 +02:00
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
2016-02-19 01:06:28 +01:00
|
|
|
PROP_NETNS_SUPPORT,
|
2015-05-12 07:34:56 +02:00
|
|
|
PROP_REGISTER_SINGLETON,
|
|
|
|
|
LAST_PROP,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
gboolean register_singleton;
|
|
|
|
|
} NMPlatformPrivate;
|
|
|
|
|
|
2013-03-27 22:23:24 +01:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
2015-11-27 12:54:31 +01:00
|
|
|
guint
|
|
|
|
|
_nm_platform_signal_id_get (NMPlatformSignalIdType signal_type)
|
|
|
|
|
{
|
|
|
|
|
nm_assert ( signal_type > 0
|
|
|
|
|
&& signal_type != NM_PLATFORM_SIGNAL_ID_NONE
|
|
|
|
|
&& signal_type < _NM_PLATFORM_SIGNAL_ID_LAST);
|
|
|
|
|
|
|
|
|
|
return signals[signal_type];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
2013-03-27 22:23:24 +01:00
|
|
|
/* Singleton NMPlatform subclass instance and cached class object */
|
2015-04-18 14:00:45 +02:00
|
|
|
NM_DEFINE_SINGLETON_INSTANCE (NMPlatform);
|
|
|
|
|
|
2015-07-24 18:54:13 +02:00
|
|
|
NM_DEFINE_SINGLETON_REGISTER (NMPlatform);
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
|
|
|
|
|
/* Just always initialize a @klass instance. NM_PLATFORM_GET_CLASS()
|
|
|
|
|
* is only a plain read on the self instance, which the compiler
|
|
|
|
|
* like can optimize out.
|
|
|
|
|
*/
|
|
|
|
|
#define _CHECK_SELF_VOID(self, klass) \
|
|
|
|
|
NMPlatformClass *klass; \
|
|
|
|
|
do { \
|
|
|
|
|
g_return_if_fail (NM_IS_PLATFORM (self)); \
|
|
|
|
|
klass = NM_PLATFORM_GET_CLASS (self); \
|
|
|
|
|
(void) klass; \
|
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
|
|
#define _CHECK_SELF(self, klass, err_val) \
|
|
|
|
|
NMPlatformClass *klass; \
|
|
|
|
|
do { \
|
|
|
|
|
g_return_val_if_fail (NM_IS_PLATFORM (self), err_val); \
|
|
|
|
|
klass = NM_PLATFORM_GET_CLASS (self); \
|
|
|
|
|
(void) klass; \
|
|
|
|
|
} while (0)
|
2013-03-27 22:23:24 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_setup:
|
2015-04-18 13:37:36 +02:00
|
|
|
* @instance: the #NMPlatform instance
|
2013-03-27 22:23:24 +01:00
|
|
|
*
|
|
|
|
|
* Failing to set up #NMPlatform singleton results in a fatal error,
|
|
|
|
|
* as well as trying to initialize it multiple times without freeing
|
|
|
|
|
* it.
|
|
|
|
|
*
|
|
|
|
|
* NetworkManager will typically use only one platform object during
|
|
|
|
|
* its run. Test programs might want to switch platform implementations,
|
2015-04-18 14:00:45 +02:00
|
|
|
* though.
|
2013-03-27 22:23:24 +01:00
|
|
|
*/
|
|
|
|
|
void
|
2015-04-18 13:37:36 +02:00
|
|
|
nm_platform_setup (NMPlatform *instance)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
2015-04-18 13:37:36 +02:00
|
|
|
g_return_if_fail (NM_IS_PLATFORM (instance));
|
|
|
|
|
g_return_if_fail (!singleton_instance);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-04-18 13:37:36 +02:00
|
|
|
singleton_instance = instance;
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-07-24 18:54:13 +02:00
|
|
|
nm_singleton_instance_register ();
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-07-26 11:48:05 +02:00
|
|
|
nm_log_dbg (LOGD_CORE, "setup %s singleton (%p, %s)", "NMPlatform", singleton_instance, G_OBJECT_TYPE_NAME (instance));
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_get:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:23:24 +01:00
|
|
|
*
|
|
|
|
|
* Retrieve #NMPlatform singleton. Use this whenever you want to connect to
|
2015-04-18 14:00:45 +02:00
|
|
|
* #NMPlatform signals. It is an error to call it before nm_platform_setup().
|
2013-03-27 22:23:24 +01:00
|
|
|
*
|
|
|
|
|
* Returns: (transfer none): The #NMPlatform singleton reference.
|
|
|
|
|
*/
|
|
|
|
|
NMPlatform *
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_get ()
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
g_assert (singleton_instance);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return singleton_instance;
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
2015-04-18 14:02:24 +02:00
|
|
|
NMPlatform *
|
|
|
|
|
nm_platform_try_get (void)
|
|
|
|
|
{
|
|
|
|
|
return singleton_instance;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-27 22:23:24 +01:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
2016-01-24 11:30:36 +01:00
|
|
|
* _nm_platform_error_to_string:
|
2015-06-15 15:50:59 +02:00
|
|
|
* @error_code: the error code to stringify.
|
2013-03-27 22:23:24 +01:00
|
|
|
*
|
2015-06-15 15:50:59 +02:00
|
|
|
* Returns: A string representation of the error.
|
|
|
|
|
* For negative numbers, this function interprets
|
|
|
|
|
* the code as -errno.
|
2016-01-24 11:30:36 +01:00
|
|
|
* For invalid (positive) numbers it returns NULL.
|
2013-03-27 22:23:24 +01:00
|
|
|
*/
|
2016-01-24 11:30:36 +01:00
|
|
|
NM_UTILS_LOOKUP_STR_DEFINE (_nm_platform_error_to_string, NMPlatformError,
|
2016-02-01 14:09:56 +01:00
|
|
|
NM_UTILS_LOOKUP_DEFAULT ( val < 0 ? g_strerror (- ((int) val)) : NULL ),
|
2016-01-24 11:30:36 +01:00
|
|
|
NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_ERROR_SUCCESS, "success"),
|
|
|
|
|
NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_ERROR_BUG, "bug"),
|
|
|
|
|
NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_ERROR_UNSPECIFIED, "unspecified"),
|
|
|
|
|
NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_ERROR_NOT_FOUND, "not-found"),
|
|
|
|
|
NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_ERROR_EXISTS, "exists"),
|
|
|
|
|
NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_ERROR_WRONG_TYPE, "wrong-type"),
|
|
|
|
|
NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_ERROR_NOT_SLAVE, "not-slave"),
|
|
|
|
|
NM_UTILS_LOOKUP_STR_ITEM (NM_PLATFORM_ERROR_NO_FIRMWARE, "no-firmware"),
|
2016-02-01 14:02:39 +01:00
|
|
|
NM_UTILS_LOOKUP_ITEM_IGNORE (_NM_PLATFORM_ERROR_MININT),
|
2016-01-24 11:30:36 +01:00
|
|
|
);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
platform: drop nm_platform_get_error()
For NMPlatform instances we had an error reporting mechanism
which stores the last error reason in a private field. Later we
would check it via nm_platform_get_error().
Remove this. It was not used much, and it is not a great way
to report errors.
One problem is that at the point where the error happens, you don't
know whether anybody cares about an error code. So, you add code to set
the error reason because somebody *might* need it (but in realitiy, almost
no caller cares).
Also, we tested this functionality which is hardly used in non-testing code.
While this was a burden to maintain in the tests, it was likely still buggy
because there were no real use-cases, beside the tests.
Then, sometimes platform functions call each other which might overwrite the
error reason. So, every function must be cautious to preserve/set
the error reason according to it's own meaning. This can involve storing
the error code, calling another function, and restoring it afterwards.
This is harder to get right compared to a "return-error-code" pattern, where
every function manages its error code independently.
It is better to return the error reason whenever due. For that we already
have our common glib patterns
(1) gboolean fcn (...);
(2) gboolean fcn (..., GError **error);
In few cases, we need more details then a #gboolean, but don't want
to bother constructing a #GError. Then we should do instead:
(3) NMPlatformError fcn (...);
2015-06-15 17:58:36 +02:00
|
|
|
/******************************************************************/
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2014-01-07 17:21:12 +01:00
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_check_support_kernel_extended_ifa_flags (NMPlatform *self)
|
2014-01-07 17:21:12 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2014-01-07 17:21:12 +01:00
|
|
|
|
|
|
|
|
if (!klass->check_support_kernel_extended_ifa_flags)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->check_support_kernel_extended_ifa_flags (self);
|
2014-01-07 17:21:12 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-24 15:57:08 -05:00
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_check_support_user_ipv6ll (NMPlatform *self)
|
2014-07-24 15:57:08 -05:00
|
|
|
{
|
|
|
|
|
static int supported = -1;
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2014-07-24 15:57:08 -05:00
|
|
|
|
|
|
|
|
if (!klass->check_support_user_ipv6ll)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (supported < 0)
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
supported = klass->check_support_user_ipv6ll (self) ? 1 : 0;
|
2014-07-24 15:57:08 -05:00
|
|
|
return !!supported;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-19 15:38:41 +02:00
|
|
|
/**
|
|
|
|
|
* nm_platform_process_events:
|
|
|
|
|
* @self: platform instance
|
|
|
|
|
*
|
|
|
|
|
* Process pending events or handle pending delayed-actions.
|
|
|
|
|
* Effectively, this reads the netlink socket and processes
|
|
|
|
|
* new netlink messages. Possibly it will raise change signals.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
nm_platform_process_events (NMPlatform *self)
|
|
|
|
|
{
|
|
|
|
|
_CHECK_SELF_VOID (self, klass);
|
|
|
|
|
|
|
|
|
|
if (klass->process_events)
|
|
|
|
|
klass->process_events (self);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-27 22:23:24 +01:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
2013-04-03 16:10:38 +02:00
|
|
|
/**
|
|
|
|
|
* nm_platform_sysctl_set:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-04-03 16:10:38 +02:00
|
|
|
* @path: Absolute option path
|
|
|
|
|
* @value: Value to write
|
|
|
|
|
*
|
|
|
|
|
* This function is intended to be used for writing values to sysctl-style
|
|
|
|
|
* virtual runtime configuration files. This includes not only /proc/sys
|
|
|
|
|
* but also for example /sys/class.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_sysctl_set (NMPlatform *self, const char *path, const char *value)
|
2013-04-03 16:10:38 +02:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-04-03 16:10:38 +02:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (path, FALSE);
|
|
|
|
|
g_return_val_if_fail (value, FALSE);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->sysctl_set (self, path, value);
|
2013-04-03 16:10:38 +02:00
|
|
|
}
|
|
|
|
|
|
2015-04-08 15:54:30 +02:00
|
|
|
gboolean
|
|
|
|
|
nm_platform_sysctl_set_ip6_hop_limit_safe (NMPlatform *self, const char *iface, int value)
|
|
|
|
|
{
|
|
|
|
|
const char *path;
|
|
|
|
|
gint64 cur;
|
|
|
|
|
|
2015-06-17 15:00:10 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
|
|
|
|
|
2015-04-08 15:54:30 +02:00
|
|
|
/* the hop-limit provided via RA is uint8. */
|
|
|
|
|
if (value > 0xFF)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
/* don't allow unreasonable small values */
|
|
|
|
|
if (value < 10)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
path = nm_utils_ip6_property_path (iface, "hop_limit");
|
|
|
|
|
cur = nm_platform_sysctl_get_int_checked (self, path, 10, 1, G_MAXINT32, -1);
|
|
|
|
|
|
|
|
|
|
/* only allow increasing the hop-limit to avoid DOS by an attacker
|
|
|
|
|
* setting a low hop-limit (CVE-2015-2924, rh#1209902) */
|
|
|
|
|
|
|
|
|
|
if (value < cur)
|
|
|
|
|
return FALSE;
|
|
|
|
|
if (value != cur) {
|
|
|
|
|
char svalue[20];
|
|
|
|
|
|
|
|
|
|
sprintf (svalue, "%d", value);
|
|
|
|
|
nm_platform_sysctl_set (self, path, svalue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-03 16:10:38 +02:00
|
|
|
/**
|
|
|
|
|
* nm_platform_sysctl_get:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-04-03 16:10:38 +02:00
|
|
|
* @path: Absolute path to sysctl
|
|
|
|
|
*
|
|
|
|
|
* Returns: (transfer full): Contents of the virtual sysctl file.
|
|
|
|
|
*/
|
|
|
|
|
char *
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_sysctl_get (NMPlatform *self, const char *path)
|
2013-04-03 16:10:38 +02:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, NULL);
|
2013-04-03 16:10:38 +02:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (path, NULL);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->sysctl_get (self, path);
|
2013-04-03 16:10:38 +02:00
|
|
|
}
|
|
|
|
|
|
2013-11-08 08:49:06 -05:00
|
|
|
/**
|
2014-01-06 19:59:17 +01:00
|
|
|
* nm_platform_sysctl_get_int32:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-11-08 08:49:06 -05:00
|
|
|
* @path: Absolute path to sysctl
|
2014-01-06 19:59:17 +01:00
|
|
|
* @fallback: default value, if the content of path could not be read
|
|
|
|
|
* as decimal integer.
|
2013-11-08 08:49:06 -05:00
|
|
|
*
|
2014-01-06 19:59:17 +01:00
|
|
|
* Returns: contents of the sysctl file parsed as s32 integer, or
|
2014-03-23 14:57:39 +01:00
|
|
|
* @fallback on error. On error, %errno will be set to a non-zero
|
|
|
|
|
* value, on success %errno will be set to zero.
|
2013-11-08 08:49:06 -05:00
|
|
|
*/
|
2014-01-06 19:59:17 +01:00
|
|
|
gint32
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_sysctl_get_int32 (NMPlatform *self, const char *path, gint32 fallback)
|
2014-03-12 12:27:58 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return nm_platform_sysctl_get_int_checked (self, path, 10, G_MININT32, G_MAXINT32, fallback);
|
2014-03-12 12:27:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_sysctl_get_int_checked:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2014-03-12 12:27:58 +01:00
|
|
|
* @path: Absolute path to sysctl
|
|
|
|
|
* @base: base of numeric conversion
|
|
|
|
|
* @min: minimal value that is still valid
|
|
|
|
|
* @max: maximal value that is still valid
|
|
|
|
|
* @fallback: default value, if the content of path could not be read
|
|
|
|
|
* as valid integer.
|
|
|
|
|
*
|
|
|
|
|
* Returns: contents of the sysctl file parsed as s64 integer, or
|
|
|
|
|
* @fallback on error. On error, %errno will be set to a non-zero
|
|
|
|
|
* value. On success, %errno will be set to zero. The returned value
|
|
|
|
|
* will always be in the range between @min and @max
|
|
|
|
|
* (inclusive) or @fallback.
|
|
|
|
|
*/
|
|
|
|
|
gint64
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_sysctl_get_int_checked (NMPlatform *self, const char *path, guint base, gint64 min, gint64 max, gint64 fallback)
|
2013-11-08 08:49:06 -05:00
|
|
|
{
|
2014-01-06 19:59:17 +01:00
|
|
|
char *value = NULL;
|
|
|
|
|
gint32 ret;
|
2013-11-08 08:49:06 -05:00
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, fallback);
|
|
|
|
|
|
2014-01-06 19:59:17 +01:00
|
|
|
g_return_val_if_fail (path, fallback);
|
2013-11-08 08:49:06 -05:00
|
|
|
|
2014-01-06 19:59:17 +01:00
|
|
|
if (path)
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
value = nm_platform_sysctl_get (self, path);
|
2014-01-06 19:59:17 +01:00
|
|
|
|
|
|
|
|
if (!value) {
|
|
|
|
|
errno = EINVAL;
|
|
|
|
|
return fallback;
|
|
|
|
|
}
|
2013-11-08 08:49:06 -05:00
|
|
|
|
2015-02-22 11:55:31 +01:00
|
|
|
ret = _nm_utils_ascii_str_to_int64 (value, base, min, max, fallback);
|
2014-01-06 19:59:17 +01:00
|
|
|
g_free (value);
|
2013-11-08 08:49:06 -05:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-03 16:10:38 +02:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
2013-03-27 22:23:24 +01:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_get_all:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* self: platform instance
|
2013-03-27 22:23:24 +01:00
|
|
|
*
|
|
|
|
|
* Retrieve a snapshot of configuration for all links at once. The result is
|
|
|
|
|
* owned by the caller and should be freed with g_array_unref().
|
|
|
|
|
*/
|
|
|
|
|
GArray *
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_get_all (NMPlatform *self)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
2013-11-06 22:15:03 -06:00
|
|
|
GArray *links, *result;
|
|
|
|
|
guint i, j, nresult;
|
|
|
|
|
GHashTable *unseen;
|
|
|
|
|
NMPlatformLink *item;
|
2013-06-03 11:49:55 -03:00
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, NULL);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
links = klass->link_get_all (self);
|
2013-11-06 22:15:03 -06:00
|
|
|
|
|
|
|
|
if (!links || links->len == 0)
|
|
|
|
|
return links;
|
|
|
|
|
|
|
|
|
|
unseen = g_hash_table_new (g_direct_hash, g_direct_equal);
|
|
|
|
|
for (i = 0; i < links->len; i++) {
|
|
|
|
|
item = &g_array_index (links, NMPlatformLink, i);
|
|
|
|
|
|
2015-11-06 12:58:55 +01:00
|
|
|
_LOGt ("link-get: %3d: %s", i, nm_platform_link_to_string (item, NULL, 0));
|
2015-07-02 14:42:08 +02:00
|
|
|
|
2015-07-02 15:00:37 +02:00
|
|
|
nm_assert (item->ifindex > 0 && !g_hash_table_contains (unseen, GINT_TO_POINTER (item->ifindex)));
|
|
|
|
|
|
2013-11-06 22:15:03 -06:00
|
|
|
g_hash_table_insert (unseen, GINT_TO_POINTER (item->ifindex), NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifndef G_DISABLE_ASSERT
|
|
|
|
|
/* Ensure that link_get_all returns a consistent and valid result. */
|
|
|
|
|
for (i = 0; i < links->len; i++) {
|
|
|
|
|
item = &g_array_index (links, NMPlatformLink, i);
|
|
|
|
|
|
|
|
|
|
if (!item->ifindex)
|
|
|
|
|
continue;
|
|
|
|
|
if (item->master != 0) {
|
|
|
|
|
g_warn_if_fail (item->master > 0);
|
|
|
|
|
g_warn_if_fail (item->master != item->ifindex);
|
|
|
|
|
g_warn_if_fail (g_hash_table_contains (unseen, GINT_TO_POINTER (item->master)));
|
|
|
|
|
}
|
|
|
|
|
if (item->parent != 0) {
|
2015-08-17 17:48:37 +02:00
|
|
|
if (item->parent != NM_PLATFORM_LINK_OTHER_NETNS) {
|
|
|
|
|
g_warn_if_fail (item->parent > 0);
|
|
|
|
|
g_warn_if_fail (item->parent != item->ifindex);
|
2015-10-12 16:07:01 +02:00
|
|
|
g_warn_if_fail (g_hash_table_contains (unseen, GINT_TO_POINTER (item->parent)));
|
2015-08-17 17:48:37 +02:00
|
|
|
}
|
2013-11-06 22:15:03 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Re-order the links list such that children/slaves come after all ancestors */
|
|
|
|
|
nresult = g_hash_table_size (unseen);
|
|
|
|
|
result = g_array_sized_new (TRUE, TRUE, sizeof (NMPlatformLink), nresult);
|
|
|
|
|
g_array_set_size (result, nresult);
|
|
|
|
|
|
|
|
|
|
j = 0;
|
|
|
|
|
do {
|
|
|
|
|
gboolean found_something = FALSE;
|
|
|
|
|
guint first_idx = G_MAXUINT;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < links->len; i++) {
|
|
|
|
|
item = &g_array_index (links, NMPlatformLink, i);
|
|
|
|
|
|
|
|
|
|
if (!item->ifindex)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (first_idx == G_MAXUINT)
|
|
|
|
|
first_idx = i;
|
|
|
|
|
|
|
|
|
|
g_assert (g_hash_table_contains (unseen, GINT_TO_POINTER (item->ifindex)));
|
|
|
|
|
|
|
|
|
|
if (item->master > 0 && g_hash_table_contains (unseen, GINT_TO_POINTER (item->master)))
|
|
|
|
|
continue;
|
|
|
|
|
if (item->parent > 0 && g_hash_table_contains (unseen, GINT_TO_POINTER (item->parent)))
|
|
|
|
|
continue;
|
|
|
|
|
|
2015-11-06 12:58:55 +01:00
|
|
|
_LOGt ("link-get: add %3d -> %3d: %s", i, j, nm_platform_link_to_string (item, NULL, 0));
|
2015-07-02 14:42:08 +02:00
|
|
|
|
2013-11-06 22:15:03 -06:00
|
|
|
g_hash_table_remove (unseen, GINT_TO_POINTER (item->ifindex));
|
|
|
|
|
g_array_index (result, NMPlatformLink, j++) = *item;
|
|
|
|
|
item->ifindex = 0;
|
|
|
|
|
found_something = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!found_something) {
|
2015-07-14 11:47:51 +02:00
|
|
|
/* There is a loop, pop the first (remaining) element from the list.
|
|
|
|
|
* This can happen for veth pairs where each peer is parent of the other end. */
|
2013-11-06 22:15:03 -06:00
|
|
|
item = &g_array_index (links, NMPlatformLink, first_idx);
|
|
|
|
|
|
2015-11-06 12:58:55 +01:00
|
|
|
_LOGt ("link-get: add (loop) %3d -> %3d: %s", first_idx, j, nm_platform_link_to_string (item, NULL, 0));
|
2015-07-02 14:42:08 +02:00
|
|
|
|
2013-11-06 22:15:03 -06:00
|
|
|
g_hash_table_remove (unseen, GINT_TO_POINTER (item->ifindex));
|
|
|
|
|
g_array_index (result, NMPlatformLink, j++) = *item;
|
|
|
|
|
item->ifindex = 0;
|
|
|
|
|
}
|
|
|
|
|
} while (j < nresult);
|
|
|
|
|
|
|
|
|
|
g_hash_table_destroy (unseen);
|
|
|
|
|
g_array_free (links, TRUE);
|
|
|
|
|
|
|
|
|
|
return result;
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
2014-04-22 16:02:15 +02:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_get:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2014-04-22 16:02:15 +02:00
|
|
|
* @ifindex: ifindex of the link
|
|
|
|
|
*
|
2015-06-20 12:05:01 +02:00
|
|
|
* Lookup the internal NMPlatformLink object.
|
2014-04-22 16:02:15 +02:00
|
|
|
*
|
2015-06-20 12:05:01 +02:00
|
|
|
* Returns: %NULL, if such a link exists or the internal
|
|
|
|
|
* platform link object. Do not modify the returned value.
|
|
|
|
|
* Also, be aware that any subsequent platform call might
|
|
|
|
|
* invalidated/modify the returned instance.
|
2014-04-22 16:02:15 +02:00
|
|
|
**/
|
2015-06-20 12:05:01 +02:00
|
|
|
const NMPlatformLink *
|
|
|
|
|
nm_platform_link_get (NMPlatform *self, int ifindex)
|
2014-04-22 16:02:15 +02:00
|
|
|
{
|
2015-06-20 12:05:01 +02:00
|
|
|
_CHECK_SELF (self, klass, NULL);
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
|
2015-06-21 15:05:52 +02:00
|
|
|
if (ifindex > 0)
|
|
|
|
|
return klass->link_get (self, ifindex);
|
|
|
|
|
return NULL;
|
2015-06-20 12:05:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_link_get_by_ifname:
|
|
|
|
|
* @self: platform instance
|
|
|
|
|
* @ifname: the ifname
|
|
|
|
|
*
|
|
|
|
|
* Returns: the first #NMPlatformLink instance with the given name.
|
|
|
|
|
**/
|
|
|
|
|
const NMPlatformLink *
|
|
|
|
|
nm_platform_link_get_by_ifname (NMPlatform *self, const char *ifname)
|
|
|
|
|
{
|
|
|
|
|
_CHECK_SELF (self, klass, NULL);
|
|
|
|
|
|
2015-06-21 15:05:52 +02:00
|
|
|
if (ifname && *ifname)
|
|
|
|
|
return klass->link_get_by_ifname (self, ifname);
|
|
|
|
|
return NULL;
|
2014-04-22 16:02:15 +02:00
|
|
|
}
|
|
|
|
|
|
2014-09-18 12:16:11 -05:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_get_by_address:
|
|
|
|
|
* @self: platform instance
|
|
|
|
|
* @address: a pointer to the binary hardware address
|
|
|
|
|
* @length: the size of @address in bytes
|
|
|
|
|
*
|
2015-06-20 12:05:01 +02:00
|
|
|
* Returns: the first #NMPlatformLink object with a matching
|
|
|
|
|
* address.
|
2014-09-18 12:16:11 -05:00
|
|
|
**/
|
2015-06-20 12:05:01 +02:00
|
|
|
const NMPlatformLink *
|
2014-09-18 12:16:11 -05:00
|
|
|
nm_platform_link_get_by_address (NMPlatform *self,
|
|
|
|
|
gconstpointer address,
|
2015-06-20 12:05:01 +02:00
|
|
|
size_t length)
|
2014-09-18 12:16:11 -05:00
|
|
|
{
|
2015-06-20 12:05:01 +02:00
|
|
|
_CHECK_SELF (self, klass, NULL);
|
2014-09-18 12:16:11 -05:00
|
|
|
|
2015-06-21 15:05:52 +02:00
|
|
|
g_return_val_if_fail (length == 0 || address, NULL);
|
|
|
|
|
if (length > 0) {
|
|
|
|
|
if (length > NM_UTILS_HWADDR_LEN_MAX)
|
|
|
|
|
g_return_val_if_reached (NULL);
|
|
|
|
|
return klass->link_get_by_address (self, address, length);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
2014-09-18 12:16:11 -05:00
|
|
|
}
|
|
|
|
|
|
2015-06-15 16:19:19 +02:00
|
|
|
static NMPlatformError
|
2015-12-09 15:13:57 +01:00
|
|
|
_link_add_check_existing (NMPlatform *self, const char *name, NMLinkType type, const NMPlatformLink **out_link)
|
2015-06-15 16:19:19 +02:00
|
|
|
{
|
2015-06-20 12:05:01 +02:00
|
|
|
const NMPlatformLink *pllink;
|
|
|
|
|
|
|
|
|
|
pllink = nm_platform_link_get_by_ifname (self, name);
|
|
|
|
|
if (pllink) {
|
|
|
|
|
gboolean wrong_type;
|
|
|
|
|
|
|
|
|
|
wrong_type = type != NM_LINK_TYPE_NONE && pllink->type != type;
|
2015-07-02 14:35:38 +02:00
|
|
|
_LOGD ("link: skip adding link due to existing interface '%s' of type %s%s%s",
|
2015-06-20 12:05:01 +02:00
|
|
|
name,
|
|
|
|
|
nm_link_type_to_string (pllink->type),
|
|
|
|
|
wrong_type ? ", expected " : "",
|
|
|
|
|
wrong_type ? nm_link_type_to_string (type) : "");
|
|
|
|
|
if (out_link)
|
2015-12-09 15:13:57 +01:00
|
|
|
*out_link = pllink;
|
2015-06-20 12:05:01 +02:00
|
|
|
if (wrong_type)
|
|
|
|
|
return NM_PLATFORM_ERROR_WRONG_TYPE;
|
|
|
|
|
return NM_PLATFORM_ERROR_EXISTS;
|
2015-06-15 16:19:19 +02:00
|
|
|
}
|
2015-12-09 15:13:57 +01:00
|
|
|
if (out_link)
|
|
|
|
|
*out_link = NULL;
|
2015-06-15 16:19:19 +02:00
|
|
|
return NM_PLATFORM_ERROR_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-27 22:23:24 +01:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_add:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:23:24 +01:00
|
|
|
* @name: Interface name
|
|
|
|
|
* @type: Interface type
|
2014-05-13 18:13:52 +02:00
|
|
|
* @address: (allow-none): set the mac address of the link
|
|
|
|
|
* @address_len: the length of the @address
|
2014-09-18 12:53:19 -05:00
|
|
|
* @out_link: on success, the link object
|
2013-03-27 22:23:24 +01:00
|
|
|
*
|
2014-09-18 12:53:19 -05:00
|
|
|
* Add a software interface. If the interface already exists and is of type
|
2015-06-15 16:19:19 +02:00
|
|
|
* @type, return NM_PLATFORM_ERROR_EXISTS and returns the link
|
2014-09-18 12:53:19 -05:00
|
|
|
* in @out_link. If the interface already exists and is not of type @type,
|
2015-06-15 16:19:19 +02:00
|
|
|
* return NM_PLATFORM_ERROR_WRONG_TYPE.
|
|
|
|
|
*
|
|
|
|
|
* Any link-changed ADDED signal will be emitted directly, before this
|
|
|
|
|
* function finishes.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the error reason or NM_PLATFORM_ERROR_SUCCESS.
|
2013-03-27 22:23:24 +01:00
|
|
|
*/
|
2015-06-15 16:19:19 +02:00
|
|
|
static NMPlatformError
|
2014-09-18 12:53:19 -05:00
|
|
|
nm_platform_link_add (NMPlatform *self,
|
|
|
|
|
const char *name,
|
|
|
|
|
NMLinkType type,
|
|
|
|
|
const void *address,
|
|
|
|
|
size_t address_len,
|
2015-12-09 15:13:57 +01:00
|
|
|
const NMPlatformLink **out_link)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
2015-06-15 16:19:19 +02:00
|
|
|
NMPlatformError plerr;
|
2014-09-18 12:53:19 -05:00
|
|
|
|
2015-06-15 16:19:19 +02:00
|
|
|
_CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-06-15 16:19:19 +02:00
|
|
|
g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
g_return_val_if_fail ( (address != NULL) ^ (address_len == 0) , NM_PLATFORM_ERROR_BUG);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-06-15 16:19:19 +02:00
|
|
|
plerr = _link_add_check_existing (self, name, type, out_link);
|
|
|
|
|
if (plerr != NM_PLATFORM_ERROR_SUCCESS)
|
|
|
|
|
return plerr;
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-07-02 14:35:38 +02:00
|
|
|
_LOGD ("link: adding %s '%s'", nm_link_type_to_string (type), name);
|
platform: drop nm_platform_get_error()
For NMPlatform instances we had an error reporting mechanism
which stores the last error reason in a private field. Later we
would check it via nm_platform_get_error().
Remove this. It was not used much, and it is not a great way
to report errors.
One problem is that at the point where the error happens, you don't
know whether anybody cares about an error code. So, you add code to set
the error reason because somebody *might* need it (but in realitiy, almost
no caller cares).
Also, we tested this functionality which is hardly used in non-testing code.
While this was a burden to maintain in the tests, it was likely still buggy
because there were no real use-cases, beside the tests.
Then, sometimes platform functions call each other which might overwrite the
error reason. So, every function must be cautious to preserve/set
the error reason according to it's own meaning. This can involve storing
the error code, calling another function, and restoring it afterwards.
This is harder to get right compared to a "return-error-code" pattern, where
every function manages its error code independently.
It is better to return the error reason whenever due. For that we already
have our common glib patterns
(1) gboolean fcn (...);
(2) gboolean fcn (..., GError **error);
In few cases, we need more details then a #gboolean, but don't want
to bother constructing a #GError. Then we should do instead:
(3) NMPlatformError fcn (...);
2015-06-15 17:58:36 +02:00
|
|
|
if (!klass->link_add (self, name, type, address, address_len, out_link))
|
2015-06-15 16:19:19 +02:00
|
|
|
return NM_PLATFORM_ERROR_UNSPECIFIED;
|
|
|
|
|
return NM_PLATFORM_ERROR_SUCCESS;
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-12-09 16:14:49 +01:00
|
|
|
* nm_platform_link_dummy_add:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:23:24 +01:00
|
|
|
* @name: New interface name
|
2014-09-18 12:53:19 -05:00
|
|
|
* @out_link: on success, the link object
|
2013-03-27 22:23:24 +01:00
|
|
|
*
|
|
|
|
|
* Create a software ethernet-like interface
|
|
|
|
|
*/
|
2015-06-15 16:19:19 +02:00
|
|
|
NMPlatformError
|
2015-12-11 13:34:50 +01:00
|
|
|
nm_platform_link_dummy_add (NMPlatform *self,
|
|
|
|
|
const char *name,
|
|
|
|
|
const NMPlatformLink **out_link)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
2014-09-18 12:53:19 -05:00
|
|
|
return nm_platform_link_add (self, name, NM_LINK_TYPE_DUMMY, NULL, 0, out_link);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_link_delete:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:23:24 +01:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_delete (NMPlatform *self, int ifindex)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
2015-06-20 12:05:01 +02:00
|
|
|
const NMPlatformLink *pllink;
|
2013-03-27 22:23:24 +01:00
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-06-20 12:05:01 +02:00
|
|
|
pllink = nm_platform_link_get (self, ifindex);
|
|
|
|
|
if (!pllink)
|
2013-03-27 22:23:24 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
2015-07-02 14:35:38 +02:00
|
|
|
_LOGD ("link: deleting '%s' (%d)", pllink->name, ifindex);
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->link_delete (self, ifindex);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
2016-03-08 13:02:58 +01:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_set_netns:
|
|
|
|
|
* @self: platform instance
|
|
|
|
|
* @ifindex: Interface index
|
|
|
|
|
* @netns_fd: the file descriptor for the new netns.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
nm_platform_link_set_netns (NMPlatform *self, int ifindex, int netns_fd)
|
|
|
|
|
{
|
|
|
|
|
const NMPlatformLink *pllink;
|
|
|
|
|
|
|
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
|
|
|
|
g_return_val_if_fail (netns_fd > 0, FALSE);
|
|
|
|
|
|
|
|
|
|
pllink = nm_platform_link_get (self, ifindex);
|
|
|
|
|
if (!pllink)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
_LOGD ("link: ifindex %d changing network namespace to %d", ifindex, netns_fd);
|
|
|
|
|
return klass->link_set_netns (self, ifindex, netns_fd);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-27 22:23:24 +01:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_get_index:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:23:24 +01:00
|
|
|
* @name: Interface name
|
|
|
|
|
*
|
|
|
|
|
* Returns: The interface index corresponding to the given interface name
|
|
|
|
|
* or 0. Inteface name is owned by #NMPlatform, don't free it.
|
|
|
|
|
*/
|
|
|
|
|
int
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_get_ifindex (NMPlatform *self, const char *name)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
2015-06-20 12:05:01 +02:00
|
|
|
const NMPlatformLink *pllink;
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-06-20 12:05:01 +02:00
|
|
|
pllink = nm_platform_link_get_by_ifname (self, name);
|
|
|
|
|
return pllink ? pllink->ifindex : 0;
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_link_get_name:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:23:24 +01:00
|
|
|
* @name: Interface name
|
|
|
|
|
*
|
|
|
|
|
* Returns: The interface name corresponding to the given interface index
|
2013-04-19 15:48:01 +02:00
|
|
|
* or %NULL.
|
2013-03-27 22:23:24 +01:00
|
|
|
*/
|
|
|
|
|
const char *
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_get_name (NMPlatform *self, int ifindex)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
2015-06-20 12:05:01 +02:00
|
|
|
const NMPlatformLink *pllink;
|
2013-03-27 22:23:24 +01:00
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, NULL);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-06-20 12:05:01 +02:00
|
|
|
pllink = nm_platform_link_get (self, ifindex);
|
|
|
|
|
return pllink ? pllink->name : NULL;
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_link_get_type:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:23:24 +01:00
|
|
|
* @ifindex: Interface index.
|
|
|
|
|
*
|
|
|
|
|
* Returns: Link type constant as defined in nm-platform.h. On error,
|
|
|
|
|
* NM_LINK_TYPE_NONE is returned.
|
|
|
|
|
*/
|
|
|
|
|
NMLinkType
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_get_type (NMPlatform *self, int ifindex)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
2015-06-20 12:05:01 +02:00
|
|
|
const NMPlatformLink *pllink;
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-06-20 12:05:01 +02:00
|
|
|
_CHECK_SELF (self, klass, NM_LINK_TYPE_NONE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-06-20 12:05:01 +02:00
|
|
|
pllink = nm_platform_link_get (self, ifindex);
|
|
|
|
|
return pllink ? pllink->type : NM_LINK_TYPE_NONE;
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
2013-04-26 11:43:08 -04:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_get_type_name:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-04-26 11:43:08 -04:00
|
|
|
* @ifindex: Interface index.
|
|
|
|
|
*
|
|
|
|
|
* Returns: A string describing the type of link. In some cases this
|
|
|
|
|
* may be more specific than nm_platform_link_get_type(), but in
|
|
|
|
|
* other cases it may not. On error, %NULL is returned.
|
|
|
|
|
*/
|
|
|
|
|
const char *
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_get_type_name (NMPlatform *self, int ifindex)
|
2013-04-26 11:43:08 -04:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, NULL);
|
2013-04-26 11:43:08 -04:00
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->link_get_type_name (self, ifindex);
|
2013-04-26 11:43:08 -04:00
|
|
|
}
|
|
|
|
|
|
2015-01-22 16:41:15 +01:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_get_unmanaged:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2015-06-24 14:21:27 +02:00
|
|
|
* @ifindex: interface index
|
|
|
|
|
* @unmanaged: management status (in case %TRUE is returned)
|
2015-01-22 16:41:15 +01:00
|
|
|
*
|
2015-06-24 14:21:27 +02:00
|
|
|
* Returns: %TRUE if platform overrides NM default-unmanaged status,
|
|
|
|
|
* %FALSE otherwise (with @unmanaged unmodified).
|
2015-01-22 16:41:15 +01:00
|
|
|
*/
|
|
|
|
|
gboolean
|
2015-06-24 14:21:27 +02:00
|
|
|
nm_platform_link_get_unmanaged (NMPlatform *self, int ifindex, gboolean *unmanaged)
|
2015-01-22 16:41:15 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2015-01-22 16:41:15 +01:00
|
|
|
|
2015-06-20 12:05:01 +02:00
|
|
|
if (klass->link_get_unmanaged)
|
2015-06-24 14:21:27 +02:00
|
|
|
return klass->link_get_unmanaged (self, ifindex, unmanaged);
|
2015-06-20 12:05:01 +02:00
|
|
|
return FALSE;
|
2015-01-22 16:41:15 +01:00
|
|
|
}
|
|
|
|
|
|
2013-06-20 12:48:44 +02:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_is_software:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-06-20 12:48:44 +02:00
|
|
|
* @ifindex: Interface index.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if ifindex belongs to a software interface, not backed by
|
|
|
|
|
* a physical device.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_is_software (NMPlatform *self, int ifindex)
|
2013-06-20 12:48:44 +02:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return (nm_platform_link_get_type (self, ifindex) & 0x10000);
|
2013-06-20 12:48:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_link_supports_slaves:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-06-20 12:48:44 +02:00
|
|
|
* @ifindex: Interface index.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if ifindex belongs to an interface capable of enslaving
|
|
|
|
|
* other interfaces.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_supports_slaves (NMPlatform *self, int ifindex)
|
2013-06-20 12:48:44 +02:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return (nm_platform_link_get_type (self, ifindex) & 0x20000);
|
2013-06-20 12:48:44 +02:00
|
|
|
}
|
2013-04-26 11:43:08 -04:00
|
|
|
|
2014-02-11 13:58:00 +01:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_refresh:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2014-02-11 13:58:00 +01:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
*
|
|
|
|
|
* Reload the cache for ifindex synchronously.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_refresh (NMPlatform *self, int ifindex)
|
2014-02-11 13:58:00 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2014-02-11 13:58:00 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
|
|
|
|
|
|
|
|
|
if (klass->link_refresh)
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->link_refresh (self, ifindex);
|
2014-02-11 13:58:00 +01:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-29 15:36:12 +01:00
|
|
|
static guint
|
2015-06-20 12:05:01 +02:00
|
|
|
_link_get_flags (NMPlatform *self, int ifindex)
|
|
|
|
|
{
|
|
|
|
|
const NMPlatformLink *pllink;
|
|
|
|
|
|
|
|
|
|
pllink = nm_platform_link_get (self, ifindex);
|
2016-02-29 15:52:27 +01:00
|
|
|
return pllink ? pllink->n_ifi_flags : IFF_NOARP;
|
2015-06-20 12:05:01 +02:00
|
|
|
}
|
|
|
|
|
|
2013-03-27 22:23:24 +01:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_is_up:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:23:24 +01:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
*
|
|
|
|
|
* Check if the interface is up.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_is_up (NMPlatform *self, int ifindex)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-06-20 12:05:01 +02:00
|
|
|
return NM_FLAGS_HAS (_link_get_flags (self, ifindex), IFF_UP);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_link_is_connected:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:23:24 +01:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
*
|
|
|
|
|
* Check if the interface is connected.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_is_connected (NMPlatform *self, int ifindex)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
2015-06-20 12:05:01 +02:00
|
|
|
const NMPlatformLink *pllink;
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-06-20 12:05:01 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-06-20 12:05:01 +02:00
|
|
|
pllink = nm_platform_link_get (self, ifindex);
|
|
|
|
|
return pllink ? pllink->connected : FALSE;
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_link_uses_arp:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:23:24 +01:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
*
|
|
|
|
|
* Check if the interface is configured to use ARP.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_uses_arp (NMPlatform *self, int ifindex)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-06-20 12:05:01 +02:00
|
|
|
return !NM_FLAGS_HAS (_link_get_flags (self, ifindex), IFF_NOARP);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
2014-09-27 09:03:56 +02:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_get_ipv6_token:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2014-09-27 09:03:56 +02:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
* @iid: Tokenized interface identifier
|
|
|
|
|
*
|
|
|
|
|
* Returns IPv6 tokenized interface identifier. If the platform or OS doesn't
|
|
|
|
|
* support IPv6 tokenized interface identifiers, or the token is not set
|
|
|
|
|
* this call will fail and return %FALSE.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE a tokenized identifier was available
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_get_ipv6_token (NMPlatform *self, int ifindex, NMUtilsIPv6IfaceId *iid)
|
2014-09-27 09:03:56 +02:00
|
|
|
{
|
2015-10-20 09:27:16 +02:00
|
|
|
const NMPlatformLink *pllink;
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2014-09-27 09:03:56 +02:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex >= 0, FALSE);
|
|
|
|
|
g_return_val_if_fail (iid, FALSE);
|
|
|
|
|
|
2015-06-20 12:05:01 +02:00
|
|
|
|
2015-10-20 09:27:16 +02:00
|
|
|
pllink = nm_platform_link_get (self, ifindex);
|
|
|
|
|
if (pllink && pllink->inet6_token.is_valid) {
|
|
|
|
|
*iid = pllink->inet6_token.iid;
|
|
|
|
|
return TRUE;
|
2015-06-20 12:05:01 +02:00
|
|
|
}
|
2014-09-27 09:03:56 +02:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-15 14:41:35 +02:00
|
|
|
const char *
|
|
|
|
|
nm_platform_link_get_udi (NMPlatform *self, int ifindex)
|
|
|
|
|
{
|
|
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex >= 0, NULL);
|
|
|
|
|
|
|
|
|
|
if (klass->link_get_udi)
|
|
|
|
|
return klass->link_get_udi (self, ifindex);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2014-09-27 09:03:56 +02:00
|
|
|
|
2015-06-15 15:19:28 +02:00
|
|
|
GObject *
|
|
|
|
|
nm_platform_link_get_udev_device (NMPlatform *self, int ifindex)
|
|
|
|
|
{
|
|
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex >= 0, NULL);
|
|
|
|
|
|
|
|
|
|
if (klass->link_get_udev_device)
|
|
|
|
|
return klass->link_get_udev_device (self, ifindex);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-24 15:57:08 -05:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_get_user_ip6vll_enabled:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2014-07-24 15:57:08 -05:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
*
|
|
|
|
|
* Check whether NM handles IPv6LL address creation for the link. If the
|
|
|
|
|
* platform or OS doesn't support changing the IPv6LL address mode, this call
|
|
|
|
|
* will fail and return %FALSE.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if NM handles the IPv6LL address for @ifindex
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_get_user_ipv6ll_enabled (NMPlatform *self, int ifindex)
|
2014-07-24 15:57:08 -05:00
|
|
|
{
|
2015-10-12 16:07:01 +02:00
|
|
|
const NMPlatformLink *pllink;
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2014-07-24 15:57:08 -05:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex >= 0, FALSE);
|
|
|
|
|
|
2015-10-12 16:07:01 +02:00
|
|
|
pllink = nm_platform_link_get (self, ifindex);
|
|
|
|
|
if (pllink && pllink->inet6_addr_gen_mode_inv)
|
|
|
|
|
return _nm_platform_uint8_inv (pllink->inet6_addr_gen_mode_inv) == NM_IN6_ADDR_GEN_MODE_NONE;
|
2014-07-24 15:57:08 -05:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_link_set_user_ip6vll_enabled:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2014-07-24 15:57:08 -05:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
*
|
|
|
|
|
* Set whether NM handles IPv6LL address creation for the link. If the
|
|
|
|
|
* platform or OS doesn't support changing the IPv6LL address mode, this call
|
|
|
|
|
* will fail and return %FALSE.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE if the operation was successful, %FALSE if it failed.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_set_user_ipv6ll_enabled (NMPlatform *self, int ifindex, gboolean enabled)
|
2014-07-24 15:57:08 -05:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2014-07-24 15:57:08 -05:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex >= 0, FALSE);
|
|
|
|
|
|
|
|
|
|
if (klass->link_set_user_ipv6ll_enabled)
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->link_set_user_ipv6ll_enabled (self, ifindex, enabled);
|
2014-07-24 15:57:08 -05:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-27 22:53:55 +01:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_set_address:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:53:55 +01:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
* @address: The new MAC address
|
|
|
|
|
*
|
|
|
|
|
* Set interface MAC address.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_set_address (NMPlatform *self, int ifindex, gconstpointer address, size_t length)
|
2013-03-27 22:53:55 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:53:55 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
|
|
|
|
g_return_val_if_fail (address, FALSE);
|
|
|
|
|
g_return_val_if_fail (length > 0, FALSE);
|
|
|
|
|
|
2015-07-02 14:35:38 +02:00
|
|
|
_LOGD ("link: setting '%s' (%d) hardware address", nm_platform_link_get_name (self, ifindex), ifindex);
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->link_set_address (self, ifindex, address, length);
|
2013-03-27 22:53:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_link_get_address:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:53:55 +01:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
* @length: Pointer to a variable to store address length
|
|
|
|
|
*
|
2014-10-03 17:37:26 -05:00
|
|
|
* Returns: the interface hardware address as an array of bytes of
|
|
|
|
|
* length @length.
|
2013-03-27 22:53:55 +01:00
|
|
|
*/
|
|
|
|
|
gconstpointer
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_get_address (NMPlatform *self, int ifindex, size_t *length)
|
2013-03-27 22:53:55 +01:00
|
|
|
{
|
2015-06-20 12:05:01 +02:00
|
|
|
const NMPlatformLink *pllink;
|
|
|
|
|
gconstpointer a = NULL;
|
|
|
|
|
guint8 l = 0;
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, NULL);
|
2013-03-27 22:53:55 +01:00
|
|
|
|
|
|
|
|
if (length)
|
|
|
|
|
*length = 0;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, NULL);
|
|
|
|
|
|
2015-06-20 12:05:01 +02:00
|
|
|
pllink = nm_platform_link_get (self, ifindex);
|
|
|
|
|
if (pllink && pllink->addr.len > 0) {
|
|
|
|
|
if (pllink->addr.len > NM_UTILS_HWADDR_LEN_MAX) {
|
|
|
|
|
if (length)
|
|
|
|
|
*length = 0;
|
|
|
|
|
g_return_val_if_reached (NULL);
|
|
|
|
|
}
|
|
|
|
|
a = pllink->addr.data;
|
|
|
|
|
l = pllink->addr.len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (length)
|
|
|
|
|
*length = l;
|
|
|
|
|
return a;
|
2013-03-27 22:53:55 +01:00
|
|
|
}
|
|
|
|
|
|
2014-10-03 17:37:26 -05:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_get_permanent_address:
|
|
|
|
|
* @self: platform instance
|
|
|
|
|
* @ifindex: Interface index
|
|
|
|
|
* @buf: buffer of at least %NM_UTILS_HWADDR_LEN_MAX bytes, on success
|
|
|
|
|
* the permanent hardware address
|
|
|
|
|
* @length: Pointer to a variable to store address length
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on success, %FALSE on failure to read the permanent hardware
|
|
|
|
|
* address.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
nm_platform_link_get_permanent_address (NMPlatform *self, int ifindex, guint8 *buf, size_t *length)
|
|
|
|
|
{
|
|
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
|
|
|
|
|
|
|
|
|
if (length)
|
|
|
|
|
*length = 0;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
|
|
|
|
g_return_val_if_fail (buf, FALSE);
|
|
|
|
|
g_return_val_if_fail (length, FALSE);
|
|
|
|
|
|
2015-06-20 12:05:01 +02:00
|
|
|
if (klass->link_get_permanent_address)
|
|
|
|
|
return klass->link_get_permanent_address (self, ifindex, buf, length);
|
|
|
|
|
return FALSE;
|
2014-10-03 17:37:26 -05:00
|
|
|
}
|
|
|
|
|
|
2013-03-27 22:53:55 +01:00
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_supports_carrier_detect (NMPlatform *self, int ifindex)
|
2013-03-27 22:53:55 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
|
|
|
|
|
2013-03-27 22:53:55 +01:00
|
|
|
g_return_val_if_fail (ifindex >= 0, FALSE);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->link_supports_carrier_detect (self, ifindex);
|
2013-03-27 22:53:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_supports_vlans (NMPlatform *self, int ifindex)
|
2013-03-27 22:53:55 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
|
|
|
|
|
2013-03-27 22:53:55 +01:00
|
|
|
g_return_val_if_fail (ifindex >= 0, FALSE);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->link_supports_vlans (self, ifindex);
|
2013-03-27 22:53:55 +01:00
|
|
|
}
|
|
|
|
|
|
2013-03-27 22:23:24 +01:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_set_up:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:23:24 +01:00
|
|
|
* @ifindex: Interface index
|
2015-06-15 17:41:27 +02:00
|
|
|
* @out_no_firmware: (allow-none): if the failure reason is due to missing firmware.
|
2013-03-27 22:23:24 +01:00
|
|
|
*
|
|
|
|
|
* Bring the interface up.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2015-06-15 17:41:27 +02:00
|
|
|
nm_platform_link_set_up (NMPlatform *self, int ifindex, gboolean *out_no_firmware)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
|
|
|
|
|
2015-07-02 14:35:38 +02:00
|
|
|
_LOGD ("link: setting up '%s' (%d)", nm_platform_link_get_name (self, ifindex), ifindex);
|
2015-06-15 17:41:27 +02:00
|
|
|
return klass->link_set_up (self, ifindex, out_no_firmware);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_link_set_down:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:23:24 +01:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
*
|
|
|
|
|
* Take the interface down.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_set_down (NMPlatform *self, int ifindex)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
|
|
|
|
|
2015-07-02 14:35:38 +02:00
|
|
|
_LOGD ("link: setting down '%s' (%d)", nm_platform_link_get_name (self, ifindex), ifindex);
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->link_set_down (self, ifindex);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_link_set_arp:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:23:24 +01:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
*
|
|
|
|
|
* Enable ARP on the interface.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_set_arp (NMPlatform *self, int ifindex)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex >= 0, FALSE);
|
|
|
|
|
|
2015-07-02 14:35:38 +02:00
|
|
|
_LOGD ("link: setting arp '%s' (%d)", nm_platform_link_get_name (self, ifindex), ifindex);
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->link_set_arp (self, ifindex);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_link_set_noarp:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:23:24 +01:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
*
|
|
|
|
|
* Disable ARP on the interface.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_set_noarp (NMPlatform *self, int ifindex)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex >= 0, FALSE);
|
|
|
|
|
|
2015-07-02 14:35:38 +02:00
|
|
|
_LOGD ("link: setting noarp '%s' (%d)", nm_platform_link_get_name (self, ifindex), ifindex);
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->link_set_noarp (self, ifindex);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
2013-04-15 21:48:12 +02:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_set_mtu:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-04-15 21:48:12 +02:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
* @mtu: The new MTU value
|
|
|
|
|
*
|
|
|
|
|
* Set interface MTU.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_set_mtu (NMPlatform *self, int ifindex, guint32 mtu)
|
2013-04-15 21:48:12 +02:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-04-15 21:48:12 +02:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex >= 0, FALSE);
|
|
|
|
|
g_return_val_if_fail (mtu > 0, FALSE);
|
|
|
|
|
|
2015-07-02 14:35:38 +02:00
|
|
|
_LOGD ("link: setting '%s' (%d) mtu %"G_GUINT32_FORMAT, nm_platform_link_get_name (self, ifindex), ifindex, mtu);
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->link_set_mtu (self, ifindex, mtu);
|
2013-04-15 21:48:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_link_get_mtu:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-04-15 21:48:12 +02:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
*
|
|
|
|
|
* Returns: MTU value for the interface or 0 on error.
|
|
|
|
|
*/
|
|
|
|
|
guint32
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_get_mtu (NMPlatform *self, int ifindex)
|
2013-04-15 21:48:12 +02:00
|
|
|
{
|
2015-06-20 12:05:01 +02:00
|
|
|
const NMPlatformLink *pllink;
|
2013-04-15 21:48:12 +02:00
|
|
|
|
2015-06-20 12:05:01 +02:00
|
|
|
_CHECK_SELF (self, klass, 0);
|
2013-04-15 21:48:12 +02:00
|
|
|
|
2015-06-20 12:05:01 +02:00
|
|
|
pllink = nm_platform_link_get (self, ifindex);
|
|
|
|
|
return pllink ? pllink->mtu : 0;
|
2013-04-15 21:48:12 +02:00
|
|
|
}
|
|
|
|
|
|
2013-10-11 14:59:26 -04:00
|
|
|
/**
|
2015-03-24 12:18:48 -05:00
|
|
|
* nm_platform_link_get_physical_port_id:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-10-11 14:59:26 -04:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
*
|
2015-03-24 12:18:48 -05:00
|
|
|
* The physical port ID, if present, indicates some unique identifier of
|
|
|
|
|
* the parent interface (eg, the physical port of which this link is a child).
|
|
|
|
|
* Two links that report the same physical port ID can be assumed to be
|
|
|
|
|
* children of the same physical port and may share resources that limit
|
|
|
|
|
* their abilities.
|
|
|
|
|
*
|
2013-10-11 14:59:26 -04:00
|
|
|
* Returns: physical port ID for the interface, or %NULL on error
|
|
|
|
|
* or if the interface has no physical port ID.
|
|
|
|
|
*/
|
|
|
|
|
char *
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_get_physical_port_id (NMPlatform *self, int ifindex)
|
2013-10-11 14:59:26 -04:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, NULL);
|
2013-10-11 14:59:26 -04:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex >= 0, NULL);
|
|
|
|
|
|
2015-06-20 12:05:01 +02:00
|
|
|
if (klass->link_get_physical_port_id)
|
|
|
|
|
return klass->link_get_physical_port_id (self, ifindex);
|
|
|
|
|
return NULL;
|
2013-10-11 14:59:26 -04:00
|
|
|
}
|
|
|
|
|
|
2015-03-24 12:35:36 -05:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_get_dev_id:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2015-03-24 12:35:36 -05:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
*
|
|
|
|
|
* In contrast to the physical device ID (which indicates which parent a
|
|
|
|
|
* child has) the device ID differentiates sibling devices that may share
|
|
|
|
|
* the same MAC address.
|
|
|
|
|
*
|
|
|
|
|
* Returns: device ID for the interface, or 0 on error or if the
|
|
|
|
|
* interface has no device ID.
|
|
|
|
|
*/
|
|
|
|
|
guint
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_get_dev_id (NMPlatform *self, int ifindex)
|
2015-03-24 12:35:36 -05:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, 0);
|
2015-03-24 12:35:36 -05:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex >= 0, 0);
|
|
|
|
|
|
2015-06-20 12:05:01 +02:00
|
|
|
if (klass->link_get_dev_id)
|
|
|
|
|
return klass->link_get_dev_id (self, ifindex);
|
|
|
|
|
return 0;
|
2015-03-24 12:35:36 -05:00
|
|
|
}
|
|
|
|
|
|
2014-02-05 11:56:44 +01:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_get_wake_onlan:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2014-02-05 11:56:44 +01:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
*
|
|
|
|
|
* Returns: the "Wake-on-LAN" status for @ifindex.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_get_wake_on_lan (NMPlatform *self, int ifindex)
|
2014-02-05 11:56:44 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2014-02-05 11:56:44 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex >= 0, FALSE);
|
|
|
|
|
|
2015-06-20 12:05:01 +02:00
|
|
|
if (klass->link_get_wake_on_lan)
|
|
|
|
|
return klass->link_get_wake_on_lan (self, ifindex);
|
|
|
|
|
return FALSE;
|
2014-02-05 11:56:44 +01:00
|
|
|
}
|
|
|
|
|
|
2014-10-03 13:41:49 -05:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_get_driver_info:
|
|
|
|
|
* @self: platform instance
|
|
|
|
|
* @ifindex: Interface index
|
|
|
|
|
* @out_driver_name: (transfer full): on success, the driver name if available
|
|
|
|
|
* @out_driver_version: (transfer full): on success, the driver version if available
|
|
|
|
|
* @out_fw_version: (transfer full): on success, the firmware version if available
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on success (though @out_driver_name, @out_driver_version and
|
|
|
|
|
* @out_fw_version can be %NULL if no information was available), %FALSE on
|
|
|
|
|
* failure.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
|
|
|
|
nm_platform_link_get_driver_info (NMPlatform *self,
|
|
|
|
|
int ifindex,
|
|
|
|
|
char **out_driver_name,
|
|
|
|
|
char **out_driver_version,
|
|
|
|
|
char **out_fw_version)
|
|
|
|
|
{
|
|
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex >= 0, FALSE);
|
|
|
|
|
|
|
|
|
|
return klass->link_get_driver_info (self,
|
|
|
|
|
ifindex,
|
|
|
|
|
out_driver_name,
|
|
|
|
|
out_driver_version,
|
|
|
|
|
out_fw_version);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-27 22:53:55 +01:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_enslave:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:53:55 +01:00
|
|
|
* @master: Interface index of the master
|
|
|
|
|
* @slave: Interface index of the slave
|
|
|
|
|
*
|
|
|
|
|
* Enslave @slave to @master.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_enslave (NMPlatform *self, int master, int slave)
|
2013-03-27 22:53:55 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:53:55 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (master > 0, FALSE);
|
|
|
|
|
g_return_val_if_fail (slave> 0, FALSE);
|
|
|
|
|
|
2015-07-02 14:35:38 +02:00
|
|
|
_LOGD ("link: enslaving '%s' (%d) to master '%s' (%d)",
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_get_name (self, slave), slave,
|
|
|
|
|
nm_platform_link_get_name (self, master), master);
|
|
|
|
|
return klass->link_enslave (self, master, slave);
|
2013-03-27 22:53:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_link_release:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:53:55 +01:00
|
|
|
* @master: Interface index of the master
|
|
|
|
|
* @slave: Interface index of the slave
|
|
|
|
|
*
|
|
|
|
|
* Release @slave from @master.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_release (NMPlatform *self, int master, int slave)
|
2013-03-27 22:53:55 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:53:55 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (master > 0, FALSE);
|
|
|
|
|
g_return_val_if_fail (slave > 0, FALSE);
|
|
|
|
|
|
platform: drop nm_platform_get_error()
For NMPlatform instances we had an error reporting mechanism
which stores the last error reason in a private field. Later we
would check it via nm_platform_get_error().
Remove this. It was not used much, and it is not a great way
to report errors.
One problem is that at the point where the error happens, you don't
know whether anybody cares about an error code. So, you add code to set
the error reason because somebody *might* need it (but in realitiy, almost
no caller cares).
Also, we tested this functionality which is hardly used in non-testing code.
While this was a burden to maintain in the tests, it was likely still buggy
because there were no real use-cases, beside the tests.
Then, sometimes platform functions call each other which might overwrite the
error reason. So, every function must be cautious to preserve/set
the error reason according to it's own meaning. This can involve storing
the error code, calling another function, and restoring it afterwards.
This is harder to get right compared to a "return-error-code" pattern, where
every function manages its error code independently.
It is better to return the error reason whenever due. For that we already
have our common glib patterns
(1) gboolean fcn (...);
(2) gboolean fcn (..., GError **error);
In few cases, we need more details then a #gboolean, but don't want
to bother constructing a #GError. Then we should do instead:
(3) NMPlatformError fcn (...);
2015-06-15 17:58:36 +02:00
|
|
|
if (nm_platform_link_get_master (self, slave) != master)
|
2013-03-27 22:53:55 +01:00
|
|
|
return FALSE;
|
|
|
|
|
|
2015-07-02 14:35:38 +02:00
|
|
|
_LOGD ("link: releasing '%s' (%d) from master '%s' (%d)",
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_get_name (self, slave), slave,
|
|
|
|
|
nm_platform_link_get_name (self, master), master);
|
|
|
|
|
return klass->link_release (self, master, slave);
|
2013-03-27 22:53:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_link_get_master:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:53:55 +01:00
|
|
|
* @slave: Interface index of the slave.
|
|
|
|
|
*
|
|
|
|
|
* Returns: Interfase index of the slave's master.
|
|
|
|
|
*/
|
|
|
|
|
int
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_link_get_master (NMPlatform *self, int slave)
|
2013-03-27 22:53:55 +01:00
|
|
|
{
|
2015-06-20 12:05:01 +02:00
|
|
|
const NMPlatformLink *pllink;
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, 0);
|
2013-03-27 22:53:55 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (slave >= 0, FALSE);
|
|
|
|
|
|
2015-06-20 12:05:01 +02:00
|
|
|
pllink = nm_platform_link_get (self, slave);
|
|
|
|
|
return pllink ? pllink->master : 0;
|
2013-03-27 22:53:55 +01:00
|
|
|
}
|
|
|
|
|
|
2015-10-12 13:44:44 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2016-03-21 15:22:10 +01:00
|
|
|
gboolean
|
|
|
|
|
nm_platform_link_can_assume (NMPlatform *self, int ifindex)
|
|
|
|
|
{
|
|
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
|
|
|
|
|
|
|
|
|
if (klass->link_can_assume)
|
|
|
|
|
return klass->link_can_assume (self, ifindex);
|
|
|
|
|
g_return_val_if_reached (FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-10-29 11:27:55 +01:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_get_lnk:
|
|
|
|
|
* @self: the platform instance
|
|
|
|
|
* @ifindex: the link ifindex to lookup
|
|
|
|
|
* @link_type: filter by link-type.
|
|
|
|
|
* @out_link: (allow-none): returns the platform link instance
|
|
|
|
|
*
|
|
|
|
|
* If the function returns %NULL, that could mean that no such ifindex
|
|
|
|
|
* exists, of that the link has no lnk data. You can find that out
|
|
|
|
|
* by checking @out_link. @out_link will always be set if a link
|
|
|
|
|
* with @ifindex exists.
|
|
|
|
|
*
|
|
|
|
|
* If @link_type is %NM_LINK_TYPE_NONE, the function returns the lnk
|
|
|
|
|
* object if it is present. If you set link-type, you can be sure
|
|
|
|
|
* that only a link type of the matching type is returned (or %NULL).
|
|
|
|
|
*
|
|
|
|
|
* Returns: the internal link lnk object. The returned object
|
|
|
|
|
* is owned by the platform cache and must not be modified. Note
|
|
|
|
|
* however, that the object is guaranteed to be immutable, so
|
|
|
|
|
* you can savely take a reference and keep it for yourself
|
|
|
|
|
* (but don't modify it).
|
|
|
|
|
*/
|
|
|
|
|
const NMPObject *
|
2015-10-12 13:44:44 +02:00
|
|
|
nm_platform_link_get_lnk (NMPlatform *self, int ifindex, NMLinkType link_type, const NMPlatformLink **out_link)
|
|
|
|
|
{
|
|
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
|
|
|
|
|
|
|
|
|
NM_SET_OUT (out_link, NULL);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, NULL);
|
|
|
|
|
|
|
|
|
|
return klass->link_get_lnk (self, ifindex, link_type, out_link);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-29 11:27:55 +01:00
|
|
|
static gconstpointer
|
|
|
|
|
_link_get_lnk (NMPlatform *self, int ifindex, NMLinkType link_type, const NMPlatformLink **out_link)
|
|
|
|
|
{
|
|
|
|
|
const NMPObject *lnk;
|
|
|
|
|
|
|
|
|
|
lnk = nm_platform_link_get_lnk (self, ifindex, link_type, out_link);
|
|
|
|
|
return lnk ? &lnk->object : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
const NMPlatformLnkGre *
|
|
|
|
|
nm_platform_link_get_lnk_gre (NMPlatform *self, int ifindex, const NMPlatformLink **out_link)
|
|
|
|
|
{
|
2015-10-29 11:27:55 +01:00
|
|
|
return _link_get_lnk (self, ifindex, NM_LINK_TYPE_GRE, out_link);
|
2015-10-12 15:15:21 +02:00
|
|
|
}
|
|
|
|
|
|
2015-10-15 15:47:14 +02:00
|
|
|
const NMPlatformLnkInfiniband *
|
|
|
|
|
nm_platform_link_get_lnk_infiniband (NMPlatform *self, int ifindex, const NMPlatformLink **out_link)
|
|
|
|
|
{
|
2015-10-29 11:27:55 +01:00
|
|
|
return _link_get_lnk (self, ifindex, NM_LINK_TYPE_INFINIBAND, out_link);
|
2015-10-15 15:47:14 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-27 22:22:25 +01:00
|
|
|
const NMPlatformLnkIp6Tnl *
|
|
|
|
|
nm_platform_link_get_lnk_ip6tnl (NMPlatform *self, int ifindex, const NMPlatformLink **out_link)
|
|
|
|
|
{
|
|
|
|
|
return _link_get_lnk (self, ifindex, NM_LINK_TYPE_IP6TNL, out_link);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-27 14:01:56 +01:00
|
|
|
const NMPlatformLnkIpIp *
|
|
|
|
|
nm_platform_link_get_lnk_ipip (NMPlatform *self, int ifindex, const NMPlatformLink **out_link)
|
|
|
|
|
{
|
|
|
|
|
return _link_get_lnk (self, ifindex, NM_LINK_TYPE_IPIP, out_link);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
const NMPlatformLnkMacvlan *
|
|
|
|
|
nm_platform_link_get_lnk_macvlan (NMPlatform *self, int ifindex, const NMPlatformLink **out_link)
|
|
|
|
|
{
|
2015-10-29 11:27:55 +01:00
|
|
|
return _link_get_lnk (self, ifindex, NM_LINK_TYPE_MACVLAN, out_link);
|
2015-10-12 15:15:21 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-04 09:49:39 +01:00
|
|
|
const NMPlatformLnkMacvtap *
|
|
|
|
|
nm_platform_link_get_lnk_macvtap (NMPlatform *self, int ifindex, const NMPlatformLink **out_link)
|
|
|
|
|
{
|
|
|
|
|
return _link_get_lnk (self, ifindex, NM_LINK_TYPE_MACVTAP, out_link);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-11 18:41:48 +01:00
|
|
|
const NMPlatformLnkSit *
|
|
|
|
|
nm_platform_link_get_lnk_sit (NMPlatform *self, int ifindex, const NMPlatformLink **out_link)
|
|
|
|
|
{
|
|
|
|
|
return _link_get_lnk (self, ifindex, NM_LINK_TYPE_SIT, out_link);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 13:44:44 +02:00
|
|
|
const NMPlatformLnkVlan *
|
|
|
|
|
nm_platform_link_get_lnk_vlan (NMPlatform *self, int ifindex, const NMPlatformLink **out_link)
|
|
|
|
|
{
|
2015-10-29 11:27:55 +01:00
|
|
|
return _link_get_lnk (self, ifindex, NM_LINK_TYPE_VLAN, out_link);
|
2015-10-12 13:44:44 +02:00
|
|
|
}
|
|
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
const NMPlatformLnkVxlan *
|
|
|
|
|
nm_platform_link_get_lnk_vxlan (NMPlatform *self, int ifindex, const NMPlatformLink **out_link)
|
|
|
|
|
{
|
2015-10-29 11:27:55 +01:00
|
|
|
return _link_get_lnk (self, ifindex, NM_LINK_TYPE_VXLAN, out_link);
|
2015-10-12 15:15:21 +02:00
|
|
|
}
|
|
|
|
|
|
2015-10-12 13:44:44 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2013-03-27 22:53:55 +01:00
|
|
|
/**
|
2015-12-09 16:14:49 +01:00
|
|
|
* nm_platform_link_bridge_add:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:53:55 +01:00
|
|
|
* @name: New interface name
|
2014-05-13 18:13:52 +02:00
|
|
|
* @address: (allow-none): set the mac address of the new bridge
|
|
|
|
|
* @address_len: the length of the @address
|
2014-09-18 12:53:19 -05:00
|
|
|
* @out_link: on success, the link object
|
2013-03-27 22:53:55 +01:00
|
|
|
*
|
2013-06-26 21:23:25 +02:00
|
|
|
* Create a software bridge.
|
2013-03-27 22:53:55 +01:00
|
|
|
*/
|
2015-06-15 16:19:19 +02:00
|
|
|
NMPlatformError
|
2015-12-09 16:14:49 +01:00
|
|
|
nm_platform_link_bridge_add (NMPlatform *self,
|
|
|
|
|
const char *name,
|
|
|
|
|
const void *address,
|
|
|
|
|
size_t address_len,
|
|
|
|
|
const NMPlatformLink **out_link)
|
2013-03-27 22:53:55 +01:00
|
|
|
{
|
2014-09-18 12:53:19 -05:00
|
|
|
return nm_platform_link_add (self, name, NM_LINK_TYPE_BRIDGE, address, address_len, out_link);
|
2013-03-27 22:53:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-12-09 16:14:49 +01:00
|
|
|
* nm_platform_link_bond_add:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:53:55 +01:00
|
|
|
* @name: New interface name
|
2014-09-18 12:53:19 -05:00
|
|
|
* @out_link: on success, the link object
|
2013-03-27 22:53:55 +01:00
|
|
|
*
|
2013-06-26 21:23:25 +02:00
|
|
|
* Create a software bonding device.
|
2013-03-27 22:53:55 +01:00
|
|
|
*/
|
2015-06-15 16:19:19 +02:00
|
|
|
NMPlatformError
|
2015-12-11 13:34:50 +01:00
|
|
|
nm_platform_link_bond_add (NMPlatform *self,
|
|
|
|
|
const char *name,
|
|
|
|
|
const NMPlatformLink **out_link)
|
2013-03-27 22:53:55 +01:00
|
|
|
{
|
2014-09-18 12:53:19 -05:00
|
|
|
return nm_platform_link_add (self, name, NM_LINK_TYPE_BOND, NULL, 0, out_link);
|
2013-03-27 22:53:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-12-09 16:14:49 +01:00
|
|
|
* nm_platform_link_team_add:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:53:55 +01:00
|
|
|
* @name: New interface name
|
2014-09-18 12:53:19 -05:00
|
|
|
* @out_link: on success, the link object
|
2013-03-27 22:53:55 +01:00
|
|
|
*
|
2013-06-26 21:23:25 +02:00
|
|
|
* Create a software teaming device.
|
2013-03-27 22:53:55 +01:00
|
|
|
*/
|
2015-06-15 16:19:19 +02:00
|
|
|
NMPlatformError
|
2015-12-11 13:34:50 +01:00
|
|
|
nm_platform_link_team_add (NMPlatform *self,
|
|
|
|
|
const char *name,
|
|
|
|
|
const NMPlatformLink **out_link)
|
2013-03-27 22:53:55 +01:00
|
|
|
{
|
2014-09-18 12:53:19 -05:00
|
|
|
return nm_platform_link_add (self, name, NM_LINK_TYPE_TEAM, NULL, 0, out_link);
|
2013-03-27 22:53:55 +01:00
|
|
|
}
|
|
|
|
|
|
2013-03-27 22:53:55 +01:00
|
|
|
/**
|
2015-12-09 16:14:49 +01:00
|
|
|
* nm_platform_link_vlan_add:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-03-27 22:53:55 +01:00
|
|
|
* @name: New interface name
|
|
|
|
|
* @vlanid: VLAN identifier
|
2014-05-19 13:44:02 -04:00
|
|
|
* @vlanflags: VLAN flags from libnm
|
2014-09-18 12:53:19 -05:00
|
|
|
* @out_link: on success, the link object
|
2013-03-27 22:53:55 +01:00
|
|
|
*
|
|
|
|
|
* Create a software VLAN device.
|
|
|
|
|
*/
|
2015-06-15 16:19:19 +02:00
|
|
|
NMPlatformError
|
2015-12-09 16:14:49 +01:00
|
|
|
nm_platform_link_vlan_add (NMPlatform *self,
|
2015-12-11 13:34:50 +01:00
|
|
|
const char *name,
|
|
|
|
|
int parent,
|
|
|
|
|
int vlanid,
|
|
|
|
|
guint32 vlanflags,
|
|
|
|
|
const NMPlatformLink **out_link)
|
2013-03-27 22:53:55 +01:00
|
|
|
{
|
2015-06-15 16:19:19 +02:00
|
|
|
NMPlatformError plerr;
|
|
|
|
|
|
|
|
|
|
_CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
|
2013-03-27 22:53:55 +01:00
|
|
|
|
2015-06-15 16:19:19 +02:00
|
|
|
g_return_val_if_fail (parent >= 0, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
g_return_val_if_fail (vlanid >= 0, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
|
2013-03-27 22:53:55 +01:00
|
|
|
|
2015-06-15 16:19:19 +02:00
|
|
|
plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_VLAN, out_link);
|
|
|
|
|
if (plerr != NM_PLATFORM_ERROR_SUCCESS)
|
|
|
|
|
return plerr;
|
2013-03-27 22:53:55 +01:00
|
|
|
|
2015-07-02 14:35:38 +02:00
|
|
|
_LOGD ("link: adding vlan '%s' parent %d vlanid %d vlanflags %x",
|
2015-06-15 16:19:19 +02:00
|
|
|
name, parent, vlanid, vlanflags);
|
|
|
|
|
if (!klass->vlan_add (self, name, parent, vlanid, vlanflags, out_link))
|
|
|
|
|
return NM_PLATFORM_ERROR_UNSPECIFIED;
|
|
|
|
|
return NM_PLATFORM_ERROR_SUCCESS;
|
2013-03-27 22:53:55 +01:00
|
|
|
}
|
|
|
|
|
|
2015-10-14 10:01:48 +02:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_vxlan_add:
|
|
|
|
|
* @self: platform instance
|
|
|
|
|
* @name: New interface name
|
|
|
|
|
* @props: properties of the new link
|
|
|
|
|
* @out_link: on success, the link object
|
|
|
|
|
*
|
|
|
|
|
* Create a VXLAN device.
|
|
|
|
|
*/
|
|
|
|
|
NMPlatformError
|
|
|
|
|
nm_platform_link_vxlan_add (NMPlatform *self,
|
|
|
|
|
const char *name,
|
2015-12-11 13:34:50 +01:00
|
|
|
const NMPlatformLnkVxlan *props,
|
2015-12-09 15:13:57 +01:00
|
|
|
const NMPlatformLink **out_link)
|
2015-10-14 10:01:48 +02:00
|
|
|
{
|
|
|
|
|
NMPlatformError plerr;
|
|
|
|
|
|
|
|
|
|
_CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (props, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
|
|
|
|
|
plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_VXLAN, out_link);
|
|
|
|
|
if (plerr != NM_PLATFORM_ERROR_SUCCESS)
|
|
|
|
|
return plerr;
|
|
|
|
|
|
|
|
|
|
_LOGD ("link: adding vxlan '%s' parent %d id %d",
|
|
|
|
|
name, props->parent_ifindex, props->id);
|
|
|
|
|
if (!klass->link_vxlan_add (self, name, props, out_link))
|
|
|
|
|
return NM_PLATFORM_ERROR_UNSPECIFIED;
|
|
|
|
|
return NM_PLATFORM_ERROR_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-15 15:07:37 +02:00
|
|
|
/**
|
2015-12-09 16:14:49 +01:00
|
|
|
* nm_platform_link_tun_add:
|
2015-09-15 15:07:37 +02:00
|
|
|
* @self: platform instance
|
|
|
|
|
* @name: new interface name
|
|
|
|
|
* @tap: whether the interface is a TAP
|
|
|
|
|
* @owner: interface owner or -1
|
|
|
|
|
* @group: interface group or -1
|
|
|
|
|
* @pi: whether to clear the IFF_NO_PI flag
|
|
|
|
|
* @vnet_hdr: whether to set the IFF_VNET_HDR flag
|
|
|
|
|
* @multi_queue: whether to set the IFF_MULTI_QUEUE flag
|
|
|
|
|
* @out_link: on success, the link object
|
|
|
|
|
*
|
|
|
|
|
* Create a TUN or TAP interface.
|
|
|
|
|
*/
|
|
|
|
|
NMPlatformError
|
2015-12-09 16:14:49 +01:00
|
|
|
nm_platform_link_tun_add (NMPlatform *self,
|
|
|
|
|
const char *name,
|
|
|
|
|
gboolean tap,
|
|
|
|
|
gint64 owner,
|
|
|
|
|
gint64 group,
|
|
|
|
|
gboolean pi,
|
|
|
|
|
gboolean vnet_hdr,
|
|
|
|
|
gboolean multi_queue,
|
|
|
|
|
const NMPlatformLink **out_link)
|
2015-09-15 15:07:37 +02:00
|
|
|
{
|
|
|
|
|
NMPlatformError plerr;
|
|
|
|
|
|
|
|
|
|
_CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
|
|
|
|
|
plerr = _link_add_check_existing (self, name, tap ? NM_LINK_TYPE_TAP : NM_LINK_TYPE_TUN, out_link);
|
|
|
|
|
if (plerr != NM_PLATFORM_ERROR_SUCCESS)
|
|
|
|
|
return plerr;
|
|
|
|
|
|
|
|
|
|
_LOGD ("link: adding %s '%s' owner %" G_GINT64_FORMAT " group %" G_GINT64_FORMAT,
|
|
|
|
|
tap ? "tap" : "tun", name, owner, group);
|
|
|
|
|
if (!klass->tun_add (self, name, tap, owner, group, pi, vnet_hdr, multi_queue, out_link))
|
|
|
|
|
return NM_PLATFORM_ERROR_UNSPECIFIED;
|
|
|
|
|
return NM_PLATFORM_ERROR_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-09 17:29:46 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
link_option_path (NMPlatform *self, int master, const char *category, const char *option)
|
|
|
|
|
{
|
|
|
|
|
const char *name = nm_platform_link_get_name (self, master);
|
|
|
|
|
|
|
|
|
|
if (!name || !category || !option)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return g_strdup_printf ("/sys/class/net/%s/%s/%s",
|
2016-03-08 17:35:41 +01:00
|
|
|
NM_ASSERT_VALID_PATH_COMPONENT (name),
|
|
|
|
|
NM_ASSERT_VALID_PATH_COMPONENT (category),
|
|
|
|
|
NM_ASSERT_VALID_PATH_COMPONENT (option));
|
2015-12-09 17:29:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
link_set_option (NMPlatform *self, int master, const char *category, const char *option, const char *value)
|
|
|
|
|
{
|
|
|
|
|
gs_free char *path = link_option_path (self, master, category, option);
|
|
|
|
|
|
|
|
|
|
return path && nm_platform_sysctl_set (self, path, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
link_get_option (NMPlatform *self, int master, const char *category, const char *option)
|
|
|
|
|
{
|
|
|
|
|
gs_free char *path = link_option_path (self, master, category, option);
|
|
|
|
|
|
|
|
|
|
return path ? nm_platform_sysctl_get (self, path) : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
|
master_category (NMPlatform *self, int master)
|
|
|
|
|
{
|
|
|
|
|
switch (nm_platform_link_get_type (self, master)) {
|
|
|
|
|
case NM_LINK_TYPE_BRIDGE:
|
|
|
|
|
return "bridge";
|
|
|
|
|
case NM_LINK_TYPE_BOND:
|
|
|
|
|
return "bonding";
|
|
|
|
|
default:
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
|
slave_category (NMPlatform *self, int slave)
|
|
|
|
|
{
|
|
|
|
|
int master = nm_platform_link_get_master (self, slave);
|
|
|
|
|
|
|
|
|
|
if (master <= 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
switch (nm_platform_link_get_type (self, master)) {
|
|
|
|
|
case NM_LINK_TYPE_BRIDGE:
|
|
|
|
|
return "brport";
|
|
|
|
|
default:
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-04 17:07:47 +02:00
|
|
|
gboolean
|
2015-12-09 17:33:30 +01:00
|
|
|
nm_platform_sysctl_master_set_option (NMPlatform *self, int ifindex, const char *option, const char *value)
|
2013-04-04 17:07:47 +02:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-04-04 17:07:47 +02:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
|
|
|
|
g_return_val_if_fail (option, FALSE);
|
|
|
|
|
g_return_val_if_fail (value, FALSE);
|
|
|
|
|
|
2015-12-09 17:29:46 +01:00
|
|
|
return link_set_option (self, ifindex, master_category (self, ifindex), option, value);
|
2013-04-04 17:07:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
2015-12-09 17:33:30 +01:00
|
|
|
nm_platform_sysctl_master_get_option (NMPlatform *self, int ifindex, const char *option)
|
2013-04-04 17:07:47 +02:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, NULL);
|
2013-04-04 17:07:47 +02:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
|
|
|
|
g_return_val_if_fail (option, FALSE);
|
|
|
|
|
|
2015-12-09 17:29:46 +01:00
|
|
|
return link_get_option (self, ifindex, master_category (self, ifindex), option);
|
2013-04-04 17:07:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
2015-12-09 17:33:30 +01:00
|
|
|
nm_platform_sysctl_slave_set_option (NMPlatform *self, int ifindex, const char *option, const char *value)
|
2013-04-04 17:07:47 +02:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-04-04 17:07:47 +02:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
|
|
|
|
g_return_val_if_fail (option, FALSE);
|
|
|
|
|
g_return_val_if_fail (value, FALSE);
|
|
|
|
|
|
2015-12-09 17:29:46 +01:00
|
|
|
return link_set_option (self, ifindex, slave_category (self, ifindex), option, value);
|
2013-04-04 17:07:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
2015-12-09 17:33:30 +01:00
|
|
|
nm_platform_sysctl_slave_get_option (NMPlatform *self, int ifindex, const char *option)
|
2013-04-04 17:07:47 +02:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, NULL);
|
2013-04-04 17:07:47 +02:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
|
|
|
|
g_return_val_if_fail (option, FALSE);
|
|
|
|
|
|
2015-12-09 17:29:46 +01:00
|
|
|
return link_get_option (self, ifindex, slave_category (self, ifindex), option);
|
2013-04-04 17:07:47 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-09 17:29:46 +01:00
|
|
|
/******************************************************************************/
|
|
|
|
|
|
2013-03-27 22:53:55 +01:00
|
|
|
gboolean
|
2015-10-27 16:14:54 +01:00
|
|
|
nm_platform_link_vlan_change (NMPlatform *self,
|
|
|
|
|
int ifindex,
|
|
|
|
|
NMVlanFlags flags_mask,
|
|
|
|
|
NMVlanFlags flags_set,
|
|
|
|
|
gboolean ingress_reset_all,
|
|
|
|
|
const NMVlanQosMapping *ingress_map,
|
|
|
|
|
gsize n_ingress_map,
|
|
|
|
|
gboolean egress_reset_all,
|
|
|
|
|
const NMVlanQosMapping *egress_map,
|
|
|
|
|
gsize n_egress_map)
|
2013-03-27 22:53:55 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:53:55 +01:00
|
|
|
|
2015-10-27 16:14:54 +01:00
|
|
|
nm_assert (klass->link_vlan_change);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (!n_ingress_map || ingress_map, FALSE);
|
|
|
|
|
g_return_val_if_fail (!n_egress_map || egress_map, FALSE);
|
|
|
|
|
|
|
|
|
|
flags_set &= flags_mask;
|
|
|
|
|
|
|
|
|
|
if (_LOGD_ENABLED ()) {
|
|
|
|
|
char buf[512];
|
|
|
|
|
char *b = buf;
|
|
|
|
|
gsize len, i;
|
|
|
|
|
|
|
|
|
|
b[0] = '\0';
|
|
|
|
|
len = sizeof (buf);
|
|
|
|
|
|
|
|
|
|
if (flags_mask)
|
|
|
|
|
nm_utils_strbuf_append (&b, &len, " flags 0x%x/0x%x", (unsigned) flags_set, (unsigned) flags_mask);
|
|
|
|
|
|
|
|
|
|
if (ingress_reset_all || n_ingress_map) {
|
|
|
|
|
nm_utils_strbuf_append_str (&b, &len, " ingress-qos-map");
|
|
|
|
|
nm_platform_vlan_qos_mapping_to_string ("", ingress_map, n_ingress_map, b, len);
|
|
|
|
|
i = strlen (b);
|
|
|
|
|
b += i;
|
|
|
|
|
len -= i;
|
|
|
|
|
if (ingress_reset_all)
|
|
|
|
|
nm_utils_strbuf_append_str (&b, &len, " (reset-all)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (egress_reset_all || n_egress_map) {
|
|
|
|
|
nm_utils_strbuf_append_str (&b, &len, " egress-qos-map");
|
|
|
|
|
nm_platform_vlan_qos_mapping_to_string ("", egress_map, n_egress_map, b, len);
|
|
|
|
|
i = strlen (b);
|
|
|
|
|
b += i;
|
|
|
|
|
len -= i;
|
|
|
|
|
if (egress_reset_all)
|
|
|
|
|
nm_utils_strbuf_append_str (&b, &len, " (reset-all)");
|
|
|
|
|
}
|
2013-03-27 22:53:55 +01:00
|
|
|
|
2015-10-27 16:14:54 +01:00
|
|
|
_LOGD ("link: change vlan %d:%s", ifindex, buf);
|
|
|
|
|
}
|
|
|
|
|
return klass->link_vlan_change (self,
|
|
|
|
|
ifindex,
|
|
|
|
|
flags_mask,
|
|
|
|
|
flags_set,
|
|
|
|
|
ingress_reset_all,
|
|
|
|
|
ingress_map,
|
|
|
|
|
n_ingress_map,
|
|
|
|
|
egress_reset_all,
|
|
|
|
|
egress_map,
|
|
|
|
|
n_egress_map);
|
2013-03-27 22:53:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
2015-12-09 16:14:49 +01:00
|
|
|
nm_platform_link_vlan_set_ingress_map (NMPlatform *self, int ifindex, int from, int to)
|
2013-03-27 22:53:55 +01:00
|
|
|
{
|
2015-10-27 16:14:54 +01:00
|
|
|
NMVlanQosMapping map = {
|
|
|
|
|
.from = from,
|
|
|
|
|
.to = to,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return nm_platform_link_vlan_change (self, ifindex, 0, 0, FALSE, &map, 1, FALSE, NULL, 0);
|
|
|
|
|
}
|
2013-03-27 22:53:55 +01:00
|
|
|
|
2015-10-27 16:14:54 +01:00
|
|
|
gboolean
|
2015-12-09 16:14:49 +01:00
|
|
|
nm_platform_link_vlan_set_egress_map (NMPlatform *self, int ifindex, int from, int to)
|
2015-10-27 16:14:54 +01:00
|
|
|
{
|
|
|
|
|
NMVlanQosMapping map = {
|
|
|
|
|
.from = from,
|
|
|
|
|
.to = to,
|
|
|
|
|
};
|
2013-03-27 22:53:55 +01:00
|
|
|
|
2015-10-27 16:14:54 +01:00
|
|
|
return nm_platform_link_vlan_change (self, ifindex, 0, 0, FALSE, NULL, 0, FALSE, &map, 1);
|
2013-03-27 22:53:55 +01:00
|
|
|
}
|
|
|
|
|
|
2015-09-01 22:11:47 +02:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_gre_add:
|
|
|
|
|
* @self: platform instance
|
|
|
|
|
* @name: name of the new interface
|
|
|
|
|
* @props: interface properties
|
|
|
|
|
* @out_link: on success, the link object
|
|
|
|
|
*
|
|
|
|
|
* Create a software GRE device.
|
|
|
|
|
*/
|
|
|
|
|
NMPlatformError
|
|
|
|
|
nm_platform_link_gre_add (NMPlatform *self,
|
|
|
|
|
const char *name,
|
2015-12-11 13:34:50 +01:00
|
|
|
const NMPlatformLnkGre *props,
|
2015-12-09 15:13:57 +01:00
|
|
|
const NMPlatformLink **out_link)
|
2015-09-01 22:11:47 +02:00
|
|
|
{
|
|
|
|
|
NMPlatformError plerr;
|
|
|
|
|
char buffer[INET_ADDRSTRLEN];
|
|
|
|
|
|
|
|
|
|
_CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (props, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
|
|
|
|
|
plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_GRE, out_link);
|
|
|
|
|
if (plerr != NM_PLATFORM_ERROR_SUCCESS)
|
|
|
|
|
return plerr;
|
|
|
|
|
|
|
|
|
|
_LOGD (LOG_FMT_IP_TUNNEL,
|
|
|
|
|
"gre",
|
|
|
|
|
name,
|
|
|
|
|
props->parent_ifindex,
|
|
|
|
|
nm_utils_inet4_ntop (props->local, NULL),
|
|
|
|
|
nm_utils_inet4_ntop (props->remote, buffer));
|
|
|
|
|
|
|
|
|
|
if (!klass->link_gre_add (self, name, props, out_link))
|
|
|
|
|
return NM_PLATFORM_ERROR_UNSPECIFIED;
|
|
|
|
|
return NM_PLATFORM_ERROR_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-20 09:16:21 +02:00
|
|
|
static NMPlatformError
|
|
|
|
|
_infiniband_add_add_or_delete (NMPlatform *self,
|
|
|
|
|
int parent,
|
|
|
|
|
int p_key,
|
|
|
|
|
gboolean add,
|
|
|
|
|
const NMPlatformLink **out_link)
|
2013-06-10 16:21:08 -03:00
|
|
|
{
|
2015-06-15 16:19:19 +02:00
|
|
|
gs_free char *name = NULL;
|
2016-04-20 10:07:03 +02:00
|
|
|
const NMPlatformLink *parent_link;
|
2015-06-15 16:19:19 +02:00
|
|
|
NMPlatformError plerr;
|
2013-06-10 16:21:08 -03:00
|
|
|
|
2015-06-15 16:19:19 +02:00
|
|
|
_CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
|
2013-06-10 16:21:08 -03:00
|
|
|
|
2015-06-15 16:19:19 +02:00
|
|
|
g_return_val_if_fail (parent >= 0, NM_PLATFORM_ERROR_BUG);
|
2016-04-20 11:44:23 +02:00
|
|
|
g_return_val_if_fail (p_key >= 0 && p_key <= 0xffff, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
|
|
|
|
|
/* the special keys 0x0000 and 0x8000 are not allowed. */
|
|
|
|
|
if (NM_IN_SET (p_key, 0, 0x8000))
|
|
|
|
|
return NM_PLATFORM_ERROR_UNSPECIFIED;
|
2013-06-10 16:21:08 -03:00
|
|
|
|
2016-04-20 10:07:03 +02:00
|
|
|
parent_link = nm_platform_link_get (self, parent);
|
|
|
|
|
if (!parent_link)
|
|
|
|
|
return NM_PLATFORM_ERROR_NOT_FOUND;
|
|
|
|
|
|
|
|
|
|
if (parent_link->type != NM_LINK_TYPE_INFINIBAND)
|
2015-06-15 16:19:19 +02:00
|
|
|
return NM_PLATFORM_ERROR_WRONG_TYPE;
|
2013-06-10 16:21:08 -03:00
|
|
|
|
2016-04-20 10:07:03 +02:00
|
|
|
name = g_strdup_printf ("%s.%04x", parent_link->name, p_key);
|
2015-06-15 16:19:19 +02:00
|
|
|
|
2016-04-20 09:16:21 +02:00
|
|
|
if (add) {
|
|
|
|
|
plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_INFINIBAND, out_link);
|
|
|
|
|
if (plerr != NM_PLATFORM_ERROR_SUCCESS)
|
|
|
|
|
return plerr;
|
|
|
|
|
|
|
|
|
|
_LOGD ("link: adding infiniband partition %s for parent '%s' (%d), key %d",
|
2016-04-20 10:07:03 +02:00
|
|
|
name, parent_link->name, parent, p_key);
|
2016-04-20 09:16:21 +02:00
|
|
|
if (!klass->infiniband_partition_add (self, parent, p_key, out_link))
|
|
|
|
|
return NM_PLATFORM_ERROR_UNSPECIFIED;
|
|
|
|
|
} else {
|
|
|
|
|
if (!klass->infiniband_partition_delete (self, parent, p_key))
|
|
|
|
|
return NM_PLATFORM_ERROR_UNSPECIFIED;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-15 16:19:19 +02:00
|
|
|
return NM_PLATFORM_ERROR_SUCCESS;
|
2013-06-10 16:21:08 -03:00
|
|
|
}
|
|
|
|
|
|
2016-04-20 09:16:21 +02:00
|
|
|
NMPlatformError
|
|
|
|
|
nm_platform_link_infiniband_add (NMPlatform *self,
|
|
|
|
|
int parent,
|
|
|
|
|
int p_key,
|
|
|
|
|
const NMPlatformLink **out_link)
|
|
|
|
|
{
|
|
|
|
|
return _infiniband_add_add_or_delete (self, parent, p_key, TRUE, out_link);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NMPlatformError
|
|
|
|
|
nm_platform_link_infiniband_delete (NMPlatform *self,
|
|
|
|
|
int parent,
|
|
|
|
|
int p_key)
|
|
|
|
|
{
|
|
|
|
|
return _infiniband_add_add_or_delete (self, parent, p_key, FALSE, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-10-06 09:37:34 -05:00
|
|
|
gboolean
|
2015-12-09 16:14:49 +01:00
|
|
|
nm_platform_link_infiniband_get_properties (NMPlatform *self,
|
|
|
|
|
int ifindex,
|
|
|
|
|
int *out_parent,
|
|
|
|
|
int *out_p_key,
|
|
|
|
|
const char **out_mode)
|
2014-10-06 09:37:34 -05:00
|
|
|
{
|
2015-10-15 15:47:14 +02:00
|
|
|
const NMPlatformLnkInfiniband *plnk;
|
|
|
|
|
const NMPlatformLink *plink;
|
|
|
|
|
const char *iface;
|
|
|
|
|
char *path, *contents;
|
|
|
|
|
const char *mode;
|
|
|
|
|
int p_key = 0;
|
|
|
|
|
|
2014-10-06 09:37:34 -05:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
|
|
|
|
|
2015-10-15 15:47:14 +02:00
|
|
|
plnk = nm_platform_link_get_lnk_infiniband (self, ifindex, &plink);
|
|
|
|
|
|
|
|
|
|
if ( !plink
|
|
|
|
|
|| plink->type != NM_LINK_TYPE_INFINIBAND)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (plnk) {
|
|
|
|
|
NM_SET_OUT (out_parent, plink->parent);
|
|
|
|
|
NM_SET_OUT (out_p_key, plnk->p_key);
|
|
|
|
|
NM_SET_OUT (out_mode, plnk->mode);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Could not get the link information via netlink. To support older kernels,
|
|
|
|
|
* fallback to reading sysfs. */
|
|
|
|
|
|
2016-03-08 17:35:41 +01:00
|
|
|
iface = NM_ASSERT_VALID_PATH_COMPONENT (plink->name);
|
2015-10-15 15:47:14 +02:00
|
|
|
|
|
|
|
|
/* Fall back to reading sysfs */
|
|
|
|
|
path = g_strdup_printf ("/sys/class/net/%s/mode", iface);
|
|
|
|
|
contents = nm_platform_sysctl_get (self, path);
|
|
|
|
|
g_free (path);
|
|
|
|
|
if (!contents)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (strstr (contents, "datagram"))
|
|
|
|
|
mode = "datagram";
|
|
|
|
|
else if (strstr (contents, "connected"))
|
|
|
|
|
mode = "connected";
|
|
|
|
|
else
|
|
|
|
|
mode = NULL;
|
|
|
|
|
g_free (contents);
|
|
|
|
|
|
|
|
|
|
path = g_strdup_printf ("/sys/class/net/%s/pkey", iface);
|
|
|
|
|
contents = nm_platform_sysctl_get (self, path);
|
|
|
|
|
g_free (path);
|
|
|
|
|
if (!contents)
|
|
|
|
|
return FALSE;
|
|
|
|
|
p_key = (int) _nm_utils_ascii_str_to_int64 (contents, 16, 0, 0xFFFF, -1);
|
|
|
|
|
g_free (contents);
|
|
|
|
|
if (p_key < 0)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
NM_SET_OUT (out_parent, plink->parent);
|
|
|
|
|
NM_SET_OUT (out_p_key, p_key);
|
|
|
|
|
NM_SET_OUT (out_mode, mode);
|
|
|
|
|
return TRUE;
|
2014-10-06 09:37:34 -05:00
|
|
|
}
|
|
|
|
|
|
2015-11-27 22:22:25 +01:00
|
|
|
/**
|
|
|
|
|
* nm_platform_ip6tnl_add:
|
|
|
|
|
* @self: platform instance
|
|
|
|
|
* @name: name of the new interface
|
|
|
|
|
* @props: interface properties
|
|
|
|
|
* @out_link: on success, the link object
|
|
|
|
|
*
|
|
|
|
|
* Create an IPv6 tunnel.
|
|
|
|
|
*/
|
|
|
|
|
NMPlatformError
|
|
|
|
|
nm_platform_link_ip6tnl_add (NMPlatform *self,
|
|
|
|
|
const char *name,
|
2015-12-11 13:34:50 +01:00
|
|
|
const NMPlatformLnkIp6Tnl *props,
|
2015-12-09 15:13:57 +01:00
|
|
|
const NMPlatformLink **out_link)
|
2015-11-27 22:22:25 +01:00
|
|
|
{
|
|
|
|
|
NMPlatformError plerr;
|
|
|
|
|
char buffer[INET6_ADDRSTRLEN];
|
|
|
|
|
|
|
|
|
|
_CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (props, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
|
|
|
|
|
plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_IP6TNL, out_link);
|
|
|
|
|
if (plerr != NM_PLATFORM_ERROR_SUCCESS)
|
|
|
|
|
return plerr;
|
|
|
|
|
|
|
|
|
|
_LOGD (LOG_FMT_IP_TUNNEL,
|
|
|
|
|
"ip6tnl",
|
|
|
|
|
name,
|
|
|
|
|
props->parent_ifindex,
|
|
|
|
|
nm_utils_inet6_ntop (&props->local, NULL),
|
|
|
|
|
nm_utils_inet6_ntop (&props->remote, buffer));
|
|
|
|
|
|
|
|
|
|
if (!klass->link_ip6tnl_add (self, name, props, out_link))
|
|
|
|
|
return NM_PLATFORM_ERROR_UNSPECIFIED;
|
|
|
|
|
return NM_PLATFORM_ERROR_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-27 14:01:56 +01:00
|
|
|
/**
|
|
|
|
|
* nm_platform_ipip_add:
|
|
|
|
|
* @self: platform instance
|
|
|
|
|
* @name: name of the new interface
|
|
|
|
|
* @props: interface properties
|
|
|
|
|
* @out_link: on success, the link object
|
|
|
|
|
*
|
|
|
|
|
* Create an IPIP tunnel.
|
|
|
|
|
*/
|
|
|
|
|
NMPlatformError
|
|
|
|
|
nm_platform_link_ipip_add (NMPlatform *self,
|
|
|
|
|
const char *name,
|
2015-12-11 13:34:50 +01:00
|
|
|
const NMPlatformLnkIpIp *props,
|
2015-12-09 15:13:57 +01:00
|
|
|
const NMPlatformLink **out_link)
|
2015-11-27 14:01:56 +01:00
|
|
|
{
|
|
|
|
|
NMPlatformError plerr;
|
|
|
|
|
char buffer[INET_ADDRSTRLEN];
|
|
|
|
|
|
|
|
|
|
_CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (props, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
|
|
|
|
|
plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_IPIP, out_link);
|
|
|
|
|
if (plerr != NM_PLATFORM_ERROR_SUCCESS)
|
|
|
|
|
return plerr;
|
|
|
|
|
|
|
|
|
|
_LOGD (LOG_FMT_IP_TUNNEL,
|
|
|
|
|
"ipip",
|
|
|
|
|
name,
|
|
|
|
|
props->parent_ifindex,
|
|
|
|
|
nm_utils_inet4_ntop (props->local, NULL),
|
|
|
|
|
nm_utils_inet4_ntop (props->remote, buffer));
|
|
|
|
|
|
|
|
|
|
if (!klass->link_ipip_add (self, name, props, out_link))
|
|
|
|
|
return NM_PLATFORM_ERROR_UNSPECIFIED;
|
|
|
|
|
return NM_PLATFORM_ERROR_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-03 17:09:50 +01:00
|
|
|
/**
|
|
|
|
|
* nm_platform_macvlan_add:
|
|
|
|
|
* @self: platform instance
|
|
|
|
|
* @name: name of the new interface
|
|
|
|
|
* @props: interface properties
|
|
|
|
|
* @out_link: on success, the link object
|
|
|
|
|
*
|
2015-12-04 09:49:39 +01:00
|
|
|
* Create a MACVLAN or MACVTAP device.
|
2015-12-03 17:09:50 +01:00
|
|
|
*/
|
|
|
|
|
NMPlatformError
|
|
|
|
|
nm_platform_link_macvlan_add (NMPlatform *self,
|
|
|
|
|
const char *name,
|
|
|
|
|
int parent,
|
2015-12-11 13:34:50 +01:00
|
|
|
const NMPlatformLnkMacvlan *props,
|
2015-12-09 15:13:57 +01:00
|
|
|
const NMPlatformLink **out_link)
|
2015-12-03 17:09:50 +01:00
|
|
|
{
|
|
|
|
|
NMPlatformError plerr;
|
2015-12-04 09:49:39 +01:00
|
|
|
NMLinkType type;
|
2015-12-03 17:09:50 +01:00
|
|
|
|
|
|
|
|
_CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (props, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
|
2015-12-04 09:49:39 +01:00
|
|
|
type = props->tap ? NM_LINK_TYPE_MACVTAP : NM_LINK_TYPE_MACVLAN;
|
|
|
|
|
|
|
|
|
|
plerr = _link_add_check_existing (self, name, type, out_link);
|
2015-12-03 17:09:50 +01:00
|
|
|
if (plerr != NM_PLATFORM_ERROR_SUCCESS)
|
|
|
|
|
return plerr;
|
|
|
|
|
|
2015-12-04 09:49:39 +01:00
|
|
|
_LOGD ("adding %s '%s' parent %u mode %u",
|
|
|
|
|
props->tap ? "macvtap" : "macvlan",
|
2015-12-03 17:09:50 +01:00
|
|
|
name,
|
|
|
|
|
parent,
|
|
|
|
|
props->mode);
|
|
|
|
|
|
|
|
|
|
if (!klass->link_macvlan_add (self, name, parent, props, out_link))
|
|
|
|
|
return NM_PLATFORM_ERROR_UNSPECIFIED;
|
|
|
|
|
return NM_PLATFORM_ERROR_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-11 18:41:48 +01:00
|
|
|
/**
|
|
|
|
|
* nm_platform_sit_add:
|
|
|
|
|
* @self: platform instance
|
|
|
|
|
* @name: name of the new interface
|
|
|
|
|
* @props: interface properties
|
|
|
|
|
* @out_link: on success, the link object
|
|
|
|
|
*
|
|
|
|
|
* Create a software SIT device.
|
|
|
|
|
*/
|
|
|
|
|
NMPlatformError
|
|
|
|
|
nm_platform_link_sit_add (NMPlatform *self,
|
|
|
|
|
const char *name,
|
2015-12-11 13:34:50 +01:00
|
|
|
const NMPlatformLnkSit *props,
|
2015-12-09 15:13:57 +01:00
|
|
|
const NMPlatformLink **out_link)
|
2015-11-11 18:41:48 +01:00
|
|
|
{
|
|
|
|
|
NMPlatformError plerr;
|
|
|
|
|
char buffer[INET_ADDRSTRLEN];
|
|
|
|
|
|
|
|
|
|
_CHECK_SELF (self, klass, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (props, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
g_return_val_if_fail (name, NM_PLATFORM_ERROR_BUG);
|
|
|
|
|
|
|
|
|
|
plerr = _link_add_check_existing (self, name, NM_LINK_TYPE_SIT, out_link);
|
|
|
|
|
if (plerr != NM_PLATFORM_ERROR_SUCCESS)
|
|
|
|
|
return plerr;
|
|
|
|
|
|
|
|
|
|
_LOGD (LOG_FMT_IP_TUNNEL,
|
|
|
|
|
"sit",
|
|
|
|
|
name,
|
|
|
|
|
props->parent_ifindex,
|
|
|
|
|
nm_utils_inet4_ntop (props->local, NULL),
|
|
|
|
|
nm_utils_inet4_ntop (props->remote, buffer));
|
|
|
|
|
|
|
|
|
|
if (!klass->link_sit_add (self, name, props, out_link))
|
|
|
|
|
return NM_PLATFORM_ERROR_UNSPECIFIED;
|
|
|
|
|
return NM_PLATFORM_ERROR_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-03 13:55:51 -04:00
|
|
|
gboolean
|
2015-12-09 16:14:49 +01:00
|
|
|
nm_platform_link_veth_get_properties (NMPlatform *self, int ifindex, int *out_peer_ifindex)
|
2013-05-03 13:55:51 -04:00
|
|
|
{
|
2015-10-16 17:53:33 +02:00
|
|
|
const NMPlatformLink *plink;
|
|
|
|
|
int peer_ifindex;
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-05-03 13:55:51 -04:00
|
|
|
|
2015-10-16 17:53:33 +02:00
|
|
|
plink = nm_platform_link_get (self, ifindex);
|
|
|
|
|
|
|
|
|
|
if (!plink)
|
|
|
|
|
return FALSE;
|
|
|
|
|
if (plink->type != NM_LINK_TYPE_VETH)
|
|
|
|
|
return FALSE;
|
2013-05-03 13:55:51 -04:00
|
|
|
|
2015-10-16 17:53:33 +02:00
|
|
|
if (plink->parent != 0) {
|
|
|
|
|
NM_SET_OUT (out_peer_ifindex, plink->parent);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Pre-4.1 kernel did not expose the peer_ifindex as IFA_LINK. Lookup via ethtool. */
|
|
|
|
|
if (out_peer_ifindex) {
|
2016-02-19 01:06:28 +01:00
|
|
|
nm_auto_pop_netns NMPNetns *netns = NULL;
|
|
|
|
|
|
|
|
|
|
if (!nm_platform_netns_push (self, &netns))
|
|
|
|
|
return FALSE;
|
2015-10-16 17:53:33 +02:00
|
|
|
peer_ifindex = nmp_utils_ethtool_get_peer_ifindex (plink->name);
|
|
|
|
|
if (peer_ifindex <= 0)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
*out_peer_ifindex = peer_ifindex;
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
2013-05-03 13:55:51 -04:00
|
|
|
}
|
|
|
|
|
|
2015-10-13 16:08:30 +02:00
|
|
|
gboolean
|
2015-12-09 16:14:49 +01:00
|
|
|
nm_platform_link_tun_get_properties_ifname (NMPlatform *self, const char *ifname, NMPlatformTunProperties *props)
|
2015-10-13 16:08:30 +02:00
|
|
|
{
|
2016-02-17 13:25:34 +01:00
|
|
|
char path[256];
|
|
|
|
|
char *val;
|
2015-10-13 16:08:30 +02:00
|
|
|
gboolean success = TRUE;
|
|
|
|
|
|
|
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (props, FALSE);
|
|
|
|
|
|
|
|
|
|
memset (props, 0, sizeof (*props));
|
|
|
|
|
props->owner = -1;
|
|
|
|
|
props->group = -1;
|
|
|
|
|
|
|
|
|
|
if (!ifname || !nm_utils_iface_valid_name (ifname))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2016-02-17 13:25:34 +01:00
|
|
|
nm_sprintf_buf (path, "/sys/class/net/%s/owner", ifname);
|
2015-10-13 16:08:30 +02:00
|
|
|
val = nm_platform_sysctl_get (self, path);
|
|
|
|
|
if (val) {
|
|
|
|
|
props->owner = _nm_utils_ascii_str_to_int64 (val, 10, -1, G_MAXINT64, -1);
|
|
|
|
|
if (errno)
|
|
|
|
|
success = FALSE;
|
|
|
|
|
g_free (val);
|
|
|
|
|
} else
|
|
|
|
|
success = FALSE;
|
|
|
|
|
|
2016-02-17 13:25:34 +01:00
|
|
|
nm_sprintf_buf (path, "/sys/class/net/%s/group", ifname);
|
2015-10-13 16:08:30 +02:00
|
|
|
val = nm_platform_sysctl_get (self, path);
|
|
|
|
|
if (val) {
|
|
|
|
|
props->group = _nm_utils_ascii_str_to_int64 (val, 10, -1, G_MAXINT64, -1);
|
|
|
|
|
if (errno)
|
|
|
|
|
success = FALSE;
|
|
|
|
|
g_free (val);
|
|
|
|
|
} else
|
|
|
|
|
success = FALSE;
|
|
|
|
|
|
2016-02-17 13:25:34 +01:00
|
|
|
nm_sprintf_buf (path, "/sys/class/net/%s/tun_flags", ifname);
|
2015-10-13 16:08:30 +02:00
|
|
|
val = nm_platform_sysctl_get (self, path);
|
|
|
|
|
if (val) {
|
|
|
|
|
gint64 flags;
|
|
|
|
|
|
|
|
|
|
flags = _nm_utils_ascii_str_to_int64 (val, 16, 0, G_MAXINT64, 0);
|
|
|
|
|
if (!errno) {
|
|
|
|
|
props->mode = ((flags & (IFF_TUN | IFF_TAP)) == IFF_TUN) ? "tun" : "tap";
|
|
|
|
|
props->no_pi = !!(flags & IFF_NO_PI);
|
|
|
|
|
props->vnet_hdr = !!(flags & IFF_VNET_HDR);
|
2015-09-15 15:07:37 +02:00
|
|
|
props->multi_queue = !!(flags & NM_IFF_MULTI_QUEUE);
|
2015-10-13 16:08:30 +02:00
|
|
|
} else
|
|
|
|
|
success = FALSE;
|
|
|
|
|
g_free (val);
|
|
|
|
|
} else
|
|
|
|
|
success = FALSE;
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-25 15:46:39 -04:00
|
|
|
gboolean
|
2015-12-09 16:14:49 +01:00
|
|
|
nm_platform_link_tun_get_properties (NMPlatform *self, int ifindex, NMPlatformTunProperties *props)
|
2013-04-25 15:46:39 -04:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-04-25 15:46:39 -04:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
|
|
|
|
g_return_val_if_fail (props != NULL, FALSE);
|
|
|
|
|
|
2015-12-09 16:14:49 +01:00
|
|
|
return nm_platform_link_tun_get_properties_ifname (self, nm_platform_link_get_name (self, ifindex), props);
|
2013-04-25 15:46:39 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-04 14:27:03 +01:00
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_wifi_get_capabilities (NMPlatform *self, int ifindex, NMDeviceWifiCapabilities *caps)
|
2014-02-04 14:27:03 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2014-02-04 14:27:03 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->wifi_get_capabilities (self, ifindex, caps);
|
2014-02-04 14:27:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_wifi_get_bssid (NMPlatform *self, int ifindex, guint8 *bssid)
|
2014-02-04 14:27:03 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2014-02-04 14:27:03 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->wifi_get_bssid (self, ifindex, bssid);
|
2014-02-04 14:27:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
guint32
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_wifi_get_frequency (NMPlatform *self, int ifindex)
|
2014-02-04 14:27:03 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, 0);
|
2014-02-04 14:27:03 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, 0);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->wifi_get_frequency (self, ifindex);
|
2014-02-04 14:27:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_wifi_get_quality (NMPlatform *self, int ifindex)
|
2014-02-04 14:27:03 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, 0);
|
2014-02-04 14:27:03 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, 0);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->wifi_get_quality (self, ifindex);
|
2014-02-04 14:27:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
guint32
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_wifi_get_rate (NMPlatform *self, int ifindex)
|
2014-02-04 14:27:03 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, 0);
|
2014-02-04 14:27:03 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, 0);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->wifi_get_rate (self, ifindex);
|
2014-02-04 14:27:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NM80211Mode
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_wifi_get_mode (NMPlatform *self, int ifindex)
|
2014-02-04 14:27:03 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, NM_802_11_MODE_UNKNOWN);
|
2014-02-04 14:27:03 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, NM_802_11_MODE_UNKNOWN);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->wifi_get_mode (self, ifindex);
|
2014-02-04 14:27:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_wifi_set_mode (NMPlatform *self, int ifindex, NM80211Mode mode)
|
2014-02-04 14:27:03 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF_VOID (self, klass);
|
2014-02-04 14:27:03 +01:00
|
|
|
|
|
|
|
|
g_return_if_fail (ifindex > 0);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
klass->wifi_set_mode (self, ifindex, mode);
|
2014-02-04 14:27:03 +01:00
|
|
|
}
|
|
|
|
|
|
2014-10-23 14:19:59 -04:00
|
|
|
static void
|
|
|
|
|
wifi_set_powersave (NMPlatform *p, int ifindex, guint32 powersave)
|
|
|
|
|
{
|
|
|
|
|
/* empty */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_wifi_set_powersave (NMPlatform *self, int ifindex, guint32 powersave)
|
2014-10-23 14:19:59 -04:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF_VOID (self, klass);
|
2014-10-23 14:19:59 -04:00
|
|
|
|
|
|
|
|
g_return_if_fail (ifindex > 0);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
klass->wifi_set_powersave (self, ifindex, powersave);
|
2014-10-23 14:19:59 -04:00
|
|
|
}
|
|
|
|
|
|
2014-02-04 14:27:03 +01:00
|
|
|
guint32
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_wifi_find_frequency (NMPlatform *self, int ifindex, const guint32 *freqs)
|
2014-02-04 14:27:03 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, 0);
|
2014-02-04 14:27:03 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, 0);
|
|
|
|
|
g_return_val_if_fail (freqs != NULL, 0);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->wifi_find_frequency (self, ifindex, freqs);
|
2014-02-04 14:27:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_wifi_indicate_addressing_running (NMPlatform *self, int ifindex, gboolean running)
|
2014-02-04 14:27:03 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF_VOID (self, klass);
|
2014-02-04 14:27:03 +01:00
|
|
|
|
|
|
|
|
g_return_if_fail (ifindex > 0);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
klass->wifi_indicate_addressing_running (self, ifindex, running);
|
2014-02-04 14:27:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
guint32
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_mesh_get_channel (NMPlatform *self, int ifindex)
|
2014-02-04 14:27:03 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, 0);
|
2014-02-04 14:27:03 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, 0);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->mesh_get_channel (self, ifindex);
|
2014-02-04 14:27:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_mesh_set_channel (NMPlatform *self, int ifindex, guint32 channel)
|
2014-02-04 14:27:03 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2014-02-04 14:27:03 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->mesh_set_channel (self, ifindex, channel);
|
2014-02-04 14:27:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_mesh_set_ssid (NMPlatform *self, int ifindex, const guint8 *ssid, gsize len)
|
2014-02-04 14:27:03 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2014-02-04 14:27:03 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
|
|
|
|
g_return_val_if_fail (ssid != NULL, FALSE);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->mesh_set_ssid (self, ifindex, ssid, len);
|
2014-02-04 14:27:03 +01:00
|
|
|
}
|
|
|
|
|
|
2014-08-11 21:32:47 +02:00
|
|
|
#define TO_STRING_DEV_BUF_SIZE (5+15+1)
|
2014-08-11 21:40:52 +02:00
|
|
|
static const char *
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_to_string_dev (NMPlatform *self, int ifindex, char *buf, size_t size)
|
2014-08-11 21:32:47 +02:00
|
|
|
{
|
|
|
|
|
g_assert (buf && size >= TO_STRING_DEV_BUF_SIZE);
|
|
|
|
|
|
|
|
|
|
if (ifindex) {
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
const char *name = ifindex > 0 && self ? nm_platform_link_get_name (self, ifindex) : NULL;
|
2014-08-11 21:40:52 +02:00
|
|
|
char *buf2;
|
2014-08-11 21:32:47 +02:00
|
|
|
|
|
|
|
|
strcpy (buf, " dev ");
|
2014-08-11 21:40:52 +02:00
|
|
|
buf2 = buf + 5;
|
2014-08-11 21:32:47 +02:00
|
|
|
size -= 5;
|
|
|
|
|
|
|
|
|
|
if (name)
|
2014-08-11 21:40:52 +02:00
|
|
|
g_strlcpy (buf2, name, size);
|
2014-08-11 21:32:47 +02:00
|
|
|
else
|
2014-08-11 21:40:52 +02:00
|
|
|
g_snprintf (buf2, size, "%d", ifindex);
|
2014-08-11 21:32:47 +02:00
|
|
|
} else
|
|
|
|
|
buf[0] = 0;
|
2014-08-11 21:40:52 +02:00
|
|
|
|
|
|
|
|
return buf;
|
2014-08-11 21:32:47 +02:00
|
|
|
}
|
|
|
|
|
|
2016-02-29 16:50:55 +01:00
|
|
|
#define TO_STRING_IFA_FLAGS_BUF_SIZE 256
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
|
_to_string_ifa_flags (guint32 ifa_flags, char *buf, gsize size)
|
|
|
|
|
{
|
|
|
|
|
#define S_FLAGS_PREFIX " flags "
|
|
|
|
|
nm_assert (buf && size >= TO_STRING_IFA_FLAGS_BUF_SIZE && size > NM_STRLEN (S_FLAGS_PREFIX));
|
|
|
|
|
|
|
|
|
|
if (!ifa_flags)
|
|
|
|
|
buf[0] = '\0';
|
|
|
|
|
else {
|
|
|
|
|
nm_platform_addr_flags2str (ifa_flags, &buf[NM_STRLEN (S_FLAGS_PREFIX)], size - NM_STRLEN (S_FLAGS_PREFIX));
|
|
|
|
|
if (buf[NM_STRLEN (S_FLAGS_PREFIX)] == '\0')
|
|
|
|
|
buf[0] = '\0';
|
|
|
|
|
else
|
|
|
|
|
memcpy (buf, S_FLAGS_PREFIX, NM_STRLEN (S_FLAGS_PREFIX));
|
|
|
|
|
}
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-27 22:23:24 +01:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
2016-02-19 23:34:25 +01:00
|
|
|
gboolean
|
|
|
|
|
nm_platform_ethtool_set_wake_on_lan (NMPlatform *self, const char *ifname, NMSettingWiredWakeOnLan wol, const char *wol_password)
|
|
|
|
|
{
|
2016-02-19 01:06:28 +01:00
|
|
|
nm_auto_pop_netns NMPNetns *netns = NULL;
|
2016-02-19 23:34:25 +01:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
|
|
|
|
|
2016-02-19 01:06:28 +01:00
|
|
|
if (!nm_platform_netns_push (self, &netns))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2016-02-19 23:34:25 +01:00
|
|
|
return nmp_utils_ethtool_set_wake_on_lan (ifname, wol, wol_password);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
nm_platform_ethtool_get_link_speed (NMPlatform *self, const char *ifname, guint32 *out_speed)
|
|
|
|
|
{
|
2016-02-19 01:06:28 +01:00
|
|
|
nm_auto_pop_netns NMPNetns *netns = NULL;
|
2016-02-19 23:34:25 +01:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
|
|
|
|
|
2016-02-19 01:06:28 +01:00
|
|
|
if (!nm_platform_netns_push (self, &netns))
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2016-02-19 23:34:25 +01:00
|
|
|
return nmp_utils_ethtool_get_link_speed (ifname, out_speed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
2015-10-21 23:17:11 +02:00
|
|
|
void
|
2016-04-06 18:04:26 +02:00
|
|
|
nm_platform_ip4_address_set_addr (NMPlatformIP4Address *addr, in_addr_t address, guint8 plen)
|
2015-10-10 17:48:32 +02:00
|
|
|
{
|
2016-04-06 18:04:26 +02:00
|
|
|
nm_assert (plen <= 32);
|
|
|
|
|
|
2015-10-21 23:17:11 +02:00
|
|
|
addr->address = address;
|
|
|
|
|
addr->peer_address = address;
|
|
|
|
|
addr->plen = plen;
|
2015-10-10 17:48:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const struct in6_addr *
|
|
|
|
|
nm_platform_ip6_address_get_peer (const NMPlatformIP6Address *addr)
|
|
|
|
|
{
|
|
|
|
|
if ( IN6_IS_ADDR_UNSPECIFIED (&addr->peer_address)
|
|
|
|
|
|| IN6_ARE_ADDR_EQUAL (&addr->peer_address, &addr->address))
|
|
|
|
|
return &addr->address;
|
|
|
|
|
return &addr->peer_address;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-27 22:23:24 +01:00
|
|
|
GArray *
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_ip4_address_get_all (NMPlatform *self, int ifindex)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, NULL);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, NULL);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->ip4_address_get_all (self, ifindex);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GArray *
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_ip6_address_get_all (NMPlatform *self, int ifindex)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, NULL);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, NULL);
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->ip6_address_get_all (self, ifindex);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_ip4_address_add (NMPlatform *self,
|
2015-10-10 17:41:49 +02:00
|
|
|
int ifindex,
|
2013-12-02 10:20:26 -05:00
|
|
|
in_addr_t address,
|
2016-04-06 18:04:26 +02:00
|
|
|
guint8 plen,
|
2015-10-10 19:58:59 +02:00
|
|
|
in_addr_t peer_address,
|
2013-12-02 10:20:26 -05:00
|
|
|
guint32 lifetime,
|
2014-02-19 16:10:59 -05:00
|
|
|
guint32 preferred,
|
2016-02-29 17:06:21 +01:00
|
|
|
guint32 flags,
|
2014-02-19 16:10:59 -05:00
|
|
|
const char *label)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
2016-04-06 18:04:26 +02:00
|
|
|
g_return_val_if_fail (plen <= 32, FALSE);
|
2013-06-29 11:30:11 +02:00
|
|
|
g_return_val_if_fail (lifetime > 0, FALSE);
|
2014-04-01 22:46:46 +02:00
|
|
|
g_return_val_if_fail (preferred <= lifetime, FALSE);
|
2014-02-19 16:10:59 -05:00
|
|
|
g_return_val_if_fail (!label || strlen (label) < sizeof (((NMPlatformIP4Address *) NULL)->label), FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-08-20 00:07:14 +02:00
|
|
|
if (_LOGD_ENABLED ()) {
|
2014-01-30 20:31:29 +01:00
|
|
|
NMPlatformIP4Address addr = { 0 };
|
|
|
|
|
|
|
|
|
|
addr.ifindex = ifindex;
|
|
|
|
|
addr.address = address;
|
|
|
|
|
addr.peer_address = peer_address;
|
|
|
|
|
addr.plen = plen;
|
2014-06-09 10:03:01 +02:00
|
|
|
addr.timestamp = 0; /* set it at zero, which to_string will treat as *now* */
|
2014-01-30 20:31:29 +01:00
|
|
|
addr.lifetime = lifetime;
|
|
|
|
|
addr.preferred = preferred;
|
2016-02-29 17:06:21 +01:00
|
|
|
addr.n_ifa_flags = flags;
|
2014-02-19 16:10:59 -05:00
|
|
|
if (label)
|
|
|
|
|
g_strlcpy (addr.label, label, sizeof (addr.label));
|
2014-01-30 20:31:29 +01:00
|
|
|
|
2015-10-12 10:27:33 +02:00
|
|
|
_LOGD ("address: adding or updating IPv4 address: %s", nm_platform_ip4_address_to_string (&addr, NULL, 0));
|
2014-01-30 20:31:29 +01:00
|
|
|
}
|
2016-02-29 17:06:21 +01:00
|
|
|
return klass->ip4_address_add (self, ifindex, address, plen, peer_address, lifetime, preferred, flags, label);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_ip6_address_add (NMPlatform *self,
|
|
|
|
|
int ifindex,
|
2013-12-02 10:20:26 -05:00
|
|
|
struct in6_addr address,
|
2016-04-06 18:04:26 +02:00
|
|
|
guint8 plen,
|
2015-10-10 19:58:59 +02:00
|
|
|
struct in6_addr peer_address,
|
2013-12-02 10:20:26 -05:00
|
|
|
guint32 lifetime,
|
|
|
|
|
guint32 preferred,
|
2016-02-29 15:36:12 +01:00
|
|
|
guint32 flags)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
2016-04-06 18:04:26 +02:00
|
|
|
g_return_val_if_fail (plen <= 128, FALSE);
|
2013-06-29 11:30:11 +02:00
|
|
|
g_return_val_if_fail (lifetime > 0, FALSE);
|
2014-04-01 22:46:46 +02:00
|
|
|
g_return_val_if_fail (preferred <= lifetime, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-08-20 00:07:14 +02:00
|
|
|
if (_LOGD_ENABLED ()) {
|
2014-01-30 20:31:29 +01:00
|
|
|
NMPlatformIP6Address addr = { 0 };
|
|
|
|
|
|
|
|
|
|
addr.ifindex = ifindex;
|
|
|
|
|
addr.address = address;
|
|
|
|
|
addr.peer_address = peer_address;
|
|
|
|
|
addr.plen = plen;
|
2014-06-09 10:03:01 +02:00
|
|
|
addr.timestamp = 0; /* set it to zero, which to_string will treat as *now* */
|
2014-01-30 20:31:29 +01:00
|
|
|
addr.lifetime = lifetime;
|
|
|
|
|
addr.preferred = preferred;
|
2016-02-29 16:23:16 +01:00
|
|
|
addr.n_ifa_flags = flags;
|
2014-01-30 20:31:29 +01:00
|
|
|
|
2015-10-12 10:27:33 +02:00
|
|
|
_LOGD ("address: adding or updating IPv6 address: %s", nm_platform_ip6_address_to_string (&addr, NULL, 0));
|
2014-01-30 20:31:29 +01:00
|
|
|
}
|
2015-10-10 19:58:59 +02:00
|
|
|
return klass->ip6_address_add (self, ifindex, address, plen, peer_address, lifetime, preferred, flags);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
2016-04-06 18:04:26 +02:00
|
|
|
nm_platform_ip4_address_delete (NMPlatform *self, int ifindex, in_addr_t address, guint8 plen, in_addr_t peer_address)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
2014-08-11 21:40:52 +02:00
|
|
|
char str_dev[TO_STRING_DEV_BUF_SIZE];
|
2015-10-21 23:17:11 +02:00
|
|
|
char str_peer2[NM_UTILS_INET_ADDRSTRLEN];
|
|
|
|
|
char str_peer[100];
|
2014-08-11 21:40:52 +02:00
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
2016-04-06 18:04:26 +02:00
|
|
|
g_return_val_if_fail (plen <= 32, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-10-21 23:17:11 +02:00
|
|
|
_LOGD ("address: deleting IPv4 address %s/%d, %sifindex %d%s",
|
2014-08-12 01:31:00 +02:00
|
|
|
nm_utils_inet4_ntop (address, NULL), plen,
|
2015-10-21 23:17:11 +02:00
|
|
|
peer_address != address
|
|
|
|
|
? nm_sprintf_buf (str_peer, "peer %s, ", nm_utils_inet4_ntop (peer_address, str_peer2)) : "",
|
2014-08-12 01:31:00 +02:00
|
|
|
ifindex,
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_to_string_dev (self, ifindex, str_dev, sizeof (str_dev)));
|
|
|
|
|
return klass->ip4_address_delete (self, ifindex, address, plen, peer_address);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
2016-04-06 18:04:26 +02:00
|
|
|
nm_platform_ip6_address_delete (NMPlatform *self, int ifindex, struct in6_addr address, guint8 plen)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
2014-08-11 21:40:52 +02:00
|
|
|
char str_dev[TO_STRING_DEV_BUF_SIZE];
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
|
|
|
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
2016-04-06 18:04:26 +02:00
|
|
|
g_return_val_if_fail (plen <= 128, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-07-02 14:35:38 +02:00
|
|
|
_LOGD ("address: deleting IPv6 address %s/%d, ifindex %d%s",
|
2014-08-11 21:40:52 +02:00
|
|
|
nm_utils_inet6_ntop (&address, NULL), plen, ifindex,
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_to_string_dev (self, ifindex, str_dev, sizeof (str_dev)));
|
|
|
|
|
return klass->ip6_address_delete (self, ifindex, address, plen);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-14 12:37:58 +02:00
|
|
|
const NMPlatformIP4Address *
|
2016-04-06 18:04:26 +02:00
|
|
|
nm_platform_ip4_address_get (NMPlatform *self, int ifindex, in_addr_t address, guint8 plen, guint32 peer_address)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
2015-10-10 17:41:49 +02:00
|
|
|
_CHECK_SELF (self, klass, NULL);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2016-04-06 18:04:26 +02:00
|
|
|
g_return_val_if_fail (plen <= 32, NULL);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-10-10 17:48:32 +02:00
|
|
|
return klass->ip4_address_get (self, ifindex, address, plen, peer_address);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-14 12:37:58 +02:00
|
|
|
const NMPlatformIP6Address *
|
2016-04-06 18:04:26 +02:00
|
|
|
nm_platform_ip6_address_get (NMPlatform *self, int ifindex, struct in6_addr address, guint8 plen)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
2015-10-10 17:41:49 +02:00
|
|
|
_CHECK_SELF (self, klass, NULL);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2016-04-06 18:04:26 +02:00
|
|
|
g_return_val_if_fail (plen <= 128, NULL);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-07-14 12:37:58 +02:00
|
|
|
return klass->ip6_address_get (self, ifindex, address, plen);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
2013-04-16 14:24:46 +02:00
|
|
|
static gboolean
|
2016-03-15 17:40:43 +01:00
|
|
|
array_contains_ip4_address (const GArray *addresses, const NMPlatformIP4Address *address, gint32 now)
|
2013-04-16 14:24:46 +02:00
|
|
|
{
|
2013-07-29 23:00:44 +02:00
|
|
|
guint len = addresses ? addresses->len : 0;
|
|
|
|
|
guint i;
|
2013-04-16 14:24:46 +02:00
|
|
|
|
2013-07-29 23:00:44 +02:00
|
|
|
for (i = 0; i < len; i++) {
|
2013-07-29 14:54:25 -05:00
|
|
|
NMPlatformIP4Address *candidate = &g_array_index (addresses, NMPlatformIP4Address, i);
|
|
|
|
|
|
2015-10-10 17:48:32 +02:00
|
|
|
if ( candidate->address == address->address
|
|
|
|
|
&& candidate->plen == address->plen
|
2016-01-12 17:57:18 +01:00
|
|
|
&& ((candidate->peer_address ^ address->peer_address) & nm_utils_ip4_prefix_to_netmask (address->plen)) == 0) {
|
2015-06-24 12:00:22 +02:00
|
|
|
guint32 lifetime, preferred;
|
|
|
|
|
|
2016-03-07 11:45:44 +01:00
|
|
|
if (nm_utils_lifetime_get (candidate->timestamp, candidate->lifetime, candidate->preferred,
|
2016-03-15 17:29:58 +01:00
|
|
|
now, &lifetime, &preferred))
|
2015-06-24 12:00:22 +02:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
2013-04-16 14:24:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2016-03-15 17:40:43 +01:00
|
|
|
array_contains_ip6_address (const GArray *addresses, const NMPlatformIP6Address *address, gint32 now)
|
2013-04-16 14:24:46 +02:00
|
|
|
{
|
2013-07-29 23:00:44 +02:00
|
|
|
guint len = addresses ? addresses->len : 0;
|
|
|
|
|
guint i;
|
2013-04-16 14:24:46 +02:00
|
|
|
|
2013-07-29 23:00:44 +02:00
|
|
|
for (i = 0; i < len; i++) {
|
2013-07-29 14:54:25 -05:00
|
|
|
NMPlatformIP6Address *candidate = &g_array_index (addresses, NMPlatformIP6Address, i);
|
|
|
|
|
|
2015-06-24 12:00:22 +02:00
|
|
|
if (IN6_ARE_ADDR_EQUAL (&candidate->address, &address->address) && candidate->plen == address->plen) {
|
|
|
|
|
guint32 lifetime, preferred;
|
|
|
|
|
|
2016-03-07 11:45:44 +01:00
|
|
|
if (nm_utils_lifetime_get (candidate->timestamp, candidate->lifetime, candidate->preferred,
|
2016-03-15 17:29:58 +01:00
|
|
|
now, &lifetime, &preferred))
|
2015-06-24 12:00:22 +02:00
|
|
|
return TRUE;
|
|
|
|
|
}
|
2013-04-16 14:24:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_ip4_address_sync:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-04-16 14:24:46 +02:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
* @known_addresses: List of addresses
|
route-manager: manage IPv4 device-routes with NMRouteManager
When adding an IPv4 address, kernel will also add a device-route.
We don't want that route because it has the wrong metric. Instead,
we add our own route (with a different metric) and remove the
kernel-added one.
This could be avoided if kernel would support an IPv4 address flag
IFA_F_NOPREFIXROUTE like it does for IPv6 (see related bug rh#1221311).
One important thing is, that we want don't want to manage the
device-route on assumed devices. Note that this is correct behavior
if "assumed" means "do-not-touch".
If "assumed" means "seamlessly-takeover", then this is wrong.
Imagine we get a new DHCP address. In this case, we would not manage
the device-route on the assumed device. This cannot be fixed without
splitting unmanaged/assumed with related bug bgo 746440.
This is no regression as we would also not manage device-routes
for assumed devices previously.
We also don't want to remove the device-route if the user added
it externally. Note that here we behave wrongly too, because we
don't record externally added kernel routes in update_ip_config().
This still needs fixing.
Let IPv4 device-routes also be managed by NMRouteManager. NMRouteManager
has a list of all routes and can properly add, remove, and restore
the device route as needed.
One problem is, that the device-route does not get added immediately
with the address. It only appears some time later. This is solved
by NMRouteManager watching platform and if a matchin device-route shows up
within a short time after configuring addresses, remove it.
If the route appears after the short timeout, assume they were added for
other reasons (e.g. by the user) and don't remove them.
https://bugzilla.gnome.org/show_bug.cgi?id=751264
https://bugzilla.redhat.com/show_bug.cgi?id=1211287
2015-06-22 18:21:53 +02:00
|
|
|
* @out_added_addresses: (out): (allow-none): if not %NULL, return a #GPtrArray
|
|
|
|
|
* with the addresses added. The pointers point into @known_addresses.
|
|
|
|
|
* It possibly does not contain all addresses from @known_address because
|
|
|
|
|
* some addresses might be expired.
|
2013-04-16 14:24:46 +02:00
|
|
|
*
|
|
|
|
|
* A convenience function to synchronize addresses for a specific interface
|
|
|
|
|
* with the least possible disturbance. It simply removes addresses that are
|
|
|
|
|
* not listed and adds addresses that are.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
route-manager: manage IPv4 device-routes with NMRouteManager
When adding an IPv4 address, kernel will also add a device-route.
We don't want that route because it has the wrong metric. Instead,
we add our own route (with a different metric) and remove the
kernel-added one.
This could be avoided if kernel would support an IPv4 address flag
IFA_F_NOPREFIXROUTE like it does for IPv6 (see related bug rh#1221311).
One important thing is, that we want don't want to manage the
device-route on assumed devices. Note that this is correct behavior
if "assumed" means "do-not-touch".
If "assumed" means "seamlessly-takeover", then this is wrong.
Imagine we get a new DHCP address. In this case, we would not manage
the device-route on the assumed device. This cannot be fixed without
splitting unmanaged/assumed with related bug bgo 746440.
This is no regression as we would also not manage device-routes
for assumed devices previously.
We also don't want to remove the device-route if the user added
it externally. Note that here we behave wrongly too, because we
don't record externally added kernel routes in update_ip_config().
This still needs fixing.
Let IPv4 device-routes also be managed by NMRouteManager. NMRouteManager
has a list of all routes and can properly add, remove, and restore
the device route as needed.
One problem is, that the device-route does not get added immediately
with the address. It only appears some time later. This is solved
by NMRouteManager watching platform and if a matchin device-route shows up
within a short time after configuring addresses, remove it.
If the route appears after the short timeout, assume they were added for
other reasons (e.g. by the user) and don't remove them.
https://bugzilla.gnome.org/show_bug.cgi?id=751264
https://bugzilla.redhat.com/show_bug.cgi?id=1211287
2015-06-22 18:21:53 +02:00
|
|
|
nm_platform_ip4_address_sync (NMPlatform *self, int ifindex, const GArray *known_addresses, GPtrArray **out_added_addresses)
|
2013-04-16 14:24:46 +02:00
|
|
|
{
|
|
|
|
|
GArray *addresses;
|
|
|
|
|
NMPlatformIP4Address *address;
|
2016-03-15 17:40:43 +01:00
|
|
|
gint32 now = nm_utils_get_monotonic_timestamp_s ();
|
2013-04-16 14:24:46 +02:00
|
|
|
int i;
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
|
|
|
|
|
2013-04-16 14:24:46 +02:00
|
|
|
/* Delete unknown addresses */
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
addresses = nm_platform_ip4_address_get_all (self, ifindex);
|
2013-04-16 14:24:46 +02:00
|
|
|
for (i = 0; i < addresses->len; i++) {
|
|
|
|
|
address = &g_array_index (addresses, NMPlatformIP4Address, i);
|
|
|
|
|
|
2016-03-15 17:29:58 +01:00
|
|
|
if (!array_contains_ip4_address (known_addresses, address, now))
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_ip4_address_delete (self, ifindex, address->address, address->plen, address->peer_address);
|
2013-04-16 14:24:46 +02:00
|
|
|
}
|
|
|
|
|
g_array_free (addresses, TRUE);
|
|
|
|
|
|
route-manager: manage IPv4 device-routes with NMRouteManager
When adding an IPv4 address, kernel will also add a device-route.
We don't want that route because it has the wrong metric. Instead,
we add our own route (with a different metric) and remove the
kernel-added one.
This could be avoided if kernel would support an IPv4 address flag
IFA_F_NOPREFIXROUTE like it does for IPv6 (see related bug rh#1221311).
One important thing is, that we want don't want to manage the
device-route on assumed devices. Note that this is correct behavior
if "assumed" means "do-not-touch".
If "assumed" means "seamlessly-takeover", then this is wrong.
Imagine we get a new DHCP address. In this case, we would not manage
the device-route on the assumed device. This cannot be fixed without
splitting unmanaged/assumed with related bug bgo 746440.
This is no regression as we would also not manage device-routes
for assumed devices previously.
We also don't want to remove the device-route if the user added
it externally. Note that here we behave wrongly too, because we
don't record externally added kernel routes in update_ip_config().
This still needs fixing.
Let IPv4 device-routes also be managed by NMRouteManager. NMRouteManager
has a list of all routes and can properly add, remove, and restore
the device route as needed.
One problem is, that the device-route does not get added immediately
with the address. It only appears some time later. This is solved
by NMRouteManager watching platform and if a matchin device-route shows up
within a short time after configuring addresses, remove it.
If the route appears after the short timeout, assume they were added for
other reasons (e.g. by the user) and don't remove them.
https://bugzilla.gnome.org/show_bug.cgi?id=751264
https://bugzilla.redhat.com/show_bug.cgi?id=1211287
2015-06-22 18:21:53 +02:00
|
|
|
if (out_added_addresses)
|
|
|
|
|
*out_added_addresses = NULL;
|
|
|
|
|
|
2013-04-16 14:24:46 +02:00
|
|
|
if (!known_addresses)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
/* Add missing addresses */
|
|
|
|
|
for (i = 0; i < known_addresses->len; i++) {
|
2013-07-30 00:03:48 +02:00
|
|
|
const NMPlatformIP4Address *known_address = &g_array_index (known_addresses, NMPlatformIP4Address, i);
|
|
|
|
|
guint32 lifetime, preferred;
|
2013-04-16 14:24:46 +02:00
|
|
|
|
2016-03-07 11:45:44 +01:00
|
|
|
if (!nm_utils_lifetime_get (known_address->timestamp, known_address->lifetime, known_address->preferred,
|
2016-03-15 17:29:58 +01:00
|
|
|
now, &lifetime, &preferred))
|
2014-03-31 11:19:45 +02:00
|
|
|
continue;
|
2013-06-29 11:30:11 +02:00
|
|
|
|
2016-02-29 17:06:21 +01:00
|
|
|
if (!nm_platform_ip4_address_add (self, ifindex, known_address->address, known_address->plen,
|
|
|
|
|
known_address->peer_address, lifetime, preferred,
|
|
|
|
|
0, known_address->label))
|
2013-07-30 00:03:48 +02:00
|
|
|
return FALSE;
|
2014-11-11 14:55:07 +01:00
|
|
|
|
route-manager: manage IPv4 device-routes with NMRouteManager
When adding an IPv4 address, kernel will also add a device-route.
We don't want that route because it has the wrong metric. Instead,
we add our own route (with a different metric) and remove the
kernel-added one.
This could be avoided if kernel would support an IPv4 address flag
IFA_F_NOPREFIXROUTE like it does for IPv6 (see related bug rh#1221311).
One important thing is, that we want don't want to manage the
device-route on assumed devices. Note that this is correct behavior
if "assumed" means "do-not-touch".
If "assumed" means "seamlessly-takeover", then this is wrong.
Imagine we get a new DHCP address. In this case, we would not manage
the device-route on the assumed device. This cannot be fixed without
splitting unmanaged/assumed with related bug bgo 746440.
This is no regression as we would also not manage device-routes
for assumed devices previously.
We also don't want to remove the device-route if the user added
it externally. Note that here we behave wrongly too, because we
don't record externally added kernel routes in update_ip_config().
This still needs fixing.
Let IPv4 device-routes also be managed by NMRouteManager. NMRouteManager
has a list of all routes and can properly add, remove, and restore
the device route as needed.
One problem is, that the device-route does not get added immediately
with the address. It only appears some time later. This is solved
by NMRouteManager watching platform and if a matchin device-route shows up
within a short time after configuring addresses, remove it.
If the route appears after the short timeout, assume they were added for
other reasons (e.g. by the user) and don't remove them.
https://bugzilla.gnome.org/show_bug.cgi?id=751264
https://bugzilla.redhat.com/show_bug.cgi?id=1211287
2015-06-22 18:21:53 +02:00
|
|
|
if (out_added_addresses) {
|
|
|
|
|
if (!*out_added_addresses)
|
|
|
|
|
*out_added_addresses = g_ptr_array_new ();
|
|
|
|
|
g_ptr_array_add (*out_added_addresses, (gpointer) known_address);
|
2014-11-11 14:55:07 +01:00
|
|
|
}
|
2013-04-16 14:24:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_ip6_address_sync:
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
* @self: platform instance
|
2013-04-16 14:24:46 +02:00
|
|
|
* @ifindex: Interface index
|
|
|
|
|
* @known_addresses: List of addresses
|
2015-01-28 12:00:00 +01:00
|
|
|
* @keep_link_local: Don't remove link-local address
|
2013-04-16 14:24:46 +02:00
|
|
|
*
|
|
|
|
|
* A convenience function to synchronize addresses for a specific interface
|
|
|
|
|
* with the least possible disturbance. It simply removes addresses that are
|
|
|
|
|
* not listed and adds addresses that are.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_ip6_address_sync (NMPlatform *self, int ifindex, const GArray *known_addresses, gboolean keep_link_local)
|
2013-04-16 14:24:46 +02:00
|
|
|
{
|
|
|
|
|
GArray *addresses;
|
|
|
|
|
NMPlatformIP6Address *address;
|
2016-03-15 17:40:43 +01:00
|
|
|
gint32 now = nm_utils_get_monotonic_timestamp_s ();
|
2013-04-16 14:24:46 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* Delete unknown addresses */
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
addresses = nm_platform_ip6_address_get_all (self, ifindex);
|
2013-04-16 14:24:46 +02:00
|
|
|
for (i = 0; i < addresses->len; i++) {
|
|
|
|
|
address = &g_array_index (addresses, NMPlatformIP6Address, i);
|
|
|
|
|
|
|
|
|
|
/* Leave link local address management to the kernel */
|
2015-01-28 12:00:00 +01:00
|
|
|
if (keep_link_local && IN6_IS_ADDR_LINKLOCAL (&address->address))
|
2013-04-16 14:24:46 +02:00
|
|
|
continue;
|
|
|
|
|
|
2016-03-15 17:29:58 +01:00
|
|
|
if (!array_contains_ip6_address (known_addresses, address, now))
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_ip6_address_delete (self, ifindex, address->address, address->plen);
|
2013-04-16 14:24:46 +02:00
|
|
|
}
|
|
|
|
|
g_array_free (addresses, TRUE);
|
|
|
|
|
|
|
|
|
|
if (!known_addresses)
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
/* Add missing addresses */
|
|
|
|
|
for (i = 0; i < known_addresses->len; i++) {
|
2013-07-30 00:03:48 +02:00
|
|
|
const NMPlatformIP6Address *known_address = &g_array_index (known_addresses, NMPlatformIP6Address, i);
|
|
|
|
|
guint32 lifetime, preferred;
|
2013-06-29 11:30:11 +02:00
|
|
|
|
2016-03-07 11:45:44 +01:00
|
|
|
if (!nm_utils_lifetime_get (known_address->timestamp, known_address->lifetime, known_address->preferred,
|
2016-03-15 17:29:58 +01:00
|
|
|
now, &lifetime, &preferred))
|
2014-03-31 11:19:45 +02:00
|
|
|
continue;
|
2013-06-29 11:30:11 +02:00
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
if (!nm_platform_ip6_address_add (self, ifindex, known_address->address,
|
2015-10-10 19:58:59 +02:00
|
|
|
known_address->plen, known_address->peer_address,
|
2016-02-29 16:23:16 +01:00
|
|
|
lifetime, preferred, known_address->n_ifa_flags))
|
2013-07-30 00:03:48 +02:00
|
|
|
return FALSE;
|
2013-04-16 14:24:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_address_flush (NMPlatform *self, int ifindex)
|
2013-04-16 14:24:46 +02:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
|
|
|
|
|
route-manager: manage IPv4 device-routes with NMRouteManager
When adding an IPv4 address, kernel will also add a device-route.
We don't want that route because it has the wrong metric. Instead,
we add our own route (with a different metric) and remove the
kernel-added one.
This could be avoided if kernel would support an IPv4 address flag
IFA_F_NOPREFIXROUTE like it does for IPv6 (see related bug rh#1221311).
One important thing is, that we want don't want to manage the
device-route on assumed devices. Note that this is correct behavior
if "assumed" means "do-not-touch".
If "assumed" means "seamlessly-takeover", then this is wrong.
Imagine we get a new DHCP address. In this case, we would not manage
the device-route on the assumed device. This cannot be fixed without
splitting unmanaged/assumed with related bug bgo 746440.
This is no regression as we would also not manage device-routes
for assumed devices previously.
We also don't want to remove the device-route if the user added
it externally. Note that here we behave wrongly too, because we
don't record externally added kernel routes in update_ip_config().
This still needs fixing.
Let IPv4 device-routes also be managed by NMRouteManager. NMRouteManager
has a list of all routes and can properly add, remove, and restore
the device route as needed.
One problem is, that the device-route does not get added immediately
with the address. It only appears some time later. This is solved
by NMRouteManager watching platform and if a matchin device-route shows up
within a short time after configuring addresses, remove it.
If the route appears after the short timeout, assume they were added for
other reasons (e.g. by the user) and don't remove them.
https://bugzilla.gnome.org/show_bug.cgi?id=751264
https://bugzilla.redhat.com/show_bug.cgi?id=1211287
2015-06-22 18:21:53 +02:00
|
|
|
return nm_platform_ip4_address_sync (self, ifindex, NULL, NULL)
|
|
|
|
|
&& nm_platform_ip6_address_sync (self, ifindex, NULL, FALSE);
|
2013-04-16 14:24:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
2013-03-27 22:23:24 +01:00
|
|
|
GArray *
|
2015-06-22 17:28:37 +02:00
|
|
|
nm_platform_ip4_route_get_all (NMPlatform *self, int ifindex, NMPlatformGetRouteFlags flags)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, NULL);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2014-11-07 10:56:21 +01:00
|
|
|
g_return_val_if_fail (ifindex >= 0, NULL);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-06-22 17:28:37 +02:00
|
|
|
return klass->ip4_route_get_all (self, ifindex, flags);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GArray *
|
2015-06-22 17:28:37 +02:00
|
|
|
nm_platform_ip6_route_get_all (NMPlatform *self, int ifindex, NMPlatformGetRouteFlags flags)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, NULL);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2014-11-07 10:56:21 +01:00
|
|
|
g_return_val_if_fail (ifindex >= 0, NULL);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-06-22 17:28:37 +02:00
|
|
|
return klass->ip6_route_get_all (self, ifindex, flags);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
2016-01-18 12:31:52 +01:00
|
|
|
/**
|
|
|
|
|
* nm_platform_ip4_route_add:
|
|
|
|
|
* @self:
|
|
|
|
|
* @ifindex:
|
|
|
|
|
* @source:
|
|
|
|
|
* network:
|
|
|
|
|
* plen:
|
|
|
|
|
* gateway:
|
|
|
|
|
* pref_src:
|
|
|
|
|
* metric:
|
|
|
|
|
* mss:
|
|
|
|
|
*
|
|
|
|
|
* For kernel, a gateway can be either explicitly set or left
|
|
|
|
|
* at zero (0.0.0.0). In addition, there is the scope of the IPv4
|
|
|
|
|
* route.
|
|
|
|
|
* When adding a route with
|
|
|
|
|
* $ ip route add default dev $IFNAME
|
|
|
|
|
* the resulting route will have gateway 0.0.0.0 and scope "link".
|
|
|
|
|
* Contrary to
|
|
|
|
|
* $ ip route add default via 0.0.0.0 dev $IFNAME
|
|
|
|
|
* which adds the route with scope "global".
|
|
|
|
|
*
|
|
|
|
|
* NetworkManager's Platform can currently only add on-link-routes with scope
|
|
|
|
|
* "link" (and gateway 0.0.0.0) or gateway-routes with scope "global" (and
|
|
|
|
|
* gateway not 0.0.0.0).
|
|
|
|
|
*
|
|
|
|
|
* It does not support adding globally scoped routes via 0.0.0.0.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE in case of success.
|
|
|
|
|
*/
|
2013-03-27 22:23:24 +01:00
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_ip4_route_add (NMPlatform *self,
|
|
|
|
|
int ifindex, NMIPConfigSource source,
|
2016-04-06 14:19:05 +02:00
|
|
|
in_addr_t network, guint8 plen,
|
2015-10-29 09:26:10 +01:00
|
|
|
in_addr_t gateway, in_addr_t pref_src,
|
2014-11-11 14:19:12 +01:00
|
|
|
guint32 metric, guint32 mss)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2016-04-06 14:19:05 +02:00
|
|
|
g_return_val_if_fail (plen <= 32, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-08-20 00:07:14 +02:00
|
|
|
if (_LOGD_ENABLED ()) {
|
2014-02-13 14:42:26 +01:00
|
|
|
NMPlatformIP4Route route = { 0 };
|
|
|
|
|
|
|
|
|
|
route.ifindex = ifindex;
|
2014-05-08 14:50:02 -04:00
|
|
|
route.source = source;
|
2014-02-13 14:42:26 +01:00
|
|
|
route.network = network;
|
|
|
|
|
route.plen = plen;
|
|
|
|
|
route.gateway = gateway;
|
|
|
|
|
route.metric = metric;
|
|
|
|
|
route.mss = mss;
|
2015-06-22 13:22:48 +02:00
|
|
|
route.pref_src = pref_src;
|
2014-02-13 14:42:26 +01:00
|
|
|
|
2015-10-12 10:27:33 +02:00
|
|
|
_LOGD ("route: adding or updating IPv4 route: %s", nm_platform_ip4_route_to_string (&route, NULL, 0));
|
2014-02-13 14:42:26 +01:00
|
|
|
}
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->ip4_route_add (self, ifindex, source, network, plen, gateway, pref_src, metric, mss);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
nm_platform_ip6_route_add (NMPlatform *self,
|
|
|
|
|
int ifindex, NMIPConfigSource source,
|
2016-04-06 14:19:05 +02:00
|
|
|
struct in6_addr network, guint8 plen, struct in6_addr gateway,
|
2014-08-28 17:25:36 +02:00
|
|
|
guint32 metric, guint32 mss)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
|
|
|
|
|
2016-04-06 14:19:05 +02:00
|
|
|
g_return_val_if_fail (plen <= 128, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-08-20 00:07:14 +02:00
|
|
|
if (_LOGD_ENABLED ()) {
|
2014-02-13 14:42:26 +01:00
|
|
|
NMPlatformIP6Route route = { 0 };
|
|
|
|
|
|
|
|
|
|
route.ifindex = ifindex;
|
2014-05-08 14:50:02 -04:00
|
|
|
route.source = source;
|
2014-02-13 14:42:26 +01:00
|
|
|
route.network = network;
|
|
|
|
|
route.plen = plen;
|
|
|
|
|
route.gateway = gateway;
|
|
|
|
|
route.metric = metric;
|
|
|
|
|
route.mss = mss;
|
|
|
|
|
|
2015-10-12 10:27:33 +02:00
|
|
|
_LOGD ("route: adding or updating IPv6 route: %s", nm_platform_ip6_route_to_string (&route, NULL, 0));
|
2014-02-13 14:42:26 +01:00
|
|
|
}
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return klass->ip6_route_add (self, ifindex, source, network, plen, gateway, metric, mss);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
2016-04-06 14:19:05 +02:00
|
|
|
nm_platform_ip4_route_delete (NMPlatform *self, int ifindex, in_addr_t network, guint8 plen, guint32 metric)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
2014-08-11 21:40:52 +02:00
|
|
|
char str_dev[TO_STRING_DEV_BUF_SIZE];
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-07-02 14:35:38 +02:00
|
|
|
_LOGD ("route: deleting IPv4 route %s/%d, metric=%"G_GUINT32_FORMAT", ifindex %d%s",
|
2014-08-11 21:40:52 +02:00
|
|
|
nm_utils_inet4_ntop (network, NULL), plen, metric, ifindex,
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_to_string_dev (self, ifindex, str_dev, sizeof (str_dev)));
|
|
|
|
|
return klass->ip4_route_delete (self, ifindex, network, plen, metric);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
2016-04-06 14:19:05 +02:00
|
|
|
nm_platform_ip6_route_delete (NMPlatform *self, int ifindex, struct in6_addr network, guint8 plen, guint32 metric)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
2014-08-11 21:40:52 +02:00
|
|
|
char str_dev[TO_STRING_DEV_BUF_SIZE];
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-07-02 14:35:38 +02:00
|
|
|
_LOGD ("route: deleting IPv6 route %s/%d, metric=%"G_GUINT32_FORMAT", ifindex %d%s",
|
2014-08-11 21:40:52 +02:00
|
|
|
nm_utils_inet6_ntop (&network, NULL), plen, metric, ifindex,
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_to_string_dev (self, ifindex, str_dev, sizeof (str_dev)));
|
|
|
|
|
return klass->ip6_route_delete (self, ifindex, network, plen, metric);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-14 12:37:58 +02:00
|
|
|
const NMPlatformIP4Route *
|
2016-04-06 14:19:05 +02:00
|
|
|
nm_platform_ip4_route_get (NMPlatform *self, int ifindex, in_addr_t network, guint8 plen, guint32 metric)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-07-14 12:37:58 +02:00
|
|
|
return klass->ip4_route_get (self ,ifindex, network, plen, metric);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
2015-07-14 12:37:58 +02:00
|
|
|
const NMPlatformIP6Route *
|
2016-04-06 14:19:05 +02:00
|
|
|
nm_platform_ip6_route_get (NMPlatform *self, int ifindex, struct in6_addr network, guint8 plen, guint32 metric)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_CHECK_SELF (self, klass, FALSE);
|
2013-03-27 22:23:24 +01:00
|
|
|
|
2015-07-14 12:37:58 +02:00
|
|
|
return klass->ip6_route_get (self, ifindex, network, plen, metric);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
2013-03-27 22:23:24 +01:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
2015-10-27 16:14:54 +01:00
|
|
|
const char *
|
|
|
|
|
nm_platform_vlan_qos_mapping_to_string (const char *name,
|
|
|
|
|
const NMVlanQosMapping *map,
|
|
|
|
|
gsize n_map,
|
|
|
|
|
char *buf,
|
|
|
|
|
gsize len)
|
|
|
|
|
{
|
|
|
|
|
gsize i;
|
|
|
|
|
char *b;
|
|
|
|
|
|
|
|
|
|
nm_utils_to_string_buffer_init (&buf, &len);
|
|
|
|
|
|
|
|
|
|
if (!n_map) {
|
|
|
|
|
nm_utils_strbuf_append_str (&buf, &len, "");
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!map)
|
|
|
|
|
g_return_val_if_reached ("");
|
|
|
|
|
|
|
|
|
|
b = buf;
|
|
|
|
|
|
|
|
|
|
if (name) {
|
|
|
|
|
nm_utils_strbuf_append_str (&b, &len, name);
|
|
|
|
|
nm_utils_strbuf_append_str (&b, &len, " {");
|
|
|
|
|
} else
|
|
|
|
|
nm_utils_strbuf_append_c (&b, &len, '{');
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n_map; i++)
|
|
|
|
|
nm_utils_strbuf_append (&b, &len, " %u:%u", map[i].from, map[i].to);
|
|
|
|
|
nm_utils_strbuf_append_str (&b, &len, " }");
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-06 14:14:14 -06:00
|
|
|
static const char *
|
2014-10-13 11:52:29 +02:00
|
|
|
source_to_string (NMIPConfigSource source)
|
2014-01-06 14:14:14 -06:00
|
|
|
{
|
|
|
|
|
switch (source) {
|
2015-06-23 17:00:24 +02:00
|
|
|
case NM_IP_CONFIG_SOURCE_RTPROT_KERNEL:
|
2015-04-06 20:01:05 +02:00
|
|
|
return "rtprot-kernel";
|
2015-04-14 23:14:06 +02:00
|
|
|
case _NM_IP_CONFIG_SOURCE_RTM_F_CLONED:
|
|
|
|
|
return "rtm-f-cloned";
|
2014-10-13 11:52:29 +02:00
|
|
|
case NM_IP_CONFIG_SOURCE_KERNEL:
|
2014-01-06 14:14:14 -06:00
|
|
|
return "kernel";
|
2014-10-13 11:52:29 +02:00
|
|
|
case NM_IP_CONFIG_SOURCE_SHARED:
|
2014-01-06 14:14:14 -06:00
|
|
|
return "shared";
|
2014-10-13 11:52:29 +02:00
|
|
|
case NM_IP_CONFIG_SOURCE_IP4LL:
|
2014-01-06 14:14:14 -06:00
|
|
|
return "ipv4ll";
|
2014-10-13 11:52:29 +02:00
|
|
|
case NM_IP_CONFIG_SOURCE_PPP:
|
2014-01-06 14:14:14 -06:00
|
|
|
return "ppp";
|
2014-10-13 11:52:29 +02:00
|
|
|
case NM_IP_CONFIG_SOURCE_WWAN:
|
2014-01-06 14:14:14 -06:00
|
|
|
return "wwan";
|
2014-10-13 11:52:29 +02:00
|
|
|
case NM_IP_CONFIG_SOURCE_VPN:
|
2014-01-06 14:14:14 -06:00
|
|
|
return "vpn";
|
2014-10-13 11:52:29 +02:00
|
|
|
case NM_IP_CONFIG_SOURCE_DHCP:
|
2014-01-06 14:14:14 -06:00
|
|
|
return "dhcp";
|
2014-10-13 11:52:29 +02:00
|
|
|
case NM_IP_CONFIG_SOURCE_RDISC:
|
2014-01-06 14:14:14 -06:00
|
|
|
return "rdisc";
|
2014-10-13 11:52:29 +02:00
|
|
|
case NM_IP_CONFIG_SOURCE_USER:
|
2014-01-06 14:14:14 -06:00
|
|
|
return "user";
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return "unknown";
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-02 14:31:12 +02:00
|
|
|
static const char *
|
|
|
|
|
_lifetime_to_string (guint32 timestamp, guint32 lifetime, gint32 now, char *buf, size_t buf_size)
|
|
|
|
|
{
|
|
|
|
|
if (lifetime == NM_PLATFORM_LIFETIME_PERMANENT)
|
|
|
|
|
return "forever";
|
|
|
|
|
|
2014-06-06 20:05:08 +02:00
|
|
|
g_snprintf (buf, buf_size, "%usec",
|
2016-03-15 17:29:58 +01:00
|
|
|
nm_utils_lifetime_rebase_relative_time_on_now (timestamp, lifetime, now));
|
2014-04-02 14:31:12 +02:00
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
|
_lifetime_summary_to_string (gint32 now, guint32 timestamp, guint32 preferred, guint32 lifetime, char *buf, size_t buf_size)
|
|
|
|
|
{
|
|
|
|
|
g_snprintf (buf, buf_size, " lifetime %d-%u[%u,%u]",
|
|
|
|
|
(signed) now, (unsigned) timestamp, (unsigned) preferred, (unsigned) lifetime);
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 10:27:33 +02:00
|
|
|
/**
|
|
|
|
|
* nm_platform_link_to_string:
|
|
|
|
|
* @route: pointer to NMPlatformLink address structure
|
|
|
|
|
* @buf: (allow-none): an optional buffer. If %NULL, a static buffer is used.
|
|
|
|
|
* @len: the size of the @buf. If @buf is %NULL, this argument is ignored.
|
|
|
|
|
*
|
|
|
|
|
* A method for converting an link struct into a string representation.
|
|
|
|
|
*
|
|
|
|
|
* Returns: a string representation of the link.
|
|
|
|
|
*/
|
2014-02-17 14:08:32 +01:00
|
|
|
const char *
|
2015-10-12 10:27:33 +02:00
|
|
|
nm_platform_link_to_string (const NMPlatformLink *link, char *buf, gsize len)
|
2014-02-17 14:08:32 +01:00
|
|
|
{
|
|
|
|
|
char master[20];
|
|
|
|
|
char parent[20];
|
2015-05-05 01:25:19 +02:00
|
|
|
GString *str_flags;
|
|
|
|
|
char str_addrmode[30];
|
|
|
|
|
gs_free char *str_addr = NULL;
|
|
|
|
|
gs_free char *str_inet6_token = NULL;
|
2015-10-14 18:45:36 +02:00
|
|
|
const char *str_link_type;
|
2014-02-17 14:08:32 +01:00
|
|
|
|
2015-10-27 10:25:22 +01:00
|
|
|
if (!nm_utils_to_string_buffer_init_null (link, &buf, &len))
|
2015-10-12 10:27:33 +02:00
|
|
|
return buf;
|
2014-02-17 14:08:32 +01:00
|
|
|
|
2015-05-05 01:25:19 +02:00
|
|
|
str_flags = g_string_new (NULL);
|
2016-02-29 15:52:27 +01:00
|
|
|
if (NM_FLAGS_HAS (link->n_ifi_flags, IFF_NOARP))
|
2015-05-05 01:25:19 +02:00
|
|
|
g_string_append (str_flags, "NOARP,");
|
2016-02-29 15:52:27 +01:00
|
|
|
if (NM_FLAGS_HAS (link->n_ifi_flags, IFF_UP))
|
2015-05-05 01:25:19 +02:00
|
|
|
g_string_append (str_flags, "UP");
|
2014-02-17 14:08:32 +01:00
|
|
|
else
|
2015-05-05 01:25:19 +02:00
|
|
|
g_string_append (str_flags, "DOWN");
|
2014-02-17 14:08:32 +01:00
|
|
|
if (link->connected)
|
2015-05-05 01:25:19 +02:00
|
|
|
g_string_append (str_flags, ",LOWER_UP");
|
2014-02-17 14:08:32 +01:00
|
|
|
|
2016-02-29 15:52:27 +01:00
|
|
|
if (link->n_ifi_flags) {
|
2015-05-05 01:25:19 +02:00
|
|
|
char str_flags_buf[64];
|
|
|
|
|
|
2016-02-29 15:52:27 +01:00
|
|
|
nm_platform_link_flags2str (link->n_ifi_flags, str_flags_buf, sizeof (str_flags_buf));
|
2015-05-05 01:25:19 +02:00
|
|
|
g_string_append_printf (str_flags, ";%s", str_flags_buf);
|
2015-04-25 16:42:26 +02:00
|
|
|
}
|
|
|
|
|
|
2014-02-17 14:08:32 +01:00
|
|
|
if (link->master)
|
|
|
|
|
g_snprintf (master, sizeof (master), " master %d", link->master);
|
|
|
|
|
else
|
|
|
|
|
master[0] = 0;
|
|
|
|
|
|
2015-08-17 17:48:37 +02:00
|
|
|
if (link->parent > 0)
|
2015-08-17 18:31:12 +02:00
|
|
|
g_snprintf (parent, sizeof (parent), "@%d", link->parent);
|
2015-08-17 17:48:37 +02:00
|
|
|
else if (link->parent == NM_PLATFORM_LINK_OTHER_NETNS)
|
|
|
|
|
g_strlcpy (parent, "@other-netns", sizeof (parent));
|
2014-02-17 14:08:32 +01:00
|
|
|
else
|
|
|
|
|
parent[0] = 0;
|
|
|
|
|
|
2015-05-05 01:25:19 +02:00
|
|
|
if (link->addr.len)
|
|
|
|
|
str_addr = nm_utils_hwaddr_ntoa (link->addr.data, MIN (link->addr.len, sizeof (link->addr.data)));
|
|
|
|
|
if (link->inet6_token.is_valid)
|
|
|
|
|
str_inet6_token = nm_utils_hwaddr_ntoa (&link->inet6_token.iid, sizeof (link->inet6_token.iid));
|
|
|
|
|
|
2015-10-14 18:45:36 +02:00
|
|
|
str_link_type = nm_link_type_to_string (link->type);
|
|
|
|
|
|
2015-10-12 10:27:33 +02:00
|
|
|
g_snprintf (buf, len,
|
2015-05-05 01:25:19 +02:00
|
|
|
"%d: " /* ifindex */
|
|
|
|
|
"%s" /* name */
|
|
|
|
|
"%s" /* parent */
|
|
|
|
|
" <%s>" /* flags */
|
|
|
|
|
" mtu %d"
|
|
|
|
|
"%s" /* master */
|
|
|
|
|
" arp %u" /* arptype */
|
2016-02-15 16:23:38 +01:00
|
|
|
" %s" /* link->type */
|
2015-05-05 01:25:19 +02:00
|
|
|
"%s%s" /* kind */
|
|
|
|
|
"%s" /* is-in-udev */
|
2016-02-17 14:00:52 +01:00
|
|
|
"%s%s" /* addr-gen-mode */
|
2015-05-05 01:25:19 +02:00
|
|
|
"%s%s" /* addr */
|
|
|
|
|
"%s%s" /* inet6_token */
|
|
|
|
|
"%s%s" /* driver */
|
2015-06-15 14:41:35 +02:00
|
|
|
,
|
2015-05-05 01:25:19 +02:00
|
|
|
link->ifindex,
|
|
|
|
|
link->name,
|
|
|
|
|
parent,
|
|
|
|
|
str_flags->str,
|
2015-04-28 10:11:04 +02:00
|
|
|
link->mtu, master,
|
2015-05-05 01:25:19 +02:00
|
|
|
link->arptype,
|
2016-03-08 17:41:31 +01:00
|
|
|
str_link_type ?: "???",
|
2016-02-15 16:23:38 +01:00
|
|
|
link->kind ? (g_strcmp0 (str_link_type, link->kind) ? "/" : "*") : "?",
|
2015-10-14 18:45:36 +02:00
|
|
|
link->kind && g_strcmp0 (str_link_type, link->kind) ? link->kind : "",
|
2015-05-05 01:25:19 +02:00
|
|
|
link->initialized ? " init" : " not-init",
|
2016-02-17 14:00:52 +01:00
|
|
|
link->inet6_addr_gen_mode_inv ? " addrgenmode " : "",
|
|
|
|
|
link->inet6_addr_gen_mode_inv ? nm_platform_link_inet6_addrgenmode2str (_nm_platform_uint8_inv (link->inet6_addr_gen_mode_inv), str_addrmode, sizeof (str_addrmode)) : "",
|
2015-05-05 01:25:19 +02:00
|
|
|
str_addr ? " addr " : "",
|
|
|
|
|
str_addr ? str_addr : "",
|
|
|
|
|
str_inet6_token ? " inet6token " : "",
|
|
|
|
|
str_inet6_token ? str_inet6_token : "",
|
|
|
|
|
link->driver ? " driver " : "",
|
2015-06-15 14:41:35 +02:00
|
|
|
link->driver ? link->driver : "");
|
2015-05-05 01:25:19 +02:00
|
|
|
g_string_free (str_flags, TRUE);
|
2015-10-12 10:27:33 +02:00
|
|
|
return buf;
|
2014-02-17 14:08:32 +01:00
|
|
|
}
|
|
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
const char *
|
|
|
|
|
nm_platform_lnk_gre_to_string (const NMPlatformLnkGre *lnk, char *buf, gsize len)
|
|
|
|
|
{
|
|
|
|
|
char str_local[30];
|
|
|
|
|
char str_local1[NM_UTILS_INET_ADDRSTRLEN];
|
|
|
|
|
char str_remote[30];
|
|
|
|
|
char str_remote1[NM_UTILS_INET_ADDRSTRLEN];
|
|
|
|
|
char str_ttl[30];
|
|
|
|
|
char str_tos[30];
|
|
|
|
|
char str_parent_ifindex[30];
|
|
|
|
|
char str_input_flags[30];
|
|
|
|
|
char str_output_flags[30];
|
|
|
|
|
char str_input_key[30];
|
|
|
|
|
char str_input_key1[NM_UTILS_INET_ADDRSTRLEN];
|
|
|
|
|
char str_output_key[30];
|
|
|
|
|
char str_output_key1[NM_UTILS_INET_ADDRSTRLEN];
|
|
|
|
|
|
2015-10-27 10:25:22 +01:00
|
|
|
if (!nm_utils_to_string_buffer_init_null (lnk, &buf, &len))
|
2015-10-12 15:15:21 +02:00
|
|
|
return buf;
|
|
|
|
|
|
|
|
|
|
g_snprintf (buf, len,
|
|
|
|
|
"gre"
|
|
|
|
|
"%s" /* remote */
|
|
|
|
|
"%s" /* local */
|
|
|
|
|
"%s" /* parent_ifindex */
|
|
|
|
|
"%s" /* ttl */
|
|
|
|
|
"%s" /* tos */
|
|
|
|
|
"%s" /* path_mtu_discovery */
|
|
|
|
|
"%s" /* iflags */
|
|
|
|
|
"%s" /* oflags */
|
|
|
|
|
"%s" /* ikey */
|
|
|
|
|
"%s" /* okey */
|
|
|
|
|
"",
|
|
|
|
|
lnk->remote ? nm_sprintf_buf (str_remote, " remote %s", nm_utils_inet4_ntop (lnk->remote, str_remote1)) : "",
|
|
|
|
|
lnk->local ? nm_sprintf_buf (str_local, " local %s", nm_utils_inet4_ntop (lnk->local, str_local1)) : "",
|
|
|
|
|
lnk->parent_ifindex ? nm_sprintf_buf (str_parent_ifindex, " dev %d", lnk->parent_ifindex) : "",
|
|
|
|
|
lnk->ttl ? nm_sprintf_buf (str_ttl, " ttl %u", lnk->ttl) : " ttl inherit",
|
|
|
|
|
lnk->tos ? (lnk->tos == 1 ? " tos inherit" : nm_sprintf_buf (str_tos, " tos 0x%x", lnk->tos)) : "",
|
|
|
|
|
lnk->path_mtu_discovery ? "" : " nopmtudisc",
|
|
|
|
|
lnk->input_flags ? nm_sprintf_buf (str_input_flags, " iflags 0x%x", lnk->input_flags) : "",
|
|
|
|
|
lnk->output_flags ? nm_sprintf_buf (str_output_flags, " oflags 0x%x", lnk->output_flags) : "",
|
|
|
|
|
NM_FLAGS_HAS (lnk->input_flags, GRE_KEY) || lnk->input_key ? nm_sprintf_buf (str_input_key, " ikey %s", nm_utils_inet4_ntop (lnk->input_key, str_input_key1)) : "",
|
|
|
|
|
NM_FLAGS_HAS (lnk->output_flags, GRE_KEY) || lnk->output_key ? nm_sprintf_buf (str_output_key, " okey %s", nm_utils_inet4_ntop (lnk->output_key, str_output_key1)) : "");
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-15 15:47:14 +02:00
|
|
|
const char *
|
|
|
|
|
nm_platform_lnk_infiniband_to_string (const NMPlatformLnkInfiniband *lnk, char *buf, gsize len)
|
|
|
|
|
{
|
|
|
|
|
char str_p_key[64];
|
|
|
|
|
|
2015-10-27 10:25:22 +01:00
|
|
|
if (!nm_utils_to_string_buffer_init_null (lnk, &buf, &len))
|
2015-10-15 15:47:14 +02:00
|
|
|
return buf;
|
|
|
|
|
|
|
|
|
|
g_snprintf (buf, len,
|
|
|
|
|
"infiniband"
|
|
|
|
|
"%s" /* p_key */
|
|
|
|
|
"%s%s" /* mode */
|
|
|
|
|
"",
|
|
|
|
|
lnk->p_key ? nm_sprintf_buf (str_p_key, " pkey %d", lnk->p_key) : "",
|
|
|
|
|
lnk->mode ? " mode " : "",
|
|
|
|
|
lnk->mode ?: "");
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-27 22:22:25 +01:00
|
|
|
const char *
|
|
|
|
|
nm_platform_lnk_ip6tnl_to_string (const NMPlatformLnkIp6Tnl *lnk, char *buf, gsize len)
|
|
|
|
|
{
|
|
|
|
|
char str_local[30];
|
|
|
|
|
char str_local1[NM_UTILS_INET_ADDRSTRLEN];
|
|
|
|
|
char str_remote[30];
|
|
|
|
|
char str_remote1[NM_UTILS_INET_ADDRSTRLEN];
|
|
|
|
|
char str_ttl[30];
|
|
|
|
|
char str_tclass[30];
|
|
|
|
|
char str_flow[30];
|
|
|
|
|
char str_encap[30];
|
|
|
|
|
char str_proto[30];
|
|
|
|
|
char str_parent_ifindex[30];
|
|
|
|
|
|
|
|
|
|
if (!nm_utils_to_string_buffer_init_null (lnk, &buf, &len))
|
|
|
|
|
return buf;
|
|
|
|
|
|
|
|
|
|
g_snprintf (buf, len,
|
|
|
|
|
"ip6tnl"
|
|
|
|
|
"%s" /* remote */
|
|
|
|
|
"%s" /* local */
|
|
|
|
|
"%s" /* parent_ifindex */
|
|
|
|
|
"%s" /* ttl */
|
|
|
|
|
"%s" /* tclass */
|
|
|
|
|
"%s" /* encap limit */
|
|
|
|
|
"%s" /* flow label */
|
|
|
|
|
"%s" /* proto */
|
|
|
|
|
"",
|
|
|
|
|
nm_sprintf_buf (str_remote, " remote %s", nm_utils_inet6_ntop (&lnk->remote, str_remote1)),
|
|
|
|
|
nm_sprintf_buf (str_local, " local %s", nm_utils_inet6_ntop (&lnk->local, str_local1)),
|
|
|
|
|
lnk->parent_ifindex ? nm_sprintf_buf (str_parent_ifindex, " dev %d", lnk->parent_ifindex) : "",
|
|
|
|
|
lnk->ttl ? nm_sprintf_buf (str_ttl, " ttl %u", lnk->ttl) : " ttl inherit",
|
|
|
|
|
lnk->tclass == 1 ? " tclass inherit" : nm_sprintf_buf (str_tclass, " tclass 0x%x", lnk->tclass),
|
|
|
|
|
nm_sprintf_buf (str_encap, " encap-limit %u", lnk->encap_limit),
|
|
|
|
|
nm_sprintf_buf (str_flow, " flow-label 0x05%x", lnk->flow_label),
|
|
|
|
|
nm_sprintf_buf (str_proto, " proto %u", lnk->proto));
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-27 14:01:56 +01:00
|
|
|
const char *
|
|
|
|
|
nm_platform_lnk_ipip_to_string (const NMPlatformLnkIpIp *lnk, char *buf, gsize len)
|
|
|
|
|
{
|
|
|
|
|
char str_local[30];
|
|
|
|
|
char str_local1[NM_UTILS_INET_ADDRSTRLEN];
|
|
|
|
|
char str_remote[30];
|
|
|
|
|
char str_remote1[NM_UTILS_INET_ADDRSTRLEN];
|
|
|
|
|
char str_ttl[30];
|
|
|
|
|
char str_tos[30];
|
|
|
|
|
char str_parent_ifindex[30];
|
|
|
|
|
|
|
|
|
|
if (!nm_utils_to_string_buffer_init_null (lnk, &buf, &len))
|
|
|
|
|
return buf;
|
|
|
|
|
|
|
|
|
|
g_snprintf (buf, len,
|
|
|
|
|
"ipip"
|
|
|
|
|
"%s" /* remote */
|
|
|
|
|
"%s" /* local */
|
|
|
|
|
"%s" /* parent_ifindex */
|
|
|
|
|
"%s" /* ttl */
|
|
|
|
|
"%s" /* tos */
|
|
|
|
|
"%s" /* path_mtu_discovery */
|
|
|
|
|
"",
|
|
|
|
|
lnk->remote ? nm_sprintf_buf (str_remote, " remote %s", nm_utils_inet4_ntop (lnk->remote, str_remote1)) : "",
|
|
|
|
|
lnk->local ? nm_sprintf_buf (str_local, " local %s", nm_utils_inet4_ntop (lnk->local, str_local1)) : "",
|
|
|
|
|
lnk->parent_ifindex ? nm_sprintf_buf (str_parent_ifindex, " dev %d", lnk->parent_ifindex) : "",
|
|
|
|
|
lnk->ttl ? nm_sprintf_buf (str_ttl, " ttl %u", lnk->ttl) : " ttl inherit",
|
|
|
|
|
lnk->tos ? (lnk->tos == 1 ? " tos inherit" : nm_sprintf_buf (str_tos, " tos 0x%x", lnk->tos)) : "",
|
|
|
|
|
lnk->path_mtu_discovery ? "" : " nopmtudisc");
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
const char *
|
|
|
|
|
nm_platform_lnk_macvlan_to_string (const NMPlatformLnkMacvlan *lnk, char *buf, gsize len)
|
|
|
|
|
{
|
2015-10-27 10:25:22 +01:00
|
|
|
if (!nm_utils_to_string_buffer_init_null (lnk, &buf, &len))
|
2015-10-12 15:15:21 +02:00
|
|
|
return buf;
|
|
|
|
|
|
|
|
|
|
g_snprintf (buf, len,
|
2015-12-03 15:44:33 +01:00
|
|
|
"macvlan mode %u %s",
|
|
|
|
|
lnk->mode,
|
|
|
|
|
lnk->no_promisc ? "not-promisc" : "promisc");
|
2015-10-12 15:15:21 +02:00
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-11 18:41:48 +01:00
|
|
|
const char *
|
|
|
|
|
nm_platform_lnk_sit_to_string (const NMPlatformLnkSit *lnk, char *buf, gsize len)
|
|
|
|
|
{
|
|
|
|
|
char str_local[30];
|
|
|
|
|
char str_local1[NM_UTILS_INET_ADDRSTRLEN];
|
|
|
|
|
char str_remote[30];
|
|
|
|
|
char str_remote1[NM_UTILS_INET_ADDRSTRLEN];
|
|
|
|
|
char str_ttl[30];
|
|
|
|
|
char str_tos[30];
|
|
|
|
|
char str_flags[30];
|
|
|
|
|
char str_proto[30];
|
|
|
|
|
char str_parent_ifindex[30];
|
|
|
|
|
|
|
|
|
|
if (!nm_utils_to_string_buffer_init_null (lnk, &buf, &len))
|
|
|
|
|
return buf;
|
|
|
|
|
|
|
|
|
|
g_snprintf (buf, len,
|
|
|
|
|
"sit"
|
|
|
|
|
"%s" /* remote */
|
|
|
|
|
"%s" /* local */
|
|
|
|
|
"%s" /* parent_ifindex */
|
|
|
|
|
"%s" /* ttl */
|
|
|
|
|
"%s" /* tos */
|
|
|
|
|
"%s" /* path_mtu_discovery */
|
|
|
|
|
"%s" /* flags */
|
|
|
|
|
"%s" /* proto */
|
|
|
|
|
"",
|
|
|
|
|
lnk->remote ? nm_sprintf_buf (str_remote, " remote %s", nm_utils_inet4_ntop (lnk->remote, str_remote1)) : "",
|
|
|
|
|
lnk->local ? nm_sprintf_buf (str_local, " local %s", nm_utils_inet4_ntop (lnk->local, str_local1)) : "",
|
|
|
|
|
lnk->parent_ifindex ? nm_sprintf_buf (str_parent_ifindex, " dev %d", lnk->parent_ifindex) : "",
|
|
|
|
|
lnk->ttl ? nm_sprintf_buf (str_ttl, " ttl %u", lnk->ttl) : " ttl inherit",
|
|
|
|
|
lnk->tos ? (lnk->tos == 1 ? " tos inherit" : nm_sprintf_buf (str_tos, " tos 0x%x", lnk->tos)) : "",
|
|
|
|
|
lnk->path_mtu_discovery ? "" : " nopmtudisc",
|
|
|
|
|
lnk->flags ? nm_sprintf_buf (str_flags, " flags 0x%x", lnk->flags) : "",
|
|
|
|
|
lnk->proto ? nm_sprintf_buf (str_proto, " proto 0x%x", lnk->proto) : "");
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 13:44:44 +02:00
|
|
|
const char *
|
|
|
|
|
nm_platform_lnk_vlan_to_string (const NMPlatformLnkVlan *lnk, char *buf, gsize len)
|
|
|
|
|
{
|
2015-10-27 16:14:54 +01:00
|
|
|
char *b;
|
|
|
|
|
|
2015-10-27 10:25:22 +01:00
|
|
|
if (!nm_utils_to_string_buffer_init_null (lnk, &buf, &len))
|
2015-10-12 13:44:44 +02:00
|
|
|
return buf;
|
|
|
|
|
|
2015-10-27 16:14:54 +01:00
|
|
|
b = buf;
|
|
|
|
|
|
|
|
|
|
nm_utils_strbuf_append (&b, &len, "vlan %u", lnk->id);
|
|
|
|
|
if (lnk->flags)
|
|
|
|
|
nm_utils_strbuf_append (&b, &len, " flags 0x%x", lnk->flags);
|
2015-10-12 13:44:44 +02:00
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
const char *
|
|
|
|
|
nm_platform_lnk_vxlan_to_string (const NMPlatformLnkVxlan *lnk, char *buf, gsize len)
|
|
|
|
|
{
|
|
|
|
|
char str_group[100];
|
|
|
|
|
char str_group6[100];
|
|
|
|
|
char str_local[100];
|
|
|
|
|
char str_local6[100];
|
|
|
|
|
char str_dev[25];
|
|
|
|
|
char str_limit[25];
|
|
|
|
|
char str_src_port[35];
|
|
|
|
|
char str_dst_port[25];
|
|
|
|
|
char str_tos[25];
|
|
|
|
|
char str_ttl[25];
|
|
|
|
|
|
2015-10-27 10:25:22 +01:00
|
|
|
if (!nm_utils_to_string_buffer_init_null (lnk, &buf, &len))
|
2015-10-12 15:15:21 +02:00
|
|
|
return buf;
|
|
|
|
|
|
|
|
|
|
if (lnk->group == 0)
|
|
|
|
|
str_group[0] = '\0';
|
|
|
|
|
else {
|
|
|
|
|
g_snprintf (str_group, sizeof (str_group),
|
|
|
|
|
" %s %s",
|
|
|
|
|
IN_MULTICAST (ntohl (lnk->group)) ? "group" : "remote",
|
|
|
|
|
nm_utils_inet4_ntop (lnk->group, NULL));
|
|
|
|
|
}
|
|
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED (&lnk->group6))
|
|
|
|
|
str_group6[0] = '\0';
|
|
|
|
|
else {
|
|
|
|
|
g_snprintf (str_group6, sizeof (str_group6),
|
|
|
|
|
" %s%s %s",
|
|
|
|
|
IN6_IS_ADDR_MULTICAST (&lnk->group6) ? "group" : "remote",
|
|
|
|
|
str_group[0] ? "6" : "", /* usually, a vxlan has either v4 or v6 only. */
|
|
|
|
|
nm_utils_inet6_ntop (&lnk->group6, NULL));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lnk->local == 0)
|
|
|
|
|
str_local[0] = '\0';
|
|
|
|
|
else {
|
|
|
|
|
g_snprintf (str_local, sizeof (str_local),
|
|
|
|
|
" local %s",
|
|
|
|
|
nm_utils_inet4_ntop (lnk->local, NULL));
|
|
|
|
|
}
|
|
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED (&lnk->local6))
|
|
|
|
|
str_local6[0] = '\0';
|
|
|
|
|
else {
|
|
|
|
|
g_snprintf (str_local6, sizeof (str_local6),
|
|
|
|
|
" local%s %s",
|
|
|
|
|
str_local[0] ? "6" : "", /* usually, a vxlan has either v4 or v6 only. */
|
|
|
|
|
nm_utils_inet6_ntop (&lnk->local6, NULL));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_snprintf (buf, len,
|
|
|
|
|
"vxlan"
|
|
|
|
|
" id %u" /* id */
|
|
|
|
|
"%s%s" /* group/group6 */
|
|
|
|
|
"%s%s" /* local/local6 */
|
|
|
|
|
"%s" /* dev */
|
|
|
|
|
"%s" /* src_port_min/src_port_max */
|
|
|
|
|
"%s" /* dst_port */
|
|
|
|
|
"%s" /* learning */
|
|
|
|
|
"%s" /* proxy */
|
|
|
|
|
"%s" /* rsc */
|
|
|
|
|
"%s" /* l2miss */
|
|
|
|
|
"%s" /* l3miss */
|
|
|
|
|
"%s" /* tos */
|
|
|
|
|
"%s" /* ttl */
|
|
|
|
|
" ageing %u" /* ageing */
|
|
|
|
|
"%s" /* limit */
|
|
|
|
|
"",
|
|
|
|
|
(guint) lnk->id,
|
|
|
|
|
str_group, str_group6,
|
|
|
|
|
str_local, str_local6,
|
|
|
|
|
lnk->parent_ifindex ? nm_sprintf_buf (str_dev, " dev %d", lnk->parent_ifindex) : "",
|
|
|
|
|
lnk->src_port_min || lnk->src_port_max ? nm_sprintf_buf (str_src_port, " srcport %u %u", lnk->src_port_min, lnk->src_port_max) : "",
|
|
|
|
|
lnk->dst_port ? nm_sprintf_buf (str_dst_port, " dstport %u", lnk->dst_port) : "",
|
|
|
|
|
!lnk->learning ? " nolearning" : "",
|
|
|
|
|
lnk->proxy ? " proxy" : "",
|
|
|
|
|
lnk->rsc ? " rsc" : "",
|
|
|
|
|
lnk->l2miss ? " l2miss" : "",
|
|
|
|
|
lnk->l3miss ? " l3miss" : "",
|
|
|
|
|
lnk->tos == 1 ? " tos inherit" : nm_sprintf_buf (str_tos, " tos %#x", lnk->tos),
|
|
|
|
|
lnk->ttl ? nm_sprintf_buf (str_ttl, " ttl %u", lnk->ttl) : "",
|
|
|
|
|
lnk->ageing,
|
|
|
|
|
lnk->limit ? nm_sprintf_buf (str_limit, " maxaddr %u", lnk->limit) : "");
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-29 20:07:34 +02:00
|
|
|
/**
|
|
|
|
|
* nm_platform_ip4_address_to_string:
|
|
|
|
|
* @route: pointer to NMPlatformIP4Address address structure
|
2015-10-12 10:27:33 +02:00
|
|
|
* @buf: (allow-none): an optional buffer. If %NULL, a static buffer is used.
|
|
|
|
|
* @len: the size of the @buf. If @buf is %NULL, this argument is ignored.
|
2013-08-29 20:07:34 +02:00
|
|
|
*
|
|
|
|
|
* A method for converting an address struct into a string representation.
|
|
|
|
|
*
|
|
|
|
|
* Example output: ""
|
|
|
|
|
*
|
2015-10-12 10:27:33 +02:00
|
|
|
* Returns: a string representation of the address.
|
2013-08-29 20:07:34 +02:00
|
|
|
*/
|
|
|
|
|
const char *
|
2015-10-12 10:27:33 +02:00
|
|
|
nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address, char *buf, gsize len)
|
2013-08-29 20:07:34 +02:00
|
|
|
{
|
2016-02-29 16:50:55 +01:00
|
|
|
char s_flags[TO_STRING_IFA_FLAGS_BUF_SIZE];
|
2013-08-29 20:07:34 +02:00
|
|
|
char s_address[INET_ADDRSTRLEN];
|
2013-12-02 21:12:05 +01:00
|
|
|
char s_peer[INET_ADDRSTRLEN];
|
2014-02-18 12:52:16 +01:00
|
|
|
char str_dev[TO_STRING_DEV_BUF_SIZE];
|
2014-02-19 16:10:59 -05:00
|
|
|
char str_label[32];
|
2014-04-02 14:31:12 +02:00
|
|
|
char str_lft[30], str_pref[30], str_time[50];
|
2013-12-02 21:12:05 +01:00
|
|
|
char *str_peer = NULL;
|
2014-04-02 14:31:12 +02:00
|
|
|
const char *str_lft_p, *str_pref_p, *str_time_p;
|
|
|
|
|
gint32 now = nm_utils_get_monotonic_timestamp_s ();
|
2013-08-29 20:07:34 +02:00
|
|
|
|
2015-10-27 10:25:22 +01:00
|
|
|
if (!nm_utils_to_string_buffer_init_null (address, &buf, &len))
|
2015-10-12 10:27:33 +02:00
|
|
|
return buf;
|
2013-08-29 20:07:34 +02:00
|
|
|
|
|
|
|
|
inet_ntop (AF_INET, &address->address, s_address, sizeof (s_address));
|
2013-10-21 14:36:59 +02:00
|
|
|
|
2015-10-21 23:17:11 +02:00
|
|
|
if (address->peer_address != address->address) {
|
2013-12-02 21:12:05 +01:00
|
|
|
inet_ntop (AF_INET, &address->peer_address, s_peer, sizeof (s_peer));
|
|
|
|
|
str_peer = g_strconcat (" ptp ", s_peer, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_to_string_dev (NULL, address->ifindex, str_dev, sizeof (str_dev));
|
2013-08-29 20:07:34 +02:00
|
|
|
|
2014-02-19 16:10:59 -05:00
|
|
|
if (*address->label)
|
|
|
|
|
g_snprintf (str_label, sizeof (str_label), " label %s", address->label);
|
|
|
|
|
else
|
|
|
|
|
str_label[0] = 0;
|
|
|
|
|
|
2014-04-02 14:31:12 +02:00
|
|
|
str_lft_p = _lifetime_to_string (address->timestamp,
|
|
|
|
|
address->lifetime ? address->lifetime : NM_PLATFORM_LIFETIME_PERMANENT,
|
|
|
|
|
now, str_lft, sizeof (str_lft)),
|
|
|
|
|
str_pref_p = (address->lifetime == address->preferred)
|
|
|
|
|
? str_lft_p
|
|
|
|
|
: ( _lifetime_to_string (address->timestamp,
|
|
|
|
|
address->lifetime ? MIN (address->preferred, address->lifetime) : NM_PLATFORM_LIFETIME_PERMANENT,
|
|
|
|
|
now, str_pref, sizeof (str_pref)) );
|
|
|
|
|
str_time_p = _lifetime_summary_to_string (now, address->timestamp, address->preferred, address->lifetime, str_time, sizeof (str_time));
|
|
|
|
|
|
2015-10-12 10:27:33 +02:00
|
|
|
g_snprintf (buf, len,
|
2016-02-29 16:50:55 +01:00
|
|
|
"%s/%d lft %s pref %s%s%s%s%s%s src %s",
|
2014-04-02 14:31:12 +02:00
|
|
|
s_address, address->plen, str_lft_p, str_pref_p, str_time_p,
|
2013-12-02 21:12:05 +01:00
|
|
|
str_peer ? str_peer : "",
|
2014-02-18 12:52:16 +01:00
|
|
|
str_dev,
|
2016-02-29 16:50:55 +01:00
|
|
|
_to_string_ifa_flags (address->n_ifa_flags, s_flags, sizeof (s_flags)),
|
2014-02-19 16:10:59 -05:00
|
|
|
str_label,
|
2014-01-06 14:14:14 -06:00
|
|
|
source_to_string (address->source));
|
2013-12-02 21:12:05 +01:00
|
|
|
g_free (str_peer);
|
2015-10-12 10:27:33 +02:00
|
|
|
return buf;
|
2013-08-29 20:07:34 +02:00
|
|
|
}
|
|
|
|
|
|
2015-12-04 16:31:15 +01:00
|
|
|
NM_UTILS_FLAGS2STR_DEFINE (nm_platform_link_flags2str, unsigned,
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFF_LOOPBACK, "loopback"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFF_BROADCAST, "broadcast"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFF_POINTOPOINT, "pointopoint"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFF_MULTICAST, "multicast"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFF_NOARP, "noarp"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFF_ALLMULTI, "allmulti"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFF_PROMISC, "promisc"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFF_MASTER, "master"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFF_SLAVE, "slave"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFF_DEBUG, "debug"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFF_DYNAMIC, "dynamic"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFF_AUTOMEDIA, "automedia"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFF_PORTSEL, "portsel"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFF_NOTRAILERS, "notrailers"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFF_UP, "up"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFF_RUNNING, "running"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFF_LOWER_UP, "lowerup"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFF_DORMANT, "dormant"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFF_ECHO, "echo"),
|
|
|
|
|
);
|
2015-10-26 21:35:18 +01:00
|
|
|
|
2016-01-18 12:54:04 +01:00
|
|
|
NM_UTILS_ENUM2STR_DEFINE (nm_platform_link_inet6_addrgenmode2str, guint8,
|
|
|
|
|
NM_UTILS_ENUM2STR (NM_IN6_ADDR_GEN_MODE_NONE, "none"),
|
|
|
|
|
NM_UTILS_ENUM2STR (NM_IN6_ADDR_GEN_MODE_EUI64, "eui64"),
|
|
|
|
|
NM_UTILS_ENUM2STR (NM_IN6_ADDR_GEN_MODE_STABLE_PRIVACY, "stable-privacy"),
|
2016-02-17 14:19:17 +01:00
|
|
|
NM_UTILS_ENUM2STR (NM_IN6_ADDR_GEN_MODE_RANDOM, "random"),
|
2016-01-18 12:54:04 +01:00
|
|
|
);
|
2015-10-26 21:35:18 +01:00
|
|
|
|
2015-12-04 16:31:15 +01:00
|
|
|
NM_UTILS_FLAGS2STR_DEFINE (nm_platform_addr_flags2str, unsigned,
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFA_F_SECONDARY, "secondary"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFA_F_NODAD, "nodad"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFA_F_OPTIMISTIC, "optimistic"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFA_F_HOMEADDRESS, "homeaddress"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFA_F_DEPRECATED, "deprecated"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFA_F_TENTATIVE, "tentative"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFA_F_PERMANENT, "permanent"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFA_F_MANAGETEMPADDR, "mngtmpaddr"),
|
|
|
|
|
NM_UTILS_FLAGS2STR (IFA_F_NOPREFIXROUTE, "noprefixroute"),
|
|
|
|
|
);
|
2015-10-26 21:35:18 +01:00
|
|
|
|
2016-01-18 12:54:04 +01:00
|
|
|
NM_UTILS_ENUM2STR_DEFINE (nm_platform_route_scope2str, int,
|
|
|
|
|
NM_UTILS_ENUM2STR (RT_SCOPE_NOWHERE, "nowhere"),
|
|
|
|
|
NM_UTILS_ENUM2STR (RT_SCOPE_HOST, "host"),
|
|
|
|
|
NM_UTILS_ENUM2STR (RT_SCOPE_LINK, "link"),
|
|
|
|
|
NM_UTILS_ENUM2STR (RT_SCOPE_SITE, "site"),
|
|
|
|
|
NM_UTILS_ENUM2STR (RT_SCOPE_UNIVERSE, "global"),
|
|
|
|
|
);
|
2014-03-04 22:00:24 +01:00
|
|
|
|
2013-08-29 20:07:34 +02:00
|
|
|
/**
|
|
|
|
|
* nm_platform_ip6_address_to_string:
|
|
|
|
|
* @route: pointer to NMPlatformIP6Address address structure
|
2015-10-12 10:27:33 +02:00
|
|
|
* @buf: (allow-none): an optional buffer. If %NULL, a static buffer is used.
|
|
|
|
|
* @len: the size of the @buf. If @buf is %NULL, this argument is ignored.
|
2013-08-29 20:07:34 +02:00
|
|
|
*
|
|
|
|
|
* A method for converting an address struct into a string representation.
|
|
|
|
|
*
|
|
|
|
|
* Example output: "2001:db8:0:f101::1/64 lft 4294967295 pref 4294967295 time 16922666 on dev em1"
|
|
|
|
|
*
|
2015-10-12 10:27:33 +02:00
|
|
|
* Returns: a string representation of the address.
|
2013-08-29 20:07:34 +02:00
|
|
|
*/
|
|
|
|
|
const char *
|
2015-10-12 10:27:33 +02:00
|
|
|
nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address, char *buf, gsize len)
|
2013-08-29 20:07:34 +02:00
|
|
|
{
|
2016-02-29 16:50:55 +01:00
|
|
|
char s_flags[TO_STRING_IFA_FLAGS_BUF_SIZE];
|
2013-08-29 20:07:34 +02:00
|
|
|
char s_address[INET6_ADDRSTRLEN];
|
2013-12-02 21:12:05 +01:00
|
|
|
char s_peer[INET6_ADDRSTRLEN];
|
2014-04-02 14:31:12 +02:00
|
|
|
char str_lft[30], str_pref[30], str_time[50];
|
2014-02-18 12:52:16 +01:00
|
|
|
char str_dev[TO_STRING_DEV_BUF_SIZE];
|
2013-12-02 21:12:05 +01:00
|
|
|
char *str_peer = NULL;
|
2014-04-02 14:31:12 +02:00
|
|
|
const char *str_lft_p, *str_pref_p, *str_time_p;
|
|
|
|
|
gint32 now = nm_utils_get_monotonic_timestamp_s ();
|
2013-08-29 20:07:34 +02:00
|
|
|
|
2015-10-27 10:25:22 +01:00
|
|
|
if (!nm_utils_to_string_buffer_init_null (address, &buf, &len))
|
2015-10-12 10:27:33 +02:00
|
|
|
return buf;
|
2013-08-29 20:07:34 +02:00
|
|
|
|
|
|
|
|
inet_ntop (AF_INET6, &address->address, s_address, sizeof (s_address));
|
2013-10-21 14:36:59 +02:00
|
|
|
|
2013-12-02 21:12:05 +01:00
|
|
|
if (!IN6_IS_ADDR_UNSPECIFIED (&address->peer_address)) {
|
|
|
|
|
inet_ntop (AF_INET6, &address->peer_address, s_peer, sizeof (s_peer));
|
|
|
|
|
str_peer = g_strconcat (" ptp ", s_peer, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_to_string_dev (NULL, address->ifindex, str_dev, sizeof (str_dev));
|
2013-08-29 20:07:34 +02:00
|
|
|
|
2014-04-02 14:31:12 +02:00
|
|
|
str_lft_p = _lifetime_to_string (address->timestamp,
|
|
|
|
|
address->lifetime ? address->lifetime : NM_PLATFORM_LIFETIME_PERMANENT,
|
|
|
|
|
now, str_lft, sizeof (str_lft)),
|
|
|
|
|
str_pref_p = (address->lifetime == address->preferred)
|
|
|
|
|
? str_lft_p
|
|
|
|
|
: ( _lifetime_to_string (address->timestamp,
|
|
|
|
|
address->lifetime ? MIN (address->preferred, address->lifetime) : NM_PLATFORM_LIFETIME_PERMANENT,
|
|
|
|
|
now, str_pref, sizeof (str_pref)) );
|
|
|
|
|
str_time_p = _lifetime_summary_to_string (now, address->timestamp, address->preferred, address->lifetime, str_time, sizeof (str_time));
|
|
|
|
|
|
2015-10-12 10:27:33 +02:00
|
|
|
g_snprintf (buf, len,
|
|
|
|
|
"%s/%d lft %s pref %s%s%s%s%s src %s",
|
2014-04-02 14:31:12 +02:00
|
|
|
s_address, address->plen, str_lft_p, str_pref_p, str_time_p,
|
2013-12-02 21:12:05 +01:00
|
|
|
str_peer ? str_peer : "",
|
2014-02-18 12:52:16 +01:00
|
|
|
str_dev,
|
2016-02-29 16:50:55 +01:00
|
|
|
_to_string_ifa_flags (address->n_ifa_flags, s_flags, sizeof (s_flags)),
|
2014-01-06 14:14:14 -06:00
|
|
|
source_to_string (address->source));
|
2013-12-02 21:12:05 +01:00
|
|
|
g_free (str_peer);
|
2015-10-12 10:27:33 +02:00
|
|
|
return buf;
|
2013-08-29 20:07:34 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-26 22:10:11 +02:00
|
|
|
/**
|
|
|
|
|
* nm_platform_ip4_route_to_string:
|
|
|
|
|
* @route: pointer to NMPlatformIP4Route route structure
|
2015-10-12 10:27:33 +02:00
|
|
|
* @buf: (allow-none): an optional buffer. If %NULL, a static buffer is used.
|
|
|
|
|
* @len: the size of the @buf. If @buf is %NULL, this argument is ignored.
|
2013-08-26 22:10:11 +02:00
|
|
|
*
|
|
|
|
|
* A method for converting a route struct into a string representation.
|
|
|
|
|
*
|
2013-08-29 20:07:34 +02:00
|
|
|
* Example output: "192.168.1.0/24 via 0.0.0.0 dev em1 metric 0 mss 0"
|
|
|
|
|
*
|
2015-10-12 10:27:33 +02:00
|
|
|
* Returns: a string representation of the route.
|
2013-08-26 22:10:11 +02:00
|
|
|
*/
|
2013-08-29 20:07:34 +02:00
|
|
|
const char *
|
2015-10-12 10:27:33 +02:00
|
|
|
nm_platform_ip4_route_to_string (const NMPlatformIP4Route *route, char *buf, gsize len)
|
2013-08-26 22:10:11 +02:00
|
|
|
{
|
2013-08-29 20:07:34 +02:00
|
|
|
char s_network[INET_ADDRSTRLEN], s_gateway[INET_ADDRSTRLEN];
|
2015-06-22 13:22:48 +02:00
|
|
|
char s_pref_src[INET_ADDRSTRLEN];
|
2014-02-18 12:52:16 +01:00
|
|
|
char str_dev[TO_STRING_DEV_BUF_SIZE];
|
2015-05-03 10:47:41 +02:00
|
|
|
char str_scope[30];
|
2013-08-29 20:07:34 +02:00
|
|
|
|
2015-10-27 10:25:22 +01:00
|
|
|
if (!nm_utils_to_string_buffer_init_null (route, &buf, &len))
|
2015-10-12 10:27:33 +02:00
|
|
|
return buf;
|
2013-08-29 20:07:34 +02:00
|
|
|
|
2013-08-26 22:10:11 +02:00
|
|
|
inet_ntop (AF_INET, &route->network, s_network, sizeof(s_network));
|
|
|
|
|
inet_ntop (AF_INET, &route->gateway, s_gateway, sizeof(s_gateway));
|
2013-10-21 14:36:59 +02:00
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_to_string_dev (NULL, route->ifindex, str_dev, sizeof (str_dev));
|
2013-08-29 20:07:34 +02:00
|
|
|
|
2015-10-12 10:27:33 +02:00
|
|
|
g_snprintf (buf, len,
|
2015-06-22 13:02:23 +02:00
|
|
|
"%s/%d"
|
|
|
|
|
" via %s"
|
|
|
|
|
"%s"
|
|
|
|
|
" metric %"G_GUINT32_FORMAT
|
|
|
|
|
" mss %"G_GUINT32_FORMAT
|
|
|
|
|
" src %s" /* source */
|
|
|
|
|
"%s%s" /* scope */
|
2015-06-22 13:22:48 +02:00
|
|
|
"%s%s" /* pref-src */
|
2015-06-22 13:02:23 +02:00
|
|
|
"",
|
2016-04-06 14:19:05 +02:00
|
|
|
s_network,
|
|
|
|
|
route->plen,
|
2015-06-22 13:02:23 +02:00
|
|
|
s_gateway,
|
2014-02-18 12:52:16 +01:00
|
|
|
str_dev,
|
2015-06-22 13:02:23 +02:00
|
|
|
route->metric,
|
|
|
|
|
route->mss,
|
2015-05-03 10:47:41 +02:00
|
|
|
source_to_string (route->source),
|
|
|
|
|
route->scope_inv ? " scope " : "",
|
2015-10-26 21:35:18 +01:00
|
|
|
route->scope_inv ? (nm_platform_route_scope2str (nm_platform_route_scope_inv (route->scope_inv), str_scope, sizeof (str_scope))) : "",
|
2015-06-22 13:22:48 +02:00
|
|
|
route->pref_src ? " pref-src " : "",
|
|
|
|
|
route->pref_src ? inet_ntop (AF_INET, &route->pref_src, s_pref_src, sizeof(s_pref_src)) : "");
|
2015-10-12 10:27:33 +02:00
|
|
|
return buf;
|
2013-08-29 20:07:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* nm_platform_ip6_route_to_string:
|
|
|
|
|
* @route: pointer to NMPlatformIP6Route route structure
|
2015-10-12 10:27:33 +02:00
|
|
|
* @buf: (allow-none): an optional buffer. If %NULL, a static buffer is used.
|
|
|
|
|
* @len: the size of the @buf. If @buf is %NULL, this argument is ignored.
|
2013-08-29 20:07:34 +02:00
|
|
|
*
|
|
|
|
|
* A method for converting a route struct into a string representation.
|
|
|
|
|
*
|
|
|
|
|
* Example output: "ff02::fb/128 via :: dev em1 metric 0"
|
|
|
|
|
*
|
2015-10-12 10:27:33 +02:00
|
|
|
* Returns: a string representation of the route.
|
2013-08-29 20:07:34 +02:00
|
|
|
*/
|
|
|
|
|
const char *
|
2015-10-12 10:27:33 +02:00
|
|
|
nm_platform_ip6_route_to_string (const NMPlatformIP6Route *route, char *buf, gsize len)
|
2013-08-29 20:07:34 +02:00
|
|
|
{
|
|
|
|
|
char s_network[INET6_ADDRSTRLEN], s_gateway[INET6_ADDRSTRLEN];
|
2014-02-18 12:52:16 +01:00
|
|
|
char str_dev[TO_STRING_DEV_BUF_SIZE];
|
2013-08-29 20:07:34 +02:00
|
|
|
|
2015-10-27 10:25:22 +01:00
|
|
|
if (!nm_utils_to_string_buffer_init_null (route, &buf, &len))
|
2015-10-12 10:27:33 +02:00
|
|
|
return buf;
|
2013-08-29 20:07:34 +02:00
|
|
|
|
|
|
|
|
inet_ntop (AF_INET6, &route->network, s_network, sizeof(s_network));
|
|
|
|
|
inet_ntop (AF_INET6, &route->gateway, s_gateway, sizeof(s_gateway));
|
2013-10-21 14:36:59 +02:00
|
|
|
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_to_string_dev (NULL, route->ifindex, str_dev, sizeof (str_dev));
|
2013-08-29 20:07:34 +02:00
|
|
|
|
2015-10-12 10:27:33 +02:00
|
|
|
g_snprintf (buf, len,
|
2015-06-22 13:02:23 +02:00
|
|
|
"%s/%d"
|
|
|
|
|
" via %s"
|
|
|
|
|
"%s"
|
|
|
|
|
" metric %"G_GUINT32_FORMAT
|
|
|
|
|
" mss %"G_GUINT32_FORMAT
|
|
|
|
|
" src %s" /* source */
|
|
|
|
|
"",
|
2016-04-06 14:19:05 +02:00
|
|
|
s_network,
|
|
|
|
|
route->plen,
|
2015-06-22 13:02:23 +02:00
|
|
|
s_gateway,
|
2014-02-18 12:52:16 +01:00
|
|
|
str_dev,
|
2015-06-22 13:02:23 +02:00
|
|
|
route->metric,
|
|
|
|
|
route->mss,
|
2014-01-06 14:14:14 -06:00
|
|
|
source_to_string (route->source));
|
2015-10-12 10:27:33 +02:00
|
|
|
return buf;
|
2013-08-26 22:10:11 +02:00
|
|
|
}
|
|
|
|
|
|
2015-10-11 15:12:45 +02:00
|
|
|
#define _CMP_SELF(a, b) \
|
2013-09-06 09:58:55 +02:00
|
|
|
G_STMT_START { \
|
|
|
|
|
if ((a) == (b)) \
|
|
|
|
|
return 0; \
|
|
|
|
|
if (!(a)) \
|
|
|
|
|
return -1; \
|
|
|
|
|
if (!(b)) \
|
|
|
|
|
return 1; \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
2015-10-10 17:48:32 +02:00
|
|
|
#define _CMP_DIRECT(a, b) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
if ((a) != (b)) \
|
|
|
|
|
return ((a) < (b)) ? -1 : 1; \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
2015-10-11 21:46:42 +02:00
|
|
|
#define _CMP_DIRECT_MEMCMP(a, b, size) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
int c = memcmp ((a), (b), (size)); \
|
|
|
|
|
if (c != 0) \
|
|
|
|
|
return c < 0 ? -1 : 1; \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
2013-09-06 09:58:55 +02:00
|
|
|
#define _CMP_FIELD(a, b, field) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
if (((a)->field) != ((b)->field)) \
|
|
|
|
|
return (((a)->field) < ((b)->field)) ? -1 : 1; \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
2015-04-13 16:29:37 -05:00
|
|
|
#define _CMP_FIELD_BOOL(a, b, field) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
if ((!((a)->field)) != (!((b)->field))) \
|
|
|
|
|
return ((!((a)->field)) < (!((b)->field))) ? -1 : 1; \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
2014-02-19 16:10:59 -05:00
|
|
|
#define _CMP_FIELD_STR(a, b, field) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
int c = strcmp ((a)->field, (b)->field); \
|
|
|
|
|
if (c != 0) \
|
|
|
|
|
return c < 0 ? -1 : 1; \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
2015-04-28 10:11:04 +02:00
|
|
|
#define _CMP_FIELD_STR_INTERNED(a, b, field) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
if (((a)->field) != ((b)->field)) { \
|
|
|
|
|
/* just to be sure, also do a strcmp() if the pointers don't match */ \
|
|
|
|
|
int c = g_strcmp0 ((a)->field, (b)->field); \
|
|
|
|
|
if (c != 0) \
|
|
|
|
|
return c < 0 ? -1 : 1; \
|
|
|
|
|
} \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
2014-04-05 18:35:20 +02:00
|
|
|
#define _CMP_FIELD_STR0(a, b, field) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
int c = g_strcmp0 ((a)->field, (b)->field); \
|
|
|
|
|
if (c != 0) \
|
|
|
|
|
return c < 0 ? -1 : 1; \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
2015-04-27 18:06:59 +02:00
|
|
|
#define _CMP_FIELD_MEMCMP_LEN(a, b, field, len) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
int c = memcmp (&((a)->field), &((b)->field), \
|
|
|
|
|
MIN (len, sizeof ((a)->field))); \
|
|
|
|
|
if (c != 0) \
|
|
|
|
|
return c < 0 ? -1 : 1; \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
2013-09-06 09:58:55 +02:00
|
|
|
#define _CMP_FIELD_MEMCMP(a, b, field) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
int c = memcmp (&((a)->field), &((b)->field), \
|
|
|
|
|
sizeof ((a)->field)); \
|
|
|
|
|
if (c != 0) \
|
|
|
|
|
return c < 0 ? -1 : 1; \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
2014-04-05 18:35:20 +02:00
|
|
|
int
|
|
|
|
|
nm_platform_link_cmp (const NMPlatformLink *a, const NMPlatformLink *b)
|
|
|
|
|
{
|
2015-10-11 15:12:45 +02:00
|
|
|
_CMP_SELF (a, b);
|
2015-05-03 16:37:07 +02:00
|
|
|
_CMP_FIELD (a, b, ifindex);
|
2014-04-05 18:35:20 +02:00
|
|
|
_CMP_FIELD (a, b, type);
|
|
|
|
|
_CMP_FIELD_STR (a, b, name);
|
|
|
|
|
_CMP_FIELD (a, b, master);
|
|
|
|
|
_CMP_FIELD (a, b, parent);
|
2016-02-29 15:52:27 +01:00
|
|
|
_CMP_FIELD (a, b, n_ifi_flags);
|
2014-04-05 18:35:20 +02:00
|
|
|
_CMP_FIELD (a, b, connected);
|
|
|
|
|
_CMP_FIELD (a, b, mtu);
|
2015-04-13 16:29:37 -05:00
|
|
|
_CMP_FIELD_BOOL (a, b, initialized);
|
2015-04-27 18:45:23 +02:00
|
|
|
_CMP_FIELD (a, b, arptype);
|
2015-04-27 18:06:59 +02:00
|
|
|
_CMP_FIELD (a, b, addr.len);
|
2015-04-27 18:32:43 +02:00
|
|
|
_CMP_FIELD (a, b, inet6_addr_gen_mode_inv);
|
2015-04-27 21:05:13 +02:00
|
|
|
_CMP_FIELD (a, b, inet6_token.is_valid);
|
2015-04-28 10:11:04 +02:00
|
|
|
_CMP_FIELD_STR_INTERNED (a, b, kind);
|
2015-04-29 09:19:15 +02:00
|
|
|
_CMP_FIELD_STR_INTERNED (a, b, driver);
|
2015-04-27 18:06:59 +02:00
|
|
|
if (a->addr.len)
|
|
|
|
|
_CMP_FIELD_MEMCMP_LEN (a, b, addr.data, a->addr.len);
|
2015-04-27 21:05:13 +02:00
|
|
|
if (a->inet6_token.is_valid)
|
|
|
|
|
_CMP_FIELD_MEMCMP (a, b, inet6_token.iid);
|
2014-04-05 18:35:20 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
int
|
|
|
|
|
nm_platform_lnk_gre_cmp (const NMPlatformLnkGre *a, const NMPlatformLnkGre *b)
|
|
|
|
|
{
|
|
|
|
|
_CMP_SELF (a, b);
|
|
|
|
|
_CMP_FIELD (a, b, parent_ifindex);
|
|
|
|
|
_CMP_FIELD (a, b, input_flags);
|
|
|
|
|
_CMP_FIELD (a, b, output_flags);
|
|
|
|
|
_CMP_FIELD (a, b, input_key);
|
|
|
|
|
_CMP_FIELD (a, b, output_key);
|
|
|
|
|
_CMP_FIELD (a, b, local);
|
|
|
|
|
_CMP_FIELD (a, b, remote);
|
|
|
|
|
_CMP_FIELD (a, b, ttl);
|
|
|
|
|
_CMP_FIELD (a, b, tos);
|
|
|
|
|
_CMP_FIELD_BOOL (a, b, path_mtu_discovery);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-15 15:47:14 +02:00
|
|
|
int
|
|
|
|
|
nm_platform_lnk_infiniband_cmp (const NMPlatformLnkInfiniband *a, const NMPlatformLnkInfiniband *b)
|
|
|
|
|
{
|
|
|
|
|
_CMP_SELF (a, b);
|
|
|
|
|
_CMP_FIELD (a, b, p_key);
|
|
|
|
|
_CMP_FIELD_STR_INTERNED (a, b, mode);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-27 22:22:25 +01:00
|
|
|
int
|
|
|
|
|
nm_platform_lnk_ip6tnl_cmp (const NMPlatformLnkIp6Tnl *a, const NMPlatformLnkIp6Tnl *b)
|
|
|
|
|
{
|
|
|
|
|
_CMP_SELF (a, b);
|
|
|
|
|
_CMP_FIELD (a, b, parent_ifindex);
|
|
|
|
|
_CMP_FIELD_MEMCMP (a, b, local);
|
|
|
|
|
_CMP_FIELD_MEMCMP (a, b, remote);
|
|
|
|
|
_CMP_FIELD (a, b, ttl);
|
|
|
|
|
_CMP_FIELD (a, b, tclass);
|
|
|
|
|
_CMP_FIELD (a, b, encap_limit);
|
|
|
|
|
_CMP_FIELD (a, b, flow_label);
|
|
|
|
|
_CMP_FIELD (a, b, proto);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-27 14:01:56 +01:00
|
|
|
int
|
|
|
|
|
nm_platform_lnk_ipip_cmp (const NMPlatformLnkIpIp *a, const NMPlatformLnkIpIp *b)
|
|
|
|
|
{
|
|
|
|
|
_CMP_SELF (a, b);
|
|
|
|
|
_CMP_FIELD (a, b, parent_ifindex);
|
|
|
|
|
_CMP_FIELD (a, b, local);
|
|
|
|
|
_CMP_FIELD (a, b, remote);
|
|
|
|
|
_CMP_FIELD (a, b, ttl);
|
|
|
|
|
_CMP_FIELD (a, b, tos);
|
|
|
|
|
_CMP_FIELD_BOOL (a, b, path_mtu_discovery);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
int
|
|
|
|
|
nm_platform_lnk_macvlan_cmp (const NMPlatformLnkMacvlan *a, const NMPlatformLnkMacvlan *b)
|
|
|
|
|
{
|
|
|
|
|
_CMP_SELF (a, b);
|
2015-12-03 15:44:33 +01:00
|
|
|
_CMP_FIELD (a, b, mode);
|
2015-10-12 15:15:21 +02:00
|
|
|
_CMP_FIELD_BOOL (a, b, no_promisc);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-11 18:41:48 +01:00
|
|
|
int
|
|
|
|
|
nm_platform_lnk_sit_cmp (const NMPlatformLnkSit *a, const NMPlatformLnkSit *b)
|
|
|
|
|
{
|
|
|
|
|
_CMP_SELF (a, b);
|
|
|
|
|
_CMP_FIELD (a, b, parent_ifindex);
|
|
|
|
|
_CMP_FIELD (a, b, local);
|
|
|
|
|
_CMP_FIELD (a, b, remote);
|
|
|
|
|
_CMP_FIELD (a, b, ttl);
|
|
|
|
|
_CMP_FIELD (a, b, tos);
|
|
|
|
|
_CMP_FIELD_BOOL (a, b, path_mtu_discovery);
|
|
|
|
|
_CMP_FIELD (a, b, flags);
|
|
|
|
|
_CMP_FIELD (a, b, proto);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 13:44:44 +02:00
|
|
|
int
|
|
|
|
|
nm_platform_lnk_vlan_cmp (const NMPlatformLnkVlan *a, const NMPlatformLnkVlan *b)
|
|
|
|
|
{
|
|
|
|
|
_CMP_SELF (a, b);
|
|
|
|
|
_CMP_FIELD (a, b, id);
|
2015-10-27 16:14:54 +01:00
|
|
|
_CMP_FIELD (a, b, flags);
|
2015-10-12 13:44:44 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-12 15:15:21 +02:00
|
|
|
int
|
|
|
|
|
nm_platform_lnk_vxlan_cmp (const NMPlatformLnkVxlan *a, const NMPlatformLnkVxlan *b)
|
|
|
|
|
{
|
|
|
|
|
_CMP_SELF (a, b);
|
|
|
|
|
_CMP_FIELD (a, b, parent_ifindex);
|
|
|
|
|
_CMP_FIELD (a, b, id);
|
|
|
|
|
_CMP_FIELD (a, b, group);
|
|
|
|
|
_CMP_FIELD (a, b, local);
|
|
|
|
|
_CMP_FIELD_MEMCMP (a, b, group6);
|
|
|
|
|
_CMP_FIELD_MEMCMP (a, b, local6);
|
|
|
|
|
_CMP_FIELD (a, b, tos);
|
|
|
|
|
_CMP_FIELD (a, b, ttl);
|
|
|
|
|
_CMP_FIELD_BOOL (a, b, learning);
|
|
|
|
|
_CMP_FIELD (a, b, ageing);
|
|
|
|
|
_CMP_FIELD (a, b, limit);
|
|
|
|
|
_CMP_FIELD (a, b, dst_port);
|
|
|
|
|
_CMP_FIELD (a, b, src_port_min);
|
|
|
|
|
_CMP_FIELD (a, b, src_port_max);
|
|
|
|
|
_CMP_FIELD_BOOL (a, b, proxy);
|
|
|
|
|
_CMP_FIELD_BOOL (a, b, rsc);
|
|
|
|
|
_CMP_FIELD_BOOL (a, b, l2miss);
|
|
|
|
|
_CMP_FIELD_BOOL (a, b, l3miss);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-06 09:58:55 +02:00
|
|
|
int
|
|
|
|
|
nm_platform_ip4_address_cmp (const NMPlatformIP4Address *a, const NMPlatformIP4Address *b)
|
|
|
|
|
{
|
2015-10-11 15:12:45 +02:00
|
|
|
_CMP_SELF (a, b);
|
2014-01-06 14:14:14 -06:00
|
|
|
_CMP_FIELD (a, b, ifindex);
|
|
|
|
|
_CMP_FIELD (a, b, source);
|
2014-01-15 20:09:57 +01:00
|
|
|
_CMP_FIELD (a, b, address);
|
2013-09-06 09:58:55 +02:00
|
|
|
_CMP_FIELD (a, b, plen);
|
2015-10-21 23:17:11 +02:00
|
|
|
_CMP_FIELD (a, b, peer_address);
|
2013-09-06 09:58:55 +02:00
|
|
|
_CMP_FIELD (a, b, timestamp);
|
|
|
|
|
_CMP_FIELD (a, b, lifetime);
|
|
|
|
|
_CMP_FIELD (a, b, preferred);
|
2016-02-29 16:50:55 +01:00
|
|
|
_CMP_FIELD (a, b, n_ifa_flags);
|
2014-02-19 16:10:59 -05:00
|
|
|
_CMP_FIELD_STR (a, b, label);
|
2013-09-06 09:58:55 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
nm_platform_ip6_address_cmp (const NMPlatformIP6Address *a, const NMPlatformIP6Address *b)
|
|
|
|
|
{
|
2015-10-11 21:46:42 +02:00
|
|
|
const struct in6_addr *p_a, *p_b;
|
|
|
|
|
|
2015-10-11 15:12:45 +02:00
|
|
|
_CMP_SELF (a, b);
|
2013-09-06 09:58:55 +02:00
|
|
|
_CMP_FIELD (a, b, ifindex);
|
2014-01-06 14:14:14 -06:00
|
|
|
_CMP_FIELD (a, b, source);
|
2013-09-06 09:58:55 +02:00
|
|
|
_CMP_FIELD_MEMCMP (a, b, address);
|
2015-10-11 21:46:42 +02:00
|
|
|
|
|
|
|
|
p_a = nm_platform_ip6_address_get_peer (a);
|
|
|
|
|
p_b = nm_platform_ip6_address_get_peer (b);
|
|
|
|
|
_CMP_DIRECT_MEMCMP (p_a, p_b, sizeof (*p_a));
|
|
|
|
|
|
2013-09-06 09:58:55 +02:00
|
|
|
_CMP_FIELD (a, b, plen);
|
|
|
|
|
_CMP_FIELD (a, b, timestamp);
|
|
|
|
|
_CMP_FIELD (a, b, lifetime);
|
|
|
|
|
_CMP_FIELD (a, b, preferred);
|
2016-02-29 16:23:16 +01:00
|
|
|
_CMP_FIELD (a, b, n_ifa_flags);
|
2013-09-06 09:58:55 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
nm_platform_ip4_route_cmp (const NMPlatformIP4Route *a, const NMPlatformIP4Route *b)
|
|
|
|
|
{
|
2015-10-11 15:12:45 +02:00
|
|
|
_CMP_SELF (a, b);
|
2013-09-06 09:58:55 +02:00
|
|
|
_CMP_FIELD (a, b, ifindex);
|
2014-01-06 14:14:14 -06:00
|
|
|
_CMP_FIELD (a, b, source);
|
2014-01-15 20:09:57 +01:00
|
|
|
_CMP_FIELD (a, b, network);
|
2013-09-06 09:58:55 +02:00
|
|
|
_CMP_FIELD (a, b, plen);
|
2014-01-15 20:09:57 +01:00
|
|
|
_CMP_FIELD (a, b, gateway);
|
2013-09-06 09:58:55 +02:00
|
|
|
_CMP_FIELD (a, b, metric);
|
|
|
|
|
_CMP_FIELD (a, b, mss);
|
2015-05-03 10:47:41 +02:00
|
|
|
_CMP_FIELD (a, b, scope_inv);
|
2015-06-22 13:22:48 +02:00
|
|
|
_CMP_FIELD (a, b, pref_src);
|
2013-09-06 09:58:55 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
nm_platform_ip6_route_cmp (const NMPlatformIP6Route *a, const NMPlatformIP6Route *b)
|
|
|
|
|
{
|
2015-10-11 15:12:45 +02:00
|
|
|
_CMP_SELF (a, b);
|
2013-09-06 09:58:55 +02:00
|
|
|
_CMP_FIELD (a, b, ifindex);
|
2014-01-06 14:14:14 -06:00
|
|
|
_CMP_FIELD (a, b, source);
|
2013-09-06 09:58:55 +02:00
|
|
|
_CMP_FIELD_MEMCMP (a, b, network);
|
|
|
|
|
_CMP_FIELD (a, b, plen);
|
|
|
|
|
_CMP_FIELD_MEMCMP (a, b, gateway);
|
|
|
|
|
_CMP_FIELD (a, b, metric);
|
|
|
|
|
_CMP_FIELD (a, b, mss);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-03 11:42:00 +02:00
|
|
|
/**
|
|
|
|
|
* nm_platform_ip_address_cmp_expiry:
|
|
|
|
|
* @a: a NMPlatformIPAddress to compare
|
|
|
|
|
* @b: the other NMPlatformIPAddress to compare
|
|
|
|
|
*
|
|
|
|
|
* Compares two addresses and returns which one has a longer remaining lifetime.
|
|
|
|
|
* If both addresses have the same lifetime, look at the remaining preferred time.
|
|
|
|
|
*
|
|
|
|
|
* For comparison, only the timestamp, lifetime and preferred fields are considered.
|
|
|
|
|
* If they compare equal (== 0), their other fields were not considered.
|
|
|
|
|
*
|
|
|
|
|
* Returns: -1, 0, or 1 according to the comparison
|
|
|
|
|
**/
|
|
|
|
|
int
|
|
|
|
|
nm_platform_ip_address_cmp_expiry (const NMPlatformIPAddress *a, const NMPlatformIPAddress *b)
|
|
|
|
|
{
|
2014-06-09 10:28:55 +02:00
|
|
|
gint64 ta = 0, tb = 0;
|
2014-04-03 11:42:00 +02:00
|
|
|
|
2015-10-11 15:12:45 +02:00
|
|
|
_CMP_SELF (a, b);
|
2014-04-03 11:42:00 +02:00
|
|
|
|
|
|
|
|
if (a->lifetime == NM_PLATFORM_LIFETIME_PERMANENT || a->lifetime == 0)
|
|
|
|
|
ta = G_MAXINT64;
|
2014-06-09 10:28:55 +02:00
|
|
|
else if (a->timestamp)
|
2014-04-03 11:42:00 +02:00
|
|
|
ta = ((gint64) a->timestamp) + a->lifetime;
|
|
|
|
|
|
|
|
|
|
if (b->lifetime == NM_PLATFORM_LIFETIME_PERMANENT || b->lifetime == 0)
|
|
|
|
|
tb = G_MAXINT64;
|
2014-06-09 10:28:55 +02:00
|
|
|
else if (b->timestamp)
|
2014-04-03 11:42:00 +02:00
|
|
|
tb = ((gint64) b->timestamp) + b->lifetime;
|
|
|
|
|
|
|
|
|
|
if (ta == tb) {
|
|
|
|
|
/* if the lifetime is equal, compare the preferred time. */
|
2014-06-09 10:28:55 +02:00
|
|
|
ta = tb = 0;
|
2014-04-03 11:42:00 +02:00
|
|
|
|
|
|
|
|
if (a->preferred == NM_PLATFORM_LIFETIME_PERMANENT || a->lifetime == 0 /* liftime==0 means permanent! */)
|
|
|
|
|
ta = G_MAXINT64;
|
2014-06-09 10:28:55 +02:00
|
|
|
else if (a->timestamp)
|
2014-04-03 11:42:00 +02:00
|
|
|
ta = ((gint64) a->timestamp) + a->preferred;
|
|
|
|
|
|
|
|
|
|
if (b->preferred == NM_PLATFORM_LIFETIME_PERMANENT|| b->lifetime == 0)
|
|
|
|
|
tb = G_MAXINT64;
|
2014-06-09 10:28:55 +02:00
|
|
|
else if (b->timestamp)
|
2014-04-03 11:42:00 +02:00
|
|
|
tb = ((gint64) b->timestamp) + b->preferred;
|
|
|
|
|
|
|
|
|
|
if (ta == tb)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ta < tb ? -1 : 1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-24 12:28:07 +02:00
|
|
|
const char *
|
|
|
|
|
nm_platform_signal_change_type_to_string (NMPlatformSignalChangeType change_type)
|
2014-03-07 19:04:38 +01:00
|
|
|
{
|
|
|
|
|
switch (change_type) {
|
|
|
|
|
case NM_PLATFORM_SIGNAL_ADDED:
|
|
|
|
|
return "added";
|
|
|
|
|
case NM_PLATFORM_SIGNAL_CHANGED:
|
|
|
|
|
return "changed";
|
|
|
|
|
case NM_PLATFORM_SIGNAL_REMOVED:
|
|
|
|
|
return "removed";
|
|
|
|
|
default:
|
|
|
|
|
g_return_val_if_reached ("UNKNOWN");
|
|
|
|
|
}
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-02 14:35:38 +02:00
|
|
|
log_link (NMPlatform *self, NMPObjectType obj_type, int ifindex, NMPlatformLink *device, NMPlatformSignalChangeType change_type, gpointer user_data)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
|
|
|
|
|
2015-10-12 10:27:33 +02:00
|
|
|
_LOGD ("signal: link %7s: %s", nm_platform_signal_change_type_to_string (change_type), nm_platform_link_to_string (device, NULL, 0));
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-02 14:35:38 +02:00
|
|
|
log_ip4_address (NMPlatform *self, NMPObjectType obj_type, int ifindex, NMPlatformIP4Address *address, NMPlatformSignalChangeType change_type, gpointer user_data)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
2015-10-12 10:27:33 +02:00
|
|
|
_LOGD ("signal: address 4 %7s: %s", nm_platform_signal_change_type_to_string (change_type), nm_platform_ip4_address_to_string (address, NULL, 0));
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-02 14:35:38 +02:00
|
|
|
log_ip6_address (NMPlatform *self, NMPObjectType obj_type, int ifindex, NMPlatformIP6Address *address, NMPlatformSignalChangeType change_type, gpointer user_data)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
2015-10-12 10:27:33 +02:00
|
|
|
_LOGD ("signal: address 6 %7s: %s", nm_platform_signal_change_type_to_string (change_type), nm_platform_ip6_address_to_string (address, NULL, 0));
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-02 14:35:38 +02:00
|
|
|
log_ip4_route (NMPlatform *self, NMPObjectType obj_type, int ifindex, NMPlatformIP4Route *route, NMPlatformSignalChangeType change_type, gpointer user_data)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
2015-10-12 10:27:33 +02:00
|
|
|
_LOGD ("signal: route 4 %7s: %s", nm_platform_signal_change_type_to_string (change_type), nm_platform_ip4_route_to_string (route, NULL, 0));
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-02 14:35:38 +02:00
|
|
|
log_ip6_route (NMPlatform *self, NMPObjectType obj_type, int ifindex, NMPlatformIP6Route *route, NMPlatformSignalChangeType change_type, gpointer user_data)
|
2013-03-27 22:23:24 +01:00
|
|
|
{
|
2015-10-12 10:27:33 +02:00
|
|
|
_LOGD ("signal: route 6 %7s: %s", nm_platform_signal_change_type_to_string (change_type), nm_platform_ip6_route_to_string (route, NULL, 0));
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
2013-03-27 22:23:24 +01:00
|
|
|
/******************************************************************/
|
|
|
|
|
|
2016-02-19 01:06:28 +01:00
|
|
|
NMPNetns *
|
|
|
|
|
nm_platform_netns_get (NMPlatform *self)
|
|
|
|
|
{
|
|
|
|
|
_CHECK_SELF (self, klass, NULL);
|
|
|
|
|
|
|
|
|
|
return self->_netns;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
nm_platform_netns_push (NMPlatform *platform, NMPNetns **netns)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (NM_IS_PLATFORM (platform), FALSE);
|
|
|
|
|
|
|
|
|
|
if ( platform->_netns
|
|
|
|
|
&& !nmp_netns_push (platform->_netns)) {
|
|
|
|
|
NM_SET_OUT (netns, NULL);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NM_SET_OUT (netns, platform->_netns);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
2015-03-25 11:28:19 +01:00
|
|
|
static gboolean
|
2015-07-05 13:25:49 +02:00
|
|
|
_vtr_v4_route_add (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route, gint64 metric)
|
2015-03-25 11:28:19 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return nm_platform_ip4_route_add (self,
|
|
|
|
|
ifindex > 0 ? ifindex : route->rx.ifindex,
|
2015-03-25 11:28:19 +01:00
|
|
|
route->rx.source,
|
|
|
|
|
route->r4.network,
|
|
|
|
|
route->rx.plen,
|
|
|
|
|
route->r4.gateway,
|
2015-06-22 13:22:48 +02:00
|
|
|
route->r4.pref_src,
|
2015-07-05 13:25:49 +02:00
|
|
|
metric >= 0 ? (guint32) metric : route->rx.metric,
|
2015-03-25 11:28:19 +01:00
|
|
|
route->rx.mss);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2015-07-05 13:25:49 +02:00
|
|
|
_vtr_v6_route_add (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route, gint64 metric)
|
2015-03-25 11:28:19 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return nm_platform_ip6_route_add (self,
|
|
|
|
|
ifindex > 0 ? ifindex : route->rx.ifindex,
|
2015-03-25 11:28:19 +01:00
|
|
|
route->rx.source,
|
|
|
|
|
route->r6.network,
|
|
|
|
|
route->rx.plen,
|
|
|
|
|
route->r6.gateway,
|
2015-07-05 13:25:49 +02:00
|
|
|
metric >= 0 ? (guint32) metric : route->rx.metric,
|
2015-03-25 11:28:19 +01:00
|
|
|
route->rx.mss);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_vtr_v4_route_delete (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route)
|
2015-03-25 11:28:19 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return nm_platform_ip4_route_delete (self,
|
|
|
|
|
ifindex > 0 ? ifindex : route->rx.ifindex,
|
2015-03-25 11:28:19 +01:00
|
|
|
route->r4.network,
|
|
|
|
|
route->rx.plen,
|
|
|
|
|
route->rx.metric);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_vtr_v6_route_delete (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route)
|
2015-03-25 11:28:19 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return nm_platform_ip6_route_delete (self,
|
|
|
|
|
ifindex > 0 ? ifindex : route->rx.ifindex,
|
2015-03-25 11:28:19 +01:00
|
|
|
route->r6.network,
|
|
|
|
|
route->rx.plen,
|
|
|
|
|
route->rx.metric);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static guint32
|
|
|
|
|
_vtr_v4_metric_normalize (guint32 metric)
|
|
|
|
|
{
|
|
|
|
|
return metric;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_vtr_v4_route_delete_default (NMPlatform *self, int ifindex, guint32 metric)
|
2015-03-25 11:28:19 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return nm_platform_ip4_route_delete (self, ifindex, 0, 0, metric);
|
2015-03-25 11:28:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
_vtr_v6_route_delete_default (NMPlatform *self, int ifindex, guint32 metric)
|
2015-03-25 11:28:19 +01:00
|
|
|
{
|
platform: add self argument to platform functions
Most nm_platform_*() functions operate on the platform
singleton nm_platform_get(). That made sense because the
NMPlatform instance was mainly to hook fake platform for
testing.
While the implicit argument saved some typing, I think explicit is
better. Especially, because NMPlatform could become a more usable
object then just a hook for testing.
With this change, NMPlatform instances can be used individually, not
only as a singleton instance.
Before this change, the constructor of NMLinuxPlatform could not
call any nm_platform_*() functions because the singleton was not
yet initialized. We could only instantiate an incomplete instance,
register it via nm_platform_setup(), and then complete initialization
via singleton->setup().
With this change, we can create and fully initialize NMPlatform instances
before/without setting them up them as singleton.
Also, currently there is no clear distinction between functions
that operate on the NMPlatform instance, and functions that can
be used stand-alone (e.g. nm_platform_ip4_address_to_string()).
The latter can not be mocked for testing. With this change, the
distinction becomes obvious. That is also useful because it becomes
clearer which functions make use of the platform cache and which not.
Inside nm-linux-platform.c, continue the pattern that the
self instance is named @platform. That makes sense because
its type is NMPlatform, and not NMLinuxPlatform what we
would expect from a paramter named @self.
This is a major diff that causes some pain when rebasing. Try
to rebase to the parent commit of this commit as a first step.
Then rebase on top of this commit using merge-strategy "ours".
2015-04-18 12:36:09 +02:00
|
|
|
return nm_platform_ip6_route_delete (self, ifindex, in6addr_any, 0, metric);
|
2015-03-25 11:28:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
|
|
|
|
const NMPlatformVTableRoute nm_platform_vtable_route_v4 = {
|
|
|
|
|
.is_ip4 = TRUE,
|
|
|
|
|
.addr_family = AF_INET,
|
|
|
|
|
.sizeof_route = sizeof (NMPlatformIP4Route),
|
|
|
|
|
.route_cmp = (int (*) (const NMPlatformIPXRoute *a, const NMPlatformIPXRoute *b)) nm_platform_ip4_route_cmp,
|
2015-10-12 10:27:33 +02:00
|
|
|
.route_to_string = (const char *(*) (const NMPlatformIPXRoute *route, char *buf, gsize len)) nm_platform_ip4_route_to_string,
|
2015-03-25 11:28:19 +01:00
|
|
|
.route_get_all = nm_platform_ip4_route_get_all,
|
|
|
|
|
.route_add = _vtr_v4_route_add,
|
|
|
|
|
.route_delete = _vtr_v4_route_delete,
|
|
|
|
|
.route_delete_default = _vtr_v4_route_delete_default,
|
|
|
|
|
.metric_normalize = _vtr_v4_metric_normalize,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const NMPlatformVTableRoute nm_platform_vtable_route_v6 = {
|
|
|
|
|
.is_ip4 = FALSE,
|
|
|
|
|
.addr_family = AF_INET6,
|
|
|
|
|
.sizeof_route = sizeof (NMPlatformIP6Route),
|
|
|
|
|
.route_cmp = (int (*) (const NMPlatformIPXRoute *a, const NMPlatformIPXRoute *b)) nm_platform_ip6_route_cmp,
|
2015-10-12 10:27:33 +02:00
|
|
|
.route_to_string = (const char *(*) (const NMPlatformIPXRoute *route, char *buf, gsize len)) nm_platform_ip6_route_to_string,
|
2015-03-25 11:28:19 +01:00
|
|
|
.route_get_all = nm_platform_ip6_route_get_all,
|
|
|
|
|
.route_add = _vtr_v6_route_add,
|
|
|
|
|
.route_delete = _vtr_v6_route_delete,
|
|
|
|
|
.route_delete_default = _vtr_v6_route_delete_default,
|
|
|
|
|
.metric_normalize = nm_utils_ip6_route_metric_normalize,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/******************************************************************/
|
|
|
|
|
|
2015-05-12 07:34:56 +02:00
|
|
|
static void
|
|
|
|
|
set_property (GObject *object, guint prop_id,
|
|
|
|
|
const GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
2016-02-19 01:06:28 +01:00
|
|
|
NMPlatform *self = NM_PLATFORM (object);
|
|
|
|
|
NMPlatformPrivate *priv = NM_PLATFORM_GET_PRIVATE (self);
|
2015-05-12 07:34:56 +02:00
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2016-02-19 01:06:28 +01:00
|
|
|
case PROP_NETNS_SUPPORT:
|
|
|
|
|
/* construct-only */
|
|
|
|
|
if (g_value_get_boolean (value)) {
|
|
|
|
|
NMPNetns *netns;
|
|
|
|
|
|
|
|
|
|
netns = nmp_netns_get_current ();
|
|
|
|
|
if (netns)
|
|
|
|
|
self->_netns = g_object_ref (netns);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2015-05-12 07:34:56 +02:00
|
|
|
case PROP_REGISTER_SINGLETON:
|
|
|
|
|
/* construct-only */
|
|
|
|
|
priv->register_singleton = g_value_get_boolean (value);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
constructed (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
NMPlatform *self = NM_PLATFORM (object);
|
|
|
|
|
NMPlatformPrivate *priv = NM_PLATFORM_GET_PRIVATE (self);
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (nm_platform_parent_class)->constructed (object);
|
|
|
|
|
|
|
|
|
|
if (priv->register_singleton)
|
|
|
|
|
nm_platform_setup (self);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-27 22:23:24 +01:00
|
|
|
static void
|
|
|
|
|
nm_platform_init (NMPlatform *object)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-19 01:06:28 +01:00
|
|
|
static void
|
|
|
|
|
finalize (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
NMPlatform *self = NM_PLATFORM (object);
|
|
|
|
|
|
|
|
|
|
g_clear_object (&self->_netns);
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-27 22:23:24 +01:00
|
|
|
static void
|
|
|
|
|
nm_platform_class_init (NMPlatformClass *platform_class)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (platform_class);
|
|
|
|
|
|
2015-05-12 07:34:56 +02:00
|
|
|
g_type_class_add_private (object_class, sizeof (NMPlatformPrivate));
|
|
|
|
|
|
|
|
|
|
object_class->set_property = set_property;
|
|
|
|
|
object_class->constructed = constructed;
|
2016-02-19 01:06:28 +01:00
|
|
|
object_class->finalize = finalize;
|
2015-05-12 07:34:56 +02:00
|
|
|
|
2014-10-23 14:19:59 -04:00
|
|
|
platform_class->wifi_set_powersave = wifi_set_powersave;
|
|
|
|
|
|
2016-02-19 01:06:28 +01:00
|
|
|
g_object_class_install_property
|
|
|
|
|
(object_class, PROP_NETNS_SUPPORT,
|
|
|
|
|
g_param_spec_boolean (NM_PLATFORM_NETNS_SUPPORT, "", "",
|
2016-04-07 12:22:44 +02:00
|
|
|
NM_PLATFORM_NETNS_SUPPORT_DEFAULT,
|
2016-02-19 01:06:28 +01:00
|
|
|
G_PARAM_WRITABLE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
2015-05-12 07:34:56 +02:00
|
|
|
g_object_class_install_property
|
|
|
|
|
(object_class, PROP_REGISTER_SINGLETON,
|
|
|
|
|
g_param_spec_boolean (NM_PLATFORM_REGISTER_SINGLETON, "", "",
|
|
|
|
|
FALSE,
|
|
|
|
|
G_PARAM_WRITABLE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
2015-11-27 12:54:31 +01:00
|
|
|
#define SIGNAL(signal, signal_id, method) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
signals[signal] = \
|
|
|
|
|
g_signal_new_class_handler (""signal_id"", \
|
|
|
|
|
G_OBJECT_CLASS_TYPE (object_class), \
|
|
|
|
|
G_SIGNAL_RUN_FIRST, \
|
|
|
|
|
G_CALLBACK (method), \
|
|
|
|
|
NULL, NULL, NULL, \
|
|
|
|
|
G_TYPE_NONE, 4, NM_TYPE_POBJECT_TYPE, G_TYPE_INT, G_TYPE_POINTER, NM_TYPE_PLATFORM_SIGNAL_CHANGE_TYPE); \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
2013-03-27 22:23:24 +01:00
|
|
|
/* Signals */
|
2015-11-27 12:54:31 +01:00
|
|
|
SIGNAL (NM_PLATFORM_SIGNAL_ID_LINK, NM_PLATFORM_SIGNAL_LINK_CHANGED, log_link);
|
|
|
|
|
SIGNAL (NM_PLATFORM_SIGNAL_ID_IP4_ADDRESS, NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, log_ip4_address);
|
|
|
|
|
SIGNAL (NM_PLATFORM_SIGNAL_ID_IP6_ADDRESS, NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, log_ip6_address);
|
|
|
|
|
SIGNAL (NM_PLATFORM_SIGNAL_ID_IP4_ROUTE, NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, log_ip4_route);
|
|
|
|
|
SIGNAL (NM_PLATFORM_SIGNAL_ID_IP6_ROUTE, NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, log_ip6_route);
|
2013-03-27 22:23:24 +01:00
|
|
|
}
|