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 vlan = strtoul(argv[k++], NULL, 0);
84 /* VLAN 0 is allowed and means no change */
85 if (vlan > VLAN_PORT_MAX) {
86 printf("vlan out of range\n");
93 memset(ports, vlan, sa->ports);
95 /* read and apply port specifics */
96 while (k < argc - 1) {
98 port = strtoul(argv[k++], NULL, 0);
99 if (port < 1 || port > sa->ports) {
100 printf("port out of range\n");
106 vlan = strtoul(argv[k++], NULL, 0);
107 /* VLAN 0 is allowed and means no change */
108 if (vlan > VLAN_PORT_MAX) {
109 printf("vlan out of range\n");
114 ports[port - 1] = vlan;
118 i = ngadmin_setVLANPortConf(nga, ports);
128 int do_vlan_port_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
130 unsigned char *ports = NULL;
131 const struct swi_attr *sa;
136 printf("this command takes no argument\n");
141 sa = ngadmin_getCurrentSwitch(nga);
143 printf("must be logged\n");
148 ports = malloc(sa->ports * sizeof(unsigned char));
150 /* request all VLANs config */
151 i = ngadmin_getVLANPortConf(nga, ports);
159 printf("Ports configuration: \n");
161 for (i = 1; i <= sa->ports; i++)
167 for (i = 0; i < sa->ports; i++)
168 printf("%u\t", ports[i]);
178 int do_vlan_8021q_set (int argc, const char **argv, struct ngadmin *nga)
180 unsigned char *ports = NULL, p, def = VLAN_UNSPEC;
181 const struct swi_attr *sa;
183 int i, k = 0, ret = 0;
187 printf("usage: vlan 802.1q set <vlan> [all unspec|no|untagged|tagged] [<port1> unspec|no|untagged|tagged ...]\n");
192 sa = ngadmin_getCurrentSwitch(nga);
194 printf("must be logged\n");
200 vlan = strtoul(argv[k++], NULL, 0);
202 if (vlan < VLAN_MIN || vlan > VLAN_DOT_MAX) {
203 printf("vlan out of range\n");
209 if (k < argc - 1 && strcasecmp(argv[k], "all") == 0) {
211 if (strcasecmp(argv[k], "tagged") == 0) {
213 } else if (strcasecmp(argv[k], "untagged") == 0) {
215 } else if (strcasecmp(argv[k], "no") == 0) {
217 } else if (strcasecmp(argv[k], "unspec") == 0) {
220 printf("incorrect type\n");
227 ports = malloc(sa->ports * sizeof(unsigned char));
230 memset(ports, def, sa->ports);
232 /* read and apply port specifics */
233 while (k < argc - 1) {
234 p = strtoul(argv[k++], NULL, 0) - 1;
235 if (p >= sa->ports) {
236 printf("port out of range\n");
240 if (strcasecmp(argv[k], "tagged") ==0) {
241 ports[p] = VLAN_TAGGED;
242 } else if (strcasecmp(argv[k], "untagged") == 0) {
243 ports[p] = VLAN_UNTAGGED;
244 } else if (strcasecmp(argv[k], "no") == 0) {
246 } else if (strcasecmp(argv[k], "unspec") == 0) {
247 ports[p] = VLAN_UNSPEC;
249 printf("incorrect type\n");
257 i = ngadmin_setVLANDotConf(nga, vlan, ports);
267 int do_vlan_8021q_show (int argc, const char **argv, struct ngadmin *nga)
269 unsigned short vl = 0, *vlans = NULL;
270 unsigned char *ports = NULL;
271 const struct swi_attr *sa;
272 int i, j, n = 16, ret = 0;
275 sa = ngadmin_getCurrentSwitch(nga);
277 printf("must be logged\n");
283 vl = strtoul(argv[0], NULL, 0);
285 ports = malloc(sa->ports * n * sizeof(unsigned char));
288 /* request all VLANs config */
289 vlans = malloc(n * sizeof(unsigned short));
290 ports = malloc(sa->ports * n * sizeof(unsigned char));
291 i = ngadmin_getVLANDotAllConf(nga, vlans, ports, &n);
293 /* request single VLAN config */
294 ports = malloc(sa->ports * sizeof(unsigned char));
295 i = ngadmin_getVLANDotConf(nga, vl, ports);
304 printf("Ports configuration: \n");
306 for (i = 1; i <= sa->ports; i++)
312 for (i = 0; i < n; i++) {
313 printf("%u\t", vlans[i]);
314 for (j = 0; j < sa->ports; j++)
315 printf("%c\t", vlan_char(ports[i * sa->ports + j]));
319 /* show single VLAN config */
321 for (j = 0; j < sa->ports; j++)
322 printf("%c\t", vlan_char(ports[j]));
334 int do_vlan_mode_set (int argc, const char **argv, struct ngadmin *nga)
341 "usage: vlan mode set <mode>\n"
343 "1 - basic port based\n"
344 "2 - advanced port based\n"
346 "4 - advanced 802.1Q\n"
351 if (ngadmin_getCurrentSwitch(nga) == NULL) {
352 printf("must be logged\n");
356 mode = strtoul(argv[0], NULL, 0);
357 if (mode < VLAN_DISABLED || mode > VLAN_DOT_ADV) {
358 printf("mode out of range\n");
362 i = ngadmin_setVLANType(nga, mode);
370 int do_vlan_mode_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
376 printf("this command takes no argument\n");
381 if (ngadmin_getCurrentSwitch(nga) == NULL) {
382 printf("must be logged\n");
387 i = ngadmin_getVLANType(nga, &t);
394 printf("VLAN type: %s\n", safeStr(getVlanTypeStr(t)));
402 int do_vlan_pvid_set (int argc, const char **argv, struct ngadmin *nga)
404 const struct swi_attr *sa;
411 printf("usage: vlan pvid set <port> <vlan>\n");
415 sa = ngadmin_getCurrentSwitch(nga);
417 printf("must be logged\n");
421 port = strtoul(argv[0], NULL, 0);
422 vlan = strtoul(argv[1], NULL, 0);
424 if (port < 1 || port > sa->ports) {
425 printf("port out of range\n");
429 if (vlan < VLAN_MIN || vlan > VLAN_DOT_MAX) {
430 printf("vlan out of range\n");
434 i = ngadmin_setPVID(nga, port, vlan);
442 int do_vlan_pvid_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
444 unsigned short *ports = NULL;
445 const struct swi_attr *sa;
450 printf("this command takes no argument\n");
455 sa = ngadmin_getCurrentSwitch(nga);
457 printf("must be logged\n");
462 ports = malloc(sa->ports * sizeof(unsigned short));
463 i = ngadmin_getAllPVID(nga, ports);
471 for (i = 1; i <= sa->ports; i++)
476 for (i = 0; i < sa->ports; i++)
477 printf("%u\t", ports[i]);