]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
9fb9cbb1 | 2 | /* |
605dcad6 | 3 | * Header for use in defining a given L4 protocol for connection tracking. |
9fb9cbb1 YK |
4 | * |
5 | * 16 Dec 2003: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp> | |
6 | * - generalized L3 protocol dependent part. | |
7 | * | |
8 | * Derived from include/linux/netfiter_ipv4/ip_conntrack_protcol.h | |
9 | */ | |
10 | ||
605dcad6 MJ |
11 | #ifndef _NF_CONNTRACK_L4PROTO_H |
12 | #define _NF_CONNTRACK_L4PROTO_H | |
df6fb868 | 13 | #include <linux/netlink.h> |
f73e924c | 14 | #include <net/netlink.h> |
9fb9cbb1 | 15 | #include <net/netfilter/nf_conntrack.h> |
2c352f44 | 16 | #include <net/netns/generic.h> |
9fb9cbb1 YK |
17 | |
18 | struct seq_file; | |
19 | ||
fd2c3ef7 | 20 | struct nf_conntrack_l4proto { |
605dcad6 MJ |
21 | /* L4 Protocol number. */ |
22 | u_int8_t l4proto; | |
9fb9cbb1 | 23 | |
71d8c47f PNA |
24 | /* Resolve clashes on insertion races. */ |
25 | bool allow_clash; | |
26 | ||
39215846 FW |
27 | /* protoinfo nlattr size, closes a hole */ |
28 | u16 nlattr_size; | |
29 | ||
9fb9cbb1 YK |
30 | /* Try to fill in the third arg: dataoff is offset past network protocol |
31 | hdr. Return true if possible. */ | |
09f263cd | 32 | bool (*pkt_to_tuple)(const struct sk_buff *skb, unsigned int dataoff, |
a31f1adc | 33 | struct net *net, struct nf_conntrack_tuple *tuple); |
9fb9cbb1 YK |
34 | |
35 | /* Invert the per-proto part of the tuple: ie. turn xmit into reply. | |
8b3892ea | 36 | * Only used by icmp, most protocols use a generic version. |
9fb9cbb1 | 37 | */ |
09f263cd JE |
38 | bool (*invert_tuple)(struct nf_conntrack_tuple *inverse, |
39 | const struct nf_conntrack_tuple *orig); | |
9fb9cbb1 | 40 | |
9fb9cbb1 | 41 | /* Returns verdict for packet, or -1 for invalid. */ |
c88130bc | 42 | int (*packet)(struct nf_conn *ct, |
83d213fd | 43 | struct sk_buff *skb, |
9fb9cbb1 | 44 | unsigned int dataoff, |
93e66024 FW |
45 | enum ip_conntrack_info ctinfo, |
46 | const struct nf_hook_state *state); | |
9fb9cbb1 | 47 | |
9fb9cbb1 | 48 | /* Called when a conntrack entry is destroyed */ |
c88130bc | 49 | void (*destroy)(struct nf_conn *ct); |
9fb9cbb1 | 50 | |
c6dd940b FW |
51 | /* called by gc worker if table is full */ |
52 | bool (*can_early_drop)(const struct nf_conn *ct); | |
53 | ||
c1d10adb | 54 | /* convert protoinfo to nfnetink attributes */ |
fdf70832 | 55 | int (*to_nlattr)(struct sk_buff *skb, struct nlattr *nla, |
440f0d58 | 56 | struct nf_conn *ct); |
c1d10adb PNA |
57 | |
58 | /* convert nfnetlink attributes to protoinfo */ | |
fdf70832 | 59 | int (*from_nlattr)(struct nlattr *tb[], struct nf_conn *ct); |
c1d10adb | 60 | |
fdf70832 | 61 | int (*tuple_to_nlattr)(struct sk_buff *skb, |
c1d10adb | 62 | const struct nf_conntrack_tuple *t); |
d0dba725 | 63 | /* Calculate tuple nlattr size */ |
5caaed15 | 64 | unsigned int (*nlattr_tuple_size)(void); |
fdf70832 | 65 | int (*nlattr_to_tuple)(struct nlattr *tb[], |
c1d10adb | 66 | struct nf_conntrack_tuple *t); |
f73e924c | 67 | const struct nla_policy *nla_policy; |
c1d10adb | 68 | |
50978462 | 69 | struct { |
8264deb8 G |
70 | int (*nlattr_to_obj)(struct nlattr *tb[], |
71 | struct net *net, void *data); | |
50978462 PNA |
72 | int (*obj_to_nlattr)(struct sk_buff *skb, const void *data); |
73 | ||
036c6940 FW |
74 | u16 obj_size; |
75 | u16 nlattr_max; | |
50978462 PNA |
76 | const struct nla_policy *nla_policy; |
77 | } ctnl_timeout; | |
ea48cc83 FW |
78 | #ifdef CONFIG_NF_CONNTRACK_PROCFS |
79 | /* Print out the private part of the conntrack. */ | |
80 | void (*print_conntrack)(struct seq_file *s, struct nf_conn *); | |
a999e683 | 81 | #endif |
c7d03a00 | 82 | unsigned int *net_id; |
2c352f44 | 83 | /* Init l4proto pernet data */ |
ca2ca6e1 | 84 | int (*init_net)(struct net *net); |
2c352f44 | 85 | |
08911475 PNA |
86 | /* Return the per-net protocol part. */ |
87 | struct nf_proto_net *(*get_net_proto)(struct net *net); | |
88 | ||
9fb9cbb1 YK |
89 | /* Module (if any) which this is connected to. */ |
90 | struct module *me; | |
91 | }; | |
92 | ||
6fe78fa4 FW |
93 | int nf_conntrack_icmpv4_error(struct nf_conn *tmpl, |
94 | struct sk_buff *skb, | |
95 | unsigned int dataoff, | |
96 | const struct nf_hook_state *state); | |
97 | ||
98 | int nf_conntrack_icmpv6_error(struct nf_conn *tmpl, | |
99 | struct sk_buff *skb, | |
100 | unsigned int dataoff, | |
101 | const struct nf_hook_state *state); | |
a47c5404 FW |
102 | |
103 | int nf_conntrack_icmp_packet(struct nf_conn *ct, | |
104 | struct sk_buff *skb, | |
105 | enum ip_conntrack_info ctinfo, | |
106 | const struct nf_hook_state *state); | |
107 | ||
108 | int nf_conntrack_icmpv6_packet(struct nf_conn *ct, | |
109 | struct sk_buff *skb, | |
110 | enum ip_conntrack_info ctinfo, | |
111 | const struct nf_hook_state *state); | |
112 | ||
113 | int nf_conntrack_udp_packet(struct nf_conn *ct, | |
114 | struct sk_buff *skb, | |
115 | unsigned int dataoff, | |
116 | enum ip_conntrack_info ctinfo, | |
117 | const struct nf_hook_state *state); | |
118 | int nf_conntrack_udplite_packet(struct nf_conn *ct, | |
119 | struct sk_buff *skb, | |
120 | unsigned int dataoff, | |
121 | enum ip_conntrack_info ctinfo, | |
122 | const struct nf_hook_state *state); | |
123 | int nf_conntrack_tcp_packet(struct nf_conn *ct, | |
124 | struct sk_buff *skb, | |
125 | unsigned int dataoff, | |
126 | enum ip_conntrack_info ctinfo, | |
127 | const struct nf_hook_state *state); | |
128 | int nf_conntrack_dccp_packet(struct nf_conn *ct, | |
129 | struct sk_buff *skb, | |
130 | unsigned int dataoff, | |
131 | enum ip_conntrack_info ctinfo, | |
132 | const struct nf_hook_state *state); | |
133 | int nf_conntrack_sctp_packet(struct nf_conn *ct, | |
134 | struct sk_buff *skb, | |
135 | unsigned int dataoff, | |
136 | enum ip_conntrack_info ctinfo, | |
137 | const struct nf_hook_state *state); | |
138 | ||
9d2493f8 | 139 | /* Existing built-in generic protocol */ |
9dae47ab | 140 | extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic; |
9fb9cbb1 | 141 | |
93185c80 | 142 | #define MAX_NF_CT_PROTO IPPROTO_UDPLITE |
9fb9cbb1 | 143 | |
dd2934a9 | 144 | const struct nf_conntrack_l4proto *__nf_ct_l4proto_find(u8 l4proto); |
c1d10adb | 145 | |
dd2934a9 | 146 | const struct nf_conntrack_l4proto *nf_ct_l4proto_find_get(u8 l4proto); |
2a04aabf | 147 | void nf_ct_l4proto_put(const struct nf_conntrack_l4proto *p); |
c1ebd7df | 148 | |
c296bb4d | 149 | /* Protocol pernet registration. */ |
0e54d217 | 150 | int nf_ct_l4proto_pernet_register_one(struct net *net, |
2a04aabf | 151 | const struct nf_conntrack_l4proto *proto); |
0e54d217 | 152 | void nf_ct_l4proto_pernet_unregister_one(struct net *net, |
2a04aabf | 153 | const struct nf_conntrack_l4proto *proto); |
4e77be46 | 154 | int nf_ct_l4proto_pernet_register(struct net *net, |
cd9ceafc | 155 | const struct nf_conntrack_l4proto *const proto[], |
0e54d217 | 156 | unsigned int num_proto); |
4e77be46 | 157 | void nf_ct_l4proto_pernet_unregister(struct net *net, |
cd9ceafc | 158 | const struct nf_conntrack_l4proto *const proto[], |
2a04aabf | 159 | unsigned int num_proto); |
9fb9cbb1 | 160 | |
c296bb4d | 161 | /* Protocol global registration. */ |
cd9ceafc | 162 | int nf_ct_l4proto_register_one(const struct nf_conntrack_l4proto *proto); |
2a04aabf | 163 | void nf_ct_l4proto_unregister_one(const struct nf_conntrack_l4proto *proto); |
c296bb4d | 164 | |
c1d10adb | 165 | /* Generic netlink helpers */ |
4e77be46 JP |
166 | int nf_ct_port_tuple_to_nlattr(struct sk_buff *skb, |
167 | const struct nf_conntrack_tuple *tuple); | |
168 | int nf_ct_port_nlattr_to_tuple(struct nlattr *tb[], | |
169 | struct nf_conntrack_tuple *t); | |
5caaed15 | 170 | unsigned int nf_ct_port_nlattr_tuple_size(void); |
f73e924c | 171 | extern const struct nla_policy nf_ct_port_nla_policy[]; |
c1d10adb | 172 | |
9fb9cbb1 | 173 | #ifdef CONFIG_SYSCTL |
3d0b527b FW |
174 | __printf(3, 4) __cold |
175 | void nf_ct_l4proto_log_invalid(const struct sk_buff *skb, | |
176 | const struct nf_conn *ct, | |
177 | const char *fmt, ...); | |
c4f3db15 FW |
178 | __printf(5, 6) __cold |
179 | void nf_l4proto_log_invalid(const struct sk_buff *skb, | |
180 | struct net *net, | |
181 | u16 pf, u8 protonum, | |
182 | const char *fmt, ...); | |
9fb9cbb1 | 183 | #else |
c4f3db15 FW |
184 | static inline __printf(5, 6) __cold |
185 | void nf_l4proto_log_invalid(const struct sk_buff *skb, struct net *net, | |
186 | u16 pf, u8 protonum, const char *fmt, ...) {} | |
3d0b527b FW |
187 | static inline __printf(3, 4) __cold |
188 | void nf_ct_l4proto_log_invalid(const struct sk_buff *skb, | |
189 | const struct nf_conn *ct, | |
190 | const char *fmt, ...) { } | |
9fb9cbb1 YK |
191 | #endif /* CONFIG_SYSCTL */ |
192 | ||
a95a7774 PNA |
193 | static inline struct nf_generic_net *nf_generic_pernet(struct net *net) |
194 | { | |
195 | return &net->ct.nf_ct_proto.generic; | |
196 | } | |
197 | ||
198 | static inline struct nf_tcp_net *nf_tcp_pernet(struct net *net) | |
199 | { | |
200 | return &net->ct.nf_ct_proto.tcp; | |
201 | } | |
202 | ||
203 | static inline struct nf_udp_net *nf_udp_pernet(struct net *net) | |
204 | { | |
205 | return &net->ct.nf_ct_proto.udp; | |
206 | } | |
207 | ||
208 | static inline struct nf_icmp_net *nf_icmp_pernet(struct net *net) | |
209 | { | |
210 | return &net->ct.nf_ct_proto.icmp; | |
211 | } | |
212 | ||
213 | static inline struct nf_icmp_net *nf_icmpv6_pernet(struct net *net) | |
214 | { | |
215 | return &net->ct.nf_ct_proto.icmpv6; | |
216 | } | |
217 | ||
218 | #ifdef CONFIG_NF_CT_PROTO_DCCP | |
219 | static inline struct nf_dccp_net *nf_dccp_pernet(struct net *net) | |
220 | { | |
221 | return &net->ct.nf_ct_proto.dccp; | |
222 | } | |
223 | #endif | |
224 | ||
225 | #ifdef CONFIG_NF_CT_PROTO_SCTP | |
226 | static inline struct nf_sctp_net *nf_sctp_pernet(struct net *net) | |
227 | { | |
228 | return &net->ct.nf_ct_proto.sctp; | |
229 | } | |
230 | #endif | |
231 | ||
9fb9cbb1 | 232 | #endif /*_NF_CONNTRACK_PROTOCOL_H*/ |