ACPI / scan: Add labels for PNP button devices
[sfrench/cifs-2.6.git] / include / net / netfilter / nf_conntrack_l4proto.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Header for use in defining a given L4 protocol for connection tracking.
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
11 #ifndef _NF_CONNTRACK_L4PROTO_H
12 #define _NF_CONNTRACK_L4PROTO_H
13 #include <linux/netlink.h>
14 #include <net/netlink.h>
15 #include <net/netfilter/nf_conntrack.h>
16 #include <net/netns/generic.h>
17
18 struct seq_file;
19
20 struct nf_conntrack_l4proto {
21         /* L4 Protocol number. */
22         u_int8_t l4proto;
23
24         /* Resolve clashes on insertion races. */
25         bool allow_clash;
26
27         /* protoinfo nlattr size, closes a hole */
28         u16 nlattr_size;
29
30         /* called by gc worker if table is full */
31         bool (*can_early_drop)(const struct nf_conn *ct);
32
33         /* convert protoinfo to nfnetink attributes */
34         int (*to_nlattr)(struct sk_buff *skb, struct nlattr *nla,
35                          struct nf_conn *ct);
36
37         /* convert nfnetlink attributes to protoinfo */
38         int (*from_nlattr)(struct nlattr *tb[], struct nf_conn *ct);
39
40         int (*tuple_to_nlattr)(struct sk_buff *skb,
41                                const struct nf_conntrack_tuple *t);
42         /* Calculate tuple nlattr size */
43         unsigned int (*nlattr_tuple_size)(void);
44         int (*nlattr_to_tuple)(struct nlattr *tb[],
45                                struct nf_conntrack_tuple *t);
46         const struct nla_policy *nla_policy;
47
48         struct {
49                 int (*nlattr_to_obj)(struct nlattr *tb[],
50                                      struct net *net, void *data);
51                 int (*obj_to_nlattr)(struct sk_buff *skb, const void *data);
52
53                 u16 obj_size;
54                 u16 nlattr_max;
55                 const struct nla_policy *nla_policy;
56         } ctnl_timeout;
57 #ifdef CONFIG_NF_CONNTRACK_PROCFS
58         /* Print out the private part of the conntrack. */
59         void (*print_conntrack)(struct seq_file *s, struct nf_conn *);
60 #endif
61 };
62
63 bool icmp_pkt_to_tuple(const struct sk_buff *skb,
64                        unsigned int dataoff,
65                        struct net *net,
66                        struct nf_conntrack_tuple *tuple);
67
68 bool icmpv6_pkt_to_tuple(const struct sk_buff *skb,
69                          unsigned int dataoff,
70                          struct net *net,
71                          struct nf_conntrack_tuple *tuple);
72
73 bool nf_conntrack_invert_icmp_tuple(struct nf_conntrack_tuple *tuple,
74                                     const struct nf_conntrack_tuple *orig);
75 bool nf_conntrack_invert_icmpv6_tuple(struct nf_conntrack_tuple *tuple,
76                                       const struct nf_conntrack_tuple *orig);
77
78 int nf_conntrack_icmpv4_error(struct nf_conn *tmpl,
79                               struct sk_buff *skb,
80                               unsigned int dataoff,
81                               const struct nf_hook_state *state);
82
83 int nf_conntrack_icmpv6_error(struct nf_conn *tmpl,
84                               struct sk_buff *skb,
85                               unsigned int dataoff,
86                               const struct nf_hook_state *state);
87
88 int nf_conntrack_icmp_packet(struct nf_conn *ct,
89                              struct sk_buff *skb,
90                              enum ip_conntrack_info ctinfo,
91                              const struct nf_hook_state *state);
92
93 int nf_conntrack_icmpv6_packet(struct nf_conn *ct,
94                                struct sk_buff *skb,
95                                enum ip_conntrack_info ctinfo,
96                                const struct nf_hook_state *state);
97
98 int nf_conntrack_udp_packet(struct nf_conn *ct,
99                             struct sk_buff *skb,
100                             unsigned int dataoff,
101                             enum ip_conntrack_info ctinfo,
102                             const struct nf_hook_state *state);
103 int nf_conntrack_udplite_packet(struct nf_conn *ct,
104                                 struct sk_buff *skb,
105                                 unsigned int dataoff,
106                                 enum ip_conntrack_info ctinfo,
107                                 const struct nf_hook_state *state);
108 int nf_conntrack_tcp_packet(struct nf_conn *ct,
109                             struct sk_buff *skb,
110                             unsigned int dataoff,
111                             enum ip_conntrack_info ctinfo,
112                             const struct nf_hook_state *state);
113 int nf_conntrack_dccp_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_sctp_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_gre_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
129 void nf_conntrack_generic_init_net(struct net *net);
130 void nf_conntrack_tcp_init_net(struct net *net);
131 void nf_conntrack_udp_init_net(struct net *net);
132 void nf_conntrack_gre_init_net(struct net *net);
133 void nf_conntrack_dccp_init_net(struct net *net);
134 void nf_conntrack_sctp_init_net(struct net *net);
135 void nf_conntrack_icmp_init_net(struct net *net);
136 void nf_conntrack_icmpv6_init_net(struct net *net);
137
138 /* Existing built-in generic protocol */
139 extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic;
140
141 #define MAX_NF_CT_PROTO IPPROTO_UDPLITE
142
143 const struct nf_conntrack_l4proto *nf_ct_l4proto_find(u8 l4proto);
144
145 /* Generic netlink helpers */
146 int nf_ct_port_tuple_to_nlattr(struct sk_buff *skb,
147                                const struct nf_conntrack_tuple *tuple);
148 int nf_ct_port_nlattr_to_tuple(struct nlattr *tb[],
149                                struct nf_conntrack_tuple *t);
150 unsigned int nf_ct_port_nlattr_tuple_size(void);
151 extern const struct nla_policy nf_ct_port_nla_policy[];
152
153 #ifdef CONFIG_SYSCTL
154 __printf(3, 4) __cold
155 void nf_ct_l4proto_log_invalid(const struct sk_buff *skb,
156                                const struct nf_conn *ct,
157                                const char *fmt, ...);
158 __printf(5, 6) __cold
159 void nf_l4proto_log_invalid(const struct sk_buff *skb,
160                             struct net *net,
161                             u16 pf, u8 protonum,
162                             const char *fmt, ...);
163 #else
164 static inline __printf(5, 6) __cold
165 void nf_l4proto_log_invalid(const struct sk_buff *skb, struct net *net,
166                             u16 pf, u8 protonum, const char *fmt, ...) {}
167 static inline __printf(3, 4) __cold
168 void nf_ct_l4proto_log_invalid(const struct sk_buff *skb,
169                                const struct nf_conn *ct,
170                                const char *fmt, ...) { }
171 #endif /* CONFIG_SYSCTL */
172
173 static inline struct nf_generic_net *nf_generic_pernet(struct net *net)
174 {
175        return &net->ct.nf_ct_proto.generic;
176 }
177
178 static inline struct nf_tcp_net *nf_tcp_pernet(struct net *net)
179 {
180        return &net->ct.nf_ct_proto.tcp;
181 }
182
183 static inline struct nf_udp_net *nf_udp_pernet(struct net *net)
184 {
185        return &net->ct.nf_ct_proto.udp;
186 }
187
188 static inline struct nf_icmp_net *nf_icmp_pernet(struct net *net)
189 {
190        return &net->ct.nf_ct_proto.icmp;
191 }
192
193 static inline struct nf_icmp_net *nf_icmpv6_pernet(struct net *net)
194 {
195        return &net->ct.nf_ct_proto.icmpv6;
196 }
197
198 #ifdef CONFIG_NF_CT_PROTO_DCCP
199 static inline struct nf_dccp_net *nf_dccp_pernet(struct net *net)
200 {
201        return &net->ct.nf_ct_proto.dccp;
202 }
203 #endif
204
205 #ifdef CONFIG_NF_CT_PROTO_SCTP
206 static inline struct nf_sctp_net *nf_sctp_pernet(struct net *net)
207 {
208        return &net->ct.nf_ct_proto.sctp;
209 }
210 #endif
211
212 #ifdef CONFIG_NF_CT_PROTO_GRE
213 static inline struct nf_gre_net *nf_gre_pernet(struct net *net)
214 {
215         return &net->ct.nf_ct_proto.gre;
216 }
217 #endif
218
219 #endif /*_NF_CONNTRACK_PROTOCOL_H*/