LCOV - code coverage report
Current view: top level - strace - netlink_unix_diag.c (source / functions) Hit Total Coverage
Test: strace-4.18.0.129.97bbb Code Coverage Lines: 57 57 100.0 %
Date: 2017-07-31 03:46:08 Functions: 6 6 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 22 22 100.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 2016 Fabien Siron <fabien.siron@epita.fr>
       3                 :            :  * Copyright (c) 2017 JingPiao Chen <chenjingpiao@gmail.com>
       4                 :            :  * Copyright (c) 2017 The strace developers.
       5                 :            :  * All rights reserved.
       6                 :            :  *
       7                 :            :  * Redistribution and use in source and binary forms, with or without
       8                 :            :  * modification, are permitted provided that the following conditions
       9                 :            :  * are met:
      10                 :            :  * 1. Redistributions of source code must retain the above copyright
      11                 :            :  *    notice, this list of conditions and the following disclaimer.
      12                 :            :  * 2. Redistributions in binary form must reproduce the above copyright
      13                 :            :  *    notice, this list of conditions and the following disclaimer in the
      14                 :            :  *    documentation and/or other materials provided with the distribution.
      15                 :            :  * 3. The name of the author may not be used to endorse or promote products
      16                 :            :  *    derived from this software without specific prior written permission.
      17                 :            :  *
      18                 :            :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
      19                 :            :  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
      20                 :            :  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
      21                 :            :  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
      22                 :            :  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      23                 :            :  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      24                 :            :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      25                 :            :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      26                 :            :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
      27                 :            :  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      28                 :            :  */
      29                 :            : 
      30                 :            : #include "defs.h"
      31                 :            : #include "netlink.h"
      32                 :            : #include "netlink_sock_diag.h"
      33                 :            : #include "nlattr.h"
      34                 :            : #include "print_fields.h"
      35                 :            : 
      36                 :            : #include <linux/sock_diag.h>
      37                 :            : #include <linux/unix_diag.h>
      38                 :            : 
      39                 :            : #include "xlat/unix_diag_attrs.h"
      40                 :            : #include "xlat/unix_diag_show.h"
      41                 :            : 
      42                 :          6 : DECL_NETLINK_DIAG_DECODER(decode_unix_diag_req)
      43                 :            : {
      44                 :          6 :         struct unix_diag_req req = { .sdiag_family = family };
      45                 :          6 :         const size_t offset = sizeof(req.sdiag_family);
      46                 :            : 
      47                 :          6 :         PRINT_FIELD_XVAL("{", req, sdiag_family, addrfams, "AF_???");
      48                 :          6 :         tprints(", ");
      49         [ +  + ]:          6 :         if (len >= sizeof(req)) {
      50         [ +  + ]:          4 :                 if (!umoven_or_printaddr(tcp, addr + offset,
      51                 :            :                                          sizeof(req) - offset,
      52                 :            :                                          (void *) &req + offset)) {
      53                 :          2 :                         PRINT_FIELD_U("", req, sdiag_protocol);
      54                 :          2 :                         PRINT_FIELD_FLAGS(", ", req, udiag_states,
      55                 :            :                                           tcp_state_flags, "1<<TCP_???");
      56                 :          2 :                         PRINT_FIELD_U(", ", req, udiag_ino);
      57                 :          2 :                         PRINT_FIELD_FLAGS(", ", req, udiag_show,
      58                 :            :                                           unix_diag_show, "UDIAG_SHOW_???");
      59                 :          2 :                         PRINT_FIELD_COOKIE(", ", req, udiag_cookie);
      60                 :            :                 }
      61                 :            :         } else
      62                 :          2 :                 tprints("...");
      63                 :          6 :         tprints("}");
      64                 :          6 : }
      65                 :            : 
      66                 :            : static bool
      67                 :          6 : decode_unix_diag_vfs(struct tcb *const tcp,
      68                 :            :                      const kernel_ulong_t addr,
      69                 :            :                      const unsigned int len,
      70                 :            :                      const void *const opaque_data)
      71                 :            : {
      72                 :            :         struct unix_diag_vfs uv;
      73                 :            : 
      74         [ +  + ]:          6 :         if (len < sizeof(uv))
      75                 :            :                 return false;
      76         [ +  + ]:          4 :         if (umove_or_printaddr(tcp, addr, &uv))
      77                 :            :                 return true;
      78                 :            : 
      79                 :          2 :         PRINT_FIELD_DEV("{", uv, udiag_vfs_dev);
      80                 :          2 :         PRINT_FIELD_U(", ", uv, udiag_vfs_ino);
      81                 :          2 :         tprints("}");
      82                 :            : 
      83                 :          2 :         return true;
      84                 :            : }
      85                 :            : 
      86                 :            : static bool
      87                 :          8 : print_inode(struct tcb *const tcp,
      88                 :            :             void *const elem_buf,
      89                 :            :             const size_t elem_size,
      90                 :            :             void *const opaque_data)
      91                 :            : {
      92                 :          8 :         tprintf("%" PRIu32, *(uint32_t *) elem_buf);
      93                 :            : 
      94                 :          8 :         return true;
      95                 :            : }
      96                 :            : 
      97                 :            : static bool
      98                 :          8 : decode_unix_diag_inode(struct tcb *const tcp,
      99                 :            :                        const kernel_ulong_t addr,
     100                 :            :                        const unsigned int len,
     101                 :            :                        const void *const opaque_data)
     102                 :            : {
     103                 :            :         uint32_t inode;
     104                 :          8 :         const size_t nmemb = len / sizeof(inode);
     105                 :            : 
     106         [ +  + ]:          8 :         if (!nmemb)
     107                 :            :                 return false;
     108                 :            : 
     109                 :          6 :         print_array(tcp, addr, nmemb, &inode, sizeof(inode),
     110                 :            :                     umoven_or_printaddr, print_inode, 0);
     111                 :            : 
     112                 :          6 :         return true;
     113                 :            : }
     114                 :            : 
     115                 :            : static bool
     116                 :          6 : decode_unix_diag_rqlen(struct tcb *const tcp,
     117                 :            :                        const kernel_ulong_t addr,
     118                 :            :                        const unsigned int len,
     119                 :            :                        const void *const opaque_data)
     120                 :            : {
     121                 :            :         struct unix_diag_rqlen rql;
     122                 :            : 
     123         [ +  + ]:          6 :         if (len < sizeof(rql))
     124                 :            :                 return false;
     125         [ +  + ]:          4 :         if (umove_or_printaddr(tcp, addr, &rql))
     126                 :            :                 return true;
     127                 :            : 
     128                 :          2 :         PRINT_FIELD_U("{", rql, udiag_rqueue);
     129                 :          2 :         PRINT_FIELD_U(", ", rql, udiag_wqueue);
     130                 :          2 :         tprints("}");
     131                 :            : 
     132                 :          2 :         return true;
     133                 :            : }
     134                 :            : 
     135                 :            : static const nla_decoder_t unix_diag_msg_nla_decoders[] = {
     136                 :            :         [UNIX_DIAG_NAME]        = decode_nla_str,
     137                 :            :         [UNIX_DIAG_VFS]         = decode_unix_diag_vfs,
     138                 :            :         [UNIX_DIAG_PEER]        = decode_nla_u32,
     139                 :            :         [UNIX_DIAG_ICONS]       = decode_unix_diag_inode,
     140                 :            :         [UNIX_DIAG_RQLEN]       = decode_unix_diag_rqlen,
     141                 :            :         [UNIX_DIAG_MEMINFO]     = decode_nla_meminfo,
     142                 :            :         [UNIX_DIAG_SHUTDOWN]    = decode_nla_u8
     143                 :            : };
     144                 :            : 
     145                 :         54 : DECL_NETLINK_DIAG_DECODER(decode_unix_diag_msg)
     146                 :            : {
     147                 :         54 :         struct unix_diag_msg msg = { .udiag_family = family };
     148                 :         54 :         size_t offset = sizeof(msg.udiag_family);
     149                 :         54 :         bool decode_nla = false;
     150                 :            : 
     151                 :         54 :         PRINT_FIELD_XVAL("{", msg, udiag_family, addrfams, "AF_???");
     152                 :         54 :         tprints(", ");
     153         [ +  + ]:         54 :         if (len >= sizeof(msg)) {
     154         [ +  + ]:         52 :                 if (!umoven_or_printaddr(tcp, addr + offset,
     155                 :            :                                          sizeof(msg) - offset,
     156                 :            :                                          (void *) &msg + offset)) {
     157                 :         50 :                         PRINT_FIELD_XVAL("", msg, udiag_type,
     158                 :            :                                          socktypes, "SOCK_???");
     159                 :         50 :                         PRINT_FIELD_XVAL(", ", msg, udiag_state,
     160                 :            :                                          tcp_states, "TCP_???");
     161                 :         50 :                         PRINT_FIELD_U(", ", msg, udiag_ino);
     162                 :         50 :                         PRINT_FIELD_COOKIE(", ", msg, udiag_cookie);
     163                 :         50 :                         decode_nla = true;
     164                 :            :                 }
     165                 :            :         } else
     166                 :          2 :                 tprints("...");
     167                 :         54 :         tprints("}");
     168                 :            : 
     169                 :         54 :         offset = NLMSG_ALIGN(sizeof(msg));
     170 [ +  + ][ +  + ]:         54 :         if (decode_nla && len > offset) {
     171                 :         48 :                 tprints(", ");
     172                 :         48 :                 decode_nlattr(tcp, addr + offset, len - offset,
     173                 :            :                               unix_diag_attrs, "UNIX_DIAG_???",
     174                 :            :                               unix_diag_msg_nla_decoders,
     175                 :            :                               ARRAY_SIZE(unix_diag_msg_nla_decoders), NULL);
     176                 :            :         }
     177                 :         54 : }

Generated by: LCOV version 1.11