1 /* SPDX-License-Identifier: LGPL-2.1-or-later
2 * Copyright © 2020 VMware, Inc. */
5 #include "netlink-util.h"
6 #include "networkd-manager.h"
7 #include "string-table.h"
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",
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=");
20 static int netdev_bare_udp_fill_message_create(NetDev
*netdev
, Link
*link
, sd_netlink_message
*m
) {
31 r
= sd_netlink_message_append_u16(m
, IFLA_BAREUDP_ETHERTYPE
, htobe16(u
->iftype
));
33 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_BAREUDP_ETHERTYPE attribute: %m");
35 r
= sd_netlink_message_append_u16(m
, IFLA_BAREUDP_PORT
, htobe16(u
->dest_port
));
37 return log_netdev_error_errno(netdev
, r
, "Could not append IFLA_BAREUDP_PORT attribute: %m");
42 static int netdev_bare_udp_verify(NetDev
*netdev
, const char *filename
) {
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
);
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
);
63 static void bare_udp_init(NetDev
*netdev
) {
72 u
->iftype
= _BARE_UDP_PROTOCOL_INVALID
;
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
,