[PATCH v7 4/4] Netlink: handle multi netlink messages
Dmitry V. Levin
ldv at altlinux.org
Wed Jun 22 17:40:39 UTC 2016
On Wed, Jun 22, 2016 at 01:27:06PM +0000, Fabien Siron wrote:
> Handle the case where there are several messages in the buffer.
> This is very useful to some protocols like SOCK_DIAG.
>
> * netlink.c (nlmsg_fetch, nlmsg_next): New functions.
> (decode_netlink_msg): New function.
> (decode_netlink): Call decode_netlink_msg().
> * tests/netlink_parsing.c (send_query): Adapt test.
> ---
> netlink.c | 85 +++++++++++++++++++++++++++++++++++++++++--------
> tests/netlink_parsing.c | 19 ++++++++++-
> 2 files changed, 90 insertions(+), 14 deletions(-)
>
> diff --git a/netlink.c b/netlink.c
> index c43f6e7..e05e50c 100644
> --- a/netlink.c
> +++ b/netlink.c
> @@ -31,34 +31,93 @@
> #include "xlat/netlink_flags.h"
> #include "xlat/netlink_types.h"
>
> -void
> -decode_netlink(struct tcb *tcp, unsigned long addr, unsigned long size)
> -{
> - struct nlmsghdr nlmsghdr;
> +/* since our target is not in the same process, here are some utils for nlmsg */
> +static int
> +nlmsg_fetch(struct tcb *tcp, struct nlmsghdr *nlmsghdr, unsigned long addr,
> + unsigned long len) {
> + if (len < sizeof(struct nlmsghdr)) {
> + if (len != 0)
> + printstr(tcp, addr, len);
> + return 0;
> + }
> +
> + if (umove_or_printaddr(tcp, addr, nlmsghdr) == -1)
> + return 0;
> +
> + if (len < nlmsghdr->nlmsg_len) {
> + printstr(tcp, addr, len);
> + return 0;
> + }
I think that if struct nlmsghdr has been successfully fetched,
the header should be printed regardless of its nlmsg_len.
> + return 1;
> +}
>
> +static unsigned long
> +nlmsg_next(struct nlmsghdr *nlmsghdr, unsigned long addr, unsigned long *len) {
> + if (NLMSG_ALIGN(nlmsghdr->nlmsg_len) == 0 ||
> + NLMSG_ALIGN(nlmsghdr->nlmsg_len) > *len)
> + return 0;
This is not going to happen with current implementation of nlmsg_fetch,
but if nlmsg_fetch changes and if this condition is true, then
*len remains unchanged and the subsequent nlmsg_fetch prints NULL.
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20160622/54248ab4/attachment.bin>
More information about the Strace-devel
mailing list