Let swconfig provide the cpu port index in its help page. This is
needed as e.g. Atheros switches have their cpu port at port 0, not
port 5.

This could allow e.g. luci to get a rough overview of the layout of
the switch.

Signed-off-by: Jonas Gorski <jonas.gorski+open...@gmail.com>
---
 package/swconfig/src/cli.c                         |    2 +-
 package/swconfig/src/swlib.c                       |    2 ++
 package/swconfig/src/swlib.h                       |    1 +
 .../generic-2.6/files/drivers/net/phy/swconfig.c   |    1 +
 .../linux/generic-2.6/files/include/linux/switch.h |    1 +
 5 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/package/swconfig/src/cli.c b/package/swconfig/src/cli.c
index 76593ba..eea88d8 100644
--- a/package/swconfig/src/cli.c
+++ b/package/swconfig/src/cli.c
@@ -74,7 +74,7 @@ print_attrs(const struct switch_attr *attr)
 static void
 list_attributes(struct switch_dev *dev)
 {
-       printf("Switch %d: %s(%s), ports: %d, vlans: %d\n", dev->id, 
dev->dev_name, dev->name, dev->ports, dev->vlans);
+       printf("Switch %d: %s(%s), ports: %d (cpu @ %d), vlans: %d\n", dev->id, 
dev->dev_name, dev->name, dev->ports, dev->cpu_port, dev->vlans);
        printf("     --switch\n");
        print_attrs(dev->ops);
        printf("     --vlan\n");
diff --git a/package/swconfig/src/swlib.c b/package/swconfig/src/swlib.c
index 04b3bef..86b82de 100644
--- a/package/swconfig/src/swlib.c
+++ b/package/swconfig/src/swlib.c
@@ -586,6 +586,8 @@ add_switch(struct nl_msg *msg, void *arg)
                dev->ports = nla_get_u32(tb[SWITCH_ATTR_PORTS]);
        if (tb[SWITCH_ATTR_VLANS])
                dev->vlans = nla_get_u32(tb[SWITCH_ATTR_VLANS]);
+       if (tb[SWITCH_ATTR_CPU_PORT])
+               dev->cpu_port = nla_get_u32(tb[SWITCH_ATTR_CPU_PORT]);
 
        if (!sa->head) {
                sa->head = dev;
diff --git a/package/swconfig/src/swlib.h b/package/swconfig/src/swlib.h
index b3c6769..2c2fccd 100644
--- a/package/swconfig/src/swlib.h
+++ b/package/swconfig/src/swlib.h
@@ -118,6 +118,7 @@ struct switch_dev {
        const char *dev_name;
        int ports;
        int vlans;
+       int cpu_port;
        struct switch_attr *ops;
        struct switch_attr *port_ops;
        struct switch_attr *vlan_ops;
diff --git a/target/linux/generic-2.6/files/drivers/net/phy/swconfig.c 
b/target/linux/generic-2.6/files/drivers/net/phy/swconfig.c
index 7207e46..21a6a7b 100644
--- a/target/linux/generic-2.6/files/drivers/net/phy/swconfig.c
+++ b/target/linux/generic-2.6/files/drivers/net/phy/swconfig.c
@@ -757,6 +757,7 @@ swconfig_send_switch(struct sk_buff *msg, u32 pid, u32 seq, 
int flags,
        NLA_PUT_STRING(msg, SWITCH_ATTR_DEV_NAME, dev->devname);
        NLA_PUT_U32(msg, SWITCH_ATTR_VLANS, dev->vlans);
        NLA_PUT_U32(msg, SWITCH_ATTR_PORTS, dev->ports);
+       NLA_PUT_U32(msg, SWITCH_ATTR_CPU_PORT, dev->cpu_port);
 
        return genlmsg_end(msg, hdr);
 nla_put_failure:
diff --git a/target/linux/generic-2.6/files/include/linux/switch.h 
b/target/linux/generic-2.6/files/include/linux/switch.h
index 98b86e8..25aedb8 100644
--- a/target/linux/generic-2.6/files/include/linux/switch.h
+++ b/target/linux/generic-2.6/files/include/linux/switch.h
@@ -40,6 +40,7 @@ enum {
        SWITCH_ATTR_DEV_NAME,
        SWITCH_ATTR_VLANS,
        SWITCH_ATTR_PORTS,
+       SWITCH_ATTR_CPU_PORT,
        /* attributes */
        SWITCH_ATTR_OP_ID,
        SWITCH_ATTR_OP_TYPE,
-- 
1.7.0

_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to