Source
x
/*
* proc_llc.c - proc interface for LLC
*
* Copyright (c) 2001 by Jay Schulist <jschlst@samba.org>
* 2002-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.
*/
static void llc_ui_format_mac(struct seq_file *seq, u8 *addr)
{
seq_printf(seq, "%pM", addr);
}
static struct sock *llc_get_sk_idx(loff_t pos)
{
struct llc_sap *sap;
struct sock *sk = NULL;
int i;
list_for_each_entry_rcu(sap, &llc_sap_list, node) {
spin_lock_bh(&sap->sk_lock);
for (i = 0; i < LLC_SK_LADDR_HASH_ENTRIES; i++) {
struct hlist_nulls_head *head = &sap->sk_laddr_hash[i];
struct hlist_nulls_node *node;
sk_nulls_for_each(sk, node, head) {
if (!pos)
goto found; /* keep the lock */
--pos;
}
}
spin_unlock_bh(&sap->sk_lock);
}
sk = NULL;
found:
return sk;
}
static void *llc_seq_start(struct seq_file *seq, loff_t *pos)
{
loff_t l = *pos;
rcu_read_lock_bh();
return l ? llc_get_sk_idx(--l) : SEQ_START_TOKEN;
}
static struct sock *laddr_hash_next(struct llc_sap *sap, int bucket)
{
struct hlist_nulls_node *node;
struct sock *sk = NULL;
while (++bucket < LLC_SK_LADDR_HASH_ENTRIES)
sk_nulls_for_each(sk, node, &sap->sk_laddr_hash[bucket])
goto out;
out:
return sk;
}
static void *llc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
{
struct sock* sk, *next;
struct llc_sock *llc;
struct llc_sap *sap;
++*pos;
if (v == SEQ_START_TOKEN) {
sk = llc_get_sk_idx(0);
goto out;
}
sk = v;
next = sk_nulls_next(sk);