]> git.sur5r.net Git - ngadmin/blob - cli/com_vlan.c
14be7845caa2755b19a7fb05e5a3907a01aeeafb
[ngadmin] / cli / com_vlan.c
1
2 #include "commands.h"
3
4
5
6
7 static char vlan_char (int t) {
8  
9  switch ( t ) {
10   case VLAN_TAGGED: return 'T';
11   case VLAN_UNTAGGED: return 'U'; 
12   case VLAN_NO: return ' ';
13   default: return '?';
14  }
15  
16 }
17
18
19
20 bool do_vlan_8021q_show (int nb, const char **com, struct ngadmin *nga) {
21  
22  unsigned short vl=0, *vlans=NULL;
23  unsigned char *ports=NULL;
24  const struct swi_attr *sa;
25  int i, j, n=16;
26  bool ret=true;
27  
28  
29  if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
30   printf("must be logged\n");
31   ret=false;
32   goto end;
33  }
34  
35  if ( nb>0 ) {
36   vl=strtoul(com[0], NULL, 0);
37  }
38  
39  
40  ports=malloc(sa->ports*n*sizeof(unsigned char));
41  
42  if ( vl==0 ) {
43   vlans=malloc(n*sizeof(unsigned short));
44   ports=malloc(sa->ports*n*sizeof(unsigned char));
45   i=ngadmin_getVLANDotAllConf(nga, vlans, ports, &n);
46  } else {
47   ports=malloc(sa->ports*sizeof(unsigned char));
48   i=ngadmin_getVLANDotConf(nga, vl, ports);
49  }
50  
51  if ( i!=ERR_OK ) {
52   printErrCode(i);
53   ret=false;
54   goto end;
55  }
56  
57  
58  printf("Ports configuration: \n");
59  printf("VLAN\t");
60  for (i=1; i<=sa->ports; ++i) {
61   printf("%i\t", i);
62  }
63  putchar('\n');
64  
65  if ( vl==0 ) {
66   
67   for (i=0; i<n; ++i) {
68    printf("%u\t", vlans[i]);
69    for (j=0; j<sa->ports; ++j) {
70     printf("%c\t", vlan_char(ports[i*sa->ports+j]));
71    }
72    putchar('\n');
73   }
74   
75  } else {
76   
77   printf("%u\t", vl);
78   for (j=0; j<sa->ports; ++j) {
79    printf("%c\t", vlan_char(ports[j]));
80   }
81   putchar('\n');
82   
83  }
84  
85  
86  end:
87  free(vlans);
88  free(ports);
89  
90  
91  return ret;
92  
93 }
94
95
96
97 bool do_vlan_mode_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
98  
99  int i, t, ret=true;
100  
101  
102  if ( ngadmin_getCurrentSwitch(nga)==NULL ) {
103   printf("must be logged\n");
104   ret=false;
105   goto end;
106  }
107  
108  if ( (i=ngadmin_getVLANType(nga, &t))!=ERR_OK ) {
109   printErrCode(i);
110   ret=false;
111   goto end;
112  }
113  
114  printf("VLAN type: ");
115  switch ( t ) {
116   case VLAN_DISABLED: printf("disabled\n"); break;
117   case VLAN_PORT_BASIC: printf("port basic\n"); break;
118   case VLAN_PORT_ADV: printf("port advanced\n"); break;
119   case VLAN_DOT_BASIC: printf("802.1Q basic\n"); break;
120   case VLAN_DOT_ADV:printf("802.1Q advanced\n");break;
121   default: printf("unknown (%i)\n", t);
122  }
123  
124  
125  end:
126  
127  return ret;
128  
129 }
130
131
132
133 bool do_vlan_pvid_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
134  
135  unsigned short *ports=NULL;
136  const struct swi_attr *sa;
137  int i;
138  bool ret=true;
139  
140  
141  if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
142   printf("must be logged\n");
143   ret=false;
144   goto end;
145  }
146  
147  ports=malloc(sa->ports*sizeof(unsigned short));
148  i=ngadmin_getPVID(nga, ports);
149  if ( i!=ERR_OK ) {
150   printErrCode(i);
151   ret=false;
152   goto end;
153  }
154  
155  
156  printf("PVID: \n");
157  printf("Port\t");
158  for (i=1; i<=sa->ports; ++i) {
159   printf("%i\t", i);
160  }
161  putchar('\n');
162  
163  printf("VLAN\t");
164  for (i=0; i<sa->ports; ++i) {
165   printf("%u\t", ports[i]);
166  }
167  putchar('\n');
168  
169  
170  end:
171  free(ports);
172  
173  return ret;
174  
175 }
176
177