ipv6: allow temporary address management for user-created addresses
Subsystems (3)
cover ipv6: allow temporary address management for user-created addresses
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 | 201 +++++++++++++++++++++++++------------------ 4 files changed, 126 insertions(+), 86 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 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.
--- 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
@@ -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
@@ -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
@@ -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
@@ -1407,7 +1407,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 ;
@@ -1424,7 +1424,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 ;
@@ -2178,7 +2178,7 @@ ok: }if (ifp) { -int flags; +u32 flags;unsigned long now;struct inet6_ifaddr *ift;u32 stored_lft;
@@ -2363,10 +2363,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;
@@ -3351,7 +3352,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,
@@ -3572,6 +3573,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
@@ -3595,7 +3597,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;
@@ -3650,7 +3652,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);
@@ -3677,8 +3679,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 ) {
@@ -3702,7 +3706,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;
@@ -3745,7 +3749,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,
@@ -3793,6 +3798,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
Re: [patch net-next 1/2] ipv6 addrconf: extend ifa_flags to u32
From: Jiri Pirko <[email protected]>
Date: Fri, 6 Dec 2013 09:45:21 +0100
Quoted 5 lines
There is no more space in u8
ifa_flags. So do what davem suffested and add another netlink attr calledIFA_FLAGSfor carry more flags.Signed-off-by Jiri Pirko <[email protected]>Signed-off-by Thomas Haller <[email protected]>
Applied, can you extend the handling of this attribute to the other protocols as I asked you to?
Re: [patch net-next 1/2] ipv6 addrconf: extend ifa_flags to u32
Quoted 11 lines · Fri, Dec 06, 2013 at 10:35:18PM CET, [email protected] wrote:
From: Jiri Pirko <[email protected]>
Date: Fri, 6 Dec 2013 09:45:21 +0100Quoted 5 lines
There is no more space in u8
ifa_flags. So do what davem suffested and add another netlink attr calledIFA_FLAGSfor carry more flags.Signed-off-by Jiri Pirko <[email protected]>Signed-off-by Thomas Haller <[email protected]>Applied, can you extend the handling of this attribute to the other protocols as I asked you to?
Will send follow-up. Thanks.
PATCH 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
@@ -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
PATCH 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
@@ -45,6 +45,7 @@ enum {#define IFA_F_DEPRECATED 0x20#define IFA_F_TENTATIVE 0x40#define IFA_F_PERMANENT 0x80 +#define IFA_F_MANAGETEMPADDR 0x0100struct ifa_cacheinfo {__u32 ifa_prefered;
ip/ipaddress.c +6 -0
@@ -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
Re: [patch iproute2 2/2] add support for IFA_F_MANAGETEMPADDR
Quoted 1 line · On Fri, 6 Dec 2013 09:46:27 +0100 Jiri Pirko <[email protected]> wrote:
Signed-off-by Jiri Pirko <[email protected]>
This is ok, but since patch depends on previous one can't apply. Please resubmit when first patch is fixed.
Re: [patch iproute2 1/2] add support for extended ifa_flags
In reply to Jiri PirkoWas about to apply this but found something while reviewing.
ip/ipaddress.c static int ipaddr_modify(int cmd, int flags, int argc, char **argv) · line 1366
Quoted 2 lines · On Fri, 6 Dec 2013 09:46:26 +0100 Jiri Pirko <[email protected]> wrote:
ip/ipaddress.c +2
-0+ req.ifa.ifa_flags = ifa_flags &0xff ; +addattr32 (&req.n,sizeof (req),IFA_FLAGS , ifa_flags);
I don't like the mystery mask (0xff) here. I think this was to mask off private flags. Perhaps a manifest constant should be added to if.h lie IFA_F_RDONLY_MASK??
Plus from an API point of view, hard coding a value (even in #define) seems like a problem when future values get added.
Re: [patch iproute2 1/2] add support for extended ifa_flags
Quoted 11 lines · Sat, Dec 28, 2013 at 08:21:47PM CET, [email protected] wrote:
Was about to apply this but found something while reviewing.
ip/ipaddress.c static int ipaddr_modify(int cmd, int flags, int argc, char **argv) · line 1366
Quoted 2 lines · On Fri, 6 Dec 2013 09:46:26 +0100 Jiri Pirko <[email protected]> wrote:
ip/ipaddress.c +2
-0+ req.ifa.ifa_flags = ifa_flags &0xff ; +addattr32 (&req.n,sizeof (req),IFA_FLAGS , ifa_flags);I don't like the mystery mask (
0xff) here. I think this was to mask off private flags. Perhaps a manifest constant should be added toif.hlieIFA_F_RDONLY_MASK??
Hmm.. I wanted to emhasize that only 1 byte of value is taken. But I think that simple "req.ifa.ifa_flags = ifa_flags" should be fine here.
I will change this and repost.
Thanks!
Quoted 4 lines
Plus from an API point of view, hard coding a value (even in #define) seems like a problem when future values get added.
PATCH 2/2 ipv6 addrconf: introduce IFA_F_MANAGETEMPADDR to tell kernel to manage temporary addresses
In reply to Jiri PirkoCreating 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.
--- include/uapi/linux/if_addr.h | 1 + net/ipv6/addrconf.c | 171 +++++++++++++++++++++++++------------------ 2 files changed, 100 insertions(+), 72 deletions(-)
include/uapi/linux/if_addr.h +1 -0
@@ -48,6 +48,7 @@ enum {#define IFA_F_DEPRECATED 0x20#define IFA_F_TENTATIVE 0x40#define IFA_F_PERMANENT 0x80 +#define IFA_F_MANAGETEMPADDR 0x100struct ifa_cacheinfo {__u32 ifa_prefered;
net/ipv6/addrconf.c +99 -72
265 lines not on this page · raw message
Signature · 1 line
1.8.3.1
Re: [patch net-next 2/2] ipv6 addrconf: introduce IFA_F_MANAGETEMPADDR to tell kernel to manage temporary addresses
From: Jiri Pirko <[email protected]>
Date: Fri, 6 Dec 2013 09:45:22 +0100
Quoted 8 lines
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.
Signed-off-by Jiri Pirko <[email protected]>Signed-off-by Thomas Haller <[email protected]>
Applied.
Re: [patch net-next 2/2] ipv6 addrconf: introduce IFA_F_MANAGETEMPADDR to tell kernel to manage temporary addresses
In reply to Jiri PirkoHi Jiri!
Quoted 5 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.
I think we should follow up on something François-Xavier Le Bail proposed here:
http://patchwork.ozlabs.org/patch/294029/
In general I like the idea, and I also agree with David, we should disable it by default. But this would be beneficial to NetworkManager to not need to set temp_addresses to 2 to have them used by default. I guess a netlink api and a per-interface flag would be the easiest thing for NM to handle?
Greetings,
Hannes