[PATCH] Add netlink domain sockets support to socketutils

Masatake YAMATO yamato at redhat.com
Fri May 13 14:06:33 UTC 2016


> +static int
> +netlink_parse_response(const char *proto_name, const void *data,
> +		    const int data_len, const unsigned long inode)
> +{
> +	const struct netlink_diag_msg *const diag_msg = data;
> +	const char *netlink_proto;
> +	char *details;
> +
> +	if (data_len < (int) NLMSG_LENGTH(sizeof(*diag_msg)))
> +		return -1;
> +	if (diag_msg->ndiag_ino != inode)
> +		return 0;
> +
> +	if (diag_msg->ndiag_family != AF_NETLINK)
> +		return -1;
> +
> +	netlink_proto = xlookup(netlink_protocols,
> +				diag_msg->ndiag_protocol);
> +
> +	if (netlink_proto) {
> +		if (asprintf(&details, "%s:[%s]", proto_name,
> +			    netlink_proto) < 0)
> +			return -1;
> +	} else {
> +		if (asprintf(&details, "%s:[%u]", proto_name,
> +			     (unsigned) diag_msg->ndiag_protocol) < 0)
> +			return -1;
> +	}

Looks good for me.

Just a question.

Your code records ndiag_protocol.
How about other fields?
    struct netlink_diag_msg {
	    __u8	ndiag_family;
	    __u8	ndiag_type;
	    __u8	ndiag_protocol;
	    __u8	ndiag_state;

	    __u32	ndiag_portid;
	    __u32	ndiag_dst_portid;
	    __u32	ndiag_dst_group;
	    __u32	ndiag_ino;
	    __u32	ndiag_cookie[2];
    };

At a glance, ndiag_portid, ndiag_dst_portid and ndiag_dst_group are
meaningful in strace for me though I don't know well.
(If this topic has been discussed alrady , ignore me.)

Masatake YAMATO




More information about the Strace-devel mailing list