int main(int argc, char *argv[]) { struct nl_cache *link_cache; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache(sock); qdisc_cache = nl_cli_qdisc_alloc_cache(sock); params.dp_fd = stdout; for (;;) { int c, optidx = 0; static struct option long_opts[] = { { "format", 1, 0, 'f' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "f:hv", long_opts, &optidx); if (c == -1) break; switch (c) { case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; } } nl_cache_foreach(link_cache, &print_link, NULL); return 0; }
int main(int argc, char *argv[]) { struct rtnl_qdisc *qdisc; struct rtnl_tc *tc; struct nl_cache *link_cache, *qdisc_cache; params.dp_fd = stdout; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache(sock); qdisc_cache = nl_cli_qdisc_alloc_cache(sock); qdisc = nl_cli_qdisc_alloc(); tc = (struct rtnl_tc *) qdisc; for (;;) { int c, optidx = 0; enum { ARG_DETAILS = 257, ARG_STATS = 258, }; static struct option long_opts[] = { { "details", 0, 0, ARG_DETAILS }, { "stats", 0, 0, ARG_STATS }, { "recursive", 0, 0, 'r' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "dev", 1, 0, 'd' }, { "parent", 1, 0, 'p' }, { "id", 1, 0, 'i' }, { "kind", 1, 0, 'k' }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "rhvd:p:i:k:", long_opts, &optidx); if (c == -1) break; switch (c) { case ARG_DETAILS: params.dp_type = NL_DUMP_DETAILS; break; case ARG_STATS: params.dp_type = NL_DUMP_STATS; break; case 'r': recursive = 1; break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg); break; case 'p': nl_cli_tc_parse_parent(tc, optarg); break; case 'i': nl_cli_tc_parse_handle(tc, optarg, 0); break; case 'k': nl_cli_tc_parse_kind(tc, optarg); break; } } if (recursive) nl_cache_foreach_filter(qdisc_cache, OBJ_CAST(qdisc), list_qdisc, NULL); else nl_cache_dump_filter(qdisc_cache, ¶ms, OBJ_CAST(qdisc)); return 0; }
int main(int argc, char *argv[]) { struct rtnl_neigh *neigh; struct nl_cache *link_cache, *neigh_cache; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache(sock); neigh_cache = nl_cli_neigh_alloc_cache(sock); neigh = nl_cli_neigh_alloc(); for (;;) { int c, optidx = 0; enum { ARG_FAMILY = 257, ARG_STATE = 258, ARG_YES, }; static struct option long_opts[] = { { "interactive", 0, 0, 'i' }, { "yes", 0, 0, ARG_YES }, { "quiet", 0, 0, 'q' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "addr", 1, 0, 'a' }, { "lladdr", 1, 0, 'l' }, { "dev", 1, 0, 'd' }, { "family", 1, 0, ARG_FAMILY }, { "state", 1, 0, ARG_STATE }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "qhva:l:d:", long_opts, &optidx); if (c == -1) break; switch (c) { case 'i': interactive = 1; break; case ARG_YES: default_yes = 1; break; case 'q': quiet = 1; break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; case 'a': nl_cli_neigh_parse_dst(neigh, optarg); break; case 'l': nl_cli_neigh_parse_lladdr(neigh, optarg); break; case 'd': nl_cli_neigh_parse_dev(neigh, link_cache, optarg); break; case ARG_FAMILY: nl_cli_neigh_parse_family(neigh, optarg); break; case ARG_STATE: nl_cli_neigh_parse_state(neigh, optarg); break; } } nl_cache_foreach_filter(neigh_cache, OBJ_CAST(neigh), delete_cb, NULL); if (!quiet) printf("Deleted %d neighbours\n", deleted); return 0; }
int main(int argc, char *argv[]) { struct nl_sock *sock; struct rtnl_neigh *neigh; struct nl_cache *link_cache, *neigh_cache; struct nl_dump_params params = { .dp_type = NL_DUMP_LINE, .dp_fd = stdout, }; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache_flags(sock, NL_CACHE_AF_ITER); neigh_cache = nl_cli_neigh_alloc_cache(sock); neigh = nl_cli_neigh_alloc(); for (;;) { int c, optidx = 0; enum { ARG_FAMILY = 257, ARG_STATE = 258, }; static struct option long_opts[] = { { "format", 1, 0, 'f' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "addr", 1, 0, 'a' }, { "lladdr", 1, 0, 'l' }, { "dev", 1, 0, 'd' }, { "family", 1, 0, ARG_FAMILY }, { "state", 1, 0, ARG_STATE }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "f:hva:l:d:", long_opts, &optidx); if (c == -1) break; switch (c) { case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; case 'a': nl_cli_neigh_parse_dst(neigh, optarg); break; case 'l': nl_cli_neigh_parse_lladdr(neigh, optarg); break; case 'd': nl_cli_neigh_parse_dev(neigh, link_cache, optarg); break; case ARG_FAMILY: nl_cli_neigh_parse_family(neigh, optarg); break; case ARG_STATE: nl_cli_neigh_parse_state(neigh, optarg); break; } } nl_cache_dump_filter(neigh_cache, ¶ms, OBJ_CAST(neigh)); return 0; }
int main(int argc, char *argv[]) { struct nl_sock *sock; struct rtnl_rule *rule; struct nl_cache *rule_cache; struct nl_dump_params params = { .dp_fd = stdout, .dp_type = NL_DUMP_LINE, }; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); nl_cli_link_alloc_cache(sock); rule_cache = nl_cli_rule_alloc_cache(sock); rule = nl_cli_rule_alloc(); for (;;) { int c, optidx = 0; enum { ARG_FAMILY = 257, }; static struct option long_opts[] = { { "format", 1, 0, 'f' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "family", 1, 0, ARG_FAMILY }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "f:hv", long_opts, &optidx); if (c == -1) break; switch (c) { case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; case ARG_FAMILY: nl_cli_rule_parse_family(rule, optarg); break; } } nl_cache_dump_filter(rule_cache, ¶ms, OBJ_CAST(rule)); return 0; }
int main(int argc, char *argv[]) { struct nl_sock *sock; struct nl_cache *link_cache; struct rtnl_link *link; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache(sock); link = nl_cli_link_alloc(); for (;;) { int c, optidx = 0; static struct option long_opts[] = { { "list", 0, 0, 'l' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "name", 1, 0, 'n' }, { "index", 1, 0, 'i' }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "lhvn:i:", long_opts, &optidx); if (c == -1) break; switch (c) { case 'l': list_stat_names(); break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; case 'n': nl_cli_link_parse_name(link, optarg); break; case 'i': nl_cli_link_parse_ifindex(link, optarg); break; } } gargc = argc; nl_cache_foreach_filter(link_cache, OBJ_CAST(link), dump_stats, argv); return 0; }
int main(int argc, char *argv[]) { struct nl_sock *sock; struct nl_cache *neightbl_cache; struct nl_dump_params params = { .dp_type = NL_DUMP_LINE, .dp_fd = stdout, }; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); nl_cli_link_alloc_cache(sock); neightbl_cache = nl_cli_alloc_cache(sock, "neighbour table", rtnl_neightbl_alloc_cache); for (;;) { int c, optidx = 0; static struct option long_opts[] = { { "format", 1, 0, 'f' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "f:hv", long_opts, &optidx); if (c == -1) break; switch (c) { case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; } } nl_cache_dump(neightbl_cache, ¶ms); return 0; }
int main(int argc, char *argv[]) { struct nl_sock *sock; struct nl_cache *link_cache; char name[IFNAMSIZ]; uint32_t ifindex; if (argc < 2) print_usage(); sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache(sock); ifindex = nl_cli_parse_u32(argv[1]); if (!rtnl_link_i2name(link_cache, ifindex, name, sizeof(name))) nl_cli_fatal(ENOENT, "Interface index %d does not exist", ifindex); printf("%s\n", name); return 0; }
int main(int argc, char *argv[]) { struct nl_sock *sock; struct nfnl_ct *ct; struct nl_dump_params params = { .dp_type = NL_DUMP_LINE, .dp_fd = stdout, }; int err, nlflags = NLM_F_CREATE; ct = nl_cli_ct_alloc(); for (;;) { int c, optidx = 0; enum { ARG_ORIG_SRC = 257, ARG_ORIG_SPORT = 258, ARG_ORIG_DST, ARG_ORIG_DPORT, ARG_REPLY_SRC, ARG_REPLY_SPORT, ARG_REPLY_DST, ARG_REPLY_DPORT, ARG_MARK, ARG_TIMEOUT, ARG_STATUS, ARG_ZONE, }; static struct option long_opts[] = { { "quiet", 0, 0, 'q' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "proto", 1, 0, 'p' }, { "orig-src", 1, 0, ARG_ORIG_SRC }, { "orig-sport", 1, 0, ARG_ORIG_SPORT }, { "orig-dst", 1, 0, ARG_ORIG_DST }, { "orig-dport", 1, 0, ARG_ORIG_DPORT }, { "reply-src", 1, 0, ARG_REPLY_SRC }, { "reply-sport", 1, 0, ARG_REPLY_SPORT }, { "reply-dst", 1, 0, ARG_REPLY_DST }, { "reply-dport", 1, 0, ARG_REPLY_DPORT }, { "family", 1, 0, 'F' }, { "mark", 1, 0, ARG_MARK }, { "timeout", 1, 0, ARG_TIMEOUT }, { "status", 1, 0, ARG_STATUS }, { "zone", 1, 0, ARG_ZONE }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "46q:hv:p:F:", long_opts, &optidx); if (c == -1) break; switch (c) { case '?': exit(NLE_INVAL); case 'q': quiet = 1; break; case '4': nfnl_ct_set_family(ct, AF_INET); break; case '6': nfnl_ct_set_family(ct, AF_INET6); break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; case 'p': nl_cli_ct_parse_protocol(ct, optarg); break; case ARG_ORIG_SRC: nl_cli_ct_parse_src(ct, 0, optarg); break; case ARG_ORIG_SPORT: nl_cli_ct_parse_src_port(ct, 0, optarg); break; case ARG_ORIG_DST: nl_cli_ct_parse_dst(ct, 0, optarg); break; case ARG_ORIG_DPORT: nl_cli_ct_parse_dst_port(ct, 0, optarg); break; case ARG_REPLY_SRC: nl_cli_ct_parse_src(ct, 1, optarg); break; case ARG_REPLY_SPORT: nl_cli_ct_parse_src_port(ct, 1, optarg); break; case ARG_REPLY_DST: nl_cli_ct_parse_dst(ct, 1, optarg); break; case ARG_REPLY_DPORT: nl_cli_ct_parse_dst_port(ct, 1, optarg); break; case 'F': nl_cli_ct_parse_family(ct, optarg); break; case ARG_MARK: nl_cli_ct_parse_mark(ct, optarg); break; case ARG_TIMEOUT: nl_cli_ct_parse_timeout(ct, optarg); break; case ARG_STATUS: nl_cli_ct_parse_status(ct, optarg); break; case ARG_ZONE: nl_cli_ct_parse_zone(ct, optarg); break; } } if (!quiet) { printf("Adding "); nl_object_dump(OBJ_CAST(ct), ¶ms); } sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_NETFILTER); if ((err = nfnl_ct_add(sock, ct, nlflags)) < 0) nl_cli_fatal(err, "Unable to add conntrack: %s", nl_geterror(err)); if (!quiet) { printf("Added "); nl_object_dump(OBJ_CAST(ct), ¶ms); } return 0; }
int main(int argc, char *argv[]) { struct nl_sock *sock; struct nl_cache *link_cache, *route_cache; struct rtnl_route *route; struct nl_dump_params params = { .dp_fd = stdout, .dp_type = NL_DUMP_LINE, }; int print_cache = 0; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache(sock); route = nl_cli_route_alloc(); for (;;) { int c, optidx = 0; enum { ARG_FAMILY = 257, ARG_SRC = 258, ARG_IIF, ARG_PREF_SRC, ARG_METRICS, ARG_PRIORITY, ARG_SCOPE, ARG_PROTOCOL, ARG_TYPE, }; static struct option long_opts[] = { { "cache", 0, 0, 'c' }, { "format", 1, 0, 'f' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "dst", 1, 0, 'd' }, { "nexthop", 1, 0, 'n' }, { "table", 1, 0, 't' }, { "family", 1, 0, ARG_FAMILY }, { "src", 1, 0, ARG_SRC }, { "iif", 1, 0, ARG_IIF }, { "pref-src", 1, 0, ARG_PREF_SRC }, { "metrics", 1, 0, ARG_METRICS }, { "priority", 1, 0, ARG_PRIORITY }, { "scope", 1, 0, ARG_SCOPE }, { "protocol", 1, 0, ARG_PROTOCOL }, { "type", 1, 0, ARG_TYPE }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "cf:hvd:n:t:", long_opts, &optidx); if (c == -1) break; switch (c) { case 'c': print_cache = 1; break; case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; case 'd': nl_cli_route_parse_dst(route, optarg); break; case 'n': nl_cli_route_parse_nexthop(route, optarg, link_cache); break; case 't': nl_cli_route_parse_table(route, optarg); break; case ARG_FAMILY: nl_cli_route_parse_family(route, optarg); break; case ARG_SRC: nl_cli_route_parse_src(route, optarg); break; case ARG_IIF: nl_cli_route_parse_iif(route, optarg, link_cache); break; case ARG_PREF_SRC: nl_cli_route_parse_pref_src(route, optarg); break; case ARG_METRICS: nl_cli_route_parse_metric(route, optarg); break; case ARG_PRIORITY: nl_cli_route_parse_prio(route, optarg); break; case ARG_SCOPE: nl_cli_route_parse_scope(route, optarg); break; case ARG_PROTOCOL: nl_cli_route_parse_protocol(route, optarg); break; case ARG_TYPE: nl_cli_route_parse_type(route, optarg); break; } } route_cache = nl_cli_route_alloc_cache(sock, print_cache ? ROUTE_CACHE_CONTENT : 0); nl_cache_dump_filter(route_cache, ¶ms, OBJ_CAST(route)); return 0; }
int main(int argc, char *argv[]) { struct nl_sock *sock; struct nl_dect_cluster *cl; struct nl_dect_ari *pari; struct nl_dump_params params = { .dp_type = NL_DUMP_LINE, .dp_fd = stdout, }; int err; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_DECT); cl = nl_dect_cluster_alloc(); pari = (void *)nl_dect_cluster_get_pari(cl); for (;;) { int c, optidx = 0; enum { ARG_NAME = 257, ARG_MODE, ARG_EMC, ARG_FPN, }; static struct option long_opts[] = { { "name", 1, 0, ARG_NAME }, { "mode", 1, 0, ARG_MODE }, { "emc", 1, 0, ARG_EMC }, { "fpn", 1, 0, ARG_FPN }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "qhvd:n:t:", long_opts, &optidx); if (c == -1) break; switch (c) { case 'v': nl_cli_print_version(); break; case ARG_NAME: nl_dect_cluster_set_name(cl, strdup(optarg)); break; case ARG_MODE: nl_dect_cluster_set_mode(cl, atoi(optarg)); break; case ARG_EMC: nl_dect_ari_set_emc(pari, strtoul(optarg, NULL, 16)); break; case ARG_FPN: nl_dect_ari_set_fpn(pari, strtoul(optarg, NULL, 16)); break; } } err = nl_dect_cluster_delete(sock, cl, 0); if (err < 0) nl_cli_fatal(err, "Unable to delete cluster: %s", nl_geterror(err)); printf("Deleted: "); nl_object_dump(OBJ_CAST(cl), ¶ms); return 0; }
int main(int argc, char *argv[]) { struct nl_sock *sock; struct rtnl_addr *addr; struct nl_cache *link_cache, *addr_cache; struct nl_dump_params params = { .dp_type = NL_DUMP_LINE, .dp_nl_cb = print_prefix, .dp_fd = stdout, }; int dump_env = 0; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache(sock); addr_cache = nl_cli_addr_alloc_cache(sock); addr = nl_cli_addr_alloc(); for (;;) { int c, optidx = 0; enum { ARG_FAMILY = 257, ARG_LABEL = 258, ARG_PEER, ARG_SCOPE, ARG_BROADCAST, ARG_DETAILS, ARG_ENV, ARG_PREFIX, ARG_PREFERRED, ARG_VALID, }; static struct option long_opts[] = { { "details", 0, 0, ARG_DETAILS }, { "env", 0, 0, ARG_ENV }, { "prefix", 1, 0, ARG_PREFIX }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "local", 1, 0, 'a' }, { "dev", 1, 0, 'd' }, { "family", 1, 0, ARG_FAMILY }, { "label", 1, 0, ARG_LABEL }, { "peer", 1, 0, ARG_PEER }, { "scope", 1, 0, ARG_SCOPE }, { "broadcast", 1, 0, ARG_BROADCAST }, { "preferred", 1, 0, ARG_PREFERRED }, { "valid", 1, 0, ARG_VALID }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "46hva:d:", long_opts, &optidx); if (c == -1) break; switch (c) { case '?': exit(NLE_INVAL); case '4': rtnl_addr_set_family(addr, AF_INET); break; case '6': rtnl_addr_set_family(addr, AF_INET6); break; case ARG_DETAILS: params.dp_type = NL_DUMP_DETAILS; break; case ARG_ENV: dump_env = 1; break; case ARG_PREFIX: prefix = strdup(optarg); break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; case 'a': nl_cli_addr_parse_local(addr, optarg); break; case 'd': nl_cli_addr_parse_dev(addr, link_cache, optarg); break; case ARG_FAMILY: nl_cli_addr_parse_family(addr, optarg); break; case ARG_LABEL: nl_cli_addr_parse_label(addr, optarg); break; case ARG_PEER: nl_cli_addr_parse_peer(addr, optarg); break; case ARG_SCOPE: nl_cli_addr_parse_scope(addr, optarg); break; case ARG_BROADCAST: nl_cli_addr_parse_broadcast(addr, optarg); break; case ARG_PREFERRED: nl_cli_addr_parse_preferred(addr, optarg); break; case ARG_VALID: nl_cli_addr_parse_valid(addr, optarg); break; } } if (dump_env) nl_cache_foreach_filter(addr_cache, OBJ_CAST(addr), env_dump, ¶ms); else nl_cache_dump_filter(addr_cache, ¶ms, OBJ_CAST(addr)); return 0; }
int main(int argc, char *argv[]) { struct rtnl_addr *addr; struct nl_cache *link_cache, *addr_cache; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache(sock); addr_cache = nl_cli_addr_alloc_cache(sock); addr = nl_cli_addr_alloc(); for (;;) { int c, optidx = 0; enum { ARG_FAMILY = 257, ARG_LABEL = 258, ARG_YES, ARG_PEER, ARG_SCOPE, ARG_BROADCAST, ARG_PREFERRED, ARG_VALID, }; static struct option long_opts[] = { { "interactive", 0, 0, 'i' }, { "yes", 0, 0, ARG_YES }, { "quiet", 0, 0, 'q' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "local", 1, 0, 'a' }, { "dev", 1, 0, 'd' }, { "family", 1, 0, ARG_FAMILY }, { "label", 1, 0, ARG_LABEL }, { "peer", 1, 0, ARG_PEER }, { "scope", 1, 0, ARG_SCOPE }, { "broadcast", 1, 0, ARG_BROADCAST }, { "preferred", 1, 0, ARG_PREFERRED }, { "valid", 1, 0, ARG_VALID }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "iqhva:d:", long_opts, &optidx); if (c == -1) break; switch (c) { case 'i': interactive = 1; break; case ARG_YES: default_yes = 1; break; case 'q': quiet = 1; break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; case 'a': nl_cli_addr_parse_local(addr, optarg); break; case 'd': nl_cli_addr_parse_dev(addr, link_cache, optarg); break; case ARG_FAMILY: nl_cli_addr_parse_family(addr, optarg); break; case ARG_LABEL: nl_cli_addr_parse_label(addr, optarg); break; case ARG_PEER: nl_cli_addr_parse_peer(addr, optarg); break; case ARG_SCOPE: nl_cli_addr_parse_scope(addr, optarg); break; case ARG_BROADCAST: nl_cli_addr_parse_broadcast(addr, optarg); break; case ARG_PREFERRED: nl_cli_addr_parse_preferred(addr, optarg); break; case ARG_VALID: nl_cli_addr_parse_valid(addr, optarg); break; } } nl_cache_foreach_filter(addr_cache, OBJ_CAST(addr), delete_cb, NULL); if (!quiet) printf("Deleted %d addresses\n", deleted); return 0; }
int main(int argc, char *argv[]) { struct nl_sock *sock; struct nfnl_exp *exp; struct nl_dump_params params = { .dp_type = NL_DUMP_LINE, .dp_fd = stdout, }; int err, nlflags = NLM_F_CREATE; exp = nl_cli_exp_alloc(); for (;;) { int c, optidx = 0; enum { ARG_MARK = 270, ARG_TCP_STATE = 271, ARG_EXPECT_PROTO, ARG_EXPECT_SRC, ARG_EXPECT_SPORT, ARG_EXPECT_DST, ARG_EXPECT_DPORT, ARG_MASTER_PROTO, ARG_MASTER_SRC, ARG_MASTER_SPORT, ARG_MASTER_DST, ARG_MASTER_DPORT, ARG_MASK_PROTO, ARG_MASK_SRC, ARG_MASK_SPORT, ARG_MASK_DST, ARG_MASK_DPORT, ARG_NAT_PROTO, ARG_NAT_SRC, ARG_NAT_SPORT, ARG_NAT_DST, ARG_NAT_DPORT, ARG_NAT_DIR, ARG_TIMEOUT, ARG_HELPER_NAME, ARG_REPLACE, ARG_FLAGS, }; static struct option long_opts[] = { { "replace", 1, 0, ARG_REPLACE }, { "quiet", 0, 0, 'q' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "id", 1, 0, 'i' }, { "expect-proto", 1, 0, ARG_EXPECT_PROTO }, { "expect-src", 1, 0, ARG_EXPECT_SRC }, { "expect-sport", 1, 0, ARG_EXPECT_SPORT }, { "expect-dst", 1, 0, ARG_EXPECT_DST }, { "expect-dport", 1, 0, ARG_EXPECT_DPORT }, { "master-proto", 1, 0, ARG_MASTER_PROTO }, { "master-src", 1, 0, ARG_MASTER_SRC }, { "master-sport", 1, 0, ARG_MASTER_SPORT }, { "master-dst", 1, 0, ARG_MASTER_DST }, { "master-dport", 1, 0, ARG_MASTER_DPORT }, { "mask-proto", 1, 0, ARG_MASK_PROTO }, { "mask-src", 1, 0, ARG_MASK_SRC }, { "mask-sport", 1, 0, ARG_MASK_SPORT }, { "mask-dst", 1, 0, ARG_MASK_DST }, { "mask-dport", 1, 0, ARG_MASK_DPORT }, { "nat-proto", 1, 0, ARG_NAT_PROTO }, { "nat-src", 1, 0, ARG_NAT_SRC }, { "nat-sport", 1, 0, ARG_NAT_SPORT }, { "nat-dst", 1, 0, ARG_NAT_DST }, { "nat-dport", 1, 0, ARG_NAT_DPORT }, { "nat-dir", 1, 0, ARG_NAT_DIR }, { "family", 1, 0, 'F' }, { "timeout", 1, 0, ARG_TIMEOUT }, { "helper", 1, 0, ARG_HELPER_NAME }, { "flags", 1, 0, ARG_FLAGS}, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "46f:hvi:p:F:", long_opts, &optidx); if (c == -1) break; switch (c) { case '?': exit(NLE_INVAL); case ARG_REPLACE: nlflags |= NLM_F_REPLACE; break; case 'q': quiet = 1; break; case '4': nfnl_exp_set_family(exp, AF_INET); break; case '6': nfnl_exp_set_family(exp, AF_INET6); break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; case 'i': nl_cli_exp_parse_id(exp, optarg); break; case ARG_EXPECT_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break; case ARG_EXPECT_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break; case ARG_EXPECT_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break; case ARG_EXPECT_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break; case ARG_EXPECT_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break; case ARG_MASTER_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_MASTER, optarg); break; case ARG_MASTER_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_MASTER, optarg); break; case ARG_MASTER_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_MASTER, optarg); break; case ARG_MASTER_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_MASTER, optarg); break; case ARG_MASTER_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_MASTER, optarg); break; case ARG_MASK_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_MASK, optarg); break; case ARG_MASK_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_MASK, optarg); break; case ARG_MASK_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_MASK, optarg); break; case ARG_MASK_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_MASK, optarg); break; case ARG_MASK_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_MASK, optarg); break; case ARG_NAT_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_NAT, optarg); break; case ARG_NAT_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_NAT, optarg); break; case ARG_NAT_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_NAT, optarg); break; case ARG_NAT_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_NAT, optarg); break; case ARG_NAT_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_NAT, optarg); break; case ARG_NAT_DIR: nl_cli_exp_parse_nat_dir(exp, optarg); break; case 'F': nl_cli_exp_parse_family(exp, optarg); break; case ARG_TIMEOUT: nl_cli_exp_parse_timeout(exp, optarg); break; case ARG_HELPER_NAME: nl_cli_exp_parse_helper_name(exp, optarg); break; case ARG_FLAGS: nl_cli_exp_parse_flags(exp, optarg); break; } } sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_NETFILTER); if ((err = nfnl_exp_add(sock, exp, nlflags)) < 0) nl_cli_fatal(err, "Unable to add expectation: %s", nl_geterror(err)); if (!quiet) { printf("Added "); nl_object_dump(OBJ_CAST(exp), ¶ms); } return 0; }
int main(int argc, char *argv[]) { struct rtnl_cls *cls; struct rtnl_tc *tc; struct nl_cache *link_cache; int ifindex; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache(sock); cls = nl_cli_cls_alloc(); tc = (struct rtnl_tc *) cls; for (;;) { int c, optidx = 0; enum { ARG_YES = 257, ARG_INTERACTIVE = 258, ARG_PROTO, ARG_PRIO, }; static struct option long_opts[] = { { "interactive", 0, 0, ARG_INTERACTIVE }, { "yes", 0, 0, ARG_YES }, { "quiet", 0, 0, 'q' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "dev", 1, 0, 'd' }, { "parent", 1, 0, 'p' }, { "id", 1, 0, 'i' }, { "kind", 1, 0, 'k' }, { "proto", 1, 0, ARG_PROTO }, { "prio", 1, 0, ARG_PRIO }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "qhvd:p:i:k:", long_opts, &optidx); if (c == -1) break; switch (c) { case '?': nl_cli_fatal(EINVAL, "Invalid options"); case ARG_INTERACTIVE: interactive = 1; break; case ARG_YES: default_yes = 1; break; case 'q': quiet = 1; break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg); break; case 'p': nl_cli_tc_parse_parent(tc, optarg); break; case 'i': nl_cli_tc_parse_handle(tc, optarg, 0); break; case 'k': nl_cli_tc_parse_kind(tc, optarg); break; case ARG_PROTO: nl_cli_cls_parse_proto(cls, optarg); break; case ARG_PRIO: rtnl_cls_set_prio(cls, nl_cli_parse_u32(optarg)); break; } } if ((ifindex = rtnl_tc_get_ifindex(tc))) __delete_link(ifindex, cls); else nl_cache_foreach(link_cache, delete_link, cls); if (!quiet) printf("Deleted %d classs\n", deleted); return 0; }
int main(int argc, char *argv[]) { struct nl_sock *sock; struct nl_cache *link_cache; struct rtnl_link *link; struct nl_dump_params params = { .dp_type = NL_DUMP_LINE, .dp_fd = stdout, }; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); link = nl_cli_link_alloc(); for (;;) { int c, optidx = 0; enum { ARG_FAMILY = 257, ARG_MTU = 258, ARG_TXQLEN, ARG_WEIGHT, ARG_DETAILS, ARG_STATS, }; static struct option long_opts[] = { { "details", 0, 0, ARG_DETAILS }, { "stats", 0, 0, ARG_STATS }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "name", 1, 0, 'n' }, { "index", 1, 0, 'i' }, { "family", 1, 0, ARG_FAMILY }, { "mtu", 1, 0, ARG_MTU }, { "txqlen", 1, 0, ARG_TXQLEN }, { "weight", 1, 0, ARG_WEIGHT }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "hvn:i:", long_opts, &optidx); if (c == -1) break; switch (c) { case ARG_DETAILS: params.dp_type = NL_DUMP_DETAILS; break; case ARG_STATS: params.dp_type = NL_DUMP_STATS; break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; case 'n': nl_cli_link_parse_name(link, optarg); break; case 'i': nl_cli_link_parse_ifindex(link, optarg); break; case ARG_FAMILY: nl_cli_link_parse_family(link, optarg); break; case ARG_MTU: nl_cli_link_parse_mtu(link, optarg); break; case ARG_TXQLEN: nl_cli_link_parse_txqlen(link, optarg); break; case ARG_WEIGHT: nl_cli_link_parse_weight(link, optarg); break; } } link_cache = nl_cli_link_alloc_cache_family(sock, rtnl_link_get_family(link)); nl_cache_dump_filter(link_cache, ¶ms, OBJ_CAST(link)); return 0; }
static void obj_input(struct nl_object *obj, void *arg) { struct nfnl_queue_msg *msg = (struct nfnl_queue_msg *) obj; struct nl_dump_params dp = { .dp_type = NL_DUMP_STATS, .dp_fd = stdout, .dp_dump_msgtype = 1, }; nfnl_queue_msg_set_verdict(msg, NF_ACCEPT); nl_object_dump(obj, &dp); nfnl_queue_msg_send_verdict(nf_sock, msg); } static int event_input(struct nl_msg *msg, void *arg) { if (nl_msg_parse(msg, &obj_input, NULL) < 0) fprintf(stderr, "<<EVENT>> Unknown message type\n"); /* Exit nl_recvmsgs_def() and return to the main select() */ return NL_STOP; } int main(int argc, char *argv[]) { struct nl_sock *rt_sock; struct nl_cache *link_cache; struct nfnl_queue *queue; enum nfnl_queue_copy_mode copy_mode; uint32_t copy_range; int err = 1; int family; nf_sock = nfnl_queue_socket_alloc(); if (nf_sock == NULL) nl_cli_fatal(ENOBUFS, "Unable to allocate netlink socket"); nl_socket_disable_seq_check(nf_sock); nl_socket_modify_cb(nf_sock, NL_CB_VALID, NL_CB_CUSTOM, event_input, NULL); if ((argc > 1 && !strcasecmp(argv[1], "-h")) || argc < 3) { printf("Usage: nf-queue family group [ copy_mode ] " "[ copy_range ]\n"); printf("family: [ inet | inet6 | ... ] \n"); printf("group: the --queue-num arg that you gave to iptables\n"); printf("copy_mode: [ none | meta | packet ] \n"); return 2; } nl_cli_connect(nf_sock, NETLINK_NETFILTER); if ((family = nl_str2af(argv[1])) == AF_UNSPEC) nl_cli_fatal(NLE_INVAL, "Unknown family \"%s\"", argv[1]); nfnl_queue_pf_unbind(nf_sock, family); if ((err = nfnl_queue_pf_bind(nf_sock, family)) < 0) nl_cli_fatal(err, "Unable to bind logger: %s", nl_geterror(err)); queue = alloc_queue(); nfnl_queue_set_group(queue, atoi(argv[2])); copy_mode = NFNL_QUEUE_COPY_PACKET; if (argc > 3) { copy_mode = nfnl_queue_str2copy_mode(argv[3]); if (copy_mode < 0) nl_cli_fatal(copy_mode, "Unable to parse copy mode \"%s\": %s", argv[3], nl_geterror(copy_mode)); } nfnl_queue_set_copy_mode(queue, copy_mode); copy_range = 0xFFFF; if (argc > 4) copy_range = atoi(argv[4]); nfnl_queue_set_copy_range(queue, copy_range); if ((err = nfnl_queue_create(nf_sock, queue)) < 0) nl_cli_fatal(err, "Unable to bind queue: %s", nl_geterror(err)); rt_sock = nl_cli_alloc_socket(); nl_cli_connect(rt_sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache(rt_sock); nl_socket_set_buffer_size(nf_sock, 1024*127, 1024*127); while (1) { fd_set rfds; int nffd, rtfd, maxfd, retval; FD_ZERO(&rfds); maxfd = nffd = nl_socket_get_fd(nf_sock); FD_SET(nffd, &rfds); rtfd = nl_socket_get_fd(rt_sock); FD_SET(rtfd, &rfds); if (maxfd < rtfd) maxfd = rtfd; /* wait for an incoming message on the netlink socket */ retval = select(maxfd+1, &rfds, NULL, NULL, NULL); if (retval) { if (FD_ISSET(nffd, &rfds)) nl_recvmsgs_default(nf_sock); if (FD_ISSET(rtfd, &rfds)) nl_recvmsgs_default(rt_sock); } } return 0; }
static void obj_input(struct nl_object *obj, void *arg) { struct nl_dump_params dp = { .dp_type = NL_DUMP_STATS, .dp_fd = stdout, .dp_dump_msgtype = 1, }; nl_object_dump(obj, &dp); } static int event_input(struct nl_msg *msg, void *arg) { if (nl_msg_parse(msg, &obj_input, NULL) < 0) fprintf(stderr, "<<EVENT>> Unknown message type\n"); /* Exit nl_recvmsgs_def() and return to the main select() */ return NL_STOP; } int main(int argc, char *argv[]) { struct nl_sock *nf_sock; struct nl_sock *rt_sock; struct nl_cache *link_cache; struct nfnl_log *log; enum nfnl_log_copy_mode copy_mode; uint32_t copy_range; int err; int family; nf_sock = nl_cli_alloc_socket(); nl_socket_disable_seq_check(nf_sock); nl_socket_modify_cb(nf_sock, NL_CB_VALID, NL_CB_CUSTOM, event_input, NULL); if ((argc > 1 && !strcasecmp(argv[1], "-h")) || argc < 3) { printf("Usage: nf-log family group [ copy_mode ] " "[copy_range] \n"); return 2; } nl_cli_connect(nf_sock, NETLINK_NETFILTER); family = nl_str2af(argv[1]); if (family == AF_UNSPEC) nl_cli_fatal(NLE_INVAL, "Unknown family \"%s\": %s", argv[1], nl_geterror(family)); nfnl_log_pf_unbind(nf_sock, family); if ((err = nfnl_log_pf_bind(nf_sock, family)) < 0) nl_cli_fatal(err, "Unable to bind logger: %s", nl_geterror(err)); log = alloc_log(); nfnl_log_set_group(log, atoi(argv[2])); copy_mode = NFNL_LOG_COPY_META; if (argc > 3) { copy_mode = nfnl_log_str2copy_mode(argv[3]); if (copy_mode < 0) nl_cli_fatal(copy_mode, "Unable to parse copy mode \"%s\": %s", argv[3], nl_geterror(copy_mode)); } nfnl_log_set_copy_mode(log, copy_mode); copy_range = 0xFFFF; if (argc > 4) copy_mode = atoi(argv[4]); nfnl_log_set_copy_range(log, copy_range); if ((err = nfnl_log_create(nf_sock, log)) < 0) nl_cli_fatal(err, "Unable to bind instance: %s", nl_geterror(err)); { struct nl_dump_params dp = { .dp_type = NL_DUMP_STATS, .dp_fd = stdout, .dp_dump_msgtype = 1, }; printf("log params: "); nl_object_dump((struct nl_object *) log, &dp); } rt_sock = nl_cli_alloc_socket(); nl_cli_connect(rt_sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache(rt_sock); while (1) { fd_set rfds; int nffd, rtfd, maxfd, retval; FD_ZERO(&rfds); maxfd = nffd = nl_socket_get_fd(nf_sock); FD_SET(nffd, &rfds); rtfd = nl_socket_get_fd(rt_sock); FD_SET(rtfd, &rfds); if (maxfd < rtfd) maxfd = rtfd; /* wait for an incoming message on the netlink nf_socket */ retval = select(maxfd+1, &rfds, NULL, NULL, NULL); if (retval) { if (FD_ISSET(nffd, &rfds)) nl_recvmsgs_default(nf_sock); if (FD_ISSET(rtfd, &rfds)) nl_recvmsgs_default(rt_sock); } } return 0; }
int main(int argc, char *argv[]) { struct nl_sock *sock; struct nl_cache *exp_cache; struct nfnl_exp *exp; struct nl_dump_params params = { .dp_type = NL_DUMP_LINE, .dp_fd = stdout, }; exp = nl_cli_exp_alloc(); for (;;) { int c, optidx = 0; enum { ARG_MARK = 270, ARG_TCP_STATE = 271, ARG_EXPECT_PROTO, ARG_EXPECT_SRC, ARG_EXPECT_SPORT, ARG_EXPECT_DST, ARG_EXPECT_DPORT, ARG_MASTER_PROTO, ARG_MASTER_SRC, ARG_MASTER_SPORT, ARG_MASTER_DST, ARG_MASTER_DPORT, ARG_TIMEOUT, ARG_HELPER_NAME, ARG_FLAGS, }; static struct option long_opts[] = { { "format", 1, 0, 'f' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "id", 1, 0, 'i' }, { "expect-proto", 1, 0, ARG_EXPECT_PROTO }, { "expect-src", 1, 0, ARG_EXPECT_SRC }, { "expect-sport", 1, 0, ARG_EXPECT_SPORT }, { "expect-dst", 1, 0, ARG_EXPECT_DST }, { "expect-dport", 1, 0, ARG_EXPECT_DPORT }, { "master-proto", 1, 0, ARG_MASTER_PROTO }, { "master-src", 1, 0, ARG_MASTER_SRC }, { "master-sport", 1, 0, ARG_MASTER_SPORT }, { "master-dst", 1, 0, ARG_MASTER_DST }, { "master-dport", 1, 0, ARG_MASTER_DPORT }, { "family", 1, 0, 'F' }, { "timeout", 1, 0, ARG_TIMEOUT }, { "helper", 1, 0, ARG_HELPER_NAME }, { "flags", 1, 0, ARG_FLAGS}, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "46f:hvi:p:F:", long_opts, &optidx); if (c == -1) break; switch (c) { case '?': exit(NLE_INVAL); case '4': nfnl_exp_set_family(exp, AF_INET); break; case '6': nfnl_exp_set_family(exp, AF_INET6); break; case 'f': params.dp_type = nl_cli_parse_dumptype(optarg); break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; case 'i': nl_cli_exp_parse_id(exp, optarg); break; case ARG_EXPECT_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break; case ARG_EXPECT_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break; case ARG_EXPECT_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break; case ARG_EXPECT_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break; case ARG_EXPECT_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_EXPECT, optarg); break; case ARG_MASTER_PROTO: nl_cli_exp_parse_l4protonum(exp, NFNL_EXP_TUPLE_MASTER, optarg); break; case ARG_MASTER_SRC: nl_cli_exp_parse_src(exp, NFNL_EXP_TUPLE_MASTER, optarg); break; case ARG_MASTER_SPORT: nl_cli_exp_parse_src_port(exp, NFNL_EXP_TUPLE_MASTER, optarg); break; case ARG_MASTER_DST: nl_cli_exp_parse_dst(exp, NFNL_EXP_TUPLE_MASTER, optarg); break; case ARG_MASTER_DPORT: nl_cli_exp_parse_dst_port(exp, NFNL_EXP_TUPLE_MASTER, optarg); break; case 'F': nl_cli_exp_parse_family(exp, optarg); break; case ARG_TIMEOUT: nl_cli_exp_parse_timeout(exp, optarg); break; case ARG_HELPER_NAME: nl_cli_exp_parse_helper_name(exp, optarg); break; case ARG_FLAGS: nl_cli_exp_parse_flags(exp, optarg); break; } } sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_NETFILTER); exp_cache = nl_cli_exp_alloc_cache(sock); nl_cache_dump_filter(exp_cache, ¶ms, OBJ_CAST(exp)); return 0; }
int main(int argc, char *argv[]) { struct nl_cache *link_cache, *route_cache; struct rtnl_route *route; int nf = 0; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache(sock); route_cache = nl_cli_route_alloc_cache(sock, 0); route = nl_cli_route_alloc(); for (;;) { int c, optidx = 0; enum { ARG_FAMILY = 257, ARG_SRC = 258, ARG_IIF, ARG_PREF_SRC, ARG_METRICS, ARG_PRIORITY, ARG_SCOPE, ARG_PROTOCOL, ARG_TYPE, ARG_YES, }; static struct option long_opts[] = { { "interactive", 0, 0, 'i' }, { "yes", 0, 0, ARG_YES }, { "quiet", 0, 0, 'q' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "dst", 1, 0, 'd' }, { "nexthop", 1, 0, 'n' }, { "table", 1, 0, 't' }, { "family", 1, 0, ARG_FAMILY }, { "src", 1, 0, ARG_SRC }, { "iif", 1, 0, ARG_IIF }, { "pref-src", 1, 0, ARG_PREF_SRC }, { "metrics", 1, 0, ARG_METRICS }, { "priority", 1, 0, ARG_PRIORITY }, { "scope", 1, 0, ARG_SCOPE }, { "protocol", 1, 0, ARG_PROTOCOL }, { "type", 1, 0, ARG_TYPE }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "iqhvd:n:t:", long_opts, &optidx); if (c == -1) break; switch (c) { case 'i': interactive = 1; break; case ARG_YES: default_yes = 1; break; case 'q': quiet = 1; break; case 'h': print_usage(); break; case 'v': print_version(); break; case 'd': nf++; nl_cli_route_parse_dst(route, optarg); break; case 'n': nf++; nl_cli_route_parse_nexthop(route, optarg, link_cache); break; case 't': nf++; nl_cli_route_parse_table(route, optarg); break; case ARG_FAMILY: nf++; nl_cli_route_parse_family(route, optarg); break; case ARG_SRC: nf++; nl_cli_route_parse_src(route, optarg); break; case ARG_IIF: nf++; nl_cli_route_parse_iif(route, optarg, link_cache); break; case ARG_PREF_SRC: nf++; nl_cli_route_parse_pref_src(route, optarg); break; case ARG_METRICS: nf++; nl_cli_route_parse_metric(route, optarg); break; case ARG_PRIORITY: nf++; nl_cli_route_parse_prio(route, optarg); break; case ARG_SCOPE: nf++; nl_cli_route_parse_scope(route, optarg); break; case ARG_PROTOCOL: nf++; nl_cli_route_parse_protocol(route, optarg); break; case ARG_TYPE: nf++; nl_cli_route_parse_type(route, optarg); break; } } if (nf == 0 && !interactive && !default_yes) { fprintf(stderr, "You attempted to delete all routes in " "non-interactive mode, aborting.\n"); exit(0); } nl_cache_foreach_filter(route_cache, OBJ_CAST(route), delete_cb, NULL); if (!quiet) printf("Deleted %d routes\n", deleted); return 0; }
int main(int argc, char *argv[]) { struct nl_sock *sock; struct rtnl_route *route; struct nl_dump_params dp = { .dp_type = NL_DUMP_LINE, .dp_fd = stdout, }; int err = 1; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache(sock); route_cache = nl_cli_route_alloc_cache(sock, 0); route = nl_cli_route_alloc(); for (;;) { int c, optidx = 0; enum { ARG_FAMILY = 257, ARG_SRC = 258, ARG_IIF, ARG_PREF_SRC, ARG_METRICS, ARG_PRIORITY, ARG_SCOPE, ARG_PROTOCOL, ARG_TYPE, }; static struct option long_opts[] = { { "quiet", 0, 0, 'q' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "dst", 1, 0, 'd' }, { "nexthop", 1, 0, 'n' }, { "table", 1, 0, 't' }, { "family", 1, 0, ARG_FAMILY }, { "src", 1, 0, ARG_SRC }, { "iif", 1, 0, ARG_IIF }, { "pref-src", 1, 0, ARG_PREF_SRC }, { "metrics", 1, 0, ARG_METRICS }, { "priority", 1, 0, ARG_PRIORITY }, { "scope", 1, 0, ARG_SCOPE }, { "protocol", 1, 0, ARG_PROTOCOL }, { "type", 1, 0, ARG_TYPE }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "qhvd:n:t:", long_opts, &optidx); if (c == -1) break; switch (c) { case 'q': quiet = 1; break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; case 'd': nl_cli_route_parse_dst(route, optarg); break; case 'n': nl_cli_route_parse_nexthop(route, optarg, link_cache); break; case 't': nl_cli_route_parse_table(route, optarg); break; case ARG_FAMILY: nl_cli_route_parse_family(route, optarg); break; case ARG_SRC: nl_cli_route_parse_src(route, optarg); break; case ARG_IIF: nl_cli_route_parse_iif(route, optarg, link_cache); break; case ARG_PREF_SRC: nl_cli_route_parse_pref_src(route, optarg); break; case ARG_METRICS: nl_cli_route_parse_metric(route, optarg); break; case ARG_PRIORITY: nl_cli_route_parse_prio(route, optarg); break; case ARG_SCOPE: nl_cli_route_parse_scope(route, optarg); break; case ARG_PROTOCOL: nl_cli_route_parse_protocol(route, optarg); break; case ARG_TYPE: nl_cli_route_parse_type(route, optarg); break; } } if ((err = rtnl_route_add(sock, route, NLM_F_EXCL)) < 0) nl_cli_fatal(err, "Unable to add route: %s", nl_geterror(err)); if (!quiet) { printf("Added "); nl_object_dump(OBJ_CAST(route), &dp); } return 0; }
int main(int argc, char *argv[]) { struct rtnl_qdisc *qdisc; struct rtnl_tc *tc; struct nl_cache *link_cache, *qdisc_cache; int nfilter = 0; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache(sock); qdisc_cache = nl_cli_qdisc_alloc_cache(sock); qdisc = nl_cli_qdisc_alloc(); tc = (struct rtnl_tc *) qdisc; for (;;) { int c, optidx = 0; enum { ARG_YES = 257, ARG_INTERACTIVE = 258, }; static struct option long_opts[] = { { "interactive", 0, 0, ARG_INTERACTIVE }, { "yes", 0, 0, ARG_YES }, { "quiet", 0, 0, 'q' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "dev", 1, 0, 'd' }, { "parent", 1, 0, 'p' }, { "id", 1, 0, 'i' }, { "kind", 1, 0, 'k' }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "qhvd:p:i:k:", long_opts, &optidx); if (c == -1) break; switch (c) { case '?': nl_cli_fatal(EINVAL, "Invalid options"); case ARG_INTERACTIVE: interactive = 1; break; case ARG_YES: default_yes = 1; break; case 'q': quiet = 1; break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; case 'd': nfilter++; nl_cli_tc_parse_dev(tc, link_cache, optarg); break; case 'p': nfilter++; nl_cli_tc_parse_parent(tc, optarg); break; case 'i': nfilter++; nl_cli_tc_parse_handle(tc, optarg, 0); break; case 'k': nfilter++; nl_cli_tc_parse_kind(tc, optarg); break; } } if (nfilter == 0 && !interactive && !default_yes) { nl_cli_fatal(EINVAL, "You are attempting to delete all qdiscs on all devices.\n" "If you want to proceed, run nl-qdisc-delete --yes.\n" "Aborting..."); } nl_cache_foreach_filter(qdisc_cache, OBJ_CAST(qdisc), delete_cb, NULL); if (!quiet) printf("Deleted %d qdiscs\n", deleted); return 0; }
int main(int argc, char *argv[]) { struct rtnl_cls *cls; struct rtnl_tc *tc; struct nl_cache *link_cache; int ifindex; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache(sock); cls = nl_cli_cls_alloc(); tc = (struct rtnl_tc *) cls; params.dp_fd = stdout; for (;;) { int c, optidx = 0; enum { ARG_DETAILS = 257, ARG_STATS = 258, ARG_PROTO, ARG_PRIO, }; static struct option long_opts[] = { { "details", 0, 0, ARG_DETAILS }, { "stats", 0, 0, ARG_STATS }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "dev", 1, 0, 'd' }, { "parent", 1, 0, 'p' }, { "id", 1, 0, 'i' }, { "kind", 1, 0, 'k' }, { "proto", 1, 0, ARG_PROTO }, { "prio", 1, 0, ARG_PRIO }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "hvd:p:i:k:", long_opts, &optidx); if (c == -1) break; switch (c) { case ARG_DETAILS: params.dp_type = NL_DUMP_DETAILS; break; case ARG_STATS: params.dp_type = NL_DUMP_STATS; break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg); break; case 'p': nl_cli_tc_parse_parent(tc, optarg); break; case 'i': nl_cli_tc_parse_handle(tc, optarg, 0); break; case 'k': nl_cli_tc_parse_kind(tc, optarg); break; case ARG_PROTO: nl_cli_cls_parse_proto(cls, optarg); break; case ARG_PRIO: rtnl_cls_set_prio(cls, nl_cli_parse_u32(optarg)); break; } } if ((ifindex = rtnl_tc_get_ifindex(tc))) __dump_link(ifindex, cls); else nl_cache_foreach(link_cache, dump_link, cls); return 0; }
int main(int argc, char *argv[]) { struct nl_sock *sock; struct rtnl_cls *cls; struct rtnl_tc *tc; struct nl_cache *link_cache; struct nl_dump_params dp = { .dp_type = NL_DUMP_DETAILS, .dp_fd = stdout, }; struct nl_cli_tc_module *tm; struct rtnl_tc_ops *ops; int err, flags = NLM_F_CREATE | NLM_F_EXCL; char *kind, *id = NULL; sock = nl_cli_alloc_socket(); nl_cli_connect(sock, NETLINK_ROUTE); link_cache = nl_cli_link_alloc_cache(sock); cls = nl_cli_cls_alloc(); tc = (struct rtnl_tc *) cls; for (;;) { int c, optidx = 0; enum { ARG_UPDATE = 257, ARG_UPDATE_ONLY = 258, ARG_MTU, ARG_MPU, ARG_OVERHEAD, ARG_LINKTYPE, ARG_PROTO, ARG_PRIO, }; static struct option long_opts[] = { { "quiet", 0, 0, 'q' }, { "help", 0, 0, 'h' }, { "version", 0, 0, 'v' }, { "dev", 1, 0, 'd' }, { "parent", 1, 0, 'p' }, { "id", 1, 0, 'i' }, { "proto", 1, 0, ARG_PROTO }, { "prio", 1, 0, ARG_PRIO }, { "update", 0, 0, ARG_UPDATE }, { "update-only", 0, 0, ARG_UPDATE_ONLY }, { "mtu", 1, 0, ARG_MTU }, { "mpu", 1, 0, ARG_MPU }, { "overhead", 1, 0, ARG_OVERHEAD }, { "linktype", 1, 0, ARG_LINKTYPE }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "+qhvd:p:i:", long_opts, &optidx); if (c == -1) break; switch (c) { case 'q': quiet = 1; break; case 'h': print_usage(); break; case 'v': nl_cli_print_version(); break; case 'd': nl_cli_tc_parse_dev(tc, link_cache, optarg); break; case 'p': nl_cli_tc_parse_parent(tc, optarg); break; case 'i': id = strdup(optarg); break; case ARG_UPDATE: flags = NLM_F_CREATE; break; case ARG_UPDATE_ONLY: flags = 0; break; case ARG_MTU: nl_cli_tc_parse_mtu(tc, optarg); break; case ARG_MPU: nl_cli_tc_parse_mpu(tc, optarg); break; case ARG_OVERHEAD: nl_cli_tc_parse_overhead(tc, optarg); break; case ARG_LINKTYPE: nl_cli_tc_parse_linktype(tc, optarg); break; case ARG_PROTO: nl_cli_cls_parse_proto(cls, optarg); break; case ARG_PRIO: rtnl_cls_set_prio(cls, nl_cli_parse_u32(optarg)); break; } } if (optind >= argc) print_usage(); if (!rtnl_tc_get_ifindex(tc)) nl_cli_fatal(EINVAL, "You must specify a network device (--dev=XXX)"); if (!rtnl_tc_get_parent(tc)) nl_cli_fatal(EINVAL, "You must specify a parent (--parent=XXX)"); if (id) { nl_cli_tc_parse_handle(tc, id, 1); free(id); } kind = argv[optind++]; rtnl_tc_set_kind(tc, kind); if (!(ops = rtnl_tc_get_ops(tc))) nl_cli_fatal(ENOENT, "Unknown classifier \"%s\".", kind); if (!(tm = nl_cli_tc_lookup(ops))) nl_cli_fatal(ENOTSUP, "Classifier type \"%s\" not supported.", kind); tm->tm_parse_argv(tc, argc, argv); if (!quiet) { printf("Adding "); nl_object_dump(OBJ_CAST(cls), &dp); } if ((err = rtnl_cls_add(sock, cls, flags)) < 0) nl_cli_fatal(EINVAL, "Unable to add classifier: %s", nl_geterror(err)); return 0; }