From: JingPiao Chen Date: Tue, 27 Jun 2017 10:10:04 +0000 (+0800) Subject: netlink: add a basic netlink attribute parser of AF_PACKET diag X-Git-Tag: v4.18~37 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6cc89c0314e2131193ffe5fffd4a902e2c4eb83f;p=strace netlink: add a basic netlink attribute parser of AF_PACKET diag * linux/packet_diag.h (PACKET_DIAG_*): New enum. * netlink_sock_diag.c: Include "xlat/packet_diag_attrs.h". (decode_packet_diag_msg): Use decode_nlattr. * xlat/packet_diag_attrs.in: New file. Co-authored-by: Fabien Siron --- diff --git a/linux/packet_diag.h b/linux/packet_diag.h index 10f48d9c..3e8120b7 100644 --- a/linux/packet_diag.h +++ b/linux/packet_diag.h @@ -26,4 +26,15 @@ struct packet_diag_msg { uint32_t pdiag_cookie[2]; }; +enum { + PACKET_DIAG_INFO, + PACKET_DIAG_MCLIST, + PACKET_DIAG_RX_RING, + PACKET_DIAG_TX_RING, + PACKET_DIAG_FANOUT, + PACKET_DIAG_UID, + PACKET_DIAG_MEMINFO, + PACKET_DIAG_FILTER, +}; + #endif /* !STRACE_LINUX_PACKET_DIAG_H */ diff --git a/netlink_sock_diag.c b/netlink_sock_diag.c index 98a3fad2..d15df970 100644 --- a/netlink_sock_diag.c +++ b/netlink_sock_diag.c @@ -49,6 +49,7 @@ #include "xlat/netlink_diag_show.h" #include "xlat/netlink_states.h" +#include "xlat/packet_diag_attrs.h" #include "xlat/packet_diag_show.h" #ifdef AF_SMC @@ -271,7 +272,8 @@ decode_packet_diag_msg(struct tcb *const tcp, const kernel_ulong_t len) { struct packet_diag_msg msg = { .pdiag_family = family }; - const size_t offset = sizeof(msg.pdiag_family); + size_t offset = sizeof(msg.pdiag_family); + bool decode_nla = false; PRINT_FIELD_XVAL("{", msg, pdiag_family, addrfams, "AF_???"); tprints(", "); @@ -284,10 +286,18 @@ decode_packet_diag_msg(struct tcb *const tcp, PRINT_FIELD_U(", ", msg, pdiag_num); PRINT_FIELD_U(", ", msg, pdiag_ino); PRINT_FIELD_COOKIE(", ", msg, pdiag_cookie); + decode_nla = true; } } else tprints("..."); tprints("}"); + + offset = NLA_ALIGN(sizeof(msg)); + if (decode_nla && len > offset) { + tprints(", "); + decode_nlattr(tcp, addr + offset, len - offset, + packet_diag_attrs, "PACKET_DIAG_???"); + } } static void diff --git a/xlat/packet_diag_attrs.in b/xlat/packet_diag_attrs.in new file mode 100644 index 00000000..5e33871e --- /dev/null +++ b/xlat/packet_diag_attrs.in @@ -0,0 +1,9 @@ +#unconditional +PACKET_DIAG_INFO +PACKET_DIAG_MCLIST +PACKET_DIAG_RX_RING +PACKET_DIAG_TX_RING +PACKET_DIAG_FANOUT +PACKET_DIAG_UID +PACKET_DIAG_MEMINFO +PACKET_DIAG_FILTER