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