]>
Commit | Line | Data |
---|---|---|
67d3fef1 MT |
1 | /*############################################################################# |
2 | # # | |
3 | # IPFire.org - A linux based firewall # | |
4 | # Copyright (C) 2023 IPFire Network Development Team # | |
5 | # # | |
6 | # This program is free software: you can redistribute it and/or modify # | |
7 | # it under the terms of the GNU General Public License as published by # | |
8 | # the Free Software Foundation, either version 3 of the License, or # | |
9 | # (at your option) any later version. # | |
10 | # # | |
11 | # This program is distributed in the hope that it will be useful, # | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
14 | # GNU General Public License for more details. # | |
15 | # # | |
16 | # You should have received a copy of the GNU General Public License # | |
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
18 | # # | |
19 | #############################################################################*/ | |
20 | ||
21 | #include <linux/veth.h> | |
22 | ||
23 | #include "json.h" | |
24 | #include "port.h" | |
25 | #include "port-veth.h" | |
26 | ||
27 | static int nw_port_veth_setup(nw_port* port) { | |
28 | int r; | |
29 | ||
30 | // Peer | |
e633147d | 31 | r = NW_CONFIG_OPTION_STRING_BUFFER(port->config, "VETH_PEER", port->veth.peer); |
67d3fef1 MT |
32 | if (r < 0) |
33 | return 1; | |
34 | ||
35 | return 0; | |
36 | } | |
37 | ||
38 | static int nw_port_veth_create_link(nw_port* port, sd_netlink_message* m) { | |
39 | int r; | |
40 | ||
41 | // Open the container | |
42 | r = sd_netlink_message_open_container(m, VETH_INFO_PEER); | |
43 | if (r < 0) | |
44 | return r; | |
45 | ||
46 | // Set VETH Peer | |
47 | r = sd_netlink_message_append_string(m, IFLA_VLAN_ID, port->veth.peer); | |
48 | if (r < 0) | |
49 | return r; | |
50 | ||
51 | // Close the container | |
52 | r = sd_netlink_message_close_container(m); | |
53 | if (r < 0) | |
54 | return r; | |
55 | ||
56 | return 0; | |
57 | } | |
58 | ||
59 | static int nw_port_veth_to_json(nw_port* port, struct json_object* o) { | |
60 | int r; | |
61 | ||
62 | // Add the VETH Peer | |
63 | r = json_object_add_string(o, "VETHPeer", port->veth.peer); | |
64 | if (r < 0) | |
65 | return r; | |
66 | ||
67 | return 0; | |
68 | } | |
69 | ||
70 | const nw_port_type_t nw_port_type_veth = { | |
71 | .kind = "veth", | |
72 | ||
73 | // Configuration | |
74 | .setup = nw_port_veth_setup, | |
75 | ||
76 | // Link | |
77 | .create_link = nw_port_veth_create_link, | |
78 | ||
79 | // JSON | |
80 | .to_json = nw_port_veth_to_json, | |
81 | }; |