Commit c1027a75 authored by site!shemminger's avatar site!shemminger

Fix batch mode handle usage.

(Logical change 1.169)
parent 28fb99c4
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "utils.h" #include "utils.h"
#include "rt_names.h" #include "rt_names.h"
#include "tc_common.h"
#include "tc_util.h" #include "tc_util.h"
static void explain(void) static void explain(void)
...@@ -79,13 +80,9 @@ static int route_parse_opt(struct filter_util *qu, char *handle, int argc, char ...@@ -79,13 +80,9 @@ static int route_parse_opt(struct filter_util *qu, char *handle, int argc, char
fh &= 0xFFFF; fh &= 0xFFFF;
fh |= id<<16; fh |= id<<16;
} else if (matches(*argv, "fromif") == 0) { } else if (matches(*argv, "fromif") == 0) {
struct rtnl_handle rth;
__u32 id; __u32 id;
NEXT_ARG(); NEXT_ARG();
if (rtnl_open(&rth, 0) == 0) { ll_init_map(&rth);
ll_init_map(&rth);
rtnl_close(&rth);
}
if ((id=ll_name_to_index(*argv)) <= 0) { if ((id=ll_name_to_index(*argv)) <= 0) {
fprintf(stderr, "Illegal \"fromif\"\n"); fprintf(stderr, "Illegal \"fromif\"\n");
return -1; return -1;
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <dlfcn.h> #include <dlfcn.h>
#include "utils.h" #include "utils.h"
#include "tc_common.h"
#include "tc_util.h" #include "tc_util.h"
static struct action_util * action_list; static struct action_util * action_list;
...@@ -341,7 +342,6 @@ int tc_action_gd(int cmd, unsigned flags, int *argc_p, char ***argv_p) ...@@ -341,7 +342,6 @@ int tc_action_gd(int cmd, unsigned flags, int *argc_p, char ***argv_p)
int prio = 0; int prio = 0;
int ret = 0; int ret = 0;
__u32 i; __u32 i;
struct rtnl_handle rth;
struct sockaddr_nl nladdr; struct sockaddr_nl nladdr;
struct rtattr *tail; struct rtattr *tail;
struct rtattr *tail2; struct rtattr *tail2;
...@@ -425,29 +425,22 @@ int tc_action_gd(int cmd, unsigned flags, int *argc_p, char ***argv_p) ...@@ -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; 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; req.n.nlmsg_seq = rth.dump = ++rth.seq;
if (cmd == RTM_GETACTION) if (cmd == RTM_GETACTION)
ans = &req.n; ans = &req.n;
if (rtnl_talk(&rth, &req.n, 0, 0, ans, NULL, NULL) < 0) { if (rtnl_talk(&rth, &req.n, 0, 0, ans, NULL, NULL) < 0) {
fprintf(stderr, "We have an error talking to the kernel\n"); fprintf(stderr, "We have an error talking to the kernel\n");
rtnl_close(&rth);
return 1; return 1;
} }
if (ans && do_print_action(NULL, &req.n, (void*)stdout) < 0) { if (ans && do_print_action(NULL, &req.n, (void*)stdout) < 0) {
fprintf(stderr, "Dump terminated\n"); fprintf(stderr, "Dump terminated\n");
rtnl_close(&rth);
return 1; return 1;
} }
*argc_p = argc; *argc_p = argc;
*argv_p = argv; *argv_p = argv;
rtnl_close(&rth);
bad_val: bad_val:
return ret; return ret;
} }
...@@ -458,7 +451,6 @@ int tc_action_modify(int cmd, unsigned flags, int *argc_p, char ***argv_p) ...@@ -458,7 +451,6 @@ int tc_action_modify(int cmd, unsigned flags, int *argc_p, char ***argv_p)
char **argv = *argv_p; char **argv = *argv_p;
int ret = 0; int ret = 0;
struct rtnl_handle rth;
struct rtattr *tail; struct rtattr *tail;
struct { struct {
struct nlmsghdr n; struct nlmsghdr n;
...@@ -482,12 +474,6 @@ int tc_action_modify(int cmd, unsigned flags, int *argc_p, char ***argv_p) ...@@ -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; 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) { if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0) {
fprintf(stderr, "We have an error talking to the kernel\n"); fprintf(stderr, "We have an error talking to the kernel\n");
ret = -1; ret = -1;
...@@ -495,7 +481,7 @@ int tc_action_modify(int cmd, unsigned flags, int *argc_p, char ***argv_p) ...@@ -495,7 +481,7 @@ int tc_action_modify(int cmd, unsigned flags, int *argc_p, char ***argv_p)
*argc_p = argc; *argc_p = argc;
*argv_p = argv; *argv_p = argv;
rtnl_close(&rth);
return ret; return ret;
} }
...@@ -503,7 +489,6 @@ int tc_act_list_or_flush(int argc, char **argv, int event) ...@@ -503,7 +489,6 @@ int tc_act_list_or_flush(int argc, char **argv, int event)
{ {
int ret = 0, prio = 0, msg_size = 0; int ret = 0, prio = 0, msg_size = 0;
char k[16]; char k[16];
struct rtnl_handle rth;
struct rtattr *tail,*tail2; struct rtattr *tail,*tail2;
struct action_util *a = NULL; struct action_util *a = NULL;
struct { struct {
...@@ -544,11 +529,6 @@ int tc_act_list_or_flush(int argc, char **argv, int event) ...@@ -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; tail2->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail2;
tail->rta_len = (void *) NLMSG_TAIL(&req.n) - (void *) tail; 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)); msg_size = NLMSG_ALIGN(req.n.nlmsg_len) - NLMSG_ALIGN(sizeof(struct nlmsghdr));
if (event == RTM_GETACTION) { if (event == RTM_GETACTION) {
...@@ -566,7 +546,6 @@ int tc_act_list_or_flush(int argc, char **argv, int event) ...@@ -566,7 +546,6 @@ int tc_act_list_or_flush(int argc, char **argv, int event)
req.n.nlmsg_flags |= NLM_F_REQUEST; req.n.nlmsg_flags |= NLM_F_REQUEST;
if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0) { if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0) {
fprintf(stderr, "We have an error flushing\n"); fprintf(stderr, "We have an error flushing\n");
rtnl_close(&rth);
return 1; return 1;
} }
...@@ -574,7 +553,6 @@ int tc_act_list_or_flush(int argc, char **argv, int event) ...@@ -574,7 +553,6 @@ int tc_act_list_or_flush(int argc, char **argv, int event)
bad_val: bad_val:
rtnl_close(&rth);
return ret; return ret;
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <string.h> #include <string.h>
#include "utils.h" #include "utils.h"
#include "tc_util.h" #include "tc_util.h"
#include "tc_common.h"
#include <linux/tc_act/tc_mirred.h> #include <linux/tc_act/tc_mirred.h>
int mirred_d = 1; int mirred_d = 1;
...@@ -66,7 +67,6 @@ parse_egress(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, str ...@@ -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 tc_mirred p;
struct rtattr *tail; struct rtattr *tail;
char d[16]; char d[16];
struct rtnl_handle rth;
memset(d,0,sizeof(d)-1); memset(d,0,sizeof(d)-1);
memset(&p,0,sizeof(struct tc_mirred)); 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 ...@@ -141,21 +141,14 @@ parse_egress(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, str
if (d[0]) { if (d[0]) {
int idx; int idx;
if (rtnl_open(&rth, 0) < 0) {
fprintf(stderr, "Cannot open rtnetlink\n");
return 1;
}
ll_init_map(&rth); ll_init_map(&rth);
if ((idx = ll_name_to_index(d)) == 0) { if ((idx = ll_name_to_index(d)) == 0) {
fprintf(stderr, "Cannot find device \"%s\"\n", d); fprintf(stderr, "Cannot find device \"%s\"\n", d);
rtnl_close(&rth);
return -1; return -1;
} }
p.ifindex = idx; p.ifindex = idx;
rtnl_close(&rth);
} }
...@@ -256,7 +249,6 @@ print_mirred(struct action_util *au,FILE * f, struct rtattr *arg) ...@@ -256,7 +249,6 @@ print_mirred(struct action_util *au,FILE * f, struct rtattr *arg)
{ {
struct tc_mirred *p; struct tc_mirred *p;
struct rtattr *tb[TCA_MIRRED_MAX + 1]; struct rtattr *tb[TCA_MIRRED_MAX + 1];
struct rtnl_handle rth;
const char *dev; const char *dev;
SPRINT_BUF(b1); SPRINT_BUF(b1);
...@@ -271,17 +263,10 @@ print_mirred(struct action_util *au,FILE * f, struct rtattr *arg) ...@@ -271,17 +263,10 @@ print_mirred(struct action_util *au,FILE * f, struct rtattr *arg)
} }
p = RTA_DATA(tb[TCA_MIRRED_PARMS]); 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); ll_init_map(&rth);
if ((dev = ll_index_to_name(p->ifindex)) == 0) { if ((dev = ll_index_to_name(p->ifindex)) == 0) {
fprintf(stderr, "Cannot find device %d\n", p->ifindex); fprintf(stderr, "Cannot find device %d\n", p->ifindex);
rtnl_close(&rth);
return -1; return -1;
} }
...@@ -297,7 +282,6 @@ print_mirred(struct action_util *au,FILE * f, struct rtattr *arg) ...@@ -297,7 +282,6 @@ print_mirred(struct action_util *au,FILE * f, struct rtattr *arg)
} }
} }
fprintf(f, "\n "); fprintf(f, "\n ");
rtnl_close(&rth);
return 0; return 0;
} }
......
...@@ -228,7 +228,6 @@ static int print_class(const struct sockaddr_nl *who, ...@@ -228,7 +228,6 @@ static int print_class(const struct sockaddr_nl *who,
int tc_class_list(int argc, char **argv) int tc_class_list(int argc, char **argv)
{ {
struct tcmsg t; struct tcmsg t;
struct rtnl_handle rth;
char d[16]; char d[16];
memset(&t, 0, sizeof(t)); memset(&t, 0, sizeof(t));
...@@ -283,13 +282,11 @@ int tc_class_list(int argc, char **argv) ...@@ -283,13 +282,11 @@ int tc_class_list(int argc, char **argv)
if (rtnl_dump_request(&rth, RTM_GETTCLASS, &t, sizeof(t)) < 0) { if (rtnl_dump_request(&rth, RTM_GETTCLASS, &t, sizeof(t)) < 0) {
perror("Cannot send dump request"); perror("Cannot send dump request");
rtnl_close(&rth);
return 1; return 1;
} }
if (rtnl_dump_filter(&rth, print_class, stdout, NULL, NULL) < 0) { if (rtnl_dump_filter(&rth, print_class, stdout, NULL, NULL) < 0) {
fprintf(stderr, "Dump terminated\n"); fprintf(stderr, "Dump terminated\n");
rtnl_close(&rth);
return 1; return 1;
} }
......
...@@ -7,4 +7,5 @@ extern int do_class(int argc, char **argv); ...@@ -7,4 +7,5 @@ extern int do_class(int argc, char **argv);
extern int do_filter(int argc, char **argv); extern int do_filter(int argc, char **argv);
extern int do_action(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); extern int parse_estimator(int *p_argc, char ***p_argv, struct tc_estimator *est);
...@@ -159,7 +159,6 @@ int tc_filter_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -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) { if ((req.t.tcm_ifindex = ll_name_to_index(d)) == 0) {
fprintf(stderr, "Cannot find device \"%s\"\n", d); fprintf(stderr, "Cannot find device \"%s\"\n", d);
rtnl_close(&rth);
return 1; return 1;
} }
} }
...@@ -259,7 +258,6 @@ static int print_filter(const struct sockaddr_nl *who, ...@@ -259,7 +258,6 @@ static int print_filter(const struct sockaddr_nl *who,
int tc_filter_list(int argc, char **argv) int tc_filter_list(int argc, char **argv)
{ {
struct tcmsg t; struct tcmsg t;
struct rtnl_handle rth;
char d[16]; char d[16];
__u32 prio = 0; __u32 prio = 0;
__u32 protocol = 0; __u32 protocol = 0;
...@@ -328,7 +326,6 @@ int tc_filter_list(int argc, char **argv) ...@@ -328,7 +326,6 @@ int tc_filter_list(int argc, char **argv)
if (d[0]) { if (d[0]) {
if ((t.tcm_ifindex = ll_name_to_index(d)) == 0) { if ((t.tcm_ifindex = ll_name_to_index(d)) == 0) {
fprintf(stderr, "Cannot find device \"%s\"\n", d); fprintf(stderr, "Cannot find device \"%s\"\n", d);
rtnl_close(&rth);
return 1; return 1;
} }
filter_ifindex = t.tcm_ifindex; filter_ifindex = t.tcm_ifindex;
......
...@@ -145,7 +145,6 @@ int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv) ...@@ -145,7 +145,6 @@ int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv)
if ((idx = ll_name_to_index(d)) == 0) { if ((idx = ll_name_to_index(d)) == 0) {
fprintf(stderr, "Cannot find device \"%s\"\n", d); fprintf(stderr, "Cannot find device \"%s\"\n", d);
rtnl_close(&rth);
return 1; return 1;
} }
req.t.tcm_ifindex = idx; req.t.tcm_ifindex = idx;
...@@ -241,7 +240,6 @@ static int print_qdisc(const struct sockaddr_nl *who, ...@@ -241,7 +240,6 @@ static int print_qdisc(const struct sockaddr_nl *who,
int tc_qdisc_list(int argc, char **argv) int tc_qdisc_list(int argc, char **argv)
{ {
struct tcmsg t; struct tcmsg t;
struct rtnl_handle rth;
char d[16]; char d[16];
memset(&t, 0, sizeof(t)); memset(&t, 0, sizeof(t));
...@@ -275,7 +273,6 @@ int tc_qdisc_list(int argc, char **argv) ...@@ -275,7 +273,6 @@ int tc_qdisc_list(int argc, char **argv)
if (d[0]) { if (d[0]) {
if ((t.tcm_ifindex = ll_name_to_index(d)) == 0) { if ((t.tcm_ifindex = ll_name_to_index(d)) == 0) {
fprintf(stderr, "Cannot find device \"%s\"\n", d); fprintf(stderr, "Cannot find device \"%s\"\n", d);
rtnl_close(&rth);
return 1; return 1;
} }
filter_ifindex = t.tcm_ifindex; filter_ifindex = t.tcm_ifindex;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment