From d58ac4b8e0e394b98f2936803cbf16657ef7bcdc11c9dcbcc7d218bf770befd3 Mon Sep 17 00:00:00 2001 From: Olaf Hering Date: Mon, 15 Jul 2013 14:17:26 +0000 Subject: [PATCH] - update hv_kvp_daemon (merge 0783d72fa from v3.9-rc1) Fix how ifcfg-* file is created OBS-URL: https://build.opensuse.org/package/show/Virtualization/hyper-v?expand=0&rev=59 --- hyper-v.changes | 6 +++ hyper-v.tools.hv.hv_kvp_daemon.c | 59 ++++++++++++++--------------- hyper-v.tools.hv.hv_set_ifconfig.sh | 41 ++++++++++---------- 3 files changed, 56 insertions(+), 50 deletions(-) diff --git a/hyper-v.changes b/hyper-v.changes index 36bd2d4..104ad6f 100644 --- a/hyper-v.changes +++ b/hyper-v.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Mon Jul 15 16:16:06 CEST 2013 - ohering@suse.de + +- update hv_kvp_daemon (merge 0783d72fa from v3.9-rc1) + Fix how ifcfg-* file is created + ------------------------------------------------------------------- Mon Jul 15 15:24:00 CEST 2013 - ohering@suse.de diff --git a/hyper-v.tools.hv.hv_kvp_daemon.c b/hyper-v.tools.hv.hv_kvp_daemon.c index 2683322..d4fcafa 100644 --- a/hyper-v.tools.hv.hv_kvp_daemon.c +++ b/hyper-v.tools.hv.hv_kvp_daemon.c @@ -1177,16 +1177,13 @@ static int process_ip_string(FILE *f, char *ip_string, int type) snprintf(str, sizeof(str), "%s", "DNS"); break; } - if (i != 0) { - if (type != DNS) { - snprintf(sub_str, sizeof(sub_str), - "_%d", i++); - } else { - snprintf(sub_str, sizeof(sub_str), - "%d", ++i); - } - } else if (type == DNS) { + + if (type == DNS) { snprintf(sub_str, sizeof(sub_str), "%d", ++i); + } else if (type == GATEWAY && i == 0) { + ++i; + } else { + snprintf(sub_str, sizeof(sub_str), "%d", i++); } @@ -1206,17 +1203,13 @@ static int process_ip_string(FILE *f, char *ip_string, int type) snprintf(str, sizeof(str), "%s", "DNS"); break; } - if ((j != 0) || (type == DNS)) { - if (type != DNS) { - snprintf(sub_str, sizeof(sub_str), - "_%d", j++); - } else { - snprintf(sub_str, sizeof(sub_str), - "%d", ++i); - } - } else if (type == DNS) { - snprintf(sub_str, sizeof(sub_str), - "%d", ++i); + + if (type == DNS) { + snprintf(sub_str, sizeof(sub_str), "%d", ++i); + } else if (j == 0) { + ++j; + } else { + snprintf(sub_str, sizeof(sub_str), "_%d", j++); } } else { return HV_INVALIDARG; @@ -1259,18 +1252,19 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val) * 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) + * DEVICE=interface name + * BOOTPROTO= (where is "dhcp" if DHCP is configured + * or "none" if no boot-time protocol should be used) * - * IPADDR=ipaddr1 - * IPADDR_1=ipaddr2 - * IPADDR_x=ipaddry (where y = x + 1) + * IPADDR0=ipaddr1 + * IPADDR1=ipaddr2 + * IPADDRx=ipaddry (where y = x + 1) * - * NETMASK=netmask1 - * NETMASK_x=netmasky (where y = x + 1) + * NETMASK0=netmask1 + * NETMASKx=netmasky (where y = x + 1) * * GATEWAY=ipaddr1 - * GATEWAY_x=ipaddry (where y = x + 1) + * GATEWAYx=ipaddry (where y = x + 1) * * DNSx=ipaddrx (where first DNS address is tagged as DNS1 etc) * @@ -1310,12 +1304,12 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val) if (error) goto setval_error; - error = kvp_write_file(file, "IF_NAME", "", if_name); + error = kvp_write_file(file, "DEVICE", "", if_name); if (error) goto setval_error; if (new_val->dhcp_enabled) { - error = kvp_write_file(file, "DHCP", "", "yes"); + error = kvp_write_file(file, "BOOTPROTO", "", "dhcp"); if (error) goto setval_error; @@ -1323,6 +1317,11 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val) * We are done!. */ goto setval_done; + + } else { + error = kvp_write_file(file, "BOOTPROTO", "", "none"); + if (error) + goto setval_error; } /* diff --git a/hyper-v.tools.hv.hv_set_ifconfig.sh b/hyper-v.tools.hv.hv_set_ifconfig.sh index a776d43..695652f 100644 --- a/hyper-v.tools.hv.hv_set_ifconfig.sh +++ b/hyper-v.tools.hv.hv_set_ifconfig.sh @@ -10,18 +10,19 @@ # 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) +# DEVICE=interface name +# BOOTPROTO= (where is "dhcp" if DHCP is configured +# or "none" if no boot-time protocol should be used) # -# IPADDR=ipaddr1 -# IPADDR_1=ipaddr2 -# IPADDR_x=ipaddry (where y = x + 1) +# IPADDR0=ipaddr1 +# IPADDR1=ipaddr2 +# IPADDRx=ipaddry (where y = x + 1) # -# NETMASK=netmask1 -# NETMASK_x=netmasky (where y = x + 1) +# NETMASK0=netmask1 +# NETMASKx=netmasky (where y = x + 1) # # GATEWAY=ipaddr1 -# GATEWAY_x=ipaddry (where y = x + 1) +# GATEWAYx=ipaddry (where y = x + 1) # # DNSx=ipaddrx (where first DNS address is tagged as DNS1 etc) # @@ -53,8 +54,8 @@ else fi # remove known config variables from environment unset HWADDR -unset DHCP -unset IF_NAME +unset BOOTPROTO +unset DEVICE unset ${!IPADDR*} unset ${!NETMASK*} unset ${!GATEWAY*} @@ -64,9 +65,9 @@ unset ${!IPV6_DEFAULTGW*} unset ${!DNS*} . "$1" # -if test -z "${IF_NAME}" +if test -z "${DEVICE}" then - echo "Missing IF_NAME= in ${cfg}" + echo "Missing DEVICE= in ${cfg}" exit 1 fi # @@ -91,7 +92,7 @@ fi : # ignore HWADDR, it just repeats the existing MAC value fi # - if test "${DHCP}" = "yes" + if test "${BOOTPROTO}" = "dhcp" then echo "BOOTPROTO=dhcp" fi @@ -145,11 +146,11 @@ fi ( if test -n "${GATEWAY}" then - echo "default $GATEWAY - $IF_NAME" + echo "default $GATEWAY - $DEVICE" fi if test -n "${IPV6_DEFAULTGW}" then - echo "default $IPV6_DEFAULTGW - $IF_NAME" + echo "default $IPV6_DEFAULTGW - $DEVICE" fi ) >> "${t_ifroute}" # Only a single default gateway is supported @@ -172,14 +173,14 @@ do fi done # -echo "$0: working on network interface ifcfg-${IF_NAME}" -cp -fb ${t_ifcfg} "/etc/sysconfig/network/ifcfg-${IF_NAME}" -cp -fb ${t_ifroute} "/etc/sysconfig/network/ifroute-${IF_NAME}" +echo "$0: working on network interface ifcfg-${DEVICE}" +cp -fb ${t_ifcfg} "/etc/sysconfig/network/ifcfg-${DEVICE}" +cp -fb ${t_ifroute} "/etc/sysconfig/network/ifroute-${DEVICE}" if test -w /etc/sysconfig/network/config then sed -i "s@^NETCONFIG_DNS_STATIC_SERVERS=.*@NETCONFIG_DNS_STATIC_SERVERS='$_DNS_'@" /etc/sysconfig/network/config netconfig update -m dns fi -ifdown "${IF_NAME}" -ifup "${IF_NAME}" +ifdown "${DEVICE}" +ifup "${DEVICE}" ) 2>&1 | logger -t "${0##*/}[$PPID / $$]"