This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / include / net / netfilter / nf_conntrack_protocol.h
1 /*
2  * Header for use in defining a given protocol for connection tracking.
3  *
4  * 16 Dec 2003: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
5  *      - generalized L3 protocol dependent part.
6  *
7  * Derived from include/linux/netfiter_ipv4/ip_conntrack_protcol.h
8  */
9
10 #ifndef _NF_CONNTRACK_PROTOCOL_H
11 #define _NF_CONNTRACK_PROTOCOL_H
12 #include <net/netfilter/nf_conntrack.h>
13
14 struct seq_file;
15 struct nfattr;
16
17 struct nf_conntrack_protocol
18 {
19         /* Next pointer. */
20         struct list_head list;
21
22         /* L3 Protocol number. */
23         u_int16_t l3proto;
24
25         /* Protocol number. */
26         u_int8_t proto;
27
28         /* Protocol name */
29         const char *name;
30
31         /* Try to fill in the third arg: dataoff is offset past network protocol
32            hdr.  Return true if possible. */
33         int (*pkt_to_tuple)(const struct sk_buff *skb,
34                             unsigned int dataoff,
35                             struct nf_conntrack_tuple *tuple);
36
37         /* Invert the per-proto part of the tuple: ie. turn xmit into reply.
38          * Some packets can't be inverted: return 0 in that case.
39          */
40         int (*invert_tuple)(struct nf_conntrack_tuple *inverse,
41                             const struct nf_conntrack_tuple *orig);
42
43         /* Print out the per-protocol part of the tuple. Return like seq_* */
44         int (*print_tuple)(struct seq_file *s,
45                            const struct nf_conntrack_tuple *);
46
47         /* Print out the private part of the conntrack. */
48         int (*print_conntrack)(struct seq_file *s, const struct nf_conn *);
49
50         /* Returns verdict for packet, or -1 for invalid. */
51         int (*packet)(struct nf_conn *conntrack,
52                       const struct sk_buff *skb,
53                       unsigned int dataoff,
54                       enum ip_conntrack_info ctinfo,
55                       int pf,
56                       unsigned int hooknum);
57
58         /* Called when a new connection for this protocol found;
59          * returns TRUE if it's OK.  If so, packet() called next. */
60         int (*new)(struct nf_conn *conntrack, const struct sk_buff *skb,
61                    unsigned int dataoff);
62
63         /* Called when a conntrack entry is destroyed */
64         void (*destroy)(struct nf_conn *conntrack);
65
66         int (*error)(struct sk_buff *skb, unsigned int dataoff,
67                      enum ip_conntrack_info *ctinfo,
68                      int pf, unsigned int hooknum);
69
70         /* convert protoinfo to nfnetink attributes */
71         int (*to_nfattr)(struct sk_buff *skb, struct nfattr *nfa,
72                          const struct nf_conn *ct);
73
74         /* convert nfnetlink attributes to protoinfo */
75         int (*from_nfattr)(struct nfattr *tb[], struct nf_conn *ct);
76
77         int (*tuple_to_nfattr)(struct sk_buff *skb,
78                                const struct nf_conntrack_tuple *t);
79         int (*nfattr_to_tuple)(struct nfattr *tb[],
80                                struct nf_conntrack_tuple *t);
81
82         /* Module (if any) which this is connected to. */
83         struct module *me;
84 };
85
86 /* Existing built-in protocols */
87 extern struct nf_conntrack_protocol nf_conntrack_protocol_tcp6;
88 extern struct nf_conntrack_protocol nf_conntrack_protocol_udp4;
89 extern struct nf_conntrack_protocol nf_conntrack_protocol_udp6;
90 extern struct nf_conntrack_protocol nf_conntrack_generic_protocol;
91
92 #define MAX_NF_CT_PROTO 256
93 extern struct nf_conntrack_protocol **nf_ct_protos[PF_MAX];
94
95 extern struct nf_conntrack_protocol *
96 __nf_ct_proto_find(u_int16_t l3proto, u_int8_t protocol);
97
98 extern struct nf_conntrack_protocol *
99 nf_ct_proto_find_get(u_int16_t l3proto, u_int8_t protocol);
100
101 extern void nf_ct_proto_put(struct nf_conntrack_protocol *p);
102
103 /* Protocol registration. */
104 extern int nf_conntrack_protocol_register(struct nf_conntrack_protocol *proto);
105 extern void nf_conntrack_protocol_unregister(struct nf_conntrack_protocol *proto);
106
107 /* Generic netlink helpers */
108 extern int nf_ct_port_tuple_to_nfattr(struct sk_buff *skb,
109                                       const struct nf_conntrack_tuple *tuple);
110 extern int nf_ct_port_nfattr_to_tuple(struct nfattr *tb[],
111                                       struct nf_conntrack_tuple *t);
112
113 /* Log invalid packets */
114 extern unsigned int nf_ct_log_invalid;
115
116 #ifdef CONFIG_SYSCTL
117 #ifdef DEBUG_INVALID_PACKETS
118 #define LOG_INVALID(proto) \
119         (nf_ct_log_invalid == (proto) || nf_ct_log_invalid == IPPROTO_RAW)
120 #else
121 #define LOG_INVALID(proto) \
122         ((nf_ct_log_invalid == (proto) || nf_ct_log_invalid == IPPROTO_RAW) \
123          && net_ratelimit())
124 #endif
125 #else
126 #define LOG_INVALID(proto) 0
127 #endif /* CONFIG_SYSCTL */
128
129 #endif /*_NF_CONNTRACK_PROTOCOL_H*/