add "swconfig list" support
authorJohn Crispin <john@openwrt.org>
Tue, 9 Apr 2013 14:19:05 +0000 (14:19 +0000)
committerJohn Crispin <john@openwrt.org>
Tue, 9 Apr 2013 14:19:05 +0000 (14:19 +0000)
Signed-off-by: John Crispin <blogic@openwrt.org>
SVN-Revision: 36282

package/network/config/swconfig/src/cli.c
package/network/config/swconfig/src/swlib.c
package/network/config/swconfig/src/swlib.h

index 9cd16abb5f5286b7630f1e8ae3874d3beaac972e..5f9e532bc08cacf04d054160d29e8935d5c557ba 100644 (file)
@@ -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();
 
index de08717e33a069fe9d2d5e441da02f75579c361f..a867d2e842279f8baca6591786b1987203258436 100644 (file)
@@ -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)
index ff73969c8718cc0edcc1c7010669b44f24da0b14..02fa45610c9be031993b0cb01074db2b9d18a478 100644 (file)
@@ -154,6 +154,11 @@ struct switch_port {
        unsigned int flags;
 };
 
+/**
+ * swlib_list: list all switches
+ */
+void swlib_list(void);
+
 /**
  * swlib_connect: connect to the switch through netlink
  * @name: name of the ethernet interface,