Skip to content

Commit acb54e3

Browse files
dsaherndavem330
authored andcommitted
net/ipv6: Add gfp_flags to route add functions
Most FIB entries can be added using memory allocated with GFP_KERNEL. Add gfp_flags to ip6_route_add and addrconf_dst_alloc. Code paths that can be reached from the packet path (e.g., ndisc and autoconfig) or atomic notifiers use GFP_ATOMIC; paths from user context (adding addresses and routes) use GFP_KERNEL. Signed-off-by: David Ahern <dsahern@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f8a1b43 commit acb54e3

File tree

4 files changed

+38
-27
lines changed

4 files changed

+38
-27
lines changed

include/net/ip6_route.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ void ip6_route_cleanup(void);
100100

101101
int ipv6_route_ioctl(struct net *net, unsigned int cmd, void __user *arg);
102102

103-
int ip6_route_add(struct fib6_config *cfg, struct netlink_ext_ack *extack);
103+
int ip6_route_add(struct fib6_config *cfg, gfp_t gfp_flags,
104+
struct netlink_ext_ack *extack);
104105
int ip6_ins_rt(struct net *net, struct rt6_info *rt);
105106
int ip6_del_rt(struct net *net, struct rt6_info *rt);
106107

@@ -138,7 +139,8 @@ struct dst_entry *icmp6_dst_alloc(struct net_device *dev, struct flowi6 *fl6);
138139
void fib6_force_start_gc(struct net *net);
139140

140141
struct rt6_info *addrconf_dst_alloc(struct net *net, struct inet6_dev *idev,
141-
const struct in6_addr *addr, bool anycast);
142+
const struct in6_addr *addr, bool anycast,
143+
gfp_t gfp_flags);
142144

143145
struct rt6_info *ip6_dst_alloc(struct net *net, struct net_device *dev,
144146
int flags);

net/ipv6/addrconf.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr,
10371037
goto out;
10381038
}
10391039

1040-
rt = addrconf_dst_alloc(net, idev, addr, false);
1040+
rt = addrconf_dst_alloc(net, idev, addr, false, gfp_flags);
10411041
if (IS_ERR(rt)) {
10421042
err = PTR_ERR(rt);
10431043
rt = NULL;
@@ -2320,7 +2320,7 @@ static void ipv6_try_regen_rndid(struct inet6_dev *idev, struct in6_addr *tmpad
23202320

23212321
static void
23222322
addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev,
2323-
unsigned long expires, u32 flags)
2323+
unsigned long expires, u32 flags, gfp_t gfp_flags)
23242324
{
23252325
struct fib6_config cfg = {
23262326
.fc_table = l3mdev_fib_table(dev) ? : RT6_TABLE_PREFIX,
@@ -2345,7 +2345,7 @@ addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev,
23452345
cfg.fc_flags |= RTF_NONEXTHOP;
23462346
#endif
23472347

2348-
ip6_route_add(&cfg, NULL);
2348+
ip6_route_add(&cfg, gfp_flags, NULL);
23492349
}
23502350

23512351

@@ -2401,7 +2401,7 @@ static void addrconf_add_mroute(struct net_device *dev)
24012401

24022402
ipv6_addr_set(&cfg.fc_dst, htonl(0xFF000000), 0, 0, 0);
24032403

2404-
ip6_route_add(&cfg, NULL);
2404+
ip6_route_add(&cfg, GFP_ATOMIC, NULL);
24052405
}
24062406

24072407
static struct inet6_dev *addrconf_add_dev(struct net_device *dev)
@@ -2685,7 +2685,7 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao)
26852685
expires = jiffies_to_clock_t(rt_expires);
26862686
}
26872687
addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len,
2688-
dev, expires, flags);
2688+
dev, expires, flags, GFP_ATOMIC);
26892689
}
26902690
ip6_rt_put(rt);
26912691
}
@@ -2900,7 +2900,7 @@ static int inet6_addr_add(struct net *net, int ifindex,
29002900
if (!IS_ERR(ifp)) {
29012901
if (!(ifa_flags & IFA_F_NOPREFIXROUTE)) {
29022902
addrconf_prefix_route(&ifp->addr, ifp->prefix_len, dev,
2903-
expires, flags);
2903+
expires, flags, GFP_KERNEL);
29042904
}
29052905

29062906
/* Send a netlink notification if DAD is enabled and
@@ -3053,7 +3053,8 @@ static void sit_add_v4_addrs(struct inet6_dev *idev)
30533053

30543054
if (addr.s6_addr32[3]) {
30553055
add_addr(idev, &addr, plen, scope);
3056-
addrconf_prefix_route(&addr, plen, idev->dev, 0, pflags);
3056+
addrconf_prefix_route(&addr, plen, idev->dev, 0, pflags,
3057+
GFP_ATOMIC);
30573058
return;
30583059
}
30593060

@@ -3078,7 +3079,7 @@ static void sit_add_v4_addrs(struct inet6_dev *idev)
30783079

30793080
add_addr(idev, &addr, plen, flag);
30803081
addrconf_prefix_route(&addr, plen, idev->dev, 0,
3081-
pflags);
3082+
pflags, GFP_ATOMIC);
30823083
}
30833084
}
30843085
}
@@ -3118,7 +3119,8 @@ void addrconf_add_linklocal(struct inet6_dev *idev,
31183119
ifp = ipv6_add_addr(idev, addr, NULL, 64, IFA_LINK, addr_flags,
31193120
INFINITY_LIFE_TIME, INFINITY_LIFE_TIME, true, NULL);
31203121
if (!IS_ERR(ifp)) {
3121-
addrconf_prefix_route(&ifp->addr, ifp->prefix_len, idev->dev, 0, 0);
3122+
addrconf_prefix_route(&ifp->addr, ifp->prefix_len, idev->dev,
3123+
0, 0, GFP_ATOMIC);
31223124
addrconf_dad_start(ifp);
31233125
in6_ifa_put(ifp);
31243126
}
@@ -3233,7 +3235,8 @@ static void addrconf_addr_gen(struct inet6_dev *idev, bool prefix_route)
32333235
addrconf_add_linklocal(idev, &addr,
32343236
IFA_F_STABLE_PRIVACY);
32353237
else if (prefix_route)
3236-
addrconf_prefix_route(&addr, 64, idev->dev, 0, 0);
3238+
addrconf_prefix_route(&addr, 64, idev->dev,
3239+
0, 0, GFP_KERNEL);
32373240
break;
32383241
case IN6_ADDR_GEN_MODE_EUI64:
32393242
/* addrconf_add_linklocal also adds a prefix_route and we
@@ -3243,7 +3246,8 @@ static void addrconf_addr_gen(struct inet6_dev *idev, bool prefix_route)
32433246
if (ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) == 0)
32443247
addrconf_add_linklocal(idev, &addr, 0);
32453248
else if (prefix_route)
3246-
addrconf_prefix_route(&addr, 64, idev->dev, 0, 0);
3249+
addrconf_prefix_route(&addr, 64, idev->dev,
3250+
0, 0, GFP_ATOMIC);
32473251
break;
32483252
case IN6_ADDR_GEN_MODE_NONE:
32493253
default:
@@ -3346,7 +3350,8 @@ static int fixup_permanent_addr(struct net *net,
33463350
if (!ifp->rt || !ifp->rt->rt6i_node) {
33473351
struct rt6_info *rt, *prev;
33483352

3349-
rt = addrconf_dst_alloc(net, idev, &ifp->addr, false);
3353+
rt = addrconf_dst_alloc(net, idev, &ifp->addr, false,
3354+
GFP_ATOMIC);
33503355
if (IS_ERR(rt))
33513356
return PTR_ERR(rt);
33523357

@@ -3361,7 +3366,7 @@ static int fixup_permanent_addr(struct net *net,
33613366

33623367
if (!(ifp->flags & IFA_F_NOPREFIXROUTE)) {
33633368
addrconf_prefix_route(&ifp->addr, ifp->prefix_len,
3364-
idev->dev, 0, 0);
3369+
idev->dev, 0, 0, GFP_ATOMIC);
33653370
}
33663371

33673372
if (ifp->state == INET6_IFADDR_STATE_PREDAD)
@@ -4572,8 +4577,9 @@ static int inet6_addr_modify(struct inet6_ifaddr *ifp, u32 ifa_flags,
45724577
ipv6_ifa_notify(0, ifp);
45734578

45744579
if (!(ifa_flags & IFA_F_NOPREFIXROUTE)) {
4575-
addrconf_prefix_route(&ifp->addr, ifp->prefix_len, ifp->idev->dev,
4576-
expires, flags);
4580+
addrconf_prefix_route(&ifp->addr, ifp->prefix_len,
4581+
ifp->idev->dev, expires, flags,
4582+
GFP_KERNEL);
45774583
} else if (had_prefixroute) {
45784584
enum cleanup_prefix_rt_t action;
45794585
unsigned long rt_expires;
@@ -5614,7 +5620,8 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
56145620
addrconf_join_anycast(ifp);
56155621
if (!ipv6_addr_any(&ifp->peer_addr))
56165622
addrconf_prefix_route(&ifp->peer_addr, 128,
5617-
ifp->idev->dev, 0, 0);
5623+
ifp->idev->dev, 0, 0,
5624+
GFP_KERNEL);
56185625
break;
56195626
case RTM_DELADDR:
56205627
if (ifp->idev->cnf.forwarding)

net/ipv6/anycast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ int __ipv6_dev_ac_inc(struct inet6_dev *idev, const struct in6_addr *addr)
267267
}
268268

269269
net = dev_net(idev->dev);
270-
rt = addrconf_dst_alloc(net, idev, addr, true);
270+
rt = addrconf_dst_alloc(net, idev, addr, true, GFP_ATOMIC);
271271
if (IS_ERR(rt)) {
272272
err = PTR_ERR(rt);
273273
goto out;

net/ipv6/route.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,6 +2866,7 @@ static int ip6_validate_gw(struct net *net, struct fib6_config *cfg,
28662866
}
28672867

28682868
static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg,
2869+
gfp_t gfp_flags,
28692870
struct netlink_ext_ack *extack)
28702871
{
28712872
struct net *net = cfg->fc_nlinfo.nl_net;
@@ -3086,12 +3087,13 @@ static struct rt6_info *ip6_route_info_create(struct fib6_config *cfg,
30863087
return ERR_PTR(err);
30873088
}
30883089

3089-
int ip6_route_add(struct fib6_config *cfg, struct netlink_ext_ack *extack)
3090+
int ip6_route_add(struct fib6_config *cfg, gfp_t gfp_flags,
3091+
struct netlink_ext_ack *extack)
30903092
{
30913093
struct rt6_info *rt;
30923094
int err;
30933095

3094-
rt = ip6_route_info_create(cfg, extack);
3096+
rt = ip6_route_info_create(cfg, gfp_flags, extack);
30953097
if (IS_ERR(rt))
30963098
return PTR_ERR(rt);
30973099

@@ -3418,7 +3420,7 @@ static struct rt6_info *rt6_add_route_info(struct net *net,
34183420
if (!prefixlen)
34193421
cfg.fc_flags |= RTF_DEFAULT;
34203422

3421-
ip6_route_add(&cfg, NULL);
3423+
ip6_route_add(&cfg, GFP_ATOMIC, NULL);
34223424

34233425
return rt6_get_route_info(net, prefix, prefixlen, gwaddr, dev);
34243426
}
@@ -3469,7 +3471,7 @@ struct rt6_info *rt6_add_dflt_router(struct net *net,
34693471

34703472
cfg.fc_gateway = *gwaddr;
34713473

3472-
if (!ip6_route_add(&cfg, NULL)) {
3474+
if (!ip6_route_add(&cfg, GFP_ATOMIC, NULL)) {
34733475
struct fib6_table *table;
34743476

34753477
table = fib6_get_table(dev_net(dev), cfg.fc_table);
@@ -3567,7 +3569,7 @@ int ipv6_route_ioctl(struct net *net, unsigned int cmd, void __user *arg)
35673569
rtnl_lock();
35683570
switch (cmd) {
35693571
case SIOCADDRT:
3570-
err = ip6_route_add(&cfg, NULL);
3572+
err = ip6_route_add(&cfg, GFP_KERNEL, NULL);
35713573
break;
35723574
case SIOCDELRT:
35733575
err = ip6_route_del(&cfg, NULL);
@@ -3640,7 +3642,7 @@ static int ip6_pkt_prohibit_out(struct net *net, struct sock *sk, struct sk_buff
36403642
struct rt6_info *addrconf_dst_alloc(struct net *net,
36413643
struct inet6_dev *idev,
36423644
const struct in6_addr *addr,
3643-
bool anycast)
3645+
bool anycast, gfp_t gfp_flags)
36443646
{
36453647
u32 tb_id;
36463648
struct net_device *dev = idev->dev;
@@ -4293,7 +4295,7 @@ static int ip6_route_multipath_add(struct fib6_config *cfg,
42934295
}
42944296

42954297
r_cfg.fc_flags |= (rtnh->rtnh_flags & RTNH_F_ONLINK);
4296-
rt = ip6_route_info_create(&r_cfg, extack);
4298+
rt = ip6_route_info_create(&r_cfg, GFP_KERNEL, extack);
42974299
if (IS_ERR(rt)) {
42984300
err = PTR_ERR(rt);
42994301
rt = NULL;
@@ -4446,7 +4448,7 @@ static int inet6_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh,
44464448
if (cfg.fc_mp)
44474449
return ip6_route_multipath_add(&cfg, extack);
44484450
else
4449-
return ip6_route_add(&cfg, extack);
4451+
return ip6_route_add(&cfg, GFP_KERNEL, extack);
44504452
}
44514453

44524454
static size_t rt6_nlmsg_size(struct rt6_info *rt)

0 commit comments

Comments
 (0)