]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/netdev/bareudp.c
8c0c895a0dfd56c8e155b426cb919207650b7840
[thirdparty/systemd.git] / src / network / netdev / bareudp.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later
2 * Copyright © 2020 VMware, Inc. */
3
4 #include "bareudp.h"
5 #include "netlink-util.h"
6 #include "networkd-manager.h"
7 #include "string-table.h"
8
9 static const char* const bare_udp_protocol_table[_BARE_UDP_PROTOCOL_MAX] = {
10 [BARE_UDP_PROTOCOL_IPV4] = "ipv4",
11 [BARE_UDP_PROTOCOL_IPV6] = "ipv6",
12 [BARE_UDP_PROTOCOL_MPLS_UC] = "mpls-uc",
13 [BARE_UDP_PROTOCOL_MPLS_MC] = "mpls-mc",
14 };
15
16 DEFINE_STRING_TABLE_LOOKUP(bare_udp_protocol, BareUDPProtocol);
17 DEFINE_CONFIG_PARSE_ENUM(config_parse_bare_udp_iftype, bare_udp_protocol, BareUDPProtocol,
18 "Failed to parse EtherType=");
19
20 static int netdev_bare_udp_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
21 BareUDP *u;
22 int r;
23
24 assert(netdev);
25 assert(m);
26
27 u = BAREUDP(netdev);
28
29 assert(u);
30
31 r = sd_netlink_message_append_u16(m, IFLA_BAREUDP_ETHERTYPE, htobe16(u->iftype));
32 if (r < 0)
33 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BAREUDP_ETHERTYPE attribute: %m");
34
35 r = sd_netlink_message_append_u16(m, IFLA_BAREUDP_PORT, htobe16(u->dest_port));
36 if (r < 0)
37 return log_netdev_error_errno(netdev, r, "Could not append IFLA_BAREUDP_PORT attribute: %m");
38
39 return 0;
40 }
41
42 static int netdev_bare_udp_verify(NetDev *netdev, const char *filename) {
43 BareUDP *u;
44
45 assert(netdev);
46 assert(filename);
47
48 u = BAREUDP(netdev);
49
50 assert(u);
51
52 if (u->dest_port == 0)
53 return log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
54 "%s: BareUDP DesinationPort= is not set. Ignoring.", filename);
55
56 if (u->iftype == _BARE_UDP_PROTOCOL_INVALID)
57 return log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
58 "%s: BareUDP EtherType= is not set. Ignoring.", filename);
59
60 return 0;
61 }
62
63 static void bare_udp_init(NetDev *netdev) {
64 BareUDP *u;
65
66 assert(netdev);
67
68 u = BAREUDP(netdev);
69
70 assert(u);
71
72 u->iftype = _BARE_UDP_PROTOCOL_INVALID;
73 }
74
75 const NetDevVTable bare_udp_vtable = {
76 .object_size = sizeof(BareUDP),
77 .sections = NETDEV_COMMON_SECTIONS "BareUDP\0",
78 .init = bare_udp_init,
79 .config_verify = netdev_bare_udp_verify,
80 .fill_message_create = netdev_bare_udp_fill_message_create,
81 .create_type = NETDEV_CREATE_INDEPENDENT,
82 };