Jozsef Kadlecsik | 5b1158e | 2006-12-02 22:07:13 -0800 | [diff] [blame] | 1 | /* 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 | |
| 7 | struct nf_nat_range; |
| 8 | |
Eric Dumazet | fd2c3ef | 2009-11-03 03:26:03 +0000 | [diff] [blame] | 9 | struct nf_nat_protocol { |
Jozsef Kadlecsik | 5b1158e | 2006-12-02 22:07:13 -0800 | [diff] [blame] | 10 | /* 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 Engelhardt | f2ea825 | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 17 | 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 Kadlecsik | 5b1158e | 2006-12-02 22:07:13 -0800 | [diff] [blame] | 21 | |
| 22 | /* Is the manipable part of the tuple between min and max incl? */ |
Jan Engelhardt | f2ea825 | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 23 | 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 Kadlecsik | 5b1158e | 2006-12-02 22:07:13 -0800 | [diff] [blame] | 27 | |
| 28 | /* Alter the per-proto part of the tuple (depending on |
| 29 | maniptype), to give a unique tuple in the given range if |
Changli Gao | f43dc98 | 2010-08-02 17:20:54 +0200 | [diff] [blame] | 30 | possible. Per-protocol part of tuple is initialized to the |
| 31 | incoming packet. */ |
| 32 | void (*unique_tuple)(struct nf_conntrack_tuple *tuple, |
Jan Engelhardt | f2ea825 | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 33 | const struct nf_nat_range *range, |
| 34 | enum nf_nat_manip_type maniptype, |
| 35 | const struct nf_conn *ct); |
Jozsef Kadlecsik | 5b1158e | 2006-12-02 22:07:13 -0800 | [diff] [blame] | 36 | |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 37 | int (*range_to_nlattr)(struct sk_buff *skb, |
Jozsef Kadlecsik | 5b1158e | 2006-12-02 22:07:13 -0800 | [diff] [blame] | 38 | const struct nf_nat_range *range); |
| 39 | |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 40 | int (*nlattr_to_range)(struct nlattr *tb[], |
Jozsef Kadlecsik | 5b1158e | 2006-12-02 22:07:13 -0800 | [diff] [blame] | 41 | struct nf_nat_range *range); |
| 42 | }; |
| 43 | |
| 44 | /* Protocol registration. */ |
Patrick McHardy | 2b628a0 | 2007-12-17 22:37:36 -0800 | [diff] [blame] | 45 | extern int nf_nat_protocol_register(const struct nf_nat_protocol *proto); |
| 46 | extern void nf_nat_protocol_unregister(const struct nf_nat_protocol *proto); |
Jozsef Kadlecsik | 5b1158e | 2006-12-02 22:07:13 -0800 | [diff] [blame] | 47 | |
Jozsef Kadlecsik | 5b1158e | 2006-12-02 22:07:13 -0800 | [diff] [blame] | 48 | /* Built-in protocols. */ |
Patrick McHardy | 2b628a0 | 2007-12-17 22:37:36 -0800 | [diff] [blame] | 49 | extern const struct nf_nat_protocol nf_nat_protocol_tcp; |
| 50 | extern const struct nf_nat_protocol nf_nat_protocol_udp; |
| 51 | extern const struct nf_nat_protocol nf_nat_protocol_icmp; |
| 52 | extern const struct nf_nat_protocol nf_nat_unknown_protocol; |
Jozsef Kadlecsik | 5b1158e | 2006-12-02 22:07:13 -0800 | [diff] [blame] | 53 | |
| 54 | extern int init_protocols(void) __init; |
| 55 | extern void cleanup_protocols(void); |
Patrick McHardy | 2b628a0 | 2007-12-17 22:37:36 -0800 | [diff] [blame] | 56 | extern const struct nf_nat_protocol *find_nat_proto(u_int16_t protonum); |
Jozsef Kadlecsik | 5b1158e | 2006-12-02 22:07:13 -0800 | [diff] [blame] | 57 | |
Jan Engelhardt | f2ea825 | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 58 | extern 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 McHardy | 937e0df | 2008-03-20 15:15:47 +0100 | [diff] [blame] | 62 | |
Changli Gao | f43dc98 | 2010-08-02 17:20:54 +0200 | [diff] [blame] | 63 | extern void nf_nat_proto_unique_tuple(struct nf_conntrack_tuple *tuple, |
Jan Engelhardt | f2ea825 | 2008-04-14 11:15:53 +0200 | [diff] [blame] | 64 | 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 McHardy | 937e0df | 2008-03-20 15:15:47 +0100 | [diff] [blame] | 68 | |
Patrick McHardy | 535b57c | 2008-04-14 11:15:47 +0200 | [diff] [blame] | 69 | extern int nf_nat_proto_range_to_nlattr(struct sk_buff *skb, |
| 70 | const struct nf_nat_range *range); |
| 71 | extern int nf_nat_proto_nlattr_to_range(struct nlattr *tb[], |
| 72 | struct nf_nat_range *range); |
Jozsef Kadlecsik | 5b1158e | 2006-12-02 22:07:13 -0800 | [diff] [blame] | 73 | |
| 74 | #endif /*_NF_NAT_PROTO_H*/ |