vserver 1.9.3
[linux-2.6.git] / include / linux / netfilter_ipv4 / ip_conntrack_protocol.h
1 /* Header for use in defining a given protocol for connection tracking. */
2 #ifndef _IP_CONNTRACK_PROTOCOL_H
3 #define _IP_CONNTRACK_PROTOCOL_H
4 #include <linux/netfilter_ipv4/ip_conntrack.h>
5
6 struct seq_file;
7
8 struct ip_conntrack_protocol
9 {
10         /* Protocol number. */
11         u_int8_t proto;
12
13         /* Protocol name */
14         const char *name;
15
16         /* Try to fill in the third arg: dataoff is offset past IP
17            hdr.  Return true if possible. */
18         int (*pkt_to_tuple)(const struct sk_buff *skb,
19                            unsigned int dataoff,
20                            struct ip_conntrack_tuple *tuple);
21
22         /* Invert the per-proto part of the tuple: ie. turn xmit into reply.
23          * Some packets can't be inverted: return 0 in that case.
24          */
25         int (*invert_tuple)(struct ip_conntrack_tuple *inverse,
26                             const struct ip_conntrack_tuple *orig);
27
28         /* Print out the per-protocol part of the tuple. Return like seq_* */
29         int (*print_tuple)(struct seq_file *,
30                            const struct ip_conntrack_tuple *);
31
32         /* Print out the private part of the conntrack. */
33         int (*print_conntrack)(struct seq_file *, const struct ip_conntrack *);
34
35         /* Returns verdict for packet, or -1 for invalid. */
36         int (*packet)(struct ip_conntrack *conntrack,
37                       const struct sk_buff *skb,
38                       enum ip_conntrack_info ctinfo);
39
40         /* Called when a new connection for this protocol found;
41          * returns TRUE if it's OK.  If so, packet() called next. */
42         int (*new)(struct ip_conntrack *conntrack, const struct sk_buff *skb);
43
44         /* Called when a conntrack entry is destroyed */
45         void (*destroy)(struct ip_conntrack *conntrack);
46
47         /* Has to decide if a expectation matches one packet or not */
48         int (*exp_matches_pkt)(struct ip_conntrack_expect *exp,
49                                const struct sk_buff *skb);
50
51         int (*error)(struct sk_buff *skb, enum ip_conntrack_info *ctinfo,
52                      unsigned int hooknum);
53
54         /* Module (if any) which this is connected to. */
55         struct module *me;
56 };
57
58 #define MAX_IP_CT_PROTO 256
59 extern struct ip_conntrack_protocol *ip_ct_protos[MAX_IP_CT_PROTO];
60
61 /* Protocol registration. */
62 extern int ip_conntrack_protocol_register(struct ip_conntrack_protocol *proto);
63 extern void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol *proto);
64
65 static inline struct ip_conntrack_protocol *ip_ct_find_proto(u_int8_t protocol)
66 {
67         return ip_ct_protos[protocol];
68 }
69
70 /* Existing built-in protocols */
71 extern struct ip_conntrack_protocol ip_conntrack_protocol_tcp;
72 extern struct ip_conntrack_protocol ip_conntrack_protocol_udp;
73 extern struct ip_conntrack_protocol ip_conntrack_protocol_icmp;
74 extern struct ip_conntrack_protocol ip_conntrack_generic_protocol;
75 extern int ip_conntrack_protocol_tcp_init(void);
76
77 /* Log invalid packets */
78 extern unsigned int ip_ct_log_invalid;
79
80 #ifdef CONFIG_SYSCTL
81 #ifdef DEBUG_INVALID_PACKETS
82 #define LOG_INVALID(proto) \
83         (ip_ct_log_invalid == (proto) || ip_ct_log_invalid == IPPROTO_RAW)
84 #else
85 #define LOG_INVALID(proto) \
86         ((ip_ct_log_invalid == (proto) || ip_ct_log_invalid == IPPROTO_RAW) \
87          && net_ratelimit())
88 #endif
89 #else
90 #define LOG_INVALID(proto) 0
91 #endif /* CONFIG_SYSCTL */
92
93 #endif /*_IP_CONNTRACK_PROTOCOL_H*/