* [PATCH net-next] ipv6: sysctl to restrict candidate source addresses
@ 2015-07-03 4:49 Erik Kline
2015-07-03 7:03 ` YOSHIFUJI Hideaki
0 siblings, 1 reply; 3+ messages in thread
From: Erik Kline @ 2015-07-03 4:49 UTC (permalink / raw)
To: hannes; +Cc: lorenzo, netdev, davem, hideaki.yoshifuji, Erik Kline
Per RFC 6724, section 4, "Candidate Source Addresses":
It is RECOMMENDED that the candidate source addresses be the set
of unicast addresses assigned to the interface that will be used
to send to the destination (the "outgoing" interface).
Add a sysctl to enable this behaviour.
Signed-off-by: Erik Kline <ek@google.com>
---
Documentation/networking/ip-sysctl.txt | 12 ++++++++++++
include/linux/ipv6.h | 1 +
include/uapi/linux/ipv6.h | 1 +
net/ipv6/addrconf.c | 30 +++++++++++++++++++++++++-----
4 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/Documentation/networking/ip-sysctl.txt b/Documentation/networking/ip-sysctl.txt
index 5fae770..d8f3e60 100644
--- a/Documentation/networking/ip-sysctl.txt
+++ b/Documentation/networking/ip-sysctl.txt
@@ -1435,6 +1435,18 @@ mtu - INTEGER
Default Maximum Transfer Unit
Default: 1280 (IPv6 required minimum)
+restrict_srcaddr - INTEGER
+ Restrict candidate source addresses (vis. RFC 6724, section 4).
+
+ When set to 1, the candidate source addresses for destinations
+ routed via this interface are restricted to the set of addresses
+ configured on this interface.
+
+ Possible values are:
+ 0 : no source address restrictions
+ 1 : require matching outgoing interface
+ Default: 0
+
router_probe_interval - INTEGER
Minimum interval (in seconds) between Router Probing described
in RFC4191.
diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h
index 82806c6..6867d1f 100644
--- a/include/linux/ipv6.h
+++ b/include/linux/ipv6.h
@@ -57,6 +57,7 @@ struct ipv6_devconf {
bool initialized;
struct in6_addr secret;
} stable_secret;
+ __s32 restrict_srcaddr;
void *sysctl;
};
diff --git a/include/uapi/linux/ipv6.h b/include/uapi/linux/ipv6.h
index 5efa54a..b174758 100644
--- a/include/uapi/linux/ipv6.h
+++ b/include/uapi/linux/ipv6.h
@@ -171,6 +171,7 @@ enum {
DEVCONF_USE_OPTIMISTIC,
DEVCONF_ACCEPT_RA_MTU,
DEVCONF_STABLE_SECRET,
+ DEVCONF_RESTRICT_SRCADDR,
DEVCONF_MAX
};
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index 21c2c81..f72c974 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -211,7 +211,8 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = {
.accept_ra_mtu = 1,
.stable_secret = {
.initialized = false,
- }
+ },
+ .restrict_srcaddr = 0,
};
static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
@@ -253,6 +254,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
.stable_secret = {
.initialized = false,
},
+ .restrict_srcaddr = 0,
};
/* Check if a valid qdisc is available */
@@ -1366,7 +1368,8 @@ int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
*score = &scores[0], *hiscore = &scores[1];
struct ipv6_saddr_dst dst;
struct net_device *dev;
- int dst_type;
+ struct inet6_dev *idev;
+ int dst_type, restrict_srcaddr = 0;
dst_type = __ipv6_addr_type(daddr);
dst.addr = daddr;
@@ -1380,9 +1383,12 @@ int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
rcu_read_lock();
- for_each_netdev_rcu(net, dev) {
- struct inet6_dev *idev;
+ if (dst_dev) {
+ idev = __in6_dev_get(dst_dev);
+ restrict_srcaddr = (idev) ? idev->cnf.restrict_srcaddr : 0;
+ }
+ for_each_netdev_rcu(net, dev) {
/* Candidate Source Address (section 4)
* - multicast and link-local destination address,
* the set of candidate source address MUST only
@@ -1394,9 +1400,14 @@ int ipv6_dev_get_saddr(struct net *net, const struct net_device *dst_dev,
* include addresses assigned to interfaces
* belonging to the same site as the outgoing
* interface.)
+ * - "It is RECOMMENDED that the candidate source addresses
+ * be the set of unicast addresses assigned to the
+ * interface that will be used to send to the destination
+ * (the 'outgoing' interface)." (RFC 6724)
*/
if (((dst_type & IPV6_ADDR_MULTICAST) ||
- dst.scope <= IPV6_ADDR_SCOPE_LINKLOCAL) &&
+ dst.scope <= IPV6_ADDR_SCOPE_LINKLOCAL ||
+ restrict_srcaddr) &&
dst.ifindex && dev->ifindex != dst.ifindex)
continue;
@@ -4586,6 +4597,7 @@ static inline void ipv6_store_devconf(struct ipv6_devconf *cnf,
array[DEVCONF_ACCEPT_RA_FROM_LOCAL] = cnf->accept_ra_from_local;
array[DEVCONF_ACCEPT_RA_MTU] = cnf->accept_ra_mtu;
/* we omit DEVCONF_STABLE_SECRET for now */
+ array[DEVCONF_RESTRICT_SRCADDR] = cnf->restrict_srcaddr;
}
static inline size_t inet6_ifla6_size(void)
@@ -5585,6 +5597,14 @@ static struct addrconf_sysctl_table
.proc_handler = addrconf_sysctl_stable_secret,
},
{
+ .procname = "restrict_srcaddr",
+ .data = &ipv6_devconf.restrict_srcaddr,
+ .maxlen = sizeof(int),
+ .mode = 0644,
+ .proc_handler = proc_dointvec,
+
+ },
+ {
/* sentinel */
}
},
--
2.4.3.573.g4eafbef
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] ipv6: sysctl to restrict candidate source addresses
2015-07-03 4:49 [PATCH net-next] ipv6: sysctl to restrict candidate source addresses Erik Kline
@ 2015-07-03 7:03 ` YOSHIFUJI Hideaki
2015-07-06 3:06 ` Erik Kline
0 siblings, 1 reply; 3+ messages in thread
From: YOSHIFUJI Hideaki @ 2015-07-03 7:03 UTC (permalink / raw)
To: Erik Kline, hannes; +Cc: hideaki.yoshifuji, lorenzo, netdev, davem
Hi,
Erik Kline wrote:
> Per RFC 6724, section 4, "Candidate Source Addresses":
>
> It is RECOMMENDED that the candidate source addresses be the set
> of unicast addresses assigned to the interface that will be used
> to send to the destination (the "outgoing" interface).
>
> Add a sysctl to enable this behaviour.
>
> Signed-off-by: Erik Kline <ek@google.com>
> ---
> Documentation/networking/ip-sysctl.txt | 12 ++++++++++++
> include/linux/ipv6.h | 1 +
> include/uapi/linux/ipv6.h | 1 +
> net/ipv6/addrconf.c | 30 +++++++++++++++++++++++++-----
> 4 files changed, 39 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/networking/ip-sysctl.txt b/Documentation/networking/ip-sysctl.txt
> index 5fae770..d8f3e60 100644
> --- a/Documentation/networking/ip-sysctl.txt
> +++ b/Documentation/networking/ip-sysctl.txt
> @@ -1435,6 +1435,18 @@ mtu - INTEGER
> Default Maximum Transfer Unit
> Default: 1280 (IPv6 required minimum)
>
> +restrict_srcaddr - INTEGER
> + Restrict candidate source addresses (vis. RFC 6724, section 4).
> +
> + When set to 1, the candidate source addresses for destinations
> + routed via this interface are restricted to the set of addresses
> + configured on this interface.
> +
> + Possible values are:
> + 0 : no source address restrictions
> + 1 : require matching outgoing interface
> + Default: 0
> +
I cannot get what "restrict" restricts. How about "use_oif_addr" or
something like that (like use_tempaddr)?
--
Hideaki Yoshifuji <hideaki.yoshifuji@miraclelinux.com>
Technical Division, MIRACLE LINUX CORPORATION
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] ipv6: sysctl to restrict candidate source addresses
2015-07-03 7:03 ` YOSHIFUJI Hideaki
@ 2015-07-06 3:06 ` Erik Kline
0 siblings, 0 replies; 3+ messages in thread
From: Erik Kline @ 2015-07-06 3:06 UTC (permalink / raw)
To: YOSHIFUJI Hideaki
Cc: Hannes Frederic Sowa, Lorenzo Colitti, netdev, David Miller
Reworked with "use_oif_addr".
Thanks,
-Erik
On 3 July 2015 at 16:03, YOSHIFUJI Hideaki
<hideaki.yoshifuji@miraclelinux.com> wrote:
> Hi,
>
> Erik Kline wrote:
>> Per RFC 6724, section 4, "Candidate Source Addresses":
>>
>> It is RECOMMENDED that the candidate source addresses be the set
>> of unicast addresses assigned to the interface that will be used
>> to send to the destination (the "outgoing" interface).
>>
>> Add a sysctl to enable this behaviour.
>>
>> Signed-off-by: Erik Kline <ek@google.com>
>> ---
>> Documentation/networking/ip-sysctl.txt | 12 ++++++++++++
>> include/linux/ipv6.h | 1 +
>> include/uapi/linux/ipv6.h | 1 +
>> net/ipv6/addrconf.c | 30 +++++++++++++++++++++++++-----
>> 4 files changed, 39 insertions(+), 5 deletions(-)
>>
>> diff --git a/Documentation/networking/ip-sysctl.txt b/Documentation/networking/ip-sysctl.txt
>> index 5fae770..d8f3e60 100644
>> --- a/Documentation/networking/ip-sysctl.txt
>> +++ b/Documentation/networking/ip-sysctl.txt
>> @@ -1435,6 +1435,18 @@ mtu - INTEGER
>> Default Maximum Transfer Unit
>> Default: 1280 (IPv6 required minimum)
>>
>> +restrict_srcaddr - INTEGER
>> + Restrict candidate source addresses (vis. RFC 6724, section 4).
>> +
>> + When set to 1, the candidate source addresses for destinations
>> + routed via this interface are restricted to the set of addresses
>> + configured on this interface.
>> +
>> + Possible values are:
>> + 0 : no source address restrictions
>> + 1 : require matching outgoing interface
>> + Default: 0
>> +
>
> I cannot get what "restrict" restricts. How about "use_oif_addr" or
> something like that (like use_tempaddr)?
>
> --
> Hideaki Yoshifuji <hideaki.yoshifuji@miraclelinux.com>
> Technical Division, MIRACLE LINUX CORPORATION
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-07-06 3:06 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-03 4:49 [PATCH net-next] ipv6: sysctl to restrict candidate source addresses Erik Kline
2015-07-03 7:03 ` YOSHIFUJI Hideaki
2015-07-06 3:06 ` Erik Kline
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).