~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/netfilter/nf_conntrack_proto_generic.c

Version: ~ [ linux-5.4-rc3 ] ~ [ linux-5.3.6 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.79 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.149 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.196 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.196 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.75 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* (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.
  7  */
  8 
  9 #include <linux/types.h>
 10 #include <linux/jiffies.h>
 11 #include <linux/timer.h>
 12 #include <linux/netfilter.h>
 13 #include <net/netfilter/nf_conntrack_l4proto.h>
 14 
 15 static unsigned int nf_ct_generic_timeout __read_mostly = 600*HZ;
 16 
 17 static bool nf_generic_should_process(u8 proto)
 18 {
 19         switch (proto) {
 20 #ifdef CONFIG_NF_CT_PROTO_SCTP_MODULE
 21         case IPPROTO_SCTP:
 22                 return false;
 23 #endif
 24 #ifdef CONFIG_NF_CT_PROTO_DCCP_MODULE
 25         case IPPROTO_DCCP:
 26                 return false;
 27 #endif
 28 #ifdef CONFIG_NF_CT_PROTO_GRE_MODULE
 29         case IPPROTO_GRE:
 30                 return false;
 31 #endif
 32 #ifdef CONFIG_NF_CT_PROTO_UDPLITE_MODULE
 33         case IPPROTO_UDPLITE:
 34                 return false;
 35 #endif
 36         default:
 37                 return true;
 38         }
 39 }
 40 
 41 static inline struct nf_generic_net *generic_pernet(struct net *net)
 42 {
 43         return &net->ct.nf_ct_proto.generic;
 44 }
 45 
 46 static bool generic_pkt_to_tuple(const struct sk_buff *skb,
 47                                  unsigned int dataoff,
 48                                  struct net *net, struct nf_conntrack_tuple *tuple)
 49 {
 50         tuple->src.u.all = 0;
 51         tuple->dst.u.all = 0;
 52 
 53         return true;
 54 }
 55 
 56 static bool generic_invert_tuple(struct nf_conntrack_tuple *tuple,
 57                                  const struct nf_conntrack_tuple *orig)
 58 {
 59         tuple->src.u.all = 0;
 60         tuple->dst.u.all = 0;
 61 
 62         return true;
 63 }
 64 
 65 /* Print out the per-protocol part of the tuple. */
 66 static void generic_print_tuple(struct seq_file *s,
 67                                 const struct nf_conntrack_tuple *tuple)
 68 {
 69 }
 70 
 71 static unsigned int *generic_get_timeouts(struct net *net)
 72 {
 73         return &(generic_pernet(net)->timeout);
 74 }
 75 
 76 /* Returns verdict for packet, or -1 for invalid. */
 77 static int generic_packet(struct nf_conn *ct,
 78                           const struct sk_buff *skb,
 79                           unsigned int dataoff,
 80                           enum ip_conntrack_info ctinfo,
 81                           u_int8_t pf,
 82                           unsigned int hooknum,
 83                           unsigned int *timeout)
 84 {
 85         nf_ct_refresh_acct(ct, ctinfo, skb, *timeout);
 86         return NF_ACCEPT;
 87 }
 88 
 89 /* Called when a new connection for this protocol found. */
 90 static bool generic_new(struct nf_conn *ct, const struct sk_buff *skb,
 91                         unsigned int dataoff, unsigned int *timeouts)
 92 {
 93         bool ret;
 94 
 95         ret = nf_generic_should_process(nf_ct_protonum(ct));
 96         if (!ret)
 97                 pr_warn_once("conntrack: generic helper won't handle protocol %d. Please consider loading the specific helper module.\n",
 98                              nf_ct_protonum(ct));
 99         return ret;
100 }
101 
102 #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
103 
104 #include <linux/netfilter/nfnetlink.h>
105 #include <linux/netfilter/nfnetlink_cttimeout.h>
106 
107 static int generic_timeout_nlattr_to_obj(struct nlattr *tb[],
108                                          struct net *net, void *data)
109 {
110         unsigned int *timeout = data;
111         struct nf_generic_net *gn = generic_pernet(net);
112 
113         if (tb[CTA_TIMEOUT_GENERIC_TIMEOUT])
114                 *timeout =
115                     ntohl(nla_get_be32(tb[CTA_TIMEOUT_GENERIC_TIMEOUT])) * HZ;
116         else {
117                 /* Set default generic timeout. */
118                 *timeout = gn->timeout;
119         }
120 
121         return 0;
122 }
123 
124 static int
125 generic_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data)
126 {
127         const unsigned int *timeout = data;
128 
129         if (nla_put_be32(skb, CTA_TIMEOUT_GENERIC_TIMEOUT, htonl(*timeout / HZ)))
130                 goto nla_put_failure;
131 
132         return 0;
133 
134 nla_put_failure:
135         return -ENOSPC;
136 }
137 
138 static const struct nla_policy
139 generic_timeout_nla_policy[CTA_TIMEOUT_GENERIC_MAX+1] = {
140         [CTA_TIMEOUT_GENERIC_TIMEOUT]   = { .type = NLA_U32 },
141 };
142 #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
143 
144 #ifdef CONFIG_SYSCTL
145 static struct ctl_table generic_sysctl_table[] = {
146         {
147                 .procname       = "nf_conntrack_generic_timeout",
148                 .maxlen         = sizeof(unsigned int),
149                 .mode           = 0644,
150                 .proc_handler   = proc_dointvec_jiffies,
151         },
152         { }
153 };
154 #endif /* CONFIG_SYSCTL */
155 
156 static int generic_kmemdup_sysctl_table(struct nf_proto_net *pn,
157                                         struct nf_generic_net *gn)
158 {
159 #ifdef CONFIG_SYSCTL
160         pn->ctl_table = kmemdup(generic_sysctl_table,
161                                 sizeof(generic_sysctl_table),
162                                 GFP_KERNEL);
163         if (!pn->ctl_table)
164                 return -ENOMEM;
165 
166         pn->ctl_table[0].data = &gn->timeout;
167 #endif
168         return 0;
169 }
170 
171 static int generic_init_net(struct net *net, u_int16_t proto)
172 {
173         struct nf_generic_net *gn = generic_pernet(net);
174         struct nf_proto_net *pn = &gn->pn;
175 
176         gn->timeout = nf_ct_generic_timeout;
177 
178         return generic_kmemdup_sysctl_table(pn, gn);
179 }
180 
181 static struct nf_proto_net *generic_get_net_proto(struct net *net)
182 {
183         return &net->ct.nf_ct_proto.generic.pn;
184 }
185 
186 struct nf_conntrack_l4proto nf_conntrack_l4proto_generic __read_mostly =
187 {
188         .l3proto                = PF_UNSPEC,
189         .l4proto                = 255,
190         .name                   = "unknown",
191         .pkt_to_tuple           = generic_pkt_to_tuple,
192         .invert_tuple           = generic_invert_tuple,
193         .print_tuple            = generic_print_tuple,
194         .packet                 = generic_packet,
195         .get_timeouts           = generic_get_timeouts,
196         .new                    = generic_new,
197 #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
198         .ctnl_timeout           = {
199                 .nlattr_to_obj  = generic_timeout_nlattr_to_obj,
200                 .obj_to_nlattr  = generic_timeout_obj_to_nlattr,
201                 .nlattr_max     = CTA_TIMEOUT_GENERIC_MAX,
202                 .obj_size       = sizeof(unsigned int),
203                 .nla_policy     = generic_timeout_nla_policy,
204         },
205 #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */
206         .init_net               = generic_init_net,
207         .get_net_proto          = generic_get_net_proto,
208 };
209 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp