1 /* SPDX-License-Identifier: LGPL-2.1-or-later
2 * Copyright © 2020 VMware, Inc. */
4 #include <netinet/in.h>
5 #include <linux/if_arp.h>
8 #include "netlink-util.h"
9 #include "networkd-manager.h"
10 #include "string-table.h"
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",
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=");
23 static int netdev_bare_udp_fill_message_create(NetDev
*netdev
, Link
*link
, sd_netlink_message
*m
) {
26 BareUDP
*u
= BAREUDP(netdev
);
29 r
= sd_netlink_message_append_u16(m
, IFLA_BAREUDP_ETHERTYPE
, htobe16(u
->iftype
));
33 r
= sd_netlink_message_append_u16(m
, IFLA_BAREUDP_PORT
, htobe16(u
->dest_port
));
40 static int netdev_bare_udp_verify(NetDev
*netdev
, const char *filename
) {
43 BareUDP
*u
= BAREUDP(netdev
);
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
);
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
);
56 static void bare_udp_init(NetDev
*netdev
) {
57 BareUDP
*u
= BAREUDP(netdev
);
59 u
->iftype
= _BARE_UDP_PROTOCOL_INVALID
;
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
,