/* * llc_core.c - Minimum needed routines for sap handling and module init/exit * * 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.
*/
/** * llc_sap_alloc - allocates and initializes sap. * * Allocates and initializes sap.
*/ staticstruct llc_sap *llc_sap_alloc(void)
{ struct llc_sap *sap = kzalloc(sizeof(*sap), GFP_ATOMIC); int i;
if (sap) { /* sap->laddr.mac - leave as a null, it's filled by bind */
sap->state = LLC_SAP_STATE_ACTIVE;
spin_lock_init(&sap->sk_lock); for (i = 0; i < LLC_SK_LADDR_HASH_ENTRIES; i++)
INIT_HLIST_NULLS_HEAD(&sap->sk_laddr_hash[i], i);
refcount_set(&sap->refcnt, 1);
} return sap;
}
list_for_each_entry(sap, &llc_sap_list, node) if (sap->laddr.lsap == sap_value) goto out;
sap = NULL;
out: return sap;
}
/** * llc_sap_find - searches a SAP in station * @sap_value: sap to be found * * Searches for a sap in the sap list of the LLC's station upon the sap ID. * If the sap is found it will be refcounted and the user will have to do * a llc_sap_put after use. * Returns the sap or %NULL if not found.
*/ struct llc_sap *llc_sap_find(unsignedchar sap_value)
{ struct llc_sap *sap;
rcu_read_lock_bh();
sap = __llc_sap_find(sap_value); if (!sap || !llc_sap_hold_safe(sap))
sap = NULL;
rcu_read_unlock_bh(); return sap;
}
/** * llc_sap_open - open interface to the upper layers. * @lsap: SAP number. * @func: rcv func for datalink protos * * Interface function to upper layer. Each one who wants to get a SAP * (for example NetBEUI) should call this function. Returns the opened * SAP for success, NULL for failure.
*/ struct llc_sap *llc_sap_open(unsignedchar lsap, int (*func)(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev))
{ struct llc_sap *sap = NULL;
spin_lock_bh(&llc_sap_list_lock); if (__llc_sap_find(lsap)) /* SAP already exists */ goto out;
sap = llc_sap_alloc(); if (!sap) goto out;
sap->laddr.lsap = lsap;
sap->rcv_func = func;
list_add_tail_rcu(&sap->node, &llc_sap_list);
out:
spin_unlock_bh(&llc_sap_list_lock); return sap;
}
/** * llc_sap_close - close interface for upper layers. * @sap: SAP to be closed. * * Close interface function to upper layer. Each one who wants to * close an open SAP (for example NetBEUI) should call this function. * Removes this sap from the list of saps in the station and then * frees the memory for this sap.
*/ void llc_sap_close(struct llc_sap *sap)
{
WARN_ON(sap->sk_count);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.