diff options
-rw-r--r-- | tc/f_route.c | 7 | ||||
-rw-r--r-- | tc/m_action.c | 28 | ||||
-rw-r--r-- | tc/m_mirred.c | 18 | ||||
-rw-r--r-- | tc/tc_class.c | 3 | ||||
-rw-r--r-- | tc/tc_common.h | 1 | ||||
-rw-r--r-- | tc/tc_filter.c | 3 | ||||
-rw-r--r-- | tc/tc_qdisc.c | 3 |
7 files changed, 7 insertions, 56 deletions
diff --git a/tc/f_route.c b/tc/f_route.c index e9de218b..a41b9d59 100644 --- a/tc/f_route.c +++ b/tc/f_route.c @@ -22,6 +22,7 @@ #include "utils.h" #include "rt_names.h" +#include "tc_common.h" #include "tc_util.h" static void explain(void) @@ -79,13 +80,9 @@ static int route_parse_opt(struct filter_util *qu, char *handle, int argc, char fh &= 0xFFFF; fh |= id<<16; } else if (matches(*argv, "fromif") == 0) { - struct rtnl_handle rth; __u32 id; NEXT_ARG(); - if (rtnl_open(&rth, 0) == 0) { - ll_init_map(&rth); - rtnl_close(&rth); - } + ll_init_map(&rth); if ((id=ll_name_to_index(*argv)) <= 0) { fprintf(stderr, "Illegal \"fromif\"\n"); return -1; diff --git a/tc/m_action.c b/tc/m_action.c index ad2c137a..2d2b0edb 100644 --- a/tc/m_action.c +++ b/tc/m_action.c @@ -25,6 +25,7 @@ #include <dlfcn.h> #include "utils.h" +#include "tc_common.h" #include "tc_util.h" static struct action_util * action_list; @@ -341,7 +342,6 @@ int tc_action_gd(int cmd, unsigned flags, int *argc_p, char ***argv_p) int prio = 0; int ret = 0; __u32 i; - struct rtnl_handle rth; struct sockaddr_nl nladdr; struct rtattr *tail; struct rtattr *tail2; @@ -425,29 +425,22 @@ int tc_action_gd(int cmd, unsigned flags, int *argc_p, char ***argv_p) tail->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail; - if (rtnl_open(&rth, 0) < 0) { - fprintf(stderr, "Cannot open rtnetlink\n"); - return 1; - } - req.n.nlmsg_seq = rth.dump = ++rth.seq; if (cmd == RTM_GETACTION) ans = &req.n; + if (rtnl_talk(&rth, &req.n, 0, 0, ans, NULL, NULL) < 0) { fprintf(stderr, "We have an error talking to the kernel\n"); - rtnl_close(&rth); return 1; } if (ans && do_print_action(NULL, &req.n, (void*)stdout) < 0) { fprintf(stderr, "Dump terminated\n"); - rtnl_close(&rth); return 1; } *argc_p = argc; *argv_p = argv; - rtnl_close(&rth); bad_val: return ret; } @@ -458,7 +451,6 @@ int tc_action_modify(int cmd, unsigned flags, int *argc_p, char ***argv_p) char **argv = *argv_p; int ret = 0; - struct rtnl_handle rth; struct rtattr *tail; struct { struct nlmsghdr n; @@ -482,12 +474,6 @@ int tc_action_modify(int cmd, unsigned flags, int *argc_p, char ***argv_p) } tail->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail; - if (rtnl_open(&rth, 0) < 0) { - fprintf(stderr, "Cannot open rtnetlink\n"); - return 1; - } - - if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0) { fprintf(stderr, "We have an error talking to the kernel\n"); ret = -1; @@ -495,7 +481,7 @@ int tc_action_modify(int cmd, unsigned flags, int *argc_p, char ***argv_p) *argc_p = argc; *argv_p = argv; - rtnl_close(&rth); + return ret; } @@ -503,7 +489,6 @@ int tc_act_list_or_flush(int argc, char **argv, int event) { int ret = 0, prio = 0, msg_size = 0; char k[16]; - struct rtnl_handle rth; struct rtattr *tail,*tail2; struct action_util *a = NULL; struct { @@ -544,11 +529,6 @@ int tc_act_list_or_flush(int argc, char **argv, int event) tail2->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail2; tail->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail; - if (rtnl_open(&rth, 0) < 0) { - fprintf(stderr, "Cannot open rtnetlink\n"); - return 1; - } - msg_size = NLMSG_ALIGN(req.n.nlmsg_len) - NLMSG_ALIGN(sizeof(struct nlmsghdr)); if (event == RTM_GETACTION) { @@ -566,7 +546,6 @@ int tc_act_list_or_flush(int argc, char **argv, int event) req.n.nlmsg_flags |= NLM_F_REQUEST; if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0) { fprintf(stderr, "We have an error flushing\n"); - rtnl_close(&rth); return 1; } @@ -574,7 +553,6 @@ int tc_act_list_or_flush(int argc, char **argv, int event) bad_val: - rtnl_close(&rth); return ret; } diff --git a/tc/m_mirred.c b/tc/m_mirred.c index fd1e2c5f..6ade2a80 100644 --- a/tc/m_mirred.c +++ b/tc/m_mirred.c @@ -23,6 +23,7 @@ #include <string.h> #include "utils.h" #include "tc_util.h" +#include "tc_common.h" #include <linux/tc_act/tc_mirred.h> int mirred_d = 1; @@ -66,7 +67,6 @@ parse_egress(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, str struct tc_mirred p; struct rtattr *tail; char d[16]; - struct rtnl_handle rth; memset(d,0,sizeof(d)-1); memset(&p,0,sizeof(struct tc_mirred)); @@ -141,21 +141,14 @@ parse_egress(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, str if (d[0]) { int idx; - if (rtnl_open(&rth, 0) < 0) { - fprintf(stderr, "Cannot open rtnetlink\n"); - return 1; - } ll_init_map(&rth); - if ((idx = ll_name_to_index(d)) == 0) { fprintf(stderr, "Cannot find device \"%s\"\n", d); - rtnl_close(&rth); return -1; } p.ifindex = idx; - rtnl_close(&rth); } @@ -256,7 +249,6 @@ print_mirred(struct action_util *au,FILE * f, struct rtattr *arg) { struct tc_mirred *p; struct rtattr *tb[TCA_MIRRED_MAX + 1]; - struct rtnl_handle rth; const char *dev; SPRINT_BUF(b1); @@ -271,17 +263,10 @@ print_mirred(struct action_util *au,FILE * f, struct rtattr *arg) } p = RTA_DATA(tb[TCA_MIRRED_PARMS]); - if (rtnl_open(&rth, 0) < 0) { - fprintf(stderr, "Cannot open rtnetlink\n"); - return -1; - } - ll_init_map(&rth); - if ((dev = ll_index_to_name(p->ifindex)) == 0) { fprintf(stderr, "Cannot find device %d\n", p->ifindex); - rtnl_close(&rth); return -1; } @@ -297,7 +282,6 @@ print_mirred(struct action_util *au,FILE * f, struct rtattr *arg) } } fprintf(f, "\n "); - rtnl_close(&rth); return 0; } diff --git a/tc/tc_class.c b/tc/tc_class.c index e84112d0..c4b27ebf 100644 --- a/tc/tc_class.c +++ b/tc/tc_class.c @@ -228,7 +228,6 @@ static int print_class(const struct sockaddr_nl *who, int tc_class_list(int argc, char **argv) { struct tcmsg t; - struct rtnl_handle rth; char d[16]; memset(&t, 0, sizeof(t)); @@ -283,13 +282,11 @@ int tc_class_list(int argc, char **argv) if (rtnl_dump_request(&rth, RTM_GETTCLASS, &t, sizeof(t)) < 0) { perror("Cannot send dump request"); - rtnl_close(&rth); return 1; } if (rtnl_dump_filter(&rth, print_class, stdout, NULL, NULL) < 0) { fprintf(stderr, "Dump terminated\n"); - rtnl_close(&rth); return 1; } diff --git a/tc/tc_common.h b/tc/tc_common.h index 62eca47e..7e135824 100644 --- a/tc/tc_common.h +++ b/tc/tc_common.h @@ -7,4 +7,5 @@ extern int do_class(int argc, char **argv); extern int do_filter(int argc, char **argv); extern int do_action(int argc, char **argv); +struct tc_estimator; extern int parse_estimator(int *p_argc, char ***p_argv, struct tc_estimator *est); diff --git a/tc/tc_filter.c b/tc/tc_filter.c index b68fa63e..f6de8402 100644 --- a/tc/tc_filter.c +++ b/tc/tc_filter.c @@ -159,7 +159,6 @@ int tc_filter_modify(int cmd, unsigned flags, int argc, char **argv) if ((req.t.tcm_ifindex = ll_name_to_index(d)) == 0) { fprintf(stderr, "Cannot find device \"%s\"\n", d); - rtnl_close(&rth); return 1; } } @@ -259,7 +258,6 @@ static int print_filter(const struct sockaddr_nl *who, int tc_filter_list(int argc, char **argv) { struct tcmsg t; - struct rtnl_handle rth; char d[16]; __u32 prio = 0; __u32 protocol = 0; @@ -328,7 +326,6 @@ int tc_filter_list(int argc, char **argv) if (d[0]) { if ((t.tcm_ifindex = ll_name_to_index(d)) == 0) { fprintf(stderr, "Cannot find device \"%s\"\n", d); - rtnl_close(&rth); return 1; } filter_ifindex = t.tcm_ifindex; diff --git a/tc/tc_qdisc.c b/tc/tc_qdisc.c index 2a71208f..7802d528 100644 --- a/tc/tc_qdisc.c +++ b/tc/tc_qdisc.c @@ -145,7 +145,6 @@ int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv) if ((idx = ll_name_to_index(d)) == 0) { fprintf(stderr, "Cannot find device \"%s\"\n", d); - rtnl_close(&rth); return 1; } req.t.tcm_ifindex = idx; @@ -241,7 +240,6 @@ static int print_qdisc(const struct sockaddr_nl *who, int tc_qdisc_list(int argc, char **argv) { struct tcmsg t; - struct rtnl_handle rth; char d[16]; memset(&t, 0, sizeof(t)); @@ -275,7 +273,6 @@ int tc_qdisc_list(int argc, char **argv) if (d[0]) { if ((t.tcm_ifindex = ll_name_to_index(d)) == 0) { fprintf(stderr, "Cannot find device \"%s\"\n", d); - rtnl_close(&rth); return 1; } filter_ifindex = t.tcm_ifindex; |