23 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
25 #include <linux/net.h>
27 #include <linux/connector.h>
56 static bool in_hand_shake =
true;
61 static int dm_reg_value;
74 static const char kvp_name[] =
"kvp_kernel_module";
75 static u8 *recv_buffer;
97 kvp_msg->
kvp_hdr.operation = reg_value;
98 strcpy(version, HV_DRV_VERSION);
114 static int kvp_handle_handshake(
struct hv_kvp_msg *msg)
118 switch (msg->
kvp_hdr.operation) {
121 pr_info(
"KVP: IP injection functionality not available\n");
122 pr_info(
"KVP: Upgrade the KVP daemon\n");
128 pr_info(
"KVP: incompatible daemon\n");
129 pr_info(
"KVP: KVP version: %d, Daemon version: %d\n",
138 pr_info(
"KVP: user-mode registering done.\n");
140 kvp_transaction.active =
false;
141 if (kvp_transaction.kvp_context)
167 if (kvp_handle_handshake(message))
168 in_hand_shake =
false;
179 switch (dm_reg_value) {
184 if (data->
data.key[0] == 0)
193 error = message->
error;
202 kvp_respond_to_host(message, error);
206 static int process_ob_ipinfo(
void *in_msg,
void *out_msg,
int op)
266 static void process_ib_ipinfo(
void *in_msg,
void *out_msg,
int op)
323 __u8 pool = kvp_transaction.kvp_msg->kvp_hdr.pool;
335 message->
kvp_hdr.operation = operation;
337 in_msg = kvp_transaction.kvp_msg;
350 switch (message->
kvp_hdr.operation) {
433 kvp_respond_to_host(
struct hv_kvp_msg *msg_to_host,
int error)
439 struct icmsg_hdr *icmsghdrp;
451 if (!kvp_transaction.active) {
455 pr_warn(
"KVP: Transaction not active\n");
463 buf_len = kvp_transaction.recv_len;
464 channel = kvp_transaction.recv_channel;
465 req_id = kvp_transaction.recv_req_id;
467 kvp_transaction.active =
false;
469 icmsghdrp = (
struct icmsg_hdr *)
470 &recv_buffer[
sizeof(
struct vmbuspipe_hdr)];
472 if (channel->onchannel_callback ==
NULL)
479 icmsghdrp->status =
error;
494 &recv_buffer[
sizeof(
struct vmbuspipe_hdr) +
495 sizeof(
struct icmsg_hdr)];
497 switch (kvp_transaction.kvp_msg->kvp_hdr.operation) {
499 ret = process_ob_ipinfo(msg_to_host,
530 (
wchar_t *) kvp_data->
key,
532 kvp_data->
key_size = 2*(keylen + 1);
537 (
wchar_t *) kvp_data->
value,
545 if ((keylen < 0) || (valuelen < 0))
551 icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION | ICMSGHDRFLAG_RESPONSE;
554 VM_PKT_DATA_INBAND, 0);
570 struct vmbus_channel *channel =
context;
576 struct icmsg_hdr *icmsghdrp;
577 struct icmsg_negotiate *negop =
NULL;
579 if (kvp_transaction.active) {
584 kvp_transaction.kvp_context =
context;
592 icmsghdrp = (
struct icmsg_hdr *)&recv_buffer[
593 sizeof(
struct vmbuspipe_hdr)];
595 if (icmsghdrp->icmsgtype == ICMSGTYPE_NEGOTIATE) {
597 recv_buffer, MAX_SRV_VER, MAX_SRV_VER);
600 sizeof(
struct vmbuspipe_hdr) +
601 sizeof(
struct icmsg_hdr)];
608 kvp_transaction.recv_len = recvlen;
609 kvp_transaction.recv_channel =
channel;
610 kvp_transaction.recv_req_id = requestid;
611 kvp_transaction.active =
true;
612 kvp_transaction.kvp_msg =
kvp_msg;
630 icmsghdrp->icflags = ICMSGHDRFLAG_TRANSACTION
631 | ICMSGHDRFLAG_RESPONSE;
635 VM_PKT_DATA_INBAND, 0);
648 recv_buffer = srv->recv_buffer;
656 kvp_transaction.active =
true;