blob: ba32ed7bdabe75c0655e728fbdcebbffae492151 [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>
15
16struct seq_file;
17
Martin Josefsson605dcad2006-11-29 02:35:06 +010018struct nf_conntrack_l4proto
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080019{
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
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080026 /* Try to fill in the third arg: dataoff is offset past network protocol
27 hdr. Return true if possible. */
Jan Engelhardt09f263c2008-04-14 11:15:53 +020028 bool (*pkt_to_tuple)(const struct sk_buff *skb, unsigned int dataoff,
29 struct nf_conntrack_tuple *tuple);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080030
31 /* Invert the per-proto part of the tuple: ie. turn xmit into reply.
32 * Some packets can't be inverted: return 0 in that case.
33 */
Jan Engelhardt09f263c2008-04-14 11:15:53 +020034 bool (*invert_tuple)(struct nf_conntrack_tuple *inverse,
35 const struct nf_conntrack_tuple *orig);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080036
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080037 /* Returns verdict for packet, or -1 for invalid. */
Patrick McHardyc88130b2008-01-31 04:42:11 -080038 int (*packet)(struct nf_conn *ct,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080039 const struct sk_buff *skb,
40 unsigned int dataoff,
41 enum ip_conntrack_info ctinfo,
Jan Engelhardt76108ce2008-10-08 11:35:00 +020042 u_int8_t pf,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080043 unsigned int hooknum);
44
45 /* Called when a new connection for this protocol found;
46 * returns TRUE if it's OK. If so, packet() called next. */
Jan Engelhardt09f263c2008-04-14 11:15:53 +020047 bool (*new)(struct nf_conn *ct, const struct sk_buff *skb,
48 unsigned int dataoff);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080049
50 /* Called when a conntrack entry is destroyed */
Patrick McHardyc88130b2008-01-31 04:42:11 -080051 void (*destroy)(struct nf_conn *ct);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080052
Alexey Dobriyan74c51a12008-10-08 11:35:05 +020053 int (*error)(struct net *net, struct sk_buff *skb, unsigned int dataoff,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080054 enum ip_conntrack_info *ctinfo,
Jan Engelhardt76108ce2008-10-08 11:35:00 +020055 u_int8_t pf, unsigned int hooknum);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080056
Patrick McHardyffaa9c12008-01-31 04:41:14 -080057 /* Print out the per-protocol part of the tuple. Return like seq_* */
58 int (*print_tuple)(struct seq_file *s,
59 const struct nf_conntrack_tuple *);
60
61 /* Print out the private part of the conntrack. */
62 int (*print_conntrack)(struct seq_file *s, const struct nf_conn *);
63
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080064 /* convert protoinfo to nfnetink attributes */
Patrick McHardyfdf70832007-09-28 14:37:41 -070065 int (*to_nlattr)(struct sk_buff *skb, struct nlattr *nla,
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080066 const struct nf_conn *ct);
Holger Eitzenbergerd0dba722009-03-25 18:24:48 +010067 /* Calculate protoinfo nlattr size */
68 int (*nlattr_size)(void);
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080069
70 /* convert nfnetlink attributes to protoinfo */
Patrick McHardyfdf70832007-09-28 14:37:41 -070071 int (*from_nlattr)(struct nlattr *tb[], struct nf_conn *ct);
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080072
Patrick McHardyfdf70832007-09-28 14:37:41 -070073 int (*tuple_to_nlattr)(struct sk_buff *skb,
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080074 const struct nf_conntrack_tuple *t);
Holger Eitzenbergerd0dba722009-03-25 18:24:48 +010075 /* Calculate tuple nlattr size */
76 int (*nlattr_tuple_size)(void);
Patrick McHardyfdf70832007-09-28 14:37:41 -070077 int (*nlattr_to_tuple)(struct nlattr *tb[],
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080078 struct nf_conntrack_tuple *t);
Patrick McHardyf73e9242007-09-28 14:39:55 -070079 const struct nla_policy *nla_policy;
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -080080
Holger Eitzenbergerd0dba722009-03-25 18:24:48 +010081 size_t nla_size;
82
Patrick McHardyd62f9ed2006-11-29 02:35:17 +010083#ifdef CONFIG_SYSCTL
84 struct ctl_table_header **ctl_table_header;
85 struct ctl_table *ctl_table;
86 unsigned int *ctl_table_users;
Patrick McHardya999e682006-11-29 02:35:20 +010087#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
88 struct ctl_table_header *ctl_compat_table_header;
89 struct ctl_table *ctl_compat_table;
90#endif
91#endif
Patrick McHardyffaa9c12008-01-31 04:41:14 -080092 /* Protocol name */
93 const char *name;
Patrick McHardyd62f9ed2006-11-29 02:35:17 +010094
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080095 /* Module (if any) which this is connected to. */
96 struct module *me;
97};
98
Christoph Paasch9d2493f2009-03-16 15:15:35 +010099/* Existing built-in generic protocol */
Martin Josefsson605dcad2006-11-29 02:35:06 +0100100extern struct nf_conntrack_l4proto nf_conntrack_l4proto_generic;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800101
102#define MAX_NF_CT_PROTO 256
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800103
Martin Josefsson605dcad2006-11-29 02:35:06 +0100104extern struct nf_conntrack_l4proto *
105__nf_ct_l4proto_find(u_int16_t l3proto, u_int8_t l4proto);
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800106
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800107/* Protocol registration. */
Martin Josefsson605dcad2006-11-29 02:35:06 +0100108extern int nf_conntrack_l4proto_register(struct nf_conntrack_l4proto *proto);
Patrick McHardyfe3eb202007-02-12 11:14:28 -0800109extern void nf_conntrack_l4proto_unregister(struct nf_conntrack_l4proto *proto);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800110
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800111/* Generic netlink helpers */
Patrick McHardyfdf70832007-09-28 14:37:41 -0700112extern int nf_ct_port_tuple_to_nlattr(struct sk_buff *skb,
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800113 const struct nf_conntrack_tuple *tuple);
Patrick McHardyfdf70832007-09-28 14:37:41 -0700114extern int nf_ct_port_nlattr_to_tuple(struct nlattr *tb[],
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800115 struct nf_conntrack_tuple *t);
Holger Eitzenberger5c0de292009-03-25 21:52:17 +0100116extern int nf_ct_port_nlattr_tuple_size(void);
Patrick McHardyf73e9242007-09-28 14:39:55 -0700117extern const struct nla_policy nf_ct_port_nla_policy[];
Pablo Neira Ayusoc1d10ad2006-01-05 12:19:05 -0800118
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800119#ifdef CONFIG_SYSCTL
120#ifdef DEBUG_INVALID_PACKETS
Alexey Dobriyanc2a2c7e2008-10-08 11:35:08 +0200121#define LOG_INVALID(net, proto) \
122 ((net)->ct.sysctl_log_invalid == (proto) || \
123 (net)->ct.sysctl_log_invalid == IPPROTO_RAW)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800124#else
Alexey Dobriyanc2a2c7e2008-10-08 11:35:08 +0200125#define LOG_INVALID(net, proto) \
126 (((net)->ct.sysctl_log_invalid == (proto) || \
127 (net)->ct.sysctl_log_invalid == IPPROTO_RAW) \
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800128 && net_ratelimit())
129#endif
130#else
Ingo Molnar65f233f2008-11-25 18:20:13 +0100131static inline int LOG_INVALID(struct net *net, int proto) { return 0; }
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800132#endif /* CONFIG_SYSCTL */
133
134#endif /*_NF_CONNTRACK_PROTOCOL_H*/