7 static char vlan_char (int t) {
10 case VLAN_TAGGED: return 'T';
11 case VLAN_UNTAGGED: return 'U';
12 case VLAN_NO: return ' ';
20 bool do_vlan_8021q_del (int nb, const char **com, struct ngadmin *nga) {
22 const struct swi_attr *sa;
28 printf("Usage: vlan 8021q del <vlan>\n");
32 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
33 printf("must be logged\n");
37 vlan=strtoul(com[0], NULL, 0);
39 if ( vlan<1 || vlan>VLAN_MAX ) {
40 printf("vlan out of range\n");
45 i=ngadmin_VLANDestroy(nga, vlan);
55 bool do_vlan_8021q_set (int nb, const char **com, struct ngadmin *nga) {
57 unsigned char *ports=NULL, p, def=VLAN_UNSPEC;
58 const struct swi_attr *sa;
65 printf("Usage: vlan 802.1q set <vlan> [all unspec|no|untagged|tagged] [<port1> unspec|no|untagged|tagged ...]\n");
70 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
71 printf("must be logged\n");
77 vlan=strtoul(com[k++], NULL, 0);
79 if ( vlan<1 || vlan>VLAN_MAX ) {
80 printf("vlan out of range\n");
87 if ( k<nb-1 && strcasecmp(com[k], "all")==0 ) {
89 if ( strcasecmp(com[k], "tagged")==0 ) def=VLAN_TAGGED;
90 else if ( strcasecmp(com[k], "untagged")==0 ) def=VLAN_UNTAGGED;
91 else if ( strcasecmp(com[k], "no")==0 ) def=VLAN_NO;
92 else if ( strcasecmp(com[k], "unspec")==0 ) def=VLAN_UNSPEC;
94 printf("incorrect type\n");
101 ports=malloc(sa->ports*sizeof(unsigned char));
104 memset(ports, def, sa->ports);
106 // apply port specifics
108 p=strtoul(com[k++], NULL, 0)-1;
109 if ( p>=sa->ports ) {
110 printf("port out of range\n");
114 if ( strcasecmp(com[k], "tagged")==0 ) ports[p]=VLAN_TAGGED;
115 else if ( strcasecmp(com[k], "untagged")==0 ) ports[p]=VLAN_UNTAGGED;
116 else if ( strcasecmp(com[k], "no")==0 ) ports[p]=VLAN_NO;
117 else if ( strcasecmp(com[k], "unspec")==0 ) ports[p]=VLAN_UNSPEC;
119 printf("incorrect type\n");
128 i=ngadmin_setVLANDotConf(nga, vlan, ports);
142 bool do_vlan_8021q_show (int nb, const char **com, struct ngadmin *nga) {
144 unsigned short vl=0, *vlans=NULL;
145 unsigned char *ports=NULL;
146 const struct swi_attr *sa;
151 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
152 printf("must be logged\n");
158 vl=strtoul(com[0], NULL, 0);
162 ports=malloc(sa->ports*n*sizeof(unsigned char));
165 vlans=malloc(n*sizeof(unsigned short));
166 ports=malloc(sa->ports*n*sizeof(unsigned char));
167 i=ngadmin_getVLANDotAllConf(nga, vlans, ports, &n);
169 ports=malloc(sa->ports*sizeof(unsigned char));
170 i=ngadmin_getVLANDotConf(nga, vl, ports);
180 printf("Ports configuration: \n");
182 for (i=1; i<=sa->ports; ++i) {
189 for (i=0; i<n; ++i) {
190 printf("%u\t", vlans[i]);
191 for (j=0; j<sa->ports; ++j) {
192 printf("%c\t", vlan_char(ports[i*sa->ports+j]));
200 for (j=0; j<sa->ports; ++j) {
201 printf("%c\t", vlan_char(ports[j]));
219 bool do_vlan_mode_set (int nb, const char **com, struct ngadmin *nga) {
225 printf("Usage: vlan mode set <mode>\n");
226 printf("1 - basic port based\n");
227 printf("2 - advanced port based\n");
228 printf("3 - basic 802.1Q\n");
229 printf("4 - advanced 802.1Q\n");
233 if ( ngadmin_getCurrentSwitch(nga)==NULL ) {
234 printf("must be logged\n");
239 mode=strtoul(com[0], NULL, 0);
241 if ( mode<1 || mode>4 ) {
242 printf("mode out of range\n");
247 i=ngadmin_setVLANType(nga, mode);
257 bool do_vlan_mode_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
262 if ( ngadmin_getCurrentSwitch(nga)==NULL ) {
263 printf("must be logged\n");
268 if ( (i=ngadmin_getVLANType(nga, &t))!=ERR_OK ) {
274 printf("VLAN type: ");
276 case VLAN_DISABLED: printf("disabled\n"); break;
277 case VLAN_PORT_BASIC: printf("port basic\n"); break;
278 case VLAN_PORT_ADV: printf("port advanced\n"); break;
279 case VLAN_DOT_BASIC: printf("802.1Q basic\n"); break;
280 case VLAN_DOT_ADV:printf("802.1Q advanced\n");break;
281 default: printf("unknown (%i)\n", t);
293 bool do_vlan_pvid_set (int nb, const char **com, struct ngadmin *nga) {
295 const struct swi_attr *sa;
302 printf("Usage: vlan pvid set <port> <vlan>\n");
306 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
307 printf("must be logged\n");
311 port=strtoul(com[0], NULL, 0);
312 vlan=strtoul(com[1], NULL, 0);
314 if ( port<1 || port>sa->ports ) {
315 printf("port out of range\n");
319 if ( vlan<1 || vlan>VLAN_MAX ) {
320 printf("vlan out of range\n");
325 i=ngadmin_setPVID(nga, port, vlan);
335 bool do_vlan_pvid_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
337 unsigned short *ports=NULL;
338 const struct swi_attr *sa;
343 if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
344 printf("must be logged\n");
349 ports=malloc(sa->ports*sizeof(unsigned short));
350 i=ngadmin_getAllPVID(nga, ports);
360 for (i=1; i<=sa->ports; ++i) {
366 for (i=0; i<sa->ports; ++i) {
367 printf("%u\t", ports[i]);