1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
3 /* Make sure the net/if.h header is included before any linux/ one */
6 #include <linux/if_arp.h>
7 #include <linux/veth.h>
8 #include <netinet/in.h>
10 #include "netlink-util.h"
13 static int netdev_veth_fill_message_create(NetDev
*netdev
, Link
*link
, sd_netlink_message
*m
) {
17 struct hw_addr_data hw_addr
;
18 Veth
*v
= VETH(netdev
);
21 r
= sd_netlink_message_open_container(m
, VETH_INFO_PEER
);
26 r
= sd_netlink_message_append_string(m
, IFLA_IFNAME
, v
->ifname_peer
);
31 r
= netdev_generate_hw_addr(netdev
, NULL
, v
->ifname_peer
, &v
->hw_addr_peer
, &hw_addr
);
35 if (hw_addr
.length
> 0) {
36 log_netdev_debug(netdev
, "Using MAC address for peer: %s", HW_ADDR_TO_STR(&hw_addr
));
37 r
= netlink_message_append_hw_addr(m
, IFLA_ADDRESS
, &hw_addr
);
42 if (netdev
->mtu
!= 0) {
43 r
= sd_netlink_message_append_u32(m
, IFLA_MTU
, netdev
->mtu
);
48 r
= sd_netlink_message_close_container(m
);
55 static int netdev_veth_verify(NetDev
*netdev
, const char *filename
) {
58 Veth
*v
= VETH(netdev
);
61 return log_netdev_warning_errno(netdev
, SYNTHETIC_ERRNO(EINVAL
),
62 "Veth NetDev without peer name configured in %s. Ignoring",
68 static void veth_done(NetDev
*netdev
) {
69 Veth
*v
= VETH(netdev
);
74 const NetDevVTable veth_vtable
= {
75 .object_size
= sizeof(Veth
),
76 .sections
= NETDEV_COMMON_SECTIONS
"Peer\0",
78 .fill_message_create
= netdev_veth_fill_message_create
,
79 .create_type
= NETDEV_CREATE_INDEPENDENT
,
80 .config_verify
= netdev_veth_verify
,
81 .iftype
= ARPHRD_ETHER
,