55ce1715675a39059b5fdd0e943c968a27ee218c
[openwrt/openwrt.git] / target / linux / generic / hack-4.9 / 911-kobject_add_broadcast_uevent.patch
1 From 0d37e6edc09c99e683dd91ca0e83bbc0df8477b3 Mon Sep 17 00:00:00 2001
2 From: Felix Fietkau <nbd@nbd.name>
3 Date: Sun, 16 Jul 2017 16:56:10 +0200
4 Subject: lib: add uevent_next_seqnum()
5
6 Signed-off-by: Felix Fietkau <nbd@nbd.name>
7 ---
8 include/linux/kobject.h | 5 +++++
9 lib/kobject_uevent.c | 37 +++++++++++++++++++++++++++++++++++++
10 2 files changed, 42 insertions(+)
11
12 --- a/include/linux/kobject.h
13 +++ b/include/linux/kobject.h
14 @@ -32,6 +32,8 @@
15 #define UEVENT_NUM_ENVP 32 /* number of env pointers */
16 #define UEVENT_BUFFER_SIZE 2048 /* buffer for the variables */
17
18 +struct sk_buff;
19 +
20 #ifdef CONFIG_UEVENT_HELPER
21 /* path to the userspace helper executed on an event */
22 extern char uevent_helper[];
23 @@ -222,4 +224,7 @@ int add_uevent_var(struct kobj_uevent_en
24 int kobject_action_type(const char *buf, size_t count,
25 enum kobject_action *type);
26
27 +int broadcast_uevent(struct sk_buff *skb, __u32 pid, __u32 group,
28 + gfp_t allocation);
29 +
30 #endif /* _KOBJECT_H_ */
31 --- a/lib/kobject_uevent.c
32 +++ b/lib/kobject_uevent.c
33 @@ -423,6 +423,43 @@ int add_uevent_var(struct kobj_uevent_en
34 EXPORT_SYMBOL_GPL(add_uevent_var);
35
36 #if defined(CONFIG_NET)
37 +int broadcast_uevent(struct sk_buff *skb, __u32 pid, __u32 group,
38 + gfp_t allocation)
39 +{
40 + struct uevent_sock *ue_sk;
41 + int err = 0;
42 +
43 + /* send netlink message */
44 + mutex_lock(&uevent_sock_mutex);
45 + list_for_each_entry(ue_sk, &uevent_sock_list, list) {
46 + struct sock *uevent_sock = ue_sk->sk;
47 + struct sk_buff *skb2;
48 +
49 + skb2 = skb_clone(skb, allocation);
50 + if (!skb2)
51 + break;
52 +
53 + err = netlink_broadcast(uevent_sock, skb2, pid, group,
54 + allocation);
55 + if (err)
56 + break;
57 + }
58 + mutex_unlock(&uevent_sock_mutex);
59 +
60 + kfree_skb(skb);
61 + return err;
62 +}
63 +#else
64 +int broadcast_uevent(struct sk_buff *skb, __u32 pid, __u32 group,
65 + gfp_t allocation)
66 +{
67 + kfree_skb(skb);
68 + return 0;
69 +}
70 +#endif
71 +EXPORT_SYMBOL_GPL(broadcast_uevent);
72 +
73 +#if defined(CONFIG_NET)
74 static int uevent_net_init(struct net *net)
75 {
76 struct uevent_sock *ue_sk;