blob: d8923d54b3585bf579c66eaba82dc4ec7d464236 [file] [log] [blame]
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -08001/* (C) 1999-2001 Paul `Rusty' Russell
2 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -08007 */
8
9#include <linux/types.h>
Tim Schmielaucd354f12007-02-14 00:33:14 -080010#include <linux/jiffies.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080011#include <linux/timer.h>
12#include <linux/netfilter.h>
Martin Josefsson605dcad2006-11-29 02:35:06 +010013#include <net/netfilter/nf_conntrack_l4proto.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080014
Patrick McHardy933a41e2006-11-29 02:35:18 +010015static unsigned int nf_ct_generic_timeout __read_mostly = 600*HZ;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080016
Jan Engelhardt09f263c2008-04-14 11:15:53 +020017static bool generic_pkt_to_tuple(const struct sk_buff *skb,
18 unsigned int dataoff,
19 struct nf_conntrack_tuple *tuple)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080020{
21 tuple->src.u.all = 0;
22 tuple->dst.u.all = 0;
23
Jan Engelhardt09f263c2008-04-14 11:15:53 +020024 return true;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080025}
26
Jan Engelhardt09f263c2008-04-14 11:15:53 +020027static bool generic_invert_tuple(struct nf_conntrack_tuple *tuple,
28 const struct nf_conntrack_tuple *orig)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080029{
30 tuple->src.u.all = 0;
31 tuple->dst.u.all = 0;
32
Jan Engelhardt09f263c2008-04-14 11:15:53 +020033 return true;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080034}
35
36/* Print out the per-protocol part of the tuple. */
37static int generic_print_tuple(struct seq_file *s,
38 const struct nf_conntrack_tuple *tuple)
39{
40 return 0;
41}
42
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +010043static unsigned int *generic_get_timeouts(struct net *net)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080044{
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +010045 return &nf_ct_generic_timeout;
46}
47
48/* Returns verdict for packet, or -1 for invalid. */
49static int generic_packet(struct nf_conn *ct,
50 const struct sk_buff *skb,
51 unsigned int dataoff,
52 enum ip_conntrack_info ctinfo,
53 u_int8_t pf,
54 unsigned int hooknum,
55 unsigned int *timeout)
56{
57 nf_ct_refresh_acct(ct, ctinfo, skb, *timeout);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080058 return NF_ACCEPT;
59}
60
61/* Called when a new connection for this protocol found. */
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +010062static bool generic_new(struct nf_conn *ct, const struct sk_buff *skb,
63 unsigned int dataoff, unsigned int *timeouts)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080064{
Jan Engelhardt09f263c2008-04-14 11:15:53 +020065 return true;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080066}
67
Pablo Neira Ayuso50978462012-02-28 19:13:48 +010068#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
69
70#include <linux/netfilter/nfnetlink.h>
71#include <linux/netfilter/nfnetlink_cttimeout.h>
72
73static int generic_timeout_nlattr_to_obj(struct nlattr *tb[], void *data)
74{
75 unsigned int *timeout = data;
76
77 if (tb[CTA_TIMEOUT_GENERIC_TIMEOUT])
78 *timeout =
79 ntohl(nla_get_be32(tb[CTA_TIMEOUT_GENERIC_TIMEOUT])) * HZ;
80 else {
81 /* Set default generic timeout. */
82 *timeout = nf_ct_generic_timeout;
83 }
84
85 return 0;
86}
87
88static int
89generic_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data)
90{
91 const unsigned int *timeout = data;
92
David S. Millerf5776942012-04-01 18:52:31 -040093 if (nla_put_be32(skb, CTA_TIMEOUT_GENERIC_TIMEOUT, htonl(*timeout / HZ)))
94 goto nla_put_failure;
Pablo Neira Ayuso50978462012-02-28 19:13:48 +010095
96 return 0;
97
98nla_put_failure:
99 return -ENOSPC;
100}
101
102static const struct nla_policy
103generic_timeout_nla_policy[CTA_TIMEOUT_GENERIC_MAX+1] = {
104 [CTA_TIMEOUT_GENERIC_TIMEOUT] = { .type = NLA_U32 },
105};
106#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
107
Patrick McHardy933a41e2006-11-29 02:35:18 +0100108#ifdef CONFIG_SYSCTL
109static struct ctl_table_header *generic_sysctl_header;
110static struct ctl_table generic_sysctl_table[] = {
111 {
Patrick McHardy933a41e2006-11-29 02:35:18 +0100112 .procname = "nf_conntrack_generic_timeout",
113 .data = &nf_ct_generic_timeout,
114 .maxlen = sizeof(unsigned int),
115 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800116 .proc_handler = proc_dointvec_jiffies,
Patrick McHardy933a41e2006-11-29 02:35:18 +0100117 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800118 { }
Patrick McHardy933a41e2006-11-29 02:35:18 +0100119};
Patrick McHardya999e682006-11-29 02:35:20 +0100120#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
121static struct ctl_table generic_compat_sysctl_table[] = {
122 {
Patrick McHardya999e682006-11-29 02:35:20 +0100123 .procname = "ip_conntrack_generic_timeout",
124 .data = &nf_ct_generic_timeout,
125 .maxlen = sizeof(unsigned int),
126 .mode = 0644,
Alexey Dobriyan6d9f2392008-11-03 18:21:05 -0800127 .proc_handler = proc_dointvec_jiffies,
Patrick McHardya999e682006-11-29 02:35:20 +0100128 },
Eric W. Biedermanf8572d82009-11-05 13:32:03 -0800129 { }
Patrick McHardya999e682006-11-29 02:35:20 +0100130};
131#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
Patrick McHardy933a41e2006-11-29 02:35:18 +0100132#endif /* CONFIG_SYSCTL */
133
Patrick McHardy61075af2007-07-14 20:48:19 -0700134struct nf_conntrack_l4proto nf_conntrack_l4proto_generic __read_mostly =
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800135{
136 .l3proto = PF_UNSPEC,
Christoph Paaschfe2a7ce2009-02-18 16:28:35 +0100137 .l4proto = 255,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800138 .name = "unknown",
139 .pkt_to_tuple = generic_pkt_to_tuple,
140 .invert_tuple = generic_invert_tuple,
141 .print_tuple = generic_print_tuple,
Pablo Neira Ayuso2c8503f2012-02-28 18:23:31 +0100142 .packet = generic_packet,
143 .get_timeouts = generic_get_timeouts,
144 .new = generic_new,
Pablo Neira Ayuso50978462012-02-28 19:13:48 +0100145#if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
146 .ctnl_timeout = {
147 .nlattr_to_obj = generic_timeout_nlattr_to_obj,
148 .obj_to_nlattr = generic_timeout_obj_to_nlattr,
149 .nlattr_max = CTA_TIMEOUT_GENERIC_MAX,
150 .obj_size = sizeof(unsigned int),
151 .nla_policy = generic_timeout_nla_policy,
152 },
153#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
Patrick McHardy933a41e2006-11-29 02:35:18 +0100154#ifdef CONFIG_SYSCTL
155 .ctl_table_header = &generic_sysctl_header,
156 .ctl_table = generic_sysctl_table,
Patrick McHardya999e682006-11-29 02:35:20 +0100157#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
158 .ctl_compat_table = generic_compat_sysctl_table,
159#endif
Patrick McHardy933a41e2006-11-29 02:35:18 +0100160#endif
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -0800161};