Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
babeld
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
babeld
Commits
c18e3b0a
Commit
c18e3b0a
authored
Nov 04, 2015
by
Matthieu Boutier
Committed by
Juliusz Chroboczek
Nov 12, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify netlink_read.
parent
72a62643
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
26 deletions
+22
-26
kernel_netlink.c
kernel_netlink.c
+22
-26
No files found.
kernel_netlink.c
View file @
c18e3b0a
...
@@ -261,7 +261,7 @@ netlink_socket(struct netlink *nl, uint32_t groups)
...
@@ -261,7 +261,7 @@ netlink_socket(struct netlink *nl, uint32_t groups)
static
int
static
int
netlink_read
(
struct
netlink
*
nl
,
struct
netlink
*
nl_ignore
,
int
answer
,
netlink_read
(
struct
netlink
*
nl
,
struct
netlink
*
nl_ignore
,
int
answer
,
int
(
*
fn
)(
struct
nlmsghdr
*
nh
,
void
*
data
),
void
*
data
)
struct
kernel_filter
*
filter
)
{
{
/* 'answer' must be true when we just have send a request on 'nl_socket' */
/* 'answer' must be true when we just have send a request on 'nl_socket' */
...
@@ -271,9 +271,7 @@ netlink_read(struct netlink *nl, struct netlink *nl_ignore, int answer,
...
@@ -271,9 +271,7 @@ netlink_read(struct netlink *nl, struct netlink *nl_ignore, int answer,
/* Return code : */
/* Return code : */
/* -1 : error */
/* -1 : error */
/* 0 : if(fn) found_interesting; else found_ack; */
/* 0 : success */
/* 1 : only if(fn) nothing interesting has been found */
/* 2 : nothing found, retry */
int
err
;
int
err
;
struct
msghdr
msg
;
struct
msghdr
msg
;
...
@@ -281,8 +279,8 @@ netlink_read(struct netlink *nl, struct netlink *nl_ignore, int answer,
...
@@ -281,8 +279,8 @@ netlink_read(struct netlink *nl, struct netlink *nl_ignore, int answer,
struct
iovec
iov
;
struct
iovec
iov
;
struct
nlmsghdr
*
nh
;
struct
nlmsghdr
*
nh
;
int
len
;
int
len
;
int
interesting
=
0
;
int
done
=
0
;
int
done
=
0
;
int
skip
=
0
;
char
buf
[
8192
];
char
buf
[
8192
];
...
@@ -314,7 +312,7 @@ netlink_read(struct netlink *nl, struct netlink *nl_ignore, int answer,
...
@@ -314,7 +312,7 @@ netlink_read(struct netlink *nl, struct netlink *nl_ignore, int answer,
if
(
len
<
0
)
{
if
(
len
<
0
)
{
perror
(
"netlink_read: recvmsg()"
);
perror
(
"netlink_read: recvmsg()"
);
return
2
;
return
-
1
;
}
else
if
(
len
==
0
)
{
}
else
if
(
len
==
0
)
{
fprintf
(
stderr
,
"netlink_read: EOF
\n
"
);
fprintf
(
stderr
,
"netlink_read: EOF
\n
"
);
goto
socket_error
;
goto
socket_error
;
...
@@ -325,7 +323,7 @@ netlink_read(struct netlink *nl, struct netlink *nl_ignore, int answer,
...
@@ -325,7 +323,7 @@ netlink_read(struct netlink *nl, struct netlink *nl_ignore, int answer,
goto
socket_error
;
goto
socket_error
;
}
else
if
(
nladdr
.
nl_pid
!=
0
)
{
}
else
if
(
nladdr
.
nl_pid
!=
0
)
{
kdebugf
(
"netlink_read: message not sent by kernel.
\n
"
);
kdebugf
(
"netlink_read: message not sent by kernel.
\n
"
);
return
2
;
return
-
1
;
}
}
kdebugf
(
"Netlink message: "
);
kdebugf
(
"Netlink message: "
);
...
@@ -359,12 +357,13 @@ netlink_read(struct netlink *nl, struct netlink *nl_ignore, int answer,
...
@@ -359,12 +357,13 @@ netlink_read(struct netlink *nl, struct netlink *nl_ignore, int answer,
errno
=
-
err
->
error
;
errno
=
-
err
->
error
;
return
-
1
;
return
-
1
;
}
}
}
else
if
(
fn
)
{
}
else
if
(
skip
)
{
kdebugf
(
"(skip)"
);
}
if
(
filter
)
{
kdebugf
(
"(msg ->
\"
"
);
kdebugf
(
"(msg ->
\"
"
);
err
=
f
n
(
nh
,
data
);
err
=
f
ilter_netlink
(
nh
,
filter
);
kdebugf
(
"
\"
%d), "
,
err
);
kdebugf
(
"
\"
%d), "
,
err
);
if
(
err
<
0
)
return
err
;
if
(
err
<
0
)
skip
=
1
;
interesting
=
interesting
||
err
;
continue
;
continue
;
}
}
kdebugf
(
", "
);
kdebugf
(
", "
);
...
@@ -376,14 +375,14 @@ netlink_read(struct netlink *nl, struct netlink *nl_ignore, int answer,
...
@@ -376,14 +375,14 @@ netlink_read(struct netlink *nl, struct netlink *nl_ignore, int answer,
}
while
(
!
done
);
}
while
(
!
done
);
return
interesting
;
return
0
;
socket_error:
socket_error:
close
(
nl
->
sock
);
close
(
nl
->
sock
);
nl
->
sock
=
-
1
;
nl
->
sock
=
-
1
;
errno
=
EIO
;
errno
=
EIO
;
return
-
1
;
return
-
1
;
}
}
static
int
static
int
netlink_talk
(
struct
nlmsghdr
*
nh
)
netlink_talk
(
struct
nlmsghdr
*
nh
)
...
@@ -428,7 +427,7 @@ netlink_talk(struct nlmsghdr *nh)
...
@@ -428,7 +427,7 @@ netlink_talk(struct nlmsghdr *nh)
return
-
1
;
return
-
1
;
}
}
rc
=
netlink_read
(
&
nl_command
,
NULL
,
1
,
NULL
,
NULL
);
/* ACK */
rc
=
netlink_read
(
&
nl_command
,
NULL
,
1
,
NULL
);
/* ACK */
return
rc
;
return
rc
;
}
}
...
@@ -1224,8 +1223,7 @@ kernel_dump(int operation, struct kernel_filter *filter)
...
@@ -1224,8 +1223,7 @@ kernel_dump(int operation, struct kernel_filter *filter)
if
(
rc
<
0
)
if
(
rc
<
0
)
return
-
1
;
return
-
1
;
rc
=
netlink_read
(
&
nl_command
,
NULL
,
1
,
rc
=
netlink_read
(
&
nl_command
,
NULL
,
1
,
filter
);
filter_netlink
,
(
void
*
)
filter
);
if
(
rc
<
0
)
if
(
rc
<
0
)
return
-
1
;
return
-
1
;
}
}
...
@@ -1237,8 +1235,7 @@ kernel_dump(int operation, struct kernel_filter *filter)
...
@@ -1237,8 +1235,7 @@ kernel_dump(int operation, struct kernel_filter *filter)
if
(
rc
<
0
)
if
(
rc
<
0
)
return
-
1
;
return
-
1
;
rc
=
netlink_read
(
&
nl_command
,
NULL
,
1
,
rc
=
netlink_read
(
&
nl_command
,
NULL
,
1
,
filter
);
filter_netlink
,
(
void
*
)
filter
);
if
(
rc
<
0
)
if
(
rc
<
0
)
return
-
1
;
return
-
1
;
}
}
...
@@ -1251,7 +1248,7 @@ kernel_dump(int operation, struct kernel_filter *filter)
...
@@ -1251,7 +1248,7 @@ kernel_dump(int operation, struct kernel_filter *filter)
if
(
rc
<
0
)
if
(
rc
<
0
)
return
-
1
;
return
-
1
;
rc
=
netlink_read
(
&
nl_command
,
NULL
,
1
,
filter
_netlink
,
(
void
*
)
filter
);
rc
=
netlink_read
(
&
nl_command
,
NULL
,
1
,
filter
);
if
(
rc
<
0
)
if
(
rc
<
0
)
return
-
1
;
return
-
1
;
}
}
...
@@ -1512,8 +1509,7 @@ kernel_callback(struct kernel_filter *filter)
...
@@ -1512,8 +1509,7 @@ kernel_callback(struct kernel_filter *filter)
return
-
1
;
return
-
1
;
}
}
}
}
rc
=
netlink_read
(
&
nl_listen
,
&
nl_command
,
0
,
filter_netlink
,
rc
=
netlink_read
(
&
nl_listen
,
&
nl_command
,
0
,
filter
);
(
void
*
)
filter
);
if
(
rc
<
0
&&
nl_listen
.
sock
<
0
)
if
(
rc
<
0
&&
nl_listen
.
sock
<
0
)
kernel_setup_socket
(
1
);
kernel_setup_socket
(
1
);
...
...
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