connector.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. #define CN_NETLINK_USERS 1
  27. /*
  28. * Maximum connector's message size.
  29. */
  30. #define CONNECTOR_MAX_MSG_SIZE 1024
  31. /*
  32. * idx and val are unique identifiers which
  33. * are used for message routing and
  34. * must be registered in connector.h for in-kernel usage.
  35. */
  36. struct cb_id {
  37. __u32 idx;
  38. __u32 val;
  39. };
  40. struct cn_msg {
  41. struct cb_id id;
  42. __u32 seq;
  43. __u32 ack;
  44. __u16 len; /* Length of the following data */
  45. __u16 flags;
  46. __u8 data[0];
  47. };
  48. /*
  49. * Notify structure - requests notification about
  50. * registering/unregistering idx/val in range [first, first+range].
  51. */
  52. struct cn_notify_req {
  53. __u32 first;
  54. __u32 range;
  55. };
  56. /*
  57. * Main notification control message
  58. * *_notify_num - number of appropriate cn_notify_req structures after
  59. * this struct.
  60. * group - notification receiver's idx.
  61. * len - total length of the attached data.
  62. */
  63. struct cn_ctl_msg {
  64. __u32 idx_notify_num;
  65. __u32 val_notify_num;
  66. __u32 group;
  67. __u32 len;
  68. __u8 data[0];
  69. };
  70. #ifdef __KERNEL__
  71. #include <asm/atomic.h>
  72. #include <linux/list.h>
  73. #include <linux/workqueue.h>
  74. #include <net/sock.h>
  75. #define CN_CBQ_NAMELEN 32
  76. struct cn_queue_dev {
  77. atomic_t refcnt;
  78. unsigned char name[CN_CBQ_NAMELEN];
  79. struct workqueue_struct *cn_queue;
  80. struct list_head queue_list;
  81. spinlock_t queue_lock;
  82. int netlink_groups;
  83. struct sock *nls;
  84. };
  85. struct cn_callback_id {
  86. unsigned char name[CN_CBQ_NAMELEN];
  87. struct cb_id id;
  88. };
  89. struct cn_callback_data {
  90. void (*destruct_data) (void *);
  91. void *ddata;
  92. void *callback_priv;
  93. void (*callback) (void *);
  94. void *free;
  95. };
  96. struct cn_callback_entry {
  97. struct list_head callback_entry;
  98. struct cn_callback *cb;
  99. struct work_struct work;
  100. struct cn_queue_dev *pdev;
  101. struct cn_callback_id id;
  102. struct cn_callback_data data;
  103. int seq, group;
  104. struct sock *nls;
  105. };
  106. struct cn_ctl_entry {
  107. struct list_head notify_entry;
  108. struct cn_ctl_msg *msg;
  109. };
  110. struct cn_dev {
  111. struct cb_id id;
  112. u32 seq, groups;
  113. struct sock *nls;
  114. void (*input) (struct sock * sk, int len);
  115. struct cn_queue_dev *cbdev;
  116. };
  117. int cn_add_callback(struct cb_id *, char *, void (*callback) (void *));
  118. void cn_del_callback(struct cb_id *);
  119. int cn_netlink_send(struct cn_msg *, u32, gfp_t);
  120. int cn_queue_add_callback(struct cn_queue_dev *dev, char *name, struct cb_id *id, void (*callback)(void *));
  121. void cn_queue_del_callback(struct cn_queue_dev *dev, struct cb_id *id);
  122. struct cn_queue_dev *cn_queue_alloc_dev(char *name, struct sock *);
  123. void cn_queue_free_dev(struct cn_queue_dev *dev);
  124. int cn_cb_equal(struct cb_id *, struct cb_id *);
  125. void cn_queue_wrapper(void *data);
  126. extern int cn_already_initialized;
  127. #endif /* __KERNEL__ */
  128. #endif /* __CONNECTOR_H */