diff options
author | John Crispin <blogic@openwrt.org> | 2013-04-09 14:19:05 +0000 |
---|---|---|
committer | John Crispin <blogic@openwrt.org> | 2013-04-09 14:19:05 +0000 |
commit | d2f8216c54b1908771ef674094b7009da2ca6ef4 (patch) | |
tree | 1b02a5fe29f8f40251f2ec5bb6e8d6a9c640527f /package/network/config/swconfig | |
parent | a2a15cdf8f24d898899e19f5f49c320fb05e465f (diff) | |
download | master-187ad058-d2f8216c54b1908771ef674094b7009da2ca6ef4.tar.gz master-187ad058-d2f8216c54b1908771ef674094b7009da2ca6ef4.tar.bz2 master-187ad058-d2f8216c54b1908771ef674094b7009da2ca6ef4.zip |
[swconfig] add "swconfig list" support
Signed-off-by: John Crispin <blogic@openwrt.org>
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@36282 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/network/config/swconfig')
-rw-r--r-- | package/network/config/swconfig/src/cli.c | 6 | ||||
-rw-r--r-- | package/network/config/swconfig/src/swlib.c | 30 | ||||
-rw-r--r-- | package/network/config/swconfig/src/swlib.h | 5 |
3 files changed, 41 insertions, 0 deletions
diff --git a/package/network/config/swconfig/src/cli.c b/package/network/config/swconfig/src/cli.c index 9cd16abb5f..5f9e532bc0 100644 --- a/package/network/config/swconfig/src/cli.c +++ b/package/network/config/swconfig/src/cli.c @@ -167,6 +167,7 @@ show_vlan(struct switch_dev *dev, int vlan, bool all) static void print_usage(void) { + printf("swconfig list\n"); printf("swconfig dev <dev> [port <port>|vlan <vlan>] (help|set <key> <value>|get <key>|load <config>|show)\n"); exit(1); } @@ -214,6 +215,11 @@ int main(int argc, char **argv) char *ckey = NULL; char *cvalue = NULL; + if((argc == 2) && !strcmp(argv[1], "list")) { + swlib_list(); + return 0; + } + if(argc < 4) print_usage(); diff --git a/package/network/config/swconfig/src/swlib.c b/package/network/config/swconfig/src/swlib.c index de08717e33..a867d2e842 100644 --- a/package/network/config/swconfig/src/swlib.c +++ b/package/network/config/swconfig/src/swlib.c @@ -624,6 +624,36 @@ done: return NL_SKIP; } +static int +list_switch(struct nl_msg *msg, void *arg) +{ + struct swlib_scan_arg *sa = arg; + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); + struct switch_dev *dev; + const char *name; + const char *alias; + + if (nla_parse(tb, SWITCH_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL) < 0) + goto done; + + if (!tb[SWITCH_ATTR_DEV_NAME] || !tb[SWITCH_ATTR_NAME]) + goto done; + + printf("Found: %s - %s\n", nla_get_string(tb[SWITCH_ATTR_DEV_NAME]), + nla_get_string(tb[SWITCH_ATTR_ALIAS])); + +done: + return NL_SKIP; +} + +void +swlib_list(void) +{ + if (swlib_priv_init() < 0) + return; + swlib_call(SWITCH_CMD_GET_SWITCH, list_switch, NULL, NULL); + swlib_priv_free(); +} struct switch_dev * swlib_connect(const char *name) diff --git a/package/network/config/swconfig/src/swlib.h b/package/network/config/swconfig/src/swlib.h index ff73969c87..02fa45610c 100644 --- a/package/network/config/swconfig/src/swlib.h +++ b/package/network/config/swconfig/src/swlib.h @@ -155,6 +155,11 @@ struct switch_port { }; /** + * swlib_list: list all switches + */ +void swlib_list(void); + +/** * swlib_connect: connect to the switch through netlink * @name: name of the ethernet interface, * |