Skip to content

Commit 386520e

Browse files
edumazetdavem330
authored andcommitted
rtnetlink: add RTNL_FLAG_DUMP_UNLOCKED flag
Similarly to RTNL_FLAG_DOIT_UNLOCKED, this new flag allows dump operations registered via rtnl_register() or rtnl_register_module() to opt-out from RTNL protection. Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Donald Hunter <donald.hunter@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e39951d commit 386520e

4 files changed

Lines changed: 8 additions & 0 deletions

File tree

include/linux/netlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ struct netlink_callback {
291291
u16 answer_flags;
292292
u32 min_dump_alloc;
293293
unsigned int prev_seq, seq;
294+
int flags;
294295
bool strict_check;
295296
union {
296297
u8 ctx[48];
@@ -323,6 +324,7 @@ struct netlink_dump_control {
323324
void *data;
324325
struct module *module;
325326
u32 min_dump_alloc;
327+
int flags;
326328
};
327329

328330
int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb,

include/net/rtnetlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ typedef int (*rtnl_dumpit_func)(struct sk_buff *, struct netlink_callback *);
1212
enum rtnl_link_flags {
1313
RTNL_FLAG_DOIT_UNLOCKED = BIT(0),
1414
RTNL_FLAG_BULK_DEL_SUPPORTED = BIT(1),
15+
RTNL_FLAG_DUMP_UNLOCKED = BIT(2),
1516
};
1617

1718
enum rtnl_kinds {

net/core/rtnetlink.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6532,6 +6532,7 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
65326532
}
65336533
owner = link->owner;
65346534
dumpit = link->dumpit;
6535+
flags = link->flags;
65356536

65366537
if (type == RTM_GETLINK - RTM_BASE)
65376538
min_dump_alloc = rtnl_calcit(skb, nlh);
@@ -6549,6 +6550,7 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
65496550
.dump = dumpit,
65506551
.min_dump_alloc = min_dump_alloc,
65516552
.module = owner,
6553+
.flags = flags,
65526554
};
65536555
err = netlink_dump_start(rtnl, skb, nlh, &c);
65546556
/* netlink_dump_start() will keep a reference on

net/netlink/af_netlink.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,6 +2261,8 @@ static int netlink_dump(struct sock *sk, bool lock_taken)
22612261

22622262
cb->extack = &extack;
22632263

2264+
if (cb->flags & RTNL_FLAG_DUMP_UNLOCKED)
2265+
extra_mutex = NULL;
22642266
if (extra_mutex)
22652267
mutex_lock(extra_mutex);
22662268
nlk->dump_done_errno = cb->dump(skb, cb);
@@ -2355,6 +2357,7 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
23552357
cb->data = control->data;
23562358
cb->module = control->module;
23572359
cb->min_dump_alloc = control->min_dump_alloc;
2360+
cb->flags = control->flags;
23582361
cb->skb = skb;
23592362

23602363
cb->strict_check = nlk_test_bit(STRICT_CHK, NETLINK_CB(skb).sk);

0 commit comments

Comments
 (0)