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/>.
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 int netdev_create_macvlan(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callback) {
40 _cleanup_rtnl_message_unref_ sd_rtnl_message *req = NULL;
45 assert(netdev->kind == NETDEV_KIND_MACVLAN);
48 assert(netdev->ifname);
49 assert(netdev->manager);
50 assert(netdev->manager->rtnl);
52 r = sd_rtnl_message_new_link(netdev->manager->rtnl, &req, RTM_NEWLINK, 0);
54 log_error_netdev(netdev,
55 "Could not allocate RTM_NEWLINK message: %s",
61 r = sd_rtnl_message_append_u32(req, IFLA_LINK, link->ifindex);
63 log_error_netdev(netdev,
64 "Could not append IFLA_LINK attribute: %s",
70 r = sd_rtnl_message_append_string(req, IFLA_IFNAME, netdev->ifname);
72 log_error_netdev(netdev,
73 "Could not append IFLA_IFNAME attribute: %s",
79 r = sd_rtnl_message_append_u32(req, IFLA_MTU, netdev->mtu);
81 log_error_netdev(netdev,
82 "Could not append IFLA_MTU attribute: %s",
89 r = sd_rtnl_message_append_ether_addr(req, IFLA_ADDRESS, netdev->mac);
91 log_error_netdev(netdev,
92 "Colud not append IFLA_ADDRESS attribute: %s",
98 r = sd_rtnl_message_open_container(req, IFLA_LINKINFO);
100 log_error_netdev(netdev,
101 "Could not open IFLA_LINKINFO container: %s",
106 kind = netdev_kind_to_string(netdev->kind);
108 log_error_netdev(netdev, "Invalid kind");
112 r = sd_rtnl_message_open_container_union(req, IFLA_INFO_DATA, kind);
114 log_error_netdev(netdev,
115 "Could not open IFLA_INFO_DATA container: %s",
120 if (netdev->macvlan_mode != _NETDEV_MACVLAN_MODE_INVALID) {
121 r = sd_rtnl_message_append_u32(req, IFLA_MACVLAN_MODE, netdev->macvlan_mode);
123 log_error_netdev(netdev,
124 "Could not append IFLA_MACVLAN_MODE attribute: %s",
130 r = sd_rtnl_message_close_container(req);
132 log_error_netdev(netdev,
133 "Could not close IFLA_INFO_DATA container %s",
138 r = sd_rtnl_message_close_container(req);
140 log_error_netdev(netdev,
141 "Could not close IFLA_LINKINFO container %s",
146 r = sd_rtnl_call_async(netdev->manager->rtnl, req, callback, link, 0, NULL);
148 log_error_netdev(netdev,
149 "Could not send rtnetlink message: %s", strerror(-r));
155 log_debug_netdev(netdev, "creating netdev");
157 netdev->state = NETDEV_STATE_CREATING;