diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/hv/hv_kvp_daemon.c | 79 | ||||
-rwxr-xr-x | tools/hv/hv_set_ifconfig.sh | 24 |
2 files changed, 49 insertions, 54 deletions
diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c index d25a46925e61..c800ea4c8bf9 100644 --- a/tools/hv/hv_kvp_daemon.c +++ b/tools/hv/hv_kvp_daemon.c | |||
@@ -97,7 +97,7 @@ static struct utsname uts_buf; | |||
97 | * The location of the interface configuration file. | 97 | * The location of the interface configuration file. |
98 | */ | 98 | */ |
99 | 99 | ||
100 | #define KVP_CONFIG_LOC "/var/opt/" | 100 | #define KVP_CONFIG_LOC "/var/lib/hyperv" |
101 | 101 | ||
102 | #define MAX_FILE_NAME 100 | 102 | #define MAX_FILE_NAME 100 |
103 | #define ENTRIES_PER_BLOCK 50 | 103 | #define ENTRIES_PER_BLOCK 50 |
@@ -151,7 +151,7 @@ static void kvp_update_file(int pool) | |||
151 | */ | 151 | */ |
152 | kvp_acquire_lock(pool); | 152 | kvp_acquire_lock(pool); |
153 | 153 | ||
154 | filep = fopen(kvp_file_info[pool].fname, "w"); | 154 | filep = fopen(kvp_file_info[pool].fname, "we"); |
155 | if (!filep) { | 155 | if (!filep) { |
156 | kvp_release_lock(pool); | 156 | kvp_release_lock(pool); |
157 | syslog(LOG_ERR, "Failed to open file, pool: %d", pool); | 157 | syslog(LOG_ERR, "Failed to open file, pool: %d", pool); |
@@ -182,7 +182,7 @@ static void kvp_update_mem_state(int pool) | |||
182 | 182 | ||
183 | kvp_acquire_lock(pool); | 183 | kvp_acquire_lock(pool); |
184 | 184 | ||
185 | filep = fopen(kvp_file_info[pool].fname, "r"); | 185 | filep = fopen(kvp_file_info[pool].fname, "re"); |
186 | if (!filep) { | 186 | if (!filep) { |
187 | kvp_release_lock(pool); | 187 | kvp_release_lock(pool); |
188 | syslog(LOG_ERR, "Failed to open file, pool: %d", pool); | 188 | syslog(LOG_ERR, "Failed to open file, pool: %d", pool); |
@@ -234,9 +234,9 @@ static int kvp_file_init(void) | |||
234 | int i; | 234 | int i; |
235 | int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK; | 235 | int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK; |
236 | 236 | ||
237 | if (access("/var/opt/hyperv", F_OK)) { | 237 | if (access(KVP_CONFIG_LOC, F_OK)) { |
238 | if (mkdir("/var/opt/hyperv", S_IRUSR | S_IWUSR | S_IROTH)) { | 238 | if (mkdir(KVP_CONFIG_LOC, 0755 /* rwxr-xr-x */)) { |
239 | syslog(LOG_ERR, " Failed to create /var/opt/hyperv"); | 239 | syslog(LOG_ERR, " Failed to create %s", KVP_CONFIG_LOC); |
240 | exit(EXIT_FAILURE); | 240 | exit(EXIT_FAILURE); |
241 | } | 241 | } |
242 | } | 242 | } |
@@ -245,14 +245,14 @@ static int kvp_file_init(void) | |||
245 | fname = kvp_file_info[i].fname; | 245 | fname = kvp_file_info[i].fname; |
246 | records_read = 0; | 246 | records_read = 0; |
247 | num_blocks = 1; | 247 | num_blocks = 1; |
248 | sprintf(fname, "/var/opt/hyperv/.kvp_pool_%d", i); | 248 | sprintf(fname, "%s/.kvp_pool_%d", KVP_CONFIG_LOC, i); |
249 | fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH); | 249 | fd = open(fname, O_RDWR | O_CREAT | O_CLOEXEC, 0644 /* rw-r--r-- */); |
250 | 250 | ||
251 | if (fd == -1) | 251 | if (fd == -1) |
252 | return 1; | 252 | return 1; |
253 | 253 | ||
254 | 254 | ||
255 | filep = fopen(fname, "r"); | 255 | filep = fopen(fname, "re"); |
256 | if (!filep) | 256 | if (!filep) |
257 | return 1; | 257 | return 1; |
258 | 258 | ||
@@ -1162,16 +1162,13 @@ static int process_ip_string(FILE *f, char *ip_string, int type) | |||
1162 | snprintf(str, sizeof(str), "%s", "DNS"); | 1162 | snprintf(str, sizeof(str), "%s", "DNS"); |
1163 | break; | 1163 | break; |
1164 | } | 1164 | } |
1165 | if (i != 0) { | 1165 | |
1166 | if (type != DNS) { | 1166 | if (type == DNS) { |
1167 | snprintf(sub_str, sizeof(sub_str), | ||
1168 | "_%d", i++); | ||
1169 | } else { | ||
1170 | snprintf(sub_str, sizeof(sub_str), | ||
1171 | "%d", ++i); | ||
1172 | } | ||
1173 | } else if (type == DNS) { | ||
1174 | snprintf(sub_str, sizeof(sub_str), "%d", ++i); | 1167 | snprintf(sub_str, sizeof(sub_str), "%d", ++i); |
1168 | } else if (type == GATEWAY && i == 0) { | ||
1169 | ++i; | ||
1170 | } else { | ||
1171 | snprintf(sub_str, sizeof(sub_str), "%d", i++); | ||
1175 | } | 1172 | } |
1176 | 1173 | ||
1177 | 1174 | ||
@@ -1191,17 +1188,13 @@ static int process_ip_string(FILE *f, char *ip_string, int type) | |||
1191 | snprintf(str, sizeof(str), "%s", "DNS"); | 1188 | snprintf(str, sizeof(str), "%s", "DNS"); |
1192 | break; | 1189 | break; |
1193 | } | 1190 | } |
1194 | if ((j != 0) || (type == DNS)) { | 1191 | |
1195 | if (type != DNS) { | 1192 | if (type == DNS) { |
1196 | snprintf(sub_str, sizeof(sub_str), | 1193 | snprintf(sub_str, sizeof(sub_str), "%d", ++i); |
1197 | "_%d", j++); | 1194 | } else if (j == 0) { |
1198 | } else { | 1195 | ++j; |
1199 | snprintf(sub_str, sizeof(sub_str), | 1196 | } else { |
1200 | "%d", ++i); | 1197 | snprintf(sub_str, sizeof(sub_str), "_%d", j++); |
1201 | } | ||
1202 | } else if (type == DNS) { | ||
1203 | snprintf(sub_str, sizeof(sub_str), | ||
1204 | "%d", ++i); | ||
1205 | } | 1198 | } |
1206 | } else { | 1199 | } else { |
1207 | return HV_INVALIDARG; | 1200 | return HV_INVALIDARG; |
@@ -1244,18 +1237,19 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val) | |||
1244 | * Here is the format of the ip configuration file: | 1237 | * Here is the format of the ip configuration file: |
1245 | * | 1238 | * |
1246 | * HWADDR=macaddr | 1239 | * HWADDR=macaddr |
1247 | * IF_NAME=interface name | 1240 | * DEVICE=interface name |
1248 | * DHCP=yes (This is optional; if yes, DHCP is configured) | 1241 | * BOOTPROTO=<protocol> (where <protocol> is "dhcp" if DHCP is configured |
1242 | * or "none" if no boot-time protocol should be used) | ||
1249 | * | 1243 | * |
1250 | * IPADDR=ipaddr1 | 1244 | * IPADDR0=ipaddr1 |
1251 | * IPADDR_1=ipaddr2 | 1245 | * IPADDR1=ipaddr2 |
1252 | * IPADDR_x=ipaddry (where y = x + 1) | 1246 | * IPADDRx=ipaddry (where y = x + 1) |
1253 | * | 1247 | * |
1254 | * NETMASK=netmask1 | 1248 | * NETMASK0=netmask1 |
1255 | * NETMASK_x=netmasky (where y = x + 1) | 1249 | * NETMASKx=netmasky (where y = x + 1) |
1256 | * | 1250 | * |
1257 | * GATEWAY=ipaddr1 | 1251 | * GATEWAY=ipaddr1 |
1258 | * GATEWAY_x=ipaddry (where y = x + 1) | 1252 | * GATEWAYx=ipaddry (where y = x + 1) |
1259 | * | 1253 | * |
1260 | * DNSx=ipaddrx (where first DNS address is tagged as DNS1 etc) | 1254 | * DNSx=ipaddrx (where first DNS address is tagged as DNS1 etc) |
1261 | * | 1255 | * |
@@ -1271,7 +1265,7 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val) | |||
1271 | */ | 1265 | */ |
1272 | 1266 | ||
1273 | snprintf(if_file, sizeof(if_file), "%s%s%s", KVP_CONFIG_LOC, | 1267 | snprintf(if_file, sizeof(if_file), "%s%s%s", KVP_CONFIG_LOC, |
1274 | "hyperv/ifcfg-", if_name); | 1268 | "/ifcfg-", if_name); |
1275 | 1269 | ||
1276 | file = fopen(if_file, "w"); | 1270 | file = fopen(if_file, "w"); |
1277 | 1271 | ||
@@ -1294,12 +1288,12 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val) | |||
1294 | if (error) | 1288 | if (error) |
1295 | goto setval_error; | 1289 | goto setval_error; |
1296 | 1290 | ||
1297 | error = kvp_write_file(file, "IF_NAME", "", if_name); | 1291 | error = kvp_write_file(file, "DEVICE", "", if_name); |
1298 | if (error) | 1292 | if (error) |
1299 | goto setval_error; | 1293 | goto setval_error; |
1300 | 1294 | ||
1301 | if (new_val->dhcp_enabled) { | 1295 | if (new_val->dhcp_enabled) { |
1302 | error = kvp_write_file(file, "DHCP", "", "yes"); | 1296 | error = kvp_write_file(file, "BOOTPROTO", "", "dhcp"); |
1303 | if (error) | 1297 | if (error) |
1304 | goto setval_error; | 1298 | goto setval_error; |
1305 | 1299 | ||
@@ -1307,6 +1301,11 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val) | |||
1307 | * We are done!. | 1301 | * We are done!. |
1308 | */ | 1302 | */ |
1309 | goto setval_done; | 1303 | goto setval_done; |
1304 | |||
1305 | } else { | ||
1306 | error = kvp_write_file(file, "BOOTPROTO", "", "none"); | ||
1307 | if (error) | ||
1308 | goto setval_error; | ||
1310 | } | 1309 | } |
1311 | 1310 | ||
1312 | /* | 1311 | /* |
diff --git a/tools/hv/hv_set_ifconfig.sh b/tools/hv/hv_set_ifconfig.sh index 3e9427e08d80..735aafd64a3f 100755 --- a/tools/hv/hv_set_ifconfig.sh +++ b/tools/hv/hv_set_ifconfig.sh | |||
@@ -20,18 +20,19 @@ | |||
20 | # Here is the format of the ip configuration file: | 20 | # Here is the format of the ip configuration file: |
21 | # | 21 | # |
22 | # HWADDR=macaddr | 22 | # HWADDR=macaddr |
23 | # IF_NAME=interface name | 23 | # DEVICE=interface name |
24 | # DHCP=yes (This is optional; if yes, DHCP is configured) | 24 | # BOOTPROTO=<protocol> (where <protocol> is "dhcp" if DHCP is configured |
25 | # or "none" if no boot-time protocol should be used) | ||
25 | # | 26 | # |
26 | # IPADDR=ipaddr1 | 27 | # IPADDR0=ipaddr1 |
27 | # IPADDR_1=ipaddr2 | 28 | # IPADDR1=ipaddr2 |
28 | # IPADDR_x=ipaddry (where y = x + 1) | 29 | # IPADDRx=ipaddry (where y = x + 1) |
29 | # | 30 | # |
30 | # NETMASK=netmask1 | 31 | # NETMASK0=netmask1 |
31 | # NETMASK_x=netmasky (where y = x + 1) | 32 | # NETMASKx=netmasky (where y = x + 1) |
32 | # | 33 | # |
33 | # GATEWAY=ipaddr1 | 34 | # GATEWAY=ipaddr1 |
34 | # GATEWAY_x=ipaddry (where y = x + 1) | 35 | # GATEWAYx=ipaddry (where y = x + 1) |
35 | # | 36 | # |
36 | # DNSx=ipaddrx (where first DNS address is tagged as DNS1 etc) | 37 | # DNSx=ipaddrx (where first DNS address is tagged as DNS1 etc) |
37 | # | 38 | # |
@@ -53,11 +54,6 @@ echo "NM_CONTROLLED=no" >> $1 | |||
53 | echo "PEERDNS=yes" >> $1 | 54 | echo "PEERDNS=yes" >> $1 |
54 | echo "ONBOOT=yes" >> $1 | 55 | echo "ONBOOT=yes" >> $1 |
55 | 56 | ||
56 | dhcp=$(grep "DHCP" $1 2>/dev/null) | ||
57 | if [ "$dhcp" != "" ]; | ||
58 | then | ||
59 | echo "BOOTPROTO=dhcp" >> $1; | ||
60 | fi | ||
61 | 57 | ||
62 | cp $1 /etc/sysconfig/network-scripts/ | 58 | cp $1 /etc/sysconfig/network-scripts/ |
63 | 59 | ||
@@ -65,4 +61,4 @@ cp $1 /etc/sysconfig/network-scripts/ | |||
65 | interface=$(echo $1 | awk -F - '{ print $2 }') | 61 | interface=$(echo $1 | awk -F - '{ print $2 }') |
66 | 62 | ||
67 | /sbin/ifdown $interface 2>/dev/null | 63 | /sbin/ifdown $interface 2>/dev/null |
68 | /sbin/ifup $interfac 2>/dev/null | 64 | /sbin/ifup $interface 2>/dev/null |