Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
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
Chen Yisong
lxc
Commits
f728ff0c
Unverified
Commit
f728ff0c
authored
Aug 11, 2018
by
Stéphane Graber
Committed by
GitHub
Aug 11, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2521 from brauner/2018-08-11/fix_netnsid_allocation
netlink: add __netlink_{send,recv,transaction}
parents
d813c8ed
9fbbc427
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
105 deletions
+40
-105
network.c
src/lxc/network.c
+1
-88
nl.c
src/lxc/nl.c
+35
-17
nl.h
src/lxc/nl.h
+4
-0
No files found.
src/lxc/network.c
View file @
f728ff0c
...
@@ -3192,93 +3192,6 @@ enum {
...
@@ -3192,93 +3192,6 @@ enum {
__LXC_NETNSA_MAX
,
__LXC_NETNSA_MAX
,
};
};
static
int
nl_send
(
struct
nl_handler
*
handler
,
struct
nlmsghdr
*
nlmsghdr
)
{
struct
sockaddr_nl
nladdr
;
struct
iovec
iov
=
{
.
iov_base
=
nlmsghdr
,
.
iov_len
=
nlmsghdr
->
nlmsg_len
,
};
struct
msghdr
msg
=
{
.
msg_name
=
&
nladdr
,
.
msg_namelen
=
sizeof
(
nladdr
),
.
msg_iov
=
&
iov
,
.
msg_iovlen
=
1
,
};
int
ret
;
memset
(
&
nladdr
,
0
,
sizeof
(
nladdr
));
nladdr
.
nl_family
=
AF_NETLINK
;
nladdr
.
nl_pid
=
0
;
nladdr
.
nl_groups
=
0
;
ret
=
sendmsg
(
handler
->
fd
,
&
msg
,
MSG_NOSIGNAL
);
if
(
ret
<
0
)
return
-
errno
;
return
ret
;
}
static
int
nl_recv
(
struct
nl_handler
*
handler
,
struct
nlmsghdr
*
nlmsghdr
)
{
int
ret
;
struct
sockaddr_nl
nladdr
;
struct
iovec
iov
=
{
.
iov_base
=
nlmsghdr
,
.
iov_len
=
nlmsghdr
->
nlmsg_len
,
};
struct
msghdr
msg
=
{
.
msg_name
=
&
nladdr
,
.
msg_namelen
=
sizeof
(
nladdr
),
.
msg_iov
=
&
iov
,
.
msg_iovlen
=
1
,
};
memset
(
&
nladdr
,
0
,
sizeof
(
nladdr
));
nladdr
.
nl_family
=
AF_NETLINK
;
nladdr
.
nl_pid
=
0
;
nladdr
.
nl_groups
=
0
;
again:
ret
=
recvmsg
(
handler
->
fd
,
&
msg
,
0
);
if
(
ret
<
0
)
{
if
(
errno
==
EINTR
)
goto
again
;
return
-
1
;
}
if
(
!
ret
)
return
0
;
if
(
msg
.
msg_flags
&
MSG_TRUNC
&&
(
ret
==
nlmsghdr
->
nlmsg_len
))
return
-
EMSGSIZE
;
return
ret
;
}
extern
int
nl_transaction
(
struct
nl_handler
*
handler
,
struct
nlmsghdr
*
request
,
struct
nlmsghdr
*
answer
)
{
int
ret
;
ret
=
nl_send
(
handler
,
request
);
if
(
ret
<
0
)
return
ret
;
ret
=
nl_recv
(
handler
,
answer
);
if
(
ret
<
0
)
return
ret
;
if
(
answer
->
nlmsg_type
==
NLMSG_ERROR
)
{
struct
nlmsgerr
*
err
=
(
struct
nlmsgerr
*
)
NLMSG_DATA
(
answer
);
return
err
->
error
;
}
return
0
;
}
int
lxc_netns_set_nsid
(
int
fd
)
int
lxc_netns_set_nsid
(
int
fd
)
{
{
ssize_t
ret
;
ssize_t
ret
;
...
@@ -3309,7 +3222,7 @@ int lxc_netns_set_nsid(int fd)
...
@@ -3309,7 +3222,7 @@ int lxc_netns_set_nsid(int fd)
addattr
(
hdr
,
1024
,
__LXC_NETNSA_FD
,
&
netns_fd
,
sizeof
(
netns_fd
));
addattr
(
hdr
,
1024
,
__LXC_NETNSA_FD
,
&
netns_fd
,
sizeof
(
netns_fd
));
addattr
(
hdr
,
1024
,
__LXC_NETNSA_NSID
,
&
ns_id
,
sizeof
(
ns_id
));
addattr
(
hdr
,
1024
,
__LXC_NETNSA_NSID
,
&
ns_id
,
sizeof
(
ns_id
));
ret
=
nl
_transaction
(
&
nlh
,
hdr
,
hdr
);
ret
=
__netlink
_transaction
(
&
nlh
,
hdr
,
hdr
);
netlink_close
(
&
nlh
);
netlink_close
(
&
nlh
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
-
1
;
return
-
1
;
...
...
src/lxc/nl.c
View file @
f728ff0c
...
@@ -171,13 +171,13 @@ extern void nlmsg_free(struct nlmsg *nlmsg)
...
@@ -171,13 +171,13 @@ extern void nlmsg_free(struct nlmsg *nlmsg)
free
(
nlmsg
);
free
(
nlmsg
);
}
}
extern
int
netlink_rcv
(
struct
nl_handler
*
handler
,
struct
nlmsg
*
answe
r
)
extern
int
__netlink_recv
(
struct
nl_handler
*
handler
,
struct
nlmsghdr
*
nlmsghd
r
)
{
{
int
ret
;
int
ret
;
struct
sockaddr_nl
nladdr
;
struct
sockaddr_nl
nladdr
;
struct
iovec
iov
=
{
struct
iovec
iov
=
{
.
iov_base
=
answer
->
nlmsghdr
,
.
iov_base
=
nlmsghdr
,
.
iov_len
=
answer
->
nlmsghdr
->
nlmsg_len
,
.
iov_len
=
nlmsghdr
->
nlmsg_len
,
};
};
struct
msghdr
msg
=
{
struct
msghdr
msg
=
{
...
@@ -197,25 +197,31 @@ again:
...
@@ -197,25 +197,31 @@ again:
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
if
(
errno
==
EINTR
)
if
(
errno
==
EINTR
)
goto
again
;
goto
again
;
return
-
errno
;
return
-
1
;
}
}
if
(
!
ret
)
if
(
!
ret
)
return
0
;
return
0
;
if
(
msg
.
msg_flags
&
MSG_TRUNC
&&
if
(
msg
.
msg_flags
&
MSG_TRUNC
&&
(
ret
==
nlmsghdr
->
nlmsg_len
))
ret
==
answer
->
nlmsghdr
->
nlmsg_len
)
return
-
EMSGSIZE
;
return
-
EMSGSIZE
;
return
ret
;
return
ret
;
}
}
extern
int
netlink_
send
(
struct
nl_handler
*
handler
,
struct
nlmsg
*
nlmsg
)
extern
int
netlink_
rcv
(
struct
nl_handler
*
handler
,
struct
nlmsg
*
answer
)
{
{
return
__netlink_recv
(
handler
,
answer
->
nlmsghdr
);
}
extern
int
__netlink_send
(
struct
nl_handler
*
handler
,
struct
nlmsghdr
*
nlmsghdr
)
{
int
ret
;
struct
sockaddr_nl
nladdr
;
struct
sockaddr_nl
nladdr
;
struct
iovec
iov
=
{
struct
iovec
iov
=
{
.
iov_base
=
nlmsg
->
nlmsghdr
,
.
iov_base
=
nlmsghdr
,
.
iov_len
=
nlmsg
->
nlmsghdr
->
nlmsg_len
,
.
iov_len
=
nlmsghdr
->
nlmsg_len
,
};
};
struct
msghdr
msg
=
{
struct
msghdr
msg
=
{
.
msg_name
=
&
nladdr
,
.
msg_name
=
&
nladdr
,
...
@@ -223,7 +229,6 @@ extern int netlink_send(struct nl_handler *handler, struct nlmsg *nlmsg)
...
@@ -223,7 +229,6 @@ extern int netlink_send(struct nl_handler *handler, struct nlmsg *nlmsg)
.
msg_iov
=
&
iov
,
.
msg_iov
=
&
iov
,
.
msg_iovlen
=
1
,
.
msg_iovlen
=
1
,
};
};
int
ret
;
memset
(
&
nladdr
,
0
,
sizeof
(
nladdr
));
memset
(
&
nladdr
,
0
,
sizeof
(
nladdr
));
nladdr
.
nl_family
=
AF_NETLINK
;
nladdr
.
nl_family
=
AF_NETLINK
;
...
@@ -232,32 +237,45 @@ extern int netlink_send(struct nl_handler *handler, struct nlmsg *nlmsg)
...
@@ -232,32 +237,45 @@ extern int netlink_send(struct nl_handler *handler, struct nlmsg *nlmsg)
ret
=
sendmsg
(
handler
->
fd
,
&
msg
,
MSG_NOSIGNAL
);
ret
=
sendmsg
(
handler
->
fd
,
&
msg
,
MSG_NOSIGNAL
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
-
errno
;
return
-
1
;
return
ret
;
return
ret
;
}
}
extern
int
netlink_transaction
(
struct
nl_handler
*
handler
,
extern
int
netlink_send
(
struct
nl_handler
*
handler
,
struct
nlmsg
*
nlmsg
)
struct
nlmsg
*
request
,
struct
nlmsg
*
answer
)
{
return
__netlink_send
(
handler
,
nlmsg
->
nlmsghdr
);
}
extern
int
__netlink_transaction
(
struct
nl_handler
*
handler
,
struct
nlmsghdr
*
request
,
struct
nlmsghdr
*
answer
)
{
{
int
ret
;
int
ret
;
ret
=
netlink_send
(
handler
,
request
);
ret
=
__
netlink_send
(
handler
,
request
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
ret
;
return
ret
;
ret
=
netlink_r
cv
(
handler
,
answer
);
ret
=
__netlink_re
cv
(
handler
,
answer
);
if
(
ret
<
0
)
if
(
ret
<
0
)
return
ret
;
return
ret
;
if
(
answer
->
nlmsg
hdr
->
nlmsg
_type
==
NLMSG_ERROR
)
{
if
(
answer
->
nlmsg_type
==
NLMSG_ERROR
)
{
struct
nlmsgerr
*
err
=
(
struct
nlmsgerr
*
)
NLMSG_DATA
(
answer
->
nlmsghd
r
);
struct
nlmsgerr
*
err
=
(
struct
nlmsgerr
*
)
NLMSG_DATA
(
answe
r
);
return
err
->
error
;
return
err
->
error
;
}
}
return
0
;
return
0
;
}
}
extern
int
netlink_transaction
(
struct
nl_handler
*
handler
,
struct
nlmsg
*
request
,
struct
nlmsg
*
answer
)
{
return
__netlink_transaction
(
handler
,
request
->
nlmsghdr
,
answer
->
nlmsghdr
);
}
extern
int
netlink_open
(
struct
nl_handler
*
handler
,
int
protocol
)
extern
int
netlink_open
(
struct
nl_handler
*
handler
,
int
protocol
)
{
{
socklen_t
socklen
;
socklen_t
socklen
;
...
...
src/lxc/nl.h
View file @
f728ff0c
...
@@ -98,6 +98,7 @@ int netlink_close(struct nl_handler *handler);
...
@@ -98,6 +98,7 @@ int netlink_close(struct nl_handler *handler);
* Returns 0 on success, < 0 otherwise
* Returns 0 on success, < 0 otherwise
*/
*/
int
netlink_rcv
(
struct
nl_handler
*
handler
,
struct
nlmsg
*
nlmsg
);
int
netlink_rcv
(
struct
nl_handler
*
handler
,
struct
nlmsg
*
nlmsg
);
int
__netlink_recv
(
struct
nl_handler
*
handler
,
struct
nlmsghdr
*
nlmsg
);
/*
/*
* netlink_send: send a netlink message to the kernel. It is up
* netlink_send: send a netlink message to the kernel. It is up
...
@@ -109,6 +110,7 @@ int netlink_rcv(struct nl_handler *handler, struct nlmsg *nlmsg);
...
@@ -109,6 +110,7 @@ int netlink_rcv(struct nl_handler *handler, struct nlmsg *nlmsg);
* Returns 0 on success, < 0 otherwise
* Returns 0 on success, < 0 otherwise
*/
*/
int
netlink_send
(
struct
nl_handler
*
handler
,
struct
nlmsg
*
nlmsg
);
int
netlink_send
(
struct
nl_handler
*
handler
,
struct
nlmsg
*
nlmsg
);
int
__netlink_send
(
struct
nl_handler
*
handler
,
struct
nlmsghdr
*
nlmsg
);
/*
/*
* netlink_transaction: send a request to the kernel and read the response.
* netlink_transaction: send a request to the kernel and read the response.
...
@@ -123,6 +125,8 @@ int netlink_send(struct nl_handler *handler, struct nlmsg *nlmsg);
...
@@ -123,6 +125,8 @@ int netlink_send(struct nl_handler *handler, struct nlmsg *nlmsg);
*/
*/
int
netlink_transaction
(
struct
nl_handler
*
handler
,
int
netlink_transaction
(
struct
nl_handler
*
handler
,
struct
nlmsg
*
request
,
struct
nlmsg
*
anwser
);
struct
nlmsg
*
request
,
struct
nlmsg
*
anwser
);
int
__netlink_transaction
(
struct
nl_handler
*
handler
,
struct
nlmsghdr
*
request
,
struct
nlmsghdr
*
anwser
);
/*
/*
* nla_put_string: copy a null terminated string to a netlink message
* nla_put_string: copy a null terminated string to a netlink message
...
...
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