Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
iproute2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
iproute2
Commits
7901660a
Commit
7901660a
authored
Mar 14, 2005
by
osdl.net!shemminger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change how netlink socket is handled for batch mode.
(Logical change 1.166)
parent
008b73a8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
95 deletions
+30
-95
tc/tc.c
tc/tc.c
+14
-18
tc/tc_class.c
tc/tc_class.c
+5
-22
tc/tc_common.h
tc/tc_common.h
+1
-0
tc/tc_filter.c
tc/tc_filter.c
+5
-25
tc/tc_qdisc.c
tc/tc_qdisc.c
+5
-30
No files found.
tc/tc.c
View file @
7901660a
...
...
@@ -35,8 +35,7 @@ int show_details = 0;
int
show_raw
=
0
;
int
resolve_hosts
=
0
;
int
use_iec
=
0
;
struct
rtnl_handle
g_rth
;
int
is_batch_mode
=
0
;
struct
rtnl_handle
rth
;
static
void
*
BODY
;
/* cached handle dlopen(NULL) */
static
struct
qdisc_util
*
qdisc_list
;
...
...
@@ -189,15 +188,6 @@ static int usage(void)
int
main
(
int
argc
,
char
**
argv
)
{
char
*
basename
;
basename
=
strrchr
(
argv
[
0
],
'/'
);
if
(
basename
==
NULL
)
basename
=
argv
[
0
];
else
basename
++
;
/* batch mode */
if
(
argc
>
1
&&
matches
(
argv
[
1
],
"-batch"
)
==
0
)
{
FILE
*
batch
;
...
...
@@ -223,12 +213,10 @@ int main(int argc, char **argv)
}
tc_core_init
();
is_batch_mode
=
1
;
if
(
rtnl_open
(
&
g_rth
,
0
)
<
0
)
{
fprintf
(
stderr
,
"Cannot open rtnetlink
\n
"
);
return
1
;
}
if
(
rtnl_open
(
&
rth
,
0
)
<
0
)
{
fprintf
(
stderr
,
"Cannot open rtnetlink
\n
"
);
exit
(
1
);
}
while
(
fgets
(
line
,
sizeof
(
line
)
-
1
,
batch
))
{
if
(
line
[
strlen
(
line
)
-
1
]
==
'\n'
)
{
...
...
@@ -252,6 +240,7 @@ int main(int argc, char **argv)
if
(
largv
[
0
][
0
]
==
'#'
)
continue
;
if
(
matches
(
largv
[
0
],
"qdisc"
)
==
0
)
{
ret
+=
do_qdisc
(
largc
-
1
,
largv
+
1
);
}
else
if
(
matches
(
largv
[
0
],
"class"
)
==
0
)
{
...
...
@@ -267,7 +256,9 @@ int main(int argc, char **argv)
}
}
fclose
(
batch
);
rtnl_close
(
&
g_rth
);
rtnl_close
(
&
rth
);
return
0
;
/* end of batch, that's all */
}
...
...
@@ -296,6 +287,10 @@ int main(int argc, char **argv)
}
tc_core_init
();
if
(
rtnl_open
(
&
rth
,
0
)
<
0
)
{
fprintf
(
stderr
,
"Cannot open rtnetlink
\n
"
);
exit
(
1
);
}
if
(
argc
>
1
)
{
if
(
matches
(
argv
[
1
],
"qdisc"
)
==
0
)
...
...
@@ -312,6 +307,7 @@ int main(int argc, char **argv)
return
-
1
;
}
rtnl_close
(
&
rth
);
usage
();
return
0
;
}
tc/tc_class.c
View file @
7901660a
...
...
@@ -42,7 +42,6 @@ static void usage(void)
int
tc_class_modify
(
int
cmd
,
unsigned
flags
,
int
argc
,
char
**
argv
)
{
struct
rtnl_handle
rth
;
struct
{
struct
nlmsghdr
n
;
struct
tcmsg
t
;
...
...
@@ -127,14 +126,8 @@ int tc_class_modify(int cmd, unsigned flags, int argc, char **argv)
}
}
if
(
!
is_batch_mode
)
if
(
rtnl_open
(
&
rth
,
0
)
<
0
)
{
fprintf
(
stderr
,
"Cannot open rtnetlink
\n
"
);
return
1
;
}
if
(
d
[
0
])
{
ll_init_map
(
&
(
is_batch_mode
?
g_rth
:
rth
)
);
ll_init_map
(
&
rth
);
if
((
req
.
t
.
tcm_ifindex
=
ll_name_to_index
(
d
))
==
0
)
{
fprintf
(
stderr
,
"Cannot find device
\"
%s
\"\n
"
,
d
);
...
...
@@ -142,11 +135,9 @@ int tc_class_modify(int cmd, unsigned flags, int argc, char **argv)
}
}
if
(
rtnl_talk
(
&
(
is_batch_mode
?
g_rth
:
rth
)
,
&
req
.
n
,
0
,
0
,
NULL
,
NULL
,
NULL
)
<
0
)
if
(
rtnl_talk
(
&
rth
,
&
req
.
n
,
0
,
0
,
NULL
,
NULL
,
NULL
)
<
0
)
return
2
;
if
(
!
is_batch_mode
)
rtnl_close
(
&
rth
);
return
0
;
}
...
...
@@ -280,13 +271,7 @@ int tc_class_list(int argc, char **argv)
argc
--
;
argv
++
;
}
if
(
!
is_batch_mode
)
if
(
rtnl_open
(
&
rth
,
0
)
<
0
)
{
fprintf
(
stderr
,
"Cannot open rtnetlink
\n
"
);
return
1
;
}
ll_init_map
(
&
(
is_batch_mode
?
g_rth
:
rth
));
ll_init_map
(
&
rth
);
if
(
d
[
0
])
{
if
((
t
.
tcm_ifindex
=
ll_name_to_index
(
d
))
==
0
)
{
...
...
@@ -296,20 +281,18 @@ int tc_class_list(int argc, char **argv)
filter_ifindex
=
t
.
tcm_ifindex
;
}
if
(
rtnl_dump_request
(
&
(
is_batch_mode
?
g_rth
:
rth
)
,
RTM_GETTCLASS
,
&
t
,
sizeof
(
t
))
<
0
)
{
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
(
&
(
is_batch_mode
?
g_rth
:
rth
)
,
print_class
,
stdout
,
NULL
,
NULL
)
<
0
)
{
if
(
rtnl_dump_filter
(
&
rth
,
print_class
,
stdout
,
NULL
,
NULL
)
<
0
)
{
fprintf
(
stderr
,
"Dump terminated
\n
"
);
rtnl_close
(
&
rth
);
return
1
;
}
if
(
!
is_batch_mode
)
rtnl_close
(
&
rth
);
return
0
;
}
...
...
tc/tc_common.h
View file @
7901660a
#define TCA_BUF_MAX (64*1024)
extern
struct
rtnl_handle
rth
;
extern
int
do_qdisc
(
int
argc
,
char
**
argv
);
extern
int
do_class
(
int
argc
,
char
**
argv
);
extern
int
do_filter
(
int
argc
,
char
**
argv
);
...
...
tc/tc_filter.c
View file @
7901660a
...
...
@@ -49,7 +49,6 @@ static void usage(void)
int
tc_filter_modify
(
int
cmd
,
unsigned
flags
,
int
argc
,
char
**
argv
)
{
struct
rtnl_handle
rth
;
struct
{
struct
nlmsghdr
n
;
struct
tcmsg
t
;
...
...
@@ -154,14 +153,9 @@ int tc_filter_modify(int cmd, unsigned flags, int argc, char **argv)
if
(
est
.
ewma_log
)
addattr_l
(
&
req
.
n
,
sizeof
(
req
),
TCA_RATE
,
&
est
,
sizeof
(
est
));
if
(
!
is_batch_mode
)
if
(
rtnl_open
(
&
rth
,
0
)
<
0
)
{
fprintf
(
stderr
,
"Cannot open rtnetlink
\n
"
);
return
1
;
}
if
(
d
[
0
])
{
ll_init_map
(
&
(
is_batch_mode
?
g_rth
:
rth
)
);
ll_init_map
(
&
rth
);
if
((
req
.
t
.
tcm_ifindex
=
ll_name_to_index
(
d
))
==
0
)
{
fprintf
(
stderr
,
"Cannot find device
\"
%s
\"\n
"
,
d
);
...
...
@@ -170,15 +164,11 @@ int tc_filter_modify(int cmd, unsigned flags, int argc, char **argv)
}
}
if
(
rtnl_talk
(
&
(
is_batch_mode
?
g_rth
:
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
"
);
if
(
!
is_batch_mode
)
rtnl_close
(
&
rth
);
return
2
;
}
if
(
!
is_batch_mode
)
rtnl_close
(
&
rth
);
return
0
;
}
...
...
@@ -333,13 +323,7 @@ int tc_filter_list(int argc, char **argv)
t
.
tcm_info
=
TC_H_MAKE
(
prio
<<
16
,
protocol
);
if
(
!
is_batch_mode
)
if
(
rtnl_open
(
&
rth
,
0
)
<
0
)
{
fprintf
(
stderr
,
"Cannot open rtnetlink
\n
"
);
return
1
;
}
ll_init_map
(
&
(
is_batch_mode
?
g_rth
:
rth
));
ll_init_map
(
&
rth
);
if
(
d
[
0
])
{
if
((
t
.
tcm_ifindex
=
ll_name_to_index
(
d
))
==
0
)
{
...
...
@@ -350,20 +334,16 @@ int tc_filter_list(int argc, char **argv)
filter_ifindex
=
t
.
tcm_ifindex
;
}
if
(
rtnl_dump_request
(
&
(
is_batch_mode
?
g_rth
:
rth
)
,
RTM_GETTFILTER
,
&
t
,
sizeof
(
t
))
<
0
)
{
if
(
rtnl_dump_request
(
&
rth
,
RTM_GETTFILTER
,
&
t
,
sizeof
(
t
))
<
0
)
{
perror
(
"Cannot send dump request"
);
if
(
!
is_batch_mode
)
rtnl_close
(
&
rth
);
return
1
;
}
if
(
rtnl_dump_filter
(
&
(
is_batch_mode
?
g_rth
:
rth
)
,
print_filter
,
stdout
,
NULL
,
NULL
)
<
0
)
{
if
(
rtnl_dump_filter
(
&
rth
,
print_filter
,
stdout
,
NULL
,
NULL
)
<
0
)
{
fprintf
(
stderr
,
"Dump terminated
\n
"
);
return
1
;
}
if
(
!
is_batch_mode
)
rtnl_close
(
&
rth
);
return
0
;
}
...
...
tc/tc_qdisc.c
View file @
7901660a
...
...
@@ -43,7 +43,6 @@ static int usage(void)
int
tc_qdisc_modify
(
int
cmd
,
unsigned
flags
,
int
argc
,
char
**
argv
)
{
struct
rtnl_handle
rth
;
struct
qdisc_util
*
q
=
NULL
;
struct
tc_estimator
est
;
char
d
[
16
];
...
...
@@ -139,17 +138,10 @@ int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv)
}
}
if
(
!
is_batch_mode
)
if
(
rtnl_open
(
&
rth
,
0
)
<
0
)
{
fprintf
(
stderr
,
"Cannot open rtnetlink
\n
"
);
rtnl_close
(
&
rth
);
return
1
;
}
if
(
d
[
0
])
{
int
idx
;
ll_init_map
(
&
(
is_batch_mode
?
g_rth
:
rth
)
);
ll_init_map
(
&
rth
);
if
((
idx
=
ll_name_to_index
(
d
))
==
0
)
{
fprintf
(
stderr
,
"Cannot find device
\"
%s
\"\n
"
,
d
);
...
...
@@ -159,14 +151,9 @@ int tc_qdisc_modify(int cmd, unsigned flags, int argc, char **argv)
req
.
t
.
tcm_ifindex
=
idx
;
}
if
(
rtnl_talk
(
&
(
is_batch_mode
?
g_rth
:
rth
),
&
req
.
n
,
0
,
0
,
NULL
,
NULL
,
NULL
)
<
0
)
{
if
(
!
is_batch_mode
)
rtnl_close
(
&
rth
);
if
(
rtnl_talk
(
&
rth
,
&
req
.
n
,
0
,
0
,
NULL
,
NULL
,
NULL
)
<
0
)
return
2
;
}
if
(
!
is_batch_mode
)
rtnl_close
(
&
rth
);
return
0
;
}
...
...
@@ -283,13 +270,7 @@ int tc_qdisc_list(int argc, char **argv)
argc
--
;
argv
++
;
}
if
(
!
is_batch_mode
)
if
(
rtnl_open
(
&
rth
,
0
)
<
0
)
{
fprintf
(
stderr
,
"Cannot open rtnetlink
\n
"
);
return
1
;
}
ll_init_map
(
&
(
is_batch_mode
?
g_rth
:
rth
));
ll_init_map
(
&
rth
);
if
(
d
[
0
])
{
if
((
t
.
tcm_ifindex
=
ll_name_to_index
(
d
))
==
0
)
{
...
...
@@ -300,22 +281,16 @@ int tc_qdisc_list(int argc, char **argv)
filter_ifindex
=
t
.
tcm_ifindex
;
}
if
(
rtnl_dump_request
(
&
(
is_batch_mode
?
g_rth
:
rth
)
,
RTM_GETQDISC
,
&
t
,
sizeof
(
t
))
<
0
)
{
if
(
rtnl_dump_request
(
&
rth
,
RTM_GETQDISC
,
&
t
,
sizeof
(
t
))
<
0
)
{
perror
(
"Cannot send dump request"
);
if
(
!
is_batch_mode
)
rtnl_close
(
&
rth
);
return
1
;
}
if
(
rtnl_dump_filter
(
&
(
is_batch_mode
?
g_rth
:
rth
)
,
print_qdisc
,
stdout
,
NULL
,
NULL
)
<
0
)
{
if
(
rtnl_dump_filter
(
&
rth
,
print_qdisc
,
stdout
,
NULL
,
NULL
)
<
0
)
{
fprintf
(
stderr
,
"Dump terminated
\n
"
);
if
(
!
is_batch_mode
)
rtnl_close
(
&
rth
);
return
1
;
}
if
(
!
is_batch_mode
)
rtnl_close
(
&
rth
);
return
0
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment