]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/network/networkd-netdev-vxlan.c
networkd: split out networkd-link.h
[thirdparty/systemd.git] / src / network / networkd-netdev-vxlan.c
CommitLineData
326cb406
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
26#include "sd-rtnl.h"
3be1d7e0 27#include "networkd-netdev-vxlan.h"
0b1831c2 28#include "networkd-link.h"
81577dc2 29#include "missing.h"
326cb406 30
3be1d7e0 31static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_rtnl_message *m) {
aa9f1140 32 VxLan *v = VXLAN(netdev);
326cb406
SS
33 int r;
34
3be1d7e0 35 assert(netdev);
aa9f1140 36 assert(v);
326cb406 37 assert(link);
326cb406
SS
38 assert(m);
39
326cb406 40
aa9f1140
TG
41 if (v->id <= VXLAN_VID_MAX) {
42 r = sd_rtnl_message_append_u32(m, IFLA_VXLAN_ID, v->id);
326cb406
SS
43 if (r < 0) {
44 log_error_netdev(netdev,
45 "Could not append IFLA_VXLAN_ID attribute: %s",
46 strerror(-r));
47 return r;
48 }
49 }
50
aa9f1140 51 r = sd_rtnl_message_append_in_addr(m, IFLA_VXLAN_GROUP, &v->group.in);
326cb406
SS
52 if (r < 0) {
53 log_error_netdev(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_error_netdev(netdev,
62 "Could not append IFLA_VXLAN_LINK attribute: %s",
63 strerror(-r));
64 return r;
65 }
66
aa9f1140
TG
67 if(v->ttl) {
68 r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_TTL, v->ttl);
326cb406
SS
69 if (r < 0) {
70 log_error_netdev(netdev,
71 "Could not append IFLA_VXLAN_TTL attribute: %s",
72 strerror(-r));
73 return r;
74 }
75 }
76
aa9f1140
TG
77 if(v->tos) {
78 r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_TOS, v->tos);
326cb406
SS
79 if (r < 0) {
80 log_error_netdev(netdev,
81 "Could not append IFLA_VXLAN_TOS attribute: %s",
82 strerror(-r));
83 return r;
84 }
85 }
86
aa9f1140 87 r = sd_rtnl_message_append_u8(m, IFLA_VXLAN_LEARNING, v->learning);
326cb406
SS
88 if (r < 0) {
89 log_error_netdev(netdev,
90 "Could not append IFLA_VXLAN_LEARNING attribute: %s",
91 strerror(-r));
92 return r;
93 }
94
326cb406
SS
95 return r;
96}
97
3be1d7e0 98static int netdev_vxlan_verify(NetDev *netdev, const char *filename) {
aa9f1140
TG
99 VxLan *v = VXLAN(netdev);
100
326cb406 101 assert(netdev);
aa9f1140 102 assert(v);
3be1d7e0 103 assert(filename);
326cb406 104
aa9f1140 105 if (v->id > VXLAN_VID_MAX) {
3be1d7e0
TG
106 log_warning("VXLAN without valid Id configured in %s. Ignoring", filename);
107 return -EINVAL;
326cb406
SS
108 }
109
326cb406
SS
110 return 0;
111}
3be1d7e0 112
aa9f1140
TG
113static 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
3be1d7e0 123const NetDevVTable vxlan_vtable = {
aa9f1140
TG
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,
3be1d7e0
TG
129 .config_verify = netdev_vxlan_verify,
130};