2 * EMFL Command Line Utility: This utility can be used to start/stop
3 * EMF, enable/disable BSS forwarding, add/delete/list the Static
6 * Copyright (C) 2010, Broadcom Corporation
9 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
10 * the contents of this file may not be disclosed to third parties, copied
11 * or duplicated in any form, in whole or in part, without the prior
12 * written permission of Broadcom Corporation.
14 * $Id: emfu.c 241182 2011-02-17 21:50:03Z gmo $
17 #include <sys/types.h>
24 #include <netinet/in.h>
29 #include "emfu_linux.h"
30 #include <arpa/inet.h>
31 #else /* defined(vxworks) */
32 #error "Unsupported osl"
35 #define MAX_DATA_SIZE sizeof(emf_cfg_request_t)
37 static int emf_cfg_enable(char *argv
[]);
38 static int emf_cfg_disable(char *argv
[]);
39 static int emf_cfg_status_get(char *argv
[]);
40 static int emf_cfg_bridge_add(char *argv
[]);
41 static int emf_cfg_bridge_del(char *argv
[]);
42 static int emf_cfg_iface_add(char *argv
[]);
43 static int emf_cfg_iface_del(char *argv
[]);
44 static int emf_cfg_iface_list(char *argv
[]);
45 static int emf_cfg_uffp_add(char *argv
[]);
46 static int emf_cfg_uffp_del(char *argv
[]);
47 static int emf_cfg_uffp_list(char *argv
[]);
48 static int emf_cfg_mfdb_add(char *argv
[]);
49 static int emf_cfg_mfdb_del(char *argv
[]);
50 static int emf_cfg_mfdb_clear(char *argv
[]);
51 static int emf_cfg_mfdb_list(char *argv
[]);
52 static int emf_cfg_stats_show(char *argv
[]);
54 static emf_cmd_arg_t cmd_args
[] =
175 fprintf(fid
, EMF_USAGE
);
180 emf_cfg_enable(char *argv
[])
182 emf_cfg_request_t req
;
184 bzero((char *)&req
, sizeof(emf_cfg_request_t
));
186 strcpy((char *)req
.inst_id
, argv
[2]);
187 req
.command_id
= EMFCFG_CMD_EMF_ENABLE
;
188 req
.size
= sizeof(bool);
189 req
.oper_type
= EMFCFG_OPER_TYPE_SET
;
190 *(bool *)req
.arg
= TRUE
;
192 /* Send request to kernel */
193 if (emf_cfg_request_send(&req
, sizeof(emf_cfg_request_t
)) < 0)
195 fprintf(stderr
, "Unable to send request to EMF\n");
199 if (req
.status
!= EMFCFG_STATUS_SUCCESS
)
201 fprintf(stderr
, "%s\n", req
.arg
);
209 emf_cfg_disable(char *argv
[])
211 emf_cfg_request_t req
;
213 bzero((char *)&req
, sizeof(emf_cfg_request_t
));
215 strcpy((char *)req
.inst_id
, argv
[2]);
216 req
.command_id
= EMFCFG_CMD_EMF_ENABLE
;
217 req
.size
= sizeof(bool);
218 req
.oper_type
= EMFCFG_OPER_TYPE_SET
;
219 *(bool *)req
.arg
= FALSE
;
221 /* Send request to kernel */
222 if (emf_cfg_request_send(&req
, sizeof(emf_cfg_request_t
)) < 0)
224 fprintf(stderr
, "Unable to send request to EMF\n");
228 if (req
.status
!= EMFCFG_STATUS_SUCCESS
)
230 fprintf(stderr
, "%s\n", req
.arg
);
238 emf_cfg_status_get(char *argv
[])
240 emf_cfg_request_t req
;
242 bzero((char *)&req
, sizeof(emf_cfg_request_t
));
244 strcpy((char *)req
.inst_id
, argv
[2]);
245 req
.command_id
= EMFCFG_CMD_EMF_ENABLE
;
246 req
.oper_type
= EMFCFG_OPER_TYPE_GET
;
248 /* Send request to kernel */
249 if (emf_cfg_request_send(&req
, sizeof(emf_cfg_request_t
)) < 0)
251 fprintf(stderr
, "Unable to send request to EMF\n");
255 if (req
.status
!= EMFCFG_STATUS_SUCCESS
)
257 fprintf(stderr
, "%sUnable to read Multicast forwarding status\n", req
.arg
);
261 fprintf(stdout
, "Multicast forwarding status: %s",
262 (*(bool *)req
.arg
? "ENABLED\n" : "DISABLED\n"));
268 emf_cfg_bridge_add(char *argv
[])
270 emf_cfg_request_t req
;
272 bzero((char *)&req
, sizeof(emf_cfg_request_t
));
274 strcpy((char *)req
.inst_id
, argv
[3]);
275 req
.command_id
= EMFCFG_CMD_BR_ADD
;
276 req
.oper_type
= EMFCFG_OPER_TYPE_SET
;
278 /* Send request to kernel */
279 if (emf_cfg_request_send(&req
, sizeof(emf_cfg_request_t
)) < 0)
281 fprintf(stderr
, "Unable to send request to EMF\n");
285 if (req
.status
!= EMFCFG_STATUS_SUCCESS
)
287 fprintf(stderr
, "%s\n", req
.arg
);
295 emf_cfg_bridge_del(char *argv
[])
297 emf_cfg_request_t req
;
299 bzero((char *)&req
, sizeof(emf_cfg_request_t
));
301 strcpy((char *)req
.inst_id
, argv
[3]);
302 req
.command_id
= EMFCFG_CMD_BR_DEL
;
303 req
.oper_type
= EMFCFG_OPER_TYPE_SET
;
305 /* Send request to kernel */
306 if (emf_cfg_request_send(&req
, sizeof(emf_cfg_request_t
)) < 0)
308 fprintf(stderr
, "Unable to send request to EMF\n");
312 if (req
.status
!= EMFCFG_STATUS_SUCCESS
)
314 fprintf(stderr
, "%s\n", req
.arg
);
322 emf_cfg_iface_add(char *argv
[])
324 emf_cfg_request_t req
;
325 emf_cfg_if_t
*cfg_if
;
327 bzero((char *)&req
, sizeof(emf_cfg_request_t
));
329 strcpy((char *)req
.inst_id
, argv
[3]);
330 req
.command_id
= EMFCFG_CMD_IF_ADD
;
331 req
.oper_type
= EMFCFG_OPER_TYPE_SET
;
333 cfg_if
= (emf_cfg_if_t
*)req
.arg
;
334 strncpy((char *)cfg_if
->if_name
, argv
[4], 16);
335 cfg_if
->if_name
[15] = 0;
337 /* Send request to kernel */
338 if (emf_cfg_request_send(&req
, sizeof(emf_cfg_request_t
)) < 0)
340 fprintf(stderr
, "Unable to send request to EMF\n");
344 if (req
.status
!= EMFCFG_STATUS_SUCCESS
)
346 fprintf(stderr
, "%s\n", req
.arg
);
354 emf_cfg_iface_del(char *argv
[])
356 emf_cfg_request_t req
;
357 emf_cfg_if_t
*cfg_if
;
359 bzero((char *)&req
, sizeof(emf_cfg_request_t
));
361 strcpy((char *)req
.inst_id
, argv
[3]);
362 req
.command_id
= EMFCFG_CMD_IF_DEL
;
363 req
.oper_type
= EMFCFG_OPER_TYPE_SET
;
365 cfg_if
= (emf_cfg_if_t
*)req
.arg
;
366 strncpy((char *)cfg_if
->if_name
, argv
[4], 16);
367 cfg_if
->if_name
[15] = 0;
369 /* Send request to kernel */
370 if (emf_cfg_request_send(&req
, sizeof(emf_cfg_request_t
)) < 0)
372 fprintf(stderr
, "Unable to send request to EMF\n");
376 if (req
.status
!= EMFCFG_STATUS_SUCCESS
)
378 fprintf(stderr
, "%s\n", req
.arg
);
386 emf_cfg_iface_list(char *argv
[])
388 emf_cfg_request_t req
;
389 emf_cfg_if_list_t
*list
;
392 bzero((char *)&req
, sizeof(emf_cfg_request_t
));
394 strcpy((char *)req
.inst_id
, argv
[3]);
395 req
.command_id
= EMFCFG_CMD_IF_LIST
;
396 req
.oper_type
= EMFCFG_OPER_TYPE_GET
;
397 req
.size
= sizeof(req
.arg
);
399 /* Send request to kernel */
400 if (emf_cfg_request_send(&req
, sizeof(emf_cfg_request_t
)) < 0)
402 fprintf(stderr
, "Unable to send request to EMF\n");
406 if (req
.status
!= EMFCFG_STATUS_SUCCESS
)
408 fprintf(stderr
, "%s\n", req
.arg
);
412 fprintf(stdout
, "EMF enabled interfaces on %s: ", argv
[3]);
414 list
= (emf_cfg_if_list_t
*)req
.arg
;
415 for (i
= 0; i
< list
->num_entries
; i
++)
417 fprintf(stdout
, "%s ", list
->if_entry
[i
].if_name
);
420 fprintf(stdout
, "\n");
426 emf_cfg_uffp_add(char *argv
[])
428 emf_cfg_request_t req
;
429 emf_cfg_uffp_t
*cfg_uffp
;
430 emf_cfg_rtport_t
*cfg_rtport
;
432 bzero((char *)&req
, sizeof(emf_cfg_request_t
));
434 strcpy((char *)req
.inst_id
, argv
[3]);
436 if (strncmp(argv
[2], "uffp", 4) == 0)
438 req
.command_id
= EMFCFG_CMD_UFFP_ADD
;
439 cfg_uffp
= (emf_cfg_uffp_t
*)req
.arg
;
440 strncpy((char *)cfg_uffp
->if_name
, argv
[4], 16);
441 cfg_uffp
->if_name
[15] = 0;
445 req
.command_id
= EMFCFG_CMD_RTPORT_ADD
;
446 cfg_rtport
= (emf_cfg_rtport_t
*)req
.arg
;
447 strncpy((char *)cfg_rtport
->if_name
, argv
[4], 16);
448 cfg_rtport
->if_name
[15] = 0;
451 req
.oper_type
= EMFCFG_OPER_TYPE_SET
;
453 /* Send request to kernel */
454 if (emf_cfg_request_send(&req
, sizeof(emf_cfg_request_t
)) < 0)
456 fprintf(stderr
, "Unable to send request to EMF\n");
460 if (req
.status
!= EMFCFG_STATUS_SUCCESS
)
462 fprintf(stderr
, "%s\n", req
.arg
);
470 emf_cfg_uffp_del(char *argv
[])
472 emf_cfg_request_t req
;
473 emf_cfg_uffp_t
*cfg_uffp
;
474 emf_cfg_rtport_t
*cfg_rtport
;
476 bzero((char *)&req
, sizeof(emf_cfg_request_t
));
478 strcpy((char *)req
.inst_id
, argv
[3]);
480 if (strncmp(argv
[2], "uffp", 4) == 0)
482 req
.command_id
= EMFCFG_CMD_UFFP_DEL
;
483 cfg_uffp
= (emf_cfg_uffp_t
*)req
.arg
;
484 strncpy((char *)cfg_uffp
->if_name
, argv
[4], 16);
485 cfg_uffp
->if_name
[15] = 0;
489 req
.command_id
= EMFCFG_CMD_RTPORT_DEL
;
490 cfg_rtport
= (emf_cfg_rtport_t
*)req
.arg
;
491 strncpy((char *)cfg_rtport
->if_name
, argv
[4], 16);
492 cfg_rtport
->if_name
[15] = 0;
495 req
.oper_type
= EMFCFG_OPER_TYPE_SET
;
497 /* Send request to kernel */
498 if (emf_cfg_request_send(&req
, sizeof(emf_cfg_request_t
)) < 0)
500 fprintf(stderr
, "Unable to send request to EMF\n");
504 if (req
.status
!= EMFCFG_STATUS_SUCCESS
)
506 fprintf(stderr
, "%s\n", req
.arg
);
514 emf_cfg_uffp_list(char *argv
[])
516 emf_cfg_request_t req
;
517 emf_cfg_uffp_list_t
*uffp_list
;
518 emf_cfg_rtport_list_t
*rtport_list
;
521 bzero((char *)&req
, sizeof(emf_cfg_request_t
));
523 strcpy((char *)req
.inst_id
, argv
[3]);
525 if (strncmp(argv
[2], "uffp", 4) == 0)
526 req
.command_id
= EMFCFG_CMD_UFFP_LIST
;
528 req
.command_id
= EMFCFG_CMD_RTPORT_LIST
;
530 req
.oper_type
= EMFCFG_OPER_TYPE_GET
;
531 req
.size
= sizeof(req
.arg
);
533 /* Send request to kernel */
534 if (emf_cfg_request_send(&req
, sizeof(emf_cfg_request_t
)) < 0)
536 fprintf(stderr
, "Unable to send request to EMF\n");
540 if (req
.status
!= EMFCFG_STATUS_SUCCESS
)
542 fprintf(stderr
, "%s\n", req
.arg
);
546 if (strncmp(argv
[2], "uffp", 4) == 0)
548 fprintf(stdout
, "UFFP list of %s: ", argv
[3]);
550 uffp_list
= (emf_cfg_uffp_list_t
*)req
.arg
;
551 for (i
= 0; i
< uffp_list
->num_entries
; i
++)
553 fprintf(stdout
, "%s ", uffp_list
->uffp_entry
[i
].if_name
);
558 fprintf(stdout
, "RTPORT list of %s: ", argv
[3]);
560 rtport_list
= (emf_cfg_rtport_list_t
*)req
.arg
;
561 for (i
= 0; i
< rtport_list
->num_entries
; i
++)
563 fprintf(stdout
, "%s ", rtport_list
->rtport_entry
[i
].if_name
);
567 fprintf(stdout
, "\n");
573 emf_cfg_mfdb_add(char *argv
[])
575 emf_cfg_mfdb_t
*mfdb_entry
;
576 emf_cfg_request_t req
;
577 struct in_addr mgrp_ip
;
579 bzero((char *)&req
, sizeof(emf_cfg_request_t
));
581 strcpy((char *)req
.inst_id
, argv
[3]);
582 req
.command_id
= EMFCFG_CMD_MFDB_ADD
;
583 req
.oper_type
= EMFCFG_OPER_TYPE_SET
;
585 /* Convert the multicast group address to binary data */
586 mfdb_entry
= (emf_cfg_mfdb_t
*)req
.arg
;
587 if (inet_aton(argv
[4], &mgrp_ip
) == 0)
589 fprintf(stderr
, "Invalid group address\n");
593 mfdb_entry
->mgrp_ip
= ntohl(mgrp_ip
.s_addr
);
594 strncpy((char *)mfdb_entry
->if_name
, argv
[5], 16);
596 /* Send request to kernel */
597 if (emf_cfg_request_send(&req
, sizeof(emf_cfg_request_t
)) < 0)
599 fprintf(stderr
, "Unable to send request to EMF\n");
603 if (req
.status
!= EMFCFG_STATUS_SUCCESS
)
605 fprintf(stderr
, "%sMFDB add failed\n", req
.arg
);
613 emf_cfg_mfdb_del(char *argv
[])
615 emf_cfg_mfdb_t
*mfdb_entry
;
616 emf_cfg_request_t req
;
617 struct in_addr mgrp_ip
;
619 bzero((char *)&req
, sizeof(emf_cfg_request_t
));
621 strcpy((char *)req
.inst_id
, argv
[3]);
622 req
.command_id
= EMFCFG_CMD_MFDB_DEL
;
623 req
.oper_type
= EMFCFG_OPER_TYPE_SET
;
625 /* Convert the multicast group address to binary data */
626 mfdb_entry
= (emf_cfg_mfdb_t
*)req
.arg
;
627 if (inet_aton(argv
[4], &mgrp_ip
) == 0)
629 fprintf(stderr
, "Invalid group address\n");
633 mfdb_entry
->mgrp_ip
= ntohl(mgrp_ip
.s_addr
);
634 strncpy((char *)mfdb_entry
->if_name
, argv
[5], 16);
636 /* Send request to kernel */
637 if (emf_cfg_request_send(&req
, sizeof(emf_cfg_request_t
)) < 0)
639 fprintf(stderr
, "Unable to send request to EMF\n");
643 if (req
.status
!= EMFCFG_STATUS_SUCCESS
)
645 fprintf(stderr
, "%sMFDB delete failed\n", req
.arg
);
653 emf_cfg_mfdb_clear(char *argv
[])
655 emf_cfg_request_t req
;
657 bzero((char *)&req
, sizeof(emf_cfg_request_t
));
659 strcpy((char *)req
.inst_id
, argv
[3]);
660 req
.command_id
= EMFCFG_CMD_MFDB_CLEAR
;
661 req
.oper_type
= EMFCFG_OPER_TYPE_SET
;
663 /* Send request to kernel */
664 if (emf_cfg_request_send(&req
, sizeof(emf_cfg_request_t
)) < 0)
666 fprintf(stderr
, "Unable to send request to EMF\n");
670 if (req
.status
!= EMFCFG_STATUS_SUCCESS
)
672 fprintf(stderr
, "%sMFDB clear failed\n", req
.arg
);
680 emf_cfg_mfdb_list(char *argv
[])
682 emf_cfg_request_t req
;
683 emf_cfg_mfdb_list_t
*list
;
686 strcpy((char *)req
.inst_id
, argv
[3]);
687 req
.command_id
= EMFCFG_CMD_MFDB_LIST
;
688 req
.oper_type
= EMFCFG_OPER_TYPE_GET
;
689 req
.size
= sizeof(req
.arg
);
690 list
= (emf_cfg_mfdb_list_t
*)req
.arg
;
692 if (emf_cfg_request_send(&req
, sizeof(emf_cfg_request_t
)) < 0)
694 fprintf(stderr
, "Unable to send request to EMF\n");
698 if (req
.status
!= EMFCFG_STATUS_SUCCESS
)
700 fprintf(stderr
, "Unable to get the MFBD list\n");
704 fprintf(stdout
, "Group Interface Pkts\n");
706 for (i
= 0; i
< list
->num_entries
; i
++)
708 fprintf(stdout
, "%08x ", list
->mfdb_entry
[i
].mgrp_ip
);
709 fprintf(stdout
, "%-15s", list
->mfdb_entry
[i
].if_name
);
710 fprintf(stdout
, "%d\n", list
->mfdb_entry
[i
].pkts_fwd
);
717 emf_cfg_stats_show(char *argv
[])
719 emf_cfg_request_t req
;
722 strcpy((char *)req
.inst_id
, argv
[3]);
723 req
.command_id
= EMFCFG_CMD_EMF_STATS
;
724 req
.oper_type
= EMFCFG_OPER_TYPE_GET
;
725 req
.size
= sizeof(emf_stats_t
);
726 emfs
= (emf_stats_t
*)req
.arg
;
728 if (emf_cfg_request_send(&req
, sizeof(emf_cfg_request_t
)) < 0)
730 fprintf(stderr
, "Unable to send request to EMF\n");
734 if (req
.status
!= EMFCFG_STATUS_SUCCESS
)
736 fprintf(stderr
, "Unable to get the EMF stats\n");
740 fprintf(stdout
, "McastDataPkts McastDataFwd McastFlooded "
741 "McastDataSentUp McastDataDropped\n");
742 fprintf(stdout
, "%-15d %-15d %-15d %-15d %d\n",
743 emfs
->mcast_data_frames
, emfs
->mcast_data_fwd
,
744 emfs
->mcast_data_flooded
, emfs
->mcast_data_sentup
,
745 emfs
->mcast_data_dropped
);
746 fprintf(stdout
, "IgmpPkts IgmpPktsFwd "
747 "IgmpPktsSentUp MFDBCacheHits MFDBCacheMisses\n");
748 fprintf(stdout
, "%-15d %-15d %-15d %-15d %d\n",
749 emfs
->igmp_frames
, emfs
->igmp_frames_fwd
,
750 emfs
->igmp_frames_sentup
, emfs
->mfdb_cache_hits
,
751 emfs
->mfdb_cache_misses
);
758 main(int argc
, char *argv
[])
759 #else /* defined(vxworks) */
760 #error "Unsupported osl"
764 bool cmd_syntax
= FALSE
;
772 /* Find the command type */
773 for (j
= 0; j
< sizeof(cmd_args
)/sizeof(cmd_args
[0]); j
++)
775 if ((strcmp(argv
[1], cmd_args
[j
].cmd_oper_str
) == 0) &&
776 (argc
- 1 == cmd_args
[j
].arg_count
) &&
777 ((cmd_args
[j
].cmd_id_str
== NULL
) ||
778 ((argv
[2] != NULL
) &&
779 (strcmp(argv
[2], cmd_args
[j
].cmd_id_str
) == 0))))
792 /* Call the command processing function. This function parses
793 * prepare command request and sends it kernel.
795 if ((ret
= cmd_args
[j
].input(argv
)) < 0)