Changeset 821
- Timestamp:
- Dec 1, 2016, 7:22:47 PM (3 years ago)
- Location:
- trunk/debian/packages/swconfig/trunk
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/debian/packages/swconfig/trunk/debian/changelog
r819 r821 2 2 3 3 * Upstream update 11 4 * Use svn-buildpackage 4 5 5 -- Johan van Zoomeren <amain@de v3> Tue, 29 Nov 2016 22:52:08 +01006 -- Johan van Zoomeren <amain@debwrt.net> Tue, 29 Nov 2016 22:52:08 +0100 6 7 7 8 swconfig (0.0.10-2~debwrt70+1) wheezy-debwrt-unstable; urgency=medium -
trunk/debian/packages/swconfig/trunk/debian/patches/002_debwrt_cli.c.patch
r819 r821 40 40 case CMD_HELP: 41 41 list_attributes(dev); 42 Index: swconfig-0.0.10/src/cli.c.orig43 ===================================================================44 --- /dev/null45 +++ swconfig-0.0.10/src/cli.c.orig46 @@ -0,0 +1,354 @@47 +/*48 + * swconfig.c: Switch configuration utility49 + *50 + * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>51 + * Copyright (C) 2010 Martin Mares <mj@ucw.cz>52 + *53 + * This program is free software; you can redistribute it and/or54 + * modify it under the terms of the GNU General Public License55 + * version 2 as published by the Free Software Foundatio.56 + *57 + * This program is distributed in the hope that it will be useful,58 + * but WITHOUT ANY WARRANTY; without even the implied warranty of59 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the60 + * GNU General Public License for more details.61 + */62 +63 +#include <stdio.h>64 +#include <string.h>65 +#include <stdlib.h>66 +#include <inttypes.h>67 +#include <errno.h>68 +#include <stdint.h>69 +#include <getopt.h>70 +#include <sys/types.h>71 +#include <sys/socket.h>72 +#include <uci.h>73 +74 +#include <linux/types.h>75 +#include <linux/netlink.h>76 +#include <linux/genetlink.h>77 +#include <netlink/netlink.h>78 +#include <netlink/genl/genl.h>79 +#include <netlink/genl/ctrl.h>80 +#include <linux/switch.h>81 +#include "swlib.h"82 +83 +enum {84 + CMD_NONE,85 + CMD_GET,86 + CMD_SET,87 + CMD_LOAD,88 + CMD_HELP,89 + CMD_SHOW,90 + CMD_PORTMAP,91 +};92 +93 +static void94 +print_attrs(const struct switch_attr *attr)95 +{96 + int i = 0;97 + while (attr) {98 + const char *type;99 + switch(attr->type) {100 + case SWITCH_TYPE_INT:101 + type = "int";102 + break;103 + case SWITCH_TYPE_STRING:104 + type = "string";105 + break;106 + case SWITCH_TYPE_PORTS:107 + type = "ports";108 + break;109 + case SWITCH_TYPE_NOVAL:110 + type = "none";111 + break;112 + default:113 + type = "unknown";114 + break;115 + }116 + printf("\tAttribute %d (%s): %s (%s)\n", ++i, type, attr->name, attr->description);117 + attr = attr->next;118 + }119 +}120 +121 +static void122 +list_attributes(struct switch_dev *dev)123 +{124 + 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);125 + printf(" --switch\n");126 + print_attrs(dev->ops);127 + printf(" --vlan\n");128 + print_attrs(dev->vlan_ops);129 + printf(" --port\n");130 + print_attrs(dev->port_ops);131 +}132 +133 +static void134 +print_attr_val(const struct switch_attr *attr, const struct switch_val *val)135 +{136 + int i;137 +138 + switch (attr->type) {139 + case SWITCH_TYPE_INT:140 + printf("%d", val->value.i);141 + break;142 + case SWITCH_TYPE_STRING:143 + printf("%s", val->value.s);144 + break;145 + case SWITCH_TYPE_PORTS:146 + for(i = 0; i < val->len; i++) {147 + printf("%d%s ",148 + val->value.ports[i].id,149 + (val->value.ports[i].flags &150 + SWLIB_PORT_FLAG_TAGGED) ? "t" : "");151 + }152 + break;153 + default:154 + printf("?unknown-type?");155 + }156 +}157 +158 +static void159 +show_attrs(struct switch_dev *dev, struct switch_attr *attr, struct switch_val *val)160 +{161 + while (attr) {162 + if (attr->type != SWITCH_TYPE_NOVAL) {163 + printf("\t%s: ", attr->name);164 + if (swlib_get_attr(dev, attr, val) < 0)165 + printf("???");166 + else167 + print_attr_val(attr, val);168 + putchar('\n');169 + }170 + attr = attr->next;171 + }172 +}173 +174 +static void175 +show_global(struct switch_dev *dev)176 +{177 + struct switch_val val;178 +179 + printf("Global attributes:\n");180 + show_attrs(dev, dev->ops, &val);181 +}182 +183 +static void184 +show_port(struct switch_dev *dev, int port)185 +{186 + struct switch_val val;187 +188 + printf("Port %d:\n", port);189 + val.port_vlan = port;190 + show_attrs(dev, dev->port_ops, &val);191 +}192 +193 +static void194 +show_vlan(struct switch_dev *dev, int vlan, bool all)195 +{196 + struct switch_val val;197 + struct switch_attr *attr;198 +199 + val.port_vlan = vlan;200 +201 + if (all) {202 + attr = swlib_lookup_attr(dev, SWLIB_ATTR_GROUP_VLAN, "ports");203 + if (swlib_get_attr(dev, attr, &val) < 0)204 + return;205 +206 + if (!val.len)207 + return;208 + }209 +210 + printf("VLAN %d:\n", vlan);211 + show_attrs(dev, dev->vlan_ops, &val);212 +}213 +214 +static void215 +print_usage(void)216 +{217 + printf("swconfig list\n");218 + printf("swconfig dev <dev> [port <port>|vlan <vlan>] (help|set <key> <value>|get <key>|load <config>|show)\n");219 + exit(1);220 +}221 +222 +static void223 +swconfig_load_uci(struct switch_dev *dev, const char *name)224 +{225 + struct uci_context *ctx;226 + struct uci_package *p = NULL;227 + int ret = -1;228 +229 + ctx = uci_alloc_context();230 + if (!ctx)231 + return;232 +233 + uci_load(ctx, name, &p);234 + if (!p) {235 + uci_perror(ctx, "Failed to load config file: ");236 + goto out;237 + }238 +239 + ret = swlib_apply_from_uci(dev, p);240 + if (ret < 0)241 + fprintf(stderr, "Failed to apply configuration for switch '%s'\n", dev->dev_name);242 +243 +out:244 + uci_free_context(ctx);245 + exit(ret);246 +}247 +248 +int main(int argc, char **argv)249 +{250 + int retval = 0;251 + struct switch_dev *dev;252 + struct switch_attr *a;253 + struct switch_val val;254 + int i;255 +256 + int cmd = CMD_NONE;257 + char *cdev = NULL;258 + int cport = -1;259 + int cvlan = -1;260 + char *ckey = NULL;261 + char *cvalue = NULL;262 + char *csegment = NULL;263 +264 + if((argc == 2) && !strcmp(argv[1], "list")) {265 + swlib_list();266 + return 0;267 + }268 +269 + if(argc < 4)270 + print_usage();271 +272 + if(strcmp(argv[1], "dev"))273 + print_usage();274 +275 + cdev = argv[2];276 +277 + for(i = 3; i < argc; i++)278 + {279 + char *arg = argv[i];280 + if (cmd != CMD_NONE) {281 + print_usage();282 + } else if (!strcmp(arg, "port") && i+1 < argc) {283 + cport = atoi(argv[++i]);284 + } else if (!strcmp(arg, "vlan") && i+1 < argc) {285 + cvlan = atoi(argv[++i]);286 + } else if (!strcmp(arg, "help")) {287 + cmd = CMD_HELP;288 + } else if (!strcmp(arg, "set") && i+1 < argc) {289 + cmd = CMD_SET;290 + ckey = argv[++i];291 + if (i+1 < argc)292 + cvalue = argv[++i];293 + } else if (!strcmp(arg, "get") && i+1 < argc) {294 + cmd = CMD_GET;295 + ckey = argv[++i];296 + } else if (!strcmp(arg, "load") && i+1 < argc) {297 + if ((cport >= 0) || (cvlan >= 0))298 + print_usage();299 + cmd = CMD_LOAD;300 + ckey = argv[++i];301 + } else if (!strcmp(arg, "portmap")) {302 + if (i + 1 < argc)303 + csegment = argv[++i];304 + cmd = CMD_PORTMAP;305 + } else if (!strcmp(arg, "show")) {306 + cmd = CMD_SHOW;307 + } else {308 + print_usage();309 + }310 + }311 +312 + if (cmd == CMD_NONE)313 + print_usage();314 + if (cport > -1 && cvlan > -1)315 + print_usage();316 +317 + dev = swlib_connect(cdev);318 + if (!dev) {319 + fprintf(stderr, "Failed to connect to the switch. Use the \"list\" command to see which switches are available.\n");320 + return 1;321 + }322 +323 + swlib_scan(dev);324 +325 + if (cmd == CMD_GET || cmd == CMD_SET) {326 + if(cport > -1)327 + a = swlib_lookup_attr(dev, SWLIB_ATTR_GROUP_PORT, ckey);328 + else if(cvlan > -1)329 + a = swlib_lookup_attr(dev, SWLIB_ATTR_GROUP_VLAN, ckey);330 + else331 + a = swlib_lookup_attr(dev, SWLIB_ATTR_GROUP_GLOBAL, ckey);332 +333 + if(!a)334 + {335 + fprintf(stderr, "Unknown attribute \"%s\"\n", ckey);336 + retval = -1;337 + goto out;338 + }339 + }340 +341 + switch(cmd)342 + {343 + case CMD_SET:344 + if ((a->type != SWITCH_TYPE_NOVAL) &&345 + (cvalue == NULL))346 + print_usage();347 +348 + if(cvlan > -1)349 + cport = cvlan;350 +351 + if(swlib_set_attr_string(dev, a, cport, cvalue) < 0)352 + {353 + fprintf(stderr, "failed\n");354 + retval = -1;355 + goto out;356 + }357 + break;358 + case CMD_GET:359 + if(cvlan > -1)360 + val.port_vlan = cvlan;361 + if(cport > -1)362 + val.port_vlan = cport;363 + if(swlib_get_attr(dev, a, &val) < 0)364 + {365 + fprintf(stderr, "failed\n");366 + retval = -1;367 + goto out;368 + }369 + print_attr_val(a, &val);370 + putchar('\n');371 + break;372 + case CMD_LOAD:373 + swconfig_load_uci(dev, ckey);374 + break;375 + case CMD_HELP:376 + list_attributes(dev);377 + break;378 + case CMD_PORTMAP:379 + swlib_print_portmap(dev, csegment);380 + break;381 + case CMD_SHOW:382 + if (cport >= 0 || cvlan >= 0) {383 + if (cport >= 0)384 + show_port(dev, cport);385 + else386 + show_vlan(dev, cvlan, false);387 + } else {388 + show_global(dev);389 + for (i=0; i < dev->ports; i++)390 + show_port(dev, i);391 + for (i=0; i < dev->vlans; i++)392 + show_vlan(dev, i, true);393 + }394 + break;395 + }396 +397 +out:398 + swlib_free_all(dev);399 + return retval;400 +} -
trunk/debian/packages/swconfig/trunk/debian/patches/003_debwrt_swlib.h.patch
r819 r821 5 5 --- swconfig-0.0.11.orig/src/swlib.h 6 6 +++ swconfig-0.0.11/src/swlib.h 7 @@ -111,7 +111,7 @@ struct switch_attr; 8 struct switch_port; 7 @@ -116,7 +116,7 @@ struct switch_port; 9 8 struct switch_port_map; 9 struct switch_port_link; 10 10 struct switch_val; 11 11 -struct uci_package; … … 14 14 struct switch_dev { 15 15 int id; 16 @@ -2 47,6 +247,6 @@ int swlib_get_attr(struct switch_dev *de16 @@ -264,6 +264,6 @@ int swlib_get_attr(struct switch_dev *de 17 17 * @dev: switch device struct 18 18 * @p: uci package which contains the desired global config -
trunk/debian/packages/swconfig/trunk/debian/patches/007_openwrt_switch.h
r810 r821 1 Description: Include OpenWrt's switch.h kernel API 2 Author: Johan van Zoomeren <amain@debwrt.net> 3 4 --- /dev/null 5 +++ swconfig-47459/include/linux/switch.h 6 @@ -0,0 +1,101 @@ 1 --- /dev/null 2016-11-27 09:28:40.775309416 +0100 2 +++ trunk/include/uapi/linux/switch.h 2016-12-01 18:58:45.203309416 +0100 3 @@ -0,0 +1,119 @@ 7 4 +/* 8 5 + * switch.h: Switch configuration API 9 6 + * 10 + * Copyright (C) 2008 Felix Fietkau <nbd@ openwrt.org>7 + * Copyright (C) 2008 Felix Fietkau <nbd@nbd.name> 11 8 + * 12 9 + * This program is free software; you can redistribute it and/or … … 21 18 + */ 22 19 + 23 +#ifndef _ LINUX_SWITCH_H24 +#define _ LINUX_SWITCH_H20 +#ifndef _UAPI_LINUX_SWITCH_H 21 +#define _UAPI_LINUX_SWITCH_H 25 22 + 26 23 +#include <linux/types.h> … … 28 25 +#include <linux/netlink.h> 29 26 +#include <linux/genetlink.h> 27 +#ifndef __KERNEL__ 30 28 +#include <netlink/netlink.h> 31 29 +#include <netlink/genl/genl.h> 32 30 +#include <netlink/genl/ctrl.h> 31 +#endif 33 32 + 34 33 +/* main attributes */ … … 55 54 + SWITCH_ATTR_OP_VALUE_STR, 56 55 + SWITCH_ATTR_OP_VALUE_PORTS, 56 + SWITCH_ATTR_OP_VALUE_LINK, 57 57 + SWITCH_ATTR_OP_DESCRIPTION, 58 58 + /* port lists */ … … 91 91 + SWITCH_TYPE_STRING, 92 92 + SWITCH_TYPE_PORTS, 93 + SWITCH_TYPE_LINK, 93 94 + SWITCH_TYPE_NOVAL, 94 95 +}; … … 102 103 +}; 103 104 + 105 +/* link nested attributes */ 106 +enum { 107 + SWITCH_LINK_UNSPEC, 108 + SWITCH_LINK_FLAG_LINK, 109 + SWITCH_LINK_FLAG_DUPLEX, 110 + SWITCH_LINK_FLAG_ANEG, 111 + SWITCH_LINK_FLAG_TX_FLOW, 112 + SWITCH_LINK_FLAG_RX_FLOW, 113 + SWITCH_LINK_SPEED, 114 + SWITCH_LINK_FLAG_EEE_100BASET, 115 + SWITCH_LINK_FLAG_EEE_1000BASET, 116 + SWITCH_LINK_ATTR_MAX, 117 +}; 118 + 104 119 +#define SWITCH_ATTR_DEFAULTS_OFFSET 0x1000 105 120 + 106 121 + 107 +#endif /* _ LINUX_SWITCH_H */122 +#endif /* _UAPI_LINUX_SWITCH_H */ -
trunk/debian/packages/swconfig/trunk/debian/rules
r810 r821 12 12 13 13 # ../include contains switch.sh kernel API (see patch 007) 14 CFLAGS+=-O2 -g -I ../include -I /usr/include/netlink-tiny14 CFLAGS+=-O2 -g -I ../include/uapi -I /usr/include/netlink-tiny 15 15 16 16 %:
Note: See TracChangeset
for help on using the changeset viewer.