1 /* 2 * src/lib/blackhole.c Blackhole module for CLI lib 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation version 2.1 7 * of the License. 8 * 9 * Copyright (c) 2010-2011 Thomas Graf <tgraf (at) suug.ch> 10 */ 11 12 #include <netlink/cli/utils.h> 13 #include <netlink/cli/tc.h> 14 15 static void print_usage(void) 16 { 17 printf( 18 "Usage: nl-qdisc-add [...] blackhole [OPTIONS]...\n" 19 "\n" 20 "OPTIONS\n" 21 " --help Show this help text.\n" 22 "\n" 23 "EXAMPLE" 24 " # Drop all outgoing packets on eth1\n" 25 " nl-qdisc-add --dev=eth1 --parent=root blackhole\n"); 26 } 27 28 static void blackhole_parse_argv(struct rtnl_tc *tc, int argc, char **argv) 29 { 30 for (;;) { 31 int c, optidx = 0; 32 static struct option long_opts[] = { 33 { "help", 0, 0, 'h' }, 34 { 0, 0, 0, 0 } 35 }; 36 37 c = getopt_long(argc, argv, "h", long_opts, &optidx); 38 if (c == -1) 39 break; 40 41 switch (c) { 42 case 'h': 43 print_usage(); 44 return; 45 } 46 } 47 } 48 49 static struct nl_cli_tc_module blackhole_module = 50 { 51 .tm_name = "blackhole", 52 .tm_type = RTNL_TC_TYPE_QDISC, 53 .tm_parse_argv = blackhole_parse_argv, 54 }; 55 56 static void __init blackhole_init(void) 57 { 58 nl_cli_tc_register(&blackhole_module); 59 } 60 61 static void __exit blackhole_exit(void) 62 { 63 nl_cli_tc_unregister(&blackhole_module); 64 } 65