LCOV - code coverage report
Current view: top level - mptcp/diag.c (source / functions) Coverage Total Hit
Test: export-net Lines: 64.5 % 76 49
Test Date: 2024-10-18 11:14:13 Functions: 66.7 % 3 2
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 43.8 % 64 28

             Branch data     Line data    Source code
       1                 :             : // SPDX-License-Identifier: GPL-2.0
       2                 :             : /* MPTCP socket monitoring support
       3                 :             :  *
       4                 :             :  * Copyright (c) 2019 Red Hat
       5                 :             :  *
       6                 :             :  * Author: Davide Caratti <dcaratti@redhat.com>
       7                 :             :  */
       8                 :             : 
       9                 :             : #include <linux/kernel.h>
      10                 :             : #include <linux/net.h>
      11                 :             : #include <linux/inet_diag.h>
      12                 :             : #include <net/netlink.h>
      13                 :             : #include "protocol.h"
      14                 :             : 
      15                 :         168 : static int subflow_get_info(struct sock *sk, struct sk_buff *skb)
      16                 :             : {
      17                 :         168 :         struct mptcp_subflow_context *sf;
      18                 :         168 :         struct nlattr *start;
      19                 :         168 :         u32 flags = 0;
      20                 :         168 :         bool slow;
      21                 :         168 :         int err;
      22                 :             : 
      23         [ -  + ]:         168 :         if (inet_sk_state_load(sk) == TCP_LISTEN)
      24                 :             :                 return 0;
      25                 :             : 
      26                 :         168 :         start = nla_nest_start_noflag(skb, INET_ULP_INFO_MPTCP);
      27         [ +  - ]:         168 :         if (!start)
      28                 :             :                 return -EMSGSIZE;
      29                 :             : 
      30                 :         168 :         slow = lock_sock_fast(sk);
      31                 :         168 :         rcu_read_lock();
      32   [ +  -  -  +  :         168 :         sf = rcu_dereference(inet_csk(sk)->icsk_ulp_data);
          -  -  -  -  -  
                      - ]
      33         [ -  + ]:         168 :         if (!sf) {
      34                 :           0 :                 err = 0;
      35                 :           0 :                 goto nla_failure;
      36                 :             :         }
      37                 :             : 
      38         [ +  + ]:         168 :         if (sf->mp_capable)
      39                 :          36 :                 flags |= MPTCP_SUBFLOW_FLAG_MCAP_REM;
      40         [ +  + ]:         168 :         if (sf->request_mptcp)
      41                 :          18 :                 flags |= MPTCP_SUBFLOW_FLAG_MCAP_LOC;
      42         [ +  + ]:         168 :         if (sf->mp_join)
      43                 :         132 :                 flags |= MPTCP_SUBFLOW_FLAG_JOIN_REM;
      44         [ +  + ]:         168 :         if (sf->request_join)
      45                 :          66 :                 flags |= MPTCP_SUBFLOW_FLAG_JOIN_LOC;
      46         [ -  + ]:         168 :         if (sf->backup)
      47                 :           0 :                 flags |= MPTCP_SUBFLOW_FLAG_BKUP_REM;
      48         [ -  + ]:         168 :         if (sf->request_bkup)
      49                 :           0 :                 flags |= MPTCP_SUBFLOW_FLAG_BKUP_LOC;
      50         [ +  - ]:         168 :         if (sf->fully_established)
      51                 :         168 :                 flags |= MPTCP_SUBFLOW_FLAG_FULLY_ESTABLISHED;
      52         [ +  - ]:         168 :         if (sf->conn_finished)
      53                 :         168 :                 flags |= MPTCP_SUBFLOW_FLAG_CONNECTED;
      54         [ -  + ]:         168 :         if (sf->map_valid)
      55                 :           0 :                 flags |= MPTCP_SUBFLOW_FLAG_MAPVALID;
      56                 :             : 
      57   [ +  -  +  - ]:         336 :         if (nla_put_u32(skb, MPTCP_SUBFLOW_ATTR_TOKEN_REM, sf->remote_token) ||
      58         [ +  - ]:         336 :             nla_put_u32(skb, MPTCP_SUBFLOW_ATTR_TOKEN_LOC, sf->token) ||
      59         [ #  # ]:         168 :             nla_put_u32(skb, MPTCP_SUBFLOW_ATTR_RELWRITE_SEQ,
      60         [ +  - ]:         168 :                         sf->rel_write_seq) ||
      61         [ #  # ]:         168 :             nla_put_u64_64bit(skb, MPTCP_SUBFLOW_ATTR_MAP_SEQ, sf->map_seq,
      62         [ +  - ]:         168 :                               MPTCP_SUBFLOW_ATTR_PAD) ||
      63         [ #  # ]:         168 :             nla_put_u32(skb, MPTCP_SUBFLOW_ATTR_MAP_SFSEQ,
      64         [ +  - ]:         168 :                         sf->map_subflow_seq) ||
      65         [ +  - ]:         336 :             nla_put_u32(skb, MPTCP_SUBFLOW_ATTR_SSN_OFFSET, sf->ssn_offset) ||
      66         [ #  # ]:         168 :             nla_put_u16(skb, MPTCP_SUBFLOW_ATTR_MAP_DATALEN,
      67         [ +  - ]:         336 :                         sf->map_data_len) ||
      68         [ +  - ]:         168 :             nla_put_u32(skb, MPTCP_SUBFLOW_ATTR_FLAGS, flags) ||
      69         [ -  + ]:         336 :             nla_put_u8(skb, MPTCP_SUBFLOW_ATTR_ID_REM, sf->remote_id) ||
      70         [ #  # ]:           0 :             nla_put_u8(skb, MPTCP_SUBFLOW_ATTR_ID_LOC, subflow_get_local_id(sf))) {
      71                 :           0 :                 err = -EMSGSIZE;
      72                 :           0 :                 goto nla_failure;
      73                 :             :         }
      74                 :             : 
      75                 :         168 :         rcu_read_unlock();
      76                 :         168 :         unlock_sock_fast(sk, slow);
      77                 :         168 :         nla_nest_end(skb, start);
      78                 :         168 :         return 0;
      79                 :             : 
      80                 :           0 : nla_failure:
      81                 :           0 :         rcu_read_unlock();
      82                 :           0 :         unlock_sock_fast(sk, slow);
      83                 :           0 :         nla_nest_cancel(skb, start);
      84                 :           0 :         return err;
      85                 :             : }
      86                 :             : 
      87                 :           0 : static size_t subflow_get_info_size(const struct sock *sk)
      88                 :             : {
      89                 :           0 :         size_t size = 0;
      90                 :             : 
      91                 :           0 :         size += nla_total_size(0) +     /* INET_ULP_INFO_MPTCP */
      92                 :           0 :                 nla_total_size(4) +     /* MPTCP_SUBFLOW_ATTR_TOKEN_REM */
      93                 :           0 :                 nla_total_size(4) +     /* MPTCP_SUBFLOW_ATTR_TOKEN_LOC */
      94                 :           0 :                 nla_total_size(4) +     /* MPTCP_SUBFLOW_ATTR_RELWRITE_SEQ */
      95                 :           0 :                 nla_total_size_64bit(8) +       /* MPTCP_SUBFLOW_ATTR_MAP_SEQ */
      96                 :           0 :                 nla_total_size(4) +     /* MPTCP_SUBFLOW_ATTR_MAP_SFSEQ */
      97                 :           0 :                 nla_total_size(4) +     /* MPTCP_SUBFLOW_ATTR_SSN_OFFSET */
      98                 :           0 :                 nla_total_size(2) +     /* MPTCP_SUBFLOW_ATTR_MAP_DATALEN */
      99                 :           0 :                 nla_total_size(4) +     /* MPTCP_SUBFLOW_ATTR_FLAGS */
     100                 :           0 :                 nla_total_size(1) +     /* MPTCP_SUBFLOW_ATTR_ID_REM */
     101                 :           0 :                 nla_total_size(1) +     /* MPTCP_SUBFLOW_ATTR_ID_LOC */
     102                 :             :                 0;
     103                 :           0 :         return size;
     104                 :             : }
     105                 :             : 
     106                 :           4 : void mptcp_diag_subflow_init(struct tcp_ulp_ops *ops)
     107                 :             : {
     108                 :           4 :         ops->get_info = subflow_get_info;
     109                 :           4 :         ops->get_info_size = subflow_get_info_size;
     110                 :           4 : }
        

Generated by: LCOV version 2.0-1