1 #ifndef _IPV4_NF_REJECT_H
2 #define _IPV4_NF_REJECT_H
9 static inline void nf_send_unreach(struct sk_buff *skb_in, int code)
11 icmp_send(skb_in, ICMP_DEST_UNREACH, code, 0);
15 static void nf_send_reset(struct sk_buff *oldskb, int hook)
18 const struct iphdr *oiph;
20 const struct tcphdr *oth;
21 struct tcphdr _otcph, *tcph;
23 /* IP header checks: fragment. */
24 if (ip_hdr(oldskb)->frag_off & htons(IP_OFFSET))
27 oth = skb_header_pointer(oldskb, ip_hdrlen(oldskb),
28 sizeof(_otcph), &_otcph);
36 if (skb_rtable(oldskb)->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST))
40 if (nf_ip_checksum(oldskb, hook, ip_hdrlen(oldskb), IPPROTO_TCP))
42 oiph = ip_hdr(oldskb);
44 nskb = alloc_skb(sizeof(struct iphdr) + sizeof(struct tcphdr) +
45 LL_MAX_HEADER, GFP_ATOMIC);
49 skb_reserve(nskb, LL_MAX_HEADER);
51 skb_reset_network_header(nskb);
52 niph = (struct iphdr *)skb_put(nskb, sizeof(struct iphdr));
54 niph->ihl = sizeof(struct iphdr) / 4;
57 niph->frag_off = htons(IP_DF);
58 niph->protocol = IPPROTO_TCP;
60 niph->saddr = oiph->daddr;
61 niph->daddr = oiph->saddr;
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;
71 tcph->seq = oth->ack_seq;
73 tcph->ack_seq = htonl(ntohl(oth->seq) + oth->syn + oth->fin +
74 oldskb->len - ip_hdrlen(oldskb) -
80 tcph->check = ~tcp_v4_check(sizeof(struct tcphdr), niph->saddr,
82 nskb->ip_summed = CHECKSUM_PARTIAL;
83 nskb->csum_start = (unsigned char *)tcph - nskb->head;
84 nskb->csum_offset = offsetof(struct tcphdr, check);
86 /* ip_route_me_harder expects skb->dst to be set */
87 skb_dst_set_noref(nskb, skb_dst(oldskb));
89 nskb->protocol = htons(ETH_P_IP);
90 if (ip_route_me_harder(nskb, RTN_UNSPEC))
93 niph->ttl = ip4_dst_hoplimit(skb_dst(nskb));
96 if (nskb->len > dst_mtu(skb_dst(nskb)))
99 nf_ct_attach(nskb, oldskb);
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.
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);
113 if (dev_hard_header(nskb, nskb->dev, ntohs(nskb->protocol),
114 oeth->h_source, oeth->h_dest, nskb->len) < 0)
116 dev_queue_xmit(nskb);
128 #endif /* _IPV4_NF_REJECT_H */