K2.6 patches and update.
[tomato.git] / release / src-rt / emf / igsconf / igsu.c
blobe10b564a8a363c44e282f91672de45e8f5a049be
1 /*
2 * IGSL Command Line Utility: This utility can be used to add/remove
3 * snooping capability on desired bridge interface.
5 * Copyright (C) 2010, Broadcom Corporation
6 * All Rights Reserved.
7 *
8 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
9 * the contents of this file may not be disclosed to third parties, copied
10 * or duplicated in any form, in whole or in part, without the prior
11 * written permission of Broadcom Corporation.
13 * $Id: igsu.c 241182 2011-02-17 21:50:03Z gmo $
15 #include <stdio.h>
16 #include <sys/types.h>
17 #include <typedefs.h>
18 #include <string.h>
19 #include <ctype.h>
20 #include <errno.h>
21 #include <stdlib.h>
22 #include <errno.h>
23 #include <netinet/in.h>
24 #include <arpa/inet.h>
25 #if defined(linux)
26 #include "igsu_linux.h"
27 #else /* defined(vxworks) */
28 #error "Unsupported osl"
29 #endif
30 #include <igs_cfg.h>
31 #include "igsu.h"
33 #define MAX_DATA_SIZE sizeof(igs_cfg_request_t)
35 static int igs_cfg_bridge_add(char *argv[]);
36 static int igs_cfg_bridge_del(char *argv[]);
37 static int igs_cfg_bridge_list(char *argv[]);
38 static int igs_cfg_sdb_list(char *argv[]);
39 static int igs_cfg_rtport_list(char *argv[]);
40 static int igs_cfg_stats_show(char *argv[]);
42 static igs_cmd_arg_t cmd_args[] =
45 "add",
46 "bridge",
47 igs_cfg_bridge_add,
48 IGS_ARGC_ADD_BRIDGE
51 "del",
52 "bridge",
53 igs_cfg_bridge_del,
54 IGS_ARGC_DEL_BRIDGE
57 "list",
58 "bridge",
59 igs_cfg_bridge_list,
60 IGS_ARGC_LIST_BRIDGE
63 "list",
64 "sdb",
65 igs_cfg_sdb_list,
66 IGS_ARGC_LIST_IGSDB
69 "list",
70 "rtport",
71 igs_cfg_rtport_list,
72 IGS_ARGC_LIST_RTPORT
75 "show",
76 "stats",
77 igs_cfg_stats_show,
78 IGS_ARGC_SHOW_STATS
82 static void
83 igs_usage(FILE *fid)
85 fprintf(fid, IGS_USAGE);
86 return;
89 static int
90 igs_cfg_bridge_add(char *argv[])
92 igs_cfg_request_t req;
94 bzero((char *)&req, sizeof(igs_cfg_request_t));
96 strcpy((char *)req.inst_id, argv[3]);
97 req.command_id = IGSCFG_CMD_BR_ADD;
98 req.oper_type = IGSCFG_OPER_TYPE_SET;
100 /* Send request to kernel */
101 if (igs_cfg_request_send(&req, sizeof(igs_cfg_request_t)) < 0)
103 fprintf(stderr, "Unable to send request to IGS\n");
104 return (FAILURE);
107 if (req.status != IGSCFG_STATUS_SUCCESS)
109 fprintf(stderr, "%s\n", req.arg);
110 return (FAILURE);
113 return (SUCCESS);
116 static int
117 igs_cfg_bridge_del(char *argv[])
119 igs_cfg_request_t req;
121 bzero((char *)&req, sizeof(igs_cfg_request_t));
123 strcpy((char *)req.inst_id, argv[3]);
124 req.command_id = IGSCFG_CMD_BR_DEL;
125 req.oper_type = IGSCFG_OPER_TYPE_SET;
127 /* Send request to kernel */
128 if (igs_cfg_request_send(&req, sizeof(igs_cfg_request_t)) < 0)
130 fprintf(stderr, "Unable to send request to IGS\n");
131 return (FAILURE);
134 if (req.status != IGSCFG_STATUS_SUCCESS)
136 fprintf(stderr, "%s\n", req.arg);
137 return (FAILURE);
140 return (SUCCESS);
143 static int
144 igs_cfg_bridge_list(char *argv[])
146 fprintf(stdout, "TBD\n");
147 return (SUCCESS);
150 static int
151 igs_cfg_sdb_list(char *argv[])
153 igs_cfg_request_t req;
154 igs_cfg_sdb_list_t *list;
155 bool first_row = TRUE;
156 int32 i;
158 strcpy((char *)req.inst_id, argv[3]);
159 req.command_id = IGSCFG_CMD_IGSDB_LIST;
160 req.oper_type = IGSCFG_OPER_TYPE_GET;
161 req.size = sizeof(req.arg);
162 list = (igs_cfg_sdb_list_t *)req.arg;
164 if (igs_cfg_request_send(&req, sizeof(igs_cfg_request_t)) < 0)
166 fprintf(stderr, "Unable to send request to IGS\n");
167 return (FAILURE);
170 if (req.status != IGSCFG_STATUS_SUCCESS)
172 fprintf(stderr, "Unable to get the IGSDB list\n");
173 fprintf(stderr, "%s\n", req.arg);
174 return (FAILURE);
177 fprintf(stdout, "Group Members Interface\n");
179 for (i = 0; i < list->num_entries; i++)
181 first_row = TRUE;
182 fprintf(stdout, "%08x ", list->sdb_entry[i].mgrp_ip);
183 if (first_row)
185 fprintf(stdout, "%08x ", list->sdb_entry[i].mh_ip);
186 fprintf(stdout, "%s\n", list->sdb_entry[i].if_name);
187 first_row = FALSE;
188 continue;
190 fprintf(stdout, " ");
191 fprintf(stdout, "%08x ", list->sdb_entry[i].mh_ip);
192 fprintf(stdout, "%s\n", list->sdb_entry[i].if_name);
195 return (SUCCESS);
198 static int
199 igs_cfg_rtport_list(char *argv[])
201 igs_cfg_request_t req;
202 igs_cfg_rtport_list_t *list;
203 int32 i;
205 bzero((char *)&req, sizeof(igs_cfg_request_t));
207 strcpy((char *)req.inst_id, argv[3]);
208 req.command_id = IGSCFG_CMD_RTPORT_LIST;
209 req.oper_type = IGSCFG_OPER_TYPE_GET;
210 req.size = sizeof(req.arg);
212 /* Send request to kernel */
213 if (igs_cfg_request_send(&req, sizeof(igs_cfg_request_t)) < 0)
215 fprintf(stderr, "Unable to send request to IGS\n");
216 return (FAILURE);
219 if (req.status != IGSCFG_STATUS_SUCCESS)
221 fprintf(stderr, "%s\n", req.arg);
222 return (FAILURE);
225 fprintf(stdout, "Router Interface\n");
227 list = (igs_cfg_rtport_list_t *)req.arg;
228 for (i = 0; i < list->num_entries; i++)
230 fprintf(stdout, "%08x ", list->rtport_entry[i].mr_ip);
231 fprintf(stdout, "%-15s", list->rtport_entry[i].if_name);
234 fprintf(stdout, "\n");
236 return (SUCCESS);
239 static int
240 igs_cfg_stats_show(char *argv[])
242 igs_cfg_request_t req;
243 igs_stats_t *igss;
245 strcpy((char *)req.inst_id, argv[3]);
246 req.command_id = IGSCFG_CMD_IGS_STATS;
247 req.oper_type = IGSCFG_OPER_TYPE_GET;
248 req.size = sizeof(igs_stats_t);
249 igss = (igs_stats_t *)req.arg;
251 if (igs_cfg_request_send(&req, sizeof(igs_cfg_request_t)) < 0)
253 fprintf(stderr, "Unable to send request to IGS\n");
254 return (FAILURE);
257 if (req.status != IGSCFG_STATUS_SUCCESS)
259 fprintf(stderr, "Unable to get the IGS stats\n");
260 return (FAILURE);
263 fprintf(stdout, "IgmpPkts IgmpQueries "
264 "IgmpReports IgmpV2Reports IgmpLeaves\n");
265 fprintf(stdout, "%-15d %-15d %-15d %-15d %d\n",
266 igss->igmp_packets, igss->igmp_queries,
267 igss->igmp_reports, igss->igmp_v2reports,
268 igss->igmp_leaves);
269 fprintf(stdout, "IgmpNotHandled McastGroups "
270 "McastMembers MemTimeouts\n");
271 fprintf(stdout, "%-15d %-15d %-15d %d\n",
272 igss->igmp_not_handled, igss->igmp_mcast_groups,
273 igss->igmp_mcast_members, igss->igmp_mem_timeouts);
275 return (SUCCESS);
279 #if defined(linux)
280 main(int argc, char *argv[])
281 #else /* defined(vxworks) */
282 #error "Unsupported osl"
283 #endif
285 int j, ret;
286 bool cmd_syntax = FALSE;
288 if (argc < 2)
290 igs_usage(stdout);
291 return (SUCCESS);
294 /* Find the command type */
295 for (j = 0; j < sizeof(cmd_args)/sizeof(cmd_args[0]); j++)
297 if ((strcmp(argv[1], cmd_args[j].cmd_oper_str) == 0) &&
298 (argc - 1 == cmd_args[j].arg_count) &&
299 ((cmd_args[j].cmd_id_str == NULL) ||
300 ((argv[2] != NULL) &&
301 (strcmp(argv[2], cmd_args[j].cmd_id_str) == 0))))
303 cmd_syntax = TRUE;
304 break;
308 if (!cmd_syntax)
310 igs_usage(stdout);
311 return (SUCCESS);
314 /* Call the command processing function. This function parses
315 * prepare command request and sends it kernel.
317 if ((ret = cmd_args[j].input(argv)) < 0)
319 fprintf(stderr, "Command failed\n");
320 return (FAILURE);
323 return (SUCCESS);