Deleted Added
full compact
hv_kvp.h (272152) hv_kvp.h (272322)
1/*-
1/*-
2 * Copyright (c) 2009-2012 Microsoft Corp.
3 * Copyright (c) 2012 NetApp Inc.
4 * Copyright (c) 2012 Citrix Inc.
2 * Copyright (c) 2014 Microsoft Corp.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice unmodified, this list of conditions, and the following
12 * disclaimer.

--- 6 unchanged lines hidden (view full) ---

19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
10 * disclaimer.

--- 6 unchanged lines hidden (view full) ---

17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
28
29#ifndef _KVP_H
30#define _KVP_H
31
32/*
27 */
28
29#ifndef _KVP_H
30#define _KVP_H
31
32/*
33 * An implementation of HyperV key value pair (KVP) functionality for FreeBSD
33 * An implementation of HyperV key value pair (KVP) functionality for FreeBSD
34 *
35 */
36
37/*
38 * Maximum value size - used for both key names and value data, and includes
39 * any applicable NULL terminators.
40 *
41 * Note: This limit is somewhat arbitrary, but falls easily within what is

--- 6 unchanged lines hidden (view full) ---

48 *
49 * Note: This value is used in defining the KVP exchange message - this value
50 * cannot be modified without affecting the message size and compatibility.
51 */
52
53/*
54 * bytes, including any null terminators
55 */
34 *
35 */
36
37/*
38 * Maximum value size - used for both key names and value data, and includes
39 * any applicable NULL terminators.
40 *
41 * Note: This limit is somewhat arbitrary, but falls easily within what is

--- 6 unchanged lines hidden (view full) ---

48 *
49 * Note: This value is used in defining the KVP exchange message - this value
50 * cannot be modified without affecting the message size and compatibility.
51 */
52
53/*
54 * bytes, including any null terminators
55 */
56#define HV_KVP_EXCHANGE_MAX_VALUE_SIZE (2048)
56#define HV_KVP_EXCHANGE_MAX_VALUE_SIZE (2048)
57
58
59/*
60 * Maximum key size - the registry limit for the length of an entry name
61 * is 256 characters, including the null terminator
62 */
57
58
59/*
60 * Maximum key size - the registry limit for the length of an entry name
61 * is 256 characters, including the null terminator
62 */
63#define HV_KVP_EXCHANGE_MAX_KEY_SIZE (512)
63
64
64#define HV_KVP_EXCHANGE_MAX_KEY_SIZE (512)
65
66/*
67 * In FreeBSD, we implement the KVP functionality in two components:
68 * 1) The kernel component which is packaged as part of the hv_utils driver
69 * is responsible for communicating with the host and responsible for
70 * implementing the host/guest protocol. 2) A user level daemon that is
71 * responsible for data gathering.
72 *

--- 33 unchanged lines hidden (view full) ---

106 * The kernel component simply acts as a conduit for communication between the
107 * Windows host and the user-level daemon. The kernel component passes up the
108 * index received from the Host to the user-level daemon. If the index is
109 * valid (supported), the corresponding key as well as its
110 * value (both are strings) is returned. If the index is invalid
111 * (not supported), a NULL key string is returned.
112 */
113
65
66/*
67 * In FreeBSD, we implement the KVP functionality in two components:
68 * 1) The kernel component which is packaged as part of the hv_utils driver
69 * is responsible for communicating with the host and responsible for
70 * implementing the host/guest protocol. 2) A user level daemon that is
71 * responsible for data gathering.
72 *

--- 33 unchanged lines hidden (view full) ---

106 * The kernel component simply acts as a conduit for communication between the
107 * Windows host and the user-level daemon. The kernel component passes up the
108 * index received from the Host to the user-level daemon. If the index is
109 * valid (supported), the corresponding key as well as its
110 * value (both are strings) is returned. If the index is invalid
111 * (not supported), a NULL key string is returned.
112 */
113
114
114
115/*
116 * Registry value types.
117 */
115/*
116 * Registry value types.
117 */
118#define HV_REG_SZ 1
119#define HV_REG_U32 4
120#define HV_REG_U64 8
118
121
119#define HV_REG_SZ 1
120#define HV_REG_U32 4
121#define HV_REG_U64 8
122
122
123
124/*
123/*
125 * Daemon code not supporting IP injection (legacy daemon).
126 */
127
128#define HV_KVP_OP_REGISTER 4
129
130/*
131 * Daemon code supporting IP injection.
124 * Daemon code supporting IP injection.
132 * The KVP opcode field is used to communicate the
133 * registration information; so define a namespace that
134 * will be distinct from the host defined KVP opcode.
135 */
125 */
126#define HV_KVP_OP_REGISTER 4
136
127
137#define KVP_OP_REGISTER1 100
138
139enum hv_kvp_exchg_op {
140 HV_KVP_OP_GET = 0,
141 HV_KVP_OP_SET,
142 HV_KVP_OP_DELETE,
143 HV_KVP_OP_ENUMERATE,
144 HV_KVP_OP_GET_IP_INFO,
145 HV_KVP_OP_SET_IP_INFO,

--- 4 unchanged lines hidden (view full) ---

150 HV_KVP_POOL_EXTERNAL = 0,
151 HV_KVP_POOL_GUEST,
152 HV_KVP_POOL_AUTO,
153 HV_KVP_POOL_AUTO_EXTERNAL,
154 HV_KVP_POOL_AUTO_INTERNAL,
155 HV_KVP_POOL_COUNT /* Number of pools, must be last. */
156};
157
128
129enum hv_kvp_exchg_op {
130 HV_KVP_OP_GET = 0,
131 HV_KVP_OP_SET,
132 HV_KVP_OP_DELETE,
133 HV_KVP_OP_ENUMERATE,
134 HV_KVP_OP_GET_IP_INFO,
135 HV_KVP_OP_SET_IP_INFO,

--- 4 unchanged lines hidden (view full) ---

140 HV_KVP_POOL_EXTERNAL = 0,
141 HV_KVP_POOL_GUEST,
142 HV_KVP_POOL_AUTO,
143 HV_KVP_POOL_AUTO_EXTERNAL,
144 HV_KVP_POOL_AUTO_INTERNAL,
145 HV_KVP_POOL_COUNT /* Number of pools, must be last. */
146};
147
148
158/*
159 * Some Hyper-V status codes.
160 */
149/*
150 * Some Hyper-V status codes.
151 */
161#define HV_KVP_S_OK 0x00000000
162#define HV_KVP_E_FAIL 0x80004005
163#define HV_KVP_S_CONT 0x80070103
164#define HV_ERROR_NOT_SUPPORTED 0x80070032
165#define HV_ERROR_MACHINE_LOCKED 0x800704F7
166#define HV_ERROR_DEVICE_NOT_CONNECTED 0x8007048F
167#define HV_INVALIDARG 0x80070057
168#define HV_KVP_GUID_NOTFOUND 0x80041002
152#define HV_KVP_S_OK 0x00000000
153#define HV_KVP_E_FAIL 0x80004005
154#define HV_KVP_S_CONT 0x80070103
155#define HV_ERROR_NOT_SUPPORTED 0x80070032
156#define HV_ERROR_MACHINE_LOCKED 0x800704F7
157#define HV_ERROR_DEVICE_NOT_CONNECTED 0x8007048F
158#define HV_INVALIDARG 0x80070057
159#define HV_KVP_GUID_NOTFOUND 0x80041002
169
160
170#define ADDR_FAMILY_NONE 0x00
171#define ADDR_FAMILY_IPV4 0x01
172#define ADDR_FAMILY_IPV6 0x02
161#define ADDR_FAMILY_NONE 0x00
162#define ADDR_FAMILY_IPV4 0x01
163#define ADDR_FAMILY_IPV6 0x02
173
164
174#define MAX_ADAPTER_ID_SIZE 128
175#define MAX_IP_ADDR_SIZE 1024
176#define MAX_GATEWAY_SIZE 512
165#define MAX_ADAPTER_ID_SIZE 128
166#define MAX_IP_ADDR_SIZE 1024
167#define MAX_GATEWAY_SIZE 512
177
178
179struct hv_kvp_ipaddr_value {
168
169
170struct hv_kvp_ipaddr_value {
180 uint16_t adapter_id[MAX_ADAPTER_ID_SIZE];
181 uint8_t addr_family;
182 uint8_t dhcp_enabled;
183 uint16_t ip_addr[MAX_IP_ADDR_SIZE];
184 uint16_t sub_net[MAX_IP_ADDR_SIZE];
185 uint16_t gate_way[MAX_GATEWAY_SIZE];
186 uint16_t dns_addr[MAX_IP_ADDR_SIZE];
187} __attribute__((packed));
171 uint16_t adapter_id[MAX_ADAPTER_ID_SIZE];
172 uint8_t addr_family;
173 uint8_t dhcp_enabled;
174 uint16_t ip_addr[MAX_IP_ADDR_SIZE];
175 uint16_t sub_net[MAX_IP_ADDR_SIZE];
176 uint16_t gate_way[MAX_GATEWAY_SIZE];
177 uint16_t dns_addr[MAX_IP_ADDR_SIZE];
178}__attribute__((packed));
188
179
189
190struct hv_kvp_hdr {
180struct hv_kvp_hdr {
191 uint8_t operation;
192 uint8_t pool;
181 uint8_t operation;
182 uint8_t pool;
193 uint16_t pad;
194} __attribute__((packed));
195
196struct hv_kvp_exchg_msg_value {
197 uint32_t value_type;
198 uint32_t key_size;
199 uint32_t value_size;
183 uint16_t pad;
184} __attribute__((packed));
185
186struct hv_kvp_exchg_msg_value {
187 uint32_t value_type;
188 uint32_t key_size;
189 uint32_t value_size;
200 uint8_t key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
190 uint8_t key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
201 union {
191 union {
202 uint8_t value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
192 uint8_t value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
203 uint32_t value_u32;
204 uint64_t value_u64;
205 } msg_value;
206} __attribute__((packed));
207
208struct hv_kvp_msg_enumerate {
209 uint32_t index;
210 struct hv_kvp_exchg_msg_value data;

--- 13 unchanged lines hidden (view full) ---

224} __attribute__((packed));
225
226struct hv_kvp_register {
227 uint8_t version[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
228} __attribute__((packed));
229
230struct hv_kvp_msg {
231 union {
193 uint32_t value_u32;
194 uint64_t value_u64;
195 } msg_value;
196} __attribute__((packed));
197
198struct hv_kvp_msg_enumerate {
199 uint32_t index;
200 struct hv_kvp_exchg_msg_value data;

--- 13 unchanged lines hidden (view full) ---

214} __attribute__((packed));
215
216struct hv_kvp_register {
217 uint8_t version[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
218} __attribute__((packed));
219
220struct hv_kvp_msg {
221 union {
232 struct hv_kvp_hdr kvp_hdr;
233 int error;
222 struct hv_kvp_hdr kvp_hdr;
223 uint32_t error;
234 } hdr;
235 union {
224 } hdr;
225 union {
236 struct hv_kvp_msg_get kvp_get;
237 struct hv_kvp_msg_set kvp_set;
226 struct hv_kvp_msg_get kvp_get;
227 struct hv_kvp_msg_set kvp_set;
238 struct hv_kvp_msg_delete kvp_delete;
239 struct hv_kvp_msg_enumerate kvp_enum_data;
228 struct hv_kvp_msg_delete kvp_delete;
229 struct hv_kvp_msg_enumerate kvp_enum_data;
240 struct hv_kvp_ipaddr_value kvp_ip_val;
241 struct hv_kvp_register kvp_register;
230 struct hv_kvp_ipaddr_value kvp_ip_val;
231 struct hv_kvp_register kvp_register;
242 } body;
243} __attribute__((packed));
244
245struct hv_kvp_ip_msg {
246 uint8_t operation;
247 uint8_t pool;
248 struct hv_kvp_ipaddr_value kvp_ip_val;
249} __attribute__((packed));
250
232 } body;
233} __attribute__((packed));
234
235struct hv_kvp_ip_msg {
236 uint8_t operation;
237 uint8_t pool;
238 struct hv_kvp_ipaddr_value kvp_ip_val;
239} __attribute__((packed));
240
251#define BSD_SOC_PATH "/etc/hyperv/socket"
252
241
253#define HV_SHUT_DOWN 0
254#define HV_TIME_SYNCH 1
255#define HV_HEART_BEAT 2
256#define HV_KVP 3
257#define HV_MAX_UTIL_SERVICES 4
242#define HV_SHUT_DOWN 0
243#define HV_TIME_SYNCH 1
244#define HV_HEART_BEAT 2
245#define HV_KVP 3
246#define HV_MAX_UTIL_SERVICES 4
258
247
259#define HV_WLTIMEDELTA 116444736000000000L /* in 100ns unit */
260#define HV_ICTIMESYNCFLAG_PROBE 0
261#define HV_ICTIMESYNCFLAG_SYNC 1
262#define HV_ICTIMESYNCFLAG_SAMPLE 2
263#define HV_NANO_SEC_PER_SEC 1000000000
248#define HV_WLTIMEDELTA 116444736000000000L /* in 100ns unit */
249#define HV_ICTIMESYNCFLAG_PROBE 0
250#define HV_ICTIMESYNCFLAG_SYNC 1
251#define HV_ICTIMESYNCFLAG_SAMPLE 2
252#define HV_NANO_SEC_PER_SEC 1000000000
264
253
265typedef struct hv_vmbus_service {
266 hv_guid guid; /* Hyper-V GUID */
267 char* name; /* name of service */
268 boolean_t enabled; /* service enabled */
269 hv_work_queue* work_queue; /* background work queue */
270
271 //
272 // function to initialize service
273 //
274 int (*init)(struct hv_vmbus_service *);
275
276 //
277 // function to process Hyper-V messages
278 //
279 void (*callback)(void *);
280} hv_vmbus_service;
281
282extern uint8_t* receive_buffer[];
283extern hv_vmbus_service service_table[];
284
285#endif /* _KVP_H */
254#endif /* _KVP_H */