2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2016-02-16 20:05:15 +01:00
|
|
|
#pragma once
|
|
|
|
|
2016-04-29 04:52:04 +02:00
|
|
|
#include "sd-netlink.h"
|
2014-07-06 14:07:34 +02:00
|
|
|
|
2018-11-12 08:45:04 +01:00
|
|
|
#include "conf-parser.h"
|
2016-04-29 04:52:04 +02:00
|
|
|
#include "list.h"
|
2018-11-28 21:06:52 +01:00
|
|
|
#include "../networkd-link.h"
|
2016-04-29 04:52:04 +02:00
|
|
|
#include "time-util.h"
|
2015-08-27 13:59:06 +02:00
|
|
|
|
2014-07-06 14:07:34 +02:00
|
|
|
typedef struct netdev_join_callback netdev_join_callback;
|
|
|
|
|
|
|
|
struct netdev_join_callback {
|
2018-11-28 21:06:52 +01:00
|
|
|
link_netlink_message_handler_t callback;
|
2014-07-06 14:07:34 +02:00
|
|
|
Link *link;
|
|
|
|
|
|
|
|
LIST_FIELDS(netdev_join_callback, callbacks);
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum NetDevKind {
|
|
|
|
NETDEV_KIND_BRIDGE,
|
|
|
|
NETDEV_KIND_BOND,
|
|
|
|
NETDEV_KIND_VLAN,
|
|
|
|
NETDEV_KIND_MACVLAN,
|
2015-07-27 07:48:28 +02:00
|
|
|
NETDEV_KIND_MACVTAP,
|
2015-01-19 22:24:32 +01:00
|
|
|
NETDEV_KIND_IPVLAN,
|
2014-07-06 14:07:34 +02:00
|
|
|
NETDEV_KIND_VXLAN,
|
|
|
|
NETDEV_KIND_IPIP,
|
|
|
|
NETDEV_KIND_GRE,
|
2014-12-20 09:05:06 +01:00
|
|
|
NETDEV_KIND_GRETAP,
|
2015-01-18 18:54:24 +01:00
|
|
|
NETDEV_KIND_IP6GRE,
|
|
|
|
NETDEV_KIND_IP6GRETAP,
|
2014-07-06 14:07:34 +02:00
|
|
|
NETDEV_KIND_SIT,
|
|
|
|
NETDEV_KIND_VETH,
|
|
|
|
NETDEV_KIND_VTI,
|
2015-04-22 10:44:55 +02:00
|
|
|
NETDEV_KIND_VTI6,
|
2015-01-16 20:09:10 +01:00
|
|
|
NETDEV_KIND_IP6TNL,
|
2014-07-06 14:07:34 +02:00
|
|
|
NETDEV_KIND_DUMMY,
|
|
|
|
NETDEV_KIND_TUN,
|
|
|
|
NETDEV_KIND_TAP,
|
2016-06-10 01:57:51 +02:00
|
|
|
NETDEV_KIND_VRF,
|
2016-09-14 18:15:16 +02:00
|
|
|
NETDEV_KIND_VCAN,
|
2017-04-25 06:15:05 +02:00
|
|
|
NETDEV_KIND_GENEVE,
|
2017-11-22 08:23:22 +01:00
|
|
|
NETDEV_KIND_VXCAN,
|
2017-12-18 15:20:34 +01:00
|
|
|
NETDEV_KIND_WIREGUARD,
|
2018-06-02 15:06:33 +02:00
|
|
|
NETDEV_KIND_NETDEVSIM,
|
2018-06-03 09:07:41 +02:00
|
|
|
NETDEV_KIND_FOU,
|
2018-11-26 12:50:09 +01:00
|
|
|
NETDEV_KIND_ERSPAN,
|
2014-07-06 14:07:34 +02:00
|
|
|
_NETDEV_KIND_MAX,
|
|
|
|
_NETDEV_KIND_INVALID = -1
|
|
|
|
} NetDevKind;
|
|
|
|
|
|
|
|
typedef enum NetDevState {
|
2018-01-04 11:36:58 +01:00
|
|
|
NETDEV_STATE_LOADING,
|
2014-07-06 14:07:34 +02:00
|
|
|
NETDEV_STATE_FAILED,
|
|
|
|
NETDEV_STATE_CREATING,
|
|
|
|
NETDEV_STATE_READY,
|
|
|
|
NETDEV_STATE_LINGER,
|
|
|
|
_NETDEV_STATE_MAX,
|
|
|
|
_NETDEV_STATE_INVALID = -1,
|
|
|
|
} NetDevState;
|
|
|
|
|
2014-07-16 13:17:10 +02:00
|
|
|
typedef enum NetDevCreateType {
|
|
|
|
NETDEV_CREATE_INDEPENDENT,
|
|
|
|
NETDEV_CREATE_MASTER,
|
|
|
|
NETDEV_CREATE_STACKED,
|
|
|
|
_NETDEV_CREATE_MAX,
|
|
|
|
_NETDEV_CREATE_INVALID = -1,
|
|
|
|
} NetDevCreateType;
|
|
|
|
|
2016-04-29 04:52:04 +02:00
|
|
|
typedef struct Manager Manager;
|
|
|
|
typedef struct Condition Condition;
|
|
|
|
|
|
|
|
typedef struct NetDev {
|
2014-07-06 14:07:34 +02:00
|
|
|
Manager *manager;
|
|
|
|
|
2018-08-27 06:48:04 +02:00
|
|
|
unsigned n_ref;
|
2014-07-06 14:07:34 +02:00
|
|
|
|
|
|
|
char *filename;
|
|
|
|
|
|
|
|
Condition *match_host;
|
|
|
|
Condition *match_virt;
|
core,udev,networkd: add ConditionKernelVersion=
This adds a simple condition/assert/match to the service manager, to
udev's .link handling and to networkd, for matching the kernel version
string.
In this version we only do fnmatch() based globbing, but we might want
to extend that to version comparisons later on, if we like, by slightly
extending the syntax with ">=", "<=", ">", "<" and "==" expressions.
2017-12-13 20:34:13 +01:00
|
|
|
Condition *match_kernel_cmdline;
|
|
|
|
Condition *match_kernel_version;
|
2014-07-06 14:07:34 +02:00
|
|
|
Condition *match_arch;
|
|
|
|
|
2014-07-16 13:17:10 +02:00
|
|
|
NetDevState state;
|
|
|
|
NetDevKind kind;
|
2014-07-06 14:07:34 +02:00
|
|
|
char *description;
|
|
|
|
char *ifname;
|
|
|
|
struct ether_addr *mac;
|
2018-04-20 16:33:00 +02:00
|
|
|
uint32_t mtu;
|
2014-07-06 14:07:34 +02:00
|
|
|
int ifindex;
|
|
|
|
|
|
|
|
LIST_HEAD(netdev_join_callback, callbacks);
|
2016-04-29 04:52:04 +02:00
|
|
|
} NetDev;
|
2014-07-06 14:07:34 +02:00
|
|
|
|
2016-04-29 04:52:04 +02:00
|
|
|
typedef struct NetDevVTable {
|
2014-07-16 13:17:10 +02:00
|
|
|
/* How much memory does an object of this unit type need */
|
|
|
|
size_t object_size;
|
|
|
|
|
|
|
|
/* Config file sections this netdev kind understands, separated
|
|
|
|
* by NUL chars */
|
|
|
|
const char *sections;
|
2014-07-06 14:07:34 +02:00
|
|
|
|
2014-07-16 13:17:10 +02:00
|
|
|
/* This should reset all type-specific variables. This should
|
|
|
|
* not allocate memory, and is called with zero-initialized
|
|
|
|
* data. It should hence only initialize variables that need
|
|
|
|
* to be set != 0. */
|
|
|
|
void (*init)(NetDev *n);
|
2014-07-06 14:07:34 +02:00
|
|
|
|
2014-07-16 13:17:10 +02:00
|
|
|
/* This should free all kind-specific variables. It should be
|
|
|
|
* idempotent. */
|
|
|
|
void (*done)(NetDev *n);
|
|
|
|
|
|
|
|
/* fill in message to create netdev */
|
2015-06-12 16:31:33 +02:00
|
|
|
int (*fill_message_create)(NetDev *netdev, Link *link, sd_netlink_message *message);
|
2014-07-16 13:17:10 +02:00
|
|
|
|
|
|
|
/* specifies if netdev is independent, or a master device or a stacked device */
|
|
|
|
NetDevCreateType create_type;
|
2014-07-06 14:07:34 +02:00
|
|
|
|
|
|
|
/* create netdev, if not done via rtnl */
|
|
|
|
int (*create)(NetDev *netdev);
|
|
|
|
|
2015-10-05 06:08:00 +02:00
|
|
|
/* perform additional configuration after netdev has been createad */
|
|
|
|
int (*post_create)(NetDev *netdev, Link *link, sd_netlink_message *message);
|
|
|
|
|
2014-07-06 14:07:34 +02:00
|
|
|
/* verify that compulsory configuration options were specified */
|
|
|
|
int (*config_verify)(NetDev *netdev, const char *filename);
|
2016-04-29 04:52:04 +02:00
|
|
|
} NetDevVTable;
|
2014-07-06 14:07:34 +02:00
|
|
|
|
|
|
|
extern const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX];
|
|
|
|
|
2017-12-20 10:17:37 +01:00
|
|
|
#define NETDEV_VTABLE(n) ((n)->kind != _NETDEV_KIND_INVALID ? netdev_vtable[(n)->kind] : NULL)
|
2014-07-06 14:07:34 +02:00
|
|
|
|
2014-07-16 13:17:10 +02:00
|
|
|
/* For casting a netdev into the various netdev kinds */
|
2016-04-29 04:52:04 +02:00
|
|
|
#define DEFINE_NETDEV_CAST(UPPERCASE, MixedCase) \
|
2014-07-16 13:17:10 +02:00
|
|
|
static inline MixedCase* UPPERCASE(NetDev *n) { \
|
2018-01-04 11:36:58 +01:00
|
|
|
if (_unlikely_(!n || \
|
|
|
|
n->kind != NETDEV_KIND_##UPPERCASE) || \
|
|
|
|
n->state == _NETDEV_STATE_INVALID) \
|
2014-07-16 13:17:10 +02:00
|
|
|
return NULL; \
|
|
|
|
\
|
|
|
|
return (MixedCase*) n; \
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For casting the various netdev kinds into a netdev */
|
|
|
|
#define NETDEV(n) (&(n)->meta)
|
|
|
|
|
2014-07-06 14:07:34 +02:00
|
|
|
int netdev_load(Manager *manager);
|
2018-11-04 22:06:03 +01:00
|
|
|
int netdev_load_one(Manager *manager, const char *filename);
|
2014-07-06 14:07:34 +02:00
|
|
|
void netdev_drop(NetDev *netdev);
|
|
|
|
|
|
|
|
NetDev *netdev_unref(NetDev *netdev);
|
|
|
|
NetDev *netdev_ref(NetDev *netdev);
|
2018-11-28 21:06:52 +01:00
|
|
|
DEFINE_TRIVIAL_DESTRUCTOR(netdev_destroy_callback, NetDev, netdev_unref);
|
2014-07-06 14:07:34 +02:00
|
|
|
DEFINE_TRIVIAL_CLEANUP_FUNC(NetDev*, netdev_unref);
|
|
|
|
|
|
|
|
int netdev_get(Manager *manager, const char *name, NetDev **ret);
|
2015-06-12 16:31:33 +02:00
|
|
|
int netdev_set_ifindex(NetDev *netdev, sd_netlink_message *newlink);
|
2014-07-06 14:07:34 +02:00
|
|
|
int netdev_get_mac(const char *ifname, struct ether_addr **ret);
|
2018-11-28 21:06:52 +01:00
|
|
|
int netdev_join(NetDev *netdev, Link *link, link_netlink_message_handler_t cb);
|
2014-07-06 14:07:34 +02:00
|
|
|
|
|
|
|
const char *netdev_kind_to_string(NetDevKind d) _const_;
|
|
|
|
NetDevKind netdev_kind_from_string(const char *d) _pure_;
|
|
|
|
|
2018-11-12 08:45:04 +01:00
|
|
|
CONFIG_PARSER_PROTOTYPE(config_parse_netdev_kind);
|
2014-07-06 14:07:34 +02:00
|
|
|
|
|
|
|
/* gperf */
|
2017-01-10 08:39:05 +01:00
|
|
|
const struct ConfigPerfItem* network_netdev_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
|
2014-07-06 14:07:34 +02:00
|
|
|
|
|
|
|
/* Macros which append INTERFACE= to the message */
|
|
|
|
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
#define log_netdev_full(netdev, level, error, ...) \
|
|
|
|
({ \
|
2016-08-23 11:29:30 +02:00
|
|
|
const NetDev *_n = (netdev); \
|
2016-08-30 23:18:46 +02:00
|
|
|
_n ? log_object_internal(level, error, __FILE__, __LINE__, __func__, "INTERFACE=", _n->ifname, NULL, NULL, ##__VA_ARGS__) : \
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
log_internal(level, error, __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
|
|
|
|
})
|
2015-04-21 17:40:18 +02:00
|
|
|
|
|
|
|
#define log_netdev_debug(netdev, ...) log_netdev_full(netdev, LOG_DEBUG, 0, ##__VA_ARGS__)
|
|
|
|
#define log_netdev_info(netdev, ...) log_netdev_full(netdev, LOG_INFO, 0, ##__VA_ARGS__)
|
|
|
|
#define log_netdev_notice(netdev, ...) log_netdev_full(netdev, LOG_NOTICE, 0, ##__VA_ARGS__)
|
|
|
|
#define log_netdev_warning(netdev, ...) log_netdev_full(netdev, LOG_WARNING, 0, ## __VA_ARGS__)
|
|
|
|
#define log_netdev_error(netdev, ...) log_netdev_full(netdev, LOG_ERR, 0, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#define log_netdev_debug_errno(netdev, error, ...) log_netdev_full(netdev, LOG_DEBUG, error, ##__VA_ARGS__)
|
|
|
|
#define log_netdev_info_errno(netdev, error, ...) log_netdev_full(netdev, LOG_INFO, error, ##__VA_ARGS__)
|
|
|
|
#define log_netdev_notice_errno(netdev, error, ...) log_netdev_full(netdev, LOG_NOTICE, error, ##__VA_ARGS__)
|
|
|
|
#define log_netdev_warning_errno(netdev, error, ...) log_netdev_full(netdev, LOG_WARNING, error, ##__VA_ARGS__)
|
|
|
|
#define log_netdev_error_errno(netdev, error, ...) log_netdev_full(netdev, LOG_ERR, error, ##__VA_ARGS__)
|
2015-04-21 01:26:59 +02:00
|
|
|
|
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
2015-05-11 20:38:21 +02:00
|
|
|
#define LOG_NETDEV_MESSAGE(netdev, fmt, ...) "MESSAGE=%s: " fmt, (netdev)->ifname, ##__VA_ARGS__
|
|
|
|
#define LOG_NETDEV_INTERFACE(netdev) "INTERFACE=%s", (netdev)->ifname
|