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