llc.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. #ifndef LLC_H
  2. #define LLC_H
  3. /*
  4. * Copyright (c) 1997 by Procom Technology, Inc.
  5. * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  6. *
  7. * This program can be redistributed or modified under the terms of the
  8. * GNU General Public License as published by the Free Software Foundation.
  9. * This program is distributed without any warranty or implied warranty
  10. * of merchantability or fitness for a particular purpose.
  11. *
  12. * See the GNU General Public License for more details.
  13. */
  14. #include <linux/if.h>
  15. #include <linux/if_ether.h>
  16. #include <linux/list.h>
  17. #include <linux/spinlock.h>
  18. #include <linux/rculist_nulls.h>
  19. #include <linux/hash.h>
  20. #include <linux/jhash.h>
  21. #include <linux/atomic.h>
  22. struct net_device;
  23. struct packet_type;
  24. struct sk_buff;
  25. struct llc_addr {
  26. unsigned char lsap;
  27. unsigned char mac[IFHWADDRLEN];
  28. };
  29. #define LLC_SAP_STATE_INACTIVE 1
  30. #define LLC_SAP_STATE_ACTIVE 2
  31. #define LLC_SK_DEV_HASH_BITS 6
  32. #define LLC_SK_DEV_HASH_ENTRIES (1<<LLC_SK_DEV_HASH_BITS)
  33. #define LLC_SK_LADDR_HASH_BITS 6
  34. #define LLC_SK_LADDR_HASH_ENTRIES (1<<LLC_SK_LADDR_HASH_BITS)
  35. /**
  36. * struct llc_sap - Defines the SAP component
  37. *
  38. * @station - station this sap belongs to
  39. * @state - sap state
  40. * @p_bit - only lowest-order bit used
  41. * @f_bit - only lowest-order bit used
  42. * @laddr - SAP value in this 'lsap'
  43. * @node - entry in station sap_list
  44. * @sk_list - LLC sockets this one manages
  45. */
  46. struct llc_sap {
  47. unsigned char state;
  48. unsigned char p_bit;
  49. unsigned char f_bit;
  50. refcount_t refcnt;
  51. int (*rcv_func)(struct sk_buff *skb,
  52. struct net_device *dev,
  53. struct packet_type *pt,
  54. struct net_device *orig_dev);
  55. struct llc_addr laddr;
  56. struct list_head node;
  57. spinlock_t sk_lock;
  58. int sk_count;
  59. struct hlist_nulls_head sk_laddr_hash[LLC_SK_LADDR_HASH_ENTRIES];
  60. struct hlist_head sk_dev_hash[LLC_SK_DEV_HASH_ENTRIES];
  61. struct rcu_head rcu;
  62. };
  63. static inline
  64. struct hlist_head *llc_sk_dev_hash(struct llc_sap *sap, int ifindex)
  65. {
  66. return &sap->sk_dev_hash[ifindex % LLC_SK_DEV_HASH_ENTRIES];
  67. }
  68. static inline
  69. u32 llc_sk_laddr_hashfn(struct llc_sap *sap, const struct llc_addr *laddr)
  70. {
  71. return hash_32(jhash(laddr->mac, sizeof(laddr->mac), 0),
  72. LLC_SK_LADDR_HASH_BITS);
  73. }
  74. static inline
  75. struct hlist_nulls_head *llc_sk_laddr_hash(struct llc_sap *sap,
  76. const struct llc_addr *laddr)
  77. {
  78. return &sap->sk_laddr_hash[llc_sk_laddr_hashfn(sap, laddr)];
  79. }
  80. #define LLC_DEST_INVALID 0 /* Invalid LLC PDU type */
  81. #define LLC_DEST_SAP 1 /* Type 1 goes here */
  82. #define LLC_DEST_CONN 2 /* Type 2 goes here */
  83. extern struct list_head llc_sap_list;
  84. int llc_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt,
  85. struct net_device *orig_dev);
  86. int llc_mac_hdr_init(struct sk_buff *skb, const unsigned char *sa,
  87. const unsigned char *da);
  88. void llc_add_pack(int type,
  89. void (*handler)(struct llc_sap *sap, struct sk_buff *skb));
  90. void llc_remove_pack(int type);
  91. void llc_set_station_handler(void (*handler)(struct sk_buff *skb));
  92. struct llc_sap *llc_sap_open(unsigned char lsap,
  93. int (*rcv)(struct sk_buff *skb,
  94. struct net_device *dev,
  95. struct packet_type *pt,
  96. struct net_device *orig_dev));
  97. static inline void llc_sap_hold(struct llc_sap *sap)
  98. {
  99. refcount_inc(&sap->refcnt);
  100. }
  101. static inline bool llc_sap_hold_safe(struct llc_sap *sap)
  102. {
  103. return refcount_inc_not_zero(&sap->refcnt);
  104. }
  105. void llc_sap_close(struct llc_sap *sap);
  106. static inline void llc_sap_put(struct llc_sap *sap)
  107. {
  108. if (refcount_dec_and_test(&sap->refcnt))
  109. llc_sap_close(sap);
  110. }
  111. struct llc_sap *llc_sap_find(unsigned char sap_value);
  112. int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb,
  113. unsigned char *dmac, unsigned char dsap);
  114. void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb);
  115. void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb);
  116. void llc_station_init(void);
  117. void llc_station_exit(void);
  118. #ifdef CONFIG_PROC_FS
  119. int llc_proc_init(void);
  120. void llc_proc_exit(void);
  121. #else
  122. #define llc_proc_init() (0)
  123. #define llc_proc_exit() do { } while(0)
  124. #endif /* CONFIG_PROC_FS */
  125. #ifdef CONFIG_SYSCTL
  126. int llc_sysctl_init(void);
  127. void llc_sysctl_exit(void);
  128. extern int sysctl_llc2_ack_timeout;
  129. extern int sysctl_llc2_busy_timeout;
  130. extern int sysctl_llc2_p_timeout;
  131. extern int sysctl_llc2_rej_timeout;
  132. #else
  133. #define llc_sysctl_init() (0)
  134. #define llc_sysctl_exit() do { } while(0)
  135. #endif /* CONFIG_SYSCTL */
  136. #endif /* LLC_H */