patch-2.4.22 linux-2.4.22/net/atm/lec.c
Next file: linux-2.4.22/net/atm/lec.h
Previous file: linux-2.4.22/net/atm/ipcommon.c
Back to the patch index
Back to the overall index
- Lines: 539
- Date:
2003-08-25 04:44:44.000000000 -0700
- Orig file:
linux-2.4.21/net/atm/lec.c
- Orig date:
2003-06-13 07:51:39.000000000 -0700
diff -urN linux-2.4.21/net/atm/lec.c linux-2.4.22/net/atm/lec.c
@@ -20,6 +20,7 @@
#include <net/arp.h>
#include <net/dst.h>
#include <linux/proc_fs.h>
+#include <linux/spinlock.h>
/* TokenRing if needed */
#ifdef CONFIG_TR
@@ -51,10 +52,12 @@
#define DPRINTK(format,args...)
#endif
+struct net_bridge;
extern struct net_bridge_fdb_entry *(*br_fdb_get_hook)(struct net_bridge *br,
unsigned char *addr);
extern void (*br_fdb_put_hook)(struct net_bridge_fdb_entry *ent);
+static spinlock_t lec_arp_spinlock = SPIN_LOCK_UNLOCKED;
#define DUMP_PACKETS 0 /* 0 = None,
* 1 = 30 first bytes
@@ -283,7 +286,7 @@
#endif
min_frame_size = LEC_MINIMUM_8023_SIZE;
if (skb->len < min_frame_size) {
- if (skb->truesize < min_frame_size) {
+ if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
skb2 = skb_copy_expand(skb, 0,
min_frame_size - skb->truesize, GFP_ATOMIC);
dev_kfree_skb(skb);
@@ -341,7 +344,6 @@
lec_h->h_dest[0], lec_h->h_dest[1], lec_h->h_dest[2],
lec_h->h_dest[3], lec_h->h_dest[4], lec_h->h_dest[5]);
ATM_SKB(skb2)->vcc = send_vcc;
- ATM_SKB(skb2)->iovcnt = 0;
ATM_SKB(skb2)->atm_options = send_vcc->atm_options;
DPRINTK("%s:sending to vpi:%d vci:%d\n", dev->name,
send_vcc->vpi, send_vcc->vci);
@@ -357,7 +359,6 @@
}
ATM_SKB(skb)->vcc = send_vcc;
- ATM_SKB(skb)->iovcnt = 0;
ATM_SKB(skb)->atm_options = send_vcc->atm_options;
if (atm_may_send(send_vcc, skb->len)) {
atomic_add(skb->truesize, &send_vcc->sk->wmem_alloc);
@@ -404,7 +405,7 @@
int i;
char *tmp; /* FIXME */
- atomic_sub(skb->truesize+ATM_PDU_OVHD, &vcc->sk->wmem_alloc);
+ atomic_sub(skb->truesize, &vcc->sk->wmem_alloc);
mesg = (struct atmlec_msg *)skb->data;
tmp = skb->data;
tmp += sizeof(struct atmlec_msg);
@@ -552,20 +553,15 @@
}
static struct atmdev_ops lecdev_ops = {
- close: lec_atm_close,
- send: lec_atm_send
+ .close = lec_atm_close,
+ .send = lec_atm_send
};
static struct atm_dev lecatm_dev = {
- &lecdev_ops,
- NULL, /*PHY*/
- "lec", /*type*/
- 999, /*dummy device number*/
- NULL,NULL, /*no VCCs*/
- NULL,NULL, /*no data*/
- { 0 }, /*no flags*/
- NULL, /* no local address*/
- { 0 } /*no ESI or rest of the atm_dev struct things*/
+ .ops = &lecdev_ops,
+ .type = "lec",
+ .number = 999,
+ .lock = SPIN_LOCK_UNLOCKED
};
/*
@@ -726,6 +722,7 @@
skb->protocol = eth_type_trans(skb, dev);
priv->stats.rx_packets++;
priv->stats.rx_bytes += skb->len;
+ memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
netif_rx(skb);
}
}
@@ -1055,15 +1052,15 @@
#define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
static __inline__ void
-lec_arp_lock(struct lec_priv *priv)
+lec_arp_get(struct lec_priv *priv)
{
- atomic_inc(&priv->lec_arp_lock_var);
+ atomic_inc(&priv->lec_arp_users);
}
static __inline__ void
-lec_arp_unlock(struct lec_priv *priv)
+lec_arp_put(struct lec_priv *priv)
{
- atomic_dec(&priv->lec_arp_lock_var);
+ atomic_dec(&priv->lec_arp_users);
}
/*
@@ -1114,33 +1111,33 @@
* LANE2: Add to the end of the list to satisfy 8.1.13
*/
static __inline__ void
-lec_arp_put(struct lec_arp_table **lec_arp_tables,
- struct lec_arp_table *to_put)
+lec_arp_add(struct lec_arp_table **lec_arp_tables,
+ struct lec_arp_table *to_add)
{
- unsigned short place;
unsigned long flags;
+ unsigned short place;
struct lec_arp_table *tmp;
- save_flags(flags);
- cli();
+ spin_lock_irqsave(&lec_arp_spinlock, flags);
- place = HASH(to_put->mac_addr[ETH_ALEN-1]);
+ place = HASH(to_add->mac_addr[ETH_ALEN-1]);
tmp = lec_arp_tables[place];
- to_put->next = NULL;
+ to_add->next = NULL;
if (tmp == NULL)
- lec_arp_tables[place] = to_put;
+ lec_arp_tables[place] = to_add;
else { /* add to the end */
while (tmp->next)
tmp = tmp->next;
- tmp->next = to_put;
+ tmp->next = to_add;
}
- restore_flags(flags);
+ spin_unlock_irqrestore(&lec_arp_spinlock, flags);
+
DPRINTK("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
- 0xff&to_put->mac_addr[0], 0xff&to_put->mac_addr[1],
- 0xff&to_put->mac_addr[2], 0xff&to_put->mac_addr[3],
- 0xff&to_put->mac_addr[4], 0xff&to_put->mac_addr[5]);
+ 0xff&to_add->mac_addr[0], 0xff&to_add->mac_addr[1],
+ 0xff&to_add->mac_addr[2], 0xff&to_add->mac_addr[3],
+ 0xff&to_add->mac_addr[4], 0xff&to_add->mac_addr[5]);
}
/*
@@ -1150,16 +1147,15 @@
lec_arp_remove(struct lec_arp_table **lec_arp_tables,
struct lec_arp_table *to_remove)
{
+ unsigned long flags;
unsigned short place;
struct lec_arp_table *tmp;
- unsigned long flags;
int remove_vcc=1;
- save_flags(flags);
- cli();
+ spin_lock_irqsave(&lec_arp_spinlock, flags);
if (!to_remove) {
- restore_flags(flags);
+ spin_unlock_irqrestore(&lec_arp_spinlock, flags);
return -1;
}
place = HASH(to_remove->mac_addr[ETH_ALEN-1]);
@@ -1171,7 +1167,7 @@
tmp = tmp->next;
}
if (!tmp) {/* Entry was not found */
- restore_flags(flags);
+ spin_unlock_irqrestore(&lec_arp_spinlock, flags);
return -1;
}
}
@@ -1197,7 +1193,9 @@
lec_arp_clear_vccs(to_remove);
}
skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
- restore_flags(flags);
+
+ spin_unlock_irqrestore(&lec_arp_spinlock, flags);
+
DPRINTK("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
0xff&to_remove->mac_addr[0], 0xff&to_remove->mac_addr[1],
0xff&to_remove->mac_addr[2], 0xff&to_remove->mac_addr[3],
@@ -1382,12 +1380,8 @@
lec_arp_destroy(struct lec_priv *priv)
{
struct lec_arp_table *entry, *next;
- unsigned long flags;
int i;
- save_flags(flags);
- cli();
-
del_timer(&priv->lec_arp_timer);
/*
@@ -1430,7 +1424,6 @@
priv->mcast_vcc = NULL;
memset(priv->lec_arp_tables, 0,
sizeof(struct lec_arp_table*)*LEC_ARP_TABLE_SIZE);
- restore_flags(flags);
}
@@ -1447,18 +1440,18 @@
DPRINTK("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
mac_addr[0]&0xff, mac_addr[1]&0xff, mac_addr[2]&0xff,
mac_addr[3]&0xff, mac_addr[4]&0xff, mac_addr[5]&0xff);
- lec_arp_lock(priv);
+ lec_arp_get(priv);
place = HASH(mac_addr[ETH_ALEN-1]);
to_return = priv->lec_arp_tables[place];
while(to_return) {
if (memcmp(mac_addr, to_return->mac_addr, ETH_ALEN) == 0) {
- lec_arp_unlock(priv);
+ lec_arp_put(priv);
return to_return;
}
to_return = to_return->next;
}
- lec_arp_unlock(priv);
+ lec_arp_put(priv);
return NULL;
}
@@ -1585,11 +1578,11 @@
del_timer(&priv->lec_arp_timer);
DPRINTK("lec_arp_check_expire %p,%d\n",priv,
- priv->lec_arp_lock_var.counter);
+ atomic_read(&priv->lec_arp_users));
DPRINTK("expire: eo:%p nf:%p\n",priv->lec_arp_empty_ones,
priv->lec_no_forward);
- if (!priv->lec_arp_lock_var.counter) {
- lec_arp_lock(priv);
+ if (!atomic_read(&priv->lec_arp_users)) {
+ lec_arp_get(priv);
now = jiffies;
for(i=0;i<LEC_ARP_TABLE_SIZE;i++) {
for(entry = lec_arp_tables[i];entry != NULL;) {
@@ -1635,7 +1628,7 @@
}
}
}
- lec_arp_unlock(priv);
+ lec_arp_put(priv);
}
priv->lec_arp_timer.expires = jiffies + LEC_ARP_REFRESH_INTERVAL;
add_timer(&priv->lec_arp_timer);
@@ -1697,7 +1690,7 @@
if (!entry) {
return priv->mcast_vcc;
}
- lec_arp_put(priv->lec_arp_tables, entry);
+ lec_arp_add(priv->lec_arp_tables, entry);
/* We want arp-request(s) to be sent */
entry->packets_flooded =1;
entry->status = ESI_ARP_PENDING;
@@ -1722,7 +1715,7 @@
struct lec_arp_table *entry, *next;
int i;
- lec_arp_lock(priv);
+ lec_arp_get(priv);
DPRINTK("lec_addr_delete\n");
for(i=0;i<LEC_ARP_TABLE_SIZE;i++) {
for(entry=priv->lec_arp_tables[i];entry != NULL; entry=next) {
@@ -1733,11 +1726,11 @@
lec_arp_remove(priv->lec_arp_tables, entry);
kfree(entry);
}
- lec_arp_unlock(priv);
+ lec_arp_put(priv);
return 0;
}
}
- lec_arp_unlock(priv);
+ lec_arp_put(priv);
return -1;
}
@@ -1762,7 +1755,7 @@
return; /* LANE2: ignore targetless LE_ARPs for which
* we have no entry in the cache. 7.1.30
*/
- lec_arp_lock(priv);
+ lec_arp_get(priv);
if (priv->lec_arp_empty_ones) {
entry = priv->lec_arp_empty_ones;
if (!memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN)) {
@@ -1796,13 +1789,13 @@
entry->status = ESI_FORWARD_DIRECT;
memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
entry->last_used = jiffies;
- lec_arp_put(priv->lec_arp_tables, entry);
+ lec_arp_add(priv->lec_arp_tables, entry);
}
if (remoteflag)
entry->flags|=LEC_REMOTE_FLAG;
else
entry->flags&=~LEC_REMOTE_FLAG;
- lec_arp_unlock(priv);
+ lec_arp_put(priv);
DPRINTK("After update\n");
dump_arp_table(priv);
return;
@@ -1812,11 +1805,11 @@
if (!entry) {
entry = make_entry(priv, mac_addr);
if (!entry) {
- lec_arp_unlock(priv);
+ lec_arp_put(priv);
return;
}
entry->status = ESI_UNKNOWN;
- lec_arp_put(priv->lec_arp_tables, entry);
+ lec_arp_add(priv->lec_arp_tables, entry);
/* Temporary, changes before end of function */
}
memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
@@ -1851,7 +1844,7 @@
}
DPRINTK("After update2\n");
dump_arp_table(priv);
- lec_arp_unlock(priv);
+ lec_arp_put(priv);
}
/*
@@ -1865,7 +1858,7 @@
struct lec_arp_table *entry;
int i, found_entry=0;
- lec_arp_lock(priv);
+ lec_arp_get(priv);
if (ioc_data->receive == 2) {
/* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
@@ -1874,7 +1867,7 @@
entry = lec_arp_find(priv, bus_mac);
if (!entry) {
printk("LEC_ARP: Multicast entry not found!\n");
- lec_arp_unlock(priv);
+ lec_arp_put(priv);
return;
}
memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
@@ -1883,7 +1876,7 @@
#endif
entry = make_entry(priv, bus_mac);
if (entry == NULL) {
- lec_arp_unlock(priv);
+ lec_arp_put(priv);
return;
}
del_timer(&entry->timer);
@@ -1892,7 +1885,7 @@
entry->old_recv_push = old_push;
entry->next = priv->mcast_fwds;
priv->mcast_fwds = entry;
- lec_arp_unlock(priv);
+ lec_arp_put(priv);
return;
} else if (ioc_data->receive == 1) {
/* Vcc which we don't want to make default vcc, attach it
@@ -1910,7 +1903,7 @@
ioc_data->atm_addr[18],ioc_data->atm_addr[19]);
entry = make_entry(priv, bus_mac);
if (entry == NULL) {
- lec_arp_unlock(priv);
+ lec_arp_put(priv);
return;
}
memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
@@ -1923,7 +1916,7 @@
add_timer(&entry->timer);
entry->next = priv->lec_no_forward;
priv->lec_no_forward = entry;
- lec_arp_unlock(priv);
+ lec_arp_put(priv);
dump_arp_table(priv);
return;
}
@@ -1982,7 +1975,7 @@
}
}
if (found_entry) {
- lec_arp_unlock(priv);
+ lec_arp_put(priv);
DPRINTK("After vcc was added\n");
dump_arp_table(priv);
return;
@@ -1991,7 +1984,7 @@
this vcc */
entry = make_entry(priv, bus_mac);
if (!entry) {
- lec_arp_unlock(priv);
+ lec_arp_put(priv);
return;
}
entry->vcc = vcc;
@@ -2004,7 +1997,7 @@
entry->timer.expires = jiffies + priv->vcc_timeout_period;
entry->timer.function = lec_arp_expire_vcc;
add_timer(&entry->timer);
- lec_arp_unlock(priv);
+ lec_arp_put(priv);
DPRINTK("After vcc was added\n");
dump_arp_table(priv);
}
@@ -2050,10 +2043,10 @@
0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
struct lec_arp_table *to_add;
- lec_arp_lock(priv);
+ lec_arp_get(priv);
to_add = make_entry(priv, mac_addr);
if (!to_add) {
- lec_arp_unlock(priv);
+ lec_arp_put(priv);
return -ENOMEM;
}
memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
@@ -2063,8 +2056,8 @@
to_add->old_push = vcc->push;
vcc->push = lec_push;
priv->mcast_vcc = vcc;
- lec_arp_put(priv->lec_arp_tables, to_add);
- lec_arp_unlock(priv);
+ lec_arp_add(priv->lec_arp_tables, to_add);
+ lec_arp_put(priv);
return 0;
}
@@ -2076,7 +2069,7 @@
DPRINTK("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n",vcc->vpi,vcc->vci);
dump_arp_table(priv);
- lec_arp_lock(priv);
+ lec_arp_get(priv);
for(i=0;i<LEC_ARP_TABLE_SIZE;i++) {
for(entry = priv->lec_arp_tables[i];entry; entry=next) {
next = entry->next;
@@ -2138,7 +2131,7 @@
entry = next;
}
- lec_arp_unlock(priv);
+ lec_arp_put(priv);
dump_arp_table(priv);
}
@@ -2146,9 +2139,9 @@
lec_arp_check_empties(struct lec_priv *priv,
struct atm_vcc *vcc, struct sk_buff *skb)
{
+ unsigned long flags;
struct lec_arp_table *entry, *prev;
struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
- unsigned long flags;
unsigned char *src;
#ifdef CONFIG_TR
struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
@@ -2158,26 +2151,26 @@
#endif
src = hdr->h_source;
- lec_arp_lock(priv);
+ lec_arp_get(priv);
entry = priv->lec_arp_empty_ones;
if (vcc == entry->vcc) {
- save_flags(flags);
- cli();
+ spin_lock_irqsave(&lec_arp_spinlock, flags);
del_timer(&entry->timer);
memcpy(entry->mac_addr, src, ETH_ALEN);
entry->status = ESI_FORWARD_DIRECT;
entry->last_used = jiffies;
priv->lec_arp_empty_ones = entry->next;
- restore_flags(flags);
+ spin_unlock_irqrestore(&lec_arp_spinlock, flags);
/* We might have got an entry */
if ((prev=lec_arp_find(priv,src))) {
lec_arp_remove(priv->lec_arp_tables, prev);
kfree(prev);
}
- lec_arp_put(priv->lec_arp_tables, entry);
- lec_arp_unlock(priv);
+ lec_arp_add(priv->lec_arp_tables, entry);
+ lec_arp_put(priv);
return;
}
+ spin_lock_irqsave(&lec_arp_spinlock, flags);
prev = entry;
entry = entry->next;
while (entry && entry->vcc != vcc) {
@@ -2186,22 +2179,21 @@
}
if (!entry) {
DPRINTK("LEC_ARP: Arp_check_empties: entry not found!\n");
- lec_arp_unlock(priv);
+ lec_arp_put(priv);
+ spin_unlock_irqrestore(&lec_arp_spinlock, flags);
return;
}
- save_flags(flags);
- cli();
del_timer(&entry->timer);
memcpy(entry->mac_addr, src, ETH_ALEN);
entry->status = ESI_FORWARD_DIRECT;
entry->last_used = jiffies;
prev->next = entry->next;
- restore_flags(flags);
+ spin_unlock_irqrestore(&lec_arp_spinlock, flags);
if ((prev = lec_arp_find(priv, src))) {
lec_arp_remove(priv->lec_arp_tables,prev);
kfree(prev);
}
- lec_arp_put(priv->lec_arp_tables,entry);
- lec_arp_unlock(priv);
+ lec_arp_add(priv->lec_arp_tables,entry);
+ lec_arp_put(priv);
}
MODULE_LICENSE("GPL");
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)