]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - include/linux/netfilter.h
[NETLINK]: Add properly module refcounting for kernel netlink sockets.
[mirror_ubuntu-zesty-kernel.git] / include / linux / netfilter.h
CommitLineData
1da177e4
LT
1#ifndef __LINUX_NETFILTER_H
2#define __LINUX_NETFILTER_H
3
4#ifdef __KERNEL__
5#include <linux/init.h>
6#include <linux/types.h>
7#include <linux/skbuff.h>
8#include <linux/net.h>
9#include <linux/if.h>
10#include <linux/wait.h>
11#include <linux/list.h>
12#endif
13#include <linux/compiler.h>
14
15/* Responses from hook functions. */
16#define NF_DROP 0
17#define NF_ACCEPT 1
18#define NF_STOLEN 2
19#define NF_QUEUE 3
20#define NF_REPEAT 4
21#define NF_STOP 5
22#define NF_MAX_VERDICT NF_STOP
23
6869c4d8
HW
24/* only for userspace compatibility */
25#ifndef __KERNEL__
1da177e4
LT
26/* Generic cache responses from hook functions.
27 <= 0x2000 is used for protocol-flags. */
28#define NFC_UNKNOWN 0x4000
29#define NFC_ALTERED 0x8000
6869c4d8 30#endif
1da177e4
LT
31
32#ifdef __KERNEL__
33#include <linux/config.h>
34#ifdef CONFIG_NETFILTER
35
36extern void netfilter_init(void);
37
38/* Largest hook number + 1 */
39#define NF_MAX_HOOKS 8
40
41struct sk_buff;
42struct net_device;
43
44typedef unsigned int nf_hookfn(unsigned int hooknum,
45 struct sk_buff **skb,
46 const struct net_device *in,
47 const struct net_device *out,
48 int (*okfn)(struct sk_buff *));
49
50struct nf_hook_ops
51{
52 struct list_head list;
53
54 /* User fills in from here down. */
55 nf_hookfn *hook;
56 struct module *owner;
57 int pf;
58 int hooknum;
59 /* Hooks are ordered in ascending priority. */
60 int priority;
61};
62
63struct nf_sockopt_ops
64{
65 struct list_head list;
66
67 int pf;
68
69 /* Non-inclusive ranges: use 0/0/NULL to never get called. */
70 int set_optmin;
71 int set_optmax;
72 int (*set)(struct sock *sk, int optval, void __user *user, unsigned int len);
73
74 int get_optmin;
75 int get_optmax;
76 int (*get)(struct sock *sk, int optval, void __user *user, int *len);
77
78 /* Number of users inside set() or get(). */
79 unsigned int use;
80 struct task_struct *cleanup_task;
81};
82
83/* Each queued (to userspace) skbuff has one of these. */
84struct nf_info
85{
86 /* The ops struct which sent us to userspace. */
87 struct nf_hook_ops *elem;
88
89 /* If we're sent to userspace, this keeps housekeeping info */
90 int pf;
91 unsigned int hook;
92 struct net_device *indev, *outdev;
93 int (*okfn)(struct sk_buff *);
94};
95
96/* Function to register/unregister hook points. */
97int nf_register_hook(struct nf_hook_ops *reg);
98void nf_unregister_hook(struct nf_hook_ops *reg);
99
100/* Functions to register get/setsockopt ranges (non-inclusive). You
101 need to check permissions yourself! */
102int nf_register_sockopt(struct nf_sockopt_ops *reg);
103void nf_unregister_sockopt(struct nf_sockopt_ops *reg);
104
105extern struct list_head nf_hooks[NPROTO][NF_MAX_HOOKS];
106
107typedef void nf_logfn(unsigned int hooknum,
108 const struct sk_buff *skb,
109 const struct net_device *in,
110 const struct net_device *out,
111 const char *prefix);
112
113/* Function to register/unregister log function. */
114int nf_log_register(int pf, nf_logfn *logfn);
115void nf_log_unregister(int pf, nf_logfn *logfn);
116
117/* Calls the registered backend logging function */
118void nf_log_packet(int pf,
119 unsigned int hooknum,
120 const struct sk_buff *skb,
121 const struct net_device *in,
122 const struct net_device *out,
123 const char *fmt, ...);
124
125/* Activate hook; either okfn or kfree_skb called, unless a hook
126 returns NF_STOLEN (in which case, it's up to the hook to deal with
127 the consequences).
128
129 Returns -ERRNO if packet dropped. Zero means queued, stolen or
130 accepted.
131*/
132
133/* RR:
134 > I don't want nf_hook to return anything because people might forget
135 > about async and trust the return value to mean "packet was ok".
136
137 AK:
138 Just document it clearly, then you can expect some sense from kernel
139 coders :)
140*/
141
142/* This is gross, but inline doesn't cut it for avoiding the function
143 call in fast path: gcc doesn't inline (needs value tracking?). --RR */
144#ifdef CONFIG_NETFILTER_DEBUG
145#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
146({int __ret; \
147if ((__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, INT_MIN)) == 1) \
148 __ret = (okfn)(skb); \
149__ret;})
150#define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
151({int __ret; \
152if ((__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, thresh)) == 1) \
153 __ret = (okfn)(skb); \
154__ret;})
155#else
156#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
157({int __ret; \
158if (list_empty(&nf_hooks[pf][hook]) || \
159 (__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, INT_MIN)) == 1) \
160 __ret = (okfn)(skb); \
161__ret;})
162#define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
163({int __ret; \
164if (list_empty(&nf_hooks[pf][hook]) || \
165 (__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, thresh)) == 1) \
166 __ret = (okfn)(skb); \
167__ret;})
168#endif
169
170int nf_hook_slow(int pf, unsigned int hook, struct sk_buff **pskb,
171 struct net_device *indev, struct net_device *outdev,
172 int (*okfn)(struct sk_buff *), int thresh);
173
174/* Call setsockopt() */
175int nf_setsockopt(struct sock *sk, int pf, int optval, char __user *opt,
176 int len);
177int nf_getsockopt(struct sock *sk, int pf, int optval, char __user *opt,
178 int *len);
179
180/* Packet queuing */
181typedef int (*nf_queue_outfn_t)(struct sk_buff *skb,
182 struct nf_info *info, void *data);
183extern int nf_register_queue_handler(int pf,
184 nf_queue_outfn_t outfn, void *data);
185extern int nf_unregister_queue_handler(int pf);
186extern void nf_reinject(struct sk_buff *skb,
187 struct nf_info *info,
188 unsigned int verdict);
189
190extern void (*ip_ct_attach)(struct sk_buff *, struct sk_buff *);
191extern void nf_ct_attach(struct sk_buff *, struct sk_buff *);
192
193/* FIXME: Before cache is ever used, this must be implemented for real. */
194extern void nf_invalidate_cache(int pf);
195
089af26c
HW
196/* Call this before modifying an existing packet: ensures it is
197 modifiable and linear to the point you care about (writable_len).
198 Returns true or false. */
199extern int skb_make_writable(struct sk_buff **pskb, unsigned int writable_len);
200
1da177e4
LT
201#else /* !CONFIG_NETFILTER */
202#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (okfn)(skb)
203static inline void nf_ct_attach(struct sk_buff *new, struct sk_buff *skb) {}
204#endif /*CONFIG_NETFILTER*/
205
206#endif /*__KERNEL__*/
207#endif /*__LINUX_NETFILTER_H*/