Commit e6464b8c authored by David Ahern's avatar David Ahern Committed by David S. Miller

net/ipv6: Convert ipv6_add_addr to struct ifa6_config

Move config parameters for adding an ipv6 address to a struct. struct
names stem from inet6_rtm_newaddr which is the modern handler for
adding an address.

Start the conversion to ifa6_config with ipv6_add_addr. This is an argument
move only; no functional change intended. Mapping of variable changes:

    addr      -->  cfg->pfx
    peer_addr -->  cfg->peer_pfx
    pfxlen    -->  cfg->plen
    flags     -->  cfg->ifa_flags

scope, valid_lft, prefered_lft have the same names within cfg
(with corrected spelling).
Signed-off-by: default avatarDavid Ahern <dsahern@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 49fb6fe3
...@@ -59,6 +59,18 @@ struct in6_validator_info { ...@@ -59,6 +59,18 @@ struct in6_validator_info {
struct netlink_ext_ack *extack; struct netlink_ext_ack *extack;
}; };
struct ifa6_config {
const struct in6_addr *pfx;
unsigned int plen;
const struct in6_addr *peer_pfx;
u32 ifa_flags;
u32 preferred_lft;
u32 valid_lft;
u16 scope;
};
int addrconf_init(void); int addrconf_init(void);
void addrconf_cleanup(void); void addrconf_cleanup(void);
......
...@@ -986,17 +986,15 @@ static int ipv6_add_addr_hash(struct net_device *dev, struct inet6_ifaddr *ifa) ...@@ -986,17 +986,15 @@ static int ipv6_add_addr_hash(struct net_device *dev, struct inet6_ifaddr *ifa)
/* On success it returns ifp with increased reference count */ /* On success it returns ifp with increased reference count */
static struct inet6_ifaddr * static struct inet6_ifaddr *
ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, ipv6_add_addr(struct inet6_dev *idev, struct ifa6_config *cfg,
const struct in6_addr *peer_addr, int pfxlen,
int scope, u32 flags, u32 valid_lft, u32 prefered_lft,
bool can_block, struct netlink_ext_ack *extack) bool can_block, struct netlink_ext_ack *extack)
{ {
gfp_t gfp_flags = can_block ? GFP_KERNEL : GFP_ATOMIC; gfp_t gfp_flags = can_block ? GFP_KERNEL : GFP_ATOMIC;
int addr_type = ipv6_addr_type(cfg->pfx);
struct net *net = dev_net(idev->dev); struct net *net = dev_net(idev->dev);
struct inet6_ifaddr *ifa = NULL; struct inet6_ifaddr *ifa = NULL;
struct fib6_info *f6i = NULL; struct fib6_info *f6i = NULL;
int err = 0; int err = 0;
int addr_type = ipv6_addr_type(addr);
if (addr_type == IPV6_ADDR_ANY || if (addr_type == IPV6_ADDR_ANY ||
addr_type & IPV6_ADDR_MULTICAST || addr_type & IPV6_ADDR_MULTICAST ||
...@@ -1019,7 +1017,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, ...@@ -1019,7 +1017,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr,
*/ */
if (can_block) { if (can_block) {
struct in6_validator_info i6vi = { struct in6_validator_info i6vi = {
.i6vi_addr = *addr, .i6vi_addr = *cfg->pfx,
.i6vi_dev = idev, .i6vi_dev = idev,
.extack = extack, .extack = extack,
}; };
...@@ -1036,7 +1034,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, ...@@ -1036,7 +1034,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr,
goto out; goto out;
} }
f6i = addrconf_f6i_alloc(net, idev, addr, false, gfp_flags); f6i = addrconf_f6i_alloc(net, idev, cfg->pfx, false, gfp_flags);
if (IS_ERR(f6i)) { if (IS_ERR(f6i)) {
err = PTR_ERR(f6i); err = PTR_ERR(f6i);
f6i = NULL; f6i = NULL;
...@@ -1049,21 +1047,21 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, ...@@ -1049,21 +1047,21 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr,
neigh_parms_data_state_setall(idev->nd_parms); neigh_parms_data_state_setall(idev->nd_parms);
ifa->addr = *addr; ifa->addr = *cfg->pfx;
if (peer_addr) if (cfg->peer_pfx)
ifa->peer_addr = *peer_addr; ifa->peer_addr = *cfg->peer_pfx;
spin_lock_init(&ifa->lock); spin_lock_init(&ifa->lock);
INIT_DELAYED_WORK(&ifa->dad_work, addrconf_dad_work); INIT_DELAYED_WORK(&ifa->dad_work, addrconf_dad_work);
INIT_HLIST_NODE(&ifa->addr_lst); INIT_HLIST_NODE(&ifa->addr_lst);
ifa->scope = scope; ifa->scope = cfg->scope;
ifa->prefix_len = pfxlen; ifa->prefix_len = cfg->plen;
ifa->flags = flags; ifa->flags = cfg->ifa_flags;
/* No need to add the TENTATIVE flag for addresses with NODAD */ /* No need to add the TENTATIVE flag for addresses with NODAD */
if (!(flags & IFA_F_NODAD)) if (!(cfg->ifa_flags & IFA_F_NODAD))
ifa->flags |= IFA_F_TENTATIVE; ifa->flags |= IFA_F_TENTATIVE;
ifa->valid_lft = valid_lft; ifa->valid_lft = cfg->valid_lft;
ifa->prefered_lft = prefered_lft; ifa->prefered_lft = cfg->preferred_lft;
ifa->cstamp = ifa->tstamp = jiffies; ifa->cstamp = ifa->tstamp = jiffies;
ifa->tokenized = false; ifa->tokenized = false;
...@@ -1260,11 +1258,10 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, ...@@ -1260,11 +1258,10 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp,
{ {
struct inet6_dev *idev = ifp->idev; struct inet6_dev *idev = ifp->idev;
struct in6_addr addr, *tmpaddr; struct in6_addr addr, *tmpaddr;
unsigned long tmp_prefered_lft, tmp_valid_lft, tmp_tstamp, age; unsigned long tmp_tstamp, age;
unsigned long regen_advance; unsigned long regen_advance;
int tmp_plen; struct ifa6_config cfg;
int ret = 0; int ret = 0;
u32 addr_flags;
unsigned long now = jiffies; unsigned long now = jiffies;
long max_desync_factor; long max_desync_factor;
s32 cnf_temp_preferred_lft; s32 cnf_temp_preferred_lft;
...@@ -1326,13 +1323,12 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, ...@@ -1326,13 +1323,12 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp,
} }
} }
tmp_valid_lft = min_t(__u32, cfg.valid_lft = min_t(__u32, ifp->valid_lft,
ifp->valid_lft,
idev->cnf.temp_valid_lft + age); idev->cnf.temp_valid_lft + age);
tmp_prefered_lft = cnf_temp_preferred_lft + age - cfg.preferred_lft = cnf_temp_preferred_lft + age - idev->desync_factor;
idev->desync_factor; cfg.preferred_lft = min_t(__u32, ifp->prefered_lft, cfg.preferred_lft);
tmp_prefered_lft = min_t(__u32, ifp->prefered_lft, tmp_prefered_lft);
tmp_plen = ifp->prefix_len; cfg.plen = ifp->prefix_len;
tmp_tstamp = ifp->tstamp; tmp_tstamp = ifp->tstamp;
spin_unlock_bh(&ifp->lock); spin_unlock_bh(&ifp->lock);
...@@ -1346,21 +1342,22 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, ...@@ -1346,21 +1342,22 @@ static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp,
* temporary addresses being generated. * temporary addresses being generated.
*/ */
age = (now - tmp_tstamp + ADDRCONF_TIMER_FUZZ_MINUS) / HZ; age = (now - tmp_tstamp + ADDRCONF_TIMER_FUZZ_MINUS) / HZ;
if (tmp_prefered_lft <= regen_advance + age) { if (cfg.preferred_lft <= regen_advance + age) {
in6_ifa_put(ifp); in6_ifa_put(ifp);
in6_dev_put(idev); in6_dev_put(idev);
ret = -1; ret = -1;
goto out; goto out;
} }
addr_flags = IFA_F_TEMPORARY; cfg.ifa_flags = IFA_F_TEMPORARY;
/* set in addrconf_prefix_rcv() */ /* set in addrconf_prefix_rcv() */
if (ifp->flags & IFA_F_OPTIMISTIC) if (ifp->flags & IFA_F_OPTIMISTIC)
addr_flags |= IFA_F_OPTIMISTIC; cfg.ifa_flags |= IFA_F_OPTIMISTIC;
cfg.pfx = &addr;
cfg.scope = ipv6_addr_scope(cfg.pfx);
ift = ipv6_add_addr(idev, &addr, NULL, tmp_plen, ift = ipv6_add_addr(idev, &cfg, block, NULL);
ipv6_addr_scope(&addr), addr_flags,
tmp_valid_lft, tmp_prefered_lft, block, NULL);
if (IS_ERR(ift)) { if (IS_ERR(ift)) {
in6_ifa_put(ifp); in6_ifa_put(ifp);
in6_dev_put(idev); in6_dev_put(idev);
...@@ -2031,13 +2028,17 @@ void addrconf_dad_failure(struct sk_buff *skb, struct inet6_ifaddr *ifp) ...@@ -2031,13 +2028,17 @@ void addrconf_dad_failure(struct sk_buff *skb, struct inet6_ifaddr *ifp)
spin_lock_bh(&ifp->lock); spin_lock_bh(&ifp->lock);
if (ifp->flags & IFA_F_STABLE_PRIVACY) { if (ifp->flags & IFA_F_STABLE_PRIVACY) {
int scope = ifp->scope;
u32 flags = ifp->flags;
struct in6_addr new_addr; struct in6_addr new_addr;
struct inet6_ifaddr *ifp2; struct inet6_ifaddr *ifp2;
u32 valid_lft, preferred_lft;
int pfxlen = ifp->prefix_len;
int retries = ifp->stable_privacy_retry + 1; int retries = ifp->stable_privacy_retry + 1;
struct ifa6_config cfg = {
.pfx = &new_addr,
.plen = ifp->prefix_len,
.ifa_flags = ifp->flags,
.valid_lft = ifp->valid_lft,
.preferred_lft = ifp->prefered_lft,
.scope = ifp->scope,
};
if (retries > net->ipv6.sysctl.idgen_retries) { if (retries > net->ipv6.sysctl.idgen_retries) {
net_info_ratelimited("%s: privacy stable address generation failed because of DAD conflicts!\n", net_info_ratelimited("%s: privacy stable address generation failed because of DAD conflicts!\n",
...@@ -2050,9 +2051,6 @@ void addrconf_dad_failure(struct sk_buff *skb, struct inet6_ifaddr *ifp) ...@@ -2050,9 +2051,6 @@ void addrconf_dad_failure(struct sk_buff *skb, struct inet6_ifaddr *ifp)
idev)) idev))
goto errdad; goto errdad;
valid_lft = ifp->valid_lft;
preferred_lft = ifp->prefered_lft;
spin_unlock_bh(&ifp->lock); spin_unlock_bh(&ifp->lock);
if (idev->cnf.max_addresses && if (idev->cnf.max_addresses &&
...@@ -2063,9 +2061,7 @@ void addrconf_dad_failure(struct sk_buff *skb, struct inet6_ifaddr *ifp) ...@@ -2063,9 +2061,7 @@ void addrconf_dad_failure(struct sk_buff *skb, struct inet6_ifaddr *ifp)
net_info_ratelimited("%s: generating new stable privacy address because of DAD conflict\n", net_info_ratelimited("%s: generating new stable privacy address because of DAD conflict\n",
ifp->idev->dev->name); ifp->idev->dev->name);
ifp2 = ipv6_add_addr(idev, &new_addr, NULL, pfxlen, ifp2 = ipv6_add_addr(idev, &cfg, false, NULL);
scope, flags, valid_lft,
preferred_lft, false, NULL);
if (IS_ERR(ifp2)) if (IS_ERR(ifp2))
goto lock_errdad; goto lock_errdad;
...@@ -2507,12 +2503,20 @@ int addrconf_prefix_rcv_add_addr(struct net *net, struct net_device *dev, ...@@ -2507,12 +2503,20 @@ int addrconf_prefix_rcv_add_addr(struct net *net, struct net_device *dev,
if (!ifp && valid_lft) { if (!ifp && valid_lft) {
int max_addresses = in6_dev->cnf.max_addresses; int max_addresses = in6_dev->cnf.max_addresses;
struct ifa6_config cfg = {
.pfx = addr,
.plen = pinfo->prefix_len,
.ifa_flags = addr_flags,
.valid_lft = valid_lft,
.preferred_lft = prefered_lft,
.scope = addr_type & IPV6_ADDR_SCOPE_MASK,
};
#ifdef CONFIG_IPV6_OPTIMISTIC_DAD #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
if ((net->ipv6.devconf_all->optimistic_dad || if ((net->ipv6.devconf_all->optimistic_dad ||
in6_dev->cnf.optimistic_dad) && in6_dev->cnf.optimistic_dad) &&
!net->ipv6.devconf_all->forwarding && sllao) !net->ipv6.devconf_all->forwarding && sllao)
addr_flags |= IFA_F_OPTIMISTIC; cfg.ifa_flags |= IFA_F_OPTIMISTIC;
#endif #endif
/* Do not allow to create too much of autoconfigured /* Do not allow to create too much of autoconfigured
...@@ -2520,11 +2524,7 @@ int addrconf_prefix_rcv_add_addr(struct net *net, struct net_device *dev, ...@@ -2520,11 +2524,7 @@ int addrconf_prefix_rcv_add_addr(struct net *net, struct net_device *dev,
*/ */
if (!max_addresses || if (!max_addresses ||
ipv6_count_addresses(in6_dev) < max_addresses) ipv6_count_addresses(in6_dev) < max_addresses)
ifp = ipv6_add_addr(in6_dev, addr, NULL, ifp = ipv6_add_addr(in6_dev, &cfg, false, NULL);
pinfo->prefix_len,
addr_type&IPV6_ADDR_SCOPE_MASK,
addr_flags, valid_lft,
prefered_lft, false, NULL);
if (IS_ERR_OR_NULL(ifp)) if (IS_ERR_OR_NULL(ifp))
return -1; return -1;
...@@ -2836,12 +2836,19 @@ static int inet6_addr_add(struct net *net, int ifindex, ...@@ -2836,12 +2836,19 @@ static int inet6_addr_add(struct net *net, int ifindex,
__u32 prefered_lft, __u32 valid_lft, __u32 prefered_lft, __u32 valid_lft,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct ifa6_config cfg = {
.pfx = pfx,
.plen = plen,
.peer_pfx = peer_pfx,
.ifa_flags = ifa_flags,
.preferred_lft = prefered_lft,
.valid_lft = valid_lft,
};
struct inet6_ifaddr *ifp; struct inet6_ifaddr *ifp;
struct inet6_dev *idev; struct inet6_dev *idev;
struct net_device *dev; struct net_device *dev;
unsigned long timeout; unsigned long timeout;
clock_t expires; clock_t expires;
int scope;
u32 flags; u32 flags;
ASSERT_RTNL(); ASSERT_RTNL();
...@@ -2872,7 +2879,7 @@ static int inet6_addr_add(struct net *net, int ifindex, ...@@ -2872,7 +2879,7 @@ static int inet6_addr_add(struct net *net, int ifindex,
return ret; return ret;
} }
scope = ipv6_addr_scope(pfx); cfg.scope = ipv6_addr_scope(pfx);
timeout = addrconf_timeout_fixup(valid_lft, HZ); timeout = addrconf_timeout_fixup(valid_lft, HZ);
if (addrconf_finite_timeout(timeout)) { if (addrconf_finite_timeout(timeout)) {
...@@ -2892,9 +2899,7 @@ static int inet6_addr_add(struct net *net, int ifindex, ...@@ -2892,9 +2899,7 @@ static int inet6_addr_add(struct net *net, int ifindex,
prefered_lft = timeout; prefered_lft = timeout;
} }
ifp = ipv6_add_addr(idev, pfx, peer_pfx, plen, scope, ifa_flags, ifp = ipv6_add_addr(idev, &cfg, true, extack);
valid_lft, prefered_lft, true, extack);
if (!IS_ERR(ifp)) { if (!IS_ERR(ifp)) {
if (!(ifa_flags & IFA_F_NOPREFIXROUTE)) { if (!(ifa_flags & IFA_F_NOPREFIXROUTE)) {
addrconf_prefix_route(&ifp->addr, ifp->prefix_len, dev, addrconf_prefix_route(&ifp->addr, ifp->prefix_len, dev,
...@@ -3010,11 +3015,16 @@ static void add_addr(struct inet6_dev *idev, const struct in6_addr *addr, ...@@ -3010,11 +3015,16 @@ static void add_addr(struct inet6_dev *idev, const struct in6_addr *addr,
int plen, int scope) int plen, int scope)
{ {
struct inet6_ifaddr *ifp; struct inet6_ifaddr *ifp;
struct ifa6_config cfg = {
.pfx = addr,
.plen = plen,
.ifa_flags = IFA_F_PERMANENT,
.valid_lft = INFINITY_LIFE_TIME,
.preferred_lft = INFINITY_LIFE_TIME,
.scope = scope
};
ifp = ipv6_add_addr(idev, addr, NULL, plen, ifp = ipv6_add_addr(idev, &cfg, true, NULL);
scope, IFA_F_PERMANENT,
INFINITY_LIFE_TIME, INFINITY_LIFE_TIME,
true, NULL);
if (!IS_ERR(ifp)) { if (!IS_ERR(ifp)) {
spin_lock_bh(&ifp->lock); spin_lock_bh(&ifp->lock);
ifp->flags &= ~IFA_F_TENTATIVE; ifp->flags &= ~IFA_F_TENTATIVE;
...@@ -3104,18 +3114,24 @@ static void init_loopback(struct net_device *dev) ...@@ -3104,18 +3114,24 @@ static void init_loopback(struct net_device *dev)
void addrconf_add_linklocal(struct inet6_dev *idev, void addrconf_add_linklocal(struct inet6_dev *idev,
const struct in6_addr *addr, u32 flags) const struct in6_addr *addr, u32 flags)
{ {
struct ifa6_config cfg = {
.pfx = addr,
.plen = 64,
.ifa_flags = flags | IFA_F_PERMANENT,
.valid_lft = INFINITY_LIFE_TIME,
.preferred_lft = INFINITY_LIFE_TIME,
.scope = IFA_LINK
};
struct inet6_ifaddr *ifp; struct inet6_ifaddr *ifp;
u32 addr_flags = flags | IFA_F_PERMANENT;
#ifdef CONFIG_IPV6_OPTIMISTIC_DAD #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
if ((dev_net(idev->dev)->ipv6.devconf_all->optimistic_dad || if ((dev_net(idev->dev)->ipv6.devconf_all->optimistic_dad ||
idev->cnf.optimistic_dad) && idev->cnf.optimistic_dad) &&
!dev_net(idev->dev)->ipv6.devconf_all->forwarding) !dev_net(idev->dev)->ipv6.devconf_all->forwarding)
addr_flags |= IFA_F_OPTIMISTIC; cfg.ifa_flags |= IFA_F_OPTIMISTIC;
#endif #endif
ifp = ipv6_add_addr(idev, addr, NULL, 64, IFA_LINK, addr_flags, ifp = ipv6_add_addr(idev, &cfg, true, NULL);
INFINITY_LIFE_TIME, INFINITY_LIFE_TIME, true, NULL);
if (!IS_ERR(ifp)) { if (!IS_ERR(ifp)) {
addrconf_prefix_route(&ifp->addr, ifp->prefix_len, idev->dev, addrconf_prefix_route(&ifp->addr, ifp->prefix_len, idev->dev,
0, 0, GFP_ATOMIC); 0, 0, GFP_ATOMIC);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment