chiark / gitweb /
journal-remote: rework fd and writer reference handling
[elogind.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 "missing.h"
29
30 static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_message *m) {
31         int r;
32
33         assert(netdev);
34         assert(link);
35         assert(link->ifname);
36         assert(m);
37
38         r = sd_rtnl_message_append_string(m, IFLA_IFNAME, netdev->ifname);
39         if (r < 0) {
40                 log_error_netdev(netdev,
41                                  "Could not append IFLA_IFNAME, attribute: %s",
42                                  strerror(-r));
43                 return r;
44         }
45
46         r = sd_rtnl_message_open_container(m, IFLA_LINKINFO);
47         if (r < 0) {
48                 log_error_netdev(netdev,
49                                  "Could not append IFLA_LINKINFO attribute: %s",
50                                  strerror(-r));
51                 return r;
52         }
53
54         r = sd_rtnl_message_open_container_union(m, IFLA_INFO_DATA, "vxlan");
55         if (r < 0) {
56                 log_error_netdev(netdev,
57                                  "Could not append IFLA_INFO_DATA attribute: %s",
58                                  strerror(-r));
59                 return r;
60         }
61
62         if (netdev->vlanid <= VXLAN_VID_MAX) {
63                 r = sd_rtnl_message_append_u32(m, IFLA_VXLAN_ID, netdev->vxlanid);
64                 if (r < 0) {
65                         log_error_netdev(netdev,
66                                          "Could not append IFLA_VXLAN_ID attribute: %s",
67                                          strerror(-r));
68                         return r;
69                 }
70         }
71
72         r = sd_rtnl_message_append_in_addr(m, IFLA_VXLAN_GROUP, &netdev->group.in);
73         if (r < 0) {
74                 log_error_netdev(netdev,
75                                  "Could not append IFLA_VXLAN_GROUP attribute: %s",
76                                  strerror(-r));
77                 return r;
78         }
79
80         r = sd_rtnl_message_append_u32(m, IFLA_VXLAN_LINK, link->ifindex);
81         if (r < 0) {
82                 log_error_netdev(netdev,
83                                  "Could not append IFLA_VXLAN_LINK attribute: %s",
84                                  strerror(-r));
85                 return r;
86         }
87
88         if(netdev->ttl) {
89                 r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_TTL, netdev->ttl);
90                 if (r < 0) {
91                         log_error_netdev(netdev,
92                                          "Could not append IFLA_VXLAN_TTL attribute: %s",
93                                          strerror(-r));
94                         return r;
95                 }
96         }
97
98         if(netdev->tos) {
99                 r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_TOS, netdev->tos);
100                 if (r < 0) {
101                         log_error_netdev(netdev,
102                                          "Could not append IFLA_VXLAN_TOS attribute: %s",
103                                          strerror(-r));
104                         return r;
105                 }
106         }
107
108         r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_LEARNING, netdev->learning);
109         if (r < 0) {
110                 log_error_netdev(netdev,
111                                  "Could not append IFLA_VXLAN_LEARNING attribute: %s",
112                                  strerror(-r));
113                 return r;
114         }
115
116         r = sd_rtnl_message_close_container(m);
117         if (r < 0) {
118                 log_error_netdev(netdev,
119                                  "Could not append IFLA_LINKINFO attribute: %s",
120                                  strerror(-r));
121                 return r;
122         }
123
124         return r;
125 }
126
127 static int netdev_vxlan_verify(NetDev *netdev, const char *filename) {
128         assert(netdev);
129         assert(filename);
130
131         if (netdev->vxlanid > VXLAN_VID_MAX) {
132                 log_warning("VXLAN without valid Id configured in %s. Ignoring", filename);
133                 return -EINVAL;
134         }
135
136         return 0;
137 }
138
139 const NetDevVTable vxlan_vtable = {
140         .fill_message_create_on_link = netdev_vxlan_fill_message_create,
141         .config_verify = netdev_vxlan_verify,
142 };