xref: /aosp_15_r20/external/libnl/lib/cli/qdisc/blackhole.c (revision 4dc78e53d49367fa8e61b07018507c90983a077d)
1 /* SPDX-License-Identifier: LGPL-2.1-only */
2 /*
3  * Copyright (c) 2010-2011 Thomas Graf <[email protected]>
4  */
5 
6 #include "nl-default.h"
7 
8 #include <netlink/cli/utils.h>
9 #include <netlink/cli/tc.h>
10 
print_usage(void)11 static void print_usage(void)
12 {
13 	printf(
14 "Usage: nl-qdisc-add [...] blackhole [OPTIONS]...\n"
15 "\n"
16 "OPTIONS\n"
17 "     --help                Show this help text.\n"
18 "\n"
19 "EXAMPLE"
20 "    # Drop all outgoing packets on eth1\n"
21 "    nl-qdisc-add --dev=eth1 --parent=root blackhole\n");
22 }
23 
blackhole_parse_argv(struct rtnl_tc * tc,int argc,char ** argv)24 static void blackhole_parse_argv(struct rtnl_tc *tc, int argc, char **argv)
25 {
26 	for (;;) {
27 		int c, optidx = 0;
28 		static struct option long_opts[] = {
29 			{ "help", 0, 0, 'h' },
30 			{ 0, 0, 0, 0 }
31 		};
32 
33 		c = getopt_long(argc, argv, "h", long_opts, &optidx);
34 		if (c == -1)
35 			break;
36 
37 		switch (c) {
38 		case 'h':
39 			print_usage();
40 			return;
41 		}
42 	}
43 }
44 
45 static struct nl_cli_tc_module blackhole_module =
46 {
47 	.tm_name		= "blackhole",
48 	.tm_type		= RTNL_TC_TYPE_QDISC,
49 	.tm_parse_argv		= blackhole_parse_argv,
50 };
51 
blackhole_init(void)52 static void _nl_init blackhole_init(void)
53 {
54 	nl_cli_tc_register(&blackhole_module);
55 }
56 
blackhole_exit(void)57 static void _nl_exit blackhole_exit(void)
58 {
59 	nl_cli_tc_unregister(&blackhole_module);
60 }
61