1 /*
2  * Copyright (c) 2021 Intel Corporation.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief Virtual Interface Management interface public header
10  */
11 
12 #ifndef ZEPHYR_INCLUDE_NET_VIRTUAL_MGMT_H_
13 #define ZEPHYR_INCLUDE_NET_VIRTUAL_MGMT_H_
14 
15 #include <zephyr/net/virtual.h>
16 #include <zephyr/net/net_mgmt.h>
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 /**
23  * @brief Virtual interface library
24  * @defgroup virtual_mgmt Virtual Interface Library
25  * @since 2.6
26  * @version 0.8.0
27  * @ingroup networking
28  * @{
29  */
30 
31 /** @cond INTERNAL_HIDDEN */
32 
33 #define _NET_VIRTUAL_INTERFACE_LAYER	NET_MGMT_LAYER_L2
34 #define _NET_VIRTUAL_INTERFACE_CODE	0x209
35 #define _NET_VIRTUAL_INTERFACE_BASE					\
36 	(NET_MGMT_IFACE_BIT |						\
37 	 NET_MGMT_LAYER(_NET_VIRTUAL_INTERFACE_LAYER) |			\
38 	 NET_MGMT_LAYER_CODE(_NET_VIRTUAL_INTERFACE_CODE))
39 #define _NET_VIRTUAL_INTERFACE_EVENT					\
40 	(_NET_VIRTUAL_INTERFACE_BASE | NET_MGMT_EVENT_BIT)
41 
42 struct virtual_interface_req_params {
43 	sa_family_t family;
44 	union {
45 		struct in_addr peer4addr;
46 		struct in6_addr peer6addr;
47 		int mtu;
48 		struct virtual_interface_link_types link_types;
49 	};
50 };
51 
52 enum net_request_virtual_interface_cmd {
53 	NET_REQUEST_VIRTUAL_INTERFACE_CMD_SET_PEER_ADDR = 1,
54 	NET_REQUEST_VIRTUAL_INTERFACE_CMD_GET_PEER_ADDR,
55 	NET_REQUEST_VIRTUAL_INTERFACE_CMD_SET_MTU,
56 	NET_REQUEST_VIRTUAL_INTERFACE_CMD_GET_MTU,
57 	NET_REQUEST_VIRTUAL_INTERFACE_CMD_SET_LINK_TYPE,
58 	NET_REQUEST_VIRTUAL_INTERFACE_CMD_GET_LINK_TYPE,
59 };
60 
61 #define NET_REQUEST_VIRTUAL_INTERFACE_SET_PEER_ADDRESS		\
62 	(_NET_VIRTUAL_INTERFACE_BASE |				\
63 	 NET_REQUEST_VIRTUAL_INTERFACE_CMD_SET_PEER_ADDR)
64 
65 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_VIRTUAL_INTERFACE_SET_PEER_ADDRESS);
66 
67 #define NET_REQUEST_VIRTUAL_INTERFACE_SET_MTU		\
68 	(_NET_VIRTUAL_INTERFACE_BASE |			\
69 	 NET_REQUEST_VIRTUAL_INTERFACE_CMD_SET_MTU)
70 
71 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_VIRTUAL_INTERFACE_SET_MTU);
72 
73 #define NET_REQUEST_VIRTUAL_INTERFACE_SET_LINK_TYPE	\
74 	(_NET_VIRTUAL_INTERFACE_BASE |			\
75 	 NET_REQUEST_VIRTUAL_INTERFACE_CMD_SET_LINK_TYPE)
76 
77 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_VIRTUAL_INTERFACE_SET_LINK_TYPE);
78 
79 #define NET_REQUEST_VIRTUAL_INTERFACE_GET_PEER_ADDRESS		\
80 	(_NET_VIRTUAL_INTERFACE_BASE |				\
81 	 NET_REQUEST_VIRTUAL_INTERFACE_CMD_GET_PEER_ADDR)
82 
83 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_VIRTUAL_INTERFACE_GET_PEER_ADDRESS);
84 
85 #define NET_REQUEST_VIRTUAL_INTERFACE_GET_MTU		\
86 	(_NET_VIRTUAL_INTERFACE_BASE |			\
87 	 NET_REQUEST_VIRTUAL_INTERFACE_CMD_GET_MTU)
88 
89 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_VIRTUAL_INTERFACE_GET_MTU);
90 
91 #define NET_REQUEST_VIRTUAL_INTERFACE_GET_LINK_TYPE	\
92 	(_NET_VIRTUAL_INTERFACE_BASE |			\
93 	 NET_REQUEST_VIRTUAL_INTERFACE_CMD_GET_LINK_TYPE)
94 
95 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_VIRTUAL_INTERFACE_GET_LINK_TYPE);
96 
97 struct net_if;
98 
99 /** @endcond */
100 
101 /**
102  * @}
103  */
104 
105 #ifdef __cplusplus
106 }
107 #endif
108 
109 #endif /* ZEPHYR_INCLUDE_NET_VIRTUAL_MGMT_H_ */
110