hc
2024-11-01 7e970c18f85f99acc678d90128b6e01dce1bf273
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _NFNETLINK_H
#define _NFNETLINK_H
 
#include <linux/netlink.h>
#include <linux/capability.h>
#include <linux/android_kabi.h>
#include <net/netlink.h>
#include <uapi/linux/netfilter/nfnetlink.h>
 
struct nfnl_callback {
   int (*call)(struct net *net, struct sock *nl, struct sk_buff *skb,
           const struct nlmsghdr *nlh,
           const struct nlattr * const cda[],
           struct netlink_ext_ack *extack);
   int (*call_rcu)(struct net *net, struct sock *nl, struct sk_buff *skb,
           const struct nlmsghdr *nlh,
           const struct nlattr * const cda[],
           struct netlink_ext_ack *extack);
   int (*call_batch)(struct net *net, struct sock *nl, struct sk_buff *skb,
             const struct nlmsghdr *nlh,
             const struct nlattr * const cda[],
             struct netlink_ext_ack *extack);
   const struct nla_policy *policy;    /* netlink attribute policy */
   const u_int16_t attr_count;        /* number of nlattr's */
 
   ANDROID_KABI_RESERVE(1);
};
 
enum nfnl_abort_action {
   NFNL_ABORT_NONE        = 0,
   NFNL_ABORT_AUTOLOAD,
   NFNL_ABORT_VALIDATE,
};
 
struct nfnetlink_subsystem {
   const char *name;
   __u8 subsys_id;            /* nfnetlink subsystem ID */
   __u8 cb_count;            /* number of callbacks */
   const struct nfnl_callback *cb;    /* callback for individual types */
   struct module *owner;
   int (*commit)(struct net *net, struct sk_buff *skb);
   int (*abort)(struct net *net, struct sk_buff *skb,
            enum nfnl_abort_action action);
   void (*cleanup)(struct net *net);
   bool (*valid_genid)(struct net *net, u32 genid);
 
   ANDROID_KABI_RESERVE(1);
};
 
int nfnetlink_subsys_register(const struct nfnetlink_subsystem *n);
int nfnetlink_subsys_unregister(const struct nfnetlink_subsystem *n);
 
int nfnetlink_has_listeners(struct net *net, unsigned int group);
int nfnetlink_send(struct sk_buff *skb, struct net *net, u32 portid,
          unsigned int group, int echo, gfp_t flags);
int nfnetlink_set_err(struct net *net, u32 portid, u32 group, int error);
int nfnetlink_unicast(struct sk_buff *skb, struct net *net, u32 portid);
 
static inline u16 nfnl_msg_type(u8 subsys, u8 msg_type)
{
   return subsys << 8 | msg_type;
}
 
static inline void nfnl_fill_hdr(struct nlmsghdr *nlh, u8 family, u8 version,
                __be16 res_id)
{
   struct nfgenmsg *nfmsg;
 
   nfmsg = nlmsg_data(nlh);
   nfmsg->nfgen_family = family;
   nfmsg->version = version;
   nfmsg->res_id = res_id;
}
 
static inline struct nlmsghdr *nfnl_msg_put(struct sk_buff *skb, u32 portid,
                       u32 seq, int type, int flags,
                       u8 family, u8 version,
                       __be16 res_id)
{
   struct nlmsghdr *nlh;
 
   nlh = nlmsg_put(skb, portid, seq, type, sizeof(struct nfgenmsg), flags);
   if (!nlh)
       return NULL;
 
   nfnl_fill_hdr(nlh, family, version, res_id);
 
   return nlh;
}
 
void nfnl_lock(__u8 subsys_id);
void nfnl_unlock(__u8 subsys_id);
#ifdef CONFIG_PROVE_LOCKING
bool lockdep_nfnl_is_held(__u8 subsys_id);
#else
static inline bool lockdep_nfnl_is_held(__u8 subsys_id)
{
   return true;
}
#endif /* CONFIG_PROVE_LOCKING */
 
#define MODULE_ALIAS_NFNL_SUBSYS(subsys) \
   MODULE_ALIAS("nfnetlink-subsys-" __stringify(subsys))
 
#endif    /* _NFNETLINK_H */