]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/netdev/macvlan.c
Merge pull request #4395 from s-urbaniak/rw-support
[thirdparty/systemd.git] / src / network / netdev / macvlan.c
1 /***
2 This file is part of systemd.
3
4 Copyright 2013 Tom Gundersen <teg@jklm.no>
5
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
18 ***/
19
20 #include <net/if.h>
21
22 #include "conf-parser.h"
23 #include "netdev/macvlan.h"
24 #include "string-table.h"
25
26 static const char* const macvlan_mode_table[_NETDEV_MACVLAN_MODE_MAX] = {
27 [NETDEV_MACVLAN_MODE_PRIVATE] = "private",
28 [NETDEV_MACVLAN_MODE_VEPA] = "vepa",
29 [NETDEV_MACVLAN_MODE_BRIDGE] = "bridge",
30 [NETDEV_MACVLAN_MODE_PASSTHRU] = "passthru",
31 };
32
33 DEFINE_STRING_TABLE_LOOKUP(macvlan_mode, MacVlanMode);
34 DEFINE_CONFIG_PARSE_ENUM(config_parse_macvlan_mode, macvlan_mode, MacVlanMode, "Failed to parse macvlan mode");
35
36 static int netdev_macvlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) {
37 MacVlan *m;
38 int r;
39
40 assert(netdev);
41 assert(link);
42 assert(netdev->ifname);
43
44 if (netdev->kind == NETDEV_KIND_MACVLAN)
45 m = MACVLAN(netdev);
46 else
47 m = MACVTAP(netdev);
48
49 assert(m);
50
51 if (m->mode != _NETDEV_MACVLAN_MODE_INVALID) {
52 r = sd_netlink_message_append_u32(req, IFLA_MACVLAN_MODE, m->mode);
53 if (r < 0)
54 return log_netdev_error_errno(netdev, r, "Could not append IFLA_MACVLAN_MODE attribute: %m");
55 }
56
57 return 0;
58 }
59
60 static void macvlan_init(NetDev *n) {
61 MacVlan *m;
62
63 assert(n);
64
65 if (n->kind == NETDEV_KIND_MACVLAN)
66 m = MACVLAN(n);
67 else
68 m = MACVTAP(n);
69
70 assert(m);
71
72 m->mode = _NETDEV_MACVLAN_MODE_INVALID;
73 }
74
75 const NetDevVTable macvtap_vtable = {
76 .object_size = sizeof(MacVlan),
77 .init = macvlan_init,
78 .sections = "Match\0NetDev\0MACVTAP\0",
79 .fill_message_create = netdev_macvlan_fill_message_create,
80 .create_type = NETDEV_CREATE_STACKED,
81 };
82
83 const NetDevVTable macvlan_vtable = {
84 .object_size = sizeof(MacVlan),
85 .init = macvlan_init,
86 .sections = "Match\0NetDev\0MACVLAN\0",
87 .fill_message_create = netdev_macvlan_fill_message_create,
88 .create_type = NETDEV_CREATE_STACKED,
89 };