Skip to content

Commit 3d1bec9

Browse files
strssndktndavem330
authored andcommitted
ipv6: introduce secret_stable to ipv6_devconf
This patch implements the procfs logic for the stable_address knob: The secret is formatted as an ipv6 address and will be stored per interface and per namespace. We track initialized flag and return EIO errors until the secret is set. We don't inherit the secret to newly created namespaces. Cc: Erik Kline <ek@google.com> Cc: Fernando Gont <fgont@si6networks.com> Cc: Lorenzo Colitti <lorenzo@google.com> Cc: YOSHIFUJI Hideaki/吉藤英明 <hideaki.yoshifuji@miraclelinux.com> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent ab2bb32 commit 3d1bec9

3 files changed

Lines changed: 73 additions & 0 deletions

File tree

‎include/linux/ipv6.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ struct ipv6_devconf {
5353
__s32 ndisc_notify;
5454
__s32 suppress_frag_ndisc;
5555
__s32 accept_ra_mtu;
56+
struct ipv6_stable_secret {
57+
bool initialized;
58+
struct in6_addr secret;
59+
} stable_secret;
5660
void *sysctl;
5761
};
5862

‎include/uapi/linux/ipv6.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ enum {
170170
DEVCONF_ACCEPT_RA_FROM_LOCAL,
171171
DEVCONF_USE_OPTIMISTIC,
172172
DEVCONF_ACCEPT_RA_MTU,
173+
DEVCONF_STABLE_SECRET,
173174
DEVCONF_MAX
174175
};
175176

‎net/ipv6/addrconf.c‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <linux/socket.h>
4747
#include <linux/sockios.h>
4848
#include <linux/net.h>
49+
#include <linux/inet.h>
4950
#include <linux/in6.h>
5051
#include <linux/netdevice.h>
5152
#include <linux/if_addr.h>
@@ -102,6 +103,9 @@
102103

103104
#define INFINITY_LIFE_TIME 0xFFFFFFFF
104105

106+
#define IPV6_MAX_STRLEN \
107+
sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")
108+
105109
static inline u32 cstamp_delta(unsigned long cstamp)
106110
{
107111
return (cstamp - INITIAL_JIFFIES) * 100UL / HZ;
@@ -202,6 +206,9 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = {
202206
.accept_dad = 1,
203207
.suppress_frag_ndisc = 1,
204208
.accept_ra_mtu = 1,
209+
.stable_secret = {
210+
.initialized = false,
211+
}
205212
};
206213

207214
static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
@@ -240,6 +247,9 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
240247
.accept_dad = 1,
241248
.suppress_frag_ndisc = 1,
242249
.accept_ra_mtu = 1,
250+
.stable_secret = {
251+
.initialized = false,
252+
},
243253
};
244254

245255
/* Check if a valid qdisc is available */
@@ -4430,6 +4440,7 @@ static inline void ipv6_store_devconf(struct ipv6_devconf *cnf,
44304440
array[DEVCONF_SUPPRESS_FRAG_NDISC] = cnf->suppress_frag_ndisc;
44314441
array[DEVCONF_ACCEPT_RA_FROM_LOCAL] = cnf->accept_ra_from_local;
44324442
array[DEVCONF_ACCEPT_RA_MTU] = cnf->accept_ra_mtu;
4443+
/* we omit DEVCONF_STABLE_SECRET for now */
44334444
}
44344445

44354446
static inline size_t inet6_ifla6_size(void)
@@ -5074,6 +5085,53 @@ int addrconf_sysctl_proxy_ndp(struct ctl_table *ctl, int write,
50745085
return ret;
50755086
}
50765087

5088+
static int addrconf_sysctl_stable_secret(struct ctl_table *ctl, int write,
5089+
void __user *buffer, size_t *lenp,
5090+
loff_t *ppos)
5091+
{
5092+
int err;
5093+
struct in6_addr addr;
5094+
char str[IPV6_MAX_STRLEN];
5095+
struct ctl_table lctl = *ctl;
5096+
struct ipv6_stable_secret *secret = ctl->data;
5097+
5098+
lctl.maxlen = IPV6_MAX_STRLEN;
5099+
lctl.data = str;
5100+
5101+
if (!rtnl_trylock())
5102+
return restart_syscall();
5103+
5104+
if (!write && !secret->initialized) {
5105+
err = -EIO;
5106+
goto out;
5107+
}
5108+
5109+
if (!write) {
5110+
err = snprintf(str, sizeof(str), "%pI6",
5111+
&secret->secret);
5112+
if (err >= sizeof(str)) {
5113+
err = -EIO;
5114+
goto out;
5115+
}
5116+
}
5117+
5118+
err = proc_dostring(&lctl, write, buffer, lenp, ppos);
5119+
if (err || !write)
5120+
goto out;
5121+
5122+
if (in6_pton(str, -1, addr.in6_u.u6_addr8, -1, NULL) != 1) {
5123+
err = -EIO;
5124+
goto out;
5125+
}
5126+
5127+
secret->initialized = true;
5128+
secret->secret = addr;
5129+
5130+
out:
5131+
rtnl_unlock();
5132+
5133+
return err;
5134+
}
50775135

50785136
static struct addrconf_sysctl_table
50795137
{
@@ -5346,6 +5404,13 @@ static struct addrconf_sysctl_table
53465404
.mode = 0644,
53475405
.proc_handler = proc_dointvec,
53485406
},
5407+
{
5408+
.procname = "stable_secret",
5409+
.data = &ipv6_devconf.stable_secret,
5410+
.maxlen = IPV6_MAX_STRLEN,
5411+
.mode = 0600,
5412+
.proc_handler = addrconf_sysctl_stable_secret,
5413+
},
53495414
{
53505415
/* sentinel */
53515416
}
@@ -5442,6 +5507,9 @@ static int __net_init addrconf_init_net(struct net *net)
54425507
dflt->autoconf = ipv6_defaults.autoconf;
54435508
dflt->disable_ipv6 = ipv6_defaults.disable_ipv6;
54445509

5510+
dflt->stable_secret.initialized = false;
5511+
all->stable_secret.initialized = false;
5512+
54455513
net->ipv6.devconf_all = all;
54465514
net->ipv6.devconf_dflt = dflt;
54475515

0 commit comments

Comments
 (0)