chiark / gitweb /
2e5554a1728606d8fec4fdd7afc63016fa01d27e
[elogind.git] / src / network / networkd-netdev-macvlan.c
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 /***
4   This file is part of systemd.
5
6   Copyright 2013 Tom Gundersen <teg@jklm.no>
7
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.
12
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.
17
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/>.
20 ***/
21
22 #include <net/if.h>
23
24 #include "networkd-netdev-macvlan.h"
25 #include "network-internal.h"
26 #include "conf-parser.h"
27 #include "list.h"
28
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",
34 };
35
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");
38
39 static int netdev_macvlan_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_message *req) {
40         MacVlan *m = MACVLAN(netdev);
41         int r;
42
43         assert(netdev);
44         assert(m);
45         assert(link);
46         assert(netdev->ifname);
47
48         if (m->mode != _NETDEV_MACVLAN_MODE_INVALID) {
49         r = sd_rtnl_message_append_u32(req, IFLA_MACVLAN_MODE, m->mode);
50         if (r < 0) {
51                 log_error_netdev(netdev,
52                                  "Could not append IFLA_MACVLAN_MODE attribute: %s",
53                                  strerror(-r));
54                         return r;
55                 }
56         }
57
58         return 0;
59 }
60
61 static void macvlan_init(NetDev *n) {
62         MacVlan *m = MACVLAN(n);
63
64         assert(n);
65         assert(m);
66
67         m->mode = _NETDEV_MACVLAN_MODE_INVALID;
68 }
69
70 const NetDevVTable macvlan_vtable = {
71         .object_size = sizeof(MacVlan),
72         .init = macvlan_init,
73         .sections = "Match\0NetDev\0MACVLAN\0",
74         .fill_message_create = netdev_macvlan_fill_message_create,
75         .create_type = NETDEV_CREATE_STACKED,
76 };