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 < 1 || vlan > VLAN_MAX) {
45 printf("vlan out of range\n");
49 i = ngadmin_VLANDestroy(nga, vlan);
57 int do_vlan_8021q_set (int argc, const char **argv, struct ngadmin *nga)
59 unsigned char *ports = NULL, p, def = VLAN_UNSPEC;
60 const struct swi_attr *sa;
62 int i, k = 0, ret = 0;
66 printf("usage: vlan 802.1q set <vlan> [all unspec|no|untagged|tagged] [<port1> unspec|no|untagged|tagged ...]\n");
71 sa = ngadmin_getCurrentSwitch(nga);
73 printf("must be logged\n");
79 vlan = strtoul(argv[k++], NULL, 0);
81 if (vlan < 1 || vlan > VLAN_MAX) {
82 printf("vlan out of range\n");
88 if (k < argc - 1 && strcasecmp(argv[k], "all") == 0) {
90 if (strcasecmp(argv[k], "tagged") == 0) {
92 } else if (strcasecmp(argv[k], "untagged") == 0) {
94 } else if (strcasecmp(argv[k], "no") == 0) {
96 } else if (strcasecmp(argv[k], "unspec") == 0) {
99 printf("incorrect type\n");
106 ports = malloc(sa->ports * sizeof(unsigned char));
109 memset(ports, def, sa->ports);
111 /* apply port specifics */
112 while (k < argc - 1) {
113 p = strtoul(argv[k++], NULL, 0) - 1;
114 if (p >= sa->ports) {
115 printf("port out of range\n");
119 if (strcasecmp(argv[k], "tagged") ==0) {
120 ports[p] = VLAN_TAGGED;
121 } else if (strcasecmp(argv[k], "untagged") == 0) {
122 ports[p] = VLAN_UNTAGGED;
123 } else if (strcasecmp(argv[k], "no") == 0) {
125 } else if (strcasecmp(argv[k], "unspec") == 0) {
126 ports[p] = VLAN_UNSPEC;
128 printf("incorrect type\n");
136 i = ngadmin_setVLANDotConf(nga, vlan, ports);
146 int do_vlan_8021q_show (int argc, const char **argv, struct ngadmin *nga)
148 unsigned short vl = 0, *vlans = NULL;
149 unsigned char *ports = NULL;
150 const struct swi_attr *sa;
151 int i, j, n = 16, ret = 0;
154 sa = ngadmin_getCurrentSwitch(nga);
156 printf("must be logged\n");
162 vl = strtoul(argv[0], NULL, 0);
164 ports = malloc(sa->ports * n * sizeof(unsigned char));
167 /* request all VLANs config */
168 vlans = malloc(n * sizeof(unsigned short));
169 ports = malloc(sa->ports * n * sizeof(unsigned char));
170 i = ngadmin_getVLANDotAllConf(nga, vlans, ports, &n);
172 /* request single VLAN config */
173 ports = malloc(sa->ports * sizeof(unsigned char));
174 i = ngadmin_getVLANDotConf(nga, vl, ports);
183 printf("Ports configuration: \n");
185 for (i = 1; i <= sa->ports; i++)
191 for (i = 0; i < n; i++) {
192 printf("%u\t", vlans[i]);
193 for (j = 0; j < sa->ports; j++)
194 printf("%c\t", vlan_char(ports[i * sa->ports + j]));
198 /* show single VLAN config */
200 for (j = 0; j < sa->ports; j++)
201 printf("%c\t", vlan_char(ports[j]));
213 int do_vlan_mode_set (int argc, const char **argv, struct ngadmin *nga)
220 "usage: vlan mode set <mode>\n"
221 "1 - basic port based\n"
222 "2 - advanced port based\n"
224 "4 - advanced 802.1Q\n"
229 if (ngadmin_getCurrentSwitch(nga) == NULL) {
230 printf("must be logged\n");
234 mode = strtoul(argv[0], NULL, 0);
235 if (mode < 1 || mode > 4) {
236 printf("mode out of range\n");
240 i = ngadmin_setVLANType(nga, mode);
248 int do_vlan_mode_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
254 printf("this command takes no argument\n");
259 if (ngadmin_getCurrentSwitch(nga) == NULL) {
260 printf("must be logged\n");
265 i = ngadmin_getVLANType(nga, &t);
272 printf("VLAN type: ");
276 printf("disabled\n");
279 case VLAN_PORT_BASIC:
280 printf("port basic\n");
284 printf("port advanced\n");
288 printf("802.1Q basic\n");
292 printf("802.1Q advanced\n");
296 printf("unknown (%i)\n", t);
305 int do_vlan_pvid_set (int argc, const char **argv, struct ngadmin *nga)
307 const struct swi_attr *sa;
314 printf("usage: vlan pvid set <port> <vlan>\n");
318 sa = ngadmin_getCurrentSwitch(nga);
320 printf("must be logged\n");
324 port = strtoul(argv[0], NULL, 0);
325 vlan = strtoul(argv[1], NULL, 0);
327 if (port < 1 || port > sa->ports) {
328 printf("port out of range\n");
332 if (vlan < 1 || vlan > VLAN_MAX) {
333 printf("vlan out of range\n");
337 i = ngadmin_setPVID(nga, port, vlan);
345 int do_vlan_pvid_show (int argc, const char **argv UNUSED, struct ngadmin *nga)
347 unsigned short *ports = NULL;
348 const struct swi_attr *sa;
353 printf("this command takes no argument\n");
358 sa = ngadmin_getCurrentSwitch(nga);
360 printf("must be logged\n");
365 ports = malloc(sa->ports * sizeof(unsigned short));
366 i = ngadmin_getAllPVID(nga, ports);
374 for (i = 1; i <= sa->ports; i++)
379 for (i = 0; i < sa->ports; i++)
380 printf("%u\t", ports[i]);