Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  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_MAX_VERDICT NF_REPEAT
 22 
 23 /* Generic cache responses from hook functions.
 24    <= 0x2000 is used for protocol-flags. */
 25 #define NFC_UNKNOWN 0x4000
 26 #define NFC_ALTERED 0x8000
 27 
 28 #ifdef __KERNEL__
 29 #include <linux/config.h>
 30 #ifdef CONFIG_NETFILTER
 31 
 32 extern void netfilter_init(void);
 33 
 34 /* Largest hook number + 1 */
 35 #define NF_MAX_HOOKS 8
 36 
 37 struct sk_buff;
 38 struct net_device;
 39 
 40 typedef unsigned int nf_hookfn(unsigned int hooknum,
 41                                struct sk_buff **skb,
 42                                const struct net_device *in,
 43                                const struct net_device *out,
 44                                int (*okfn)(struct sk_buff *));
 45 
 46 struct nf_hook_ops
 47 {
 48         struct list_head list;
 49 
 50         /* User fills in from here down. */
 51         nf_hookfn *hook;
 52         struct module *owner;
 53         int pf;
 54         int hooknum;
 55         /* Hooks are ordered in ascending priority. */
 56         int priority;
 57 };
 58 
 59 struct nf_sockopt_ops
 60 {
 61         struct list_head list;
 62 
 63         int pf;
 64 
 65         /* Non-inclusive ranges: use 0/0/NULL to never get called. */
 66         int set_optmin;
 67         int set_optmax;
 68         int (*set)(struct sock *sk, int optval, void __user *user, unsigned int len);
 69 
 70         int get_optmin;
 71         int get_optmax;
 72         int (*get)(struct sock *sk, int optval, void __user *user, int *len);
 73 
 74         /* Number of users inside set() or get(). */
 75         unsigned int use;
 76         struct task_struct *cleanup_task;
 77 };
 78 
 79 /* Each queued (to userspace) skbuff has one of these. */
 80 struct nf_info
 81 {
 82         /* The ops struct which sent us to userspace. */
 83         struct nf_hook_ops *elem;
 84         
 85         /* If we're sent to userspace, this keeps housekeeping info */
 86         int pf;
 87         unsigned int hook;
 88         struct net_device *indev, *outdev;
 89         int (*okfn)(struct sk_buff *);
 90 };
 91                                                                                 
 92 /* Function to register/unregister hook points. */
 93 int nf_register_hook(struct nf_hook_ops *reg);
 94 void nf_unregister_hook(struct nf_hook_ops *reg);
 95 
 96 /* Functions to register get/setsockopt ranges (non-inclusive).  You
 97    need to check permissions yourself! */
 98 int nf_register_sockopt(struct nf_sockopt_ops *reg);
 99 void nf_unregister_sockopt(struct nf_sockopt_ops *reg);
100 
101 extern struct list_head nf_hooks[NPROTO][NF_MAX_HOOKS];
102 
103 typedef void nf_logfn(unsigned int hooknum,
104                       const struct sk_buff *skb,
105                       const struct net_device *in,
106                       const struct net_device *out,
107                       const char *prefix);
108 
109 /* Function to register/unregister log function. */
110 int nf_log_register(int pf, nf_logfn *logfn);
111 void nf_log_unregister(int pf, nf_logfn *logfn);
112 
113 /* Calls the registered backend logging function */
114 void nf_log_packet(int pf,
115                    unsigned int hooknum,
116                    const struct sk_buff *skb,
117                    const struct net_device *in,
118                    const struct net_device *out,
119                    const char *fmt, ...);
120                    
121 /* Activate hook; either okfn or kfree_skb called, unless a hook
122    returns NF_STOLEN (in which case, it's up to the hook to deal with
123    the consequences).
124 
125    Returns -ERRNO if packet dropped.  Zero means queued, stolen or
126    accepted.
127 */
128 
129 /* RR:
130    > I don't want nf_hook to return anything because people might forget
131    > about async and trust the return value to mean "packet was ok".
132 
133    AK:
134    Just document it clearly, then you can expect some sense from kernel
135    coders :)
136 */
137 
138 /* This is gross, but inline doesn't cut it for avoiding the function
139    call in fast path: gcc doesn't inline (needs value tracking?). --RR */
140 #ifdef CONFIG_NETFILTER_DEBUG
141 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn)                     \
142  nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN)
143 #define NF_HOOK_THRESH nf_hook_slow
144 #else
145 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn)                     \
146 (list_empty(&nf_hooks[(pf)][(hook)])                                    \
147  ? (okfn)(skb)                                                          \
148  : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN))
149 #define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh)      \
150 (list_empty(&nf_hooks[(pf)][(hook)])                                    \
151  ? (okfn)(skb)                                                          \
152  : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), (thresh)))
153 #endif
154 
155 int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
156                  struct net_device *indev, struct net_device *outdev,
157                  int (*okfn)(struct sk_buff *), int thresh);
158 
159 /* Call setsockopt() */
160 int nf_setsockopt(struct sock *sk, int pf, int optval, char __user *opt, 
161                   int len);
162 int nf_getsockopt(struct sock *sk, int pf, int optval, char __user *opt,
163                   int *len);
164 
165 /* Packet queuing */
166 typedef int (*nf_queue_outfn_t)(struct sk_buff *skb, 
167                                 struct nf_info *info, void *data);
168 extern int nf_register_queue_handler(int pf, 
169                                      nf_queue_outfn_t outfn, void *data);
170 extern int nf_unregister_queue_handler(int pf);
171 extern void nf_reinject(struct sk_buff *skb,
172                         struct nf_info *info,
173                         unsigned int verdict);
174 
175 extern void (*ip_ct_attach)(struct sk_buff *, struct sk_buff *);
176 extern void nf_ct_attach(struct sk_buff *, struct sk_buff *);
177 
178 /* FIXME: Before cache is ever used, this must be implemented for real. */
179 extern void nf_invalidate_cache(int pf);
180 
181 #else /* !CONFIG_NETFILTER */
182 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (okfn)(skb)
183 static inline void nf_ct_attach(struct sk_buff *new, struct sk_buff *skb) {}
184 #endif /*CONFIG_NETFILTER*/
185 
186 #endif /*__KERNEL__*/
187 #endif /*__LINUX_NETFILTER_H*/
188 
  This page was automatically generated by the LXR engine.