Skip to contentSkip to conversation

Tools: hv: kvp

PATCH In review K. Y. Srinivasan 2 participants 17 messages Sep 4, 2012 – Sep 5, 2012 Hyper-V/Azure core and drivers

lore
Share & tools
lore
#0 lore raw

v4 cover Tools: hv: kvp

This is a resubmission of the subset of the patches that were not accepted in an earlier submission. The main objection last time was that the KVP daemon code invoked external scripts for some of the operations and that I had not included those scripts in the patchset. This current approach of not encumbering the KVP daemon code with Distro specific details was discussed on this mailing list and here is the summary:

1) Using Network Manager APIs in the KVP daemon code directly would minimize environments where KVP functionality could be deployed since Network Manager is not available in all of the Distro images of interest; especially server images.

2) The current architecture of invoking external scripts for what is essentially a distro specific operation retains full flexibility of deploying KVP on all Distros of interest while not sacrificing our ability to use Network Manager APIs. For instance a Distro could choose to implement these external scripts using NM AMPIs.

In this patchset I have included the external scripts that I had used to test the KVP functionality as example scripts. These are meant as just examples.

K. Y. Srinivasan (10):
Tools: hv: Get rid of some unused variables
Tools: hv: Correctly type string variables
Tools: hv: Add an example script to retrieve DNS entries
Tools: hv: Gather DNS information
Tools: hv: Add an example script to retrieve dhcp state
Tools: hv: Gather DHCP information
Tools: hv: Add an example script to configure an interface
Tools: hv: Implement the KVP verb - KVP_OP_SET_IP_INFO
Tools: hv: Rename the function kvp_get_ip_address()
Tools: hv: Implement the KVP verb - KVP_OP_GET_IP_INFO

 include/linux/hyperv.h       |    2 +
 tools/hv/hv_get_dhcp_info.sh |   25 ++
 tools/hv/hv_get_dns_info.sh  |   13 +
 tools/hv/hv_kvp_daemon.c     |  607 +++++++++++++++++++++++++++++++++++++++++-
 tools/hv/hv_set_ifconfig.sh  |   68 +++++
 5 files changed, 703 insertions(+), 12 deletions(-)
 create mode 100755 tools/hv/hv_get_dhcp_info.sh
 create mode 100755 tools/hv/hv_get_dns_info.sh
 create mode 100755 tools/hv/hv_set_ifconfig.sh
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH v4 1/10 Tools: hv: Get rid of some unused variables

Get rid of unused variables.

---
 tools/hv/hv_kvp_daemon.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
tools/hv/hv_kvp_daemon.c +1 -2
index 65d54c8..d12d714 100644
@@ -196,7 +196,7 @@ static void kvp_update_mem_state(int pool)
 }
 static int kvp_file_init(void)
 {
-	int ret, fd;
+	int  fd;
 	FILE *filep;
 	size_t records_read;
 	__u8 *fname;
@@ -312,7 +312,6 @@ static int kvp_key_add_or_modify(int pool, __u8 *key, int key_size, __u8 *value,
 			int value_size)
 {
 	int i;
-	int j, k;
 	int num_records;
 	struct kvp_record *record;
 	int num_blocks;
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH v4 2/10 Tools: hv: Correctly type string variables

Correctly type character strings.

---
 tools/hv/hv_kvp_daemon.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
tools/hv/hv_kvp_daemon.c +4 -4
index d12d714..026bf0e 100644
@@ -86,8 +86,8 @@ static struct utsname uts_buf;
 #define ENTRIES_PER_BLOCK 50
 
 struct kvp_record {
-	__u8 key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
-	__u8 value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
+	char key[HV_KVP_EXCHANGE_MAX_KEY_SIZE];
+	char value[HV_KVP_EXCHANGE_MAX_VALUE_SIZE];
 };
 
 struct kvp_file_state {
@@ -95,7 +95,7 @@ struct kvp_file_state {
 	int num_blocks;
 	struct kvp_record *records;
 	int num_records;
-	__u8 fname[MAX_FILE_NAME];
+	char fname[MAX_FILE_NAME];
 };
 
 static struct kvp_file_state kvp_file_info[KVP_POOL_COUNT];
@@ -199,7 +199,7 @@ static int kvp_file_init(void)
 	int  fd;
 	FILE *filep;
 	size_t records_read;
-	__u8 *fname;
+	char *fname;
 	struct kvp_record *record;
 	struct kvp_record *readp;
 	int num_blocks;
Signature · 1 line
1.7.4.1
#3 lore raw

PATCH v4 3/10 Tools: hv: Add an example script to retrieve DNS entries

In reply to K. Y. Srinivasan

To keep the KVP daemon code free of distro specific details, we invoke an external script to retrieve the DNS entries. This is an example script that was used to test the KVP code. This script has to be implemented in a Distro specific fashion. For instance on distros that ship with Network Manager enabled, this script can be based on NM APIs.

---
 tools/hv/hv_get_dns_info.sh |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
 create mode 100755 tools/hv/hv_get_dns_info.sh
tools/hv/hv_get_dns_info.sh new file +13 -0
new file mode 100755
index 0000000..058c17b
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+# This example script parses /etc/resolv.conf to retrive DNS information.
+# In the interest of keeping the KVP daemon code free of distro specific
+# information; the kvp daemon code invokes this external script to gather
+# DNS information.
+# This script is expected to print the nameserver values to stdout.
+# Each Distro is expected to implement this script in a distro specific
+# fashion. For instance on Distros that ship with Network Manager enabled,
+# this script can be based on the Network Manager APIs for retrieving DNS
+# entries.
+
+cat /etc/resolv.conf 2>/dev/null | awk '/^nameserver/ { print $2 }'
Signature · 1 line
1.7.4.1
#4 lore raw

PATCH v4 4/10 Tools: hv: Gather DNS information

In reply to K. Y. Srinivasan

Now, gather DNS information. Invoke an external script (that can be distro dependent) to gather the DNS information.

---
 tools/hv/hv_kvp_daemon.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
tools/hv/hv_kvp_daemon.c +23 -0
index 026bf0e..cfa23a1 100644
@@ -549,6 +549,29 @@ static void kvp_get_ipconfig_info(char *if_name,
 	kvp_process_ipconfig_file(cmd, (char *)buffer->gate_way,
 				(MAX_GATEWAY_SIZE * 2), INET6_ADDRSTRLEN, 1);
 
+
+	/*
+	 * Gather the DNS  state.
+	 * Since there is no standard way to get this information
+	 * across various distributions of interest; we just invoke
+	 * an external script that needs to be ported across distros
+	 * of interest.
+	 *
+	 * Following is the expected format of the information from the script:
+	 *
+	 * ipaddr1 (nameserver1)
+	 * ipaddr2 (nameserver2)
+	 * .
+	 * .
+	 */
+
+	sprintf(cmd, "%s",  "hv_get_dns_info");
+
+	/*
+	 * Execute the command to gather DNS info.
+	 */
+	kvp_process_ipconfig_file(cmd, (char *)buffer->dns_addr,
+				(MAX_IP_ADDR_SIZE * 2), INET_ADDRSTRLEN, 0);
 }
 
 
Signature · 1 line
1.7.4.1
#5 lore raw

PATCH v4 5/10 Tools: hv: Add an example script to retrieve dhcp state

In reply to K. Y. Srinivasan

To keep the KVP daemon code free of distro specific details, we invoke an external script to retrieve the DHCP state. This is an example script that was used to test the KVP code. This script has to be implemented in a Distro specific fashion. For instance on distros that ship with Network Manager enabled, this script can be based on NM APIs.

---
 tools/hv/hv_get_dhcp_info.sh |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
 create mode 100755 tools/hv/hv_get_dhcp_info.sh
tools/hv/hv_get_dhcp_info.sh new file +25 -0
new file mode 100755
index 0000000..3de4587
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# This example script retrieves the DHCP state of a given interface.
+# In the interest of keeping the KVP daemon code free of distro specific
+# information; the kvp daemon code invokes this external script to gather
+# DHCP setting for the specific interface.
+#
+# Input: Name of the interface
+#
+# Output: The script prints the string "Enabled" to stdout to indicate
+#	that DHCP is enabled on the interface.
+#
+# Each Distro is expected to implement this script in a distro specific
+# fashion. For instance on Distros that ship with Network Manager enabled,
+# this script can be based on the Network Manager APIs for retrieving DHCP
+# information.
+
+if_file="/etc/sysconfig/network-scripts/ifcfg-"$1
+
+dhcp=$(grep "dhcp" $if_file 2>/dev/null)
+
+if [ "$dhcp" != "" ];
+then
+echo "Enabled"
+fi
Signature · 1 line
1.7.4.1
#6 lore raw

Re: [PATCH V4 05/10] Tools: hv: Add an example script to retrieve dhcp state

Quoted 20 lines · K. Y. Srinivasan

To keep the KVP daemon code free of distro specific details, we invoke an external script to retrieve the DHCP state. This is an example script that was used to test the KVP code. This script has to be implemented in a Distro specific fashion. For instance on distros that ship with Network Manager enabled, this script can be based on NM APIs.

---
 tools/hv/hv_get_dhcp_info.sh |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
 create mode 100755 tools/hv/hv_get_dhcp_info.sh
tools/hv/hv_get_dhcp_info.sh new file +1 -0
new file mode 100755
index 0000000..3de4587
@@ -0,0 +1,25 @@
+#!/bin/bash

tools/hv/hv_get_dhcp_info.sh line 11

Quoted 10 lines
tools/hv/hv_get_dhcp_info.sh new file +10 -0
+
+# This example script retrieves the DHCP state of a given interface.
+# In the interest of keeping the KVP daemon code free of distro specific
+# information; the kvp daemon code invokes this external script to gather
+# DHCP setting for the specific interface.
+#
+# Input: Name of the interface
+#
+# Output: The script prints the string "Enabled" to stdout to indicate
+#	that DHCP is enabled on the interface.

What happens if DHCP is not enabled on the interface? Shouldn't that also return something other than "success"?

greg k-h

#7 lore raw

RE: [PATCH V4 05/10] Tools: hv: Add an example script to retrieve dhcp state

Quoted 39 lines

-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Tuesday, September 04, 2012 6:59 PM
To: KY Srinivasan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V4 05/10] Tools: hv: Add an example script to retrieve dhcp state

Quoted 4 lines · K. Y. Srinivasan

To keep the KVP daemon code free of distro specific details, we invoke an external script to retrieve the DHCP state. This is an example script that was used to test the KVP code. This script has to be implemented in a Distro specific fashion. For instance on distros that ship with Network Manager

enabled,

Quoted 21 lines

this script can be based on NM APIs.

---
 tools/hv/hv_get_dhcp_info.sh |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
 create mode 100755 tools/hv/hv_get_dhcp_info.sh
tools/hv/hv_get_dhcp_info.sh new file +6 -0
new file mode 100755
index 0000000..3de4587
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# This example script retrieves the DHCP state of a given interface.
+# In the interest of keeping the KVP daemon code free of distro specific
+# information; the kvp daemon code invokes this external script to gather
+# DHCP setting for the specific interface.
Quoted 8 lines

tools/hv/hv_get_dhcp_info.sh line 11

Quoted 5 lines
tools/hv/hv_get_dhcp_info.sh new file +5 -0
+#
+# Input: Name of the interface
+#
+# Output: The script prints the string "Enabled" to stdout to indicate
+#	that DHCP is enabled on the interface.

What happens if DHCP is not enabled on the interface? Shouldn't that also return something other than "success"?

The script is expected to write "Enabled" to stdout to indicate if DHCP is enabled; if this is not the case, implicitly we assume DHCP is not enabled (since this is a binary state).

Regards,

K. Y

#8 lore raw

Re: [PATCH V4 05/10] Tools: hv: Add an example script to retrieve dhcp state

Quoted 48 lines · KY Srinivasan
Quoted 39 lines

-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Tuesday, September 04, 2012 6:59 PM
To: KY Srinivasan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V4 05/10] Tools: hv: Add an example script to retrieve dhcp state

Quoted 4 lines · K. Y. Srinivasan

To keep the KVP daemon code free of distro specific details, we invoke an external script to retrieve the DHCP state. This is an example script that was used to test the KVP code. This script has to be implemented in a Distro specific fashion. For instance on distros that ship with Network Manager

enabled,

Quoted 21 lines

this script can be based on NM APIs.

---
 tools/hv/hv_get_dhcp_info.sh |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
 create mode 100755 tools/hv/hv_get_dhcp_info.sh
tools/hv/hv_get_dhcp_info.sh new file +6 -0
new file mode 100755
index 0000000..3de4587
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# This example script retrieves the DHCP state of a given interface.
+# In the interest of keeping the KVP daemon code free of distro specific
+# information; the kvp daemon code invokes this external script to gather
+# DHCP setting for the specific interface.
Quoted 8 lines

tools/hv/hv_get_dhcp_info.sh line 11

Quoted 5 lines
tools/hv/hv_get_dhcp_info.sh new file +5 -0
+#
+# Input: Name of the interface
+#
+# Output: The script prints the string "Enabled" to stdout to indicate
+#	that DHCP is enabled on the interface.

What happens if DHCP is not enabled on the interface? Shouldn't that also return something other than "success"?

Quoted 2 lines

The script is expected to write "Enabled" to stdout to indicate if DHCP is enabled; if this is not the case, implicitly we assume DHCP is not enabled (since this is a binary state).

It's not really "binary" given that you are expecting "Enabled" or nothing, right? "Disabled" would make a bit more sense perhaps?

Having a script return "nothing at all" to show the failure of a state doesn't seem the wisest thing, does it?

thanks,

greg k-h

#9 lore raw

RE: [PATCH V4 05/10] Tools: hv: Add an example script to retrieve dhcp state

Quoted 63 lines

-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Tuesday, September 04, 2012 8:04 PM
To: KY Srinivasan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V4 05/10] Tools: hv: Add an example script to retrieve dhcp state

Quoted 7 lines · KY Srinivasan
Quoted 7 lines

-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Tuesday, September 04, 2012 6:59 PM
To: KY Srinivasan
Cc: [email protected]; [email protected];

[email protected];

Quoted 3 lines
Quoted 3 lines

[email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V4 05/10] Tools: hv: Add an example script to retrieve

dhcp

Quoted 38 lines
Quoted 37 lines

state

Quoted 4 lines · K. Y. Srinivasan

To keep the KVP daemon code free of distro specific details, we invoke an external script to retrieve the DHCP state. This is an example script that was used to test the KVP code. This script has to be implemented in a Distro specific fashion. For instance on distros that ship with Network Manager

enabled,

Quoted 16 lines

this script can be based on NM APIs.

---
 tools/hv/hv_get_dhcp_info.sh |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
 create mode 100755 tools/hv/hv_get_dhcp_info.sh
tools/hv/hv_get_dhcp_info.sh new file +1 -0
new file mode 100755
index 0000000..3de4587
@@ -0,0 +1,25 @@
+#!/bin/bash

tools/hv/hv_get_dhcp_info.sh line 11

Quoted 10 lines
tools/hv/hv_get_dhcp_info.sh new file +10 -0
+
+# This example script retrieves the DHCP state of a given interface.
+# In the interest of keeping the KVP daemon code free of distro specific
+# information; the kvp daemon code invokes this external script to gather
+# DHCP setting for the specific interface.
+#
+# Input: Name of the interface
+#
+# Output: The script prints the string "Enabled" to stdout to indicate
+#	that DHCP is enabled on the interface.

What happens if DHCP is not enabled on the interface? Shouldn't that also return something other than "success"?

Quoted 7 lines
Quoted 1 line

The script is expected to write "Enabled" to stdout to indicate if DHCP is

enabled; if this

Quoted 1 line

is not the case, implicitly we assume DHCP is not enabled (since this is a binary

state).

It's not really "binary" given that you are expecting "Enabled" or nothing, right? "Disabled" would make a bit more sense perhaps?

In the KVP daemon code, I currently only check for "Enabled" to see if DHCP is enabled.

Quoted 3 lines

Having a script return "nothing at all" to show the failure of a state doesn't seem the wisest thing, does it?

I can certainly resubmit this patch with the change you are suggesting. This patch adds a new file and does not impact any of the other patches that follows this. Would you want me to resubmit all of the remaining patches starting with this one.

Regards,

K. Y

#10 lore raw

RE: [PATCH V4 05/10] Tools: hv: Add an example script to retrieve dhcp state

Quoted 91 lines

-----Original Message-----
From: devel [mailto:[email protected]] On Behalf Of KY Srinivasan
Sent: Tuesday, September 04, 2012 8:29 PM
To: Greg KH
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: RE: [PATCH V4 05/10] Tools: hv: Add an example script to retrieve dhcp state

Quoted 18 lines

-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Tuesday, September 04, 2012 8:04 PM
To: KY Srinivasan
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V4 05/10] Tools: hv: Add an example script to retrieve dhcp state

Quoted 7 lines · KY Srinivasan
Quoted 7 lines

-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Tuesday, September 04, 2012 6:59 PM
To: KY Srinivasan
Cc: [email protected]; [email protected];

Quoted 11 lines

[email protected];

Quoted 3 lines
Quoted 3 lines

[email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH V4 05/10] Tools: hv: Add an example script to retrieve

dhcp

Quoted 6 lines
Quoted 6 lines

state

Quoted 3 lines · K. Y. Srinivasan

To keep the KVP daemon code free of distro specific details, we invoke an external script to retrieve the DHCP state. This is an example script that was used to test the KVP code. This script has to be implemented in a

Distro

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

specific fashion. For instance on distros that ship with Network Manager

enabled,

Quoted 2 lines

this script can be based on NM APIs.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Review

Quoted 8 lines
---
 tools/hv/hv_get_dhcp_info.sh |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
 create mode 100755 tools/hv/hv_get_dhcp_info.sh
(quoted diff) +0 -0

b/tools/hv/hv_get_dhcp_info.sh

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

tools/hv/hv_get_dhcp_info.sh line 5

Quoted 10 lines

new file mode 100755
index 0000000..3de4587

tools/hv/hv_get_dhcp_info.sh new file +5 -0
@@ -0,0 +1,25 @@
+#!/bin/bash
+
+# This example script retrieves the DHCP state of a given interface.
+# In the interest of keeping the KVP daemon code free of distro specific
+# information; the kvp daemon code invokes this external script to

gather

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

tools/hv/hv_get_dhcp_info.sh line 11

Quoted 6 lines
tools/hv/hv_get_dhcp_info.sh new file +6 -0
+# DHCP setting for the specific interface.
+#
+# Input: Name of the interface
+#
+# Output: The script prints the string "Enabled" to stdout to indicate
+#	that DHCP is enabled on the interface.

What happens if DHCP is not enabled on the interface? Shouldn't that also return something other than "success"?

Quoted 7 lines
Quoted 1 line

The script is expected to write "Enabled" to stdout to indicate if DHCP is

enabled; if this

Quoted 1 line

is not the case, implicitly we assume DHCP is not enabled (since this is a binary

state).

It's not really "binary" given that you are expecting "Enabled" or nothing, right? "Disabled" would make a bit more sense perhaps?

In the KVP daemon code, I currently only check for "Enabled" to see if DHCP is enabled.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

Having a script return "nothing at all" to show the failure of a state doesn't seem the wisest thing, does it?

I can certainly resubmit this patch with the change you are suggesting. This patch adds a new file
and does not impact any of the other patches that follows this. Would you want me to resubmit all of the
remaining patches starting with this one.

I have resent this patch with the change you have suggested. Since this patch is a standalone patch I have not resent the other patches that follow this patch. Let me know if you want me to resend the remaining patches.

Regards,

K. Y

Quoted 6 lines

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/devel

#11 lore raw

Re: [PATCH V4 05/10] Tools: hv: Add an example script to retrieve dhcp state

Quoted 9 lines · KY Srinivasan
Quoted 5 lines

I can certainly resubmit this patch with the change you are suggesting. This patch adds a new file
and does not impact any of the other patches that follows this. Would you want me to resubmit all of the
remaining patches starting with this one.

I have resent this patch with the change you have suggested. Since this patch is a standalone patch I have not resent the other patches that follow this patch. Let me know if you want me to resend the remaining patches.

Please resend all of them, I no longer have them in my to-apply queue.

greg k-h

#12 lore raw

PATCH v4 6/10 Tools: hv: Gather DHCP information

In reply to K. Y. Srinivasan

Collect information on dhcp setting for the specified interface. We invoke an external (Distro specific) script to get this information.

---
 tools/hv/hv_kvp_daemon.c |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)
tools/hv/hv_kvp_daemon.c +31 -0
index cfa23a1..6fb2c1c 100644
@@ -524,6 +524,9 @@ static void kvp_get_ipconfig_info(char *if_name,
 				 struct hv_kvp_ipaddr_value *buffer)
 {
 	char cmd[512];
+	char dhcp_info[128];
+	char *p;
+	FILE *file;
 
 	/*
 	 * Get the address of default gateway (ipv4).
@@ -572,6 +575,34 @@ static void kvp_get_ipconfig_info(char *if_name,
 	 */
 	kvp_process_ipconfig_file(cmd, (char *)buffer->dns_addr,
 				(MAX_IP_ADDR_SIZE * 2), INET_ADDRSTRLEN, 0);
+
+	/*
+	 * Gather the DHCP state.
+	 * We will gather this state by invoking an external script.
+	 * The parameter to the script is the interface name.
+	 * Here is the expected output:
+	 *
+	 * Enabled: DHCP enabled.
+	 */
+
+	sprintf(cmd, "%s %s", "hv_get_dhcp_info", if_name);
+
+	file = popen(cmd, "r");
+	if (file == NULL)
+		return;
+
+	p = fgets(dhcp_info, sizeof(dhcp_info), file);
+	if (p == NULL) {
+		pclose(file);
+		return;
+	}
+
+	if (!strncmp(p, "Enabled", 7))
+		buffer->dhcp_enabled = 1;
+	else
+		buffer->dhcp_enabled = 0;
+
+	pclose(file);
 }
 
 
Signature · 1 line
1.7.4.1
#13 lore raw

PATCH v4 7/10 Tools: hv: Add an example script to configure an interface

In reply to K. Y. Srinivasan

To keep the KVP daemon code free of distro specific details, we invoke an external script to configure the interface. This is an example script that was used to test the KVP code. This script has to be implemented in a Distro specific fashion. For instance on distros that ship with Network Manager enabled, this script can be based on NM APIs.

---
 tools/hv/hv_set_ifconfig.sh |   68 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 68 insertions(+), 0 deletions(-)
 create mode 100755 tools/hv/hv_set_ifconfig.sh
tools/hv/hv_set_ifconfig.sh new file +68 -0
new file mode 100755
index 0000000..3e9427e
@@ -0,0 +1,68 @@
+#!/bin/bash
+
+# This example script activates an interface based on the specified
+# configuration.
+#
+# In the interest of keeping the KVP daemon code free of distro specific
+# information; the kvp daemon code invokes this external script to configure
+# the interface.
+#
+# The only argument to this script is the configuration file that is to
+# be used to configure the interface.
+#
+# Each Distro is expected to implement this script in a distro specific
+# fashion. For instance on Distros that ship with Network Manager enabled,
+# this script can be based on the Network Manager APIs for configuring the
+# interface.
+#
+# This example script is based on a RHEL environment.
+#
+# Here is the format of the ip configuration file:
+#
+# HWADDR=macaddr
+# IF_NAME=interface name
+# DHCP=yes (This is optional; if yes, DHCP is configured)
+#
+# IPADDR=ipaddr1
+# IPADDR_1=ipaddr2
+# IPADDR_x=ipaddry (where y = x + 1)
+#
+# NETMASK=netmask1
+# NETMASK_x=netmasky (where y = x + 1)
+#
+# GATEWAY=ipaddr1
+# GATEWAY_x=ipaddry (where y = x + 1)
+#
+# DNSx=ipaddrx (where first DNS address is tagged as DNS1 etc)
+#
+# IPV6 addresses will be tagged as IPV6ADDR, IPV6 gateway will be
+# tagged as IPV6_DEFAULTGW and IPV6 NETMASK will be tagged as
+# IPV6NETMASK.
+#
+# The host can specify multiple ipv4 and ipv6 addresses to be
+# configured for the interface. Furthermore, the configuration
+# needs to be persistent. A subsequent GET call on the interface
+# is expected to return the configuration that is set via the SET
+# call.
+#
+
+
+
+echo "IPV6INIT=yes" >> $1
+echo "NM_CONTROLLED=no" >> $1
+echo "PEERDNS=yes" >> $1
+echo "ONBOOT=yes" >> $1
+
+dhcp=$(grep "DHCP" $1 2>/dev/null)
+if [ "$dhcp" != "" ];
+then
+echo "BOOTPROTO=dhcp" >> $1;
+fi
+
+cp $1 /etc/sysconfig/network-scripts/
+
+
+interface=$(echo $1 | awk -F - '{ print $2 }')
+
+/sbin/ifdown $interface 2>/dev/null
+/sbin/ifup $interfac 2>/dev/null
Signature · 1 line
1.7.4.1
#14 lore raw

PATCH v4 8/10 Tools: hv: Implement the KVP verb - KVP_OP_SET_IP_INFO

In reply to K. Y. Srinivasan

Implement the KVP verb - KVP_OP_SET_IP_INFO. This operation configures the specified interface based on the given configuration. Since configuring an interface is very distro specific, we invoke an external (Distro specific) script to configure the interface.

---
 include/linux/hyperv.h   |    2 +
 tools/hv/hv_kvp_daemon.c |  443 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 445 insertions(+), 0 deletions(-)
include/linux/hyperv.h +2 -0
index 7585d55..e73b852 100644
@@ -191,6 +191,8 @@ enum hv_kvp_exchg_pool {
 #define HV_ERROR_NOT_SUPPORTED		0x80070032
 #define HV_ERROR_MACHINE_LOCKED		0x800704F7
 #define HV_ERROR_DEVICE_NOT_CONNECTED	0x8007048F
+#define HV_INVALIDARG			0x80070057
+#define HV_GUID_NOTFOUND		0x80041002
 
 #define ADDR_FAMILY_NONE	0x00
 #define ADDR_FAMILY_IPV4	0x01
tools/hv/hv_kvp_daemon.c +443 -0

491 lines not on this page · raw message

Signature · 1 line
1.7.4.1
#15 lore raw

PATCH v4 9/10 Tools: hv: Rename the function kvp_get_ip_address()

In reply to K. Y. Srinivasan

Rename the function kvp_get_ip_address() to better reflect the functionality being implemented.

---
 tools/hv/hv_kvp_daemon.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
tools/hv/hv_kvp_daemon.c +3 -3
index ac144b9..849c438 100644
@@ -765,7 +765,7 @@ static int kvp_process_ip_address(void *addrp,
 }
 
 static int
-kvp_get_ip_address(int family, char *if_name, int op,
+kvp_get_ip_info(int family, char *if_name, int op,
 		 void  *out_buffer, int length)
 {
 	struct ifaddrs *ifap;
@@ -1468,12 +1468,12 @@ int main(void)
 			strcpy(key_value, lic_version);
 			break;
 		case NetworkAddressIPv4:
-			kvp_get_ip_address(AF_INET, NULL, KVP_OP_ENUMERATE,
+			kvp_get_ip_info(AF_INET, NULL, KVP_OP_ENUMERATE,
 				key_value, HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
 			strcpy(key_name, "NetworkAddressIPv4");
 			break;
 		case NetworkAddressIPv6:
-			kvp_get_ip_address(AF_INET6, NULL, KVP_OP_ENUMERATE,
+			kvp_get_ip_info(AF_INET6, NULL, KVP_OP_ENUMERATE,
 				key_value, HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
 			strcpy(key_name, "NetworkAddressIPv6");
 			break;
Signature · 1 line
1.7.4.1
#16 lore raw

PATCH v4 10/10 Tools: hv: Implement the KVP verb - KVP_OP_GET_IP_INFO

In reply to K. Y. Srinivasan

Now implement the KVP verb - KVP_OP_GET_IP_INFO. This operation retrieves IP information for the specified interface.

---
 tools/hv/hv_kvp_daemon.c |   93 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 90 insertions(+), 3 deletions(-)
tools/hv/hv_kvp_daemon.c +90 -3
index 849c438..c8e1013 100644
@@ -603,6 +603,69 @@ static char *kvp_if_name_to_mac(char *if_name)
 }
 
 
+/*
+ * Retrieve the interface name given tha MAC address.
+ */
+
+static char *kvp_mac_to_if_name(char *mac)
+{
+	DIR *dir;
+	struct dirent *entry;
+	FILE    *file;
+	char    *p, *q, *x;
+	char    *if_name = NULL;
+	char    buf[256];
+	char *kvp_net_dir = "/sys/class/net/";
+	char dev_id[256];
+	int i;
+
+	dir = opendir(kvp_net_dir);
+	if (dir == NULL)
+		return NULL;
+
+	snprintf(dev_id, sizeof(dev_id), kvp_net_dir);
+	q = dev_id + strlen(kvp_net_dir);
+
+	while ((entry = readdir(dir)) != NULL) {
+		/*
+		 * Set the state for the next pass.
+		 */
+		*q = '\0';
+
+		strcat(dev_id, entry->d_name);
+		strcat(dev_id, "/address");
+
+		file = fopen(dev_id, "r");
+		if (file == NULL)
+			continue;
+
+		p = fgets(buf, sizeof(buf), file);
+		if (p) {
+			x = strchr(p, '\n');
+			if (x)
+				*x = '\0';
+
+			for (i = 0; i < strlen(p); i++)
+				p[i] = toupper(p[i]);
+
+			if (!strcmp(p, mac)) {
+				/*
+				 * Found the MAC match; return the interface
+				 * name. The caller will free the memory.
+				 */
+				if_name = strdup(entry->d_name);
+				fclose(file);
+				break;
+			}
+		}
+		fclose(file);
+	}
+
+	closedir(dir);
+	return if_name;
+}
+
+
 static void kvp_process_ipconfig_file(char *cmd,
 					char *config_buf, int len,
 					int element_size, int offset)
@@ -749,10 +812,10 @@ static int kvp_process_ip_address(void *addrp,
 	}
 
 	if ((length - *offset) < addr_length + 1)
-		return 1;
+		return HV_E_FAIL;
 	if (str == NULL) {
 		strcpy(buffer, "inet_ntop failed\n");
-		return 1;
+		return HV_E_FAIL;
 	}
 	if (*offset == 0)
 		strcpy(buffer, tmp);
@@ -796,7 +859,7 @@ kvp_get_ip_info(int family, char *if_name, int op,
 
 	if (getifaddrs(&ifap)) {
 		strcpy(buffer, "getifaddrs failed\n");
-		return 1;
+		return HV_E_FAIL;
 	}
 
 	curp = ifap;
@@ -1386,6 +1449,30 @@ int main(void)
 		}
 
 		switch (op) {
+		case KVP_OP_GET_IP_INFO:
+			kvp_ip_val = &hv_msg->body.kvp_ip_val;
+			if_name =
+			kvp_mac_to_if_name((char *)kvp_ip_val->adapter_id);
+
+			if (if_name == NULL) {
+				/*
+				 * We could not map the mac address to an
+				 * interface name; return error.
+				 */
+				hv_msg->error = HV_E_FAIL;
+				break;
+			}
+			error = kvp_get_ip_info(
+						0, if_name, KVP_OP_GET_IP_INFO,
+						kvp_ip_val,
+						(MAX_IP_ADDR_SIZE * 2));
+
+			if (error)
+				hv_msg->error = error;
+
+			free(if_name);
+			break;
+
 		case KVP_OP_SET_IP_INFO:
 			kvp_ip_val = &hv_msg->body.kvp_ip_val;
 			if_name = kvp_get_if_name(
Signature · 1 line
1.7.4.1