diff options
| -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 | const struct ipv6hdr *oip6h = ipv6_hdr(oldskb); | ||
| 28 | struct ipv6hdr *ip6h; | ||
| 29 | #define DEFAULT_TOS_VALUE 0x0U | ||
| 30 | const __u8 tclass = DEFAULT_TOS_VALUE; | ||
| 31 | struct dst_entry *dst = NULL; | ||
| 32 | u8 proto; | ||
| 33 | __be16 frag_off; | ||
| 34 | struct flowi6 fl6; | ||
| 35 | |||
| 36 | if ((!(ipv6_addr_type(&oip6h->saddr) & IPV6_ADDR_UNICAST)) || | ||
| 37 | (!(ipv6_addr_type(&oip6h->daddr) & IPV6_ADDR_UNICAST))) { | ||
| 38 | pr_debug("addr is not unicast.\n"); | ||
