]> git.sur5r.net Git - ngadmin/blob - cli/com_mirror.c
67cbb04c781eaa16d83146d79bb0bbf72dfc9fb5
[ngadmin] / cli / com_mirror.c
1
2 #include "commands.h"
3
4
5
6
7 bool do_mirror_disable (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
8  
9  int i;
10  
11  
12  if ( ngadmin_getCurrentSwitch(nga)==NULL ) {
13   printf("must be logged\n");
14   return false;
15  }
16  
17  
18  i=ngadmin_setMirror(nga, NULL);
19  printErrCode(i);
20  
21  
22  return true;
23  
24 }
25
26
27
28 bool do_mirror_set (int nb, const char **com, struct ngadmin *nga) {
29  
30  const struct swi_attr *sa;
31  char *ports=NULL;
32  bool ret=true;
33  int i, k=0;
34  
35  
36  if ( nb<3 ) {
37   printf("Usage: mirror set <destination port> clone <port1> [<port2> ...]\n");
38   goto end;
39  }
40  
41  if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
42   printf("must be logged\n");
43   ret=false;
44   goto end;
45  }
46  
47  
48  ports=malloc((sa->ports+1)*sizeof(char));
49  memset(ports, 0, sa->ports+1);
50  
51  ports[0]=strtol(com[k++], NULL, 0);
52  if ( ports[0]<1 || ports[0]>sa->ports || strcasecmp(com[k++], "clone")!=0 ) {
53   printf("syntax error\n");
54   ret=false;
55   goto end;
56  }
57  
58  
59  while ( k<nb ) {
60   i=strtol(com[k++], NULL, 0);
61   if ( i<1 || i>sa->ports ) {
62    printf("port out of range\n");
63    ret=false;
64    goto end;
65   } else if ( i==ports[0] ) {
66    printf("destination port cannot be in port list\n");
67    ret=false;
68    goto end;
69   }
70   ports[i]=1;
71  }
72  
73  
74  i=ngadmin_setMirror(nga, ports);
75  printErrCode(i);
76  
77  
78  end:
79  free(ports);
80  
81  return ret;
82  
83 }
84
85
86
87 bool do_mirror_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) {
88  
89  const struct swi_attr *sa;
90  char *ports=NULL;
91  int i;
92  
93  
94  if ( (sa=ngadmin_getCurrentSwitch(nga))==NULL ) {
95   printf("must be logged\n");
96   return false;
97  }
98  
99  
100  ports=malloc((sa->ports+1)*sizeof(char));
101  
102  i=ngadmin_getMirror(nga, ports);
103  if ( i!=ERR_OK ) {
104   printErrCode(i);
105   goto end;
106  }
107  
108  if ( ports[0]==0 ) {
109   printf("port mirroring is disabled\n");
110   goto end;
111  }
112  
113  printf("destination: %i\n", ports[0]);
114  printf("ports: ");
115  for (i=1; i<=sa->ports; ++i) {
116   if ( ports[i] ) {
117    printf("%i ", i);
118   }
119  }
120  printf("\n");
121  
122  
123  
124  end:
125  free(ports);
126  
127  return true;
128  
129 }
130
131
132