Skip to content

Commit a210d01

Browse files
Julian Anastasovdavem330
authored andcommitted
ipv4: Loosen source address check on IPv4 output
ip_route_output() contains a check to make sure that no flows with non-local source IP addresses are routed. This obviously makes using such addresses impossible. This patch introduces a flowi flag which makes omitting this check possible. The new flag provides a way of handling transparent and non-transparent connections differently. Signed-off-by: Julian Anastasov <ja@ssi.bg> Signed-off-by: KOVACS Krisztian <hidden@sch.bme.hu> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4edd87a commit a210d01

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

‎include/net/flow.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ struct flowi {
4747
#define fl4_scope nl_u.ip4_u.scope
4848

4949
__u8 proto;
50+
__u8 flags;
51+
#define FLOWI_FLAG_ANYSRC 0x01
5052
union {
5153
struct {
5254
__be16 sport;

‎net/ipv4/route.c‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2361,11 +2361,6 @@ static int ip_route_output_slow(struct net *net, struct rtable **rp,
23612361
ipv4_is_zeronet(oldflp->fl4_src))
23622362
goto out;
23632363

2364-
/* It is equivalent to inet_addr_type(saddr) == RTN_LOCAL */
2365-
dev_out = ip_dev_find(net, oldflp->fl4_src);
2366-
if (dev_out == NULL)
2367-
goto out;
2368-
23692364
/* I removed check for oif == dev_out->oif here.
23702365
It was wrong for two reasons:
23712366
1. ip_dev_find(net, saddr) can return wrong iface, if saddr
@@ -2377,6 +2372,11 @@ static int ip_route_output_slow(struct net *net, struct rtable **rp,
23772372
if (oldflp->oif == 0
23782373
&& (ipv4_is_multicast(oldflp->fl4_dst) ||
23792374
oldflp->fl4_dst == htonl(0xFFFFFFFF))) {
2375+
/* It is equivalent to inet_addr_type(saddr) == RTN_LOCAL */
2376+
dev_out = ip_dev_find(net, oldflp->fl4_src);
2377+
if (dev_out == NULL)
2378+
goto out;
2379+
23802380
/* Special hack: user can direct multicasts
23812381
and limited broadcast via necessary interface
23822382
without fiddling with IP_MULTICAST_IF or IP_PKTINFO.
@@ -2395,9 +2395,15 @@ static int ip_route_output_slow(struct net *net, struct rtable **rp,
23952395
fl.oif = dev_out->ifindex;
23962396
goto make_route;
23972397
}
2398-
if (dev_out)
2398+
2399+
if (!(oldflp->flags & FLOWI_FLAG_ANYSRC)) {
2400+
/* It is equivalent to inet_addr_type(saddr) == RTN_LOCAL */
2401+
dev_out = ip_dev_find(net, oldflp->fl4_src);
2402+
if (dev_out == NULL)
2403+
goto out;
23992404
dev_put(dev_out);
2400-
dev_out = NULL;
2405+
dev_out = NULL;
2406+
}
24012407
}
24022408

24032409

0 commit comments

Comments
 (0)