llc.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 <asm/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. atomic_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. };
  62. static inline
  63. struct hlist_head *llc_sk_dev_hash(struct llc_sap *sap, int ifindex)
  64. {
  65. return &sap->sk_dev_hash[ifindex % LLC_SK_DEV_HASH_ENTRIES];
  66. }
  67. static inline
  68. u32 llc_sk_laddr_hashfn(struct llc_sap *sap, const struct llc_addr *laddr)
  69. {
  70. return hash_32(jhash(laddr->mac, sizeof(laddr->mac), 0),
  71. LLC_SK_LADDR_HASH_BITS);
  72. }
  73. static inline
  74. struct hlist_nulls_head *llc_sk_laddr_hash(struct llc_sap *sap,
  75. const struct llc_addr *laddr)
  76. {
  77. return &sap->sk_laddr_hash[llc_sk_laddr_hashfn(sap, laddr)];
  78. }
  79. #define LLC_DEST_INVALID 0 /* Invalid LLC PDU type */
  80. #define LLC_DEST_SAP 1 /* Type 1 goes here */
  81. #define LLC_DEST_CONN 2 /* Type 2 goes here */
  82. extern struct list_head llc_sap_list;
  83. extern spinlock_t llc_sap_list_lock;
  84. extern int llc_rcv(struct sk_buff *skb, struct net_device *dev,
  85. struct packet_type *pt, struct net_device *orig_dev);
  86. extern int llc_mac_hdr_init(struct sk_buff *skb,
  87. const unsigned char *sa, const unsigned char *da);
  88. extern void llc_add_pack(int type, void (*handler)(struct llc_sap *sap,
  89. struct sk_buff *skb));
  90. extern void llc_remove_pack(int type);
  91. extern void llc_set_station_handler(void (*handler)(struct sk_buff *skb));
  92. extern 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. atomic_inc(&sap->refcnt);
  100. }
  101. extern void llc_sap_close(struct llc_sap *sap);
  102. static inline void llc_sap_put(struct llc_sap *sap)
  103. {
  104. if (atomic_dec_and_test(&sap->refcnt))
  105. llc_sap_close(sap);
  106. }
  107. extern struct llc_sap *llc_sap_find(unsigned char sap_value);
  108. extern int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb,
  109. unsigned char *dmac, unsigned char dsap);
  110. extern void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb);
  111. extern void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb);
  112. extern int llc_station_init(void);
  113. extern void llc_station_exit(void);
  114. #ifdef CONFIG_PROC_FS
  115. extern int llc_proc_init(void);
  116. extern void llc_proc_exit(void);
  117. #else
  118. #define llc_proc_init() (0)
  119. #define llc_proc_exit() do { } while(0)
  120. #endif /* CONFIG_PROC_FS */
  121. #ifdef CONFIG_SYSCTL
  122. extern int llc_sysctl_init(void);
  123. extern void llc_sysctl_exit(void);
  124. extern int sysctl_llc2_ack_timeout;
  125. extern int sysctl_llc2_busy_timeout;
  126. extern int sysctl_llc2_p_timeout;
  127. extern int sysctl_llc2_rej_timeout;
  128. extern int sysctl_llc_station_ack_timeout;
  129. #else
  130. #define llc_sysctl_init() (0)
  131. #define llc_sysctl_exit() do { } while(0)
  132. #endif /* CONFIG_SYSCTL */
  133. #endif /* LLC_H */