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>
30 static int netdev_fill_vxlan_rtnl_message(NetDev *netdev, Link *link, sd_rtnl_message *m) {
34 assert(link->network);
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 if (netdev->vlanid <= VXLAN_VID_MAX) {
63 r = sd_rtnl_message_append_u32(m, IFLA_VXLAN_ID, netdev->vxlanid);
65 log_error_netdev(netdev,
66 "Could not append IFLA_VXLAN_ID attribute: %s",
72 r = sd_rtnl_message_append_in_addr(m, IFLA_VXLAN_GROUP, &netdev->group);
74 log_error_netdev(netdev,
75 "Could not append IFLA_VXLAN_GROUP attribute: %s",
80 r = sd_rtnl_message_append_u32(m, IFLA_VXLAN_LINK, link->ifindex);
82 log_error_netdev(netdev,
83 "Could not append IFLA_VXLAN_LINK attribute: %s",
89 r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_TTL, netdev->ttl);
91 log_error_netdev(netdev,
92 "Could not append IFLA_VXLAN_TTL attribute: %s",
99 r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_TOS, netdev->tos);
101 log_error_netdev(netdev,
102 "Could not append IFLA_VXLAN_TOS attribute: %s",
108 r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_LEARNING, netdev->learning);
110 log_error_netdev(netdev,
111 "Could not append IFLA_VXLAN_LEARNING attribute: %s",
116 r = sd_rtnl_message_close_container(m);
118 log_error_netdev(netdev,
119 "Could not append IFLA_LINKINFO attribute: %s",
127 int netdev_create_vxlan(NetDev *netdev, Link *link, sd_rtnl_message_handler_t callback) {
128 _cleanup_rtnl_message_unref_ sd_rtnl_message *m = NULL;
132 assert(!(netdev->kind == NETDEV_KIND_VXLAN) || (link && callback));
133 assert(netdev->ifname);
134 assert(netdev->manager);
135 assert(netdev->manager->rtnl);
137 r = sd_rtnl_message_new_link(netdev->manager->rtnl, &m, RTM_NEWLINK, 0);
139 log_error_netdev(netdev,
140 "Could not allocate RTM_NEWLINK message: %s",
145 r = netdev_fill_vxlan_rtnl_message(netdev, link, m);
149 r = sd_rtnl_call_async(netdev->manager->rtnl, m, callback, link, 0, NULL);
151 log_error_netdev(netdev,
152 "Could not send rtnetlink message: %s", strerror(-r));
156 log_debug_netdev(netdev, "Creating vxlan netdev: %s",
157 netdev_kind_to_string(netdev->kind));
159 netdev->state = NETDEV_STATE_CREATING;