aboutsummaryrefslogtreecommitdiffstats
path: root/tools/hv/hv_kvp_daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/hv/hv_kvp_daemon.c')
-rw-r--r--tools/hv/hv_kvp_daemon.c62
1 files changed, 16 insertions, 46 deletions
diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 11224eddcdc2..4ebf70380582 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -34,21 +34,12 @@
34#include <errno.h> 34#include <errno.h>
35#include <arpa/inet.h> 35#include <arpa/inet.h>
36#include <linux/connector.h> 36#include <linux/connector.h>
37#include <linux/hyperv.h>
37#include <linux/netlink.h> 38#include <linux/netlink.h>
38#include <ifaddrs.h> 39#include <ifaddrs.h>
39#include <netdb.h> 40#include <netdb.h>
40#include <syslog.h> 41#include <syslog.h>
41 42
42/*
43 * KYS: TODO. Need to register these in the kernel.
44 *
45 * The following definitions are shared with the in-kernel component; do not
46 * change any of this without making the corresponding changes in
47 * the KVP kernel component.
48 */
49#define CN_KVP_IDX 0x9 /* MSFT KVP functionality */
50#define CN_KVP_VAL 0x1 /* This supports queries from the kernel */
51#define CN_KVP_USER_VAL 0x2 /* This supports queries from the user */
52 43
53/* 44/*
54 * KVP protocol: The user mode component first registers with the 45 * KVP protocol: The user mode component first registers with the
@@ -60,25 +51,8 @@
60 * We use this infrastructure for also supporting queries from user mode 51 * We use this infrastructure for also supporting queries from user mode
61 * application for state that may be maintained in the KVP kernel component. 52 * application for state that may be maintained in the KVP kernel component.
62 * 53 *
63 * XXXKYS: Have a shared header file between the user and kernel (TODO)
64 */ 54 */
65 55
66enum kvp_op {
67 KVP_REGISTER = 0, /* Register the user mode component*/
68 KVP_KERNEL_GET, /*Kernel is requesting the value for the specified key*/
69 KVP_KERNEL_SET, /*Kernel is providing the value for the specified key*/
70 KVP_USER_GET, /*User is requesting the value for the specified key*/
71 KVP_USER_SET /*User is providing the value for the specified key*/
72};
73
74#define HV_KVP_EXCHANGE_MAX_KEY_SIZE 512
75#define HV_KVP_EXCHANGE_MAX_VALUE_SIZE 2048
76
77struct hv_ku_msg {
78 __u32 kvp_index;
79 __u8 kvp_key[HV_KVP_EXCHANGE_MAX_KEY_SIZE]; /* Key name */
80 __u8 kvp_value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE]; /* Key value */
81};
82 56
83enum key_index { 57enum key_index {
84 FullyQualifiedDomainName = 0, 58 FullyQualifiedDomainName = 0,
@@ -93,10 +67,6 @@ enum key_index {
93 ProcessorArchitecture 67 ProcessorArchitecture
94}; 68};
95 69
96/*
97 * End of shared definitions.
98 */
99
100static char kvp_send_buffer[4096]; 70static char kvp_send_buffer[4096];
101static char kvp_recv_buffer[4096]; 71static char kvp_recv_buffer[4096];
102static struct sockaddr_nl addr; 72static struct sockaddr_nl addr;
@@ -332,7 +302,7 @@ int main(void)
332 struct pollfd pfd; 302 struct pollfd pfd;
333 struct nlmsghdr *incoming_msg; 303 struct nlmsghdr *incoming_msg;
334 struct cn_msg *incoming_cn_msg; 304 struct cn_msg *incoming_cn_msg;
335 struct hv_ku_msg *hv_msg; 305 struct hv_kvp_msg *hv_msg;
336 char *p; 306 char *p;
337 char *key_value; 307 char *key_value;
338 char *key_name; 308 char *key_name;
@@ -370,9 +340,11 @@ int main(void)
370 message = (struct cn_msg *)kvp_send_buffer; 340 message = (struct cn_msg *)kvp_send_buffer;
371 message->id.idx = CN_KVP_IDX; 341 message->id.idx = CN_KVP_IDX;
372 message->id.val = CN_KVP_VAL; 342 message->id.val = CN_KVP_VAL;
373 message->seq = KVP_REGISTER; 343
344 hv_msg = (struct hv_kvp_msg *)message->data;
345 hv_msg->kvp_hdr.operation = KVP_OP_REGISTER;
374 message->ack = 0; 346 message->ack = 0;
375 message->len = 0; 347 message->len = sizeof(struct hv_kvp_msg);
376 348
377 len = netlink_send(fd, message); 349 len = netlink_send(fd, message);
378 if (len < 0) { 350 if (len < 0) {
@@ -398,14 +370,15 @@ int main(void)
398 370
399 incoming_msg = (struct nlmsghdr *)kvp_recv_buffer; 371 incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
400 incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg); 372 incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
373 hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data;
401 374
402 switch (incoming_cn_msg->seq) { 375 switch (hv_msg->kvp_hdr.operation) {
403 case KVP_REGISTER: 376 case KVP_OP_REGISTER:
404 /* 377 /*
405 * Driver is registering with us; stash away the version 378 * Driver is registering with us; stash away the version
406 * information. 379 * information.
407 */ 380 */
408 p = (char *)incoming_cn_msg->data; 381 p = (char *)hv_msg->body.kvp_version;
409 lic_version = malloc(strlen(p) + 1); 382 lic_version = malloc(strlen(p) + 1);
410 if (lic_version) { 383 if (lic_version) {
411 strcpy(lic_version, p); 384 strcpy(lic_version, p);
@@ -416,17 +389,15 @@ int main(void)
416 } 389 }
417 continue; 390 continue;
418 391
419 case KVP_KERNEL_GET:
420 break;
421 default: 392 default:
422 continue; 393 break;
423 } 394 }
424 395
425 hv_msg = (struct hv_ku_msg *)incoming_cn_msg->data; 396 hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data;
426 key_name = (char *)hv_msg->kvp_key; 397 key_name = (char *)hv_msg->body.kvp_enum_data.data.key;
427 key_value = (char *)hv_msg->kvp_value; 398 key_value = (char *)hv_msg->body.kvp_enum_data.data.value;
428 399
429 switch (hv_msg->kvp_index) { 400 switch (hv_msg->body.kvp_enum_data.index) {
430 case FullyQualifiedDomainName: 401 case FullyQualifiedDomainName:
431 kvp_get_domain_name(key_value, 402 kvp_get_domain_name(key_value,
432 HV_KVP_EXCHANGE_MAX_VALUE_SIZE); 403 HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
@@ -486,9 +457,8 @@ int main(void)
486 457
487 incoming_cn_msg->id.idx = CN_KVP_IDX; 458 incoming_cn_msg->id.idx = CN_KVP_IDX;
488 incoming_cn_msg->id.val = CN_KVP_VAL; 459 incoming_cn_msg->id.val = CN_KVP_VAL;
489 incoming_cn_msg->seq = KVP_USER_SET;
490 incoming_cn_msg->ack = 0; 460 incoming_cn_msg->ack = 0;
491 incoming_cn_msg->len = sizeof(struct hv_ku_msg); 461 incoming_cn_msg->len = sizeof(struct hv_kvp_msg);
492 462
493 len = netlink_send(fd, incoming_cn_msg); 463 len = netlink_send(fd, incoming_cn_msg);
494 if (len < 0) { 464 if (len < 0) {