]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/netdev/bareudp.c
sd-ipv4acd: fix assertion triggered when an ARP received in STARTED state
[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 <netinet/in.h>
5 #include <linux/if_arp.h>
6
7 #include "bareudp.h"
8 #include "netlink-util.h"
9 #include "networkd-manager.h"
10 #include "string-table.h"
11
12 static const char* const bare_udp_protocol_table[_BARE_UDP_PROTOCOL_MAX] = {
13 [BARE_UDP_PROTOCOL_IPV4] = "ipv4",
14 [BARE_UDP_PROTOCOL_IPV6] = "ipv6",
15 [BARE_UDP_PROTOCOL_MPLS_UC] = "mpls-uc",
16 [BARE_UDP_PROTOCOL_MPLS_MC] = "mpls-mc",
17 };
18
19 DEFINE_STRING_TABLE_LOOKUP(bare_udp_protocol, BareUDPProtocol);
20 DEFINE_CONFIG_PARSE_ENUM(config_parse_bare_udp_iftype, bare_udp_protocol, BareUDPProtocol,
21 "Failed to parse EtherType=");
22
23 static int netdev_bare_udp_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
24 assert(m);
25
26 BareUDP *u = BAREUDP(netdev);
27 int r;
28
29 r = sd_netlink_message_append_u16(m, IFLA_BAREUDP_ETHERTYPE, htobe16(u->iftype));
30 if (r < 0)
31 return r;
32
33 r = sd_netlink_message_append_u16(m, IFLA_BAREUDP_PORT, htobe16(u->dest_port));
34 if (r < 0)
35 return r;
36
37 return 0;
38 }
39
40 static int netdev_bare_udp_verify(NetDev *netdev, const char *filename) {
41 assert(filename);
42
43 BareUDP *u = BAREUDP(netdev);
44
45 if (u->dest_port == 0)
46 return log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
47 "%s: BareUDP DesinationPort= is not set. Ignoring.", filename);
48
49 if (u->iftype == _BARE_UDP_PROTOCOL_INVALID)
50 return log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
51 "%s: BareUDP EtherType= is not set. Ignoring.", filename);
52
53 return 0;
54 }
55
56 static void bare_udp_init(NetDev *netdev) {
57 BareUDP *u = BAREUDP(netdev);
58
59 u->iftype = _BARE_UDP_PROTOCOL_INVALID;
60 }
61
62 const NetDevVTable bare_udp_vtable = {
63 .object_size = sizeof(BareUDP),
64 .sections = NETDEV_COMMON_SECTIONS "BareUDP\0",
65 .init = bare_udp_init,
66 .config_verify = netdev_bare_udp_verify,
67 .fill_message_create = netdev_bare_udp_fill_message_create,
68 .create_type = NETDEV_CREATE_INDEPENDENT,
69 .iftype = ARPHRD_NONE,
70 };