Skip to content

Commit c1deb06

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: nf_tables: merge route type into core
very little code, so it really doesn't make sense to have extra modules or even a kconfig knob for this. Merge them and make functionality available unconditionally. The merge makes inet family route support trivial, so add it as well here. Before: text data bss dec hex filename 835 832 0 1667 683 nft_chain_route_ipv4.ko 870 832 0 1702 6a6 nft_chain_route_ipv6.ko 111568 2556 529 114653 1bfdd nf_tables.ko After: text data bss dec hex filename 113133 2556 529 116218 1c5fa nf_tables.ko Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent d164385 commit c1deb06

12 files changed

Lines changed: 191 additions & 214 deletions

File tree

‎include/linux/netfilter_ipv6.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ static inline int nf_ip6_route(struct net *net, struct dst_entry **dst,
8787
}
8888

8989
int ip6_route_me_harder(struct net *net, struct sk_buff *skb);
90+
91+
static inline int nf_ip6_route_me_harder(struct net *net, struct sk_buff *skb)
92+
{
93+
#if IS_MODULE(CONFIG_IPV6)
94+
const struct nf_ipv6_ops *v6_ops = nf_get_ipv6_ops();
95+
96+
if (!v6_ops)
97+
return -EHOSTUNREACH;
98+
99+
return v6_ops->route_me_harder(net, skb);
100+
#else
101+
return ip6_route_me_harder(net, skb);
102+
#endif
103+
}
104+
90105
__sum16 nf_ip6_checksum(struct sk_buff *skb, unsigned int hook,
91106
unsigned int dataoff, u_int8_t protocol);
92107

‎include/net/netfilter/nf_tables.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,4 +1411,6 @@ struct nft_trans_flowtable {
14111411
int __init nft_chain_filter_init(void);
14121412
void nft_chain_filter_fini(void);
14131413

1414+
void __init nft_chain_route_init(void);
1415+
void nft_chain_route_fini(void);
14141416
#endif /* _NET_NF_TABLES_H */

‎net/ipv4/netfilter/Kconfig‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ config NF_TABLES_IPV4
2727

2828
if NF_TABLES_IPV4
2929

30-
config NFT_CHAIN_ROUTE_IPV4
31-
tristate "IPv4 nf_tables route chain support"
32-
help
33-
This option enables the "route" chain for IPv4 in nf_tables. This
34-
chain type is used to force packet re-routing after mangling header
35-
fields such as the source, destination, type of service and
36-
the packet mark.
37-
3830
config NFT_REJECT_IPV4
3931
select NF_REJECT_IPV4
4032
default NFT_REJECT

‎net/ipv4/netfilter/Makefile‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ nf_nat_snmp_basic-y := nf_nat_snmp_basic.asn1.o nf_nat_snmp_basic_main.o
2424
$(obj)/nf_nat_snmp_basic_main.o: $(obj)/nf_nat_snmp_basic.asn1.h
2525
obj-$(CONFIG_NF_NAT_SNMP_BASIC) += nf_nat_snmp_basic.o
2626

27-
obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV4) += nft_chain_route_ipv4.o
2827
obj-$(CONFIG_NFT_REJECT_IPV4) += nft_reject_ipv4.o
2928
obj-$(CONFIG_NFT_FIB_IPV4) += nft_fib_ipv4.o
3029
obj-$(CONFIG_NFT_DUP_IPV4) += nft_dup_ipv4.o

‎net/ipv4/netfilter/nft_chain_route_ipv4.c‎

Lines changed: 0 additions & 89 deletions
This file was deleted.

‎net/ipv6/netfilter/Kconfig‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ config NF_TABLES_IPV6
2323

2424
if NF_TABLES_IPV6
2525

26-
config NFT_CHAIN_ROUTE_IPV6
27-
tristate "IPv6 nf_tables route chain support"
28-
help
29-
This option enables the "route" chain for IPv6 in nf_tables. This
30-
chain type is used to force packet re-routing after mangling header
31-
fields such as the source, destination, flowlabel, hop-limit and
32-
the packet mark.
33-
3426
config NFT_REJECT_IPV6
3527
select NF_REJECT_IPV6
3628
default NFT_REJECT

‎net/ipv6/netfilter/Makefile‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ obj-$(CONFIG_NF_REJECT_IPV6) += nf_reject_ipv6.o
2727
obj-$(CONFIG_NF_DUP_IPV6) += nf_dup_ipv6.o
2828

2929
# nf_tables
30-
obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV6) += nft_chain_route_ipv6.o
3130
obj-$(CONFIG_NFT_REJECT_IPV6) += nft_reject_ipv6.o
3231
obj-$(CONFIG_NFT_DUP_IPV6) += nft_dup_ipv6.o
3332
obj-$(CONFIG_NFT_FIB_IPV6) += nft_fib_ipv6.o

‎net/ipv6/netfilter/nft_chain_route_ipv6.c‎

Lines changed: 0 additions & 91 deletions
This file was deleted.

‎net/netfilter/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ obj-$(CONFIG_NF_DUP_NETDEV) += nf_dup_netdev.o
7777
nf_tables-objs := nf_tables_core.o nf_tables_api.o nft_chain_filter.o \
7878
nf_tables_trace.o nft_immediate.o nft_cmp.o nft_range.o \
7979
nft_bitwise.o nft_byteorder.o nft_payload.o nft_lookup.o \
80-
nft_dynset.o nft_meta.o nft_rt.o nft_exthdr.o
80+
nft_dynset.o nft_meta.o nft_rt.o nft_exthdr.o \
81+
nft_chain_route.o
8182

8283
nf_tables_set-objs := nf_tables_set_core.o \
8384
nft_set_hash.o nft_set_bitmap.o nft_set_rbtree.o

‎net/netfilter/nf_nat_proto.c‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -926,20 +926,6 @@ nf_nat_ipv6_out(void *priv, struct sk_buff *skb,
926926
return ret;
927927
}
928928

929-
static int nat_route_me_harder(struct net *net, struct sk_buff *skb)
930-
{
931-
#ifdef CONFIG_IPV6_MODULE
932-
const struct nf_ipv6_ops *v6_ops = nf_get_ipv6_ops();
933-
934-
if (!v6_ops)
935-
return -EHOSTUNREACH;
936-
937-
return v6_ops->route_me_harder(net, skb);
938-
#else
939-
return ip6_route_me_harder(net, skb);
940-
#endif
941-
}
942-
943929
static unsigned int
944930
nf_nat_ipv6_local_fn(void *priv, struct sk_buff *skb,
945931
const struct nf_hook_state *state)
@@ -959,7 +945,7 @@ nf_nat_ipv6_local_fn(void *priv, struct sk_buff *skb,
959945

960946
if (!nf_inet_addr_cmp(&ct->tuplehash[dir].tuple.dst.u3,
961947
&ct->tuplehash[!dir].tuple.src.u3)) {
962-
err = nat_route_me_harder(state->net, skb);
948+
err = nf_ip6_route_me_harder(state->net, skb);
963949
if (err < 0)
964950
ret = NF_DROP_ERR(err);
965951
}

0 commit comments

Comments
 (0)