Skip to content

Commit e57a632

Browse files
q2venkuba-moo
authored andcommitted
net: Add net_passive_inc() and net_passive_dec().
net_drop_ns() is NULL when CONFIG_NET_NS is disabled. The next patch introduces a function that increments and decrements net->passive. As a prep, let's rename and export net_free() to net_passive_dec() and add net_passive_inc(). Suggested-by: Eric Dumazet <[email protected]> Link: https://lore.kernel.org/netdev/CANn89i+oUCt2VGvrbrweniTendZFEh+nwS=uonc004-aPkWy-Q@mail.gmail.com/ Signed-off-by: Kuniyuki Iwashima <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent f6093c5 commit e57a632

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

include/net/net_namespace.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ static inline int check_net(const struct net *net)
297297
}
298298

299299
void net_drop_ns(void *);
300+
void net_passive_dec(struct net *net);
300301

301302
#else
302303

@@ -326,8 +327,18 @@ static inline int check_net(const struct net *net)
326327
}
327328

328329
#define net_drop_ns NULL
330+
331+
static inline void net_passive_dec(struct net *net)
332+
{
333+
refcount_dec(&net->passive);
334+
}
329335
#endif
330336

337+
static inline void net_passive_inc(struct net *net)
338+
{
339+
refcount_inc(&net->passive);
340+
}
341+
331342
/* Returns true if the netns initialization is completed successfully */
332343
static inline bool net_initialized(const struct net *net)
333344
{

net/core/net_namespace.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ static void net_complete_free(void)
464464

465465
}
466466

467-
static void net_free(struct net *net)
467+
void net_passive_dec(struct net *net)
468468
{
469469
if (refcount_dec_and_test(&net->passive)) {
470470
kfree(rcu_access_pointer(net->gen));
@@ -482,7 +482,7 @@ void net_drop_ns(void *p)
482482
struct net *net = (struct net *)p;
483483

484484
if (net)
485-
net_free(net);
485+
net_passive_dec(net);
486486
}
487487

488488
struct net *copy_net_ns(unsigned long flags,
@@ -523,7 +523,7 @@ struct net *copy_net_ns(unsigned long flags,
523523
key_remove_domain(net->key_domain);
524524
#endif
525525
put_user_ns(user_ns);
526-
net_free(net);
526+
net_passive_dec(net);
527527
dec_ucounts:
528528
dec_net_namespaces(ucounts);
529529
return ERR_PTR(rv);
@@ -672,7 +672,7 @@ static void cleanup_net(struct work_struct *work)
672672
key_remove_domain(net->key_domain);
673673
#endif
674674
put_user_ns(net->user_ns);
675-
net_free(net);
675+
net_passive_dec(net);
676676
}
677677
cleanup_net_task = NULL;
678678
}

0 commit comments

Comments
 (0)