911-kobject_add_broadcast_uevent.patch 2.0 KB

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