LCOV - code coverage report
Current view: top level - include/linux - sock_diag.h (source / functions) Hit Total Coverage
Test: landlock.info Lines: 12 27 44.4 %
Date: 2021-04-22 12:43:58 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: GPL-2.0 */
       2             : #ifndef __SOCK_DIAG_H__
       3             : #define __SOCK_DIAG_H__
       4             : 
       5             : #include <linux/netlink.h>
       6             : #include <linux/user_namespace.h>
       7             : #include <net/net_namespace.h>
       8             : #include <net/sock.h>
       9             : #include <uapi/linux/sock_diag.h>
      10             : 
      11             : struct sk_buff;
      12             : struct nlmsghdr;
      13             : struct sock;
      14             : 
      15             : struct sock_diag_handler {
      16             :         __u8 family;
      17             :         int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
      18             :         int (*get_info)(struct sk_buff *skb, struct sock *sk);
      19             :         int (*destroy)(struct sk_buff *skb, struct nlmsghdr *nlh);
      20             : };
      21             : 
      22             : int sock_diag_register(const struct sock_diag_handler *h);
      23             : void sock_diag_unregister(const struct sock_diag_handler *h);
      24             : 
      25             : void sock_diag_register_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh));
      26             : void sock_diag_unregister_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh));
      27             : 
      28             : u64 __sock_gen_cookie(struct sock *sk);
      29             : 
      30           0 : static inline u64 sock_gen_cookie(struct sock *sk)
      31             : {
      32           0 :         u64 cookie;
      33             : 
      34           0 :         preempt_disable();
      35           0 :         cookie = __sock_gen_cookie(sk);
      36           0 :         preempt_enable();
      37             : 
      38           0 :         return cookie;
      39             : }
      40             : 
      41             : int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie);
      42             : void sock_diag_save_cookie(struct sock *sk, __u32 *cookie);
      43             : 
      44             : int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attr);
      45             : int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
      46             :                              struct sk_buff *skb, int attrtype);
      47             : 
      48             : static inline
      49         738 : enum sknetlink_groups sock_diag_destroy_group(const struct sock *sk)
      50             : {
      51         738 :         switch (sk->sk_family) {
      52          43 :         case AF_INET:
      53          43 :                 if (sk->sk_type == SOCK_RAW)
      54             :                         return SKNLGRP_NONE;
      55             : 
      56          43 :                 switch (sk->sk_protocol) {
      57             :                 case IPPROTO_TCP:
      58             :                         return SKNLGRP_INET_TCP_DESTROY;
      59          39 :                 case IPPROTO_UDP:
      60          39 :                         return SKNLGRP_INET_UDP_DESTROY;
      61           0 :                 default:
      62           0 :                         return SKNLGRP_NONE;
      63             :                 }
      64           0 :         case AF_INET6:
      65           0 :                 if (sk->sk_type == SOCK_RAW)
      66             :                         return SKNLGRP_NONE;
      67             : 
      68           0 :                 switch (sk->sk_protocol) {
      69             :                 case IPPROTO_TCP:
      70             :                         return SKNLGRP_INET6_TCP_DESTROY;
      71           0 :                 case IPPROTO_UDP:
      72           0 :                         return SKNLGRP_INET6_UDP_DESTROY;
      73           0 :                 default:
      74           0 :                         return SKNLGRP_NONE;
      75             :                 }
      76             :         default:
      77             :                 return SKNLGRP_NONE;
      78             :         }
      79             : }
      80             : 
      81             : static inline
      82         738 : bool sock_diag_has_destroy_listeners(const struct sock *sk)
      83             : {
      84         738 :         const struct net *n = sock_net(sk);
      85         738 :         const enum sknetlink_groups group = sock_diag_destroy_group(sk);
      86             : 
      87         781 :         return group != SKNLGRP_NONE && n->diag_nlsk &&
      88          43 :                 netlink_has_listeners(n->diag_nlsk, group);
      89             : }
      90             : void sock_diag_broadcast_destroy(struct sock *sk);
      91             : 
      92             : int sock_diag_destroy(struct sock *sk, int err);
      93             : #endif

Generated by: LCOV version 1.14