1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Header for use in defining a given L4 protocol for connection tracking.
5 * 16 Dec 2003: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
6 * - generalized L3 protocol dependent part.
8 * Derived from include/linux/netfiter_ipv4/ip_conntrack_protcol.h
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>
20 struct nf_conntrack_l4proto {
21 /* L4 Protocol number. */
24 /* Resolve clashes on insertion races. */
27 /* protoinfo nlattr size, closes a hole */
30 /* Try to fill in the third arg: dataoff is offset past network protocol
31 hdr. Return true if possible. */
32 bool (*pkt_to_tuple)(const struct sk_buff *skb, unsigned int dataoff,
33 struct net *net, struct nf_conntrack_tuple *tuple);
35 /* Invert the per-proto part of the tuple: ie. turn xmit into reply.
36 * Only used by icmp, most protocols use a generic version.
38 bool (*invert_tuple)(struct nf_conntrack_tuple *inverse,
39 const struct nf_conntrack_tuple *orig);
41 /* Returns verdict for packet, or -1 for invalid. */
42 int (*packet)(struct nf_conn *ct,
45 enum ip_conntrack_info ctinfo,
46 const struct nf_hook_state *state);
48 /* Called when a conntrack entry is destroyed */
49 void (*destroy)(struct nf_conn *ct);
51 /* called by gc worker if table is full */
52 bool (*can_early_drop)(const struct nf_conn *ct);
54 /* convert protoinfo to nfnetink attributes */
55 int (*to_nlattr)(struct sk_buff *skb, struct nlattr *nla,
58 /* convert nfnetlink attributes to protoinfo */
59 int (*from_nlattr)(struct nlattr *tb[], struct nf_conn *ct);
61 int (*tuple_to_nlattr)(struct sk_buff *skb,
62 const struct nf_conntrack_tuple *t);
63 /* Calculate tuple nlattr size */
64 unsigned int (*nlattr_tuple_size)(void);
65 int (*nlattr_to_tuple)(struct nlattr *tb[],
66 struct nf_conntrack_tuple *t);
67 const struct nla_policy *nla_policy;
70 int (*nlattr_to_obj)(struct nlattr *tb[],
71 struct net *net, void *data);
72 int (*obj_to_nlattr)(struct sk_buff *skb, const void *data);
76 const struct nla_policy *nla_policy;
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 *);
83 /* Init l4proto pernet data */
84 int (*init_net)(struct net *net);
86 /* Return the per-net protocol part. */
87 struct nf_proto_net *(*get_net_proto)(struct net *net);
89 /* Module (if any) which this is connected to. */
93 int nf_conntrack_icmpv4_error(struct nf_conn *tmpl,
96 const struct nf_hook_state *state);
98 int nf_conntrack_icmpv6_error(struct nf_conn *tmpl,
100 unsigned int dataoff,
101 const struct nf_hook_state *state);
102 /* Existing built-in generic protocol */
103 extern const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic;
105 #define MAX_NF_CT_PROTO IPPROTO_UDPLITE
107 const struct nf_conntrack_l4proto *__nf_ct_l4proto_find(u8 l4proto);
109 const struct nf_conntrack_l4proto *nf_ct_l4proto_find_get(u8 l4proto);
110 void nf_ct_l4proto_put(const struct nf_conntrack_l4proto *p);
112 /* Protocol pernet registration. */
113 int nf_ct_l4proto_pernet_register_one(struct net *net,
114 const struct nf_conntrack_l4proto *proto);
115 void nf_ct_l4proto_pernet_unregister_one(struct net *net,
116 const struct nf_conntrack_l4proto *proto);
117 int nf_ct_l4proto_pernet_register(struct net *net,
118 const struct nf_conntrack_l4proto *const proto[],
119 unsigned int num_proto);
120 void nf_ct_l4proto_pernet_unregister(struct net *net,
121 const struct nf_conntrack_l4proto *const proto[],
122 unsigned int num_proto);
124 /* Protocol global registration. */
125 int nf_ct_l4proto_register_one(const struct nf_conntrack_l4proto *proto);
126 void nf_ct_l4proto_unregister_one(const struct nf_conntrack_l4proto *proto);
128 /* Generic netlink helpers */
129 int nf_ct_port_tuple_to_nlattr(struct sk_buff *skb,
130 const struct nf_conntrack_tuple *tuple);
131 int nf_ct_port_nlattr_to_tuple(struct nlattr *tb[],
132 struct nf_conntrack_tuple *t);
133 unsigned int nf_ct_port_nlattr_tuple_size(void);
134 extern const struct nla_policy nf_ct_port_nla_policy[];
137 __printf(3, 4) __cold
138 void nf_ct_l4proto_log_invalid(const struct sk_buff *skb,
139 const struct nf_conn *ct,
140 const char *fmt, ...);
141 __printf(5, 6) __cold
142 void nf_l4proto_log_invalid(const struct sk_buff *skb,
145 const char *fmt, ...);
147 static inline __printf(5, 6) __cold
148 void nf_l4proto_log_invalid(const struct sk_buff *skb, struct net *net,
149 u16 pf, u8 protonum, const char *fmt, ...) {}
150 static inline __printf(3, 4) __cold
151 void nf_ct_l4proto_log_invalid(const struct sk_buff *skb,
152 const struct nf_conn *ct,
153 const char *fmt, ...) { }
154 #endif /* CONFIG_SYSCTL */
156 #endif /*_NF_CONNTRACK_PROTOCOL_H*/