- use full nlmsghdr in netlink_send

- correct payload size in netlink_send
- use single send+recv buffer
- log errors to syslog in kvp_set_ip_info
- check return value of system in hv_kvp_daemon
- in kvp_set_ip_info free mac_addr right after usage
- check return value of daemon to fix compiler warning.

OBS-URL: https://build.opensuse.org/package/show/Virtualization/hyper-v?expand=0&rev=66
This commit is contained in:
Olaf Hering 2013-08-07 13:55:15 +00:00 committed by Git OBS Bridge
parent d22cc8ce10
commit 18c1b296af
3 changed files with 40 additions and 38 deletions

View File

@ -1,3 +1,14 @@
-------------------------------------------------------------------
Wed Aug 7 15:54:19 CEST 2013 - ohering@suse.de
- use full nlmsghdr in netlink_send
- correct payload size in netlink_send
- use single send+recv buffer
- log errors to syslog in kvp_set_ip_info
- check return value of system in hv_kvp_daemon
- in kvp_set_ip_info free mac_addr right after usage
- check return value of daemon to fix compiler warning.
-------------------------------------------------------------------
Thu Aug 1 14:21:57 CEST 2013 - ohering@suse.de

View File

@ -1299,6 +1299,7 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)
}
error = kvp_write_file(file, "HWADDR", "", mac_addr);
free(mac_addr);
if (error)
goto setval_error;
@ -1344,7 +1345,6 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)
goto setval_error;
setval_done:
free(mac_addr);
fclose(file);
/*
@ -1353,12 +1353,16 @@ setval_done:
*/
snprintf(cmd, sizeof(cmd), "%s %s", "hv_set_ifconfig", if_file);
system(cmd);
if (system(cmd)) {
syslog(LOG_ERR, "Failed to execute cmd '%s'; error: %d %s",
cmd, errno, strerror(errno));
return HV_E_FAIL;
}
return 0;
setval_error:
syslog(LOG_ERR, "Failed to write config file");
free(mac_addr);
syslog(LOG_ERR, "Failed to write config file. error: %d %s",
errno, strerror(errno));
fclose(file);
return error;
}
@ -1389,23 +1393,18 @@ kvp_get_domain_name(char *buffer, int length)
static int
netlink_send(int fd, struct cn_msg *msg)
{
struct nlmsghdr *nlh;
struct nlmsghdr nlh = { .nlmsg_type = NLMSG_DONE };
unsigned int size;
struct msghdr message;
char buffer[64];
struct iovec iov[2];
size = NLMSG_SPACE(sizeof(struct cn_msg) + msg->len);
size = sizeof(struct cn_msg) + msg->len;
nlh = (struct nlmsghdr *)buffer;
nlh->nlmsg_seq = 0;
nlh->nlmsg_pid = getpid();
nlh->nlmsg_type = NLMSG_DONE;
nlh->nlmsg_len = NLMSG_LENGTH(size - sizeof(*nlh));
nlh->nlmsg_flags = 0;
nlh.nlmsg_pid = getpid();
nlh.nlmsg_len = NLMSG_LENGTH(size);
iov[0].iov_base = nlh;
iov[0].iov_len = sizeof(*nlh);
iov[0].iov_base = &nlh;
iov[0].iov_len = sizeof(nlh);
iov[1].iov_base = msg;
iov[1].iov_len = size;
@ -1435,19 +1434,18 @@ int main(void)
int pool;
char *if_name;
struct hv_kvp_ipaddr_value *kvp_ip_val;
char *kvp_send_buffer;
char *kvp_recv_buffer;
size_t kvp_recv_buffer_len;
daemon(1, 0);
if (daemon(1, 0))
return 1;
openlog("KVP", 0, LOG_USER);
syslog(LOG_INFO, "KVP starting; pid is:%d", getpid());
kvp_recv_buffer_len = NLMSG_HDRLEN + sizeof(struct cn_msg) + sizeof(struct hv_kvp_msg);
kvp_send_buffer = calloc(1, kvp_recv_buffer_len);
kvp_recv_buffer_len = NLMSG_LENGTH(0) + sizeof(struct cn_msg) + sizeof(struct hv_kvp_msg);
kvp_recv_buffer = calloc(1, kvp_recv_buffer_len);
if (!(kvp_send_buffer && kvp_recv_buffer)) {
syslog(LOG_ERR, "Failed to allocate netlink buffers");
if (!kvp_recv_buffer) {
syslog(LOG_ERR, "Failed to allocate netlink buffer");
exit(EXIT_FAILURE);
}
/*
@ -1489,7 +1487,7 @@ int main(void)
/*
* Register ourselves with the kernel.
*/
message = (struct cn_msg *)kvp_send_buffer;
message = (struct cn_msg *)kvp_recv_buffer;
message->id.idx = CN_KVP_IDX;
message->id.val = CN_KVP_VAL;

View File

@ -105,23 +105,18 @@ static int vss_operate(int operation)
static int netlink_send(int fd, struct cn_msg *msg)
{
struct nlmsghdr *nlh;
struct nlmsghdr nlh = { .nlmsg_type = NLMSG_DONE };
unsigned int size;
struct msghdr message;
char buffer[64];
struct iovec iov[2];
size = NLMSG_SPACE(sizeof(struct cn_msg) + msg->len);
size = sizeof(struct cn_msg) + msg->len;
nlh = (struct nlmsghdr *)buffer;
nlh->nlmsg_seq = 0;
nlh->nlmsg_pid = getpid();
nlh->nlmsg_type = NLMSG_DONE;
nlh->nlmsg_len = NLMSG_LENGTH(size - sizeof(*nlh));
nlh->nlmsg_flags = 0;
nlh.nlmsg_pid = getpid();
nlh.nlmsg_len = NLMSG_LENGTH(size);
iov[0].iov_base = nlh;
iov[0].iov_len = sizeof(*nlh);
iov[0].iov_base = &nlh;
iov[0].iov_len = sizeof(nlh);
iov[1].iov_base = msg;
iov[1].iov_len = size;
@ -145,7 +140,6 @@ int main(void)
struct cn_msg *incoming_cn_msg;
int op;
struct hv_vss_msg *vss_msg;
char *vss_send_buffer;
char *vss_recv_buffer;
size_t vss_recv_buffer_len;
@ -155,10 +149,9 @@ int main(void)
openlog("Hyper-V VSS", 0, LOG_USER);
syslog(LOG_INFO, "VSS starting; pid is:%d", getpid());
vss_recv_buffer_len = NLMSG_HDRLEN + sizeof(struct cn_msg) + sizeof(struct hv_vss_msg);
vss_send_buffer = calloc(1, vss_recv_buffer_len);
vss_recv_buffer_len = NLMSG_LENGTH(0) + sizeof(struct cn_msg) + sizeof(struct hv_vss_msg);
vss_recv_buffer = calloc(1, vss_recv_buffer_len);
if (!(vss_send_buffer && vss_recv_buffer)) {
if (!vss_recv_buffer) {
syslog(LOG_ERR, "Failed to allocate netlink buffers");
exit(EXIT_FAILURE);
}
@ -185,7 +178,7 @@ int main(void)
/*
* Register ourselves with the kernel.
*/
message = (struct cn_msg *)vss_send_buffer;
message = (struct cn_msg *)vss_recv_buffer;
message->id.idx = CN_VSS_IDX;
message->id.val = CN_VSS_VAL;
message->ack = 0;