1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/kernel.h>
3 #include <linux/init.h>
4 #include <linux/module.h>
5 #include <linux/netfilter.h>
6 #include <linux/rhashtable.h>
7 #include <net/netfilter/nf_flow_table.h>
8 #include <net/netfilter/nf_tables.h>
9 #include <linux/if_vlan.h>
12 nf_flow_offload_inet_hook(void *priv, struct sk_buff *skb,
13 const struct nf_hook_state *state)
15 struct vlan_ethhdr *veth;
18 switch (skb->protocol) {
19 case htons(ETH_P_8021Q):
20 veth = (struct vlan_ethhdr *)skb_mac_header(skb);
21 proto = veth->h_vlan_encapsulated_proto;
23 case htons(ETH_P_PPP_SES):
24 proto = nf_flow_pppoe_proto(skb);
27 proto = skb->protocol;
33 return nf_flow_offload_ip_hook(priv, skb, state);
34 case htons(ETH_P_IPV6):
35 return nf_flow_offload_ipv6_hook(priv, skb, state);
41 static int nf_flow_rule_route_inet(struct net *net,
42 const struct flow_offload *flow,
43 enum flow_offload_tuple_dir dir,
44 struct nf_flow_rule *flow_rule)
46 const struct flow_offload_tuple *flow_tuple = &flow->tuplehash[dir].tuple;
49 switch (flow_tuple->l3proto) {
51 err = nf_flow_rule_route_ipv4(net, flow, dir, flow_rule);
54 err = nf_flow_rule_route_ipv6(net, flow, dir, flow_rule);
64 static struct nf_flowtable_type flowtable_inet = {
65 .family = NFPROTO_INET,
66 .init = nf_flow_table_init,
67 .setup = nf_flow_table_offload_setup,
68 .action = nf_flow_rule_route_inet,
69 .free = nf_flow_table_free,
70 .hook = nf_flow_offload_inet_hook,
74 static int __init nf_flow_inet_module_init(void)
76 nft_register_flowtable_type(&flowtable_inet);
81 static void __exit nf_flow_inet_module_exit(void)
83 nft_unregister_flowtable_type(&flowtable_inet);
86 module_init(nf_flow_inet_module_init);
87 module_exit(nf_flow_inet_module_exit);
89 MODULE_LICENSE("GPL");
90 MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
91 MODULE_ALIAS_NF_FLOWTABLE(1); /* NFPROTO_INET */
92 MODULE_DESCRIPTION("Netfilter flow table mixed IPv4/IPv6 module");