[PATCH 1/2] rtnl_route: decode rtmsg netlink attributes

Dmitry V. Levin ldv at altlinux.org
Wed Aug 23 02:09:30 UTC 2017


On Wed, Aug 23, 2017 at 09:57:37AM +0800, JingPiao Chen wrote:
> On Wed, Aug 23, 2017 at 04:30:28AM +0300, Dmitry V. Levin wrote:
> > On Wed, Aug 23, 2017 at 08:45:18AM +0800, JingPiao Chen wrote:
> > > * configure.ac (AC_CHECK_TYPES): Check for
> > > rta_mfc_stats and rtvia structures in <linux/rtnetlink.h>.
> > > * nlattr.c (decode_nla_ifindex): New function.
> > > * nlattr.h (decode_nla_ifindex): New prototype.
> > > * rtnl_route.c (decode_route_addr, decode_rta_metrics,
> > > decode_rta_multipath, decode_rta_cacheinfo,
> > > decode_rta_mfc_stats, decode_rtvia,
> > > decode_rta_encap_type): New functions.
> > > (rta_metrics_nla_decoders, rtmsg_nla_decoders): New arrays.
> > > (decode_rtmsg): Use rtmsg_nla_decoders.
> > > * xlat/lwtunnel_encap_types.in: New file.
> > > * xlat/route_nexthop_flags.in: Likewise.
> > > * xlat/rtnl_rta_metrics_attrs.in: Likewise.
> > [...]
> > > +static bool
> > > +decode_rtvia(struct tcb *const tcp,
> > > +	     const kernel_ulong_t addr,
> > > +	     const unsigned int len,
> > > +	     const void *const opaque_data)
> > > +{
> > > +#ifdef HAVE_STRUCT_RTVIA
> > > +	struct rtvia via;
> > > +
> > > +	if (len < sizeof(via))
> > > +		return false;
> > > +	else if (!umove_or_printaddr(tcp, addr, &via)) {
> > > +		PRINT_FIELD_XVAL("{", via, rtvia_family, addrfams, "AF_???");
> > > +
> > > +		if (len > sizeof(via)) {
> > > +			tprints(", rtvia_addr=");
> > > +			printstr_ex(tcp, addr + sizeof(via),
> > > +				    len - sizeof(via), QUOTE_FORCE_HEX);
> > 
> > Looks like decode_inet_addr would be more appropriate here than printstr_ex.
> > 
> > We might end up with renaming decode_inet_addr to something more generic
> > and extending it to handle AF_PACKET in addition to AF_INET and AF_INET6.
> 
> bool
> decode_proto_address(struct tcb *const tcp,
> 		     const kernel_ulong_t addr,
> 		     const unsigned int len,
> 		     const int family,
> 		     const char *const var_name)
> {
> 	switch (family) {
> 	case AF_INET:
> 	case AF_INET6:
> 		return decode_inet_addr(tcp, addr, len, family, var_name);
> 	case AF_PACKET:
> 		....
> 	}
> 
> 	if (var_name)
> 		tprintf("%s=", var_name);
> 	printstr_ex(tcp, addr, len, QUOTE_FORCE_HEX);
> 
> 	return false;
> }
> 
> How about this?

I'd rather extend decode_inet_addr (and print_inet_addr) to handle
AF_PACKET and maybe other address families, but couldn't think of
a proper name for this extended decode_inet_addr function.


-- 
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/20170823/6031eff3/attachment.bin>


More information about the Strace-devel mailing list