Skip to content

Commit 8153a10

Browse files
kaberdavem330
authored andcommitted
ipv4 05/05: add sysctl to accept packets with local source addresses
commit 8ec1e0ebe26087bfc5c0394ada5feb5758014fc8 Author: Patrick McHardy <[email protected]> Date: Thu Dec 3 12:16:35 2009 +0100 ipv4: add sysctl to accept packets with local source addresses Change fib_validate_source() to accept packets with a local source address when the "accept_local" sysctl is set for the incoming inet device. Combined with the previous patches, this allows to communicate between multiple local interfaces over the wire. Signed-off-by: Patrick McHardy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5adef18 commit 8153a10

File tree

6 files changed

+17
-4
lines changed

6 files changed

+17
-4
lines changed

Documentation/networking/ip-sysctl.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,12 @@ accept_source_route - BOOLEAN
731731
default TRUE (router)
732732
FALSE (host)
733733

734+
accept_local - BOOLEAN
735+
Accept packets with local source addresses. In combination with
736+
suitable routing, this can be used to direct packets between two
737+
local interfaces over the wire and have them accepted properly.
738+
default FALSE
739+
734740
rp_filter - INTEGER
735741
0 - No source validation.
736742
1 - Strict mode as defined in RFC3704 Strict Reverse Path

include/linux/inetdevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ static inline void ipv4_devconf_setall(struct in_device *in_dev)
8383
#define IN_DEV_RPFILTER(in_dev) IN_DEV_MAXCONF((in_dev), RP_FILTER)
8484
#define IN_DEV_SOURCE_ROUTE(in_dev) IN_DEV_ANDCONF((in_dev), \
8585
ACCEPT_SOURCE_ROUTE)
86+
#define IN_DEV_ACCEPT_LOCAL(in_dev) IN_DEV_ORCONF((in_dev), ACCEPT_LOCAL)
8687
#define IN_DEV_BOOTP_RELAY(in_dev) IN_DEV_ANDCONF((in_dev), BOOTP_RELAY)
8788

8889
#define IN_DEV_LOG_MARTIANS(in_dev) IN_DEV_ORCONF((in_dev), LOG_MARTIANS)

include/linux/sysctl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ enum
490490
NET_IPV4_CONF_PROMOTE_SECONDARIES=20,
491491
NET_IPV4_CONF_ARP_ACCEPT=21,
492492
NET_IPV4_CONF_ARP_NOTIFY=22,
493+
NET_IPV4_CONF_ACCEPT_LOCAL=23,
493494
__NET_IPV4_CONF_MAX
494495
};
495496

kernel/sysctl_check.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ static const struct trans_ctl_table trans_net_ipv4_conf_vars_table[] = {
220220
{ NET_IPV4_CONF_PROMOTE_SECONDARIES, "promote_secondaries" },
221221
{ NET_IPV4_CONF_ARP_ACCEPT, "arp_accept" },
222222
{ NET_IPV4_CONF_ARP_NOTIFY, "arp_notify" },
223+
{ NET_IPV4_CONF_ACCEPT_LOCAL, "accept_local" },
223224
{}
224225
};
225226

net/ipv4/devinet.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,7 @@ static struct devinet_sysctl_table {
14681468
DEVINET_SYSCTL_RW_ENTRY(SEND_REDIRECTS, "send_redirects"),
14691469
DEVINET_SYSCTL_RW_ENTRY(ACCEPT_SOURCE_ROUTE,
14701470
"accept_source_route"),
1471+
DEVINET_SYSCTL_RW_ENTRY(ACCEPT_LOCAL, "accept_local"),
14711472
DEVINET_SYSCTL_RW_ENTRY(PROXY_ARP, "proxy_arp"),
14721473
DEVINET_SYSCTL_RW_ENTRY(MEDIUM_ID, "medium_id"),
14731474
DEVINET_SYSCTL_RW_ENTRY(BOOTP_RELAY, "bootp_relay"),

net/ipv4/fib_frontend.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,16 +241,17 @@ int fib_validate_source(__be32 src, __be32 dst, u8 tos, int oif,
241241
.iif = oif };
242242

243243
struct fib_result res;
244-
int no_addr, rpf;
244+
int no_addr, rpf, accept_local;
245245
int ret;
246246
struct net *net;
247247

248-
no_addr = rpf = 0;
248+
no_addr = rpf = accept_local = 0;
249249
rcu_read_lock();
250250
in_dev = __in_dev_get_rcu(dev);
251251
if (in_dev) {
252252
no_addr = in_dev->ifa_list == NULL;
253253
rpf = IN_DEV_RPFILTER(in_dev);
254+
accept_local = IN_DEV_ACCEPT_LOCAL(in_dev);
254255
}
255256
rcu_read_unlock();
256257

@@ -260,8 +261,10 @@ int fib_validate_source(__be32 src, __be32 dst, u8 tos, int oif,
260261
net = dev_net(dev);
261262
if (fib_lookup(net, &fl, &res))
262263
goto last_resort;
263-
if (res.type != RTN_UNICAST)
264-
goto e_inval_res;
264+
if (res.type != RTN_UNICAST) {
265+
if (res.type != RTN_LOCAL || !accept_local)
266+
goto e_inval_res;
267+
}
265268
*spec_dst = FIB_RES_PREFSRC(res);
266269
fib_combine_itag(itag, &res);
267270
#ifdef CONFIG_IP_ROUTE_MULTIPATH

0 commit comments

Comments
 (0)