aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorK. Y. Srinivasan <kys@microsoft.com>2012-08-16 21:32:18 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-08-17 11:23:58 -0400
commit4a52c4af48a2a35282ddc4dcf2df83486d636754 (patch)
tree86224376fa6d1250d3a3fade1144fb6b700e7a3f /tools
parent6a60a6a8ea97795a288469c21262522894a1e6db (diff)
Tools: hv: Gather ipv[4,6] gateway information
Gather information on the default gateways - ipv4/ipv6. Signed-off-by: K. Y. Srinivasan <kys@microsoft.com> Reviewed-by: Haiyang Zhang <haiyangz@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/hv/hv_kvp_daemon.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index a63e83a0159f..65d54c89394e 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -491,6 +491,68 @@ done:
491 return; 491 return;
492} 492}
493 493
494static void kvp_process_ipconfig_file(char *cmd,
495 char *config_buf, int len,
496 int element_size, int offset)
497{
498 char buf[256];
499 char *p;
500 char *x;
501 FILE *file;
502
503 /*
504 * First execute the command.
505 */
506 file = popen(cmd, "r");
507 if (file == NULL)
508 return;
509
510 if (offset == 0)
511 memset(config_buf, 0, len);
512 while ((p = fgets(buf, sizeof(buf), file)) != NULL) {
513 if ((len - strlen(config_buf)) < (element_size + 1))
514 break;
515
516 x = strchr(p, '\n');
517 *x = '\0';
518 strcat(config_buf, p);
519 strcat(config_buf, ";");
520 }
521 pclose(file);
522}
523
524static void kvp_get_ipconfig_info(char *if_name,
525 struct hv_kvp_ipaddr_value *buffer)
526{
527 char cmd[512];
528
529 /*
530 * Get the address of default gateway (ipv4).
531 */
532 sprintf(cmd, "%s %s", "ip route show dev", if_name);
533 strcat(cmd, " | awk '/default/ {print $3 }'");
534
535 /*
536 * Execute the command to gather gateway info.
537 */
538 kvp_process_ipconfig_file(cmd, (char *)buffer->gate_way,
539 (MAX_GATEWAY_SIZE * 2), INET_ADDRSTRLEN, 0);
540
541 /*
542 * Get the address of default gateway (ipv6).
543 */
544 sprintf(cmd, "%s %s", "ip -f inet6 route show dev", if_name);
545 strcat(cmd, " | awk '/default/ {print $3 }'");
546
547 /*
548 * Execute the command to gather gateway info (ipv6).
549 */
550 kvp_process_ipconfig_file(cmd, (char *)buffer->gate_way,
551 (MAX_GATEWAY_SIZE * 2), INET6_ADDRSTRLEN, 1);
552
553}
554
555
494static unsigned int hweight32(unsigned int *w) 556static unsigned int hweight32(unsigned int *w)
495{ 557{
496 unsigned int res = *w - ((*w >> 1) & 0x55555555); 558 unsigned int res = *w - ((*w >> 1) & 0x55555555);
@@ -650,6 +712,12 @@ kvp_get_ip_address(int family, char *if_name, int op,
650 strcat((char *)ip_buffer->sub_net, ";"); 712 strcat((char *)ip_buffer->sub_net, ";");
651 sn_offset += strlen(sn_str) + 1; 713 sn_offset += strlen(sn_str) + 1;
652 } 714 }
715
716 /*
717 * Collect other ip related configuration info.
718 */
719
720 kvp_get_ipconfig_info(if_name, ip_buffer);
653 } 721 }
654 722
655gather_ipaddr: 723gather_ipaddr: