2005-04-17 06:20:36 +08:00
|
|
|
#ifndef LLC_H
|
|
|
|
#define LLC_H
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1997 by Procom Technology, Inc.
|
|
|
|
* 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
|
|
|
|
*
|
|
|
|
* This program can be redistributed or modified under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation.
|
|
|
|
* This program is distributed without any warranty or implied warranty
|
|
|
|
* of merchantability or fitness for a particular purpose.
|
|
|
|
*
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/if.h>
|
|
|
|
#include <linux/if_ether.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/spinlock.h>
|
2009-12-26 19:51:02 +08:00
|
|
|
#include <linux/rculist_nulls.h>
|
2009-12-26 19:51:05 +08:00
|
|
|
#include <linux/hash.h>
|
|
|
|
#include <linux/jhash.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-07-27 07:09:06 +08:00
|
|
|
#include <linux/atomic.h>
|
2005-09-22 15:43:05 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
struct net_device;
|
|
|
|
struct packet_type;
|
|
|
|
struct sk_buff;
|
|
|
|
|
|
|
|
struct llc_addr {
|
|
|
|
unsigned char lsap;
|
|
|
|
unsigned char mac[IFHWADDRLEN];
|
|
|
|
};
|
|
|
|
|
|
|
|
#define LLC_SAP_STATE_INACTIVE 1
|
|
|
|
#define LLC_SAP_STATE_ACTIVE 2
|
|
|
|
|
2009-12-26 19:51:04 +08:00
|
|
|
#define LLC_SK_DEV_HASH_BITS 6
|
|
|
|
#define LLC_SK_DEV_HASH_ENTRIES (1<<LLC_SK_DEV_HASH_BITS)
|
|
|
|
|
2009-12-26 19:51:05 +08:00
|
|
|
#define LLC_SK_LADDR_HASH_BITS 6
|
|
|
|
#define LLC_SK_LADDR_HASH_ENTRIES (1<<LLC_SK_LADDR_HASH_BITS)
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* struct llc_sap - Defines the SAP component
|
|
|
|
*
|
|
|
|
* @station - station this sap belongs to
|
|
|
|
* @state - sap state
|
|
|
|
* @p_bit - only lowest-order bit used
|
|
|
|
* @f_bit - only lowest-order bit used
|
|
|
|
* @laddr - SAP value in this 'lsap'
|
|
|
|
* @node - entry in station sap_list
|
|
|
|
* @sk_list - LLC sockets this one manages
|
|
|
|
*/
|
|
|
|
struct llc_sap {
|
|
|
|
unsigned char state;
|
|
|
|
unsigned char p_bit;
|
|
|
|
unsigned char f_bit;
|
2017-07-04 20:52:56 +08:00
|
|
|
refcount_t refcnt;
|
2005-04-17 06:20:36 +08:00
|
|
|
int (*rcv_func)(struct sk_buff *skb,
|
|
|
|
struct net_device *dev,
|
2005-08-10 10:34:12 +08:00
|
|
|
struct packet_type *pt,
|
|
|
|
struct net_device *orig_dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct llc_addr laddr;
|
|
|
|
struct list_head node;
|
2009-12-26 19:51:02 +08:00
|
|
|
spinlock_t sk_lock;
|
2009-12-26 19:51:05 +08:00
|
|
|
int sk_count;
|
|
|
|
struct hlist_nulls_head sk_laddr_hash[LLC_SK_LADDR_HASH_ENTRIES];
|
2009-12-26 19:51:04 +08:00
|
|
|
struct hlist_head sk_dev_hash[LLC_SK_DEV_HASH_ENTRIES];
|
2018-09-12 02:42:06 +08:00
|
|
|
struct rcu_head rcu;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2009-12-26 19:51:04 +08:00
|
|
|
static inline
|
|
|
|
struct hlist_head *llc_sk_dev_hash(struct llc_sap *sap, int ifindex)
|
|
|
|
{
|
2021-11-06 05:42:14 +08:00
|
|
|
u32 bucket = hash_32(ifindex, LLC_SK_DEV_HASH_BITS);
|
|
|
|
|
|
|
|
return &sap->sk_dev_hash[bucket];
|
2009-12-26 19:51:04 +08:00
|
|
|
}
|
|
|
|
|
2009-12-26 19:51:05 +08:00
|
|
|
static inline
|
|
|
|
u32 llc_sk_laddr_hashfn(struct llc_sap *sap, const struct llc_addr *laddr)
|
|
|
|
{
|
|
|
|
return hash_32(jhash(laddr->mac, sizeof(laddr->mac), 0),
|
|
|
|
LLC_SK_LADDR_HASH_BITS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline
|
|
|
|
struct hlist_nulls_head *llc_sk_laddr_hash(struct llc_sap *sap,
|
|
|
|
const struct llc_addr *laddr)
|
|
|
|
{
|
|
|
|
return &sap->sk_laddr_hash[llc_sk_laddr_hashfn(sap, laddr)];
|
|
|
|
}
|
2009-12-26 19:51:04 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#define LLC_DEST_INVALID 0 /* Invalid LLC PDU type */
|
|
|
|
#define LLC_DEST_SAP 1 /* Type 1 goes here */
|
|
|
|
#define LLC_DEST_CONN 2 /* Type 2 goes here */
|
|
|
|
|
|
|
|
extern struct list_head llc_sap_list;
|
|
|
|
|
2013-09-22 01:22:45 +08:00
|
|
|
int llc_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt,
|
|
|
|
struct net_device *orig_dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-09-22 01:22:45 +08:00
|
|
|
int llc_mac_hdr_init(struct sk_buff *skb, const unsigned char *sa,
|
|
|
|
const unsigned char *da);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-09-22 01:22:45 +08:00
|
|
|
void llc_add_pack(int type,
|
|
|
|
void (*handler)(struct llc_sap *sap, struct sk_buff *skb));
|
|
|
|
void llc_remove_pack(int type);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-09-22 01:22:45 +08:00
|
|
|
void llc_set_station_handler(void (*handler)(struct sk_buff *skb));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-09-22 01:22:45 +08:00
|
|
|
struct llc_sap *llc_sap_open(unsigned char lsap,
|
|
|
|
int (*rcv)(struct sk_buff *skb,
|
|
|
|
struct net_device *dev,
|
|
|
|
struct packet_type *pt,
|
|
|
|
struct net_device *orig_dev));
|
2005-09-22 15:43:05 +08:00
|
|
|
static inline void llc_sap_hold(struct llc_sap *sap)
|
|
|
|
{
|
2017-07-04 20:52:56 +08:00
|
|
|
refcount_inc(&sap->refcnt);
|
2005-09-22 15:43:05 +08:00
|
|
|
}
|
|
|
|
|
2018-08-08 03:41:38 +08:00
|
|
|
static inline bool llc_sap_hold_safe(struct llc_sap *sap)
|
|
|
|
{
|
|
|
|
return refcount_inc_not_zero(&sap->refcnt);
|
|
|
|
}
|
|
|
|
|
2013-09-22 01:22:45 +08:00
|
|
|
void llc_sap_close(struct llc_sap *sap);
|
2005-09-22 16:14:33 +08:00
|
|
|
|
2005-09-22 15:43:05 +08:00
|
|
|
static inline void llc_sap_put(struct llc_sap *sap)
|
|
|
|
{
|
2017-07-04 20:52:56 +08:00
|
|
|
if (refcount_dec_and_test(&sap->refcnt))
|
2005-09-22 15:43:05 +08:00
|
|
|
llc_sap_close(sap);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-09-22 01:22:45 +08:00
|
|
|
struct llc_sap *llc_sap_find(unsigned char sap_value);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-09-22 01:22:45 +08:00
|
|
|
int llc_build_and_send_ui_pkt(struct llc_sap *sap, struct sk_buff *skb,
|
2021-10-12 23:58:37 +08:00
|
|
|
const unsigned char *dmac, unsigned char dsap);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-09-22 01:22:45 +08:00
|
|
|
void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb);
|
|
|
|
void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb);
|
2005-09-22 16:14:33 +08:00
|
|
|
|
2013-09-22 01:22:45 +08:00
|
|
|
void llc_station_init(void);
|
|
|
|
void llc_station_exit(void);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2013-09-22 01:22:45 +08:00
|
|
|
int llc_proc_init(void);
|
|
|
|
void llc_proc_exit(void);
|
2005-04-17 06:20:36 +08:00
|
|
|
#else
|
|
|
|
#define llc_proc_init() (0)
|
|
|
|
#define llc_proc_exit() do { } while(0)
|
|
|
|
#endif /* CONFIG_PROC_FS */
|
2005-09-22 15:30:44 +08:00
|
|
|
#ifdef CONFIG_SYSCTL
|
2013-09-22 01:22:45 +08:00
|
|
|
int llc_sysctl_init(void);
|
|
|
|
void llc_sysctl_exit(void);
|
2005-09-22 16:14:33 +08:00
|
|
|
|
|
|
|
extern int sysctl_llc2_ack_timeout;
|
|
|
|
extern int sysctl_llc2_busy_timeout;
|
|
|
|
extern int sysctl_llc2_p_timeout;
|
|
|
|
extern int sysctl_llc2_rej_timeout;
|
2005-09-22 15:30:44 +08:00
|
|
|
#else
|
|
|
|
#define llc_sysctl_init() (0)
|
|
|
|
#define llc_sysctl_exit() do { } while(0)
|
|
|
|
#endif /* CONFIG_SYSCTL */
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif /* LLC_H */
|