]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - include/net/netfilter/nf_conntrack_l4proto.h
netfilter: nf_tables: Support RULE_ID reference in new rule
[thirdparty/kernel/stable.git] / include / net / netfilter / nf_conntrack_l4proto.h
CommitLineData
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
18struct seq_file;
19
fd2c3ef7 20struct 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
93int 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
98int nf_conntrack_icmpv6_error(struct nf_conn *tmpl,
99 struct sk_buff *skb,
100 unsigned int dataoff,
101 const struct nf_hook_state *state);
9d2493f8 102/* Existing built-in generic protocol */
9dae47ab 103extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic;
9fb9cbb1 104
93185c80 105#define MAX_NF_CT_PROTO IPPROTO_UDPLITE
9fb9cbb1 106
dd2934a9 107const struct nf_conntrack_l4proto *__nf_ct_l4proto_find(u8 l4proto);
c1d10adb 108
dd2934a9 109const struct nf_conntrack_l4proto *nf_ct_l4proto_find_get(u8 l4proto);
2a04aabf 110void nf_ct_l4proto_put(const struct nf_conntrack_l4proto *p);
c1ebd7df 111
c296bb4d 112/* Protocol pernet registration. */
0e54d217 113int nf_ct_l4proto_pernet_register_one(struct net *net,
2a04aabf 114 const struct nf_conntrack_l4proto *proto);
0e54d217 115void nf_ct_l4proto_pernet_unregister_one(struct net *net,
2a04aabf 116 const struct nf_conntrack_l4proto *proto);
4e77be46 117int nf_ct_l4proto_pernet_register(struct net *net,
cd9ceafc 118 const struct nf_conntrack_l4proto *const proto[],
0e54d217 119 unsigned int num_proto);
4e77be46 120void nf_ct_l4proto_pernet_unregister(struct net *net,
cd9ceafc 121 const struct nf_conntrack_l4proto *const proto[],
2a04aabf 122 unsigned int num_proto);
9fb9cbb1 123
c296bb4d 124/* Protocol global registration. */
cd9ceafc 125int nf_ct_l4proto_register_one(const struct nf_conntrack_l4proto *proto);
2a04aabf 126void nf_ct_l4proto_unregister_one(const struct nf_conntrack_l4proto *proto);
c296bb4d 127
c1d10adb 128/* Generic netlink helpers */
4e77be46
JP
129int nf_ct_port_tuple_to_nlattr(struct sk_buff *skb,
130 const struct nf_conntrack_tuple *tuple);
131int nf_ct_port_nlattr_to_tuple(struct nlattr *tb[],
132 struct nf_conntrack_tuple *t);
5caaed15 133unsigned int nf_ct_port_nlattr_tuple_size(void);
f73e924c 134extern const struct nla_policy nf_ct_port_nla_policy[];
c1d10adb 135
9fb9cbb1 136#ifdef CONFIG_SYSCTL
3d0b527b
FW
137__printf(3, 4) __cold
138void nf_ct_l4proto_log_invalid(const struct sk_buff *skb,
139 const struct nf_conn *ct,
140 const char *fmt, ...);
c4f3db15
FW
141__printf(5, 6) __cold
142void nf_l4proto_log_invalid(const struct sk_buff *skb,
143 struct net *net,
144 u16 pf, u8 protonum,
145 const char *fmt, ...);
9fb9cbb1 146#else
c4f3db15
FW
147static inline __printf(5, 6) __cold
148void nf_l4proto_log_invalid(const struct sk_buff *skb, struct net *net,
149 u16 pf, u8 protonum, const char *fmt, ...) {}
3d0b527b
FW
150static inline __printf(3, 4) __cold
151void nf_ct_l4proto_log_invalid(const struct sk_buff *skb,
152 const struct nf_conn *ct,
153 const char *fmt, ...) { }
9fb9cbb1
YK
154#endif /* CONFIG_SYSCTL */
155
a95a7774
PNA
156static inline struct nf_generic_net *nf_generic_pernet(struct net *net)
157{
158 return &net->ct.nf_ct_proto.generic;
159}
160
161static inline struct nf_tcp_net *nf_tcp_pernet(struct net *net)
162{
163 return &net->ct.nf_ct_proto.tcp;
164}
165
166static inline struct nf_udp_net *nf_udp_pernet(struct net *net)
167{
168 return &net->ct.nf_ct_proto.udp;
169}
170
171static inline struct nf_icmp_net *nf_icmp_pernet(struct net *net)
172{
173 return &net->ct.nf_ct_proto.icmp;
174}
175
176static inline struct nf_icmp_net *nf_icmpv6_pernet(struct net *net)
177{
178 return &net->ct.nf_ct_proto.icmpv6;
179}
180
181#ifdef CONFIG_NF_CT_PROTO_DCCP
182static inline struct nf_dccp_net *nf_dccp_pernet(struct net *net)
183{
184 return &net->ct.nf_ct_proto.dccp;
185}
186#endif
187
188#ifdef CONFIG_NF_CT_PROTO_SCTP
189static inline struct nf_sctp_net *nf_sctp_pernet(struct net *net)
190{
191 return &net->ct.nf_ct_proto.sctp;
192}
193#endif
194
9fb9cbb1 195#endif /*_NF_CONNTRACK_PROTOCOL_H*/