aboutsummaryrefslogtreecommitdiffstats
path: root/package
diff options
context:
space:
mode:
authorJohn Crispin <john@phrozen.org>2016-08-16 10:19:13 +0200
committerJohn Crispin <john@phrozen.org>2016-08-16 10:20:01 +0200
commit99a188828713d6ff9c541590b08d4e63ef52f6d7 (patch)
treeefe6ec0d17b98554bc810ed0e68e0a1f98f2d6a8 /package
parent58466208909d5b9264537256b353b3c3db57ef0e (diff)
downloadupstream-99a188828713d6ff9c541590b08d4e63ef52f6d7.tar.gz
upstream-99a188828713d6ff9c541590b08d4e63ef52f6d7.tar.bz2
upstream-99a188828713d6ff9c541590b08d4e63ef52f6d7.zip
swconfig: revert the portmapping patches, they seem to cause a segfault
Revert "kernel/swconfig: remove obsolete portmapping feature from swconfig" This reverts commit 675407baa44a8700de20b6b2857009a552a807ba. Revert "swconfig: remove obsolete portmapping feature" This reverts commit fca1eb349ef31b133a62880cbd562d6bf17500aa. Signed-off-by: John Crispin <john@phrozen.org>
Diffstat (limited to 'package')
-rw-r--r--package/network/config/swconfig/src/cli.c8
-rw-r--r--package/network/config/swconfig/src/swlib.c84
-rw-r--r--package/network/config/swconfig/src/swlib.h12
3 files changed, 104 insertions, 0 deletions
diff --git a/package/network/config/swconfig/src/cli.c b/package/network/config/swconfig/src/cli.c
index 28b7ed8625..eab6c64742 100644
--- a/package/network/config/swconfig/src/cli.c
+++ b/package/network/config/swconfig/src/cli.c
@@ -41,6 +41,7 @@ enum {
CMD_LOAD,
CMD_HELP,
CMD_SHOW,
+ CMD_PORTMAP,
};
static void
@@ -284,6 +285,10 @@ int main(int argc, char **argv)
print_usage();
cmd = CMD_LOAD;
ckey = argv[++i];
+ } else if (!strcmp(arg, "portmap")) {
+ if (i + 1 < argc)
+ csegment = argv[++i];
+ cmd = CMD_PORTMAP;
} else if (!strcmp(arg, "show")) {
cmd = CMD_SHOW;
} else {
@@ -357,6 +362,9 @@ int main(int argc, char **argv)
case CMD_HELP:
list_attributes(dev);
break;
+ case CMD_PORTMAP:
+ swlib_print_portmap(dev, csegment);
+ break;
case CMD_SHOW:
if (cport >= 0 || cvlan >= 0) {
if (cport >= 0)
diff --git a/package/network/config/swconfig/src/swlib.c b/package/network/config/swconfig/src/swlib.c
index 440a45aef7..e6e9aead47 100644
--- a/package/network/config/swconfig/src/swlib.c
+++ b/package/network/config/swconfig/src/swlib.c
@@ -46,6 +46,11 @@ static struct nla_policy port_policy[SWITCH_ATTR_MAX] = {
[SWITCH_PORT_FLAG_TAGGED] = { .type = NLA_FLAG },
};
+static struct nla_policy portmap_policy[SWITCH_PORTMAP_MAX] = {
+ [SWITCH_PORTMAP_SEGMENT] = { .type = NLA_STRING },
+ [SWITCH_PORTMAP_VIRT] = { .type = NLA_U32 },
+};
+
static struct nla_policy link_policy[SWITCH_LINK_ATTR_MAX] = {
[SWITCH_LINK_FLAG_LINK] = { .type = NLA_FLAG },
[SWITCH_LINK_FLAG_DUPLEX] = { .type = NLA_FLAG },
@@ -697,6 +702,41 @@ struct swlib_scan_arg {
};
static int
+add_port_map(struct switch_dev *dev, struct nlattr *nla)
+{
+ struct nlattr *p;
+ int err = 0, idx = 0;
+ int remaining;
+
+ dev->maps = malloc(sizeof(struct switch_portmap) * dev->ports);
+ if (!dev->maps)
+ return -1;
+ memset(dev->maps, 0, sizeof(struct switch_portmap) * dev->ports);
+
+ nla_for_each_nested(p, nla, remaining) {
+ struct nlattr *tb[SWITCH_PORTMAP_MAX+1];
+
+ if (idx >= dev->ports)
+ continue;
+
+ err = nla_parse_nested(tb, SWITCH_PORTMAP_MAX, p, portmap_policy);
+ if (err < 0)
+ continue;
+
+
+ if (tb[SWITCH_PORTMAP_SEGMENT] && tb[SWITCH_PORTMAP_VIRT]) {
+ dev->maps[idx].segment = strdup(nla_get_string(tb[SWITCH_PORTMAP_SEGMENT]));
+ dev->maps[idx].virt = nla_get_u32(tb[SWITCH_PORTMAP_VIRT]);
+ }
+ idx++;
+ }
+
+out:
+ return err;
+}
+
+
+static int
add_switch(struct nl_msg *msg, void *arg)
{
struct swlib_scan_arg *sa = arg;
@@ -733,6 +773,8 @@ add_switch(struct nl_msg *msg, void *arg)
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 (tb[SWITCH_ATTR_PORTMAP])
+ add_port_map(dev, tb[SWITCH_ATTR_PORTMAP]);
if (!sa->head) {
sa->head = dev;
@@ -774,6 +816,34 @@ swlib_list(void)
swlib_priv_free();
}
+void
+swlib_print_portmap(struct switch_dev *dev, char *segment)
+{
+ int i;
+
+ if (segment) {
+ if (!strcmp(segment, "cpu")) {
+ printf("%d ", dev->cpu_port);
+ } else if (!strcmp(segment, "disabled")) {
+ for (i = 0; i < dev->ports; i++)
+ if (!dev->maps[i].segment)
+ printf("%d ", i);
+ } else for (i = 0; i < dev->ports; i++) {
+ if (dev->maps[i].segment && !strcmp(dev->maps[i].segment, segment))
+ printf("%d ", i);
+ }
+ } else {
+ printf("%s - %s\n", dev->dev_name, dev->name);
+ for (i = 0; i < dev->ports; i++)
+ if (i == dev->cpu_port)
+ printf("port%d:\tcpu\n", i);
+ else if (dev->maps[i].segment)
+ printf("port%d:\t%s.%d\n", i, dev->maps[i].segment, dev->maps[i].virt);
+ else
+ printf("port%d:\tdisabled\n", i);
+ }
+}
+
struct switch_dev *
swlib_connect(const char *name)
{
@@ -811,12 +881,26 @@ swlib_free_attributes(struct switch_attr **head)
*head = NULL;
}
+static void
+swlib_free_port_map(struct switch_dev *dev)
+{
+ int i;
+
+ if (!dev || !dev->maps)
+ return;
+
+ for (i = 0; i < dev->ports; i++)
+ free(dev->maps[i].segment);
+ free(dev->maps);
+}
+
void
swlib_free(struct switch_dev *dev)
{
swlib_free_attributes(&dev->ops);
swlib_free_attributes(&dev->port_ops);
swlib_free_attributes(&dev->vlan_ops);
+ swlib_free_port_map(dev);
free(dev->name);
free(dev->alias);
free(dev);
diff --git a/package/network/config/swconfig/src/swlib.h b/package/network/config/swconfig/src/swlib.h
index 89dbba748d..3826a5e340 100644
--- a/package/network/config/swconfig/src/swlib.h
+++ b/package/network/config/swconfig/src/swlib.h
@@ -129,6 +129,7 @@ struct switch_dev {
struct switch_attr *ops;
struct switch_attr *port_ops;
struct switch_attr *vlan_ops;
+ struct switch_portmap *maps;
struct switch_dev *next;
void *priv;
};
@@ -161,6 +162,11 @@ struct switch_port {
unsigned int flags;
};
+struct switch_portmap {
+ unsigned int virt;
+ char *segment;
+};
+
struct switch_port_link {
int link:1;
int duplex:1;
@@ -178,6 +184,12 @@ struct switch_port_link {
void swlib_list(void);
/**
+ * swlib_print_portmap: get portmap
+ * @dev: switch device struct
+ */
+void swlib_print_portmap(struct switch_dev *dev, char *segment);
+
+/**
* swlib_connect: connect to the switch through netlink
* @name: name of the ethernet interface,
*