History

Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next

Pablo Neira Ayuso says: ==================== Netfilter updates for net-next The following patchset contains Netfilter updates for your net-next tree. This includes better integration with the routing subsystem for nf_tables, explicit notrack support and smaller updates. More specifically, they are: 1) Add fib lookup expression for nf_tables, from Florian Westphal. This new expression provides a native replacement for iptables addrtype and rp_filter matches. This is more flexible though, since we can populate the kernel flowi representation to inquire fib to accomodate new usecases, such as RTBH through skb mark. 2) Introduce rt expression for nf_tables, from Anders K. Pedersen. This new expression allow you to access skbuff route metadata, more specifically nexthop and classid fields. 3) Add notrack support for nf_tables, to skip conntracking, requested by many users already. 4) Add boilerplate code to allow to use nf_log infrastructure from nf_tables ingress. 5) Allow to mangle pkttype from nf_tables prerouting chain, to emulate the xtables cluster match, from Liping Zhang. 6) Move socket lookup code into generic nf_socket_* infrastructure so we can provide a native replacement for the xtables socket match. 7) Make sure nfnetlink_queue data that is updated on every packets is placed in a different cache from read-only data, from Florian Westphal. 8) Handle NF_STOLEN from nf_tables core, also from Florian Westphal. 9) Start round robin number generation in nft_numgen from zero, instead of n-1, for consistency with xtables statistics match, patch from Liping Zhang. 10) Set GFP_NOWARN flag in skbuff netlink allocations in nfnetlink_log, given we retry with a smaller allocation on failure, from Calvin Owens. 11) Cleanup xt_multiport to use switch(), from Gao feng. 12) Remove superfluous check in nft_immediate and nft_cmp, from Liping Zhang. ====================

David S. Miller committed 10 years ago

Commit 4cb551a2 parents 22ca904 886bc5031 files · +1610 −340Browse files

Unified · Split

31 files
  1. include/net/netfilter/nf_log.h +5 −0
  2. include/net/netfilter/nf_socket.h +27 −0
  3. include/net/netfilter/nft_fib.h +31 −0
  4. include/uapi/linux/netfilter/nf_tables.h +63 −0
  5. net/bridge/netfilter/Kconfig +1 −0
  6. net/bridge/netfilter/nf_log_bridge.c +1 −15
  7. net/ipv4/netfilter/Kconfig +14 −0
  8. net/ipv4/netfilter/Makefile +3 −0
  9. net/ipv4/netfilter/nf_socket_ipv4.c +163 −0
  10. net/ipv4/netfilter/nft_fib_ipv4.c +238 −0
  11. net/ipv6/netfilter/Kconfig +14 −0
  12. net/ipv6/netfilter/Makefile +3 −0
  13. net/ipv6/netfilter/nf_socket_ipv6.c +151 −0
  14. net/ipv6/netfilter/nft_fib_ipv6.c +275 −0
  15. net/netfilter/Kconfig +25 −1
  16. net/netfilter/Makefile +6 −0
  17. net/netfilter/nf_log_common.c +27 −0
  18. net/netfilter/nf_log_netdev.c +80 −0
  19. net/netfilter/nf_tables_core.c +1 −0
  20. net/netfilter/nfnetlink_log.c +1 −1
  21. net/netfilter/nfnetlink_queue.c +1 −1
  22. net/netfilter/nft_cmp.c +0 −3
  23. net/netfilter/nft_ct.c +49 −1
  24. net/netfilter/nft_fib.c +159 −0
  25. net/netfilter/nft_fib_inet.c +82 −0
  26. net/netfilter/nft_immediate.c +0 −3
  27. net/netfilter/nft_meta.c +5 −0
  28. net/netfilter/nft_numgen.c +1 −1
  29. net/netfilter/nft_rt.c +153 −0
  30. net/netfilter/xt_multiport.c +21 −19
  31. net/netfilter/xt_socket.c +10 −295
include/net/netfilter/nf_log.h+5−0
@@ -109,5 +109,10 @@ void nf_log_dump_packet_common(struct nf_log_buf *m, u_int8_t pf, · 108 unmodified lines
109 const struct net_device *out,109 const struct net_device *out,
110 const struct nf_loginfo *loginfo,110 const struct nf_loginfo *loginfo,
111 const char *prefix);111 const char *prefix);
112void nf_log_l2packet(struct net *net, u_int8_t pf, unsigned int hooknum,
113 const struct sk_buff *skb,
114 const struct net_device *in,
115 const struct net_device *out,
116 const struct nf_loginfo *loginfo, const char *prefix);
112 117
113#endif /* _NF_LOG_H */118#endif /* _NF_LOG_H */
include/net/netfilter/nf_socket.h+27−0
@@ -0,0 +1,27 @@
1#ifndef _NF_SOCK_H_
2#define _NF_SOCK_H_
3
4struct net_device;
5struct sk_buff;
6struct sock;
7struct net;
8
9static inline bool nf_sk_is_transparent(struct sock *sk)
10{
11 switch (sk->sk_state) {
12 case TCP_TIME_WAIT:
13 return inet_twsk(sk)->tw_transparent;
14 case TCP_NEW_SYN_RECV:
15 return inet_rsk(inet_reqsk(sk))->no_srccheck;
16 default:
17 return inet_sk(sk)->transparent;
18 }
19}
20
21struct sock *nf_sk_lookup_slow_v4(struct net *net, const struct sk_buff *skb,
22 const struct net_device *indev);
23
24struct sock *nf_sk_lookup_slow_v6(struct net *net, const struct sk_buff *skb,
25 const struct net_device *indev);
26
27#endif
include/net/netfilter/nft_fib.h+31−0
@@ -0,0 +1,31 @@
1#ifndef _NFT_FIB_H_
2#define _NFT_FIB_H_
3
4struct nft_fib {
5 enum nft_registers dreg:8;
6 u8 result;
7 u32 flags;
8};
9
10extern const struct nla_policy nft_fib_policy[];
11
12int nft_fib_dump(struct sk_buff *skb, const struct nft_expr *expr);
13int nft_fib_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
14 const struct nlattr * const tb[]);
15int nft_fib_validate(const struct nft_ctx *ctx, const struct nft_expr *expr,
16 const struct nft_data **data);
17
18
19void nft_fib4_eval_type(const struct nft_expr *expr, struct nft_regs *regs,
20 const struct nft_pktinfo *pkt);
21void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
22 const struct nft_pktinfo *pkt);
23
24void nft_fib6_eval_type(const struct nft_expr *expr, struct nft_regs *regs,
25 const struct nft_pktinfo *pkt);
26void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs,
27 const struct nft_pktinfo *pkt);
28
29void nft_fib_store_result(void *reg, enum nft_fib_result r,
30 const struct nft_pktinfo *pkt, int index);
31#endif
include/uapi/linux/netfilter/nf_tables.h+63−0
@@ -758,6 +758,19 @@ enum nft_meta_keys { · 757 unmodified lines
758 NFT_META_PRANDOM,758 NFT_META_PRANDOM,
759};759};
760 760
761/**
762 * enum nft_rt_keys - nf_tables routing expression keys
763 *
764 * @NFT_RT_CLASSID: realm value of packet's route (skb->dst->tclassid)
765 * @NFT_RT_NEXTHOP4: routing nexthop for IPv4
766 * @NFT_RT_NEXTHOP6: routing nexthop for IPv6
767 */
768enum nft_rt_keys {
769 NFT_RT_CLASSID,
770 NFT_RT_NEXTHOP4,
771 NFT_RT_NEXTHOP6,
772};
773
761/**774/**
762 * enum nft_hash_attributes - nf_tables hash expression netlink attributes775 * enum nft_hash_attributes - nf_tables hash expression netlink attributes
763 *776 *
@@ -796,6 +809,20 @@ enum nft_meta_attributes { · 32 unmodified lines
796};809};
797#define NFTA_META_MAX (__NFTA_META_MAX - 1)810#define NFTA_META_MAX (__NFTA_META_MAX - 1)
798 811
812/**
813 * enum nft_rt_attributes - nf_tables routing expression netlink attributes
814 *
815 * @NFTA_RT_DREG: destination register (NLA_U32)
816 * @NFTA_RT_KEY: routing data item to load (NLA_U32: nft_rt_keys)
817 */
818enum nft_rt_attributes {
819 NFTA_RT_UNSPEC,
820 NFTA_RT_DREG,
821 NFTA_RT_KEY,
822 __NFTA_RT_MAX
823};
824#define NFTA_RT_MAX (__NFTA_RT_MAX - 1)
825
799/**826/**
800 * enum nft_ct_keys - nf_tables ct expression keys827 * enum nft_ct_keys - nf_tables ct expression keys
801 *828 *
@@ -1109,6 +1136,42 @@ enum nft_gen_attributes { · 307 unmodified lines
1109};1136};
1110#define NFTA_GEN_MAX (__NFTA_GEN_MAX - 1)1137#define NFTA_GEN_MAX (__NFTA_GEN_MAX - 1)
1111 1138
1139/*
1140 * enum nft_fib_attributes - nf_tables fib expression netlink attributes
1141 *
1142 * @NFTA_FIB_DREG: destination register (NLA_U32)
1143 * @NFTA_FIB_RESULT: desired result (NLA_U32)
1144 * @NFTA_FIB_FLAGS: flowi fields to initialize when querying the FIB (NLA_U32)
1145 *
1146 * The FIB expression performs a route lookup according
1147 * to the packet data.
1148 */
1149enum nft_fib_attributes {
1150 NFTA_FIB_UNSPEC,
1151 NFTA_FIB_DREG,
1152 NFTA_FIB_RESULT,
1153 NFTA_FIB_FLAGS,
1154 __NFTA_FIB_MAX
1155};
1156#define NFTA_FIB_MAX (__NFTA_FIB_MAX - 1)
1157
1158enum nft_fib_result {
1159 NFT_FIB_RESULT_UNSPEC,
1160 NFT_FIB_RESULT_OIF,
1161 NFT_FIB_RESULT_OIFNAME,
1162 NFT_FIB_RESULT_ADDRTYPE,
1163 __NFT_FIB_RESULT_MAX
1164};
1165#define NFT_FIB_RESULT_MAX (__NFT_FIB_RESULT_MAX - 1)
1166
1167enum nft_fib_flags {
1168 NFTA_FIB_F_SADDR = 1 << 0, /* look up src */
1169 NFTA_FIB_F_DADDR = 1 << 1, /* look up dst */
1170 NFTA_FIB_F_MARK = 1 << 2, /* use skb->mark */
1171 NFTA_FIB_F_IIF = 1 << 3, /* restrict to iif */
1172 NFTA_FIB_F_OIF = 1 << 4, /* restrict to oif */
1173};
1174
1112/**1175/**
1113 * enum nft_trace_attributes - nf_tables trace netlink attributes1176 * enum nft_trace_attributes - nf_tables trace netlink attributes
1114 *1177 *
net/bridge/netfilter/Kconfig+1−0
@@ -22,6 +22,7 @@ config NFT_BRIDGE_REJECT · 21 unmodified lines
22 22
23config NF_LOG_BRIDGE23config NF_LOG_BRIDGE
24 tristate "Bridge packet logging"24 tristate "Bridge packet logging"
25 select NF_LOG_COMMON
25 26
26endif # NF_TABLES_BRIDGE27endif # NF_TABLES_BRIDGE
27 28
net/bridge/netfilter/nf_log_bridge.c+1−15
@@ -24,21 +24,7 @@ static void nf_log_bridge_packet(struct net *net, u_int8_t pf, · 23 unmodified lines
24 const struct nf_loginfo *loginfo,24 const struct nf_loginfo *loginfo,
25 const char *prefix)25 const char *prefix)
26{26{
27 switch (eth_hdr(skb)->h_proto) {27 nf_log_l2packet(net, pf, hooknum, skb, in, out, loginfo, prefix);
28 case htons(ETH_P_IP):
29 nf_log_packet(net, NFPROTO_IPV4, hooknum, skb, in, out,
30 loginfo, "%s", prefix);
31 break;
32 case htons(ETH_P_IPV6):
33 nf_log_packet(net, NFPROTO_IPV6, hooknum, skb, in, out,
34 loginfo, "%s", prefix);
35 break;
36 case htons(ETH_P_ARP):
37 case htons(ETH_P_RARP):
38 nf_log_packet(net, NFPROTO_ARP, hooknum, skb, in, out,
39 loginfo, "%s", prefix);
40 break;
41 }
42}28}
43 29
44static struct nf_logger nf_bridge_logger __read_mostly = {30static struct nf_logger nf_bridge_logger __read_mostly = {
net/ipv4/netfilter/Kconfig+14−0
@@ -25,6 +25,12 @@ config NF_CONNTRACK_IPV4 · 24 unmodified lines
25 25
26 To compile it as a module, choose M here. If unsure, say N.26 To compile it as a module, choose M here. If unsure, say N.
27 27
28config NF_SOCKET_IPV4
29 tristate "IPv4 socket lookup support"
30 help
31 This option enables the IPv4 socket lookup infrastructure. This is
32 is required by the iptables socket match.
33
28if NF_TABLES34if NF_TABLES
29 35
30config NF_TABLES_IPV436config NF_TABLES_IPV4
@@ -54,6 +60,14 @@ config NFT_DUP_IPV4 · 23 unmodified lines
54 help60 help
55 This module enables IPv4 packet duplication support for nf_tables.61 This module enables IPv4 packet duplication support for nf_tables.
56 62
63config NFT_FIB_IPV4
64 select NFT_FIB
65 tristate "nf_tables fib / ip route lookup support"
66 help
67 This module enables IPv4 FIB lookups, e.g. for reverse path filtering.
68 It also allows query of the FIB for the route type, e.g. local, unicast,
69 multicast or blackhole.
70
57endif # NF_TABLES_IPV471endif # NF_TABLES_IPV4
58 72
59config NF_TABLES_ARP73config NF_TABLES_ARP
net/ipv4/netfilter/Makefile+3−0
@@ -14,6 +14,8 @@ obj-$(CONFIG_NF_NAT_IPV4) += nf_nat_ipv4.o · 13 unmodified lines
14# defrag14# defrag
15obj-$(CONFIG_NF_DEFRAG_IPV4) += nf_defrag_ipv4.o15obj-$(CONFIG_NF_DEFRAG_IPV4) += nf_defrag_ipv4.o
16 16
17obj-$(CONFIG_NF_SOCKET_IPV4) += nf_socket_ipv4.o
18
17# logging19# logging
18obj-$(CONFIG_NF_LOG_ARP) += nf_log_arp.o20obj-$(CONFIG_NF_LOG_ARP) += nf_log_arp.o
19obj-$(CONFIG_NF_LOG_IPV4) += nf_log_ipv4.o21obj-$(CONFIG_NF_LOG_IPV4) += nf_log_ipv4.o
@@ -34,6 +36,7 @@ obj-$(CONFIG_NF_TABLES_IPV4) += nf_tables_ipv4.o · 14 unmodified lines
34obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV4) += nft_chain_route_ipv4.o36obj-$(CONFIG_NFT_CHAIN_ROUTE_IPV4) += nft_chain_route_ipv4.o
35obj-$(CONFIG_NFT_CHAIN_NAT_IPV4) += nft_chain_nat_ipv4.o37obj-$(CONFIG_NFT_CHAIN_NAT_IPV4) += nft_chain_nat_ipv4.o
36obj-$(CONFIG_NFT_REJECT_IPV4) += nft_reject_ipv4.o38obj-$(CONFIG_NFT_REJECT_IPV4) += nft_reject_ipv4.o
39obj-$(CONFIG_NFT_FIB_IPV4) += nft_fib_ipv4.o
37obj-$(CONFIG_NFT_MASQ_IPV4) += nft_masq_ipv4.o40obj-$(CONFIG_NFT_MASQ_IPV4) += nft_masq_ipv4.o
38obj-$(CONFIG_NFT_REDIR_IPV4) += nft_redir_ipv4.o41obj-$(CONFIG_NFT_REDIR_IPV4) += nft_redir_ipv4.o
39obj-$(CONFIG_NFT_DUP_IPV4) += nft_dup_ipv4.o42obj-$(CONFIG_NFT_DUP_IPV4) += nft_dup_ipv4.o
net/ipv4/netfilter/nf_socket_ipv4.c+163−0
@@ -0,0 +1,163 @@
1/*
2 * Copyright (C) 2007-2008 BalaBit IT Ltd.
3 * Author: Krisztian Kovacs
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 */
10#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11#include <linux/module.h>
12#include <linux/skbuff.h>
13#include <net/tcp.h>
14#include <net/udp.h>
15#include <net/icmp.h>
16#include <net/sock.h>
17#include <net/inet_sock.h>
18#include <net/netfilter/nf_socket.h>
19#if IS_ENABLED(CONFIG_NF_CONNTRACK)
20#include <net/netfilter/nf_conntrack.h>
21#endif
22
23static int
24extract_icmp4_fields(const struct sk_buff *skb, u8 *protocol,
25 __be32 *raddr, __be32 *laddr,
26 __be16 *rport, __be16 *lport)
27{
28 unsigned int outside_hdrlen = ip_hdrlen(skb);
29 struct iphdr *inside_iph, _inside_iph;
30 struct icmphdr *icmph, _icmph;
31 __be16 *ports, _ports[2];
32
33 icmph = skb_header_pointer(skb, outside_hdrlen,
34 sizeof(_icmph), &_icmph);
35 if (icmph == NULL)
36 return 1;
37
38 switch (icmph->type) {
39 case ICMP_DEST_UNREACH:
40 case ICMP_SOURCE_QUENCH:
41 case ICMP_REDIRECT:
42 case ICMP_TIME_EXCEEDED:
43 case ICMP_PARAMETERPROB:
44 break;
45 default:
46 return 1;
47 }
48
49 inside_iph = skb_header_pointer(skb, outside_hdrlen +
50 sizeof(struct icmphdr),
51 sizeof(_inside_iph), &_inside_iph);
52 if (inside_iph == NULL)
53 return 1;
54
55 if (inside_iph->protocol != IPPROTO_TCP &&
56 inside_iph->protocol != IPPROTO_UDP)
57 return 1;
58
59 ports = skb_header_pointer(skb, outside_hdrlen +
60 sizeof(struct icmphdr) +
61 (inside_iph->ihl << 2),
62 sizeof(_ports), &_ports);
63 if (ports == NULL)
64 return 1;
65
66 /* the inside IP packet is the one quoted from our side, thus
67 * its saddr is the local address */
68 *protocol = inside_iph->protocol;
69 *laddr = inside_iph->saddr;
70 *lport = ports[0];
71 *raddr = inside_iph->daddr;
72 *rport = ports[1];
73
74 return 0;
75}
76
77static struct sock *
78nf_socket_get_sock_v4(struct net *net, struct sk_buff *skb, const int doff,
79 const u8 protocol,
80 const __be32 saddr, const __be32 daddr,
81 const __be16 sport, const __be16 dport,
82 const struct net_device *in)
83{
84 switch (protocol) {
85 case IPPROTO_TCP:
86 return inet_lookup(net, &tcp_hashinfo, skb, doff,
87 saddr, sport, daddr, dport,
88 in->ifindex);
89 case IPPROTO_UDP:
90 return udp4_lib_lookup(net, saddr, sport, daddr, dport,
91 in->ifindex);
92 }
93 return NULL;
94}
95
96struct sock *nf_sk_lookup_slow_v4(struct net *net, const struct sk_buff *skb,
97 const struct net_device *indev)
98{
99 __be32 uninitialized_var(daddr), uninitialized_var(saddr);
100 __be16 uninitialized_var(dport), uninitialized_var(sport);
101 const struct iphdr *iph = ip_hdr(skb);
102 struct sk_buff *data_skb = NULL;
103 u8 uninitialized_var(protocol);
104#if IS_ENABLED(CONFIG_NF_CONNTRACK)
105 enum ip_conntrack_info ctinfo;
106 struct nf_conn const *ct;
107#endif
108 int doff = 0;
109
110 if (iph->protocol == IPPROTO_UDP || iph->protocol == IPPROTO_TCP) {
111 struct udphdr _hdr, *hp;
112
113 hp = skb_header_pointer(skb, ip_hdrlen(skb),
114 sizeof(_hdr), &_hdr);
115 if (hp == NULL)
116 return NULL;
117
118 protocol = iph->protocol;
119 saddr = iph->saddr;
120 sport = hp->source;
121 daddr = iph->daddr;
122 dport = hp->dest;
123 data_skb = (struct sk_buff *)skb;
124 doff = iph->protocol == IPPROTO_TCP ?
125 ip_hdrlen(skb) + __tcp_hdrlen((struct tcphdr *)hp) :
126 ip_hdrlen(skb) + sizeof(*hp);
127
128 } else if (iph->protocol == IPPROTO_ICMP) {
129 if (extract_icmp4_fields(skb, &protocol, &saddr, &daddr,
130 &sport, &dport))
131 return NULL;
132 } else {
133 return NULL;
134 }
135
136#if IS_ENABLED(CONFIG_NF_CONNTRACK)
137 /* Do the lookup with the original socket address in
138 * case this is a reply packet of an established
139 * SNAT-ted connection.
140 */
141 ct = nf_ct_get(skb, &ctinfo);
142 if (ct && !nf_ct_is_untracked(ct) &&
143 ((iph->protocol != IPPROTO_ICMP &&
144 ctinfo == IP_CT_ESTABLISHED_REPLY) ||
145 (iph->protocol == IPPROTO_ICMP &&
146 ctinfo == IP_CT_RELATED_REPLY)) &&
147 (ct->status & IPS_SRC_NAT_DONE)) {
148
149 daddr = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip;
150 dport = (iph->protocol == IPPROTO_TCP) ?
151 ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u.tcp.port :
152 ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u.udp.port;
153 }
154#endif
155
156 return nf_socket_get_sock_v4(net, data_skb, doff, protocol, saddr,
157 daddr, sport, dport, indev);
158}
159EXPORT_SYMBOL_GPL(nf_sk_lookup_slow_v4);
160
161MODULE_LICENSE("GPL");
162MODULE_AUTHOR("Krisztian Kovacs, Balazs Scheidler");
163MODULE_DESCRIPTION("Netfilter IPv4 socket lookup infrastructure");
net/ipv4/netfilter/nft_fib_ipv4.c+238−0
@@ -0,0 +1,238 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
5 */
6
7#include <linux/kernel.h>
8#include <linux/init.h>
9#include <linux/module.h>
10#include <linux/netlink.h>
11#include <linux/netfilter.h>
12#include <linux/netfilter/nf_tables.h>
13#include <net/netfilter/nf_tables_core.h>
14#include <net/netfilter/nf_tables.h>
15#include <net/netfilter/nft_fib.h>
16
17#include <net/ip_fib.h>
18#include <net/route.h>
19
20/* don't try to find route from mcast/bcast/zeronet */
21static __be32 get_saddr(__be32 addr)
22{
23 if (ipv4_is_multicast(addr) || ipv4_is_lbcast(addr) ||
24 ipv4_is_zeronet(addr))
25 return 0;
26 return addr;
27}
28
29static bool fib4_is_local(const struct sk_buff *skb)
30{
31 const struct rtable *rt = skb_rtable(skb);
32
33 return rt && (rt->rt_flags & RTCF_LOCAL);
34}
35
36#define DSCP_BITS 0xfc
37
38void nft_fib4_eval_type(const struct nft_expr *expr, struct nft_regs *regs,
39 const struct nft_pktinfo *pkt)
40{
41 const struct nft_fib *priv = nft_expr_priv(expr);
42 u32 *dst = &regs->data[priv->dreg];
43 const struct net_device *dev = NULL;
44 const struct iphdr *iph;
45 __be32 addr;
46
47 if (priv->flags & NFTA_FIB_F_IIF)
48 dev = pkt->in;
49 else if (priv->flags & NFTA_FIB_F_OIF)
50 dev = pkt->out;
51
52 iph = ip_hdr(pkt->skb);
53 if (priv->flags & NFTA_FIB_F_DADDR)
54 addr = iph->daddr;
55 else
56 addr = iph->saddr;
57
58 *dst = inet_dev_addr_type(pkt->net, dev, addr);
59}
60EXPORT_SYMBOL_GPL(nft_fib4_eval_type);
61
62static int get_ifindex(const struct net_device *dev)
63{
64 return dev ? dev->ifindex : 0;
65}
66
67void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
68 const struct nft_pktinfo *pkt)
69{
70 const struct nft_fib *priv = nft_expr_priv(expr);
71 u32 *dest = &regs->data[priv->dreg];
72 const struct iphdr *iph;
73 struct fib_result res;
74 struct flowi4 fl4 = {
75 .flowi4_scope = RT_SCOPE_UNIVERSE,
76 .flowi4_iif = LOOPBACK_IFINDEX,
77 };
78 const struct net_device *oif;
79 struct net_device *found;
80#ifdef CONFIG_IP_ROUTE_MULTIPATH
81 int i;
82#endif
83
84 /*
85 * Do not set flowi4_oif, it restricts results (for example, asking
86 * for oif 3 will get RTN_UNICAST result even if the daddr exits
87 * on another interface.
88 *
89 * Search results for the desired outinterface instead.
90 */
91 if (priv->flags & NFTA_FIB_F_OIF)
92 oif = pkt->out;
93 else if (priv->flags & NFTA_FIB_F_IIF)
94 oif = pkt->in;
95 else
96 oif = NULL;
97
98 if (pkt->hook == NF_INET_PRE_ROUTING && fib4_is_local(pkt->skb)) {
99 nft_fib_store_result(dest, priv->result, pkt, LOOPBACK_IFINDEX);
100 return;
101 }
102
103 iph = ip_hdr(pkt->skb);
104 if (ipv4_is_multicast(iph->daddr) &&
105 ipv4_is_zeronet(iph->saddr) &&
106 ipv4_is_local_multicast(iph->daddr)) {
107 nft_fib_store_result(dest, priv->result, pkt,
108 get_ifindex(pkt->skb->dev));
109 return;
110 }
111
112 if (priv->flags & NFTA_FIB_F_MARK)
113 fl4.flowi4_mark = pkt->skb->mark;
114
115 fl4.flowi4_tos = iph->tos & DSCP_BITS;
116
117 if (priv->flags & NFTA_FIB_F_DADDR) {
118 fl4.daddr = iph->daddr;
119 fl4.saddr = get_saddr(iph->saddr);
120 } else {
121 fl4.daddr = iph->saddr;
122 fl4.saddr = get_saddr(iph->daddr);
123 }
124
125 if (fib_lookup(pkt->net, &fl4, &res, FIB_LOOKUP_IGNORE_LINKSTATE))
126 return;
127
128 switch (res.type) {
129 case RTN_UNICAST:
130 break;
131 case RTN_LOCAL: /* should not appear here, see fib4_is_local() above */
132 return;
133 default:
134 break;
135 }
136
137 if (!oif) {
138 found = FIB_RES_DEV(res);
139 goto ok;
140 }
141
142#ifdef CONFIG_IP_ROUTE_MULTIPATH
143 for (i = 0; i < res.fi->fib_nhs; i++) {
144 struct fib_nh *nh = &res.fi->fib_nh[i];
145
146 if (nh->nh_dev == oif) {
147 found = nh->nh_dev;
148 goto ok;
149 }
150 }
151 return;
152#else
153 found = FIB_RES_DEV(res);
154 if (found != oif)
155 return;
156#endif
157ok:
158 switch (priv->result) {
159 case NFT_FIB_RESULT_OIF:
160 *dest = found->ifindex;
161 break;
162 case NFT_FIB_RESULT_OIFNAME:
163 strncpy((char *)dest, found->name, IFNAMSIZ);
164 break;
165 default:
166 WARN_ON_ONCE(1);
167 break;
168 }
169}
170EXPORT_SYMBOL_GPL(nft_fib4_eval);
171
172static struct nft_expr_type nft_fib4_type;
173
174static const struct nft_expr_ops nft_fib4_type_ops = {
175 .type = &nft_fib4_type,
176 .size = NFT_EXPR_SIZE(sizeof(struct nft_fib)),
177 .eval = nft_fib4_eval_type,
178 .init = nft_fib_init,
179 .dump = nft_fib_dump,
180 .validate = nft_fib_validate,
181};
182
183static const struct nft_expr_ops nft_fib4_ops = {
184 .type = &nft_fib4_type,
185 .size = NFT_EXPR_SIZE(sizeof(struct nft_fib)),
186 .eval = nft_fib4_eval,
187 .init = nft_fib_init,
188 .dump = nft_fib_dump,
189 .validate = nft_fib_validate,
190};
191
192static const struct nft_expr_ops *
193nft_fib4_select_ops(const struct nft_ctx *ctx,
194 const struct nlattr * const tb[])
195{
196 enum nft_fib_result result;
197
198 if (!tb[NFTA_FIB_RESULT])
199 return ERR_PTR(-EINVAL);
200
201 result = htonl(nla_get_be32(tb[NFTA_FIB_RESULT]));
202
203 switch (result) {
204 case NFT_FIB_RESULT_OIF:
205 return &nft_fib4_ops;
206 case NFT_FIB_RESULT_OIFNAME:
207 return &nft_fib4_ops;
208 case NFT_FIB_RESULT_ADDRTYPE:
209 return &nft_fib4_type_ops;
210 default:
211 return ERR_PTR(-EOPNOTSUPP);
212 }
213}
214
215static struct nft_expr_type nft_fib4_type __read_mostly = {
216 .name = "fib",
217 .select_ops = &nft_fib4_select_ops,
218 .policy = nft_fib_policy,
219 .maxattr = NFTA_FIB_MAX,
220 .family = NFPROTO_IPV4,
221 .owner = THIS_MODULE,
222};
223
224static int __init nft_fib4_module_init(void)
225{
226 return nft_register_expr(&nft_fib4_type);
227}
228
229static void __exit nft_fib4_module_exit(void)
230{
231 nft_unregister_expr(&nft_fib4_type);
232}
233
234module_init(nft_fib4_module_init);
235module_exit(nft_fib4_module_exit);
236MODULE_LICENSE("GPL");
237MODULE_AUTHOR("Florian Westphal <fw@strlen.de>");
238MODULE_ALIAS_NFT_AF_EXPR(2, "fib");
net/ipv6/netfilter/Kconfig+14−0
@@ -25,6 +25,12 @@ config NF_CONNTRACK_IPV6 · 24 unmodified lines
25 25
26 To compile it as a module, choose M here. If unsure, say N.26 To compile it as a module, choose M here. If unsure, say N.
27 27
28config NF_SOCKET_IPV6
29 tristate "IPv6 socket lookup support"
30 help
31 This option enables the IPv6 socket lookup infrastructure. This
32 is used by the ip6tables socket match.
33
28if NF_TABLES34if NF_TABLES
29 35
30config NF_TABLES_IPV636config NF_TABLES_IPV6
@@ -54,6 +60,14 @@ config NFT_DUP_IPV6 · 23 unmodified lines
54 help60 help
55 This module enables IPv6 packet duplication support for nf_tables.61 This module enables IPv6 packet duplication support for nf_tables.
56 62
63config NFT_FIB_IPV6
64 tristate "nf_tables fib / ipv6 route lookup support"
65 select NFT_FIB
66 help
67 This module enables IPv6 FIB lookups, e.g. for reverse path filtering.
68 It also allows query of the FIB for the route type, e.g. local, unicast,
69 multicast or blackhole.
70
57endif # NF_TABLES_IPV671endif # NF_TABLES_IPV6
58endif # NF_TABLES72endif # NF_TABLES
59 73
net/ipv6/netfilter/Makefile+3−0
@@ -24,6 +24,8 @@ obj-$(CONFIG_NF_NAT_MASQUERADE_IPV6) += nf_nat_masquerade_ipv6.o · 23 unmodified lines
24nf_defrag_ipv6-y := nf_defrag_ipv6_hooks.o nf_conntrack_reasm.o24nf_defrag_ipv6-y := nf_defrag_ipv6_hooks.o nf_conntrack_reasm.o
25obj-$(CONFIG_NF_DEFRAG_IPV6) += nf_defrag_ipv6.o25obj-$(CONFIG_NF_DEFRAG_IPV6) += nf_defrag_ipv6.o
26 26
27obj-$(CONFIG_NF_SOCKET_IPV6) += nf_socket_ipv6.o
28
27# logging29# logging
28obj-$(CONFIG_NF_LOG_IPV6) += nf_log_ipv6.o30obj-$(CONFIG_NF_LOG_IPV6) += nf_log_ipv6.o
29 31
@@ -40,6 +42,7 @@ obj-$(CONFIG_NFT_REJECT_IPV6) += nft_reject_ipv6.o · 10 unmodified lines
40obj-$(CONFIG_NFT_MASQ_IPV6) += nft_masq_ipv6.o42obj-$(CONFIG_NFT_MASQ_IPV6) += nft_masq_ipv6.o
41obj-$(CONFIG_NFT_REDIR_IPV6) += nft_redir_ipv6.o43obj-$(CONFIG_NFT_REDIR_IPV6) += nft_redir_ipv6.o
42obj-$(CONFIG_NFT_DUP_IPV6) += nft_dup_ipv6.o44obj-$(CONFIG_NFT_DUP_IPV6) += nft_dup_ipv6.o
45obj-$(CONFIG_NFT_FIB_IPV6) += nft_fib_ipv6.o
43 46
44# matches47# matches
45obj-$(CONFIG_IP6_NF_MATCH_AH) += ip6t_ah.o48obj-$(CONFIG_IP6_NF_MATCH_AH) += ip6t_ah.o
net/ipv6/netfilter/nf_socket_ipv6.c+151−0
@@ -0,0 +1,151 @@
1/*
2 * Copyright (C) 2007-2008 BalaBit IT Ltd.
3 * Author: Krisztian Kovacs
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 */
10#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11#include <linux/module.h>
12#include <linux/skbuff.h>
13#include <net/tcp.h>
14#include <net/udp.h>
15#include <net/icmp.h>
16#include <net/sock.h>
17#include <net/inet_sock.h>
18#include <net/inet6_hashtables.h>
19#include <net/netfilter/ipv6/nf_defrag_ipv6.h>
20#include <net/netfilter/nf_socket.h>
21#if IS_ENABLED(CONFIG_NF_CONNTRACK)
22#include <net/netfilter/nf_conntrack.h>
23#endif
24
25static int
26extract_icmp6_fields(const struct sk_buff *skb,
27 unsigned int outside_hdrlen,
28 int *protocol,
29 const struct in6_addr **raddr,
30 const struct in6_addr **laddr,
31 __be16 *rport,
32 __be16 *lport,
33 struct ipv6hdr *ipv6_var)
34{
35 const struct ipv6hdr *inside_iph;
36 struct icmp6hdr *icmph, _icmph;
37 __be16 *ports, _ports[2];
38 u8 inside_nexthdr;
39 __be16 inside_fragoff;
40 int inside_hdrlen;
41
42 icmph = skb_header_pointer(skb, outside_hdrlen,
43 sizeof(_icmph), &_icmph);
44 if (icmph == NULL)
45 return 1;
46
47 if (icmph->icmp6_type & ICMPV6_INFOMSG_MASK)
48 return 1;
49
50 inside_iph = skb_header_pointer(skb, outside_hdrlen + sizeof(_icmph),
51 sizeof(*ipv6_var), ipv6_var);
52 if (inside_iph == NULL)
53 return 1;
54 inside_nexthdr = inside_iph->nexthdr;
55
56 inside_hdrlen = ipv6_skip_exthdr(skb, outside_hdrlen + sizeof(_icmph) +
57 sizeof(*ipv6_var),
58 &inside_nexthdr, &inside_fragoff);
59 if (inside_hdrlen < 0)
60 return 1; /* hjm: Packet has no/incomplete transport layer headers. */
61
62 if (inside_nexthdr != IPPROTO_TCP &&
63 inside_nexthdr != IPPROTO_UDP)
64 return 1;
65
66 ports = skb_header_pointer(skb, inside_hdrlen,
67 sizeof(_ports), &_ports);
68 if (ports == NULL)
69 return 1;
70
71 /* the inside IP packet is the one quoted from our side, thus
72 * its saddr is the local address */
73 *protocol = inside_nexthdr;
74 *laddr = &inside_iph->saddr;
75 *lport = ports[0];
76 *raddr = &inside_iph->daddr;
77 *rport = ports[1];
78
79 return 0;
80}
81
82static struct sock *
83nf_socket_get_sock_v6(struct net *net, struct sk_buff *skb, int doff,
84 const u8 protocol,
85 const struct in6_addr *saddr, const struct in6_addr *daddr,
86 const __be16 sport, const __be16 dport,
87 const struct net_device *in)
88{
89 switch (protocol) {
90 case IPPROTO_TCP:
91 return inet6_lookup(net, &tcp_hashinfo, skb, doff,
92 saddr, sport, daddr, dport,
93 in->ifindex);
94 case IPPROTO_UDP:
95 return udp6_lib_lookup(net, saddr, sport, daddr, dport,
96 in->ifindex);
97 }
98
99 return NULL;
100}
101
102struct sock *nf_sk_lookup_slow_v6(struct net *net, const struct sk_buff *skb,
103 const struct net_device *indev)
104{
105 __be16 uninitialized_var(dport), uninitialized_var(sport);
106 const struct in6_addr *daddr = NULL, *saddr = NULL;
107 struct ipv6hdr *iph = ipv6_hdr(skb);
108 struct sk_buff *data_skb = NULL;
109 int doff = 0;
110 int thoff = 0, tproto;
111
112 tproto = ipv6_find_hdr(skb, &thoff, -1, NULL, NULL);
113 if (tproto < 0) {
114 pr_debug("unable to find transport header in IPv6 packet, dropping\n");
115 return NULL;
116 }
117
118 if (tproto == IPPROTO_UDP || tproto == IPPROTO_TCP) {
119 struct udphdr _hdr, *hp;
120
121 hp = skb_header_pointer(skb, thoff, sizeof(_hdr), &_hdr);
122 if (hp == NULL)
123 return NULL;
124
125 saddr = &iph->saddr;
126 sport = hp->source;
127 daddr = &iph->daddr;
128 dport = hp->dest;
129 data_skb = (struct sk_buff *)skb;
130 doff = tproto == IPPROTO_TCP ?
131 thoff + __tcp_hdrlen((struct tcphdr *)hp) :
132 thoff + sizeof(*hp);
133
134 } else if (tproto == IPPROTO_ICMPV6) {
135 struct ipv6hdr ipv6_var;
136
137 if (extract_icmp6_fields(skb, thoff, &tproto, &saddr, &daddr,
138 &sport, &dport, &ipv6_var))
139 return NULL;
140 } else {
141 return NULL;
142 }
143
144 return nf_socket_get_sock_v6(net, data_skb, doff, tproto, saddr, daddr,
145 sport, dport, indev);
146}
147EXPORT_SYMBOL_GPL(nf_sk_lookup_slow_v6);
148
149MODULE_LICENSE("GPL");
150MODULE_AUTHOR("Krisztian Kovacs, Balazs Scheidler");
151MODULE_DESCRIPTION("Netfilter IPv6 socket lookup infrastructure");
net/ipv6/netfilter/nft_fib_ipv6.c+275−0
@@ -0,0 +1,275 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
5 */
6
7#include <linux/kernel.h>
8#include <linux/init.h>
9#include <linux/module.h>
10#include <linux/netlink.h>
11#include <linux/netfilter.h>
12#include <linux/netfilter/nf_tables.h>
13#include <linux/netfilter_ipv6.h>
14#include <net/netfilter/nf_tables_core.h>
15#include <net/netfilter/nf_tables.h>
16#include <net/netfilter/nft_fib.h>
17
18#include <net/ip6_fib.h>
19#include <net/ip6_route.h>
20
21static bool fib6_is_local(const struct sk_buff *skb)
22{
23 const struct rt6_info *rt = (const void *)skb_dst(skb);
24
25 return rt && (rt->rt6i_flags & RTF_LOCAL);
26}
27
28static int get_ifindex(const struct net_device *dev)
29{
30 return dev ? dev->ifindex : 0;
31}
32
33static int nft_fib6_flowi_init(struct flowi6 *fl6, const struct nft_fib *priv,
34 const struct nft_pktinfo *pkt,
35 const struct net_device *dev)
36{
37 const struct ipv6hdr *iph = ipv6_hdr(pkt->skb);
38 int lookup_flags = 0;
39
40 if (priv->flags & NFTA_FIB_F_DADDR) {
41 fl6->daddr = iph->daddr;
42 fl6->saddr = iph->saddr;
43 } else {
44 fl6->daddr = iph->saddr;
45 fl6->saddr = iph->daddr;
46 }
47
48 if (ipv6_addr_type(&fl6->daddr) & IPV6_ADDR_LINKLOCAL) {
49 lookup_flags |= RT6_LOOKUP_F_IFACE;
50 fl6->flowi6_oif = get_ifindex(dev ? dev : pkt->skb->dev);
51 }
52
53 if (ipv6_addr_type(&fl6->saddr) & IPV6_ADDR_UNICAST)
54 lookup_flags |= RT6_LOOKUP_F_HAS_SADDR;
55
56 if (priv->flags & NFTA_FIB_F_MARK)
57 fl6->flowi6_mark = pkt->skb->mark;
58
59 fl6->flowlabel = (*(__be32 *)iph) & IPV6_FLOWINFO_MASK;
60
61 return lookup_flags;
62}
63
64static u32 __nft_fib6_eval_type(const struct nft_fib *priv,
65 const struct nft_pktinfo *pkt)
66{
67 const struct net_device *dev = NULL;
68 const struct nf_ipv6_ops *v6ops;
69 const struct nf_afinfo *afinfo;
70 int route_err, addrtype;
71 struct rt6_info *rt;
72 struct flowi6 fl6 = {
73 .flowi6_iif = LOOPBACK_IFINDEX,
74 .flowi6_proto = pkt->tprot,
75 };
76 u32 ret = 0;
77
78 afinfo = nf_get_afinfo(NFPROTO_IPV6);
79 if (!afinfo)
80 return RTN_UNREACHABLE;
81
82 if (priv->flags & NFTA_FIB_F_IIF)
83 dev = pkt->in;
84 else if (priv->flags & NFTA_FIB_F_OIF)
85 dev = pkt->out;
86
87 nft_fib6_flowi_init(&fl6, priv, pkt, dev);
88
89 v6ops = nf_get_ipv6_ops();
90 if (dev && v6ops && v6ops->chk_addr(pkt->net, &fl6.daddr, dev, true))
91 ret = RTN_LOCAL;
92
93 route_err = afinfo->route(pkt->net, (struct dst_entry **)&rt,
94 flowi6_to_flowi(&fl6), false);
95 if (route_err)
96 goto err;
97
98 if (rt->rt6i_flags & RTF_REJECT) {
99 route_err = rt->dst.error;
100 dst_release(&rt->dst);
101 goto err;
102 }
103
104 if (ipv6_anycast_destination((struct dst_entry *)rt, &fl6.daddr))
105 ret = RTN_ANYCAST;
106 else if (!dev && rt->rt6i_flags & RTF_LOCAL)
107 ret = RTN_LOCAL;
108
109 dst_release(&rt->dst);
110
111 if (ret)
112 return ret;
113
114 addrtype = ipv6_addr_type(&fl6.daddr);
115
116 if (addrtype & IPV6_ADDR_MULTICAST)
117 return RTN_MULTICAST;
118 if (addrtype & IPV6_ADDR_UNICAST)
119 return RTN_UNICAST;
120
121 return RTN_UNSPEC;
122 err:
123 switch (route_err) {
124 case -EINVAL:
125 return RTN_BLACKHOLE;
126 case -EACCES:
127 return RTN_PROHIBIT;
128 case -EAGAIN:
129 return RTN_THROW;
130 default:
131 break;
132 }
133
134 return RTN_UNREACHABLE;
135}
136
137void nft_fib6_eval_type(const struct nft_expr *expr, struct nft_regs *regs,
138 const struct nft_pktinfo *pkt)
139{
140 const struct nft_fib *priv = nft_expr_priv(expr);
141 u32 *dest = &regs->data[priv->dreg];
142
143 *dest = __nft_fib6_eval_type(priv, pkt);
144}
145EXPORT_SYMBOL_GPL(nft_fib6_eval_type);
146
147void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs,
148 const struct nft_pktinfo *pkt)
149{
150 const struct nft_fib *priv = nft_expr_priv(expr);
151 const struct net_device *oif = NULL;
152 u32 *dest = &regs->data[priv->dreg];
153 struct flowi6 fl6 = {
154 .flowi6_iif = LOOPBACK_IFINDEX,
155 .flowi6_proto = pkt->tprot,
156 };
157 struct rt6_info *rt;
158 int lookup_flags;
159
160 if (priv->flags & NFTA_FIB_F_IIF)
161 oif = pkt->in;
162 else if (priv->flags & NFTA_FIB_F_OIF)
163 oif = pkt->out;
164
165 lookup_flags = nft_fib6_flowi_init(&fl6, priv, pkt, oif);
166
167 if (pkt->hook == NF_INET_PRE_ROUTING && fib6_is_local(pkt->skb)) {
168 nft_fib_store_result(dest, priv->result, pkt, LOOPBACK_IFINDEX);
169 return;
170 }
171
172 *dest = 0;
173 again:
174 rt = (void *)ip6_route_lookup(pkt->net, &fl6, lookup_flags);
175 if (rt->dst.error)
176 goto put_rt_err;
177
178 /* Should not see RTF_LOCAL here */
179 if (rt->rt6i_flags & (RTF_REJECT | RTF_ANYCAST | RTF_LOCAL))
180 goto put_rt_err;
181
182 if (oif && oif != rt->rt6i_idev->dev) {
183 /* multipath route? Try again with F_IFACE */
184 if ((lookup_flags & RT6_LOOKUP_F_IFACE) == 0) {
185 lookup_flags |= RT6_LOOKUP_F_IFACE;
186 fl6.flowi6_oif = oif->ifindex;
187 ip6_rt_put(rt);
188 goto again;
189 }
190 }
191
192 switch (priv->result) {
193 case NFT_FIB_RESULT_OIF:
194 *dest = rt->rt6i_idev->dev->ifindex;
195 break;
196 case NFT_FIB_RESULT_OIFNAME:
197 strncpy((char *)dest, rt->rt6i_idev->dev->name, IFNAMSIZ);
198 break;
199 default:
200 WARN_ON_ONCE(1);
201 break;
202 }
203
204 put_rt_err:
205 ip6_rt_put(rt);
206}
207EXPORT_SYMBOL_GPL(nft_fib6_eval);
208
209static struct nft_expr_type nft_fib6_type;
210
211static const struct nft_expr_ops nft_fib6_type_ops = {
212 .type = &nft_fib6_type,
213 .size = NFT_EXPR_SIZE(sizeof(struct nft_fib)),
214 .eval = nft_fib6_eval_type,
215 .init = nft_fib_init,
216 .dump = nft_fib_dump,
217 .validate = nft_fib_validate,
218};
219
220static const struct nft_expr_ops nft_fib6_ops = {
221 .type = &nft_fib6_type,
222 .size = NFT_EXPR_SIZE(sizeof(struct nft_fib)),
223 .eval = nft_fib6_eval,
224 .init = nft_fib_init,
225 .dump = nft_fib_dump,
226 .validate = nft_fib_validate,
227};
228
229static const struct nft_expr_ops *
230nft_fib6_select_ops(const struct nft_ctx *ctx,
231 const struct nlattr * const tb[])
232{
233 enum nft_fib_result result;
234
235 if (!tb[NFTA_FIB_RESULT])
236 return ERR_PTR(-EINVAL);
237
238 result = htonl(nla_get_be32(tb[NFTA_FIB_RESULT]));
239
240 switch (result) {
241 case NFT_FIB_RESULT_OIF:
242 return &nft_fib6_ops;
243 case NFT_FIB_RESULT_OIFNAME:
244 return &nft_fib6_ops;
245 case NFT_FIB_RESULT_ADDRTYPE:
246 return &nft_fib6_type_ops;
247 default:
248 return ERR_PTR(-EOPNOTSUPP);
249 }
250}
251
252static struct nft_expr_type nft_fib6_type __read_mostly = {
253 .name = "fib",
254 .select_ops = &nft_fib6_select_ops,
255 .policy = nft_fib_policy,
256 .maxattr = NFTA_FIB_MAX,
257 .family = NFPROTO_IPV6,
258 .owner = THIS_MODULE,
259};
260
261static int __init nft_fib6_module_init(void)
262{
263 return nft_register_expr(&nft_fib6_type);
264}
265
266static void __exit nft_fib6_module_exit(void)
267{
268 nft_unregister_expr(&nft_fib6_type);
269}
270module_init(nft_fib6_module_init);
271module_exit(nft_fib6_module_exit);
272
273MODULE_LICENSE("GPL");
274MODULE_AUTHOR("Florian Westphal <fw@strlen.de>");
275MODULE_ALIAS_NFT_AF_EXPR(10, "fib");
net/netfilter/Kconfig+25−1
@@ -57,6 +57,10 @@ config NF_CONNTRACK · 56 unmodified lines
57config NF_LOG_COMMON57config NF_LOG_COMMON
58 tristate58 tristate
59 59
60config NF_LOG_NETDEV
61 tristate "Netdev packet logging"
62 select NF_LOG_COMMON
63
60if NF_CONNTRACK64if NF_CONNTRACK
61 65
62config NF_CONNTRACK_MARK66config NF_CONNTRACK_MARK
@@ -474,6 +478,12 @@ config NFT_META · 411 unmodified lines
474 This option adds the "meta" expression that you can use to match and478 This option adds the "meta" expression that you can use to match and
475 to set packet metainformation such as the packet mark.479 to set packet metainformation such as the packet mark.
476 480
481config NFT_RT
482 tristate "Netfilter nf_tables routing module"
483 help
484 This option adds the "rt" expression that you can use to match
485 packet routing information such as the packet nexthop.
486
477config NFT_NUMGEN487config NFT_NUMGEN
478 tristate "Netfilter nf_tables number generator module"488 tristate "Netfilter nf_tables number generator module"
479 help489 help
@@ -581,6 +591,19 @@ config NFT_HASH · 101 unmodified lines
581 This option adds the "hash" expression that you can use to perform591 This option adds the "hash" expression that you can use to perform
582 a hash operation on registers.592 a hash operation on registers.
583 593
594config NFT_FIB
595 tristate
596
597config NFT_FIB_INET
598 depends on NF_TABLES_INET
599 depends on NFT_FIB_IPV4
600 depends on NFT_FIB_IPV6
601 tristate "Netfilter nf_tables fib inet support"
602 help
603 This option allows using the FIB expression from the inet table.
604 The lookup will be delegated to the IPv4 or IPv6 FIB depending
605 on the protocol of the packet.
606
584if NF_TABLES_NETDEV607if NF_TABLES_NETDEV
585 608
586config NF_DUP_NETDEV609config NF_DUP_NETDEV
@@ -1409,9 +1432,10 @@ config NETFILTER_XT_MATCH_SOCKET · 822 unmodified lines
1409 tristate '"socket" match support'1432 tristate '"socket" match support'
1410 depends on NETFILTER_XTABLES1433 depends on NETFILTER_XTABLES
1411 depends on NETFILTER_ADVANCED1434 depends on NETFILTER_ADVANCED
1412 depends on !NF_CONNTRACK || NF_CONNTRACK
1413 depends on IPV6 || IPV6=n1435 depends on IPV6 || IPV6=n
1414 depends on IP6_NF_IPTABLES || IP6_NF_IPTABLES=n1436 depends on IP6_NF_IPTABLES || IP6_NF_IPTABLES=n
1437 depends on NF_SOCKET_IPV4
1438 depends on NF_SOCKET_IPV6
1415 select NF_DEFRAG_IPV41439 select NF_DEFRAG_IPV4
1416 select NF_DEFRAG_IPV6 if IP6_NF_IPTABLES != n1440 select NF_DEFRAG_IPV6 if IP6_NF_IPTABLES != n
1417 help1441 help
net/netfilter/Makefile+6−0
@@ -48,6 +48,9 @@ nf_nat-y := nf_nat_core.o nf_nat_proto_unknown.o nf_nat_proto_common.o \ · 47 unmodified lines
48# generic transport layer logging48# generic transport layer logging
49obj-$(CONFIG_NF_LOG_COMMON) += nf_log_common.o49obj-$(CONFIG_NF_LOG_COMMON) += nf_log_common.o
50 50
51# packet logging for netdev family
52obj-$(CONFIG_NF_LOG_NETDEV) += nf_log_netdev.o
53
51obj-$(CONFIG_NF_NAT) += nf_nat.o54obj-$(CONFIG_NF_NAT) += nf_nat.o
52obj-$(CONFIG_NF_NAT_REDIRECT) += nf_nat_redirect.o55obj-$(CONFIG_NF_NAT_REDIRECT) += nf_nat_redirect.o
53 56
@@ -81,6 +84,7 @@ obj-$(CONFIG_NF_TABLES_NETDEV) += nf_tables_netdev.o · 27 unmodified lines
81obj-$(CONFIG_NFT_COMPAT) += nft_compat.o84obj-$(CONFIG_NFT_COMPAT) += nft_compat.o
82obj-$(CONFIG_NFT_EXTHDR) += nft_exthdr.o85obj-$(CONFIG_NFT_EXTHDR) += nft_exthdr.o
83obj-$(CONFIG_NFT_META) += nft_meta.o86obj-$(CONFIG_NFT_META) += nft_meta.o
87obj-$(CONFIG_NFT_RT) += nft_rt.o
84obj-$(CONFIG_NFT_NUMGEN) += nft_numgen.o88obj-$(CONFIG_NFT_NUMGEN) += nft_numgen.o
85obj-$(CONFIG_NFT_CT) += nft_ct.o89obj-$(CONFIG_NFT_CT) += nft_ct.o
86obj-$(CONFIG_NFT_LIMIT) += nft_limit.o90obj-$(CONFIG_NFT_LIMIT) += nft_limit.o
@@ -96,6 +100,8 @@ obj-$(CONFIG_NFT_LOG) += nft_log.o · 9 unmodified lines
96obj-$(CONFIG_NFT_MASQ) += nft_masq.o100obj-$(CONFIG_NFT_MASQ) += nft_masq.o
97obj-$(CONFIG_NFT_REDIR) += nft_redir.o101obj-$(CONFIG_NFT_REDIR) += nft_redir.o
98obj-$(CONFIG_NFT_HASH) += nft_hash.o102obj-$(CONFIG_NFT_HASH) += nft_hash.o
103obj-$(CONFIG_NFT_FIB) += nft_fib.o
104obj-$(CONFIG_NFT_FIB_INET) += nft_fib_inet.o
99 105
100# nf_tables netdev106# nf_tables netdev
101obj-$(CONFIG_NFT_DUP_NETDEV) += nft_dup_netdev.o107obj-$(CONFIG_NFT_DUP_NETDEV) += nft_dup_netdev.o
net/netfilter/nf_log_common.c+27−0
@@ -175,6 +175,33 @@ nf_log_dump_packet_common(struct nf_log_buf *m, u_int8_t pf, · 174 unmodified lines
175}175}
176EXPORT_SYMBOL_GPL(nf_log_dump_packet_common);176EXPORT_SYMBOL_GPL(nf_log_dump_packet_common);
177 177
178/* bridge and netdev logging families share this code. */
179void nf_log_l2packet(struct net *net, u_int8_t pf,
180 unsigned int hooknum,
181 const struct sk_buff *skb,
182 const struct net_device *in,
183 const struct net_device *out,
184 const struct nf_loginfo *loginfo,
185 const char *prefix)
186{
187 switch (eth_hdr(skb)->h_proto) {
188 case htons(ETH_P_IP):
189 nf_log_packet(net, NFPROTO_IPV4, hooknum, skb, in, out,
190 loginfo, "%s", prefix);
191 break;
192 case htons(ETH_P_IPV6):
193 nf_log_packet(net, NFPROTO_IPV6, hooknum, skb, in, out,
194 loginfo, "%s", prefix);
195 break;
196 case htons(ETH_P_ARP):
197 case htons(ETH_P_RARP):
198 nf_log_packet(net, NFPROTO_ARP, hooknum, skb, in, out,
199 loginfo, "%s", prefix);
200 break;
201 }
202}
203EXPORT_SYMBOL_GPL(nf_log_l2packet);
204
178static int __init nf_log_common_init(void)205static int __init nf_log_common_init(void)
179{206{
180 return 0;207 return 0;
net/netfilter/nf_log_netdev.c+80−0
@@ -0,0 +1,80 @@
1/*
2 * (C) 2016 by Pablo Neira Ayuso <pablo@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/module.h>
10#include <linux/spinlock.h>
11#include <linux/skbuff.h>
12#include <linux/ip.h>
13#include <net/route.h>
14
15#include <linux/netfilter.h>
16#include <net/netfilter/nf_log.h>
17
18static void nf_log_netdev_packet(struct net *net, u_int8_t pf,
19 unsigned int hooknum,
20 const struct sk_buff *skb,
21 const struct net_device *in,
22 const struct net_device *out,
23 const struct nf_loginfo *loginfo,
24 const char *prefix)
25{
26 nf_log_l2packet(net, pf, hooknum, skb, in, out, loginfo, prefix);
27}
28
29static struct nf_logger nf_netdev_logger __read_mostly = {
30 .name = "nf_log_netdev",
31 .type = NF_LOG_TYPE_LOG,
32 .logfn = nf_log_netdev_packet,
33 .me = THIS_MODULE,
34};
35
36static int __net_init nf_log_netdev_net_init(struct net *net)
37{
38 return nf_log_set(net, NFPROTO_NETDEV, &nf_netdev_logger);
39}
40
41static void __net_exit nf_log_netdev_net_exit(struct net *net)
42{
43 nf_log_unset(net, &nf_netdev_logger);
44}
45
46static struct pernet_operations nf_log_netdev_net_ops = {
47 .init = nf_log_netdev_net_init,
48 .exit = nf_log_netdev_net_exit,
49};
50
51static int __init nf_log_netdev_init(void)
52{
53 int ret;
54
55 /* Request to load the real packet loggers. */
56 nf_logger_request_module(NFPROTO_IPV4, NF_LOG_TYPE_LOG);
57 nf_logger_request_module(NFPROTO_IPV6, NF_LOG_TYPE_LOG);
58 nf_logger_request_module(NFPROTO_ARP, NF_LOG_TYPE_LOG);
59
60 ret = register_pernet_subsys(&nf_log_netdev_net_ops);
61 if (ret < 0)
62 return ret;
63
64 nf_log_register(NFPROTO_NETDEV, &nf_netdev_logger);
65 return 0;
66}
67
68static void __exit nf_log_netdev_exit(void)
69{
70 unregister_pernet_subsys(&nf_log_netdev_net_ops);
71 nf_log_unregister(&nf_netdev_logger);
72}
73
74module_init(nf_log_netdev_init);
75module_exit(nf_log_netdev_exit);
76
77MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
78MODULE_DESCRIPTION("Netfilter netdev packet logging");
79MODULE_LICENSE("GPL");
80MODULE_ALIAS_NF_LOGGER(5, 0); /* NFPROTO_NETDEV */
net/netfilter/nf_tables_core.c+1−0
@@ -178,6 +178,7 @@ next_rule: · 177 unmodified lines
178 case NF_ACCEPT:178 case NF_ACCEPT:
179 case NF_DROP:179 case NF_DROP:
180 case NF_QUEUE:180 case NF_QUEUE:
181 case NF_STOLEN:
181 nft_trace_packet(&info, chain, rule,182 nft_trace_packet(&info, chain, rule,
182 rulenum, NFT_TRACETYPE_RULE);183 rulenum, NFT_TRACETYPE_RULE);
183 return regs.verdict.code;184 return regs.verdict.code;
net/netfilter/nfnetlink_log.c+1−1
@@ -330,7 +330,7 @@ nfulnl_alloc_skb(struct net *net, u32 peer_portid, unsigned int inst_size, · 329 unmodified lines
330 * message. WARNING: has to be <= 128k due to slab restrictions */330 * message. WARNING: has to be <= 128k due to slab restrictions */
331 331
332 n = max(inst_size, pkt_size);332 n = max(inst_size, pkt_size);
333 skb = alloc_skb(n, GFP_ATOMIC);333 skb = alloc_skb(n, GFP_ATOMIC | __GFP_NOWARN);
334 if (!skb) {334 if (!skb) {
335 if (n > pkt_size) {335 if (n > pkt_size) {
336 /* try to allocate only as much as we need for current336 /* try to allocate only as much as we need for current
net/netfilter/nfnetlink_queue.c+1−1
@@ -69,7 +69,7 @@ struct nfqnl_instance { · 68 unmodified lines
69 * Following fields are dirtied for each queued packet,69 * Following fields are dirtied for each queued packet,
70 * keep them in same cache line if possible.70 * keep them in same cache line if possible.
71 */71 */
72 spinlock_t lock;72 spinlock_t lock ____cacheline_aligned_in_smp;
73 unsigned int queue_total;73 unsigned int queue_total;
74 unsigned int id_sequence; /* 'sequence' of pkt ids */74 unsigned int id_sequence; /* 'sequence' of pkt ids */
75 struct list_head queue_list; /* packets in queue */75 struct list_head queue_list; /* packets in queue */
net/netfilter/nft_cmp.c+0−3
@@ -84,9 +84,6 @@ static int nft_cmp_init(const struct nft_ctx *ctx, const struct nft_expr *expr, · 83 unmodified lines
84 if (err < 0)84 if (err < 0)
85 return err;85 return err;
86 86
87 if (desc.len > U8_MAX)
88 return -ERANGE;
89
90 priv->op = ntohl(nla_get_be32(tb[NFTA_CMP_OP]));87 priv->op = ntohl(nla_get_be32(tb[NFTA_CMP_OP]));
91 priv->len = desc.len;88 priv->len = desc.len;
92 return 0;89 return 0;
net/netfilter/nft_ct.c+49−1
@@ -1,5 +1,6 @@
1/*1/*
2 * Copyright (c) 2008-2009 Patrick McHardy <kaber@trash.net>2 * Copyright (c) 2008-2009 Patrick McHardy <kaber@trash.net>
3 * Copyright (c) 2016 Pablo Neira Ayuso <pablo@netfilter.org>
3 *4 *
4 * This program is free software; you can redistribute it and/or modify5 * 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 as6 * it under the terms of the GNU General Public License version 2 as
@@ -518,15 +519,61 @@ static struct nft_expr_type nft_ct_type __read_mostly = { · 512 unmodified lines
518 .owner = THIS_MODULE,519 .owner = THIS_MODULE,
519};520};
520 521
522static void nft_notrack_eval(const struct nft_expr *expr,
523 struct nft_regs *regs,
524 const struct nft_pktinfo *pkt)
525{
526 struct sk_buff *skb = pkt->skb;
527 enum ip_conntrack_info ctinfo;
528 struct nf_conn *ct;
529
530 ct = nf_ct_get(pkt->skb, &ctinfo);
531 /* Previously seen (loopback or untracked)? Ignore. */
532 if (ct)
533 return;
534
535 ct = nf_ct_untracked_get();
536 atomic_inc(&ct->ct_general.use);
537 skb->nfct = &ct->ct_general;
538 skb->nfctinfo = IP_CT_NEW;
539}
540
541static struct nft_expr_type nft_notrack_type;
542static const struct nft_expr_ops nft_notrack_ops = {
543 .type = &nft_notrack_type,
544 .size = NFT_EXPR_SIZE(0),
545 .eval = nft_notrack_eval,
546};
547
548static struct nft_expr_type nft_notrack_type __read_mostly = {
549 .name = "notrack",
550 .ops = &nft_notrack_ops,
551 .owner = THIS_MODULE,
552};
553
521static int __init nft_ct_module_init(void)554static int __init nft_ct_module_init(void)
522{555{
556 int err;
557
523 BUILD_BUG_ON(NF_CT_LABELS_MAX_SIZE > NFT_REG_SIZE);558 BUILD_BUG_ON(NF_CT_LABELS_MAX_SIZE > NFT_REG_SIZE);
524 559
525 return nft_register_expr(&nft_ct_type);560 err = nft_register_expr(&nft_ct_type);
561 if (err < 0)
562 return err;
563
564 err = nft_register_expr(&nft_notrack_type);
565 if (err < 0)
566 goto err1;
567
568 return 0;
569err1:
570 nft_unregister_expr(&nft_ct_type);
571 return err;
526}572}
527 573
528static void __exit nft_ct_module_exit(void)574static void __exit nft_ct_module_exit(void)
529{575{
576 nft_unregister_expr(&nft_notrack_type);
530 nft_unregister_expr(&nft_ct_type);577 nft_unregister_expr(&nft_ct_type);
531}578}
532 579
@@ -536,3 +583,4 @@ module_exit(nft_ct_module_exit); · 3 unmodified lines
536MODULE_LICENSE("GPL");583MODULE_LICENSE("GPL");
537MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");584MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
538MODULE_ALIAS_NFT_EXPR("ct");585MODULE_ALIAS_NFT_EXPR("ct");
586MODULE_ALIAS_NFT_EXPR("notrack");
net/netfilter/nft_fib.c+159−0
@@ -0,0 +1,159 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
5 *
6 * Generic part shared by ipv4 and ipv6 backends.
7 */
8
9#include <linux/kernel.h>
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/netlink.h>
13#include <linux/netfilter.h>
14#include <linux/netfilter/nf_tables.h>
15#include <net/netfilter/nf_tables_core.h>
16#include <net/netfilter/nf_tables.h>
17#include <net/netfilter/nft_fib.h>
18
19const struct nla_policy nft_fib_policy[NFTA_FIB_MAX + 1] = {
20 [NFTA_FIB_DREG] = { .type = NLA_U32 },
21 [NFTA_FIB_RESULT] = { .type = NLA_U32 },
22 [NFTA_FIB_FLAGS] = { .type = NLA_U32 },
23};
24EXPORT_SYMBOL(nft_fib_policy);
25
26#define NFTA_FIB_F_ALL (NFTA_FIB_F_SADDR | NFTA_FIB_F_DADDR | \
27 NFTA_FIB_F_MARK | NFTA_FIB_F_IIF | NFTA_FIB_F_OIF)
28
29int nft_fib_validate(const struct nft_ctx *ctx, const struct nft_expr *expr,
30 const struct nft_data **data)
31{
32 const struct nft_fib *priv = nft_expr_priv(expr);
33 unsigned int hooks;
34
35 switch (priv->result) {
36 case NFT_FIB_RESULT_OIF: /* fallthrough */
37 case NFT_FIB_RESULT_OIFNAME:
38 hooks = (1 << NF_INET_PRE_ROUTING);
39 break;
40 case NFT_FIB_RESULT_ADDRTYPE:
41 if (priv->flags & NFTA_FIB_F_IIF)
42 hooks = (1 << NF_INET_PRE_ROUTING) |
43 (1 << NF_INET_LOCAL_IN) |
44 (1 << NF_INET_FORWARD);
45 else if (priv->flags & NFTA_FIB_F_OIF)
46 hooks = (1 << NF_INET_LOCAL_OUT) |
47 (1 << NF_INET_POST_ROUTING) |
48 (1 << NF_INET_FORWARD);
49 else
50 hooks = (1 << NF_INET_LOCAL_IN) |
51 (1 << NF_INET_LOCAL_OUT) |
52 (1 << NF_INET_FORWARD) |
53 (1 << NF_INET_PRE_ROUTING) |
54 (1 << NF_INET_POST_ROUTING);
55
56 break;
57 default:
58 return -EINVAL;
59 }
60
61 return nft_chain_validate_hooks(ctx->chain, hooks);
62}
63EXPORT_SYMBOL_GPL(nft_fib_validate);
64
65int nft_fib_init(const struct nft_ctx *ctx, const struct nft_expr *expr,
66 const struct nlattr * const tb[])
67{
68 struct nft_fib *priv = nft_expr_priv(expr);
69 unsigned int len;
70 int err;
71
72 if (!tb[NFTA_FIB_DREG] || !tb[NFTA_FIB_RESULT] || !tb[NFTA_FIB_FLAGS])
73 return -EINVAL;
74
75 priv->flags = ntohl(nla_get_be32(tb[NFTA_FIB_FLAGS]));
76
77 if (priv->flags == 0 || (priv->flags & ~NFTA_FIB_F_ALL))
78 return -EINVAL;
79
80 if ((priv->flags & (NFTA_FIB_F_SADDR | NFTA_FIB_F_DADDR)) ==
81 (NFTA_FIB_F_SADDR | NFTA_FIB_F_DADDR))
82 return -EINVAL;
83 if ((priv->flags & (NFTA_FIB_F_IIF | NFTA_FIB_F_OIF)) ==
84 (NFTA_FIB_F_IIF | NFTA_FIB_F_OIF))
85 return -EINVAL;
86 if ((priv->flags & (NFTA_FIB_F_SADDR | NFTA_FIB_F_DADDR)) == 0)
87 return -EINVAL;
88
89 priv->result = htonl(nla_get_be32(tb[NFTA_FIB_RESULT]));
90 priv->dreg = nft_parse_register(tb[NFTA_FIB_DREG]);
91
92 switch (priv->result) {
93 case NFT_FIB_RESULT_OIF:
94 if (priv->flags & NFTA_FIB_F_OIF)
95 return -EINVAL;
96 len = sizeof(int);
97 break;
98 case NFT_FIB_RESULT_OIFNAME:
99 if (priv->flags & NFTA_FIB_F_OIF)
100 return -EINVAL;
101 len = IFNAMSIZ;
102 break;
103 case NFT_FIB_RESULT_ADDRTYPE:
104 len = sizeof(u32);
105 break;
106 default:
107 return -EINVAL;
108 }
109
110 err = nft_validate_register_store(ctx, priv->dreg, NULL,
111 NFT_DATA_VALUE, len);
112 if (err < 0)
113 return err;
114
115 return nft_fib_validate(ctx, expr, NULL);
116}
117EXPORT_SYMBOL_GPL(nft_fib_init);
118
119int nft_fib_dump(struct sk_buff *skb, const struct nft_expr *expr)
120{
121 const struct nft_fib *priv = nft_expr_priv(expr);
122
123 if (nft_dump_register(skb, NFTA_FIB_DREG, priv->dreg))
124 return -1;
125
126 if (nla_put_be32(skb, NFTA_FIB_RESULT, htonl(priv->result)))
127 return -1;
128
129 if (nla_put_be32(skb, NFTA_FIB_FLAGS, htonl(priv->flags)))
130 return -1;
131
132 return 0;
133}
134EXPORT_SYMBOL_GPL(nft_fib_dump);
135
136void nft_fib_store_result(void *reg, enum nft_fib_result r,
137 const struct nft_pktinfo *pkt, int index)
138{
139 struct net_device *dev;
140 u32 *dreg = reg;
141
142 switch (r) {
143 case NFT_FIB_RESULT_OIF:
144 *dreg = index;
145 break;
146 case NFT_FIB_RESULT_OIFNAME:
147 dev = dev_get_by_index_rcu(pkt->net, index);
148 strncpy(reg, dev ? dev->name : "", IFNAMSIZ);
149 break;
150 default:
151 WARN_ON_ONCE(1);
152 *dreg = 0;
153 break;
154 }
155}
156EXPORT_SYMBOL_GPL(nft_fib_store_result);
157
158MODULE_LICENSE("GPL");
159MODULE_AUTHOR("Florian Westphal <fw@strlen.de>");
net/netfilter/nft_fib_inet.c+82−0
@@ -0,0 +1,82 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
5 */
6
7#include <linux/kernel.h>
8#include <linux/init.h>
9#include <linux/module.h>
10#include <linux/netlink.h>
11#include <linux/netfilter.h>
12#include <linux/netfilter/nf_tables.h>
13#include <net/netfilter/nf_tables_core.h>
14#include <net/netfilter/nf_tables.h>
15
16#include <net/netfilter/nft_fib.h>
17
18static void nft_fib_inet_eval(const struct nft_expr *expr,
19 struct nft_regs *regs,
20 const struct nft_pktinfo *pkt)
21{
22 const struct nft_fib *priv = nft_expr_priv(expr);
23
24 switch (pkt->pf) {
25 case NFPROTO_IPV4:
26 switch (priv->result) {
27 case NFT_FIB_RESULT_OIF:
28 case NFT_FIB_RESULT_OIFNAME:
29 return nft_fib4_eval(expr, regs, pkt);
30 case NFT_FIB_RESULT_ADDRTYPE:
31 return nft_fib4_eval_type(expr, regs, pkt);
32 }
33 break;
34 case NFPROTO_IPV6:
35 switch (priv->result) {
36 case NFT_FIB_RESULT_OIF:
37 case NFT_FIB_RESULT_OIFNAME:
38 return nft_fib6_eval(expr, regs, pkt);
39 case NFT_FIB_RESULT_ADDRTYPE:
40 return nft_fib6_eval_type(expr, regs, pkt);
41 }
42 break;
43 }
44
45 regs->verdict.code = NF_DROP;
46}
47
48static struct nft_expr_type nft_fib_inet_type;
49static const struct nft_expr_ops nft_fib_inet_ops = {
50 .type = &nft_fib_inet_type,
51 .size = NFT_EXPR_SIZE(sizeof(struct nft_fib)),
52 .eval = nft_fib_inet_eval,
53 .init = nft_fib_init,
54 .dump = nft_fib_dump,
55 .validate = nft_fib_validate,
56};
57
58static struct nft_expr_type nft_fib_inet_type __read_mostly = {
59 .family = NFPROTO_INET,
60 .name = "fib",
61 .ops = &nft_fib_inet_ops,
62 .policy = nft_fib_policy,
63 .maxattr = NFTA_FIB_MAX,
64 .owner = THIS_MODULE,
65};
66
67static int __init nft_fib_inet_module_init(void)
68{
69 return nft_register_expr(&nft_fib_inet_type);
70}
71
72static void __exit nft_fib_inet_module_exit(void)
73{
74 nft_unregister_expr(&nft_fib_inet_type);
75}
76
77module_init(nft_fib_inet_module_init);
78module_exit(nft_fib_inet_module_exit);
79
80MODULE_LICENSE("GPL");
81MODULE_AUTHOR("Florian Westphal <fw@strlen.de>");
82MODULE_ALIAS_NFT_AF_EXPR(1, "fib");
net/netfilter/nft_immediate.c+0−3
@@ -54,9 +54,6 @@ static int nft_immediate_init(const struct nft_ctx *ctx, · 53 unmodified lines
54 if (err < 0)54 if (err < 0)
55 return err;55 return err;
56 56
57 if (desc.len > U8_MAX)
58 return -ERANGE;
59
60 priv->dlen = desc.len;57 priv->dlen = desc.len;
61 58
62 priv->dreg = nft_parse_register(tb[NFTA_IMMEDIATE_DREG]);59 priv->dreg = nft_parse_register(tb[NFTA_IMMEDIATE_DREG]);
net/netfilter/nft_meta.c+5−0
@@ -310,6 +310,11 @@ int nft_meta_set_validate(const struct nft_ctx *ctx, · 309 unmodified lines
310 case NFPROTO_NETDEV:310 case NFPROTO_NETDEV:
311 hooks = 1 << NF_NETDEV_INGRESS;311 hooks = 1 << NF_NETDEV_INGRESS;
312 break;312 break;
313 case NFPROTO_IPV4:
314 case NFPROTO_IPV6:
315 case NFPROTO_INET:
316 hooks = 1 << NF_INET_PRE_ROUTING;
317 break;
313 default:318 default:
314 return -EOPNOTSUPP;319 return -EOPNOTSUPP;
315 }320 }
net/netfilter/nft_numgen.c+1−1
@@ -65,7 +65,7 @@ static int nft_ng_inc_init(const struct nft_ctx *ctx, · 64 unmodified lines
65 return -EOVERFLOW;65 return -EOVERFLOW;
66 66
67 priv->dreg = nft_parse_register(tb[NFTA_NG_DREG]);67 priv->dreg = nft_parse_register(tb[NFTA_NG_DREG]);
68 atomic_set(&priv->counter, 0);68 atomic_set(&priv->counter, priv->modulus - 1);
69 69
70 return nft_validate_register_store(ctx, priv->dreg, NULL,70 return nft_validate_register_store(ctx, priv->dreg, NULL,
71 NFT_DATA_VALUE, sizeof(u32));71 NFT_DATA_VALUE, sizeof(u32));
net/netfilter/nft_rt.c+153−0
@@ -0,0 +1,153 @@
1/*
2 * Copyright (c) 2016 Anders K. Pedersen <akp@cohaesio.com>
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/kernel.h>
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/netlink.h>
13#include <linux/netfilter.h>
14#include <linux/netfilter/nf_tables.h>
15#include <net/dst.h>
16#include <net/ip6_route.h>
17#include <net/route.h>
18#include <net/netfilter/nf_tables.h>
19#include <net/netfilter/nf_tables_core.h>
20
21struct nft_rt {
22 enum nft_rt_keys key:8;
23 enum nft_registers dreg:8;
24};
25
26void nft_rt_get_eval(const struct nft_expr *expr,
27 struct nft_regs *regs,
28 const struct nft_pktinfo *pkt)
29{
30 const struct nft_rt *priv = nft_expr_priv(expr);
31 const struct sk_buff *skb = pkt->skb;
32 u32 *dest = &regs->data[priv->dreg];
33 const struct dst_entry *dst;
34
35 dst = skb_dst(skb);
36 if (!dst)
37 goto err;
38
39 switch (priv->key) {
40#ifdef CONFIG_IP_ROUTE_CLASSID
41 case NFT_RT_CLASSID:
42 *dest = dst->tclassid;
43 break;
44#endif
45 case NFT_RT_NEXTHOP4:
46 if (pkt->pf != NFPROTO_IPV4)
47 goto err;
48
49 *dest = rt_nexthop((const struct rtable *)dst,
50 ip_hdr(skb)->daddr);
51 break;
52 case NFT_RT_NEXTHOP6:
53 if (pkt->pf != NFPROTO_IPV6)
54 goto err;
55
56 memcpy(dest, rt6_nexthop((struct rt6_info *)dst,
57 &ipv6_hdr(skb)->daddr),
58 sizeof(struct in6_addr));
59 break;
60 default:
61 WARN_ON(1);
62 goto err;
63 }
64 return;
65
66err:
67 regs->verdict.code = NFT_BREAK;
68}
69
70const struct nla_policy nft_rt_policy[NFTA_RT_MAX + 1] = {
71 [NFTA_RT_DREG] = { .type = NLA_U32 },
72 [NFTA_RT_KEY] = { .type = NLA_U32 },
73};
74
75int nft_rt_get_init(const struct nft_ctx *ctx,
76 const struct nft_expr *expr,
77 const struct nlattr * const tb[])
78{
79 struct nft_rt *priv = nft_expr_priv(expr);
80 unsigned int len;
81
82 if (tb[NFTA_RT_KEY] == NULL ||
83 tb[NFTA_RT_DREG] == NULL)
84 return -EINVAL;
85
86 priv->key = ntohl(nla_get_be32(tb[NFTA_RT_KEY]));
87 switch (priv->key) {
88#ifdef CONFIG_IP_ROUTE_CLASSID
89 case NFT_RT_CLASSID:
90#endif
91 case NFT_RT_NEXTHOP4:
92 len = sizeof(u32);
93 break;
94 case NFT_RT_NEXTHOP6:
95 len = sizeof(struct in6_addr);
96 break;
97 default:
98 return -EOPNOTSUPP;
99 }
100
101 priv->dreg = nft_parse_register(tb[NFTA_RT_DREG]);
102 return nft_validate_register_store(ctx, priv->dreg, NULL,
103 NFT_DATA_VALUE, len);
104}
105
106int nft_rt_get_dump(struct sk_buff *skb,
107 const struct nft_expr *expr)
108{
109 const struct nft_rt *priv = nft_expr_priv(expr);
110
111 if (nla_put_be32(skb, NFTA_RT_KEY, htonl(priv->key)))
112 goto nla_put_failure;
113 if (nft_dump_register(skb, NFTA_RT_DREG, priv->dreg))
114 goto nla_put_failure;
115 return 0;
116
117nla_put_failure:
118 return -1;
119}
120
121static struct nft_expr_type nft_rt_type;
122static const struct nft_expr_ops nft_rt_get_ops = {
123 .type = &nft_rt_type,
124 .size = NFT_EXPR_SIZE(sizeof(struct nft_rt)),
125 .eval = nft_rt_get_eval,
126 .init = nft_rt_get_init,
127 .dump = nft_rt_get_dump,
128};
129
130static struct nft_expr_type nft_rt_type __read_mostly = {
131 .name = "rt",
132 .ops = &nft_rt_get_ops,
133 .policy = nft_rt_policy,
134 .maxattr = NFTA_RT_MAX,
135 .owner = THIS_MODULE,
136};
137
138static int __init nft_rt_module_init(void)
139{
140 return nft_register_expr(&nft_rt_type);
141}
142
143static void __exit nft_rt_module_exit(void)
144{
145 nft_unregister_expr(&nft_rt_type);
146}
147
148module_init(nft_rt_module_init);
149module_exit(nft_rt_module_exit);
150
151MODULE_LICENSE("GPL");
152MODULE_AUTHOR("Anders K. Pedersen <akp@cohaesio.com>");
153MODULE_ALIAS_NFT_EXPR("rt");
net/netfilter/xt_multiport.c+21−19
@@ -42,29 +42,31 @@ ports_match_v1(const struct xt_multiport_v1 *minfo, · 41 unmodified lines
42 e = minfo->ports[++i];42 e = minfo->ports[++i];
43 pr_debug("src or dst matches with %d-%d?\n", s, e);43 pr_debug("src or dst matches with %d-%d?\n", s, e);
44 44
45 if (minfo->flags == XT_MULTIPORT_SOURCE45 switch (minfo->flags) {
46 && src >= s && src <= e)46 case XT_MULTIPORT_SOURCE:
47 return true ^ minfo->invert;47 return (src >= s && src <= e) ^ minfo->invert;
48 if (minfo->flags == XT_MULTIPORT_DESTINATION48 case XT_MULTIPORT_DESTINATION:
49 && dst >= s && dst <= e)49 return (dst >= s && dst <= e) ^ minfo->invert;
50 return true ^ minfo->invert;50 case XT_MULTIPORT_EITHER:
51 if (minfo->flags == XT_MULTIPORT_EITHER51 return ((dst >= s && dst <= e) ||
52 && ((dst >= s && dst <= e)52 (src >= s && src <= e)) ^ minfo->invert;
53 || (src >= s && src <= e)))53 default:
54 return true ^ minfo->invert;54 break;
55 }
55 } else {56 } else {
56 /* exact port matching */57 /* exact port matching */
57 pr_debug("src or dst matches with %d?\n", s);58 pr_debug("src or dst matches with %d?\n", s);
58 59
59 if (minfo->flags == XT_MULTIPORT_SOURCE60 switch (minfo->flags) {
60 && src == s)61 case XT_MULTIPORT_SOURCE:
61 return true ^ minfo->invert;62 return (src == s) ^ minfo->invert;
62 if (minfo->flags == XT_MULTIPORT_DESTINATION63 case XT_MULTIPORT_DESTINATION:
63 && dst == s)64 return (dst == s) ^ minfo->invert;
64 return true ^ minfo->invert;65 case XT_MULTIPORT_EITHER:
65 if (minfo->flags == XT_MULTIPORT_EITHER66 return (src == s || dst == s) ^ minfo->invert;
66 && (src == s || dst == s))67 default:
67 return true ^ minfo->invert;68 break;
69 }
68 }70 }
69 }71 }
70 72
net/netfilter/xt_socket.c+10−295
@@ -22,76 +22,14 @@ · 21 unmodified lines
22#include <net/netfilter/ipv4/nf_defrag_ipv4.h>22#include <net/netfilter/ipv4/nf_defrag_ipv4.h>
23 23
24#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)24#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
25#define XT_SOCKET_HAVE_IPV6 1
26#include <linux/netfilter_ipv6/ip6_tables.h>25#include <linux/netfilter_ipv6/ip6_tables.h>
27#include <net/inet6_hashtables.h>26#include <net/inet6_hashtables.h>
28#include <net/netfilter/ipv6/nf_defrag_ipv6.h>27#include <net/netfilter/ipv6/nf_defrag_ipv6.h>
29#endif28#endif
30 29
30#include <net/netfilter/nf_socket.h>
31#include <linux/netfilter/xt_socket.h>31#include <linux/netfilter/xt_socket.h>
32 32
33#if IS_ENABLED(CONFIG_NF_CONNTRACK)
34#define XT_SOCKET_HAVE_CONNTRACK 1
35#include <net/netfilter/nf_conntrack.h>
36#endif
37
38static int
39extract_icmp4_fields(const struct sk_buff *skb,
40 u8 *protocol,
41 __be32 *raddr,
42 __be32 *laddr,
43 __be16 *rport,
44 __be16 *lport)
45{
46 unsigned int outside_hdrlen = ip_hdrlen(skb);
47 struct iphdr *inside_iph, _inside_iph;
48 struct icmphdr *icmph, _icmph;
49 __be16 *ports, _ports[2];
50
51 icmph = skb_header_pointer(skb, outside_hdrlen,
52 sizeof(_icmph), &_icmph);
53 if (icmph == NULL)
54 return 1;
55
56 switch (icmph->type) {
57 case ICMP_DEST_UNREACH:
58 case ICMP_SOURCE_QUENCH:
59 case ICMP_REDIRECT:
60 case ICMP_TIME_EXCEEDED:
61 case ICMP_PARAMETERPROB:
62 break;
63 default:
64 return 1;
65 }
66
67 inside_iph = skb_header_pointer(skb, outside_hdrlen +
68 sizeof(struct icmphdr),
69 sizeof(_inside_iph), &_inside_iph);
70 if (inside_iph == NULL)
71 return 1;
72
73 if (inside_iph->protocol != IPPROTO_TCP &&
74 inside_iph->protocol != IPPROTO_UDP)
75 return 1;
76
77 ports = skb_header_pointer(skb, outside_hdrlen +
78 sizeof(struct icmphdr) +
79 (inside_iph->ihl << 2),
80 sizeof(_ports), &_ports);
81 if (ports == NULL)
82 return 1;
83
84 /* the inside IP packet is the one quoted from our side, thus
85 * its saddr is the local address */
86 *protocol = inside_iph->protocol;
87 *laddr = inside_iph->saddr;
88 *lport = ports[0];
89 *raddr = inside_iph->daddr;
90 *rport = ports[1];
91
92 return 0;
93}
94
95/* "socket" match based redirection (no specific rule)33/* "socket" match based redirection (no specific rule)
96 * ===================================================34 * ===================================================
97 *35 *
@@ -111,104 +49,6 @@ extract_icmp4_fields(const struct sk_buff *skb, · 13 unmodified lines
111 * then local services could intercept traffic going through the49 * then local services could intercept traffic going through the
112 * box.50 * box.
113 */51 */
114static struct sock *
115xt_socket_get_sock_v4(struct net *net, struct sk_buff *skb, const int doff,
116 const u8 protocol,
117 const __be32 saddr, const __be32 daddr,
118 const __be16 sport, const __be16 dport,
119 const struct net_device *in)
120{
121 switch (protocol) {
122 case IPPROTO_TCP:
123 return inet_lookup(net, &tcp_hashinfo, skb, doff,
124 saddr, sport, daddr, dport,
125 in->ifindex);
126 case IPPROTO_UDP:
127 return udp4_lib_lookup(net, saddr, sport, daddr, dport,
128 in->ifindex);
129 }
130 return NULL;
131}
132
133static bool xt_socket_sk_is_transparent(struct sock *sk)
134{
135 switch (sk->sk_state) {
136 case TCP_TIME_WAIT:
137 return inet_twsk(sk)->tw_transparent;
138
139 case TCP_NEW_SYN_RECV:
140 return inet_rsk(inet_reqsk(sk))->no_srccheck;
141
142 default:
143 return inet_sk(sk)->transparent;
144 }
145}
146
147static struct sock *xt_socket_lookup_slow_v4(struct net *net,
148 const struct sk_buff *skb,
149 const struct net_device *indev)
150{
151 const struct iphdr *iph = ip_hdr(skb);
152 struct sk_buff *data_skb = NULL;
153 int doff = 0;
154 __be32 uninitialized_var(daddr), uninitialized_var(saddr);
155 __be16 uninitialized_var(dport), uninitialized_var(sport);
156 u8 uninitialized_var(protocol);
157#ifdef XT_SOCKET_HAVE_CONNTRACK
158 struct nf_conn const *ct;
159 enum ip_conntrack_info ctinfo;
160#endif
161
162 if (iph->protocol == IPPROTO_UDP || iph->protocol == IPPROTO_TCP) {
163 struct udphdr _hdr, *hp;
164
165 hp = skb_header_pointer(skb, ip_hdrlen(skb),
166 sizeof(_hdr), &_hdr);
167 if (hp == NULL)
168 return NULL;
169
170 protocol = iph->protocol;
171 saddr = iph->saddr;
172 sport = hp->source;
173 daddr = iph->daddr;
174 dport = hp->dest;
175 data_skb = (struct sk_buff *)skb;
176 doff = iph->protocol == IPPROTO_TCP ?
177 ip_hdrlen(skb) + __tcp_hdrlen((struct tcphdr *)hp) :
178 ip_hdrlen(skb) + sizeof(*hp);
179
180 } else if (iph->protocol == IPPROTO_ICMP) {
181 if (extract_icmp4_fields(skb, &protocol, &saddr, &daddr,
182 &sport, &dport))
183 return NULL;
184 } else {
185 return NULL;
186 }
187
188#ifdef XT_SOCKET_HAVE_CONNTRACK
189 /* Do the lookup with the original socket address in
190 * case this is a reply packet of an established
191 * SNAT-ted connection.
192 */
193 ct = nf_ct_get(skb, &ctinfo);
194 if (ct && !nf_ct_is_untracked(ct) &&
195 ((iph->protocol != IPPROTO_ICMP &&
196 ctinfo == IP_CT_ESTABLISHED_REPLY) ||
197 (iph->protocol == IPPROTO_ICMP &&
198 ctinfo == IP_CT_RELATED_REPLY)) &&
199 (ct->status & IPS_SRC_NAT_DONE)) {
200
201 daddr = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u3.ip;
202 dport = (iph->protocol == IPPROTO_TCP) ?
203 ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u.tcp.port :
204 ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.u.udp.port;
205 }
206#endif
207
208 return xt_socket_get_sock_v4(net, data_skb, doff, protocol, saddr,
209 daddr, sport, dport, indev);
210}
211
212static bool52static bool
213socket_match(const struct sk_buff *skb, struct xt_action_param *par,53socket_match(const struct sk_buff *skb, struct xt_action_param *par,
214 const struct xt_socket_mtinfo1 *info)54 const struct xt_socket_mtinfo1 *info)
@@ -217,7 +57,7 @@ socket_match(const struct sk_buff *skb, struct xt_action_param *par, · 2 unmodified lines
217 struct sock *sk = skb->sk;57 struct sock *sk = skb->sk;
218 58
219 if (!sk)59 if (!sk)
220 sk = xt_socket_lookup_slow_v4(par->net, skb, par->in);60 sk = nf_sk_lookup_slow_v4(par->net, skb, par->in);
221 if (sk) {61 if (sk) {
222 bool wildcard;62 bool wildcard;
223 bool transparent = true;63 bool transparent = true;
@@ -233,7 +73,7 @@ socket_match(const struct sk_buff *skb, struct xt_action_param *par, · 9 unmodified lines
233 * if XT_SOCKET_TRANSPARENT is used73 * if XT_SOCKET_TRANSPARENT is used
234 */74 */
235 if (info->flags & XT_SOCKET_TRANSPARENT)75 if (info->flags & XT_SOCKET_TRANSPARENT)
236 transparent = xt_socket_sk_is_transparent(sk);76 transparent = nf_sk_is_transparent(sk);
237 77
238 if (info->flags & XT_SOCKET_RESTORESKMARK && !wildcard &&78 if (info->flags & XT_SOCKET_RESTORESKMARK && !wildcard &&
239 transparent)79 transparent)
@@ -265,132 +105,7 @@ socket_mt4_v1_v2_v3(const struct sk_buff *skb, struct xt_action_param *par) · 25 unmodified lines
265 return socket_match(skb, par, par->matchinfo);105 return socket_match(skb, par, par->matchinfo);
266}106}
267 107
268#ifdef XT_SOCKET_HAVE_IPV6108#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
269
270static int
271extract_icmp6_fields(const struct sk_buff *skb,
272 unsigned int outside_hdrlen,
273 int *protocol,
274 const struct in6_addr **raddr,
275 const struct in6_addr **laddr,
276 __be16 *rport,
277 __be16 *lport,
278 struct ipv6hdr *ipv6_var)
279{
280 const struct ipv6hdr *inside_iph;
281 struct icmp6hdr *icmph, _icmph;
282 __be16 *ports, _ports[2];
283 u8 inside_nexthdr;
284 __be16 inside_fragoff;
285 int inside_hdrlen;
286
287 icmph = skb_header_pointer(skb, outside_hdrlen,
288 sizeof(_icmph), &_icmph);
289 if (icmph == NULL)
290 return 1;
291
292 if (icmph->icmp6_type & ICMPV6_INFOMSG_MASK)
293 return 1;
294
295 inside_iph = skb_header_pointer(skb, outside_hdrlen + sizeof(_icmph),
296 sizeof(*ipv6_var), ipv6_var);
297 if (inside_iph == NULL)
298 return 1;
299 inside_nexthdr = inside_iph->nexthdr;
300
301 inside_hdrlen = ipv6_skip_exthdr(skb, outside_hdrlen + sizeof(_icmph) +
302 sizeof(*ipv6_var),
303 &inside_nexthdr, &inside_fragoff);
304 if (inside_hdrlen < 0)
305 return 1; /* hjm: Packet has no/incomplete transport layer headers. */
306
307 if (inside_nexthdr != IPPROTO_TCP &&
308 inside_nexthdr != IPPROTO_UDP)
309 return 1;
310
311 ports = skb_header_pointer(skb, inside_hdrlen,
312 sizeof(_ports), &_ports);
313 if (ports == NULL)
314 return 1;
315
316 /* the inside IP packet is the one quoted from our side, thus
317 * its saddr is the local address */
318 *protocol = inside_nexthdr;
319 *laddr = &inside_iph->saddr;
320 *lport = ports[0];
321 *raddr = &inside_iph->daddr;
322 *rport = ports[1];
323
324 return 0;
325}
326
327static struct sock *
328xt_socket_get_sock_v6(struct net *net, struct sk_buff *skb, int doff,
329 const u8 protocol,
330 const struct in6_addr *saddr, const struct in6_addr *daddr,
331 const __be16 sport, const __be16 dport,
332 const struct net_device *in)
333{
334 switch (protocol) {
335 case IPPROTO_TCP:
336 return inet6_lookup(net, &tcp_hashinfo, skb, doff,
337 saddr, sport, daddr, dport,
338 in->ifindex);
339 case IPPROTO_UDP:
340 return udp6_lib_lookup(net, saddr, sport, daddr, dport,
341 in->ifindex);
342 }
343
344 return NULL;
345}
346
347static struct sock *xt_socket_lookup_slow_v6(struct net *net,
348 const struct sk_buff *skb,
349 const struct net_device *indev)
350{
351 __be16 uninitialized_var(dport), uninitialized_var(sport);
352 const struct in6_addr *daddr = NULL, *saddr = NULL;
353 struct ipv6hdr *iph = ipv6_hdr(skb);
354 struct sk_buff *data_skb = NULL;
355 int doff = 0;
356 int thoff = 0, tproto;
357
358 tproto = ipv6_find_hdr(skb, &thoff, -1, NULL, NULL);
359 if (tproto < 0) {
360 pr_debug("unable to find transport header in IPv6 packet, dropping\n");
361 return NULL;
362 }
363
364 if (tproto == IPPROTO_UDP || tproto == IPPROTO_TCP) {
365 struct udphdr _hdr, *hp;
366
367 hp = skb_header_pointer(skb, thoff, sizeof(_hdr), &_hdr);
368 if (hp == NULL)
369 return NULL;
370
371 saddr = &iph->saddr;
372 sport = hp->source;
373 daddr = &iph->daddr;
374 dport = hp->dest;
375 data_skb = (struct sk_buff *)skb;
376 doff = tproto == IPPROTO_TCP ?
377 thoff + __tcp_hdrlen((struct tcphdr *)hp) :
378 thoff + sizeof(*hp);
379
380 } else if (tproto == IPPROTO_ICMPV6) {
381 struct ipv6hdr ipv6_var;
382
383 if (extract_icmp6_fields(skb, thoff, &tproto, &saddr, &daddr,
384 &sport, &dport, &ipv6_var))
385 return NULL;
386 } else {
387 return NULL;
388 }
389
390 return xt_socket_get_sock_v6(net, data_skb, doff, tproto, saddr, daddr,
391 sport, dport, indev);
392}
393
394static bool109static bool
395socket_mt6_v1_v2_v3(const struct sk_buff *skb, struct xt_action_param *par)110socket_mt6_v1_v2_v3(const struct sk_buff *skb, struct xt_action_param *par)
396{111{
@@ -399,7 +114,7 @@ socket_mt6_v1_v2_v3(const struct sk_buff *skb, struct xt_action_param *par) · 2 unmodified lines
399 struct sock *sk = skb->sk;114 struct sock *sk = skb->sk;
400 115
401 if (!sk)116 if (!sk)
402 sk = xt_socket_lookup_slow_v6(par->net, skb, par->in);117 sk = nf_sk_lookup_slow_v6(par->net, skb, par->in);
403 if (sk) {118 if (sk) {
404 bool wildcard;119 bool wildcard;
405 bool transparent = true;120 bool transparent = true;
@@ -415,7 +130,7 @@ socket_mt6_v1_v2_v3(const struct sk_buff *skb, struct xt_action_param *par) · 9 unmodified lines
415 * if XT_SOCKET_TRANSPARENT is used130 * if XT_SOCKET_TRANSPARENT is used
416 */131 */
417 if (info->flags & XT_SOCKET_TRANSPARENT)132 if (info->flags & XT_SOCKET_TRANSPARENT)
418 transparent = xt_socket_sk_is_transparent(sk);133 transparent = nf_sk_is_transparent(sk);
419 134
420 if (info->flags & XT_SOCKET_RESTORESKMARK && !wildcard &&135 if (info->flags & XT_SOCKET_RESTORESKMARK && !wildcard &&
421 transparent)136 transparent)
@@ -488,7 +203,7 @@ static struct xt_match socket_mt_reg[] __read_mostly = { · 66 unmodified lines
488 (1 << NF_INET_LOCAL_IN),203 (1 << NF_INET_LOCAL_IN),
489 .me = THIS_MODULE,204 .me = THIS_MODULE,
490 },205 },
491#ifdef XT_SOCKET_HAVE_IPV6206#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
492 {207 {
493 .name = "socket",208 .name = "socket",
494 .revision = 1,209 .revision = 1,
@@ -512,7 +227,7 @@ static struct xt_match socket_mt_reg[] __read_mostly = { · 17 unmodified lines
512 (1 << NF_INET_LOCAL_IN),227 (1 << NF_INET_LOCAL_IN),
513 .me = THIS_MODULE,228 .me = THIS_MODULE,
514 },229 },
515#ifdef XT_SOCKET_HAVE_IPV6230#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
516 {231 {
517 .name = "socket",232 .name = "socket",
518 .revision = 2,233 .revision = 2,
@@ -536,7 +251,7 @@ static struct xt_match socket_mt_reg[] __read_mostly = { · 17 unmodified lines
536 (1 << NF_INET_LOCAL_IN),251 (1 << NF_INET_LOCAL_IN),
537 .me = THIS_MODULE,252 .me = THIS_MODULE,
538 },253 },
539#ifdef XT_SOCKET_HAVE_IPV6254#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
540 {255 {
541 .name = "socket",256 .name = "socket",
542 .revision = 3,257 .revision = 3,
@@ -554,7 +269,7 @@ static struct xt_match socket_mt_reg[] __read_mostly = { · 11 unmodified lines
554static int __init socket_mt_init(void)269static int __init socket_mt_init(void)
555{270{
556 nf_defrag_ipv4_enable();271 nf_defrag_ipv4_enable();
557#ifdef XT_SOCKET_HAVE_IPV6272#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
558 nf_defrag_ipv6_enable();273 nf_defrag_ipv6_enable();
559#endif274#endif
560 275

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t