connector.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * connector.h
  3. *
  4. * 2004-2005 Copyright (c) Evgeniy Polyakov <johnpol@2ka.mipt.ru>
  5. * All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #ifndef __CONNECTOR_H
  22. #define __CONNECTOR_H
  23. #include <asm/types.h>
  24. #define CN_IDX_CONNECTOR 0xffffffff
  25. #define CN_VAL_CONNECTOR 0xffffffff
  26. /*
  27. * Process Events connector unique ids -- used for message routing
  28. */
  29. #define CN_IDX_PROC 0x1
  30. #define CN_VAL_PROC 0x1
  31. #define CN_IDX_CIFS 0x2
  32. #define CN_VAL_CIFS 0x1
  33. #define CN_NETLINK_USERS 1
  34. /*
  35. * Maximum connector's message size.
  36. */
  37. #define CONNECTOR_MAX_MSG_SIZE 1024
  38. /*
  39. * idx and val are unique identifiers which
  40. * are used for message routing and
  41. * must be registered in connector.h for in-kernel usage.
  42. */
  43. struct cb_id {
  44. __u32 idx;
  45. __u32 val;
  46. };
  47. struct cn_msg {
  48. struct cb_id id;
  49. __u32 seq;
  50. __u32 ack;
  51. __u16 len; /* Length of the following data */
  52. __u16 flags;
  53. __u8 data[0];
  54. };
  55. /*
  56. * Notify structure - requests notification about
  57. * registering/unregistering idx/val in range [first, first+range].
  58. */
  59. struct cn_notify_req {
  60. __u32 first;
  61. __u32 range;
  62. };
  63. /*
  64. * Main notification control message
  65. * *_notify_num - number of appropriate cn_notify_req structures after
  66. * this struct.
  67. * group - notification receiver's idx.
  68. * len - total length of the attached data.
  69. */
  70. struct cn_ctl_msg {
  71. __u32 idx_notify_num;
  72. __u32 val_notify_num;
  73. __u32 group;
  74. __u32 len;
  75. __u8 data[0];
  76. };
  77. #ifdef __KERNEL__
  78. #include <asm/atomic.h>
  79. #include <linux/list.h>
  80. #include <linux/workqueue.h>
  81. #include <net/sock.h>
  82. #define CN_CBQ_NAMELEN 32
  83. struct cn_queue_dev {
  84. atomic_t refcnt;
  85. unsigned char name[CN_CBQ_NAMELEN];
  86. struct workqueue_struct *cn_queue;
  87. struct list_head queue_list;
  88. spinlock_t queue_lock;
  89. int netlink_groups;
  90. struct sock *nls;
  91. };
  92. struct cn_callback_id {
  93. unsigned char name[CN_CBQ_NAMELEN];
  94. struct cb_id id;
  95. };
  96. struct cn_callback_data {
  97. void (*destruct_data) (void *);
  98. void *ddata;
  99. void *callback_priv;
  100. void (*callback) (void *);
  101. void *free;
  102. };
  103. struct cn_callback_entry {
  104. struct list_head callback_entry;
  105. struct cn_callback *cb;
  106. struct work_struct work;
  107. struct cn_queue_dev *pdev;
  108. struct cn_callback_id id;
  109. struct cn_callback_data data;
  110. int seq, group;
  111. struct sock *nls;
  112. };
  113. struct cn_ctl_entry {
  114. struct list_head notify_entry;
  115. struct cn_ctl_msg *msg;
  116. };
  117. struct cn_dev {
  118. struct cb_id id;
  119. u32 seq, groups;
  120. struct sock *nls;
  121. void (*input) (struct sock * sk, int len);
  122. struct cn_queue_dev *cbdev;
  123. };
  124. int cn_add_callback(struct cb_id *, char *, void (*callback) (void *));
  125. void cn_del_callback(struct cb_id *);
  126. int cn_netlink_send(struct cn_msg *, u32, gfp_t);
  127. int cn_queue_add_callback(struct cn_queue_dev *dev, char *name, struct cb_id *id, void (*callback)(void *));
  128. void cn_queue_del_callback(struct cn_queue_dev *dev, struct cb_id *id);
  129. struct cn_queue_dev *cn_queue_alloc_dev(char *name, struct sock *);
  130. void cn_queue_free_dev(struct cn_queue_dev *dev);
  131. int cn_cb_equal(struct cb_id *, struct cb_id *);
  132. void cn_queue_wrapper(void *data);
  133. extern int cn_already_initialized;
  134. #endif /* __KERNEL__ */
  135. #endif /* __CONNECTOR_H */