1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 
3 #include <linux/if_arp.h>
4 
5 #include "missing_network.h"
6 #include "xfrm.h"
7 
xfrm_fill_message_create(NetDev * netdev,Link * link,sd_netlink_message * message)8 static int xfrm_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *message) {
9         Xfrm *x;
10         int r;
11 
12         assert(netdev);
13         assert(message);
14 
15         x = XFRM(netdev);
16 
17         assert(x);
18         assert(link || x->independent);
19 
20         r = sd_netlink_message_append_u32(message, IFLA_XFRM_LINK, link ? link->ifindex : LOOPBACK_IFINDEX);
21         if (r < 0)
22                 return r;
23 
24         r = sd_netlink_message_append_u32(message, IFLA_XFRM_IF_ID, x->if_id);
25         if (r < 0)
26                 return r;
27 
28         return 0;
29 }
30 
xfrm_verify(NetDev * netdev,const char * filename)31 static int xfrm_verify(NetDev *netdev, const char *filename) {
32         Xfrm *x;
33 
34         assert(netdev);
35         assert(filename);
36 
37         x = XFRM(netdev);
38 
39         assert(x);
40 
41         if (x->if_id == 0)
42                 return log_netdev_warning_errno(netdev, SYNTHETIC_ERRNO(EINVAL),
43                                                 "%s: Xfrm interface ID cannot be zero.", filename);
44 
45         return 0;
46 }
47 
48 const NetDevVTable xfrm_vtable = {
49         .object_size = sizeof(Xfrm),
50         .sections = NETDEV_COMMON_SECTIONS "Xfrm\0",
51         .fill_message_create = xfrm_fill_message_create,
52         .config_verify = xfrm_verify,
53         .create_type = NETDEV_CREATE_STACKED,
54         .iftype = ARPHRD_NONE,
55 };
56