]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-netdev-macvlan.c
networkd: ndisc - consider configured on timeout
[thirdparty/systemd.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 "conf-parser.h"
25 #include "networkd-netdev-macvlan.h"
26 #include "string-table.h"
27
28 static const char* const macvlan_mode_table[_NETDEV_MACVLAN_MODE_MAX] = {
29 [NETDEV_MACVLAN_MODE_PRIVATE] = "private",
30 [NETDEV_MACVLAN_MODE_VEPA] = "vepa",
31 [NETDEV_MACVLAN_MODE_BRIDGE] = "bridge",
32 [NETDEV_MACVLAN_MODE_PASSTHRU] = "passthru",
33 };
34
35 DEFINE_STRING_TABLE_LOOKUP(macvlan_mode, MacVlanMode);
36 DEFINE_CONFIG_PARSE_ENUM(config_parse_macvlan_mode, macvlan_mode, MacVlanMode, "Failed to parse macvlan mode");
37
38 static int netdev_macvlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) {
39 MacVlan *m;
40 int r;
41
42 assert(netdev);
43 assert(link);
44 assert(netdev->ifname);
45
46 if (netdev->kind == NETDEV_KIND_MACVLAN)
47 m = MACVLAN(netdev);
48 else
49 m = MACVTAP(netdev);
50
51 assert(m);
52
53 if (m->mode != _NETDEV_MACVLAN_MODE_INVALID) {
54 r = sd_netlink_message_append_u32(req, IFLA_MACVLAN_MODE, m->mode);
55 if (r < 0)
56 return log_netdev_error_errno(netdev, r, "Could not append IFLA_MACVLAN_MODE attribute: %m");
57 }
58
59 return 0;
60 }
61
62 static void macvlan_init(NetDev *n) {
63 MacVlan *m;
64
65 assert(n);
66
67 if (n->kind == NETDEV_KIND_MACVLAN)
68 m = MACVLAN(n);
69 else
70 m = MACVTAP(n);
71
72 assert(m);
73
74 m->mode = _NETDEV_MACVLAN_MODE_INVALID;
75 }
76
77 const NetDevVTable macvtap_vtable = {
78 .object_size = sizeof(MacVlan),
79 .init = macvlan_init,
80 .sections = "Match\0NetDev\0MACVTAP\0",
81 .fill_message_create = netdev_macvlan_fill_message_create,
82 .create_type = NETDEV_CREATE_STACKED,
83 };
84
85 const NetDevVTable macvlan_vtable = {
86 .object_size = sizeof(MacVlan),
87 .init = macvlan_init,
88 .sections = "Match\0NetDev\0MACVLAN\0",
89 .fill_message_create = netdev_macvlan_fill_message_create,
90 .create_type = NETDEV_CREATE_STACKED,
91 };