1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2014 Susant Sahani <susant@redhat.com>
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.
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.
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/>.
22 #include <netinet/ether.h>
23 #include <arpa/inet.h>
25 #include <linux/veth.h>
31 static int netdev_fill_veth_rtnl_message(NetDev *netdev, sd_rtnl_message *m) {
37 r = sd_rtnl_message_append_string(m, IFLA_IFNAME, netdev->ifname);
39 log_error_netdev(netdev,
40 "Could not append IFLA_IFNAME, attribute: %s",
45 r = sd_rtnl_message_open_container(m, IFLA_LINKINFO);
47 log_error_netdev(netdev,
48 "Could not append IFLA_LINKINFO attribute: %s",
53 r = sd_rtnl_message_open_container_union(m, IFLA_INFO_DATA,
54 netdev_kind_to_string(netdev->kind));
56 log_error_netdev(netdev,
57 "Could not append IFLA_INFO_DATA attribute: %s",
62 r = sd_rtnl_message_open_container(m, VETH_INFO_PEER);
64 log_error_netdev(netdev,
65 "Could not append IFLA_IPTUN_LINK attribute: %s",
70 if(netdev->ifname_peer) {
71 r = sd_rtnl_message_append_string(m, IFLA_IFNAME, netdev->ifname_peer);
73 log_error("Failed to add netlink interface name: %s", strerror(-r));
78 r = sd_rtnl_message_close_container(m);
80 log_error_netdev(netdev,
81 "Could not append IFLA_INFO_DATA attribute: %s",
86 r = sd_rtnl_message_close_container(m);
88 log_error_netdev(netdev,
89 "Could not append IFLA_LINKINFO attribute: %s",
97 int netdev_create_veth(NetDev *netdev, sd_rtnl_message_handler_t callback) {
98 _cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
102 assert(netdev->ifname);
103 assert(netdev->manager);
104 assert(netdev->manager->rtnl);
106 r = sd_rtnl_message_new_link(netdev->manager->rtnl, &m, RTM_NEWLINK, 0);
108 log_error_netdev(netdev,
109 "Could not allocate RTM_NEWLINK message: %s",
114 if(netdev->kind != NETDEV_KIND_VETH)
117 r = netdev_fill_veth_rtnl_message(netdev, m);
121 r = sd_rtnl_call_async(netdev->manager->rtnl, m, callback, netdev, 0, NULL);
123 log_error_netdev(netdev,
124 "Could not send rtnetlink message: %s", strerror(-r));
128 log_debug_netdev(netdev, "Creating veth netdev: %s",
129 netdev_kind_to_string(netdev->kind));
131 netdev->state = NETDEV_STATE_CREATING;