diff options
| author | David S. Miller <davem@davemloft.net> | 2014-01-06 13:29:30 -0500 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2014-01-06 13:29:30 -0500 |
| commit | 9aa28f2b71055d5ae17a2e1daee359d4174bb13e (patch) | |
| tree | fbf4e0fd11eb924e0bece74a87f442bc54441b35 | |
| parent | 6a8c4796df74045088a916581c736432d08c53c0 (diff) | |
| parent | c9c8e485978a308c8a359140da187d55120f8fee (diff) | |
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nftables
Pablo Neira Ayuso says: <pablo@netfilter.org>
====================
nftables updates for net-next
The following patchset contains nftables updates for your net-next tree,
they are:
* Add set operation to the meta expression by means of the select_ops()
infrastructure, this allows us to set the packet mark among other things.
From Arturo Borrero Gonzalez.
* Fix wrong format in sscanf in nf_tables_set_alloc_name(), from Daniel
Borkmann.
* Add new queue expression to nf_tables. These comes with two previous patches
to prepare this new feature, one to add mask in nf_tables_core to
evaluate the queue verdict appropriately and another to refactor common
code with xt_NFQUEUE, from Eric Leblond.
* Do not hide nftables from Kconfig if nfnetlink is not enabled, also from
Eric Leblond.
* Add the reject expression to nf_tables, this adds the missing TCP RST
support. It comes with an initial patch to refactor common code with
xt_NFQUEUE, again from Eric Leblond.
* Remove an unused variable assignment in nf_tables_dump_set(), from Michal
Nazarewicz.
* Remove the nft_meta_target code, now that Arturo added the set operation
to the meta expression, from me.
* Add help information for nf_tables to Kconfig, also from me.
* Allow to dump all sets by specifying NFPROTO_UNSPEC, similar feature is
available to other nf_tables objects, requested by Arturo, from me.
* Expose the table usage counter, so we can know how many chains are using
this table without dumping the list of chains, from Tomasz Bursztyka.
====================
Signed-off-by: David S. Miller <davem@davemloft.net>
| -rw-r--r-- | include/net/netfilter/ipv4/nf_reject.h | 128 | ||||
| -rw-r--r-- | include/net/netfilter/ipv6/nf_reject.h | 171 | ||||
| -rw-r--r-- | include/net/netfilter/nf_queue.h | 62 | ||||
| -rw-r--r-- | include/uapi/linux/netfilter/nf_tables.h | 24 | ||||
| -rw-r--r-- | net/ipv4/netfilter/Kconfig | 18 | ||||
| -rw-r--r-- | net/ipv4/netfilter/Makefile | 1 | ||||
| -rw-r--r-- | net/ipv4/netfilter/ipt_REJECT.c | 140 | ||||
| -rw-r--r-- | net/ipv6/netfilter/Kconfig | 12 | ||||
| -rw-r--r-- | net/ipv6/netfilter/ip6t_REJECT.c | 179 | ||||
| -rw-r--r-- | net/netfilter/Kconfig | 59 | ||||
| -rw-r--r-- | net/netfilter/Makefile | 3 | ||||
| -rw-r--r-- | net/netfilter/nf_tables_api.c | 104 | ||||
| -rw-r--r-- | net/netfilter/nf_tables_core.c | 5 | ||||
| -rw-r--r-- | net/netfilter/nft_meta.c | 146 | ||||
| -rw-r--r-- | net/netfilter/nft_meta_target.c | 117 | ||||
| -rw-r--r-- | net/netfilter/nft_queue.c | 134 | ||||
| -rw-r--r-- | net/netfilter/nft_reject.c (renamed from net/ipv4/netfilter/nft_reject_ipv4.c) | 23 | ||||
| -rw-r--r-- | net/netfilter/xt_NFQUEUE.c | 80 |
18 files changed, 872 insertions, 534 deletions
diff --git a/include/net/netfilter/ipv4/nf_reject.h b/include/net/netfilter/ipv4/nf_reject.h new file mode 100644 index 000000000000..931fbf812171 --- /dev/null +++ b/include/net/netfilter/ipv4/nf_reject.h | |||
| @@ -0,0 +1,128 @@ | |||
| 1 | #ifndef _IPV4_NF_REJECT_H | ||
| 2 | #define _IPV4_NF_REJECT_H | ||
| 3 | |||
| 4 | #include <net/ip.h> | ||
| 5 | #include <net/tcp.h> | ||
| 6 | #include <net/route.h> | ||
| 7 | #include <net/dst.h> | ||
| 8 | |||
| 9 | static inline void nf_send_unreach(struct sk_buff *skb_in, int code) | ||
| 10 | { | ||
| 11 | icmp_send(skb_in, ICMP_DEST_UNREACH, code, 0); | ||
| 12 | } | ||
| 13 | |||
| 14 | /* Send RST reply */ | ||
| 15 | static void nf_send_reset(struct sk_buff *oldskb, int hook) | ||
| 16 | { | ||
| 17 | struct sk_buff *nskb; | ||
| 18 | const struct iphdr *oiph; | ||
| 19 | struct iphdr *niph; | ||
| 20 | const struct tcphdr *oth; | ||
| 21 | struct tcphdr _otcph, *tcph; | ||
| 22 | |||
| 23 | /* IP header checks: fragment. */ | ||
| 24 | if (ip_hdr(oldskb)->frag_off & htons(IP_OFFSET)) | ||
| 25 | return; | ||
| 26 | |||
| 27 | oth = skb_header_pointer(oldskb, ip_hdrlen(oldskb), | ||
| 28 | sizeof(_otcph), &_otcph); | ||
| 29 | if (oth == NULL) | ||
| 30 | return; | ||
| 31 | |||
| 32 | /* No RST for RST. */ | ||
| 33 | if (oth->rst) | ||
| 34 | return; | ||
| 35 | |||
| 36 | if (skb_rtable(oldskb)->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST)) | ||
| 37 | return; | ||
| 38 | |||
| 39 | /* Check checksum */ | ||
| 40 | if (nf_ip_checksum(oldskb, hook, ip_hdrlen(oldskb), IPPROTO_TCP)) | ||
| 41 | return; | ||
| 42 | oiph = ip_hdr(oldskb); | ||
| 43 | |||
| 44 | nskb = alloc_skb(sizeof(struct iphdr) + sizeof(struct tcphdr) + | ||
| 45 | LL_MAX_HEADER, GFP_ATOMIC); | ||
| 46 | if (!nskb) | ||
| 47 | return; | ||
| 48 | |||
| 49 | skb_reserve(nskb, LL_MAX_HEADER); | ||
| 50 | |||
| 51 | skb_reset_network_header(nskb); | ||
| 52 | niph = (struct iphdr *)skb_put(nskb, sizeof(struct iphdr)); | ||
| 53 | niph->version = 4; | ||
| 54 | niph->ihl = sizeof(struct iphdr) / 4; | ||
| 55 | niph->tos = 0; | ||
| 56 | niph->id = 0; | ||
| 57 | niph->frag_off = htons(IP_DF); | ||
| 58 | niph->protocol = IPPROTO_TCP; | ||
| 59 | niph->check = 0; | ||
| 60 | niph->saddr = oiph->daddr; | ||
| 61 | niph->daddr = oiph->saddr; | ||
| 62 | |||
| 63 | skb_reset_transport_header(nskb); | ||
| 64 | tcph = (struct tcphdr *)skb_put(nskb, sizeof(struct tcphdr)); | ||
| 65 | memset(tcph, 0, sizeof(*tcph)); | ||
| 66 | tcph->source = oth->dest; | ||
| 67 | tcph->dest = oth->source; | ||
| 68 | tcph->doff = sizeof(struct tcphdr) / 4; | ||
| 69 | |||
| 70 | if (oth->ack) | ||
| 71 | tcph->seq = oth->ack_seq; | ||
| 72 | else { | ||
| 73 | tcph->ack_seq = htonl(ntohl(oth->seq) + oth->syn + oth->fin + | ||
| 74 | oldskb->len - ip_hdrlen(oldskb) - | ||
| 75 | (oth->doff << 2)); | ||
| 76 | tcph->ack = 1; | ||
| 77 | } | ||
| 78 | |||
| 79 | tcph->rst = 1; | ||
| 80 | tcph->check = ~tcp_v4_check(sizeof(struct tcphdr), niph->saddr, | ||
| 81 | niph->daddr, 0); | ||
| 82 | nskb->ip_summed = CHECKSUM_PARTIAL; | ||
| 83 | nskb->csum_start = (unsigned char *)tcph - nskb->head; | ||
| 84 | nskb->csum_offset = offsetof(struct tcphdr, check); | ||
| 85 | |||
| 86 | /* ip_route_me_harder expects skb->dst to be set */ | ||
| 87 | skb_dst_set_noref(nskb, skb_dst(oldskb)); | ||
| 88 | |||
| 89 | nskb->protocol = htons(ETH_P_IP); | ||
| 90 | if (ip_route_me_harder(nskb, RTN_UNSPEC)) | ||
| 91 | goto free_nskb; | ||
| 92 | |||
| 93 | niph->ttl = ip4_dst_hoplimit(skb_dst(nskb)); | ||
| 94 | |||
| 95 | /* "Never happens" */ | ||
| 96 | if (nskb->len > dst_mtu(skb_dst(nskb))) | ||
| 97 | goto free_nskb; | ||
| 98 | |||
| 99 | nf_ct_attach(nskb, oldskb); | ||
| 100 | |||
| 101 | #ifdef CONFIG_BRIDGE_NETFILTER | ||
| 102 | /* If we use ip_local_out for bridged traffic, the MAC source on | ||
| 103 | * the RST will be ours, instead of the destination's. This confuses | ||
| 104 | * some routers/firewalls, and they drop the packet. So we need to | ||
| 105 | * build the eth header using the original destination's MAC as the | ||
| 106 | * source, and send the RST packet directly. | ||
| 107 | */ | ||
| 108 | if (oldskb->nf_bridge) { | ||
| 109 | struct ethhdr *oeth = eth_hdr(oldskb); | ||
| 110 | nskb->dev = oldskb->nf_bridge->physindev; | ||
| 111 | niph->tot_len = htons(nskb->len); | ||
| 112 | ip_send_check(niph); | ||
| 113 | if (dev_hard_header(nskb, nskb->dev, ntohs(nskb->protocol), | ||
| 114 | oeth->h_source, oeth->h_dest, nskb->len) < 0) | ||
| 115 | goto free_nskb; | ||
| 116 | dev_queue_xmit(nskb); | ||
| 117 | } else | ||
| 118 | #endif | ||
| 119 | ip_local_out(nskb); | ||
| 120 | |||
| 121 | return; | ||
| 122 | |||
| 123 | free_nskb: | ||
| 124 | kfree_skb(nskb); | ||
| 125 | } | ||
| 126 | |||
| 127 | |||
| 128 | #endif /* _IPV4_NF_REJECT_H */ | ||
diff --git a/include/net/netfilter/ipv6/nf_reject.h b/include/net/netfilter/ipv6/nf_reject.h new file mode 100644 index 000000000000..710d17ed70b4 --- /dev/null +++ b/include/net/netfilter/ipv6/nf_reject.h | |||
| @@ -0,0 +1,171 @@ | |||
| 1 | #ifndef _IPV6_NF_REJECT_H | ||
| 2 | #define _IPV6_NF_REJECT_H | ||
| 3 | |||
| 4 | #include <net/ipv6.h> | ||
| 5 | #include <net/ip6_route.h> | ||
| 6 | #include <net/ip6_fib.h> | ||
| 7 | #include <net/ip6_checksum.h> | ||
| 8 | #include <linux/netfilter_ipv6.h> | ||
| 9 | |||
| 10 | static inline void | ||
| 11 | nf_send_unreach6(struct net *net, struct sk_buff *skb_in, unsigned char code, | ||
| 12 | unsigned int hooknum) | ||
| 13 | { | ||
| 14 | if (hooknum == NF_INET_LOCAL_OUT && skb_in->dev == NULL) | ||
| 15 | skb_in->dev = net->loopback_dev; | ||
| 16 | |||
| 17 | icmpv6_send(skb_in, ICMPV6_DEST_UNREACH, code, 0); | ||
| 18 | } | ||
| 19 | |||
| 20 | /* Send RST reply */ | ||
| 21 | static void nf_send_reset6(struct net *net, struct sk_buff *oldskb, int hook) | ||
| 22 | { | ||
| 23 | struct sk_buff *nskb; | ||
| 24 | struct tcphdr otcph, *tcph; | ||
| 25 | unsigned int otcplen, hh_len; | ||
| 26 | int tcphoff, needs_ack; | ||
| 27 | |||
