From: Dmitry V. Levin Date: Thu, 23 Jun 2016 17:38:18 +0000 (+0000) Subject: net.c: fix printing AF_PACKET socket addresses X-Git-Tag: v4.13~99 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=45ae937cedd8ddb477ead0a04158c79b214d5422;p=strace net.c: fix printing AF_PACKET socket addresses * defs.h (print_ifindex, print_sockaddr_data_ll): New prototypes. * net.c: Stop including "xlat/af_packet_types.h". (print_ifindex): Remove static keyword. (print_sockaddr_data_l): Remove. * sockaddr_ll.c: New file. * Makefile.am (strace_SOURCES): Add it. * xlat/arp_hardware_types.in: New file. * xlat/ethernet_protocols.in: Likewise. --- diff --git a/Makefile.am b/Makefile.am index 77e0cc87..3edd76f0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -198,6 +198,7 @@ strace_SOURCES = \ signalfd.c \ sigreturn.c \ sock.c \ + sockaddr_ll.c \ socketutils.c \ sram_alloc.c \ statfs.c \ diff --git a/defs.h b/defs.h index 99447e65..37b6af6f 100644 --- a/defs.h +++ b/defs.h @@ -682,6 +682,9 @@ struct strace_statfs; extern void print_struct_statfs(struct tcb *tcp, long); extern void print_struct_statfs64(struct tcb *tcp, long, unsigned long); +extern void print_ifindex(unsigned int); +extern void print_sockaddr_data_ll(const void *, int); + extern int file_ioctl(struct tcb *, const unsigned int, long); extern int fs_x_ioctl(struct tcb *, const unsigned int, long); extern int loop_ioctl(struct tcb *, const unsigned int, long); diff --git a/net.c b/net.c index 239b407e..cc063744 100644 --- a/net.c +++ b/net.c @@ -101,8 +101,6 @@ #include "xlat/msg_flags.h" -#include "xlat/af_packet_types.h" - #define SIZEOF_SA_FAMILY sizeof(((struct sockaddr *) 0)->sa_family) static void @@ -132,7 +130,7 @@ print_sockaddr_data_in(const void *const buf, const int addrlen) ntohs(sa_in->sin_port), inet_ntoa(sa_in->sin_addr)); } -static void +void print_ifindex(unsigned int ifindex) { #ifdef HAVE_IF_INDEXTONAME @@ -203,21 +201,6 @@ print_sockaddr_data_nl(const void *const buf, const int addrlen) sa_nl->nl_pid, sa_nl->nl_groups); } -static void -print_sockaddr_data_ll(const void *const buf, const int addrlen) -{ - const struct sockaddr_ll *const sa_ll = buf; - unsigned int i; - - tprintf("proto=%#04x, if%d, pkttype=", - ntohs(sa_ll->sll_protocol), - sa_ll->sll_ifindex); - printxval(af_packet_types, sa_ll->sll_pkttype, "PACKET_???"); - tprintf(", addr(%d)={%d, ", sa_ll->sll_halen, sa_ll->sll_hatype); - for (i = 0; i < sa_ll->sll_halen; i++) - tprintf("%02x", sa_ll->sll_addr[i]); -} - static void print_sockaddr_data_raw(const void *const buf, const int addrlen) { diff --git a/sockaddr_ll.c b/sockaddr_ll.c new file mode 100644 index 00000000..7de88feb --- /dev/null +++ b/sockaddr_ll.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2016 Dmitry V. Levin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "defs.h" + +#include +#include +#include +#include +#include + +#include "xlat/arp_hardware_types.h" +#include "xlat/ethernet_protocols.h" +#include "xlat/af_packet_types.h" + +void +print_sockaddr_data_ll(const void *const buf, const int addrlen) +{ + const struct sockaddr_ll *const sa_ll = buf; + + tprints("sll_protocol=htons("); + printxval(ethernet_protocols, ntohs(sa_ll->sll_protocol), "ETH_P_???"); + tprints("), sll_ifindex="); + print_ifindex(sa_ll->sll_ifindex); + tprints(", sll_hatype="); + printxval(arp_hardware_types, sa_ll->sll_hatype, "ARPHRD_???"); + tprints(", sll_pkttype="); + printxval(af_packet_types, sa_ll->sll_pkttype, "PACKET_???"); + tprintf(", sll_halen=%u", sa_ll->sll_halen); + if (sa_ll->sll_halen) { + const unsigned int oob_halen = + addrlen - offsetof(struct sockaddr_ll, sll_addr); + unsigned int i; + + tprints(", sll_addr=["); + for (i = 0; i < sa_ll->sll_halen; ++i) { + if (i) + tprints(", "); + if (i >= oob_halen) { + tprints("..."); + break; + } + tprintf("%#02x", sa_ll->sll_addr[i]); + } + tprints("]"); + } +} diff --git a/xlat/arp_hardware_types.in b/xlat/arp_hardware_types.in new file mode 100644 index 00000000..df8b4fcf --- /dev/null +++ b/xlat/arp_hardware_types.in @@ -0,0 +1,64 @@ +ARPHRD_NETROM +ARPHRD_ETHER +ARPHRD_EETHER +ARPHRD_AX25 +ARPHRD_PRONET +ARPHRD_CHAOS +ARPHRD_IEEE802 +ARPHRD_ARCNET +ARPHRD_APPLETLK +ARPHRD_DLCI +ARPHRD_ATM +ARPHRD_METRICOM +ARPHRD_IEEE1394 +ARPHRD_EUI64 +ARPHRD_INFINIBAND +ARPHRD_SLIP +ARPHRD_CSLIP +ARPHRD_SLIP6 +ARPHRD_CSLIP6 +ARPHRD_RSRVD +ARPHRD_ADAPT +ARPHRD_ROSE +ARPHRD_X25 +ARPHRD_HWX25 +ARPHRD_CAN +ARPHRD_PPP +ARPHRD_CISCO +ARPHRD_LAPB +ARPHRD_DDCMP +ARPHRD_RAWHDLC +ARPHRD_TUNNEL +ARPHRD_TUNNEL6 +ARPHRD_FRAD +ARPHRD_SKIP +ARPHRD_LOOPBACK +ARPHRD_LOCALTLK +ARPHRD_FDDI +ARPHRD_BIF +ARPHRD_SIT +ARPHRD_IPDDP +ARPHRD_IPGRE +ARPHRD_PIMREG +ARPHRD_HIPPI +ARPHRD_ASH +ARPHRD_ECONET +ARPHRD_IRDA +ARPHRD_FCPP +ARPHRD_FCAL +ARPHRD_FCPL +ARPHRD_FCFABRIC +ARPHRD_IEEE802_TR +ARPHRD_IEEE80211 +ARPHRD_IEEE80211_PRISM +ARPHRD_IEEE80211_RADIOTAP +ARPHRD_IEEE802154 +ARPHRD_IEEE802154_MONITOR +ARPHRD_PHONET +ARPHRD_PHONET_PIPE +ARPHRD_CAIF +ARPHRD_IP6GRE +ARPHRD_NETLINK +ARPHRD_6LOWPAN +ARPHRD_VOID +ARPHRD_NONE diff --git a/xlat/ethernet_protocols.in b/xlat/ethernet_protocols.in new file mode 100644 index 00000000..df078ba8 --- /dev/null +++ b/xlat/ethernet_protocols.in @@ -0,0 +1,83 @@ +ETH_P_LOOP +ETH_P_PUP +ETH_P_PUPAT +ETH_P_TSN +ETH_P_IP +ETH_P_X25 +ETH_P_ARP +ETH_P_BPQ +ETH_P_IEEEPUP +ETH_P_IEEEPUPAT +ETH_P_BATMAN +ETH_P_DEC +ETH_P_DNA_DL +ETH_P_DNA_RC +ETH_P_DNA_RT +ETH_P_LAT +ETH_P_DIAG +ETH_P_CUST +ETH_P_SCA +ETH_P_TEB +ETH_P_RARP +ETH_P_ATALK +ETH_P_AARP +ETH_P_8021Q +ETH_P_IPX +ETH_P_IPV6 +ETH_P_PAUSE +ETH_P_SLOW +ETH_P_WCCP +ETH_P_MPLS_UC +ETH_P_MPLS_MC +ETH_P_ATMMPOA +ETH_P_PPP_DISC +ETH_P_PPP_SES +ETH_P_LINK_CTL +ETH_P_ATMFATE +ETH_P_PAE +ETH_P_AOE +ETH_P_8021AD +ETH_P_802_EX1 +ETH_P_TIPC +ETH_P_MACSEC +ETH_P_8021AH +ETH_P_MVRP +ETH_P_1588 +ETH_P_PRP +ETH_P_FCOE +ETH_P_TDLS +ETH_P_FIP +ETH_P_80221 +ETH_P_HSR +ETH_P_LOOPBACK +ETH_P_QINQ1 +ETH_P_QINQ2 +ETH_P_QINQ3 +ETH_P_EDSA +ETH_P_AF_IUCV +ETH_P_802_3_MIN +ETH_P_802_3 +ETH_P_AX25 +ETH_P_ALL +ETH_P_802_2 +ETH_P_SNAP +ETH_P_DDCMP +ETH_P_WAN_PPP +ETH_P_PPP_MP +ETH_P_LOCALTALK +ETH_P_CAN +ETH_P_CANFD +ETH_P_PPPTALK +ETH_P_TR_802_2 +ETH_P_MOBITEX +ETH_P_CONTROL +ETH_P_IRDA +ETH_P_ECONET +ETH_P_HDLC +ETH_P_ARCNET +ETH_P_DSA +ETH_P_TRAILER +ETH_P_PHONET +ETH_P_IEEE802154 +ETH_P_CAIF +ETH_P_XDSA