1 /* SPDX-License-Identifier: GPL-2.0 */
2 /* Header for use in defining a given protocol. */
3 #ifndef _NF_NAT_L4PROTO_H
4 #define _NF_NAT_L4PROTO_H
5 #include <net/netfilter/nf_nat.h>
6 #include <linux/netfilter/nfnetlink_conntrack.h>
11 struct nf_nat_l4proto
{
12 /* Protocol number. */
15 /* Translate a packet to the target according to manip type.
16 * Return true if succeeded.
18 bool (*manip_pkt
)(struct sk_buff
*skb
,
19 const struct nf_nat_l3proto
*l3proto
,
20 unsigned int iphdroff
, unsigned int hdroff
,
21 const struct nf_conntrack_tuple
*tuple
,
22 enum nf_nat_manip_type maniptype
);
24 /* Is the manipable part of the tuple between min and max incl? */
25 bool (*in_range
)(const struct nf_conntrack_tuple
*tuple
,
26 enum nf_nat_manip_type maniptype
,
27 const union nf_conntrack_man_proto
*min
,
28 const union nf_conntrack_man_proto
*max
);
30 /* Alter the per-proto part of the tuple (depending on
31 * maniptype), to give a unique tuple in the given range if
32 * possible. Per-protocol part of tuple is initialized to the
35 void (*unique_tuple
)(const struct nf_nat_l3proto
*l3proto
,
36 struct nf_conntrack_tuple
*tuple
,
37 const struct nf_nat_range
*range
,
38 enum nf_nat_manip_type maniptype
,
39 const struct nf_conn
*ct
);
41 int (*nlattr_to_range
)(struct nlattr
*tb
[],
42 struct nf_nat_range
*range
);
45 /* Protocol registration. */
46 int nf_nat_l4proto_register(u8 l3proto
, const struct nf_nat_l4proto
*l4proto
);
47 void nf_nat_l4proto_unregister(u8 l3proto
,
48 const struct nf_nat_l4proto
*l4proto
);
50 const struct nf_nat_l4proto
*__nf_nat_l4proto_find(u8 l3proto
, u8 l4proto
);
52 /* Built-in protocols. */
53 extern const struct nf_nat_l4proto nf_nat_l4proto_tcp
;
54 extern const struct nf_nat_l4proto nf_nat_l4proto_udp
;
55 extern const struct nf_nat_l4proto nf_nat_l4proto_icmp
;
56 extern const struct nf_nat_l4proto nf_nat_l4proto_icmpv6
;
57 extern const struct nf_nat_l4proto nf_nat_l4proto_unknown
;
58 #ifdef CONFIG_NF_NAT_PROTO_DCCP
59 extern const struct nf_nat_l4proto nf_nat_l4proto_dccp
;
61 #ifdef CONFIG_NF_NAT_PROTO_SCTP
62 extern const struct nf_nat_l4proto nf_nat_l4proto_sctp
;
64 #ifdef CONFIG_NF_NAT_PROTO_UDPLITE
65 extern const struct nf_nat_l4proto nf_nat_l4proto_udplite
;
68 bool nf_nat_l4proto_in_range(const struct nf_conntrack_tuple
*tuple
,
69 enum nf_nat_manip_type maniptype
,
70 const union nf_conntrack_man_proto
*min
,
71 const union nf_conntrack_man_proto
*max
);
73 void nf_nat_l4proto_unique_tuple(const struct nf_nat_l3proto
*l3proto
,
74 struct nf_conntrack_tuple
*tuple
,
75 const struct nf_nat_range
*range
,
76 enum nf_nat_manip_type maniptype
,
77 const struct nf_conn
*ct
, u16
*rover
);
79 int nf_nat_l4proto_nlattr_to_range(struct nlattr
*tb
[],
80 struct nf_nat_range
*range
);
82 #endif /*_NF_NAT_L4PROTO_H*/