26 #include <linux/module.h>
27 #include <linux/types.h>
29 #include <linux/list.h>
32 #include <linux/netdevice.h>
34 #include <linux/slab.h>
50 static unsigned int gre_timeouts[
GRE_CT_MAX] = {
71 struct nf_ct_gre_keymap *km, *
tmp;
82 static inline int gre_key_cmpfn(
const struct nf_ct_gre_keymap *km,
85 return km->tuple.src.l3num == t->
src.l3num &&
86 !
memcmp(&km->tuple.src.u3, &t->
src.u3,
sizeof(t->
src.u3)) &&
87 !
memcmp(&km->tuple.dst.u3, &t->
dst.u3,
sizeof(t->
dst.u3)) &&
88 km->tuple.dst.protonum == t->
dst.protonum &&
89 km->tuple.dst.u.all == t->
dst.u.all;
96 struct nf_ct_gre_keymap *km;
101 if (gre_key_cmpfn(km, t)) {
102 key = km->tuple.src.u.gre.key;
108 pr_debug(
"lookup src key 0x%x for ", key);
118 struct net *net = nf_ct_net(ct);
121 struct nf_ct_gre_keymap **kmp, *km;
123 kmp = &ct_pptp_info->
keymap[dir];
128 if (gre_key_cmpfn(km, t) && km == *kmp) {
134 pr_debug(
"trying to override keymap_%s for ct %p\n",
142 memcpy(&km->tuple, t,
sizeof(*t));
145 pr_debug(
"adding new entry %p: ", km);
146 nf_ct_dump_tuple(&km->tuple);
159 struct net *net = nf_ct_net(ct);
164 pr_debug(
"entering for ct %p\n", ct);
168 if (ct_pptp_info->
keymap[dir]) {
170 ct_pptp_info->
keymap[dir]);
186 tuple->
dst.u.gre.key = orig->
src.u.gre.key;
187 tuple->
src.u.gre.key = orig->
dst.u.gre.key;
192 static bool gre_pkt_to_tuple(
const struct sk_buff *
skb,
unsigned int dataoff,
195 struct net *net = dev_net(skb->
dev ? skb->
dev : skb_dst(skb)->
dev);
203 grehdr = skb_header_pointer(skb, dataoff,
sizeof(_grehdr), &_grehdr);
206 tuple->
src.u.all = 0;
207 tuple->
dst.u.all = 0;
212 pgrehdr = skb_header_pointer(skb, dataoff, 8, &_pgrehdr);
217 pr_debug(
"GRE_VERSION_PPTP but unknown proto\n");
222 srckey = gre_keymap_lookup(net, tuple);
223 tuple->
src.u.gre.key = srckey;
229 static int gre_print_tuple(
struct seq_file *
s,
232 return seq_printf(s,
"srckey=0x%x dstkey=0x%x ",
240 return seq_printf(s,
"timeout=%u, stream_timeout=%u ",
245 static unsigned int *gre_get_timeouts(
struct net *net)
247 return gre_pernet(net)->gre_timeouts;
251 static int gre_packet(
struct nf_conn *ct,
253 unsigned int dataoff,
257 unsigned int *timeouts)
262 nf_ct_refresh_acct(ct, ctinfo, skb,
268 nf_ct_refresh_acct(ct, ctinfo, skb,
275 static bool gre_new(
struct nf_conn *ct,
const struct sk_buff *skb,
276 unsigned int dataoff,
unsigned int *timeouts)
291 static void gre_destroy(
struct nf_conn *ct)
302 #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
304 #include <linux/netfilter/nfnetlink.h>
307 static int gre_timeout_nlattr_to_obj(
struct nlattr *
tb[],
308 struct net *net,
void *
data)
310 unsigned int *timeouts =
data;
319 ntohl(nla_get_be32(tb[CTA_TIMEOUT_GRE_UNREPLIED])) *
HZ;
323 ntohl(nla_get_be32(tb[CTA_TIMEOUT_GRE_REPLIED])) *
HZ;
329 gre_timeout_obj_to_nlattr(
struct sk_buff *skb,
const void *data)
331 const unsigned int *timeouts =
data;
333 if (nla_put_be32(skb, CTA_TIMEOUT_GRE_UNREPLIED,
335 nla_put_be32(skb, CTA_TIMEOUT_GRE_REPLIED,
337 goto nla_put_failure;
369 .pkt_to_tuple = gre_pkt_to_tuple,
370 .invert_tuple = gre_invert_tuple,
371 .print_tuple = gre_print_tuple,
372 .print_conntrack = gre_print_conntrack,
373 .get_timeouts = gre_get_timeouts,
374 .packet = gre_packet,
376 .destroy = gre_destroy,
378 #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
384 #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT)
386 .nlattr_to_obj = gre_timeout_nlattr_to_obj,
387 .obj_to_nlattr = gre_timeout_obj_to_nlattr,
393 .
net_id = &proto_gre_net_id,
397 static int proto_gre_net_init(
struct net *net)
402 pr_err(
"nf_conntrack_l4proto_gre4 :protocol register failed.\n");
406 static void proto_gre_net_exit(
struct net *net)
413 .init = proto_gre_net_init,
414 .exit = proto_gre_net_exit,
415 .id = &proto_gre_net_id,
419 static int __init nf_ct_proto_gre_init(
void)
424 static void __exit nf_ct_proto_gre_fini(
void)