xl: network2-list command

Usage: xl network2-list <Domains>

Signed-off-by: Eric Chanudet <eric.chanudet@citrix.com>
This commit is contained in:
Keir Fraser committed 2010-06-07 07:11:15 +01:00
1 parent 1742e2a8ea
commit 2018b98c2f
5 files changed
+129

No files matched your search

+63
View File
@@ -1694,6 +1694,69 @@ int libxl_device_net2_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_ne
return 0;
}
libxl_net2info *libxl_device_net2_list(struct libxl_ctx *ctx, uint32_t domid, unsigned int *nb)
{
char *dompath, *net2_path_fe;
char **l;
char *val, *tok;
unsigned int nb_net2s, i;
libxl_net2info *res, *net2s;
dompath = libxl_xs_get_dompath(ctx, domid);
if (!dompath) {
return NULL;
}
l = libxl_xs_directory(ctx, XBT_NULL,
libxl_sprintf(ctx, "%s/device/vif2", dompath), &nb_net2s);
if (!l) {
return NULL;
}
res = libxl_calloc(ctx, nb_net2s, sizeof (libxl_net2info));
if (!res) {
libxl_free(ctx, l);
return NULL;
}
net2s = res;
for (*nb = nb_net2s; nb_net2s > 0; --nb_net2s, ++l, ++net2s) {
net2_path_fe = libxl_sprintf(ctx, "%s/device/vif2/%s", dompath, *l);
net2s->backend = libxl_xs_read(ctx, XBT_NULL,
libxl_sprintf(ctx, "%s/backend", net2_path_fe));
val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/backend-id", net2_path_fe));
net2s->backend_id = val ? strtoul(val, NULL, 10) : -1;
net2s->devid = strtoul(*l, NULL, 10);
val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/state", net2_path_fe));
net2s->state = val ? strtoul(val, NULL, 10) : -1;
val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/mac", net2_path_fe));
for (i = 0, tok = strtok(val, ":"); tok && (i < 6);
++i, tok = strtok(NULL, ":")) {
net2s->mac[i] = strtoul(tok, NULL, 16);
}
val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/remote-trusted", net2_path_fe));
net2s->trusted = val ? strtoul(val, NULL, 10) : -1;
val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/remote-mac", net2_path_fe));
for (i = 0, tok = strtok(val, ":"); tok && (i < 6);
++i, tok = strtok(NULL, ":")) {
net2s->back_mac[i] = strtoul(tok, NULL, 16);
}
val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/filter-mac", net2_path_fe));
net2s->filter_mac = val ? strtoul(val, NULL, 10) : -1;
net2s->frontend = libxl_xs_read(ctx, XBT_NULL,
libxl_sprintf(ctx, "%s/frontend", net2s->backend));
val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/frontend-id", net2s->backend));
net2s->frontend_id = val ? strtoul(val, NULL, 10) : -1;
libxl_free(ctx, net2_path_fe);
}
libxl_free(ctx, l);
return res;
}
/******************************************************************************/
int libxl_device_console_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_console *console)
{
+15
View File
@@ -554,8 +554,23 @@ int libxl_tmem_set(struct libxl_ctx *ctx, uint32_t domid, char* name,
int libxl_tmem_shared_auth(struct libxl_ctx *ctx, uint32_t domid, char* uuid,
int auth);
typedef struct {
char *backend;
uint32_t backend_id;
char *frontend;
uint32_t frontend_id;
int devid;
int state;
uint8_t mac[6];
int trusted;
uint8_t back_mac[6];
int filter_mac;
} libxl_net2info;
int libxl_device_net2_add(struct libxl_ctx *ctx, uint32_t domid,
libxl_device_net2 *net2);
libxl_net2info *libxl_device_net2_list(struct libxl_ctx *ctx, uint32_t domid,
unsigned int *nb);
/* common paths */
const char *libxl_sbindir_path(void);
+1
View File
@@ -73,6 +73,7 @@ int main_tmem_thaw(int argc, char **argv);
int main_tmem_set(int argc, char **argv);
int main_tmem_shared_auth(int argc, char **argv);
int main_network2attach(int argc, char **argv);
int main_network2list(int argc, char **argv);
void help(char *command);
+45
View File
@@ -3877,6 +3877,51 @@ int main_network2attach(int argc, char **argv)
exit(0);
}
int main_network2list(int argc, char **argv)
{
int opt;
unsigned int nb;
libxl_net2info *net2s;
if (argc < 3) {
help("network2-list");
exit(0);
}
while ((opt = getopt(argc, argv, "h")) != -1) {
switch (opt) {
case 'h':
help("network2-list");
exit(0);
default:
fprintf(stderr, "option `%c' not supported.\n", opt);
break;
}
}
printf("%-3s %-2s %-5s %-17s %-17s %-7s %-6s %-30s\n",
"Idx", "BE", "state", "Mac Addr.", "Remote Mac Addr.",
"trusted", "filter", "backend");
for (argv += 2, argc -=2; argc > 0; --argc, ++argv) {
if (domain_qualifier_to_domid(*argv, &domid, 0) < 0) {
fprintf(stderr, "%s is an invalid domain identifier\n", *argv);
continue;
}
if ((net2s = libxl_device_net2_list(&ctx, domid, &nb))) {
for (; nb > 0; --nb, ++net2s) {
printf("%3d %2d %5d ", net2s->devid, net2s->backend_id, net2s->state);
printf("%02x:%02x:%02x:%02x:%02x:%02x ",
net2s->mac[0], net2s->mac[1], net2s->mac[2],
net2s->mac[3], net2s->mac[4], net2s->mac[5]);
printf("%02x:%02x:%02x:%02x:%02x:%02x ",
net2s->back_mac[0], net2s->back_mac[1], net2s->back_mac[2],
net2s->back_mac[3], net2s->back_mac[4], net2s->back_mac[5]);
printf("%-7d %-6d %-30s\n", net2s->trusted, net2s->filter_mac, net2s->backend);
}
}
}
exit(0);
}
static char *uptime_to_string(unsigned long time, int short_mode)
{
int sec, min, hour, day;
+5
View File
@@ -295,6 +295,11 @@ struct cmd_spec cmd_table[] = {
" [filter_mac=<0|1>] [front_filter_mac=<0|1>] [pdev=<PDEV>]"
" [max_bypasses=n]",
},
{ "network2-list",
&main_network2list,
"list version 2 virtual network interfaces for a domain",
"<Domain(s)>",
},
};
int cmdtable_len = sizeof(cmd_table)/sizeof(struct cmd_spec);
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.