aboutsummaryrefslogtreecommitdiffstats
path: root/tools/hv
diff options
context:
space:
mode:
authorOlaf Hering <olaf@aepfle.de>2013-08-01 08:34:26 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-08-01 23:44:18 -0400
commitb4919a5f95c09992f66d4b7cbe392c33731a5cec (patch)
tree2e5cece4cb4167d5e99e804cd10c54601ac3a1d0 /tools/hv
parentcfc25993e81f3fa68481d062be634d33184d5eae (diff)
Tools: hv: fix send/recv buffer allocation
hv_kvp_daemon fails to start in current openSuSE 13.1 snapshots because the kvp_send_buffer is too small to hold cn_msg+hv_kvp_msg, the very first sendmsg returns with EFAULT. In addition it fixes the Network info tab in Windows Server 2012R2 in SLES11. Adjust the code in kvp and vss daemon to allocate the needed buffers at runtime. To keep the code simple, the buffer_len includes also the nlmsghdr, although only the recv_buffer needs this extra space. Signed-off-by: Olaf Hering <olaf@aepfle.de> Signed-off-by: K. Y. Srinivasan <kys@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'tools/hv')
-rw-r--r--tools/hv/hv_kvp_daemon.c15
-rw-r--r--tools/hv/hv_vss_daemon.c15
2 files changed, 24 insertions, 6 deletions
diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 07819bfa7dba..657c1d27e02e 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -79,8 +79,6 @@ enum {
79 DNS 79 DNS
80}; 80};
81 81
82static char kvp_send_buffer[4096];
83static char kvp_recv_buffer[4096 * 2];
84static struct sockaddr_nl addr; 82static struct sockaddr_nl addr;
85static int in_hand_shake = 1; 83static int in_hand_shake = 1;
86 84
@@ -1437,10 +1435,21 @@ int main(void)
1437 int pool; 1435 int pool;
1438 char *if_name; 1436 char *if_name;
1439 struct hv_kvp_ipaddr_value *kvp_ip_val; 1437 struct hv_kvp_ipaddr_value *kvp_ip_val;
1438 char *kvp_send_buffer;
1439 char *kvp_recv_buffer;
1440 size_t kvp_recv_buffer_len;
1440 1441
1441 daemon(1, 0); 1442 daemon(1, 0);
1442 openlog("KVP", 0, LOG_USER); 1443 openlog("KVP", 0, LOG_USER);
1443 syslog(LOG_INFO, "KVP starting; pid is:%d", getpid()); 1444 syslog(LOG_INFO, "KVP starting; pid is:%d", getpid());
1445
1446 kvp_recv_buffer_len = NLMSG_HDRLEN + sizeof(struct cn_msg) + sizeof(struct hv_kvp_msg);
1447 kvp_send_buffer = calloc(1, kvp_recv_buffer_len);
1448 kvp_recv_buffer = calloc(1, kvp_recv_buffer_len);
1449 if (!(kvp_send_buffer && kvp_recv_buffer)) {
1450 syslog(LOG_ERR, "Failed to allocate netlink buffers");
1451 exit(EXIT_FAILURE);
1452 }
1444 /* 1453 /*
1445 * Retrieve OS release information. 1454 * Retrieve OS release information.
1446 */ 1455 */
@@ -1514,7 +1523,7 @@ int main(void)
1514 continue; 1523 continue;
1515 } 1524 }
1516 1525
1517 len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0, 1526 len = recvfrom(fd, kvp_recv_buffer, kvp_recv_buffer_len, 0,
1518 addr_p, &addr_l); 1527 addr_p, &addr_l);
1519 1528
1520 if (len < 0) { 1529 if (len < 0) {
diff --git a/tools/hv/hv_vss_daemon.c b/tools/hv/hv_vss_daemon.c
index 826d499dc354..4213d0e3083f 100644
--- a/tools/hv/hv_vss_daemon.c
+++ b/tools/hv/hv_vss_daemon.c
@@ -38,8 +38,6 @@
38#include <linux/netlink.h> 38#include <linux/netlink.h>
39#include <syslog.h> 39#include <syslog.h>
40 40
41static char vss_recv_buffer[4096];
42static char vss_send_buffer[4096];
43static struct sockaddr_nl addr; 41static struct sockaddr_nl addr;
44 42
45#ifndef SOL_NETLINK 43#ifndef SOL_NETLINK
@@ -147,6 +145,9 @@ int main(void)
147 struct cn_msg *incoming_cn_msg; 145 struct cn_msg *incoming_cn_msg;
148 int op; 146 int op;
149 struct hv_vss_msg *vss_msg; 147 struct hv_vss_msg *vss_msg;
148 char *vss_send_buffer;
149 char *vss_recv_buffer;
150 size_t vss_recv_buffer_len;
150 151
151 if (daemon(1, 0)) 152 if (daemon(1, 0))
152 return 1; 153 return 1;
@@ -154,6 +155,14 @@ int main(void)
154 openlog("Hyper-V VSS", 0, LOG_USER); 155 openlog("Hyper-V VSS", 0, LOG_USER);
155 syslog(LOG_INFO, "VSS starting; pid is:%d", getpid()); 156 syslog(LOG_INFO, "VSS starting; pid is:%d", getpid());
156 157
158 vss_recv_buffer_len = NLMSG_HDRLEN + sizeof(struct cn_msg) + sizeof(struct hv_vss_msg);
159 vss_send_buffer = calloc(1, vss_recv_buffer_len);
160 vss_recv_buffer = calloc(1, vss_recv_buffer_len);
161 if (!(vss_send_buffer && vss_recv_buffer)) {
162 syslog(LOG_ERR, "Failed to allocate netlink buffers");
163 exit(EXIT_FAILURE);
164 }
165
157 fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR); 166 fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR);
158 if (fd < 0) { 167 if (fd < 0) {
159 syslog(LOG_ERR, "netlink socket creation failed; error:%d %s", 168 syslog(LOG_ERR, "netlink socket creation failed; error:%d %s",
@@ -215,7 +224,7 @@ int main(void)
215 continue; 224 continue;
216 } 225 }
217 226
218 len = recvfrom(fd, vss_recv_buffer, sizeof(vss_recv_buffer), 0, 227 len = recvfrom(fd, vss_recv_buffer, vss_recv_buffer_len, 0,
219 addr_p, &addr_l); 228 addr_p, &addr_l);
220 229
221 if (len < 0) { 230 if (len < 0) {