Skip to content

Commit 797fd39

Browse files
Julian Anastasovdavem330
authored andcommitted
netfilter: TCP and raw fix for ip_route_me_harder
TCP in some cases uses different global (raw) socket to send RST and ACK. The transparent flag is not set there. Currently, it is a problem for rerouting after the previous change. Fix it by simplifying the checks in ip_route_me_harder and use FLOWI_FLAG_ANYSRC even for sockets. It looks safe because the initial routing allowed this source address to be used and now we just have to make sure the packet is rerouted. As a side effect this also allows rerouting for normal raw sockets that use spoofed source addresses which was not possible even before we eliminated the ip_route_input call. Signed-off-by: Julian Anastasov <ja@ssi.bg> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6602a4b commit 797fd39

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

‎net/ipv4/netfilter.c‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@ int ip_route_me_harder(struct sk_buff *skb, unsigned addr_type)
1818
struct rtable *rt;
1919
struct flowi4 fl4 = {};
2020
__be32 saddr = iph->saddr;
21-
__u8 flags = 0;
21+
__u8 flags = skb->sk ? inet_sk_flowi_flags(skb->sk) : 0;
2222
unsigned int hh_len;
2323

24-
if (!skb->sk && addr_type != RTN_LOCAL) {
25-
if (addr_type == RTN_UNSPEC)
26-
addr_type = inet_addr_type(net, saddr);
27-
if (addr_type == RTN_LOCAL || addr_type == RTN_UNICAST)
28-
flags |= FLOWI_FLAG_ANYSRC;
29-
else
30-
saddr = 0;
31-
}
24+
if (addr_type == RTN_UNSPEC)
25+
addr_type = inet_addr_type(net, saddr);
26+
if (addr_type == RTN_LOCAL || addr_type == RTN_UNICAST)
27+
flags |= FLOWI_FLAG_ANYSRC;
28+
else
29+
saddr = 0;
3230

3331
/* some non-standard hacks like ipt_REJECT.c:send_reset() can cause
3432
* packets with foreign saddr to appear on the NF_INET_LOCAL_OUT hook.
@@ -38,7 +36,7 @@ int ip_route_me_harder(struct sk_buff *skb, unsigned addr_type)
3836
fl4.flowi4_tos = RT_TOS(iph->tos);
3937
fl4.flowi4_oif = skb->sk ? skb->sk->sk_bound_dev_if : 0;
4038
fl4.flowi4_mark = skb->mark;
41-
fl4.flowi4_flags = skb->sk ? inet_sk_flowi_flags(skb->sk) : flags;
39+
fl4.flowi4_flags = flags;
4240
rt = ip_route_output_key(net, &fl4);
4341
if (IS_ERR(rt))
4442
return -1;

0 commit comments

Comments
 (0)