]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-netdev-vxlan.c
treewide: use log_*_errno whenever %m is in the format string
[thirdparty/systemd.git] / src / network / networkd-netdev-vxlan.c
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
26 #include "sd-rtnl.h"
27 #include "networkd-netdev-vxlan.h"
28 #include "networkd-link.h"
29 #include "missing.h"
30
31 static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_message *m) {
32 VxLan *v = VXLAN(netdev);
33 int r;
34
35 assert(netdev);
36 assert(v);
37 assert(link);
38 assert(m);
39
40
41 if (v->id <= VXLAN_VID_MAX) {
42 r = sd_rtnl_message_append_u32(m, IFLA_VXLAN_ID, v->id);
43 if (r < 0) {
44 log_netdev_error(netdev,
45 "Could not append IFLA_VXLAN_ID attribute: %s",
46 strerror(-r));
47 return r;
48 }
49 }
50
51 r = sd_rtnl_message_append_in_addr(m, IFLA_VXLAN_GROUP, &v->group.in);
52 if (r < 0) {
53 log_netdev_error(netdev,
54 "Could not append IFLA_VXLAN_GROUP attribute: %s",
55 strerror(-r));
56 return r;
57 }
58
59 r = sd_rtnl_message_append_u32(m, IFLA_VXLAN_LINK, link->ifindex);
60 if (r < 0) {
61 log_netdev_error(netdev,
62 "Could not append IFLA_VXLAN_LINK attribute: %s",
63 strerror(-r));
64 return r;
65 }
66
67 if(v->ttl) {
68 r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_TTL, v->ttl);
69 if (r < 0) {
70 log_netdev_error(netdev,
71 "Could not append IFLA_VXLAN_TTL attribute: %s",
72 strerror(-r));
73 return r;
74 }
75 }
76
77 if(v->tos) {
78 r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_TOS, v->tos);
79 if (r < 0) {
80 log_netdev_error(netdev,
81 "Could not append IFLA_VXLAN_TOS attribute: %s",
82 strerror(-r));
83 return r;
84 }
85 }
86
87 r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_LEARNING, v->learning);
88 if (r < 0) {
89 log_netdev_error(netdev,
90 "Could not append IFLA_VXLAN_LEARNING attribute: %s",
91 strerror(-r));
92 return r;
93 }
94
95 return r;
96 }
97
98 static int netdev_vxlan_verify(NetDev *netdev, const char *filename) {
99 VxLan *v = VXLAN(netdev);
100
101 assert(netdev);
102 assert(v);
103 assert(filename);
104
105 if (v->id > VXLAN_VID_MAX) {
106 log_warning("VXLAN without valid Id configured in %s. Ignoring", filename);
107 return -EINVAL;
108 }
109
110 return 0;
111 }
112
113 static void vxlan_init(NetDev *netdev) {
114 VxLan *v = VXLAN(netdev);
115
116 assert(netdev);
117 assert(v);
118
119 v->id = VXLAN_VID_MAX + 1;
120 v->learning = true;
121 }
122
123 const NetDevVTable vxlan_vtable = {
124 .object_size = sizeof(VxLan),
125 .init = vxlan_init,
126 .sections = "Match\0NetDev\0VXLAN\0",
127 .fill_message_create = netdev_vxlan_fill_message_create,
128 .create_type = NETDEV_CREATE_STACKED,
129 .config_verify = netdev_vxlan_verify,
130 };