6 static char vlan_char (int t)
25 int do_vlan_8021q_del (int argc, const char **argv, struct ngadmin *nga)
27 const struct swi_attr *sa;
33 printf("usage: vlan 8021q del <vlan>\n");
37 sa = ngadmin_getCurrentSwitch(nga);
39 printf("must be logged\n");
43 vlan=strtoul(argv[0], NULL, 0);
44 if (vlan < VLAN_MIN || vlan > VLAN_DOT_MAX) {
45 printf("vlan out of range\n");
49 i = ngadmin_VLANDestroy(nga, vlan);
57 int do_vlan_port_set (int argc, const char **argv, struct ngadmin *nga)
59 unsigned char vlan, port, *ports = NULL;
60 const struct swi_attr *sa;
61 int i, k = 0, ret = 0;
65 printf("usage: vlan port set [all <vlan>] [<port1> <vlan>] [<port2> <vlan>] [...]\n");
70 sa = ngadmin_getCurrentSwitch(nga);
72 printf("must be logged\n");
77 ports = malloc(sa->ports * sizeof(unsigned char));
81 if (strcmp(argv[k], "all") == 0) {
83 port = strtoul(argv[k++], NULL, 0);
84 if (port < 1 || port > sa->ports) {
85 printf("port out of range");
92 memset(ports, port, sa->ports);
94 /* read and apply port specifics */
95 while (k < argc - 1) {
97 port = strtoul(argv[k++], NULL, 0);
98 if (port < 1 || port > sa->ports) {
99 printf("port out of range");
105 vlan = strtoul(argv[k++], NULL, 0);
106 if (vlan < VLAN_MIN || vlan > VLAN_PORT_MAX) {
107 printf("vlan out of range\n");
112 ports[port - 1] = vlan;
116 i = ngadmin_setVLANPortConf(nga, ports);
126 int do_vlan_port_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
128 unsigned char *ports = NULL;
129 const struct swi_attr *sa;
134 printf("this command takes no argument\n");
139 sa = ngadmin_getCurrentSwitch(nga);
141 printf("must be logged\n");
146 ports = malloc(sa->ports * sizeof(unsigned char));
148 /* request all VLANs config */
149 i = ngadmin_getVLANPortConf(nga, ports);
157 printf("Ports configuration: \n");
159 for (i = 1; i <= sa->ports; i++)
165 for (i = 0; i < sa->ports; i++)
166 printf("%u\t", ports[i]);
176 int do_vlan_8021q_set (int argc, const char **argv, struct ngadmin *nga)
178 unsigned char *ports = NULL, p, def = VLAN_UNSPEC;
179 const struct swi_attr *sa;
181 int i, k = 0, ret = 0;
185 printf("usage: vlan 802.1q set <vlan> [all unspec|no|untagged|tagged] [<port1> unspec|no|untagged|tagged ...]\n");
190 sa = ngadmin_getCurrentSwitch(nga);
192 printf("must be logged\n");
198 vlan = strtoul(argv[k++], NULL, 0);
200 if (vlan < VLAN_MIN || vlan > VLAN_DOT_MAX) {
201 printf("vlan out of range\n");
207 if (k < argc - 1 && strcasecmp(argv[k], "all") == 0) {
209 if (strcasecmp(argv[k], "tagged") == 0) {
211 } else if (strcasecmp(argv[k], "untagged") == 0) {
213 } else if (strcasecmp(argv[k], "no") == 0) {
215 } else if (strcasecmp(argv[k], "unspec") == 0) {
218 printf("incorrect type\n");
225 ports = malloc(sa->ports * sizeof(unsigned char));
228 memset(ports, def, sa->ports);
230 /* read and apply port specifics */
231 while (k < argc - 1) {
232 p = strtoul(argv[k++], NULL, 0) - 1;
233 if (p >= sa->ports) {
234 printf("port out of range\n");
238 if (strcasecmp(argv[k], "tagged") ==0) {
239 ports[p] = VLAN_TAGGED;
240 } else if (strcasecmp(argv[k], "untagged") == 0) {
241 ports[p] = VLAN_UNTAGGED;
242 } else if (strcasecmp(argv[k], "no") == 0) {
244 } else if (strcasecmp(argv[k], "unspec") == 0) {
245 ports[p] = VLAN_UNSPEC;
247 printf("incorrect type\n");
255 i = ngadmin_setVLANDotConf(nga, vlan, ports);
265 int do_vlan_8021q_show (int argc, const char **argv, struct ngadmin *nga)
267 unsigned short vl = 0, *vlans = NULL;
268 unsigned char *ports = NULL;
269 const struct swi_attr *sa;
270 int i, j, n = 16, ret = 0;
273 sa = ngadmin_getCurrentSwitch(nga);
275 printf("must be logged\n");
281 vl = strtoul(argv[0], NULL, 0);
283 ports = malloc(sa->ports * n * sizeof(unsigned char));
286 /* request all VLANs config */
287 vlans = malloc(n * sizeof(unsigned short));
288 ports = malloc(sa->ports * n * sizeof(unsigned char));
289 i = ngadmin_getVLANDotAllConf(nga, vlans, ports, &n);
291 /* request single VLAN config */
292 ports = malloc(sa->ports * sizeof(unsigned char));
293 i = ngadmin_getVLANDotConf(nga, vl, ports);
302 printf("Ports configuration: \n");
304 for (i = 1; i <= sa->ports; i++)
310 for (i = 0; i < n; i++) {
311 printf("%u\t", vlans[i]);
312 for (j = 0; j < sa->ports; j++)
313 printf("%c\t", vlan_char(ports[i * sa->ports + j]));
317 /* show single VLAN config */
319 for (j = 0; j < sa->ports; j++)
320 printf("%c\t", vlan_char(ports[j]));
332 int do_vlan_mode_set (int argc, const char **argv, struct ngadmin *nga)
339 "usage: vlan mode set <mode>\n"
340 "1 - basic port based\n"
341 "2 - advanced port based\n"
343 "4 - advanced 802.1Q\n"
348 if (ngadmin_getCurrentSwitch(nga) == NULL) {
349 printf("must be logged\n");
353 mode = strtoul(argv[0], NULL, 0);
354 if (mode < 1 || mode > 4) {
355 printf("mode out of range\n");
359 i = ngadmin_setVLANType(nga, mode);
367 int do_vlan_mode_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
373 printf("this command takes no argument\n");
378 if (ngadmin_getCurrentSwitch(nga) == NULL) {
379 printf("must be logged\n");
384 i = ngadmin_getVLANType(nga, &t);
391 printf("VLAN type: ");
395 printf("disabled\n");
398 case VLAN_PORT_BASIC:
399 printf("port basic\n");
403 printf("port advanced\n");
407 printf("802.1Q basic\n");
411 printf("802.1Q advanced\n");
415 printf("unknown (%i)\n", t);
424 int do_vlan_pvid_set (int argc, const char **argv, struct ngadmin *nga)
426 const struct swi_attr *sa;
433 printf("usage: vlan pvid set <port> <vlan>\n");
437 sa = ngadmin_getCurrentSwitch(nga);
439 printf("must be logged\n");
443 port = strtoul(argv[0], NULL, 0);
444 vlan = strtoul(argv[1], NULL, 0);
446 if (port < 1 || port > sa->ports) {
447 printf("port out of range\n");
451 if (vlan < VLAN_MIN || vlan > VLAN_DOT_MAX) {
452 printf("vlan out of range\n");
456 i = ngadmin_setPVID(nga, port, vlan);
464 int do_vlan_pvid_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
466 unsigned short *ports = NULL;
467 const struct swi_attr *sa;
472 printf("this command takes no argument\n");
477 sa = ngadmin_getCurrentSwitch(nga);
479 printf("must be logged\n");
484 ports = malloc(sa->ports * sizeof(unsigned short));
485 i = ngadmin_getAllPVID(nga, ports);
493 for (i = 1; i <= sa->ports; i++)
498 for (i = 0; i < sa->ports; i++)
499 printf("%u\t", ports[i]);