vserver 1.9.5.x5
[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         int (*error)(struct sk_buff *skb, enum ip_conntrack_info *ctinfo,
48                      unsigned int hooknum);
49
50         /* Module (if any) which this is connected to. */
51         struct module *me;
52 };
53
54 #define MAX_IP_CT_PROTO 256
55 extern struct ip_conntrack_protocol *ip_ct_protos[MAX_IP_CT_PROTO];
56
57 /* Protocol registration. */
58 extern int ip_conntrack_protocol_register(struct ip_conntrack_protocol *proto);
59 extern void ip_conntrack_protocol_unregister(struct ip_conntrack_protocol *proto);
60
61 static inline struct ip_conntrack_protocol *ip_ct_find_proto(u_int8_t protocol)
62 {
63         return ip_ct_protos[protocol];
64 }
65
66 /* Existing built-in protocols */
67 extern struct ip_conntrack_protocol ip_conntrack_protocol_tcp;
68 extern struct ip_conntrack_protocol ip_conntrack_protocol_udp;
69 extern struct ip_conntrack_protocol ip_conntrack_protocol_icmp;
70 extern struct ip_conntrack_protocol ip_conntrack_generic_protocol;
71 extern int ip_conntrack_protocol_tcp_init(void);
72
73 /* Log invalid packets */
74 extern unsigned int ip_ct_log_invalid;
75
76 #ifdef CONFIG_SYSCTL
77 #ifdef DEBUG_INVALID_PACKETS
78 #define LOG_INVALID(proto) \
79         (ip_ct_log_invalid == (proto) || ip_ct_log_invalid == IPPROTO_RAW)
80 #else
81 #define LOG_INVALID(proto) \
82         ((ip_ct_log_invalid == (proto) || ip_ct_log_invalid == IPPROTO_RAW) \
83          && net_ratelimit())
84 #endif
85 #else
86 #define LOG_INVALID(proto) 0
87 #endif /* CONFIG_SYSCTL */
88
89 #endif /*_IP_CONNTRACK_PROTOCOL_H*/