mirror of
https://git.proxmox.com/git/mirror_iproute2
synced 2025-11-03 20:20:35 +00:00
Fix batch mode handle usage.
(Logical change 1.169)
This commit is contained in:
parent
28fb99c441
commit
c1027a759b
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user