Skip to content

Commit fc9e50f

Browse files
tomratbertdavem330
authored andcommitted
netlink: add a start callback for starting a netlink dump
The start callback allows the caller to set up a context for the dump callbacks. Presumably, the context can then be destroyed in the done callback. Signed-off-by: Tom Herbert <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3502cad commit fc9e50f

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

include/linux/netlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ netlink_skb_clone(struct sk_buff *skb, gfp_t gfp_mask)
131131
struct netlink_callback {
132132
struct sk_buff *skb;
133133
const struct nlmsghdr *nlh;
134+
int (*start)(struct netlink_callback *);
134135
int (*dump)(struct sk_buff * skb,
135136
struct netlink_callback *cb);
136137
int (*done)(struct netlink_callback *cb);
@@ -153,6 +154,7 @@ struct nlmsghdr *
153154
__nlmsg_put(struct sk_buff *skb, u32 portid, u32 seq, int type, int len, int flags);
154155

155156
struct netlink_dump_control {
157+
int (*start)(struct netlink_callback *);
156158
int (*dump)(struct sk_buff *skb, struct netlink_callback *);
157159
int (*done)(struct netlink_callback *);
158160
void *data;

include/net/genetlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ static inline void genl_info_net_set(struct genl_info *info, struct net *net)
114114
* @flags: flags
115115
* @policy: attribute validation policy
116116
* @doit: standard command callback
117+
* @start: start callback for dumps
117118
* @dumpit: callback for dumpers
118119
* @done: completion callback for dumps
119120
* @ops_list: operations list
@@ -122,6 +123,7 @@ struct genl_ops {
122123
const struct nla_policy *policy;
123124
int (*doit)(struct sk_buff *skb,
124125
struct genl_info *info);
126+
int (*start)(struct netlink_callback *cb);
125127
int (*dumpit)(struct sk_buff *skb,
126128
struct netlink_callback *cb);
127129
int (*done)(struct netlink_callback *cb);

net/netlink/af_netlink.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2915,6 +2915,7 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
29152915

29162916
cb = &nlk->cb;
29172917
memset(cb, 0, sizeof(*cb));
2918+
cb->start = control->start;
29182919
cb->dump = control->dump;
29192920
cb->done = control->done;
29202921
cb->nlh = nlh;
@@ -2927,6 +2928,9 @@ int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
29272928

29282929
mutex_unlock(nlk->cb_mutex);
29292930

2931+
if (cb->start)
2932+
cb->start(cb);
2933+
29302934
ret = netlink_dump(sk);
29312935
sock_put(sk);
29322936

net/netlink/genetlink.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,20 @@ void *genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq,
513513
}
514514
EXPORT_SYMBOL(genlmsg_put);
515515

516+
static int genl_lock_start(struct netlink_callback *cb)
517+
{
518+
/* our ops are always const - netlink API doesn't propagate that */
519+
const struct genl_ops *ops = cb->data;
520+
int rc = 0;
521+
522+
if (ops->start) {
523+
genl_lock();
524+
rc = ops->start(cb);
525+
genl_unlock();
526+
}
527+
return rc;
528+
}
529+
516530
static int genl_lock_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
517531
{
518532
/* our ops are always const - netlink API doesn't propagate that */
@@ -577,6 +591,7 @@ static int genl_family_rcv_msg(struct genl_family *family,
577591
.module = family->module,
578592
/* we have const, but the netlink API doesn't */
579593
.data = (void *)ops,
594+
.start = genl_lock_start,
580595
.dump = genl_lock_dumpit,
581596
.done = genl_lock_done,
582597
};
@@ -588,6 +603,7 @@ static int genl_family_rcv_msg(struct genl_family *family,
588603
} else {
589604
struct netlink_dump_control c = {
590605
.module = family->module,
606+
.start = ops->start,
591607
.dump = ops->dumpit,
592608
.done = ops->done,
593609
};

0 commit comments

Comments
 (0)