[PATCH 04/26] netlink: add a basic rtnetlink parser of route messages

Dmitry V. Levin ldv at altlinux.org
Sat Aug 12 00:08:06 UTC 2017


On Thu, Aug 10, 2017 at 09:04:54AM +0800, JingPiao Chen wrote:
> * netlink_route.c: New file.
> * Makefile.am (strace_SOURCES): Add it
> * netlink_route.h (decode_rtmsg): New prototype.
> * netlink_route.c (route_decoders): Add RTM_DELROUTE,
> RTM_GETROUTE, and RTM_NEWROUTE.
> * xlat/ip_type_of_services.in: New file.
> * xlat/rtm_flags.in: Likewise.
> * xlat/rtm_protocol.in: Likewise.
> * xlat/rtm_scope.in: Likewise.
> * xlat/rtm_table.in: Likewise.
> * xlat/rtm_types.in: Likewise.
[...]
> +DECL_NETLINK_ROUTE_DECODER(decode_rtmsg)
> +{
> +	struct rtmsg rtmsg = { .rtm_family = family };
> +	const size_t offset = sizeof(rtmsg.rtm_family);
> +
> +	PRINT_FIELD_XVAL("{", rtmsg, rtm_family, addrfams, "AF_???");
> +
> +	tprints(", ");
> +	if (len >= sizeof(rtmsg)) {
> +		if (!umoven_or_printaddr(tcp, addr + offset,
> +					 sizeof(rtmsg) - offset,
> +					 (void *) &rtmsg + offset)) {
> +			PRINT_FIELD_U("", rtmsg, rtm_dst_len);
> +			PRINT_FIELD_U(", ", rtmsg, rtm_src_len);
> +			PRINT_FIELD_FLAGS(", ", rtmsg, rtm_tos,
> +					  ip_type_of_services, "IPTOS_TOS_???");
> +			PRINT_FIELD_XVAL(", ", rtmsg, rtm_table,
> +					 rtm_table, "RT_TABLE_???");
> +			PRINT_FIELD_XVAL(", ", rtmsg, rtm_protocol,
> +					 rtm_protocol, "RTPROT_???");
> +			PRINT_FIELD_XVAL(", ", rtmsg, rtm_scope,
> +					 rtm_scope, "RT_SCOPE_???");

Both rtmsg.rtm_table and rtmsg.rtm_scope can legitimately contain values
defined by user, see comments in definitions of enum rt_scope_t and
enum rt_class_t in <linux/rtnetlink.h>.
 
I think specifying NULL instead of "RT_TABLE_???" and "RT_SCOPE_???"
would result to more appropriate decoding of these fields.


-- 
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/20170812/95f9e5ef/attachment.bin>


More information about the Strace-devel mailing list