blob: 93cc90d28e66e31047f7219e2c4a1cbd8ce6774c [file] [log] [blame]
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -08001/* Header for use in defining a given protocol. */
2#ifndef _NF_NAT_PROTOCOL_H
3#define _NF_NAT_PROTOCOL_H
4#include <net/netfilter/nf_nat.h>
5#include <linux/netfilter/nfnetlink_conntrack.h>
6
7struct nf_nat_range;
8
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +00009struct nf_nat_protocol {
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080010 /* Protocol number. */
11 unsigned int protonum;
12
13 struct module *me;
14
15 /* Translate a packet to the target according to manip type.
16 Return true if succeeded. */
Jan Engelhardtf2ea8252008-04-14 11:15:53 +020017 bool (*manip_pkt)(struct sk_buff *skb,
18 unsigned int iphdroff,
19 const struct nf_conntrack_tuple *tuple,
20 enum nf_nat_manip_type maniptype);
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080021
22 /* Is the manipable part of the tuple between min and max incl? */
Jan Engelhardtf2ea8252008-04-14 11:15:53 +020023 bool (*in_range)(const struct nf_conntrack_tuple *tuple,
24 enum nf_nat_manip_type maniptype,
25 const union nf_conntrack_man_proto *min,
26 const union nf_conntrack_man_proto *max);
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080027
28 /* Alter the per-proto part of the tuple (depending on
29 maniptype), to give a unique tuple in the given range if
Changli Gaof43dc982010-08-02 17:20:54 +020030 possible. Per-protocol part of tuple is initialized to the
31 incoming packet. */
32 void (*unique_tuple)(struct nf_conntrack_tuple *tuple,
Jan Engelhardtf2ea8252008-04-14 11:15:53 +020033 const struct nf_nat_range *range,
34 enum nf_nat_manip_type maniptype,
35 const struct nf_conn *ct);
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080036
Patrick McHardyfdf70832007-09-28 14:37:41 -070037 int (*range_to_nlattr)(struct sk_buff *skb,
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080038 const struct nf_nat_range *range);
39
Patrick McHardyfdf70832007-09-28 14:37:41 -070040 int (*nlattr_to_range)(struct nlattr *tb[],
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080041 struct nf_nat_range *range);
42};
43
44/* Protocol registration. */
Patrick McHardy2b628a02007-12-17 22:37:36 -080045extern int nf_nat_protocol_register(const struct nf_nat_protocol *proto);
46extern void nf_nat_protocol_unregister(const struct nf_nat_protocol *proto);
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080047
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080048/* Built-in protocols. */
Patrick McHardy2b628a02007-12-17 22:37:36 -080049extern const struct nf_nat_protocol nf_nat_protocol_tcp;
50extern const struct nf_nat_protocol nf_nat_protocol_udp;
51extern const struct nf_nat_protocol nf_nat_protocol_icmp;
52extern const struct nf_nat_protocol nf_nat_unknown_protocol;
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080053
54extern int init_protocols(void) __init;
55extern void cleanup_protocols(void);
Patrick McHardy2b628a02007-12-17 22:37:36 -080056extern const struct nf_nat_protocol *find_nat_proto(u_int16_t protonum);
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080057
Jan Engelhardtf2ea8252008-04-14 11:15:53 +020058extern bool nf_nat_proto_in_range(const struct nf_conntrack_tuple *tuple,
59 enum nf_nat_manip_type maniptype,
60 const union nf_conntrack_man_proto *min,
61 const union nf_conntrack_man_proto *max);
Patrick McHardy937e0df2008-03-20 15:15:47 +010062
Changli Gaof43dc982010-08-02 17:20:54 +020063extern void nf_nat_proto_unique_tuple(struct nf_conntrack_tuple *tuple,
Jan Engelhardtf2ea8252008-04-14 11:15:53 +020064 const struct nf_nat_range *range,
65 enum nf_nat_manip_type maniptype,
66 const struct nf_conn *ct,
67 u_int16_t *rover);
Patrick McHardy937e0df2008-03-20 15:15:47 +010068
Patrick McHardy535b57c2008-04-14 11:15:47 +020069extern int nf_nat_proto_range_to_nlattr(struct sk_buff *skb,
70 const struct nf_nat_range *range);
71extern int nf_nat_proto_nlattr_to_range(struct nlattr *tb[],
72 struct nf_nat_range *range);
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080073
74#endif /*_NF_NAT_PROTO_H*/