]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-netdev-macvlan.c
networkd: add dbus interface for lease raw options (#3528)
[thirdparty/systemd.git] / src / network / networkd-netdev-macvlan.c
CommitLineData
0372cb2b
TG
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
0372cb2b 22#include "conf-parser.h"
8b43440b
LP
23#include "networkd-netdev-macvlan.h"
24#include "string-table.h"
0372cb2b
TG
25
26static 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
33DEFINE_STRING_TABLE_LOOKUP(macvlan_mode, MacVlanMode);
34DEFINE_CONFIG_PARSE_ENUM(config_parse_macvlan_mode, macvlan_mode, MacVlanMode, "Failed to parse macvlan mode");
35
1c4baffc 36static int netdev_macvlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) {
f33ff02b 37 MacVlan *m;
0372cb2b
TG
38 int r;
39
40 assert(netdev);
0372cb2b 41 assert(link);
0372cb2b 42 assert(netdev->ifname);
0372cb2b 43
f33ff02b
SS
44 if (netdev->kind == NETDEV_KIND_MACVLAN)
45 m = MACVLAN(netdev);
46 else
47 m = MACVTAP(netdev);
48
49 assert(m);
50
aa9f1140 51 if (m->mode != _NETDEV_MACVLAN_MODE_INVALID) {
1c4baffc 52 r = sd_netlink_message_append_u32(req, IFLA_MACVLAN_MODE, m->mode);
c8a09ef4
SS
53 if (r < 0)
54 return log_netdev_error_errno(netdev, r, "Could not append IFLA_MACVLAN_MODE attribute: %m");
0372cb2b
TG
55 }
56
aa9f1140
TG
57 return 0;
58}
0372cb2b 59
aa9f1140 60static void macvlan_init(NetDev *n) {
f33ff02b 61 MacVlan *m;
0372cb2b 62
aa9f1140 63 assert(n);
f33ff02b
SS
64
65 if (n->kind == NETDEV_KIND_MACVLAN)
66 m = MACVLAN(n);
67 else
68 m = MACVTAP(n);
69
aa9f1140
TG
70 assert(m);
71
72 m->mode = _NETDEV_MACVLAN_MODE_INVALID;
0372cb2b 73}
3be1d7e0 74
f33ff02b
SS
75const 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
3be1d7e0 83const NetDevVTable macvlan_vtable = {
aa9f1140
TG
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,
3be1d7e0 89};