]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
Fix batch mode handle usage.
authorsite!shemminger <site!shemminger>
Mon, 14 Mar 2005 22:19:16 +0000 (22:19 +0000)
committersite!shemminger <site!shemminger>
Mon, 14 Mar 2005 22:19:16 +0000 (22:19 +0000)
(Logical change 1.169)

tc/f_route.c
tc/m_action.c
tc/m_mirred.c
tc/tc_class.c
tc/tc_common.h
tc/tc_filter.c
tc/tc_qdisc.c

index e9de218b7c55670754f91963eadd5dded7ce0a53..a41b9d59c9bb7e5f771aaeb99d94e0284b03dedb 100644 (file)
@@ -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;
index ad2c137a1fc060bfe4629af313ebacb735ec8fae..2d2b0edbd9477621e89ac0e4266b67666ad77d98 100644 (file)
@@ -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;
 }
 
index fd1e2c5feeed5186a1cac6679dbb0773d94941eb..6ade2a80510fedb3b2311a8dec4b7c2c94846e95 100644 (file)
@@ -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;
 }
 
index e84112d0aafc316870ef4c0e68e7aa4caa65695b..c4b27ebfa66ea6fe3066d8269c97bacb4d3c0350 100644 (file)
@@ -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;
        }
 
index 62eca47e7e92eb895e49736042a8e88dbcff0056..7e135824a7c74139324325b4cb9e54579402e3b5 100644 (file)
@@ -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);
index b68fa63e5f81963b56e86fc82775c17a53ce71af..f6de8402f344ebb11a66a0ac5b3aba7b692751e9 100644 (file)
@@ -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;
index 2a71208f6229f7c66d41e70360545210496feae3..7802d528fedddfad82024d28e521f9007efc61ed 100644 (file)
@@ -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;