911-kobject_add_broadcast_uevent.patch 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  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 32 /* 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. @@ -241,4 +243,7 @@ int kobject_synth_uevent(struct kobject
  21. __printf(2, 3)
  22. int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...);
  23. +int broadcast_uevent(struct sk_buff *skb, __u32 pid, __u32 group,
  24. + gfp_t allocation);
  25. +
  26. #endif /* _KOBJECT_H_ */
  27. --- a/lib/kobject_uevent.c
  28. +++ b/lib/kobject_uevent.c
  29. @@ -603,6 +603,43 @@ int add_uevent_var(struct kobj_uevent_en
  30. EXPORT_SYMBOL_GPL(add_uevent_var);
  31. #if defined(CONFIG_NET)
  32. +int broadcast_uevent(struct sk_buff *skb, __u32 pid, __u32 group,
  33. + gfp_t allocation)
  34. +{
  35. + struct uevent_sock *ue_sk;
  36. + int err = 0;
  37. +
  38. + /* send netlink message */
  39. + mutex_lock(&uevent_sock_mutex);
  40. + list_for_each_entry(ue_sk, &uevent_sock_list, list) {
  41. + struct sock *uevent_sock = ue_sk->sk;
  42. + struct sk_buff *skb2;
  43. +
  44. + skb2 = skb_clone(skb, allocation);
  45. + if (!skb2)
  46. + break;
  47. +
  48. + err = netlink_broadcast(uevent_sock, skb2, pid, group,
  49. + allocation);
  50. + if (err)
  51. + break;
  52. + }
  53. + mutex_unlock(&uevent_sock_mutex);
  54. +
  55. + kfree_skb(skb);
  56. + return err;
  57. +}
  58. +#else
  59. +int broadcast_uevent(struct sk_buff *skb, __u32 pid, __u32 group,
  60. + gfp_t allocation)
  61. +{
  62. + kfree_skb(skb);
  63. + return 0;
  64. +}
  65. +#endif
  66. +EXPORT_SYMBOL_GPL(broadcast_uevent);
  67. +
  68. +#if defined(CONFIG_NET)
  69. static int uevent_net_init(struct net *net)
  70. {
  71. struct uevent_sock *ue_sk;