]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-netdev-veth.c
treewide: no need to negate errno for log_*_errno()
[thirdparty/systemd.git] / src / network / networkd-netdev-veth.c
CommitLineData
10142d75
SS
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2014 Susant Sahani <susant@redhat.com>
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 <netinet/ether.h>
23#include <arpa/inet.h>
24#include <net/if.h>
25#include <linux/veth.h>
26
27#include "sd-rtnl.h"
3be1d7e0 28#include "networkd-netdev-veth.h"
10142d75 29
aa9f1140
TG
30static int netdev_veth_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_message *m) {
31 Veth *v = VETH(netdev);
10142d75
SS
32 int r;
33
34 assert(netdev);
aa9f1140
TG
35 assert(!link);
36 assert(v);
10142d75
SS
37 assert(m);
38
10142d75
SS
39 r = sd_rtnl_message_open_container(m, VETH_INFO_PEER);
40 if (r < 0) {
79008bdd 41 log_netdev_error(netdev,
ed7fb9cb 42 "Could not append VETH_INFO_PEER attribute: %s",
10142d75
SS
43 strerror(-r));
44 return r;
45 }
46
aa9f1140
TG
47 if (v->ifname_peer) {
48 r = sd_rtnl_message_append_string(m, IFLA_IFNAME, v->ifname_peer);
10142d75 49 if (r < 0) {
da927ba9 50 log_error_errno(r, "Failed to add netlink interface name: %m");
10142d75
SS
51 return r;
52 }
53 }
54
aa9f1140
TG
55 if (v->mac_peer) {
56 r = sd_rtnl_message_append_ether_addr(m, IFLA_ADDRESS, v->mac_peer);
96c90742 57 if (r < 0) {
79008bdd 58 log_netdev_error(netdev,
6eb33ab2 59 "Could not append IFLA_ADDRESS attribute: %s",
96c90742
TG
60 strerror(-r));
61 return r;
62 }
63 }
64
10142d75
SS
65 r = sd_rtnl_message_close_container(m);
66 if (r < 0) {
79008bdd 67 log_netdev_error(netdev,
10142d75
SS
68 "Could not append IFLA_INFO_DATA attribute: %s",
69 strerror(-r));
70 return r;
71 }
72
10142d75
SS
73 return r;
74}
75
3be1d7e0 76static int netdev_veth_verify(NetDev *netdev, const char *filename) {
aa9f1140 77 Veth *v = VETH(netdev);
10142d75
SS
78 int r;
79
80 assert(netdev);
aa9f1140 81 assert(v);
3be1d7e0 82 assert(filename);
10142d75 83
aa9f1140 84 if (!v->ifname_peer) {
3be1d7e0
TG
85 log_warning("Veth NetDev without peer name configured in %s. Ignoring",
86 filename);
87 return -EINVAL;
10142d75
SS
88 }
89
aa9f1140
TG
90 if (!v->mac_peer) {
91 r = netdev_get_mac(v->ifname_peer, &v->mac_peer);
3be1d7e0
TG
92 if (r < 0) {
93 log_warning("Failed to generate predictable MAC address for %s. Ignoring",
aa9f1140 94 v->ifname_peer);
3be1d7e0
TG
95 return -EINVAL;
96 }
10142d75
SS
97 }
98
10142d75
SS
99 return 0;
100}
3be1d7e0 101
aa9f1140
TG
102static void veth_done(NetDev *n) {
103 Veth *v = VETH(n);
104
105 assert(n);
106 assert(v);
107
108 free(v->ifname_peer);
109 free(v->mac_peer);
110}
111
3be1d7e0 112const NetDevVTable veth_vtable = {
aa9f1140
TG
113 .object_size = sizeof(Veth),
114 .sections = "Match\0NetDev\0Peer\0",
115 .done = veth_done,
3be1d7e0 116 .fill_message_create = netdev_veth_fill_message_create,
aa9f1140 117 .create_type = NETDEV_CREATE_INDEPENDENT,
3be1d7e0
TG
118 .config_verify = netdev_veth_verify,
119};