Skip to contentSkip to conversation

ipv6: allow temporary address management for user-created addresses

RFC PATCH In review Jiri Pirko 4 participants 11 messages Nov 19, 2013 – Nov 27, 2013

Subsystems (3)
lore
Share & tools
lore

Jiri Pirko

author
#0 lore raw

v2 cover ipv6: allow temporary address management for user-created addresses

Both kernel patches were modified, see details in each patch description. No modification to iproute2 patches was done.

Jiri Pirko (2):
ipv6 addrconf: extend ifa_flags to u32
ipv6 addrconf: introduce IFA_F_MANAGETEMPADDR to tell kernel to manage
temporary addresses

 include/net/addrconf.h       |   4 +-
 include/net/if_inet6.h       |   2 +-
 include/uapi/linux/if_addr.h |   5 ++
 net/ipv6/addrconf.c          | 197 +++++++++++++++++++++++++------------------
 4 files changed, 122 insertions(+), 86 deletions(-)
Signature · 1 line
1.8.3.1
author
#1 lore raw

RFC PATCH v2 1/2 ipv6 addrconf: extend ifa_flags to u32

There is no more space in u8 ifa_flags. So do what davem suffested and add another netlink attr called IFA_FLAGS for carry more flags.

---
v1->v2:
- reordered struct inet6_ifaddr as suggested by David Laight
- changed flags type to u32 on couple of places as suggested by Thomas Haller
- changed output of if6_seq_show as suggested by Thomas Haller

 include/net/addrconf.h       |  4 ++--
 include/net/if_inet6.h       |  2 +-
 include/uapi/linux/if_addr.h |  4 ++++
 net/ipv6/addrconf.c          | 32 ++++++++++++++++++++------------
 4 files changed, 27 insertions(+), 15 deletions(-)
include/net/addrconf.h +2 -2
index 86505bf..e70278e 100644
@@ -81,9 +81,9 @@ int ipv6_dev_get_saddr(struct net *net, const struct net_device *dev,
 		       const struct in6_addr *daddr, unsigned int srcprefs,
 		       struct in6_addr *saddr);
 int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
-		      unsigned char banned_flags);
+		      u32 banned_flags);
 int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
-		    unsigned char banned_flags);
+		    u32 banned_flags);
 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2);
 void addrconf_join_solict(struct net_device *dev, const struct in6_addr *addr);
 void addrconf_leave_solict(struct inet6_dev *idev, const struct in6_addr *addr);
include/net/if_inet6.h +1 -1
index 76d5427..b58c36c 100644
@@ -50,8 +50,8 @@ struct inet6_ifaddr {
 
 	int			state;
 
+	__u32			flags;
 	__u8			dad_probes;
-	__u8			flags;
 
 	__u16			scope;
 
include/uapi/linux/if_addr.h +4 -0
index 23357ab..8ab0c2c 100644
@@ -18,6 +18,9 @@ struct ifaddrmsg {
  * It makes no difference for normally configured broadcast interfaces,
  * but for point-to-point IFA_ADDRESS is DESTINATION address,
  * local address is supplied in IFA_LOCAL attribute.
+ *
+ * IFA_FLAGS is a u32 attribute that extends the u8 field ifa_flags.
+ * If present, the value from struct ifaddrmsg will be ignored.
  */
 enum {
 	IFA_UNSPEC,
@@ -28,6 +31,7 @@ enum {
 	IFA_ANYCAST,
 	IFA_CACHEINFO,
 	IFA_MULTICAST,
+	IFA_FLAGS,
 	__IFA_MAX,
 };
 
net/ipv6/addrconf.c +20 -12
index 542d095..c94da31 100644
@@ -1393,7 +1393,7 @@ try_nextdev:
 EXPORT_SYMBOL(ipv6_dev_get_saddr);
 
 int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
-		      unsigned char banned_flags)
+		      u32 banned_flags)
 {
 	struct inet6_ifaddr *ifp;
 	int err = -EADDRNOTAVAIL;
@@ -1410,7 +1410,7 @@ int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr,
 }
 
 int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr,
-		    unsigned char banned_flags)
+		    u32 banned_flags)
 {
 	struct inet6_dev *idev;
 	int err = -EADDRNOTAVAIL;
@@ -2181,7 +2181,7 @@ ok:
 		}
 
 		if (ifp) {
-			int flags;
+			u32 flags;
 			unsigned long now;
 			struct inet6_ifaddr *ift;
 			u32 stored_lft;
@@ -2366,10 +2366,11 @@ err_exit:
 /*
  *	Manual configuration of address on an interface
  */
-static int inet6_addr_add(struct net *net, int ifindex, const struct in6_addr *pfx,
+static int inet6_addr_add(struct net *net, int ifindex,
+			  const struct in6_addr *pfx,
 			  const struct in6_addr *peer_pfx,
-			  unsigned int plen, __u8 ifa_flags, __u32 prefered_lft,
-			  __u32 valid_lft)
+			  unsigned int plen, __u32 ifa_flags,
+			  __u32 prefered_lft, __u32 valid_lft)
 {
 	struct inet6_ifaddr *ifp;
 	struct inet6_dev *idev;
@@ -3357,7 +3358,7 @@ static void if6_seq_stop(struct seq_file *seq, void *v)
 static int if6_seq_show(struct seq_file *seq, void *v)
 {
 	struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
-	seq_printf(seq, "%pi6 %02x %02x %02x %02x %8s\n",
+	seq_printf(seq, "%pi6 %02x %02x %02x %03x %8s\n",
 		   &ifp->addr,
 		   ifp->idev->dev->ifindex,
 		   ifp->prefix_len,
@@ -3578,6 +3579,7 @@ static const struct nla_policy ifa_ipv6_policy[IFA_MAX+1] = {
 	[IFA_ADDRESS]		= { .len = sizeof(struct in6_addr) },
 	[IFA_LOCAL]		= { .len = sizeof(struct in6_addr) },
 	[IFA_CACHEINFO]		= { .len = sizeof(struct ifa_cacheinfo) },
+	[IFA_FLAGS]		= { .len = sizeof(u32) },
 };
 
 static int
@@ -3601,7 +3603,7 @@ inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh)
 	return inet6_addr_del(net, ifm->ifa_index, pfx, ifm->ifa_prefixlen);
 }
 
-static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags,
+static int inet6_addr_modify(struct inet6_ifaddr *ifp, u32 ifa_flags,
 			     u32 prefered_lft, u32 valid_lft)
 {
 	u32 flags;
@@ -3656,7 +3658,7 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh)
 	struct inet6_ifaddr *ifa;
 	struct net_device *dev;
 	u32 valid_lft = INFINITY_LIFE_TIME, preferred_lft = INFINITY_LIFE_TIME;
-	u8 ifa_flags;
+	u32 ifa_flags;
 	int err;
 
 	err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
@@ -3683,8 +3685,10 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh)
 	if (dev == NULL)
 		return -ENODEV;
 
+	ifa_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) : ifm->ifa_flags;
+
 	/* We ignore other flags so far. */
-	ifa_flags = ifm->ifa_flags & (IFA_F_NODAD | IFA_F_HOMEADDRESS);
+	ifa_flags &= IFA_F_NODAD | IFA_F_HOMEADDRESS;
 
 	ifa = ipv6_get_ifaddr(net, pfx, dev, 1);
 	if (ifa == NULL) {
@@ -3708,7 +3712,7 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh)
 	return err;
 }
 
-static void put_ifaddrmsg(struct nlmsghdr *nlh, u8 prefixlen, u8 flags,
+static void put_ifaddrmsg(struct nlmsghdr *nlh, u8 prefixlen, u32 flags,
 			  u8 scope, int ifindex)
 {
 	struct ifaddrmsg *ifm;
@@ -3751,7 +3755,8 @@ static inline int inet6_ifaddr_msgsize(void)
 	return NLMSG_ALIGN(sizeof(struct ifaddrmsg))
 	       + nla_total_size(16) /* IFA_LOCAL */
 	       + nla_total_size(16) /* IFA_ADDRESS */
-	       + nla_total_size(sizeof(struct ifa_cacheinfo));
+	       + nla_total_size(sizeof(struct ifa_cacheinfo))
+	       + nla_total_size(4)  /* IFA_FLAGS */;
 }
 
 static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa,
@@ -3799,6 +3804,9 @@ static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa,
 	if (put_cacheinfo(skb, ifa->cstamp, ifa->tstamp, preferred, valid) < 0)
 		goto error;
 
+	if (nla_put_u32(skb, IFA_FLAGS, ifa->flags) < 0)
+		goto error;
+
 	return nlmsg_end(skb, nlh);
 
 error:
Signature · 1 line
1.8.3.1
maintainer
#2 lore raw

Re: [patch net-next RFC v2 1/2] ipv6 addrconf: extend ifa_flags to u32

From: Jiri Pirko <[email protected]>
Date: Tue, 19 Nov 2013 11:43:28 +0100

Quoted 10 lines

There is no more space in u8 ifa_flags. So do what davem suffested and add another netlink attr called IFA_FLAGS for carry more flags.

---
v1->v2:
- reordered struct inet6_ifaddr as suggested by David Laight
- changed flags type to u32 on couple of places as suggested by Thomas Haller
- changed output of if6_seq_show as suggested by Thomas Haller

This looks fine, but I would suggest to extend this to all addressing types using ifm->ifa_flags. It is not such a big deal, there are only 3 or 4.

DecNET, ipv4, ipv6, and lastly phonet (which just reports "permanent" flag on get/dump).

That way tools like iproute2 can just generically provide and interpret IFA_FLAGS attribute unconditionally.

author
#3 lore raw

Re: [patch net-next RFC v2 1/2] ipv6 addrconf: extend ifa_flags to u32

Quoted 14 lines · Tue, Nov 19, 2013 at 10:16:53PM CET, [email protected] wrote:

From: Jiri Pirko <[email protected]>
Date: Tue, 19 Nov 2013 11:43:28 +0100

Quoted 10 lines

There is no more space in u8 ifa_flags. So do what davem suffested and add another netlink attr called IFA_FLAGS for carry more flags.

---
v1->v2:
- reordered struct inet6_ifaddr as suggested by David Laight
- changed flags type to u32 on couple of places as suggested by Thomas Haller
- changed output of if6_seq_show as suggested by Thomas Haller

Quoted 3 lines

This looks fine, but I would suggest to extend this to all addressing types using ifm->ifa_flags. It is not such a big deal, there are only 3 or 4.

Okay - I will do that.

Quoted 6 lines

DecNET, ipv4, ipv6, and lastly phonet (which just reports "permanent" flag on get/dump).

That way tools like iproute2 can just generically provide and interpret IFA_FLAGS attribute unconditionally.

Well the check and ->ifa_flags fallback needs to be in iproute2 anyway in order to maintain compatibility with older kernels.

Thanks for review!

Jiri

author
#4 lore raw

RFC PATCH v2 1/2 add support for extended ifa_flags

In reply to Jiri Pirko
---
 include/linux/if_addr.h |  1 +
 ip/ipaddress.c          | 44 ++++++++++++++++++++++++++++++--------------
 2 files changed, 31 insertions(+), 14 deletions(-)
include/linux/if_addr.h +1 -0
index 58b39f4..cced59f 100644
@@ -28,6 +28,7 @@ enum {
 	IFA_ANYCAST,
 	IFA_CACHEINFO,
 	IFA_MULTICAST,
+	IFA_FLAGS,
 	__IFA_MAX,
 };
 
ip/ipaddress.c +30 -14

123 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author
#5 lore raw

RFC PATCH v2 2/2 add support for IFA_F_MANAGETEMPADDR

---
 include/linux/if_addr.h | 1 +
 ip/ipaddress.c          | 6 ++++++
 2 files changed, 7 insertions(+)
include/linux/if_addr.h +1 -0
index cced59f..e1e95ce 100644
@@ -45,6 +45,7 @@ enum {
 #define IFA_F_DEPRECATED	0x20
 #define IFA_F_TENTATIVE		0x40
 #define IFA_F_PERMANENT		0x80
+#define IFA_F_MANAGETEMPADDR	0x0100
 
 struct ifa_cacheinfo {
 	__u32	ifa_prefered;
ip/ipaddress.c +6 -0
index 59dbd71..fa6417d 100644
@@ -703,6 +703,10 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
 		ifa_flags &= ~IFA_F_NODAD;
 		fprintf(fp, "nodad ");
 	}
+	if (ifa_flags & IFA_F_MANAGETEMPADDR) {
+		ifa_flags &= ~IFA_F_MANAGETEMPADDR;
+		fprintf(fp, "mngtmpaddr ");
+	}
 	if (!(ifa_flags & IFA_F_PERMANENT)) {
 		fprintf(fp, "dynamic ");
 	} else
@@ -1345,6 +1349,8 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
 			ifa_flags |= IFA_F_HOMEADDRESS;
 		} else if (strcmp(*argv, "nodad") == 0) {
 			ifa_flags |= IFA_F_NODAD;
+		} else if (strcmp(*argv, "mngtmpaddr") == 0) {
+			ifa_flags |= IFA_F_MANAGETEMPADDR;
 		} else {
 			if (strcmp(*argv, "local") == 0) {
 				NEXT_ARG();
Signature · 1 line
1.8.3.1
author
#6 lore raw

RFC PATCH v2 2/2 ipv6 addrconf: introduce IFA_F_MANAGETEMPADDR to tell kernel to manage temporary addresses

In reply to Jiri Pirko

Creating an address with this flag set will result in kernel taking care of temporary addresses in the same way as if the address was created by kernel itself (after RA receive). This allows userspace applications implementing the autoconfiguration (NetworkManager for example) to implement ipv6 addresses privacy.

---
v1->v2:
- Added possibility to change IFA_F_MANAGETEMPADDR flag as suggested by Thomas Haller

 include/uapi/linux/if_addr.h |   1 +
 net/ipv6/addrconf.c          | 167 ++++++++++++++++++++++++-------------------
 2 files changed, 96 insertions(+), 72 deletions(-)
include/uapi/linux/if_addr.h +1 -0
index 8ab0c2c..cfed10b 100644
@@ -48,6 +48,7 @@ enum {
 #define IFA_F_DEPRECATED	0x20
 #define IFA_F_TENTATIVE		0x40
 #define IFA_F_PERMANENT		0x80
+#define IFA_F_MANAGETEMPADDR	0x100
 
 struct ifa_cacheinfo {
 	__u32	ifa_prefered;
net/ipv6/addrconf.c +95 -72

252 lines not on this page · raw message

Signature · 1 line
1.8.3.1
Reviewed-by on v2 2/2
#7 lore raw

Re: [patch net-next RFC v2 2/2] ipv6 addrconf: introduce IFA_F_MANAGETEMPADDR to tell kernel to manage temporary addresses

Quoted 8 lines · Jiri Pirko

Creating an address with this flag set will result in kernel taking care of temporary addresses in the same way as if the address was created by kernel itself (after RA receive). This allows userspace applications implementing the autoconfiguration (NetworkManager for example) to implement ipv6 addresses privacy.

The patch looks good.

The _bh conversion seems not to be strictly necessary, no? ipv6_create_tempaddr is always called with bh disabled.

Thanks,

Hannes

author
#8 lore raw

Re: [patch net-next RFC v2 2/2] ipv6 addrconf: introduce IFA_F_MANAGETEMPADDR to tell kernel to manage temporary addresses

Quoted 10 lines · Wed, Nov 20, 2013 at 05:05:43PM CET, [email protected] wrote:
Quoted 8 lines · Jiri Pirko

Creating an address with this flag set will result in kernel taking care of temporary addresses in the same way as if the address was created by kernel itself (after RA receive). This allows userspace applications implementing the autoconfiguration (NetworkManager for example) to implement ipv6 addresses privacy.

Quoted 6 lines

The patch looks good.

The _bh conversion seems not to be strictly necessary, no? ipv6_create_tempaddr is always called with bh disabled.

It is needed. Found out using lock debug config option.

Quoted 5 lines

Thanks,

Hannes

#9 lore raw

Re: [patch net-next RFC v2 2/2] ipv6 addrconf: introduce IFA_F_MANAGETEMPADDR to tell kernel to manage temporary addresses

Quoted 11 lines · Jiri Pirko
Quoted 10 lines · Wed, Nov 20, 2013 at 05:05:43PM CET, [email protected] wrote:
Quoted 8 lines · Jiri Pirko

Creating an address with this flag set will result in kernel taking care of temporary addresses in the same way as if the address was created by kernel itself (after RA receive). This allows userspace applications implementing the autoconfiguration (NetworkManager for example) to implement ipv6 addresses privacy.

Quoted 8 lines
Quoted 6 lines

The patch looks good.

The _bh conversion seems not to be strictly necessary, no? ipv6_create_tempaddr is always called with bh disabled.

It is needed. Found out using lock debug config option.

Yes, I can see it now, too. ;)

#10 lore raw

Re: [patch net-next RFC v2 2/2] ipv6 addrconf: introduce IFA_F_MANAGETEMPADDR to tell kernel to manage temporary addresses

In reply to Jiri Pirko

Hi Jiri,

just two comments:

Quoted 11 lines
net/ipv6/addrconf.c +1 -0
 		addrconf_verify(0);
 		return 0;
@@ -3609,6 +3617,7 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, u32 ifa_flags,
 	u32 flags;
 	clock_t expires;
 	unsigned long timeout;
+	bool was_managetempaddr;
 
 	if (!valid_lft || (prefered_lft > valid_lft))
 		return -EINVAL;

net/ipv6/addrconf.c static int inet6_addr_modify(struct inet6_ifaddr *ifp, u32 ifa_flags, · line 3643

Quoted 3 lines
net/ipv6/addrconf.c +0 -0
@@ -3632,7 +3641,10 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, u32 ifa_flags,
 	}
 
 	spin_lock_bh(&ifp->lock);

We should make sure here, not to allow IFA_F_MANAGETEMPADDR, if ifp has prefixlen!=64 or is IFA_F_TEMPORARY itself. Note, that inet6_rtm_newaddr does check for ifm->ifa_prefixlen != 64, but when modifying an existing address, the ifm->ifa_prefixlen is not relevant.

Quoted 9 lines
net/ipv6/addrconf.c +4 -1
-	ifp->flags = (ifp->flags & ~(IFA_F_DEPRECATED | IFA_F_PERMANENT | IFA_F_NODAD | IFA_F_HOMEADDRESS)) | ifa_flags;
+	was_managetempaddr = ifp->flags & IFA_F_MANAGETEMPADDR;
+	ifp->flags &= ~(IFA_F_DEPRECATED | IFA_F_PERMANENT | IFA_F_NODAD |
+			IFA_F_HOMEADDRESS | IFA_F_MANAGETEMPADDR);
+	ifp->flags |= ifa_flags;
 	ifp->tstamp = jiffies;
 	ifp->valid_lft = valid_lft;
 	ifp->prefered_lft = prefered_lft;

net/ipv6/addrconf.c static int inet6_addr_modify(struct inet6_ifaddr *ifp, u32 ifa_flags, · line 3663

Quoted 9 lines
net/ipv6/addrconf.c +6 -0
@@ -3643,6 +3655,14 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, u32 ifa_flags,
 
 	addrconf_prefix_route(&ifp->addr, ifp->prefix_len, ifp->idev->dev,
 			      expires, flags);
+
+	if (was_managetempaddr || ifp->flags & IFA_F_MANAGETEMPADDR) {
+		if (was_managetempaddr && !(ifp->flags & IFA_F_MANAGETEMPADDR))
+			valid_lft = prefered_lft = 0;
+		manage_tempaddrs(ifp->idev, ifp, valid_lft, prefered_lft,
+				 false, jiffies);

I think, the parameter "create" of manage_tempaddrs should be set to "!was_managetempaddr", because we want to force creation of a new temporary address, if ifp just gets the flag IFA_F_MANAGETEMPADDR (without having it before).

Thomas