networkd: netdev - add ipvlan support
This commit is contained in:
@@ -29,6 +29,7 @@ NetDev.MTUBytes, config_parse_iec_size, 0,
|
||||
NetDev.MACAddress, config_parse_hwaddr, 0, offsetof(NetDev, mac)
|
||||
VLAN.Id, config_parse_uint64, 0, offsetof(VLan, id)
|
||||
MACVLAN.Mode, config_parse_macvlan_mode, 0, offsetof(MacVlan, mode)
|
||||
IPVLAN.Mode, config_parse_ipvlan_mode, 0, offsetof(IPVlan, mode)
|
||||
Tunnel.Local, config_parse_tunnel_address, 0, offsetof(Tunnel, local)
|
||||
Tunnel.Remote, config_parse_tunnel_address, 0, offsetof(Tunnel, remote)
|
||||
Tunnel.TOS, config_parse_unsigned, 0, offsetof(Tunnel, tos)
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2013-2015 Tom Gundersen <teg@jklm.no>
|
||||
|
||||
systemd is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
systemd 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#include <net/if.h>
|
||||
#include <linux/if_link.h>
|
||||
|
||||
#include "networkd-netdev-ipvlan.h"
|
||||
#include "network-internal.h"
|
||||
#include "conf-parser.h"
|
||||
#include "list.h"
|
||||
|
||||
static const char* const ipvlan_mode_table[_NETDEV_IPVLAN_MODE_MAX] = {
|
||||
[NETDEV_IPVLAN_MODE_L2] = "L2",
|
||||
[NETDEV_IPVLAN_MODE_L3] = "L3",
|
||||
};
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(ipvlan_mode, IPVlanMode);
|
||||
DEFINE_CONFIG_PARSE_ENUM(config_parse_ipvlan_mode, ipvlan_mode, IPVlanMode, "Failed to parse ipvlan mode");
|
||||
|
||||
static int netdev_ipvlan_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_message *req) {
|
||||
IPVlan *m = IPVLAN(netdev);
|
||||
int r;
|
||||
|
||||
assert(netdev);
|
||||
assert(m);
|
||||
assert(link);
|
||||
assert(netdev->ifname);
|
||||
|
||||
if (m->mode != _NETDEV_IPVLAN_MODE_INVALID) {
|
||||
r = sd_rtnl_message_append_u16(req, IFLA_IPVLAN_MODE, m->mode);
|
||||
if (r < 0) {
|
||||
log_netdev_error(netdev,
|
||||
"Could not append IFLA_IPVLAN_MODE attribute: %s",
|
||||
strerror(-r));
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ipvlan_init(NetDev *n) {
|
||||
IPVlan *m = IPVLAN(n);
|
||||
|
||||
assert(n);
|
||||
assert(m);
|
||||
|
||||
m->mode = _NETDEV_IPVLAN_MODE_INVALID;
|
||||
}
|
||||
|
||||
const NetDevVTable ipvlan_vtable = {
|
||||
.object_size = sizeof(IPVlan),
|
||||
.init = ipvlan_init,
|
||||
.sections = "Match\0NetDev\0IPVLAN\0",
|
||||
.fill_message_create = netdev_ipvlan_fill_message_create,
|
||||
.create_type = NETDEV_CREATE_STACKED,
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||
|
||||
/***
|
||||
This file is part of systemd.
|
||||
|
||||
Copyright 2014-2015 Tom Gundersen <teg@jklm.no>
|
||||
|
||||
systemd is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
systemd 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef struct IPVlan IPVlan;
|
||||
|
||||
#include "missing.h"
|
||||
#include "networkd-netdev.h"
|
||||
|
||||
typedef enum IPVlanMode {
|
||||
NETDEV_IPVLAN_MODE_L2 = IPVLAN_MODE_L2,
|
||||
NETDEV_IPVLAN_MODE_L3 = IPVLAN_MODE_L3,
|
||||
_NETDEV_IPVLAN_MODE_MAX,
|
||||
_NETDEV_IPVLAN_MODE_INVALID = -1
|
||||
} IPVlanMode;
|
||||
|
||||
struct IPVlan {
|
||||
NetDev meta;
|
||||
|
||||
IPVlanMode mode;
|
||||
};
|
||||
|
||||
extern const NetDevVTable ipvlan_vtable;
|
||||
|
||||
const char *ipvlan_mode_to_string(IPVlanMode d) _const_;
|
||||
IPVlanMode ipvlan_mode_from_string(const char *d) _pure_;
|
||||
|
||||
int config_parse_ipvlan_mode(const char *unit, const char *filename, unsigned line, const char *section, unsigned section_line, const char *lvalue, int ltype, const char *rvalue, void *data, void *userdata);
|
||||
@@ -35,6 +35,7 @@ const NetDevVTable * const netdev_vtable[_NETDEV_KIND_MAX] = {
|
||||
[NETDEV_KIND_BOND] = &bond_vtable,
|
||||
[NETDEV_KIND_VLAN] = &vlan_vtable,
|
||||
[NETDEV_KIND_MACVLAN] = &macvlan_vtable,
|
||||
[NETDEV_KIND_IPVLAN] = &ipvlan_vtable,
|
||||
[NETDEV_KIND_VXLAN] = &vxlan_vtable,
|
||||
[NETDEV_KIND_IPIP] = &ipip_vtable,
|
||||
[NETDEV_KIND_GRE] = &gre_vtable,
|
||||
@@ -51,6 +52,7 @@ static const char* const netdev_kind_table[_NETDEV_KIND_MAX] = {
|
||||
[NETDEV_KIND_BOND] = "bond",
|
||||
[NETDEV_KIND_VLAN] = "vlan",
|
||||
[NETDEV_KIND_MACVLAN] = "macvlan",
|
||||
[NETDEV_KIND_IPVLAN] = "ipvlan",
|
||||
[NETDEV_KIND_VXLAN] = "vxlan",
|
||||
[NETDEV_KIND_IPIP] = "ipip",
|
||||
[NETDEV_KIND_GRE] = "gre",
|
||||
|
||||
@@ -43,6 +43,7 @@ typedef enum NetDevKind {
|
||||
NETDEV_KIND_BOND,
|
||||
NETDEV_KIND_VLAN,
|
||||
NETDEV_KIND_MACVLAN,
|
||||
NETDEV_KIND_IPVLAN,
|
||||
NETDEV_KIND_VXLAN,
|
||||
NETDEV_KIND_IPIP,
|
||||
NETDEV_KIND_GRE,
|
||||
@@ -100,6 +101,7 @@ struct NetDev {
|
||||
#include "networkd-netdev-bond.h"
|
||||
#include "networkd-netdev-vlan.h"
|
||||
#include "networkd-netdev-macvlan.h"
|
||||
#include "networkd-netdev-ipvlan.h"
|
||||
#include "networkd-netdev-vxlan.h"
|
||||
#include "networkd-netdev-veth.h"
|
||||
#include "networkd-netdev-tunnel.h"
|
||||
@@ -157,6 +159,7 @@ DEFINE_CAST(BRIDGE, Bridge);
|
||||
DEFINE_CAST(BOND, Bond);
|
||||
DEFINE_CAST(VLAN, VLan);
|
||||
DEFINE_CAST(MACVLAN, MacVlan);
|
||||
DEFINE_CAST(IPVLAN, IPVlan);
|
||||
DEFINE_CAST(VXLAN, VxLan);
|
||||
DEFINE_CAST(IPIP, Tunnel);
|
||||
DEFINE_CAST(GRE, Tunnel);
|
||||
|
||||
@@ -31,6 +31,7 @@ Network.Bridge, config_parse_netdev, 0,
|
||||
Network.Bond, config_parse_netdev, 0, offsetof(Network, bond)
|
||||
Network.VLAN, config_parse_netdev, 0, 0
|
||||
Network.MACVLAN, config_parse_netdev, 0, 0
|
||||
Network.IPVLAN, config_parse_netdev, 0, 0
|
||||
Network.VXLAN, config_parse_netdev, 0, 0
|
||||
Network.Tunnel, config_parse_tunnel, 0, 0
|
||||
Network.DHCP, config_parse_dhcp, 0, offsetof(Network, dhcp)
|
||||
|
||||
@@ -362,6 +362,7 @@ int config_parse_netdev(const char *unit,
|
||||
break;
|
||||
case NETDEV_KIND_VLAN:
|
||||
case NETDEV_KIND_MACVLAN:
|
||||
case NETDEV_KIND_IPVLAN:
|
||||
case NETDEV_KIND_VXLAN:
|
||||
r = hashmap_put(network->stacked_netdevs, netdev->ifname, netdev);
|
||||
if (r < 0) {
|
||||
|
||||
@@ -21,6 +21,7 @@ int main(int argc, char **argv) {
|
||||
test_table(nl_union_link_info_data, NL_UNION_LINK_INFO_DATA);
|
||||
|
||||
test_table_sparse(macvlan_mode, NETDEV_MACVLAN_MODE);
|
||||
test_table_sparse(ipvlan_mode, NETDEV_IPVLAN_MODE);
|
||||
test_table_sparse(dhcp6_message_type, DHCP6_MESSAGE);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
Reference in New Issue
Block a user