[PATCH v3 6/7] Netlink: Introduce nlmsg_* functions
Dmitry V. Levin
ldv at altlinux.org
Fri Jun 17 12:21:01 UTC 2016
On Wed, Jun 15, 2016 at 12:43:04PM +0000, Fabien Siron wrote:
> Since our target is not in the same process, the netlink macros NLMSG_*
> must be rewritten for strace.
>
> * netlink.c (nlmsg_ok, nlmsg_next): New functions.
> ---
> netlink.c | 26 ++++++++++++++++++++++++++
> 1 file changed, 26 insertions(+)
>
> diff --git a/netlink.c b/netlink.c
> index 30116dd..c1a9ad4 100644
> --- a/netlink.c
> +++ b/netlink.c
> @@ -31,6 +31,32 @@
> #include "xlat/netlink_flags.h"
> #include "xlat/netlink_types.h"
>
> +/* since our target is not in the same process, here are some utils for nlmsg */
> +static int
> +nlmsg_ok(struct tcb *tcp, unsigned long nlh, unsigned long len) {
> + struct nlmsghdr nlmsghdr;
> +
> + if (umoven(tcp, nlh, sizeof(struct nlmsghdr), &nlmsghdr) == -1)
> + return 0;
> +
> + return (len >= (int)sizeof(struct nlmsghdr)) &&
Shouldn't umoven be skipped if this condition is false?
> + nlmsghdr.nlmsg_len >= sizeof(struct nlmsghdr) &&
> + nlmsghdr.nlmsg_len <= len;
> +}
> +
> +static unsigned long
> +nlmsg_next(struct tcb *tcp, unsigned long nlh, unsigned long *len) {
> + struct nlmsghdr nlmsghdr;
> +
> + if (umoven(tcp, nlh, sizeof(struct nlmsghdr), &nlmsghdr) == -1)
> + return 0;
> +
> + *len -= NLMSG_ALIGN(nlmsghdr.nlmsg_len);
> +
> + return (unsigned long)
> + ((char *)(nlh) + NLMSG_ALIGN(nlmsghdr.nlmsg_len));
> +}
> +
> void
> decode_netlink(struct tcb *tcp, unsigned long addr, unsigned long size)
> {
All these three functions (nlmsg_ok, nlmsg_next, and decode_netlink) fetch
struct nlmsghdr, and likely they fetch the same structure. Couldn't this
inefficiency be avoided?
--
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/20160617/94b60b84/attachment.bin>
More information about the Strace-devel
mailing list