llc.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. 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. int llc_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt,
  84. struct net_device *orig_dev);
  85. int llc_mac_hdr_init(struct sk_buff *skb, const unsigned char *sa,
  86. const unsigned char *da);
  87. void llc_add_pack(int type,
  88. void (*handler)(struct llc_sap *sap, struct sk_buff *skb));
  89. void llc_remove_pack(int type);
  90. void llc_set_station_handler(void (*handler)(struct sk_buff *skb));
  91. struct llc_sap *llc_sap_open(unsigned char lsap,
  92. int (*rcv)(struct sk_buff *skb,
  93. struct net_device *dev,
  94. struct packet_type *pt,
  95. struct net_device *orig_dev));
  96. static inline void llc_sap_hold(struct llc_sap *sap)
  97. {
  98. atomic_inc(&sap->refcnt);
  99. }
  100. void llc_sap_close(struct llc_sap *sap);
  101. static inline void llc_sap_put(struct llc_sap *sap)
  102. {
  103. if (atomic_dec_and_test(&sap->refcnt))
  104. llc_sap_close(sap);
  105. }
  106. struct llc_sap *llc_sap_find(unsigned char sap_value);
  107. int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb,
  108. unsigned char *dmac, unsigned char dsap);
  109. void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb);
  110. void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb);
  111. void llc_station_init(void);
  112. void llc_station_exit(void);
  113. #ifdef CONFIG_PROC_FS
  114. int llc_proc_init(void);
  115. void llc_proc_exit(void);
  116. #else
  117. #define llc_proc_init() (0)
  118. #define llc_proc_exit() do { } while(0)
  119. #endif /* CONFIG_PROC_FS */
  120. #ifdef CONFIG_SYSCTL
  121. int llc_sysctl_init(void);
  122. void llc_sysctl_exit(void);
  123. extern int sysctl_llc2_ack_timeout;
  124. extern int sysctl_llc2_busy_timeout;
  125. extern int sysctl_llc2_p_timeout;
  126. extern int sysctl_llc2_rej_timeout;
  127. #else
  128. #define llc_sysctl_init() (0)
  129. #define llc_sysctl_exit() do { } while(0)
  130. #endif /* CONFIG_SYSCTL */
  131. #endif /* LLC_H */