Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
criu
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhul
criu
Commits
00a33747
Commit
00a33747
authored
Jan 27, 2012
by
Andrey Vagin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zdtm: cleanout netlink00
Signed-off-by:
Andrey Vagin
<
avagin@openvz.org
>
parent
3a1de341
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
60 deletions
+36
-60
netlink00.c
test/zdtm/live/streaming/netlink00.c
+36
-60
No files found.
test/zdtm/live/streaming/netlink00.c
View file @
00a33747
...
@@ -94,25 +94,19 @@ int main(int argc, char *argv[])
...
@@ -94,25 +94,19 @@ int main(int argc, char *argv[])
test_daemon
();
test_daemon
();
while
(
test_go
()){
while
(
test_go
()){
for
(
i
=
0
;
i
<
CMD_NUM
;
i
++
){
for
(
i
=
0
;
i
<
CMD_NUM
;
i
++
){
cmd
[
i
]();
cmd
[
i
]();
if
(
send_request
()
<
0
){
if
(
send_request
()
<
0
){
if
((
errno
==
EINTR
)
&&
!
test_go
())
goto
pass
;
fail
(
"send_request failed"
);
fail
(
"send_request failed"
);
goto
out
;
goto
out
;
};
};
if
(
recv_reply
()
<
0
){
if
(
recv_reply
()
<
0
){
if
((
errno
==
EINTR
)
&&
!
test_go
())
goto
pass
;
fail
(
"RTNETLINK answers: %m"
);
fail
(
"RTNETLINK answers: %m"
);
goto
out
;
goto
out
;
};
};
#ifdef DEBUG
#ifdef DEBUG
if
(
read_reply
()
<
0
){
if
(
read_reply
()
<
0
){
if
((
errno
==
EINTR
)
&&
!
test_go
())
goto
pass
;
fail
(
"read_reply failed"
);
fail
(
"read_reply failed"
);
goto
out
;
goto
out
;
}
}
...
@@ -120,8 +114,6 @@ int main(int argc, char *argv[])
...
@@ -120,8 +114,6 @@ int main(int argc, char *argv[])
}
}
}
}
test_waitsig
();
pass:
pass
();
pass
();
out:
out:
...
@@ -165,7 +157,7 @@ int recv_reply()
...
@@ -165,7 +157,7 @@ int recv_reply()
// or if it was a monitoring socket
// or if it was a monitoring socket
while
(
1
)
{
while
(
1
)
{
rtn
=
recv
(
fd
,
p
,
sizeof
(
buf
)
-
nll
,
0
);
rtn
=
recv
(
fd
,
p
,
sizeof
(
buf
)
-
nll
,
0
);
if
(
rtn
<
0
)
{
if
(
rtn
<
0
)
{
err
(
"recv failed: %m"
);
err
(
"recv failed: %m"
);
return
-
1
;
return
-
1
;
}
}
...
@@ -208,7 +200,7 @@ int read_reply()
...
@@ -208,7 +200,7 @@ int read_reply()
// headers that also include the route entry
// headers that also include the route entry
// header
// header
nlp
=
(
struct
nlmsghdr
*
)
buf
;
nlp
=
(
struct
nlmsghdr
*
)
buf
;
for
(;
NLMSG_OK
(
nlp
,
nll
);
nlp
=
NLMSG_NEXT
(
nlp
,
nll
))
for
(;
NLMSG_OK
(
nlp
,
nll
);
nlp
=
NLMSG_NEXT
(
nlp
,
nll
))
{
{
// get route entry header
// get route entry header
rtp
=
(
struct
rtmsg
*
)
NLMSG_DATA
(
nlp
);
rtp
=
(
struct
rtmsg
*
)
NLMSG_DATA
(
nlp
);
...
@@ -225,7 +217,7 @@ int read_reply()
...
@@ -225,7 +217,7 @@ int read_reply()
// one route entry
// one route entry
rtap
=
(
struct
rtattr
*
)
RTM_RTA
(
rtp
);
rtap
=
(
struct
rtattr
*
)
RTM_RTA
(
rtp
);
rtl
=
RTM_PAYLOAD
(
nlp
);
rtl
=
RTM_PAYLOAD
(
nlp
);
for
(
;
RTA_OK
(
rtap
,
rtl
);
rtap
=
RTA_NEXT
(
rtap
,
rtl
))
for
(
;
RTA_OK
(
rtap
,
rtl
);
rtap
=
RTA_NEXT
(
rtap
,
rtl
))
{
{
switch
(
rtap
->
rta_type
)
switch
(
rtap
->
rta_type
)
{
{
...
@@ -255,75 +247,59 @@ int read_reply()
...
@@ -255,75 +247,59 @@ int read_reply()
return
0
;
return
0
;
}
}
int
form_request_add
()
#define NLMSG_TAIL(nmsg) \
((struct rtattr *) (((void *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
int
form_request_del
()
{
{
// attributes of the route entry
int
ifcn
=
1
;
//interface number
// initialize RTNETLINK request buffer
bzero
(
&
req
,
sizeof
(
req
));
bzero
(
&
req
,
sizeof
(
req
));
// compute the initial length of the
req
.
nl
.
nlmsg_len
=
NLMSG_LENGTH
(
sizeof
(
struct
rtmsg
));
// service request
rtl
=
sizeof
(
struct
rtmsg
);
rtap
=
NLMSG_TAIL
(
&
req
.
nl
);
// add first attrib:
// set destination IP addr and increment the
// RTNETLINK buffer size
rtap
=
(
struct
rtattr
*
)
req
.
buf
;
rtap
->
rta_type
=
RTA_DST
;
rtap
->
rta_type
=
RTA_DST
;
rtap
->
rta_len
=
sizeof
(
struct
rtattr
)
+
4
;
rtap
->
rta_len
=
RTA_LENGTH
(
4
)
;
inet_pton
(
AF_INET
,
dsts
,
inet_pton
(
AF_INET
,
dsts
,
((
char
*
)
rtap
)
+
sizeof
(
struct
rtattr
));
((
char
*
)
rtap
)
+
sizeof
(
struct
rtattr
));
rtl
+=
rtap
->
rta_len
;
req
.
nl
.
nlmsg_len
=
NLMSG_ALIGN
(
req
.
nl
.
nlmsg_len
)
+
RTA_ALIGN
(
rtap
->
rta_len
);
// add second attrib:
req
.
nl
.
nlmsg_flags
=
NLM_F_CREATE
|
NLM_F_ACK
|
NLM_F_REQUEST
;
// set ifc index and increment the size
req
.
nl
.
nlmsg_type
=
RTM_DELROUTE
;
rtap
=
(
struct
rtattr
*
)
(((
char
*
)
rtap
)
+
rtap
->
rta_len
);
rtap
->
rta_type
=
RTA_OIF
;
//Output interface index
rtap
->
rta_len
=
sizeof
(
struct
rtattr
)
+
4
;
memcpy
(((
char
*
)
rtap
)
+
sizeof
(
struct
rtattr
),
&
ifcn
,
sizeof
(
int
));
rtl
+=
rtap
->
rta_len
;
// setup the NETLINK header
req
.
nl
.
nlmsg_len
=
NLMSG_LENGTH
(
rtl
);
req
.
nl
.
nlmsg_flags
=
NLM_F_REQUEST
|
NLM_F_CREATE
|
NLM_F_ACK
;
req
.
nl
.
nlmsg_type
=
RTM_NEWROUTE
;
// setup the service header (struct rtmsg)
req
.
rt
.
rtm_family
=
AF_INET
;
req
.
rt
.
rtm_family
=
AF_INET
;
req
.
rt
.
rtm_table
=
RT_TABLE_MAIN
;
req
.
rt
.
rtm_table
=
RT_TABLE_MAIN
;
req
.
rt
.
rtm_protocol
=
RTPROT_STATIC
;
req
.
rt
.
rtm_protocol
=
RTPROT_STATIC
;
req
.
rt
.
rtm_scope
=
RT_SCOPE_UNIVERSE
;
req
.
rt
.
rtm_scope
=
RT_SCOPE_UNIVERSE
;
req
.
rt
.
rtm_type
=
RTN_UNICAST
;
req
.
rt
.
rtm_type
=
RTN_UNICAST
;
// set the network prefix size
req
.
rt
.
rtm_dst_len
=
pn
;
req
.
rt
.
rtm_dst_len
=
pn
;
return
0
;
return
0
;
}
}
int
form_request_del
()
int
form_request_add
()
{
{
// attributes of the route entry
int
ifcn
=
1
;
//interface number
// initialize RTNETLINK request buffer
bzero
(
&
req
,
sizeof
(
req
));
bzero
(
&
req
,
sizeof
(
req
));
// compute the initial length of the
req
.
nl
.
nlmsg_len
=
NLMSG_LENGTH
(
sizeof
(
struct
rtmsg
));
// service request
rtap
=
NLMSG_TAIL
(
&
req
.
nl
);
rtl
=
sizeof
(
struct
rtmsg
);
// add first attrib:
// set destination IP addr and increment the
// RTNETLINK buffer size
rtap
=
(
struct
rtattr
*
)
req
.
buf
;
rtap
->
rta_type
=
RTA_DST
;
rtap
->
rta_type
=
RTA_DST
;
rtap
->
rta_len
=
sizeof
(
struct
rtattr
)
+
4
;
rtap
->
rta_len
=
RTA_LENGTH
(
4
)
;
inet_pton
(
AF_INET
,
dsts
,
inet_pton
(
AF_INET
,
dsts
,
((
char
*
)
rtap
)
+
sizeof
(
struct
rtattr
));
((
char
*
)
rtap
)
+
sizeof
(
struct
rtattr
));
rtl
+=
rtap
->
rta_len
;
req
.
nl
.
nlmsg_len
=
NLMSG_ALIGN
(
req
.
nl
.
nlmsg_len
)
+
RTA_ALIGN
(
rtap
->
rta_len
);
// setup the NETLINK header
req
.
nl
.
nlmsg_len
=
NLMSG_LENGTH
(
rtl
);
rtap
=
NLMSG_TAIL
(
&
req
.
nl
);;
rtap
->
rta_type
=
RTA_OIF
;
//Output interface index
rtap
->
rta_len
=
RTA_LENGTH
(
sizeof
(
int
));
memcpy
(((
char
*
)
rtap
)
+
sizeof
(
struct
rtattr
),
&
ifcn
,
sizeof
(
int
));
req
.
nl
.
nlmsg_len
=
NLMSG_ALIGN
(
req
.
nl
.
nlmsg_len
)
+
RTA_ALIGN
(
rtap
->
rta_len
);
req
.
nl
.
nlmsg_flags
=
NLM_F_REQUEST
|
NLM_F_CREATE
|
NLM_F_ACK
;
req
.
nl
.
nlmsg_flags
=
NLM_F_REQUEST
|
NLM_F_CREATE
|
NLM_F_ACK
;
req
.
nl
.
nlmsg_type
=
RTM_
DEL
ROUTE
;
req
.
nl
.
nlmsg_type
=
RTM_
NEW
ROUTE
;
// setup the service header (struct rtmsg)
req
.
rt
.
rtm_family
=
AF_INET
;
req
.
rt
.
rtm_family
=
AF_INET
;
req
.
rt
.
rtm_table
=
RT_TABLE_MAIN
;
req
.
rt
.
rtm_table
=
RT_TABLE_MAIN
;
req
.
rt
.
rtm_protocol
=
RTPROT_STATIC
;
req
.
rt
.
rtm_protocol
=
RTPROT_STATIC
;
req
.
rt
.
rtm_scope
=
RT_SCOPE_UNIVERSE
;
req
.
rt
.
rtm_scope
=
RT_SCOPE_UNIVERSE
;
req
.
rt
.
rtm_type
=
RTN_UNICAST
;
req
.
rt
.
rtm_type
=
RTN_UNICAST
;
// set the network prefix size
req
.
rt
.
rtm_dst_len
=
pn
;
req
.
rt
.
rtm_dst_len
=
pn
;
return
0
;
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