1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2013 Tom Gundersen <teg@jklm.no>
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 #include "networkd-netdev-macvlan.h"
25 #include "network-internal.h"
26 #include "conf-parser.h"
29 static const char* const macvlan_mode_table[_NETDEV_MACVLAN_MODE_MAX] = {
30 [NETDEV_MACVLAN_MODE_PRIVATE] = "private",
31 [NETDEV_MACVLAN_MODE_VEPA] = "vepa",
32 [NETDEV_MACVLAN_MODE_BRIDGE] = "bridge",
33 [NETDEV_MACVLAN_MODE_PASSTHRU] = "passthru",
36 DEFINE_STRING_TABLE_LOOKUP(macvlan_mode, MacVlanMode);
37 DEFINE_CONFIG_PARSE_ENUM(config_parse_macvlan_mode, macvlan_mode, MacVlanMode, "Failed to parse macvlan mode");
39 static int netdev_macvlan_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_message *req) {
43 assert(netdev->kind == NETDEV_KIND_MACVLAN);
45 assert(netdev->ifname);
47 r = sd_rtnl_message_append_u32(req, IFLA_LINK, link->ifindex);
49 log_error_netdev(netdev,
50 "Could not append IFLA_LINK attribute: %s",
55 r = sd_rtnl_message_append_string(req, IFLA_IFNAME, netdev->ifname);
57 log_error_netdev(netdev,
58 "Could not append IFLA_IFNAME attribute: %s",
64 r = sd_rtnl_message_append_u32(req, IFLA_MTU, netdev->mtu);
66 log_error_netdev(netdev,
67 "Could not append IFLA_MTU attribute: %s",
74 r = sd_rtnl_message_append_ether_addr(req, IFLA_ADDRESS, netdev->mac);
76 log_error_netdev(netdev,
77 "Colud not append IFLA_ADDRESS attribute: %s",
83 r = sd_rtnl_message_open_container(req, IFLA_LINKINFO);
85 log_error_netdev(netdev,
86 "Could not open IFLA_LINKINFO container: %s",
91 r = sd_rtnl_message_open_container_union(req, IFLA_INFO_DATA, "macvlan");
93 log_error_netdev(netdev,
94 "Could not open IFLA_INFO_DATA container: %s",
99 if (netdev->macvlan_mode != _NETDEV_MACVLAN_MODE_INVALID) {
100 r = sd_rtnl_message_append_u32(req, IFLA_MACVLAN_MODE, netdev->macvlan_mode);
102 log_error_netdev(netdev,
103 "Could not append IFLA_MACVLAN_MODE attribute: %s",
109 r = sd_rtnl_message_close_container(req);
111 log_error_netdev(netdev,
112 "Could not close IFLA_INFO_DATA container %s",
117 r = sd_rtnl_message_close_container(req);
119 log_error_netdev(netdev,
120 "Could not close IFLA_LINKINFO container %s",
128 const NetDevVTable macvlan_vtable = {
129 .fill_message_create_on_link = netdev_macvlan_fill_message_create,