[PATCH 1/4] netlink: decode netlink message ack flags

Dmitry V. Levin ldv at altlinux.org
Tue Jul 18 21:19:37 UTC 2017


On Mon, Jul 17, 2017 at 11:07:43PM +0800, JingPiao Chen wrote:
> * netlink.c: Include "xlat/netlink_ack_flags.h".
> (decode_nlmsg_flags): Decode ack flags when type == NLMSG_ERROR.
> * xlat/netlink_ack_flags.in: New file.
> * tests/netlink_protocol.c (test_ack_flags): New function, check this.
> (main): Use it.
> ---
>  netlink.c                 |  5 +++++
>  tests/netlink_protocol.c  | 42 ++++++++++++++++++++++++++++++++++++++++++
>  xlat/netlink_ack_flags.in |  2 ++
>  3 files changed, 49 insertions(+)
>  create mode 100644 xlat/netlink_ack_flags.in
> 
> diff --git a/netlink.c b/netlink.c
> index e054ae3..9d480d3 100644
> --- a/netlink.c
> +++ b/netlink.c
> @@ -32,6 +32,7 @@
>  #include <linux/audit.h>
>  #include <linux/rtnetlink.h>
>  #include <linux/xfrm.h>
> +#include "xlat/netlink_ack_flags.h"
>  #include "xlat/netlink_flags.h"
>  #include "xlat/netlink_get_flags.h"
>  #include "xlat/netlink_new_flags.h"
> @@ -198,6 +199,10 @@ decode_nlmsg_flags(const uint16_t flags, const uint16_t type, const int family)
>  
>  	if (type == NLMSG_DONE)
>  		goto end;
> +	if (type == NLMSG_ERROR) {
> +		table = netlink_ack_flags;
> +		goto end;
> +	}

Two subsequent "if" statements of this kind would look better as a "switch"
statement.  If there is no need to handle family-specific control messages
in decode_nlmsg_flags, a more appropriate alternative might be

	if (type < NLMSG_MIN_TYPE) {
		if (type == NLMSG_ERROR)
			table = netlink_ack_flags;
		goto end;
	}


-- 
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20170719/c237c903/attachment.bin>


More information about the Strace-devel mailing list