blob: de629f1520df2d476f74acab98ba08cbadd03a92 [file] [log] [blame]
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -08001/*
Martin Josefsson605dcad2006-11-29 02:35:06 +01002 * Header for use in defining a given L4 protocol for connection tracking.
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -08003 *
4 * 16 Dec 2003: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
5 * - generalized L3 protocol dependent part.
6 *
7 * Derived from include/linux/netfiter_ipv4/ip_conntrack_protcol.h
8 */
9
Martin Josefsson605dcad2006-11-29 02:35:06 +010010#ifndef _NF_CONNTRACK_L4PROTO_H
11#define _NF_CONNTRACK_L4PROTO_H
Patrick McHardydf6fb862007-09-28 14:37:03 -070012#include <linux/netlink.h>
Patrick McHardyf73e9242007-09-28 14:39:55 -070013#include <net/netlink.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080014#include <net/netfilter/nf_conntrack.h>
Gao feng2c352f42012-05-28 21:04:09 +000015#include <net/netns/generic.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080016
17struct seq_file;
18
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000019struct nf_conntrack_l4proto {
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080020 /* L3 Protocol number. */
21 u_int16_t l3proto;
22
Martin Josefsson605dcad2006-11-29 02:35:06 +010023 /* L4 Protocol number. */
24 u_int8_t l4proto;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080025
Pablo Neira Ayuso71d8c472016-05-01 00:28:40 +020026 /* Resolve clashes on insertion races. */
27 bool allow_clash;
28
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080029 /* Try to fill in the third arg: dataoff is offset past network protocol
30 hdr. Return true if possible. */
Jan Engelhardt09f263c2008-04-14 11:15:53 +020031 bool (*pkt_to_tuple)(const struct sk_buff *skb, unsigned int dataoff,
Eric W. Biedermana31f1ad2015-09-18 14:33:04 -050032 struct net *net, struct nf_conntrack_tuple *tuple);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080033
34 /* Invert the per-proto part of the tuple: ie. turn xmit into reply.
35 * Some packets can't be inverted: return 0 in that case.
36 */
Jan Engelhardt09f263c2008-04-14 11:15:53 +020037 bool (*invert_tuple)(struct nf_conntrack_tuple *inverse,
38 const struct nf_conntrack_tuple *orig);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080039
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080040 /* Returns verdict for packet, or -1 for invalid. */
Patrick McHardyc88130b2008-01-31 04:42:11 -080041 int (*packet)(struct nf_conn *ct,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080042 const struct sk_buff *skb,
43 unsigned int dataoff,
44 enum ip_conntrack_info ctinfo,
Jan Engelhardt76108ce2008-10-08 11:35:00 +020045 u_int8_t pf,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +010046 unsigned int hooknum,
47 unsigned int *timeouts);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080048
49 /* Called when a new connection for this protocol found;
50 * returns TRUE if it's OK. If so, packet() called next. */
Jan Engelhardt09f263c2008-04-14 11:15:53 +020051 bool (*new)(struct nf_conn *ct, const struct sk_buff *skb,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +010052 unsigned int dataoff, unsigned int *timeouts);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080053
54 /* Called when a conntrack entry is destroyed */
Patrick McHardyc88130b2008-01-31 04:42:11 -080055 void (*destroy)(struct nf_conn *ct);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080056
Patrick McHardy8fea97e2010-02-15 17:45:08 +010057 int (*error)(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,
58 unsigned int dataoff, enum ip_conntrack_info *ctinfo,
Jan Engelhardt76108ce2008-10-08 11:35:00 +020059 u_int8_t pf, unsigned int hooknum);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080060
Patrick McHardyffaa9c12008-01-31 04:41:14 -080061 /* Print out the per-protocol part of the tuple. Return like seq_* */
Joe Perches824f1fb2014-09-29 16:08:22 -070062 void (*print_tuple)(struct seq_file *s,
63 const struct nf_conntrack_tuple *);
Patrick McHardyffaa9c12008-01-31 04:41:14 -080064
65 /* Print out the private part of the conntrack. */
Steven Rostedt (Red Hat)37246a52014-10-27 16:02:47 -040066 void (*print_conntrack)(struct seq_file *s, struct nf_conn *);
Patrick McHardyffaa9c12008-01-31 04:41:14 -080067
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +010068 /* Return the array of timeouts for this protocol. */
69 unsigned int *(*get_timeouts)(struct net *net);
70
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080071 /* convert protoinfo to nfnetink attributes */
Patrick McHardyfdf70832007-09-28 14:37:41 -070072 int (*to_nlattr)(struct sk_buff *skb, struct nlattr *nla,
Patrick McHardy440f0d52009-06-10 14:32:47 +020073 struct nf_conn *ct);
Holger Eitzenbergerd0dba722009-03-25 18:24:48 +010074 /* Calculate protoinfo nlattr size */
75 int (*nlattr_size)(void);
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080076
77 /* convert nfnetlink attributes to protoinfo */
Patrick McHardyfdf70832007-09-28 14:37:41 -070078 int (*from_nlattr)(struct nlattr *tb[], struct nf_conn *ct);
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080079
Patrick McHardyfdf70832007-09-28 14:37:41 -070080 int (*tuple_to_nlattr)(struct sk_buff *skb,
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080081 const struct nf_conntrack_tuple *t);
Holger Eitzenbergerd0dba722009-03-25 18:24:48 +010082 /* Calculate tuple nlattr size */
83 int (*nlattr_tuple_size)(void);
Patrick McHardyfdf70832007-09-28 14:37:41 -070084 int (*nlattr_to_tuple)(struct nlattr *tb[],
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080085 struct nf_conntrack_tuple *t);
Patrick McHardyf73e9242007-09-28 14:39:55 -070086 const struct nla_policy *nla_policy;
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080087
Holger Eitzenbergerd0dba722009-03-25 18:24:48 +010088 size_t nla_size;
89
Pablo Neira Ayuso50978462012-02-28 19:13:48 +010090#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
91 struct {
92 size_t obj_size;
Gao feng8264deb2012-05-28 21:04:23 +000093 int (*nlattr_to_obj)(struct nlattr *tb[],
94 struct net *net, void *data);
Pablo Neira Ayuso50978462012-02-28 19:13:48 +010095 int (*obj_to_nlattr)(struct sk_buff *skb, const void *data);
96
97 unsigned int nlattr_max;
98 const struct nla_policy *nla_policy;
99 } ctnl_timeout;
100#endif
Gao feng2c352f42012-05-28 21:04:09 +0000101 int *net_id;
102 /* Init l4proto pernet data */
Gao fengf1caad22012-06-21 04:36:39 +0000103 int (*init_net)(struct net *net, u_int16_t proto);
Gao feng2c352f42012-05-28 21:04:09 +0000104
Pablo Neira Ayuso08911472012-06-29 05:23:24 +0000105 /* Return the per-net protocol part. */
106 struct nf_proto_net *(*get_net_proto)(struct net *net);
107
Patrick McHardyffaa9c12008-01-31 04:41:14 -0800108 /* Protocol name */
109 const char *name;
Patrick McHardyd62f9ed2006-11-29 02:35:17 +0100110
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800111 /* Module (if any) which this is connected to. */
112 struct module *me;
113};
114
Christoph Paasch9d2493f2009-03-16 15:15:35 +0100115/* Existing built-in generic protocol */
Martin Josefsson605dcad2006-11-29 02:35:06 +0100116extern struct nf_conntrack_l4proto nf_conntrack_l4proto_generic;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800117
118#define MAX_NF_CT_PROTO 256
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800119
Joe Perches4e77be42013-09-23 11:37:48 -0700120struct nf_conntrack_l4proto *__nf_ct_l4proto_find(u_int16_t l3proto,
121 u_int8_t l4proto);
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800122
Joe Perches4e77be42013-09-23 11:37:48 -0700123struct nf_conntrack_l4proto *nf_ct_l4proto_find_get(u_int16_t l3proto,
124 u_int8_t l4proto);
125void nf_ct_l4proto_put(struct nf_conntrack_l4proto *p);
Pablo Neira Ayusoc1ebd7d2012-03-22 23:40:01 +0100126
Gao fengc296bb42013-01-23 12:51:10 +0100127/* Protocol pernet registration. */
Joe Perches4e77be42013-09-23 11:37:48 -0700128int nf_ct_l4proto_pernet_register(struct net *net,
129 struct nf_conntrack_l4proto *proto);
130void nf_ct_l4proto_pernet_unregister(struct net *net,
131 struct nf_conntrack_l4proto *proto);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800132
Gao fengc296bb42013-01-23 12:51:10 +0100133/* Protocol global registration. */
Joe Perches4e77be42013-09-23 11:37:48 -0700134int nf_ct_l4proto_register(struct nf_conntrack_l4proto *proto);
135void nf_ct_l4proto_unregister(struct nf_conntrack_l4proto *proto);
Gao fengc296bb42013-01-23 12:51:10 +0100136
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800137/* Generic netlink helpers */
Joe Perches4e77be42013-09-23 11:37:48 -0700138int nf_ct_port_tuple_to_nlattr(struct sk_buff *skb,
139 const struct nf_conntrack_tuple *tuple);
140int nf_ct_port_nlattr_to_tuple(struct nlattr *tb[],
141 struct nf_conntrack_tuple *t);
142int nf_ct_port_nlattr_tuple_size(void);
Patrick McHardyf73e9242007-09-28 14:39:55 -0700143extern const struct nla_policy nf_ct_port_nla_policy[];
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800144
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800145#ifdef CONFIG_SYSCTL
Alexey Dobriyanc2a2c7e2008-10-08 11:35:08 +0200146#define LOG_INVALID(net, proto) \
147 ((net)->ct.sysctl_log_invalid == (proto) || \
148 (net)->ct.sysctl_log_invalid == IPPROTO_RAW)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800149#else
Ingo Molnar65f233f2008-11-25 18:20:13 +0100150static inline int LOG_INVALID(struct net *net, int proto) { return 0; }
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800151#endif /* CONFIG_SYSCTL */
152
153#endif /*_NF_CONNTRACK_PROTOCOL_H*/