[backfire] swconfig: Add generic switch identifiers
[openwrt-10.03/.git] / package / swconfig / src / swlib.c
index 20e727eb5371c88bcf0c5d80c3eadc4cd98cf9f5..531a23a1ab00f68a7827c40682f72120a159641a 100644 (file)
@@ -580,6 +580,7 @@ add_switch(struct nl_msg *msg, void *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;
@@ -588,14 +589,17 @@ add_switch(struct nl_msg *msg, void *arg)
                goto done;
 
        name = nla_get_string(tb[SWITCH_ATTR_DEV_NAME]);
-       if (sa->name && (strcmp(name, sa->name) != 0))
+       alias = nla_get_string(tb[SWITCH_ATTR_ALIAS]);
+
+       if (sa->name && (strcmp(name, sa->name) != 0) && (strcmp(alias, sa->name) != 0))
                goto done;
 
        dev = swlib_alloc(sizeof(struct switch_dev));
        if (!dev)
                goto done;
 
-       dev->dev_name = strdup(name);
+       strncpy(dev->dev_name, name, IFNAMSIZ - 1);
+       dev->alias = strdup(alias);
        if (tb[SWITCH_ATTR_ID])
                dev->id = nla_get_u32(tb[SWITCH_ATTR_ID]);
        if (tb[SWITCH_ATTR_NAME])