[PATCH v3 1/4] netlink: introduce NETLINK_NETFILTER parser

Dmitry V. Levin ldv at altlinux.org
Wed Mar 7 21:41:02 UTC 2018


On Wed, Mar 07, 2018 at 12:34:44PM +0800, Chen Jingpiao wrote:
> * netlink_netfilter.c: New file.
> * Makefile.am (strace_SOURCES): Add it.
> * defs.h (decode_netlink_netfilter): New prototype.
> * netlink.c (netlink_decoders): Add NETLINK_NETFILTER.
> * xlat/netfilter_versions.in: New file.
[...]
> +bool
> +decode_netlink_netfilter(struct tcb *const tcp,
> +			 const struct nlmsghdr *const nlmsghdr,
> +			 const kernel_ulong_t addr,
> +			 const unsigned int len)
> +{
> +	if (nlmsghdr->nlmsg_type == NLMSG_DONE)
> +		return false;
> +
> +	struct nfgenmsg nfmsg;
> +
> +	if (len < sizeof(nfmsg))
> +		printstr_ex(tcp, addr, len, QUOTE_FORCE_HEX);
> +	else if (!umove_or_printaddr(tcp, addr, &nfmsg)) {
> +		const uint8_t subsys_id = (uint8_t) (nlmsghdr->nlmsg_type >> 8);
> +		uint16_t res_id = ntohs(nfmsg.res_id);
> +
> +		PRINT_FIELD_XVAL("{", nfmsg, nfgen_family, addrfams, "AF_???");
> +		PRINT_FIELD_XVAL(", ", nfmsg, version, netfilter_versions,
> +				 "NFNETLINK_???");
> +
> +		/*
> +		 * Work around wrong endianness in res_id field,
> +		 * see linux commit v4.3-rc1~28^2~47^2~1
> +		 */
> +		tprints(", res_id=");
> +		if (subsys_id == NFNL_SUBSYS_NFTABLES
> +		    && nfmsg.res_id == NFNL_SUBSYS_NFTABLES) {
> +# ifdef WORDS_BIGENDIAN
> +			tprints("htons(NFNL_SUBSYS_NFTABLES)");
> +# else
> +			tprints("NFNL_SUBSYS_NFTABLES");
> +# endif
> +		} else {
> +			tprints("htons(");
> +			if (subsys_id == NFNL_SUBSYS_NFTABLES
> +			    && res_id == NFNL_SUBSYS_NFTABLES)
> +				tprints("NFNL_SUBSYS_NFTABLES");
> +			else
> +				tprintf("%d", res_id);
> +			tprints(")");
> +		}

I don't think you need a special handling for WORDS_BIGENDIAN here.
What I was talking about in the previous review cycle is the following:

		tprints(", res_id=");
		if (subsys_id == NFNL_SUBSYS_NFTABLES
		    && res_id == NFNL_SUBSYS_NFTABLES) {
			tprints("htons(NFNL_SUBSYS_NFTABLES)");
		} else if (subsys_id == NFNL_SUBSYS_NFTABLES
			   && nfmsg.res_id == NFNL_SUBSYS_NFTABLES) {
			tprints("NFNL_SUBSYS_NFTABLES");
		} else {
			tprintf("htons(%d)", res_id);
		}


-- 
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/20180308/bb2aef16/attachment.bin>


More information about the Strace-devel mailing list