c02402d5ec361ca7ec2d1f0e56e86cd528914fee
[safe/jmp/linux-2.6] / include / net / netfilter / nf_conntrack_l3proto.h
1 /*
2  * Copyright (C)2003,2004 USAGI/WIDE Project
3  *
4  * Header for use in defining a given L3 protocol for connection tracking.
5  *
6  * Author:
7  *      Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
8  *
9  * Derived from include/netfilter_ipv4/ip_conntrack_protocol.h
10  */
11
12 #ifndef _NF_CONNTRACK_L3PROTO_H
13 #define _NF_CONNTRACK_L3PROTO_H
14 #include <linux/netlink.h>
15 #include <linux/seq_file.h>
16 #include <net/netfilter/nf_conntrack.h>
17
18 struct nf_conntrack_l3proto
19 {
20         /* L3 Protocol Family number. ex) PF_INET */
21         u_int16_t l3proto;
22
23         /* Protocol name */
24         const char *name;
25
26         /*
27          * Try to fill in the third arg: nhoff is offset of l3 proto
28          * hdr.  Return true if possible.
29          */
30         int (*pkt_to_tuple)(const struct sk_buff *skb, unsigned int nhoff,
31                             struct nf_conntrack_tuple *tuple);
32
33         /*
34          * Invert the per-proto part of the tuple: ie. turn xmit into reply.
35          * Some packets can't be inverted: return 0 in that case.
36          */
37         int (*invert_tuple)(struct nf_conntrack_tuple *inverse,
38                             const struct nf_conntrack_tuple *orig);
39
40         /* Print out the per-protocol part of the tuple. */
41         int (*print_tuple)(struct seq_file *s,
42                            const struct nf_conntrack_tuple *);
43
44         /* Print out the private part of the conntrack. */
45         int (*print_conntrack)(struct seq_file *s, const struct nf_conn *);
46
47         /* Returns verdict for packet, or -1 for invalid. */
48         int (*packet)(struct nf_conn *conntrack,
49                       const struct sk_buff *skb,
50                       enum ip_conntrack_info ctinfo);
51
52         /*
53          * Called when a new connection for this protocol found;
54          * returns TRUE if it's OK.  If so, packet() called next.
55          */
56         int (*new)(struct nf_conn *conntrack, const struct sk_buff *skb);
57
58         /*
59          * Called before tracking. 
60          *      *dataoff: offset of protocol header (TCP, UDP,...) in skb
61          *      *protonum: protocol number
62          */
63         int (*get_l4proto)(const struct sk_buff *skb, unsigned int nhoff,
64                            unsigned int *dataoff, u_int8_t *protonum);
65
66         int (*tuple_to_nfattr)(struct sk_buff *skb,
67                                const struct nf_conntrack_tuple *t);
68
69         int (*nfattr_to_tuple)(struct nlattr *tb[],
70                                struct nf_conntrack_tuple *t);
71
72 #ifdef CONFIG_SYSCTL
73         struct ctl_table_header *ctl_table_header;
74         struct ctl_table        *ctl_table_path;
75         struct ctl_table        *ctl_table;
76 #endif /* CONFIG_SYSCTL */
77
78         /* Module (if any) which this is connected to. */
79         struct module *me;
80 };
81
82 extern struct nf_conntrack_l3proto *nf_ct_l3protos[AF_MAX];
83
84 /* Protocol registration. */
85 extern int nf_conntrack_l3proto_register(struct nf_conntrack_l3proto *proto);
86 extern void nf_conntrack_l3proto_unregister(struct nf_conntrack_l3proto *proto);
87 extern struct nf_conntrack_l3proto *nf_ct_l3proto_find_get(u_int16_t l3proto);
88 extern void nf_ct_l3proto_put(struct nf_conntrack_l3proto *p);
89
90 /* Existing built-in protocols */
91 extern struct nf_conntrack_l3proto nf_conntrack_l3proto_generic;
92
93 static inline struct nf_conntrack_l3proto *
94 __nf_ct_l3proto_find(u_int16_t l3proto)
95 {
96         if (unlikely(l3proto >= AF_MAX))
97                 return &nf_conntrack_l3proto_generic;
98         return rcu_dereference(nf_ct_l3protos[l3proto]);
99 }
100
101 #endif /*_NF_CONNTRACK_L3PROTO_H*/