[NETFILTER]: ctnetlink: use netlink policy
[pandora-kernel.git] / include / net / netfilter / nf_conntrack_l4proto.h
1 /*
2  * Header for use in defining a given L4 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_L4PROTO_H
11 #define _NF_CONNTRACK_L4PROTO_H
12 #include <linux/netlink.h>
13 #include <net/netlink.h>
14 #include <net/netfilter/nf_conntrack.h>
15
16 struct seq_file;
17
18 struct nf_conntrack_l4proto
19 {
20         /* L3 Protocol number. */
21         u_int16_t l3proto;
22
23         /* L4 Protocol number. */
24         u_int8_t l4proto;
25
26         /* Protocol name */
27         const char *name;
28
29         /* Try to fill in the third arg: dataoff is offset past network protocol
30            hdr.  Return true if possible. */
31         int (*pkt_to_tuple)(const struct sk_buff *skb,
32                             unsigned int dataoff,
33                             struct nf_conntrack_tuple *tuple);
34
35         /* Invert the per-proto part of the tuple: ie. turn xmit into reply.
36          * Some packets can't be inverted: return 0 in that case.
37          */
38         int (*invert_tuple)(struct nf_conntrack_tuple *inverse,
39                             const struct nf_conntrack_tuple *orig);
40
41         /* Print out the per-protocol part of the tuple. Return like seq_* */
42         int (*print_tuple)(struct seq_file *s,
43                            const struct nf_conntrack_tuple *);
44
45         /* Print out the private part of the conntrack. */
46         int (*print_conntrack)(struct seq_file *s, const struct nf_conn *);
47
48         /* Returns verdict for packet, or -1 for invalid. */
49         int (*packet)(struct nf_conn *conntrack,
50                       const struct sk_buff *skb,
51                       unsigned int dataoff,
52                       enum ip_conntrack_info ctinfo,
53                       int pf,
54                       unsigned int hooknum);
55
56         /* Called when a new connection for this protocol found;
57          * returns TRUE if it's OK.  If so, packet() called next. */
58         int (*new)(struct nf_conn *conntrack, const struct sk_buff *skb,
59                    unsigned int dataoff);
60
61         /* Called when a conntrack entry is destroyed */
62         void (*destroy)(struct nf_conn *conntrack);
63
64         int (*error)(struct sk_buff *skb, unsigned int dataoff,
65                      enum ip_conntrack_info *ctinfo,
66                      int pf, unsigned int hooknum);
67
68         /* convert protoinfo to nfnetink attributes */
69         int (*to_nlattr)(struct sk_buff *skb, struct nlattr *nla,
70                          const struct nf_conn *ct);
71
72         /* convert nfnetlink attributes to protoinfo */
73         int (*from_nlattr)(struct nlattr *tb[], struct nf_conn *ct);
74
75         int (*tuple_to_nlattr)(struct sk_buff *skb,
76                                const struct nf_conntrack_tuple *t);
77         int (*nlattr_to_tuple)(struct nlattr *tb[],
78                                struct nf_conntrack_tuple *t);
79         const struct nla_policy *nla_policy;
80
81 #ifdef CONFIG_SYSCTL
82         struct ctl_table_header **ctl_table_header;
83         struct ctl_table        *ctl_table;
84         unsigned int            *ctl_table_users;
85 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
86         struct ctl_table_header *ctl_compat_table_header;
87         struct ctl_table        *ctl_compat_table;
88 #endif
89 #endif
90
91         /* Module (if any) which this is connected to. */
92         struct module *me;
93 };
94
95 /* Existing built-in protocols */
96 extern struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp6;
97 extern struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4;
98 extern struct nf_conntrack_l4proto nf_conntrack_l4proto_udp6;
99 extern struct nf_conntrack_l4proto nf_conntrack_l4proto_generic;
100
101 #define MAX_NF_CT_PROTO 256
102
103 extern struct nf_conntrack_l4proto *
104 __nf_ct_l4proto_find(u_int16_t l3proto, u_int8_t l4proto);
105
106 extern struct nf_conntrack_l4proto *
107 nf_ct_l4proto_find_get(u_int16_t l3proto, u_int8_t protocol);
108
109 extern void nf_ct_l4proto_put(struct nf_conntrack_l4proto *p);
110
111 /* Protocol registration. */
112 extern int nf_conntrack_l4proto_register(struct nf_conntrack_l4proto *proto);
113 extern void nf_conntrack_l4proto_unregister(struct nf_conntrack_l4proto *proto);
114
115 /* Generic netlink helpers */
116 extern int nf_ct_port_tuple_to_nlattr(struct sk_buff *skb,
117                                       const struct nf_conntrack_tuple *tuple);
118 extern int nf_ct_port_nlattr_to_tuple(struct nlattr *tb[],
119                                       struct nf_conntrack_tuple *t);
120 extern const struct nla_policy nf_ct_port_nla_policy[];
121
122 /* Log invalid packets */
123 extern unsigned int nf_ct_log_invalid;
124
125 #ifdef CONFIG_SYSCTL
126 #ifdef DEBUG_INVALID_PACKETS
127 #define LOG_INVALID(proto) \
128         (nf_ct_log_invalid == (proto) || nf_ct_log_invalid == IPPROTO_RAW)
129 #else
130 #define LOG_INVALID(proto) \
131         ((nf_ct_log_invalid == (proto) || nf_ct_log_invalid == IPPROTO_RAW) \
132          && net_ratelimit())
133 #endif
134 #else
135 #define LOG_INVALID(proto) 0
136 #endif /* CONFIG_SYSCTL */
137
138 #endif /*_NF_CONNTRACK_PROTOCOL_H*/