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