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/if_inet6.h | 2 +- include/uapi/linux/if_addr.h | 5 ++ net/ipv6/addrconf.c | 181 +++++++++++++++++++++++++------------------ 3 files changed, 110 insertions(+), 78 deletions(-)
Signature · 1 line
1.8.3.1
RFC 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/if_inet6.h | 2 +- include/uapi/linux/if_addr.h | 4 ++++ net/ipv6/addrconf.c | 22 +++++++++++++++------- 3 files changed, 20 insertions(+), 8 deletions(-)
include/net/if_inet6.h +1 -1
@@ -51,7 +51,7 @@ struct inet6_ifaddr {int state;__u8 dad_probes; -__u8 flags; +__u32 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 +15 -7
@@ -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;
@@ -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 ) {
@@ -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
RE: [patch net-next RFC 1/2] ipv6 addrconf: extend ifa_flags to u32
include/net/if_inet6.h struct inet6_ifaddr { · line 56
Quoted 10 lines
include/net/if_inet6.h +1
-1@@ -51,7 +51,7 @@ struct inet6_ifaddr {int state;__u8 dad_probes; -__u8 flags; +__u32 flags;__u16 scope;
That is adding a lot of padding.
David
Re: [patch net-next RFC 1/2] ipv6 addrconf: extend ifa_flags to u32
Quoted 5 lines · Mon, Nov 11, 2013 at 04:07:20PM CET, [email protected] wrote:
Quoted 5 lines
include/net/if_inet6.h +0
-0@@ -51,7 +51,7 @@ struct inet6_ifaddr {int state;
Quoted 7 lines
include/net/if_inet6.h struct inet6_ifaddr { · line 56
Quoted 5 lines
include/net/if_inet6.h +1
-1__u8 dad_probes; -__u8 flags; +__u32 flags;__u16 scope;That is adding a lot of padding.
Allright. Will reorder. Thanks
Quoted 5 lines
David
RFC 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
RFC 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
RFC 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 | 161 ++++++++++++++++++++++++------------------- 2 files changed, 91 insertions(+), 71 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 +90 -71
245 lines not on this page · raw message
Signature · 1 line
1.8.3.1
PATCH 1/1 fixup! ipv6 addrconf: introduce IFA_F_MANAGETEMPADDR to tell kernel to manage temporary addresses
Handle IFA_F_MANAGETEMPADDR flag when modifying existing addresses too.
---
Hi,
I'd like to suggest this change, I think it makes it easier for the user space application to set this flag of (potentially) existing addresses.
Note, that if the flag gets cleared if the ifa had it set before and the temporary addresses will exprire immediatly. This makes sense for me.
Or if we don't want this, then the command should fail (EEXIST?) when trying to set MANAGETEMPADDR for an existing address that doesn't have the flag already.
Thomas
net/ipv6/addrconf.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
net/ipv6/addrconf.c +17 -6
@@ -3613,20 +3613,21 @@ 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,u32 ifa_flags,u32 prefered_lft,u32 valid_lft) {u32 flags;clock_t expires;unsigned long timeout; +int mngtmp;if (!valid_lft || (prefered_lft > valid_lft))return -EINVAL ; timeout =addrconf_timeout_fixup (valid_lft,HZ );if (addrconf_finite_timeout (timeout)) { expires =jiffies_to_clock_t (timeout *HZ ); valid_lft = timeout; flags =RTF_EXPIRES ; }else {
@@ -3636,35 +3637,48 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, u32 ifa_flags, } timeout =addrconf_timeout_fixup (prefered_lft,HZ );if (addrconf_finite_timeout (timeout)) {if (timeout ==0 ) ifa_flags |=IFA_F_DEPRECATED ; prefered_lft = timeout; }spin_lock_bh (&ifp->lock); - ifp->flags = (ifp->flags & ~(IFA_F_DEPRECATED |IFA_F_PERMANENT |IFA_F_NODAD |IFA_F_HOMEADDRESS )) | ifa_flags; +if (ifa_flags &IFA_F_MANAGETEMPADDR && + (ifp->prefix_len !=64 || ifp->flags &IFA_F_TEMPORARY )) { +spin_unlock_bh (&ifp->lock); +return -EEXIST ; + } + mngtmp = ifp->flags &IFA_F_MANAGETEMPADDR ; + ifp->flags = (ifp->flags & ~(IFA_F_DEPRECATED |IFA_F_PERMANENT |IFA_F_NODAD |IFA_F_HOMEADDRESS | +IFA_F_MANAGETEMPADDR )) | ifa_flags; ifp->tstamp = jiffies; ifp->valid_lft = valid_lft; ifp->prefered_lft = prefered_lft;spin_unlock_bh (&ifp->lock);if (!(ifp->flags&IFA_F_TENTATIVE ))ipv6_ifa_notify (0 , ifp);addrconf_prefix_route (&ifp->addr, ifp->prefix_len, ifp->idev->dev, expires, flags); -if (ifp->flags &IFA_F_MANAGETEMPADDR ) -manage_tempaddrs (ifp->idev, ifp, valid_lft, prefered_lft, +if (mngtmp && !(ifa_flags &IFA_F_MANAGETEMPADDR )) { +/* expire the life time of the temporary addresses */ +manage_tempaddrs (ifp->idev, ifp,0 ,0 , false, jiffies); + }else if (ifa_flags &IFA_F_MANAGETEMPADDR ) { +/* if we did not yet mngtmp, create temporary addresses */ +manage_tempaddrs (ifp->idev, ifp, valid_lft, prefered_lft, + !mngtmp, jiffies); + }addrconf_verify (0 );return 0 ; }static int inet6_rtm_newaddr (struct sk_buff *skb,struct nlmsghdr *nlh) {struct net *net =sock_net (skb->sk);
@@ -3710,23 +3724,20 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh)if (ifa ==NULL ) {/* * It would be best to check for !NLM_F_CREATE here but * userspace alreay relies on not having to provide this. */ return inet6_addr_add (net, ifm->ifa_index, pfx, peer_pfx, ifm->ifa_prefixlen, ifa_flags, preferred_lft, valid_lft); } -/* We ignore IFA_F_MANAGETEMPADDR for modify. */ - ifa_flags &= ~IFA_F_MANAGETEMPADDR ; -if (nlh->nlmsg_flags &NLM_F_EXCL || !(nlh->nlmsg_flags &NLM_F_REPLACE )) err = -EEXIST ;else err =inet6_addr_modify (ifa, ifa_flags, preferred_lft, valid_lft);in6_ifa_put (ifa);return err; }
Signature · 1 line
1.8.4.1.559.gdb9bdfb
Re: [PATCH 1/1] fixup! ipv6 addrconf: introduce IFA_F_MANAGETEMPADDR to tell kernel to manage temporary addresses
Okay. I will try incorporate modify into my patch. Thanks.
Quoted 126 lines · Fri, Nov 15, 2013 at 06:48:46PM CET, [email protected] wrote:
Handle
IFA_F_MANAGETEMPADDRflag when modifying existing addresses too.Signed-off-by Thomas Haller <[email protected]>---
Hi,I'd like to suggest this change, I think it makes it easier for the user space application to set this flag of (potentially) existing addresses.
Note, that if the flag gets cleared if the ifa had it set before and the temporary addresses will exprire immediatly. This makes sense for me.
Or if we don't want this, then the command should fail (EEXIST?) when trying to set MANAGETEMPADDR for an existing address that doesn't have the flag already.
Thomas
net/ipv6/addrconf.c| 23 +++++++++++++++++------1 file changed, 17 insertions(+), 6 deletions(-)net/ipv6/addrconf.c +17
-3@@ -3613,20 +3613,21 @@ 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,u32 ifa_flags,u32 prefered_lft,u32 valid_lft) {u32 flags;clock_t expires;unsigned long timeout; +int mngtmp;if (!valid_lft || (prefered_lft > valid_lft))return -EINVAL ; timeout =addrconf_timeout_fixup (valid_lft,HZ );if (addrconf_finite_timeout (timeout)) { expires =jiffies_to_clock_t (timeout *HZ ); valid_lft = timeout; flags =RTF_EXPIRES ; }else {@@ -3636,35 +3637,48 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, u32 ifa_flags, } timeout =addrconf_timeout_fixup (prefered_lft,HZ );if (addrconf_finite_timeout (timeout)) {if (timeout ==0 ) ifa_flags |=IFA_F_DEPRECATED ; prefered_lft = timeout; }spin_lock_bh (&ifp->lock); - ifp->flags = (ifp->flags & ~(IFA_F_DEPRECATED |IFA_F_PERMANENT |IFA_F_NODAD |IFA_F_HOMEADDRESS )) | ifa_flags; +if (ifa_flags &IFA_F_MANAGETEMPADDR && + (ifp->prefix_len !=64 || ifp->flags &IFA_F_TEMPORARY )) { +spin_unlock_bh (&ifp->lock); +return -EEXIST ; + } + mngtmp = ifp->flags &IFA_F_MANAGETEMPADDR ; + ifp->flags = (ifp->flags & ~(IFA_F_DEPRECATED |IFA_F_PERMANENT |IFA_F_NODAD |IFA_F_HOMEADDRESS | +IFA_F_MANAGETEMPADDR )) | ifa_flags; ifp->tstamp = jiffies; ifp->valid_lft = valid_lft; ifp->prefered_lft = prefered_lft;spin_unlock_bh (&ifp->lock);if (!(ifp->flags&IFA_F_TENTATIVE ))ipv6_ifa_notify (0 , ifp);addrconf_prefix_route (&ifp->addr, ifp->prefix_len, ifp->idev->dev, expires, flags); -if (ifp->flags &IFA_F_MANAGETEMPADDR ) -manage_tempaddrs (ifp->idev, ifp, valid_lft, prefered_lft, +if (mngtmp && !(ifa_flags &IFA_F_MANAGETEMPADDR )) { +/* expire the life time of the temporary addresses */ +manage_tempaddrs (ifp->idev, ifp,0 ,0 , false, jiffies); + }else if (ifa_flags &IFA_F_MANAGETEMPADDR ) { +/* if we did not yet mngtmp, create temporary addresses */ +manage_tempaddrs (ifp->idev, ifp, valid_lft, prefered_lft, + !mngtmp, jiffies); + }addrconf_verify (0 );return 0 ; }static int
inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh){ struct net *net = sock_net(skb->sk);net/ipv6/addrconf.c +0
-3@@ -3710,23 +3724,20 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh)if (ifa ==NULL ) {/* * It would be best to check for !NLM_F_CREATE here but * userspace alreay relies on not having to provide this. */ return inet6_addr_add (net, ifm->ifa_index, pfx, peer_pfx, ifm->ifa_prefixlen, ifa_flags, preferred_lft, valid_lft); } -/* We ignore IFA_F_MANAGETEMPADDR for modify. */ - ifa_flags &= ~IFA_F_MANAGETEMPADDR ; -if (nlh->nlmsg_flags &NLM_F_EXCL || !(nlh->nlmsg_flags &NLM_F_REPLACE )) err = -EEXIST ;else err =inet6_addr_modify (ifa, ifa_flags, preferred_lft, valid_lft);in6_ifa_put (ifa);return err; }Signature · 1 line
1.8.4.1.559.gdb9bdfb
Re: [patch net-next RFC 2/2] ipv6 addrconf: introduce IFA_F_MANAGETEMPADDR to tell kernel to manage temporary addresses
In reply to Jiri PirkoQuoted 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.
Hi,
I think, addrconf_prefix_rcv should not do anything if user created ones already exist.
"Already exist" could mean, a user created address with:
- the same IP address and MANAGETEMPADDR flag
- the same IP address
- the same /64 prefix and MANAGETEMPADDR flag
- the same /64 prefix
(??)
Of course, the user should disable accept_ra, if he wants to manage the temporary addresses himself. But it would still be more correct to check that prefixes from RA do not interfere.
Thomas
David Miller
maintainerI'm not really going to read patches not properly at least CC:'d to netdev, sorry Jiri.
Quoted 3 lines · Mon, Nov 11, 2013 at 07:42:43PM CET, [email protected] wrote:
I'm not really going to read patches not properly at least CC:'d to netdev, sorry Jiri.
netdev is in "To:"
I marked the patches as "RFC" on patchwork. Maybe I should not do it next time, right?
Thanks
Jiri
David Miller
maintainerFrom: Jiri Pirko <[email protected]>
Date: Mon, 11 Nov 2013 20:49:01 +0100
Quoted 9 lines
Quoted 3 lines · Mon, Nov 11, 2013 at 07:42:43PM CET, [email protected] wrote:
I'm not really going to read patches not properly at least CC:'d to netdev, sorry Jiri.
netdev is in "To:"
I marked the patches as "RFC" on patchwork. Maybe I should not do it next time, right?
I think you sent this multiple times, once without netdev in the CC: and then again with it present.
In any event you did the right thing in the end, sorry about that :)
Quoted 10 lines · Mon, Nov 11, 2013 at 09:01:52PM CET, [email protected] wrote:
From: Jiri Pirko <[email protected]>
Date: Mon, 11 Nov 2013 20:49:01 +0100Quoted 7 lines
Quoted 3 lines · Mon, Nov 11, 2013 at 07:42:43PM CET, [email protected] wrote:
I'm not really going to read patches not properly at least CC:'d to netdev, sorry Jiri.
netdev is in "To:"
Quoted 7 lines
Quoted 2 lines
I marked the patches as "RFC" on patchwork. Maybe I should not do it next time, right?
I think you sent this multiple times, once without netdev in the CC: and then again with it present.
In any event you did the right thing in the end, sorry about that :)
Nope, I sent this only once.
Anyway, should I touch the state in netdev patchwork or should I always leave that to you?
I'm used to set "changes requested" before I send another patch version and "RFC" when I send RFC patch.
Thanks.
Jiri
David Miller
maintainerFrom: Jiri Pirko <[email protected]>
Date: Mon, 11 Nov 2013 22:04:04 +0100
Quoted 5 lines
Anyway, should I touch the state in netdev patchwork or should I always leave that to you?
I'm used to set "changes requested" before I send another patch version and "RFC" when I send RFC patch.
I'd rather others not touch the patchwork state.
You plan to send this again, so whether it's marked RFC or changes requested is not all that important :-)