List available switches.

As part of the usage message or when the switch name was mistyped,
show the user a summary of switch devices available in the system.

Signed-off-by: Tobias Diedrich <ranma+open...@tdiedrich.de>


Index: package/swconfig/src/cli.c
===================================================================
--- package/swconfig/src/cli.c  (revision 31813)
+++ package/swconfig/src/cli.c  (working copy)
@@ -72,9 +72,15 @@
 }
 
 static void
+print_dev_summary(struct switch_dev *dev)
+{
+       printf("%s: %s(%s), ports: %d (cpu @ %d), vlans: %d\n", dev->dev_name, 
dev->alias, dev->name, dev->ports, dev->cpu_port, dev->vlans);
+}
+
+static void
 list_attributes(struct switch_dev *dev)
 {
-       printf("%s: %s(%s), ports: %d (cpu @ %d), vlans: %d\n", dev->dev_name, 
dev->alias, dev->name, dev->ports, dev->cpu_port, dev->vlans);
+       print_dev_summary(dev);
        printf("     --switch\n");
        print_attrs(dev->ops);
        printf("     --vlan\n");
@@ -84,6 +90,21 @@
 }
 
 static void
+list_switches(void)
+{
+       struct switch_dev *dev;
+       dev = swlib_connect(NULL);
+       if (!dev)
+               printf("No switches found\n");
+       while (dev) {
+               struct switch_dev *next = dev->next;
+               print_dev_summary(dev);
+               swlib_free(dev);
+               dev = dev->next;
+       }
+}
+
+static void
 print_attr_val(const struct switch_attr *attr, const struct switch_val *val)
 {
        int i;
@@ -168,6 +189,7 @@
 print_usage(void)
 {
        printf("swconfig dev <dev> [port <port>|vlan <vlan>] (help|set <key> 
<value>|get <key>|load <config>|show)\n");
+       list_switches();
        exit(1);
 }
 
@@ -260,7 +282,8 @@
 
        dev = swlib_connect(cdev);
        if (!dev) {
-               fprintf(stderr, "Failed to connect to the switch\n");
+               fprintf(stderr, "Failed to connect to the switch, available 
switches:\n");
+               list_switches();
                return 1;
        }
 

-- 
Tobias                                          PGP: http://8ef7ddba.uguu.de
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to