libnl
3.2.3
|
00001 /* 00002 * src/lib/blackhole.c Blackhole module for CLI lib 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation version 2.1 00007 * of the License. 00008 * 00009 * Copyright (c) 2010-2011 Thomas Graf <tgraf@suug.ch> 00010 */ 00011 00012 #include <netlink/cli/utils.h> 00013 #include <netlink/cli/tc.h> 00014 00015 static void print_usage(void) 00016 { 00017 printf( 00018 "Usage: nl-qdisc-add [...] blackhole [OPTIONS]...\n" 00019 "\n" 00020 "OPTIONS\n" 00021 " --help Show this help text.\n" 00022 "\n" 00023 "EXAMPLE" 00024 " # Drop all outgoing packets on eth1\n" 00025 " nl-qdisc-add --dev=eth1 --parent=root blackhole\n"); 00026 } 00027 00028 static void blackhole_parse_argv(struct rtnl_tc *tc, int argc, char **argv) 00029 { 00030 for (;;) { 00031 int c, optidx = 0; 00032 static struct option long_opts[] = { 00033 { "help", 0, 0, 'h' }, 00034 { 0, 0, 0, 0 } 00035 }; 00036 00037 c = getopt_long(argc, argv, "h", long_opts, &optidx); 00038 if (c == -1) 00039 break; 00040 00041 switch (c) { 00042 case 'h': 00043 print_usage(); 00044 return; 00045 } 00046 } 00047 } 00048 00049 static struct nl_cli_tc_module blackhole_module = 00050 { 00051 .tm_name = "blackhole", 00052 .tm_type = RTNL_TC_TYPE_QDISC, 00053 .tm_parse_argv = blackhole_parse_argv, 00054 }; 00055 00056 static void __init blackhole_init(void) 00057 { 00058 nl_cli_tc_register(&blackhole_module); 00059 } 00060 00061 static void __exit blackhole_exit(void) 00062 { 00063 nl_cli_tc_unregister(&blackhole_module); 00064 }