2 * lec.c: Lan Emulation driver
3 * Marko Kiiskila mkiiskila@yahoo.com
7 #include <linux/config.h>
8 #include <linux/kernel.h>
9 #include <linux/bitops.h>
11 /* We are ethernet device */
12 #include <linux/if_ether.h>
13 #include <linux/netdevice.h>
14 #include <linux/etherdevice.h>
16 #include <linux/skbuff.h>
18 #include <asm/byteorder.h>
19 #include <asm/uaccess.h>
22 #include <linux/proc_fs.h>
23 #include <linux/spinlock.h>
24 #include <linux/proc_fs.h>
25 #include <linux/seq_file.h>
27 /* TokenRing if needed */
29 #include <linux/trdevice.h>
33 #include <linux/atmdev.h>
34 #include <linux/atmlec.h>
36 /* Proxy LEC knows about bridging */
37 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
38 #include <linux/if_bridge.h>
39 #include "../bridge/br_private.h"
40 static unsigned char bridge_ula_lec[] = {0x01, 0x80, 0xc2, 0x00, 0x00};
42 extern struct net_bridge_fdb_entry *(*br_fdb_get_hook)(struct net_bridge *br,
44 extern void (*br_fdb_put_hook)(struct net_bridge_fdb_entry *ent);
48 #include <linux/module.h>
49 #include <linux/init.h>
53 #include "resources.h"
56 #define DPRINTK printk
58 #define DPRINTK(format,args...)
61 #define DUMP_PACKETS 0 /* 0 = None,
66 #define LEC_UNRES_QUE_LEN 8 /* number of tx packets to queue for a
67 single destination while waiting for SVC */
69 static int lec_open(struct net_device *dev);
70 static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev);
71 static int lec_close(struct net_device *dev);
72 static struct net_device_stats *lec_get_stats(struct net_device *dev);
73 static void lec_init(struct net_device *dev);
74 static struct lec_arp_table* lec_arp_find(struct lec_priv *priv,
75 unsigned char *mac_addr);
76 static int lec_arp_remove(struct lec_priv *priv,
77 struct lec_arp_table *to_remove);
79 static void lane2_associate_ind (struct net_device *dev, u8 *mac_address,
80 u8 *tlvs, u32 sizeoftlvs);
81 static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
82 u8 **tlvs, u32 *sizeoftlvs);
83 static int lane2_associate_req (struct net_device *dev, u8 *lan_dst,
84 u8 *tlvs, u32 sizeoftlvs);
86 static struct lane2_ops lane2_ops = {
87 lane2_resolve, /* resolve, spec 3.1.3 */
88 lane2_associate_req, /* associate_req, spec 3.1.4 */
89 NULL /* associate indicator, spec 3.1.5 */
92 static unsigned char bus_mac[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
94 /* Device structures */
95 static struct net_device *dev_lec[MAX_LEC_ITF];
97 /* This will be called from proc.c via function pointer */
98 struct net_device *get_dev_lec(int itf)
100 struct net_device *dev;
102 if (itf >= MAX_LEC_ITF)
112 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
113 static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
117 struct lec_priv *priv;
119 /* Check if this is a BPDU. If so, ask zeppelin to send
120 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
121 * as the Config BPDU has */
122 eth = (struct ethhdr *)skb->data;
123 buff = skb->data + skb->dev->hard_header_len;
124 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
125 struct sk_buff *skb2;
126 struct atmlec_msg *mesg;
128 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
129 if (skb2 == NULL) return;
130 skb2->len = sizeof(struct atmlec_msg);
131 mesg = (struct atmlec_msg *)skb2->data;
132 mesg->type = l_topology_change;
134 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
136 priv = (struct lec_priv *)dev->priv;
137 atm_force_charge(priv->lecd, skb2->truesize);
138 skb_queue_tail(&priv->lecd->sk->sk_receive_queue, skb2);
139 priv->lecd->sk->sk_data_ready(priv->lecd->sk, skb2->len);
144 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
147 * Modelled after tr_type_trans
148 * All multicast and ARE or STE frames go to BUS.
149 * Non source routed frames go by destination address.
150 * Last hop source routed frames go by destination address.
151 * Not last hop source routed frames go by _next_ route descriptor.
152 * Returns pointer to destination MAC address or fills in rdesc
156 unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
159 int riflen, num_rdsc;
161 trh = (struct trh_hdr *)packet;
162 if (trh->daddr[0] & (uint8_t)0x80)
163 return bus_mac; /* multicast */
165 if (trh->saddr[0] & TR_RII) {
166 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
167 if ((ntohs(trh->rcf) >> 13) != 0)
168 return bus_mac; /* ARE or STE */
171 return trh->daddr; /* not source routed */
174 return trh->daddr; /* last hop, source routed */
176 /* riflen is 6 or more, packet has more than one route descriptor */
177 num_rdsc = (riflen/2) - 1;
178 memset(rdesc, 0, ETH_ALEN);
179 /* offset 4 comes from LAN destination field in LE control frames */
180 if (trh->rcf & htons((uint16_t)TR_RCF_DIR_BIT))
181 memcpy(&rdesc[4], &trh->rseg[num_rdsc-2], sizeof(uint16_t));
183 memcpy(&rdesc[4], &trh->rseg[1], sizeof(uint16_t));
184 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
189 #endif /* CONFIG_TR */
192 * Open/initialize the netdevice. This is called (in the current kernel)
193 * sometime after booting when the 'ifconfig' program is run.
195 * This routine should set everything up anew at each open, even
196 * registers that "should" only need to be set once at boot, so that
197 * there is non-reboot way to recover if something goes wrong.
201 lec_open(struct net_device *dev)
203 struct lec_priv *priv = (struct lec_priv *)dev->priv;
205 netif_start_queue(dev);
206 memset(&priv->stats,0,sizeof(struct net_device_stats));
211 static __inline__ void
212 lec_send(struct atm_vcc *vcc, struct sk_buff *skb, struct lec_priv *priv)
214 ATM_SKB(skb)->vcc = vcc;
215 ATM_SKB(skb)->atm_options = vcc->atm_options;
217 atomic_add(skb->truesize, &vcc->sk->sk_wmem_alloc);
218 if (vcc->send(vcc, skb) < 0) {
219 priv->stats.tx_dropped++;
223 priv->stats.tx_packets++;
224 priv->stats.tx_bytes += skb->len;
228 lec_tx_timeout(struct net_device *dev)
230 printk(KERN_INFO "%s: tx timeout\n", dev->name);
231 dev->trans_start = jiffies;
232 netif_wake_queue(dev);
236 lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
238 struct sk_buff *skb2;
239 struct lec_priv *priv = (struct lec_priv *)dev->priv;
240 struct lecdatahdr_8023 *lec_h;
242 struct lec_arp_table *entry;
246 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
252 #endif /* DUMP_PACKETS >0 */
254 DPRINTK("lec_start_xmit called\n");
256 printk("%s:No lecd attached\n",dev->name);
257 priv->stats.tx_errors++;
258 netif_stop_queue(dev);
262 DPRINTK("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
263 (long)skb->head, (long)skb->data, (long)skb->tail,
265 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
266 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
267 lec_handle_bridge(skb, dev);
270 /* Make sure we have room for lec_id */
271 if (skb_headroom(skb) < 2) {
273 DPRINTK("lec_start_xmit: reallocating skb\n");
274 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
276 if (skb2 == NULL) return 0;
281 /* Put le header to place, works for TokenRing too */
282 lec_h = (struct lecdatahdr_8023*)skb->data;
283 lec_h->le_header = htons(priv->lecid);
286 /* Ugly. Use this to realign Token Ring packets for
287 * e.g. PCA-200E driver. */
288 if (priv->is_trdev) {
289 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
291 if (skb2 == NULL) return 0;
297 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
298 skb->len, priv->lecid);
299 #if DUMP_PACKETS >= 2
300 for(i=0;i<skb->len && i <99;i++) {
301 sprintf(buf+i*3,"%2.2x ",0xff&skb->data[i]);
303 #elif DUMP_PACKETS >= 1
304 for(i=0;i<skb->len && i < 30;i++) {
305 sprintf(buf+i*3,"%2.2x ", 0xff&skb->data[i]);
307 #endif /* DUMP_PACKETS >= 1 */
311 printk("%s...\n",buf);
312 #endif /* DUMP_PACKETS > 0 */
314 /* Minimum ethernet-frame size */
317 min_frame_size = LEC_MINIMUM_8025_SIZE;
320 min_frame_size = LEC_MINIMUM_8023_SIZE;
321 if (skb->len < min_frame_size) {
322 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
323 skb2 = skb_copy_expand(skb, 0,
324 min_frame_size - skb->truesize, GFP_ATOMIC);
327 priv->stats.tx_dropped++;
332 skb_put(skb, min_frame_size - skb->len);
335 /* Send to right vcc */
339 if (priv->is_trdev) {
340 dst = get_tr_dst(skb->data+2, rdesc);
348 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
349 DPRINTK("%s:vcc:%p vcc_flags:%x, entry:%p\n", dev->name,
350 vcc, vcc?vcc->flags:0, entry);
351 if (!vcc || !test_bit(ATM_VF_READY,&vcc->flags)) {
352 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
353 DPRINTK("%s:lec_start_xmit: queuing packet, ", dev->name);
354 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
355 lec_h->h_dest[0], lec_h->h_dest[1], lec_h->h_dest[2],
356 lec_h->h_dest[3], lec_h->h_dest[4], lec_h->h_dest[5]);
357 skb_queue_tail(&entry->tx_wait, skb);
359 DPRINTK("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ", dev->name);
360 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
361 lec_h->h_dest[0], lec_h->h_dest[1], lec_h->h_dest[2],
362 lec_h->h_dest[3], lec_h->h_dest[4], lec_h->h_dest[5]);
363 priv->stats.tx_dropped++;
370 printk("%s:sending to vpi:%d vci:%d\n", dev->name,
372 #endif /* DUMP_PACKETS > 0 */
374 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
375 DPRINTK("lec.c: emptying tx queue, ");
376 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
377 lec_h->h_dest[0], lec_h->h_dest[1], lec_h->h_dest[2],
378 lec_h->h_dest[3], lec_h->h_dest[4], lec_h->h_dest[5]);
379 lec_send(vcc, skb2, priv);
382 lec_send(vcc, skb, priv);
384 if (!atm_may_send(vcc, 0)) {
385 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
388 netif_stop_queue(dev);
391 * vcc->pop() might have occurred in between, making
392 * the vcc usuable again. Since xmit is serialized,
393 * this is the only situation we have to re-test.
396 if (atm_may_send(vcc, 0))
397 netif_wake_queue(dev);
400 dev->trans_start = jiffies;
404 /* The inverse routine to net_open(). */
406 lec_close(struct net_device *dev)
408 netif_stop_queue(dev);
413 * Get the current statistics.
414 * This may be called with the card open or closed.
416 static struct net_device_stats *
417 lec_get_stats(struct net_device *dev)
419 return &((struct lec_priv *)dev->priv)->stats;
423 lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
426 struct net_device *dev = (struct net_device*)vcc->proto_data;
427 struct lec_priv *priv = (struct lec_priv*)dev->priv;
428 struct atmlec_msg *mesg;
429 struct lec_arp_table *entry;
431 char *tmp; /* FIXME */
433 atomic_sub(skb->truesize, &vcc->sk->sk_wmem_alloc);
434 mesg = (struct atmlec_msg *)skb->data;
436 tmp += sizeof(struct atmlec_msg);
437 DPRINTK("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
441 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
446 dev->dev_addr[i] = 0;
450 lec_addr_delete(priv, mesg->content.normal.atm_addr,
451 mesg->content.normal.flag);
453 case l_topology_change:
454 priv->topology_change = mesg->content.normal.flag;
456 case l_flush_complete:
457 lec_flush_complete(priv, mesg->content.normal.flag);
459 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
460 spin_lock_irqsave(&priv->lec_arp_lock, flags);
461 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
462 lec_arp_remove(priv, entry);
463 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
465 if (mesg->content.normal.no_source_le_narp)
469 lec_arp_update(priv, mesg->content.normal.mac_addr,
470 mesg->content.normal.atm_addr,
471 mesg->content.normal.flag,
472 mesg->content.normal.targetless_le_arp);
473 DPRINTK("lec: in l_arp_update\n");
474 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
475 DPRINTK("lec: LANE2 3.1.5, got tlvs, size %d\n", mesg->sizeoftlvs);
476 lane2_associate_ind(dev,
477 mesg->content.normal.mac_addr,
478 tmp, mesg->sizeoftlvs);
482 priv->maximum_unknown_frame_count =
483 mesg->content.config.maximum_unknown_frame_count;
484 priv->max_unknown_frame_time =
485 (mesg->content.config.max_unknown_frame_time*HZ);
486 priv->max_retry_count =
487 mesg->content.config.max_retry_count;
488 priv->aging_time = (mesg->content.config.aging_time*HZ);
489 priv->forward_delay_time =
490 (mesg->content.config.forward_delay_time*HZ);
491 priv->arp_response_time =
492 (mesg->content.config.arp_response_time*HZ);
493 priv->flush_timeout = (mesg->content.config.flush_timeout*HZ);
494 priv->path_switching_delay =
495 (mesg->content.config.path_switching_delay*HZ);
496 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
497 priv->lane2_ops = NULL;
498 if (priv->lane_version > 1)
499 priv->lane2_ops = &lane2_ops;
500 if (dev->change_mtu(dev, mesg->content.config.mtu))
501 printk("%s: change_mtu to %d failed\n", dev->name,
502 mesg->content.config.mtu);
503 priv->is_proxy = mesg->content.config.is_proxy;
505 case l_flush_tran_id:
506 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
507 mesg->content.normal.flag);
510 priv->lecid=(unsigned short)(0xffff&mesg->content.normal.flag);
512 case l_should_bridge: {
513 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
514 struct net_bridge_fdb_entry *f;
516 DPRINTK("%s: bridge zeppelin asks about 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
518 mesg->content.proxy.mac_addr[0], mesg->content.proxy.mac_addr[1],
519 mesg->content.proxy.mac_addr[2], mesg->content.proxy.mac_addr[3],
520 mesg->content.proxy.mac_addr[4], mesg->content.proxy.mac_addr[5]);
522 if (br_fdb_get_hook == NULL || dev->br_port == NULL)
525 f = br_fdb_get_hook(dev->br_port->br, mesg->content.proxy.mac_addr);
527 f->dst->dev != dev &&
528 f->dst->state == BR_STATE_FORWARDING) {
529 /* hit from bridge table, send LE_ARP_RESPONSE */
530 struct sk_buff *skb2;
532 DPRINTK("%s: entry found, responding to zeppelin\n", dev->name);
533 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
538 skb2->len = sizeof(struct atmlec_msg);
539 memcpy(skb2->data, mesg, sizeof(struct atmlec_msg));
540 atm_force_charge(priv->lecd, skb2->truesize);
541 skb_queue_tail(&priv->lecd->sk->sk_receive_queue, skb2);
542 priv->lecd->sk->sk_data_ready(priv->lecd->sk, skb2->len);
544 if (f != NULL) br_fdb_put_hook(f);
545 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
549 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
558 lec_atm_close(struct atm_vcc *vcc)
561 struct net_device *dev = (struct net_device *)vcc->proto_data;
562 struct lec_priv *priv = (struct lec_priv *)dev->priv;
565 /* Do something needful? */
567 netif_stop_queue(dev);
568 lec_arp_destroy(priv);
570 if (skb_peek(&vcc->sk->sk_receive_queue))
571 printk("%s lec_atm_close: closing with messages pending\n",
573 while ((skb = skb_dequeue(&vcc->sk->sk_receive_queue)) != NULL) {
574 atm_return(vcc, skb->truesize);
578 printk("%s: Shut down!\n", dev->name);
579 module_put(THIS_MODULE);
582 static struct atmdev_ops lecdev_ops = {
583 .close = lec_atm_close,
587 static struct atm_dev lecatm_dev = {
590 .number = 999, /* dummy device number */
591 .lock = SPIN_LOCK_UNLOCKED
595 * LANE2: new argument struct sk_buff *data contains
596 * the LE_ARP based TLVs introduced in the LANE2 spec
599 send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
600 unsigned char *mac_addr, unsigned char *atm_addr,
601 struct sk_buff *data)
604 struct atmlec_msg *mesg;
606 if (!priv || !priv->lecd) {
609 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
612 skb->len = sizeof(struct atmlec_msg);
613 mesg = (struct atmlec_msg *)skb->data;
614 memset(mesg, 0, sizeof(struct atmlec_msg));
617 mesg->sizeoftlvs = data->len;
619 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
621 mesg->content.normal.targetless_le_arp = 1;
623 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
625 atm_force_charge(priv->lecd, skb->truesize);
626 skb_queue_tail(&priv->lecd->sk->sk_receive_queue, skb);
627 priv->lecd->sk->sk_data_ready(priv->lecd->sk, skb->len);
630 DPRINTK("lec: about to send %d bytes of data\n", data->len);
631 atm_force_charge(priv->lecd, data->truesize);
632 skb_queue_tail(&priv->lecd->sk->sk_receive_queue, data);
633 priv->lecd->sk->sk_data_ready(priv->lecd->sk, skb->len);
639 /* shamelessly stolen from drivers/net/net_init.c */
640 static int lec_change_mtu(struct net_device *dev, int new_mtu)
642 if ((new_mtu < 68) || (new_mtu > 18190))
648 static void lec_set_multicast_list(struct net_device *dev)
650 /* by default, all multicast frames arrive over the bus.
651 * eventually support selective multicast service
657 lec_init(struct net_device *dev)
659 dev->change_mtu = lec_change_mtu;
660 dev->open = lec_open;
661 dev->stop = lec_close;
662 dev->hard_start_xmit = lec_start_xmit;
663 dev->tx_timeout = lec_tx_timeout;
665 dev->get_stats = lec_get_stats;
666 dev->set_multicast_list = lec_set_multicast_list;
667 dev->do_ioctl = NULL;
668 printk("%s: Initialized!\n",dev->name);
672 static unsigned char lec_ctrl_magic[] = {
679 lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
681 struct net_device *dev = (struct net_device *)vcc->proto_data;
682 struct lec_priv *priv = (struct lec_priv *)dev->priv;
688 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
692 DPRINTK("%s: null skb\n",dev->name);
693 lec_vcc_close(priv, vcc);
697 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
698 skb->len, priv->lecid);
699 #if DUMP_PACKETS >= 2
700 for(i=0;i<skb->len && i <99;i++) {
701 sprintf(buf+i*3,"%2.2x ",0xff&skb->data[i]);
703 #elif DUMP_PACKETS >= 1
704 for(i=0;i<skb->len && i < 30;i++) {
705 sprintf(buf+i*3,"%2.2x ", 0xff&skb->data[i]);
707 #endif /* DUMP_PACKETS >= 1 */
711 printk("%s...\n",buf);
712 #endif /* DUMP_PACKETS > 0 */
713 if (memcmp(skb->data, lec_ctrl_magic, 4) ==0) { /* Control frame, to daemon*/
714 DPRINTK("%s: To daemon\n",dev->name);
715 skb_queue_tail(&vcc->sk->sk_receive_queue, skb);
716 vcc->sk->sk_data_ready(vcc->sk, skb->len);
717 } else { /* Data frame, queue to protocol handlers */
720 atm_return(vcc,skb->truesize);
721 if (*(uint16_t *)skb->data == htons(priv->lecid) ||
723 !(dev->flags & IFF_UP)) {
724 /* Probably looping back, or if lecd is missing,
725 lecd has gone down */
726 DPRINTK("Ignoring frame...\n");
731 if (priv->is_trdev) dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
734 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
736 if (!(dst[0]&0x01) && /* Never filter Multi/Broadcast */
737 !priv->is_proxy && /* Proxy wants all the packets */
738 memcmp(dst, dev->dev_addr, dev->addr_len)) {
742 if (priv->lec_arp_empty_ones) {
743 lec_arp_check_empties(priv, vcc, skb);
746 skb_pull(skb, 2); /* skip lec_id */
748 if (priv->is_trdev) skb->protocol = tr_type_trans(skb, dev);
751 skb->protocol = eth_type_trans(skb, dev);
752 priv->stats.rx_packets++;
753 priv->stats.rx_bytes += skb->len;
754 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
760 lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
762 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
763 struct net_device *dev = skb->dev;
766 printk("lec_pop(): vpriv = NULL!?!?!?\n");
770 vpriv->old_pop(vcc, skb);
772 if (vpriv->xoff && atm_may_send(vcc, 0)) {
774 if (netif_running(dev) && netif_queue_stopped(dev))
775 netif_wake_queue(dev);
780 lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
782 struct lec_vcc_priv *vpriv;
784 struct atmlec_ioc ioc_data;
786 /* Lecd must be up in this case */
787 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
788 if (bytes_left != 0) {
789 printk("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
792 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
793 !dev_lec[ioc_data.dev_num])
795 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
798 vpriv->old_pop = vcc->pop;
799 vcc->user_back = vpriv;
801 lec_vcc_added(dev_lec[ioc_data.dev_num]->priv,
802 &ioc_data, vcc, vcc->push);
803 vcc->proto_data = dev_lec[ioc_data.dev_num];
804 vcc->push = lec_push;
809 lec_mcast_attach(struct atm_vcc *vcc, int arg)
811 if (arg <0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
813 vcc->proto_data = dev_lec[arg];
814 return (lec_mcast_make((struct lec_priv*)dev_lec[arg]->priv, vcc));
817 /* Initialize device. */
819 lecd_attach(struct atm_vcc *vcc, int arg)
822 struct lec_priv *priv;
829 if (arg >= MAX_LEC_ITF)
831 #else /* Reserve the top NUM_TR_DEVS for TR */
832 if (arg >= (MAX_LEC_ITF-NUM_TR_DEVS))
839 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
842 size = sizeof(struct lec_priv);
845 dev_lec[i] = alloc_trdev(size);
848 dev_lec[i] = alloc_etherdev(size);
851 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
852 if (register_netdev(dev_lec[i])) {
853 free_netdev(dev_lec[i]);
857 priv = dev_lec[i]->priv;
858 priv->is_trdev = is_trdev;
859 lec_init(dev_lec[i]);
861 priv = dev_lec[i]->priv;
866 priv->itfnum = i; /* LANE2 addition */
868 vcc->dev = &lecatm_dev;
869 vcc_insert_socket(vcc->sk);
871 vcc->proto_data = dev_lec[i];
872 set_bit(ATM_VF_META,&vcc->flags);
873 set_bit(ATM_VF_READY,&vcc->flags);
875 /* Set default values to these variables */
876 priv->maximum_unknown_frame_count = 1;
877 priv->max_unknown_frame_time = (1*HZ);
878 priv->vcc_timeout_period = (1200*HZ);
879 priv->max_retry_count = 1;
880 priv->aging_time = (300*HZ);
881 priv->forward_delay_time = (15*HZ);
882 priv->topology_change = 0;
883 priv->arp_response_time = (1*HZ);
884 priv->flush_timeout = (4*HZ);
885 priv->path_switching_delay = (6*HZ);
887 if (dev_lec[i]->flags & IFF_UP) {
888 netif_start_queue(dev_lec[i]);
890 __module_get(THIS_MODULE);
894 #ifdef CONFIG_PROC_FS
895 static char* lec_arp_get_status_string(unsigned char status)
897 static char *lec_arp_status_string[] = {
902 "ESI_FLUSH_PENDING ",
906 if (status > ESI_FORWARD_DIRECT)
907 status = 3; /* ESI_UNDEFINED */
908 return lec_arp_status_string[status];
911 static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
915 for (i = 0; i < ETH_ALEN; i++)
916 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
917 seq_printf(seq, " ");
918 for (i = 0; i < ATM_ESA_LEN; i++)
919 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
920 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
921 entry->flags & 0xffff);
923 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
925 seq_printf(seq, " ");
926 if (entry->recv_vcc) {
927 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
928 entry->recv_vcc->vci);
936 struct lec_priv *locked;
937 struct lec_arp_table *entry;
938 struct net_device *dev;
944 static void *lec_tbl_walk(struct lec_state *state, struct lec_arp_table *tbl,
947 struct lec_arp_table *e = state->entry;
951 if (e == (void *)1) {
955 for (; e; e = e->next) {
960 return (*l < 0) ? state : NULL;
963 static void *lec_arp_walk(struct lec_state *state, loff_t *l,
964 struct lec_priv *priv)
969 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
970 v = lec_tbl_walk(state, priv->lec_arp_tables[p], l);
974 state->arp_table = p;
978 static void *lec_misc_walk(struct lec_state *state, loff_t *l,
979 struct lec_priv *priv)
981 struct lec_arp_table *lec_misc_tables[] = {
982 priv->lec_arp_empty_ones,
983 priv->lec_no_forward,
989 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
990 v = lec_tbl_walk(state, lec_misc_tables[q], l);
994 state->misc_table = q;
998 static void *lec_priv_walk(struct lec_state *state, loff_t *l,
999 struct lec_priv *priv)
1001 if (!state->locked) {
1002 state->locked = priv;
1003 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1005 if (!lec_arp_walk(state, l, priv) &&
1006 !lec_misc_walk(state, l, priv)) {
1007 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1008 state->locked = NULL;
1009 /* Partial state reset for the next time we get called */
1010 state->arp_table = state->misc_table = 0;
1012 return state->locked;
1015 static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1017 struct net_device *dev;
1020 dev = state->dev ? state->dev : dev_lec[state->itf];
1021 v = (dev && dev->priv) ? lec_priv_walk(state, l, dev->priv) : NULL;
1024 /* Partial state reset for the next time we get called */
1031 static void *lec_get_idx(struct lec_state *state, loff_t l)
1035 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1036 v = lec_itf_walk(state, &l);
1043 static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1045 struct lec_state *state = seq->private;
1049 state->locked = NULL;
1050 state->arp_table = 0;
1051 state->misc_table = 0;
1052 state->entry = (void *)1;
1054 return *pos ? lec_get_idx(state, *pos) : (void*)1;
1057 static void lec_seq_stop(struct seq_file *seq, void *v)
1059 struct lec_state *state = seq->private;
1062 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1064 dev_put(state->dev);
1068 static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1070 struct lec_state *state = seq->private;
1072 v = lec_get_idx(state, 1);
1073 *pos += !!PTR_ERR(v);
1077 static int lec_seq_show(struct seq_file *seq, void *v)
1079 static char lec_banner[] = "Itf MAC ATM destination"
1081 "VPI/VCI Recv VPI/VCI\n";
1084 seq_puts(seq, lec_banner);
1086 struct lec_state *state = seq->private;
1087 struct net_device *dev = state->dev;
1089 seq_printf(seq, "%s ", dev->name);
1090 lec_info(seq, state->entry);
1095 static struct seq_operations lec_seq_ops = {
1096 .start = lec_seq_start,
1097 .next = lec_seq_next,
1098 .stop = lec_seq_stop,
1099 .show = lec_seq_show,
1102 static int lec_seq_open(struct inode *inode, struct file *file)
1104 struct lec_state *state;
1105 struct seq_file *seq;
1108 state = kmalloc(sizeof(*state), GFP_KERNEL);
1114 rc = seq_open(file, &lec_seq_ops);
1117 seq = file->private_data;
1118 seq->private = state;
1127 static int lec_seq_release(struct inode *inode, struct file *file)
1129 return seq_release_private(inode, file);
1132 static struct file_operations lec_seq_fops = {
1133 .owner = THIS_MODULE,
1134 .open = lec_seq_open,
1136 .llseek = seq_lseek,
1137 .release = lec_seq_release,
1141 static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1143 struct atm_vcc *vcc = ATM_SD(sock);
1150 if (!capable(CAP_NET_ADMIN))
1154 return -ENOIOCTLCMD;
1159 err = lecd_attach(vcc, (int) arg);
1161 sock->state = SS_CONNECTED;
1164 err = lec_mcast_attach(vcc, (int) arg);
1167 err = lec_vcc_attach(vcc, (void __user *) arg);
1174 static struct atm_ioctl lane_ioctl_ops = {
1175 .owner = THIS_MODULE,
1176 .ioctl = lane_ioctl,
1179 static int __init lane_module_init(void)
1181 #ifdef CONFIG_PROC_FS
1182 struct proc_dir_entry *p;
1184 p = create_proc_entry("lec", S_IRUGO, atm_proc_root);
1186 p->proc_fops = &lec_seq_fops;
1189 register_atm_ioctl(&lane_ioctl_ops);
1190 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1194 static void __exit lane_module_cleanup(void)
1197 struct lec_priv *priv;
1199 remove_proc_entry("lec", atm_proc_root);
1201 deregister_atm_ioctl(&lane_ioctl_ops);
1203 for (i = 0; i < MAX_LEC_ITF; i++) {
1204 if (dev_lec[i] != NULL) {
1205 priv = (struct lec_priv *)dev_lec[i]->priv;
1206 unregister_netdev(dev_lec[i]);
1207 free_netdev(dev_lec[i]);
1215 module_init(lane_module_init);
1216 module_exit(lane_module_cleanup);
1219 * LANE2: 3.1.3, LE_RESOLVE.request
1220 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1221 * If sizeoftlvs == NULL the default TLVs associated with with this
1223 * If dst_mac == NULL, targetless LE_ARP will be sent
1225 static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
1226 u8 **tlvs, u32 *sizeoftlvs)
1228 unsigned long flags;
1229 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1230 struct lec_arp_table *table;
1231 struct sk_buff *skb;
1235 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1236 table = lec_arp_find(priv, dst_mac);
1237 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1241 *tlvs = kmalloc(table->sizeoftlvs, GFP_ATOMIC);
1245 memcpy(*tlvs, table->tlvs, table->sizeoftlvs);
1246 *sizeoftlvs = table->sizeoftlvs;
1251 if (sizeoftlvs == NULL)
1252 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
1255 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1258 skb->len = *sizeoftlvs;
1259 memcpy(skb->data, *tlvs, *sizeoftlvs);
1260 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1267 * LANE2: 3.1.4, LE_ASSOCIATE.request
1268 * Associate the *tlvs with the *lan_dst address.
1269 * Will overwrite any previous association
1270 * Returns 1 for success, 0 for failure (out of memory)
1273 static int lane2_associate_req (struct net_device *dev, u8 *lan_dst,
1274 u8 *tlvs, u32 sizeoftlvs)
1277 struct sk_buff *skb;
1278 struct lec_priv *priv = (struct lec_priv*)dev->priv;
1280 if ( memcmp(lan_dst, dev->dev_addr, ETH_ALEN) != 0 )
1281 return (0); /* not our mac address */
1283 kfree(priv->tlvs); /* NULL if there was no previous association */
1285 priv->tlvs = kmalloc(sizeoftlvs, GFP_KERNEL);
1286 if (priv->tlvs == NULL)
1288 priv->sizeoftlvs = sizeoftlvs;
1289 memcpy(priv->tlvs, tlvs, sizeoftlvs);
1291 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1294 skb->len = sizeoftlvs;
1295 memcpy(skb->data, tlvs, sizeoftlvs);
1296 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1298 printk("lec.c: lane2_associate_req() failed\n");
1299 /* If the previous association has changed we must
1300 * somehow notify other LANE entities about the change
1306 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1309 static void lane2_associate_ind (struct net_device *dev, u8 *mac_addr,
1310 u8 *tlvs, u32 sizeoftlvs)
1315 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1316 #if 0 /* Why have the TLVs in LE_ARP entries since we do not use them? When you
1317 uncomment this code, make sure the TLVs get freed when entry is killed */
1318 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
1321 return; /* should not happen */
1325 entry->tlvs = kmalloc(sizeoftlvs, GFP_KERNEL);
1326 if (entry->tlvs == NULL)
1329 entry->sizeoftlvs = sizeoftlvs;
1330 memcpy(entry->tlvs, tlvs, sizeoftlvs);
1333 printk("lec.c: lane2_associate_ind()\n");
1334 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1335 while (i < sizeoftlvs)
1336 printk("%02x ", tlvs[i++]);
1341 /* tell MPOA about the TLVs we saw */
1342 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1343 priv->lane2_ops->associate_indicator(dev, mac_addr,
1350 * Here starts what used to lec_arpc.c
1352 * lec_arpc.c was added here when making
1353 * lane client modular. October 1997
1357 #include <linux/types.h>
1358 #include <linux/sched.h>
1359 #include <linux/timer.h>
1360 #include <asm/param.h>
1361 #include <asm/atomic.h>
1362 #include <linux/inetdevice.h>
1363 #include <net/route.h>
1367 #define DPRINTK(format,args...)
1369 #define DPRINTK printk
1372 #define DEBUG_ARP_TABLE 0
1374 #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1376 static void lec_arp_check_expire(unsigned long data);
1377 static void lec_arp_expire_arp(unsigned long data);
1378 void dump_arp_table(struct lec_priv *priv);
1384 #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1387 * Initialization of arp-cache
1390 lec_arp_init(struct lec_priv *priv)
1394 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1395 priv->lec_arp_tables[i] = NULL;
1397 spin_lock_init(&priv->lec_arp_lock);
1398 init_timer(&priv->lec_arp_timer);
1399 priv->lec_arp_timer.expires = jiffies + LEC_ARP_REFRESH_INTERVAL;
1400 priv->lec_arp_timer.data = (unsigned long)priv;
1401 priv->lec_arp_timer.function = lec_arp_check_expire;
1402 add_timer(&priv->lec_arp_timer);
1406 lec_arp_clear_vccs(struct lec_arp_table *entry)
1409 struct atm_vcc *vcc = entry->vcc;
1410 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
1411 struct net_device *dev = (struct net_device*) vcc->proto_data;
1413 vcc->pop = vpriv->old_pop;
1415 netif_wake_queue(dev);
1417 vcc->user_back = NULL;
1418 vcc->push = entry->old_push;
1419 vcc_release_async(vcc, -EPIPE);
1422 if (entry->recv_vcc) {
1423 entry->recv_vcc->push = entry->old_recv_push;
1424 vcc_release_async(entry->recv_vcc, -EPIPE);
1425 entry->recv_vcc = NULL;
1430 * Insert entry to lec_arp_table
1431 * LANE2: Add to the end of the list to satisfy 8.1.13
1434 lec_arp_add(struct lec_priv *priv, struct lec_arp_table *to_add)
1436 unsigned short place;
1437 struct lec_arp_table *tmp;
1439 place = HASH(to_add->mac_addr[ETH_ALEN-1]);
1440 tmp = priv->lec_arp_tables[place];
1441 to_add->next = NULL;
1443 priv->lec_arp_tables[place] = to_add;
1445 else { /* add to the end */
1451 DPRINTK("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1452 0xff&to_add->mac_addr[0], 0xff&to_add->mac_addr[1],
1453 0xff&to_add->mac_addr[2], 0xff&to_add->mac_addr[3],
1454 0xff&to_add->mac_addr[4], 0xff&to_add->mac_addr[5]);
1458 * Remove entry from lec_arp_table
1461 lec_arp_remove(struct lec_priv *priv,
1462 struct lec_arp_table *to_remove)
1464 unsigned short place;
1465 struct lec_arp_table *tmp;
1471 place = HASH(to_remove->mac_addr[ETH_ALEN-1]);
1472 tmp = priv->lec_arp_tables[place];
1473 if (tmp == to_remove) {
1474 priv->lec_arp_tables[place] = tmp->next;
1476 while(tmp && tmp->next != to_remove) {
1479 if (!tmp) {/* Entry was not found */
1483 tmp->next = to_remove->next;
1484 del_timer(&to_remove->timer);
1486 /* If this is the only MAC connected to this VCC, also tear down
1488 if (to_remove->status >= ESI_FLUSH_PENDING) {
1490 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1492 for(place = 0; place < LEC_ARP_TABLE_SIZE; place++) {
1493 for(tmp = priv->lec_arp_tables[place]; tmp != NULL; tmp = tmp->next) {
1494 if (memcmp(tmp->atm_addr, to_remove->atm_addr,
1502 lec_arp_clear_vccs(to_remove);
1504 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1506 DPRINTK("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1507 0xff&to_remove->mac_addr[0], 0xff&to_remove->mac_addr[1],
1508 0xff&to_remove->mac_addr[2], 0xff&to_remove->mac_addr[3],
1509 0xff&to_remove->mac_addr[4], 0xff&to_remove->mac_addr[5]);
1515 get_status_string(unsigned char st)
1519 return "ESI_UNKNOWN";
1520 case ESI_ARP_PENDING:
1521 return "ESI_ARP_PENDING";
1522 case ESI_VC_PENDING:
1523 return "ESI_VC_PENDING";
1524 case ESI_FLUSH_PENDING:
1525 return "ESI_FLUSH_PENDING";
1526 case ESI_FORWARD_DIRECT:
1527 return "ESI_FORWARD_DIRECT";
1535 dump_arp_table(struct lec_priv *priv)
1539 struct lec_arp_table *rulla;
1541 struct lec_arp_table **lec_arp_tables =
1542 (struct lec_arp_table **)priv->lec_arp_tables;
1543 struct lec_arp_table *lec_arp_empty_ones =
1544 (struct lec_arp_table *)priv->lec_arp_empty_ones;
1545 struct lec_arp_table *lec_no_forward =
1546 (struct lec_arp_table *)priv->lec_no_forward;
1547 struct lec_arp_table *mcast_fwds = priv->mcast_fwds;
1550 printk("Dump %p:\n",priv);
1551 for (i=0;i<LEC_ARP_TABLE_SIZE;i++) {
1552 rulla = lec_arp_tables[i];
1554 offset += sprintf(buf,"%d: %p\n",i, rulla);
1556 offset += sprintf(buf+offset,"Mac:");
1557 for(j=0;j<ETH_ALEN;j++) {
1558 offset+=sprintf(buf+offset,
1560 rulla->mac_addr[j]&0xff);
1562 offset +=sprintf(buf+offset,"Atm:");
1563 for(j=0;j<ATM_ESA_LEN;j++) {
1564 offset+=sprintf(buf+offset,
1566 rulla->atm_addr[j]&0xff);
1568 offset+=sprintf(buf+offset,
1569 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1570 rulla->vcc?rulla->vcc->vpi:0,
1571 rulla->vcc?rulla->vcc->vci:0,
1572 rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1573 rulla->recv_vcc?rulla->recv_vcc->vci:0,
1575 rulla->timestamp, rulla->no_tries);
1576 offset+=sprintf(buf+offset,
1577 "Flags:%x, Packets_flooded:%x, Status: %s ",
1578 rulla->flags, rulla->packets_flooded,
1579 get_status_string(rulla->status));
1580 offset+=sprintf(buf+offset,"->%p\n",rulla->next);
1581 rulla = rulla->next;
1585 rulla = lec_no_forward;
1587 printk("No forward\n");
1590 offset += sprintf(buf+offset,"Mac:");
1591 for(j=0;j<ETH_ALEN;j++) {
1592 offset+=sprintf(buf+offset,"%2.2x ",
1593 rulla->mac_addr[j]&0xff);
1595 offset +=sprintf(buf+offset,"Atm:");
1596 for(j=0;j<ATM_ESA_LEN;j++) {
1597 offset+=sprintf(buf+offset,"%2.2x ",
1598 rulla->atm_addr[j]&0xff);
1600 offset+=sprintf(buf+offset,
1601 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1602 rulla->vcc?rulla->vcc->vpi:0,
1603 rulla->vcc?rulla->vcc->vci:0,
1604 rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1605 rulla->recv_vcc?rulla->recv_vcc->vci:0,
1607 rulla->timestamp, rulla->no_tries);
1608 offset+=sprintf(buf+offset,
1609 "Flags:%x, Packets_flooded:%x, Status: %s ",
1610 rulla->flags, rulla->packets_flooded,
1611 get_status_string(rulla->status));
1612 offset+=sprintf(buf+offset,"->%lx\n",(long)rulla->next);
1613 rulla = rulla->next;
1616 rulla = lec_arp_empty_ones;
1618 printk("Empty ones\n");
1621 offset += sprintf(buf+offset,"Mac:");
1622 for(j=0;j<ETH_ALEN;j++) {
1623 offset+=sprintf(buf+offset,"%2.2x ",
1624 rulla->mac_addr[j]&0xff);
1626 offset +=sprintf(buf+offset,"Atm:");
1627 for(j=0;j<ATM_ESA_LEN;j++) {
1628 offset+=sprintf(buf+offset,"%2.2x ",
1629 rulla->atm_addr[j]&0xff);
1631 offset+=sprintf(buf+offset,
1632 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1633 rulla->vcc?rulla->vcc->vpi:0,
1634 rulla->vcc?rulla->vcc->vci:0,
1635 rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1636 rulla->recv_vcc?rulla->recv_vcc->vci:0,
1638 rulla->timestamp, rulla->no_tries);
1639 offset+=sprintf(buf+offset,
1640 "Flags:%x, Packets_flooded:%x, Status: %s ",
1641 rulla->flags, rulla->packets_flooded,
1642 get_status_string(rulla->status));
1643 offset+=sprintf(buf+offset,"->%lx\n",(long)rulla->next);
1644 rulla = rulla->next;
1650 printk("Multicast Forward VCCs\n");
1653 offset += sprintf(buf+offset,"Mac:");
1654 for(j=0;j<ETH_ALEN;j++) {
1655 offset+=sprintf(buf+offset,"%2.2x ",
1656 rulla->mac_addr[j]&0xff);
1658 offset +=sprintf(buf+offset,"Atm:");
1659 for(j=0;j<ATM_ESA_LEN;j++) {
1660 offset+=sprintf(buf+offset,"%2.2x ",
1661 rulla->atm_addr[j]&0xff);
1663 offset+=sprintf(buf+offset,
1664 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1665 rulla->vcc?rulla->vcc->vpi:0,
1666 rulla->vcc?rulla->vcc->vci:0,
1667 rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1668 rulla->recv_vcc?rulla->recv_vcc->vci:0,
1670 rulla->timestamp, rulla->no_tries);
1671 offset+=sprintf(buf+offset,
1672 "Flags:%x, Packets_flooded:%x, Status: %s ",
1673 rulla->flags, rulla->packets_flooded,
1674 get_status_string(rulla->status));
1675 offset+=sprintf(buf+offset,"->%lx\n",(long)rulla->next);
1676 rulla = rulla->next;
1684 * Destruction of arp-cache
1687 lec_arp_destroy(struct lec_priv *priv)
1689 unsigned long flags;
1690 struct lec_arp_table *entry, *next;
1693 del_timer_sync(&priv->lec_arp_timer);
1696 * Remove all entries
1699 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1700 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1701 for(entry = priv->lec_arp_tables[i]; entry != NULL; entry=next) {
1703 lec_arp_remove(priv, entry);
1707 entry = priv->lec_arp_empty_ones;
1710 del_timer_sync(&entry->timer);
1711 lec_arp_clear_vccs(entry);
1715 priv->lec_arp_empty_ones = NULL;
1716 entry = priv->lec_no_forward;
1719 del_timer_sync(&entry->timer);
1720 lec_arp_clear_vccs(entry);
1724 priv->lec_no_forward = NULL;
1725 entry = priv->mcast_fwds;
1728 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1729 lec_arp_clear_vccs(entry);
1733 priv->mcast_fwds = NULL;
1734 priv->mcast_vcc = NULL;
1735 memset(priv->lec_arp_tables, 0,
1736 sizeof(struct lec_arp_table *) * LEC_ARP_TABLE_SIZE);
1737 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1742 * Find entry by mac_address
1744 static struct lec_arp_table*
1745 lec_arp_find(struct lec_priv *priv,
1746 unsigned char *mac_addr)
1748 unsigned short place;
1749 struct lec_arp_table *to_return;
1751 DPRINTK("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1752 mac_addr[0]&0xff, mac_addr[1]&0xff, mac_addr[2]&0xff,
1753 mac_addr[3]&0xff, mac_addr[4]&0xff, mac_addr[5]&0xff);
1754 place = HASH(mac_addr[ETH_ALEN-1]);
1756 to_return = priv->lec_arp_tables[place];
1758 if (memcmp(mac_addr, to_return->mac_addr, ETH_ALEN) == 0) {
1761 to_return = to_return->next;
1766 static struct lec_arp_table*
1767 make_entry(struct lec_priv *priv, unsigned char *mac_addr)
1769 struct lec_arp_table *to_return;
1771 to_return = (struct lec_arp_table *) kmalloc(sizeof(struct lec_arp_table),
1774 printk("LEC: Arp entry kmalloc failed\n");
1777 memset(to_return, 0, sizeof(struct lec_arp_table));
1778 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
1779 init_timer(&to_return->timer);
1780 to_return->timer.function = lec_arp_expire_arp;
1781 to_return->timer.data = (unsigned long) to_return;
1782 to_return->last_used = jiffies;
1783 to_return->priv = priv;
1784 skb_queue_head_init(&to_return->tx_wait);
1790 * Arp sent timer expired
1794 lec_arp_expire_arp(unsigned long data)
1796 struct lec_arp_table *entry;
1798 entry = (struct lec_arp_table *)data;
1800 DPRINTK("lec_arp_expire_arp\n");
1801 if (entry->status == ESI_ARP_PENDING) {
1802 if (entry->no_tries <= entry->priv->max_retry_count) {
1803 if (entry->is_rdesc)
1804 send_to_lecd(entry->priv, l_rdesc_arp_xmt, entry->mac_addr, NULL, NULL);
1806 send_to_lecd(entry->priv, l_arp_xmt, entry->mac_addr, NULL, NULL);
1809 mod_timer(&entry->timer, jiffies + (1*HZ));
1815 * Unknown/unused vcc expire, remove associated entry
1819 lec_arp_expire_vcc(unsigned long data)
1821 unsigned long flags;
1822 struct lec_arp_table *to_remove = (struct lec_arp_table*)data;
1823 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
1824 struct lec_arp_table *entry = NULL;
1826 del_timer(&to_remove->timer);
1828 DPRINTK("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1830 to_remove->vcc?to_remove->recv_vcc->vpi:0,
1831 to_remove->vcc?to_remove->recv_vcc->vci:0);
1832 DPRINTK("eo:%p nf:%p\n",priv->lec_arp_empty_ones,priv->lec_no_forward);
1834 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1835 if (to_remove == priv->lec_arp_empty_ones)
1836 priv->lec_arp_empty_ones = to_remove->next;
1838 entry = priv->lec_arp_empty_ones;
1839 while (entry && entry->next != to_remove)
1840 entry = entry->next;
1842 entry->next = to_remove->next;
1845 if (to_remove == priv->lec_no_forward) {
1846 priv->lec_no_forward = to_remove->next;
1848 entry = priv->lec_no_forward;
1849 while (entry && entry->next != to_remove)
1850 entry = entry->next;
1852 entry->next = to_remove->next;
1855 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1857 lec_arp_clear_vccs(to_remove);
1864 * 2. For each entry, delete entries that have aged past the age limit.
1865 * 3. For each entry, depending on the status of the entry, perform
1866 * the following maintenance.
1867 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1868 * tick_count is above the max_unknown_frame_time, clear
1869 * the tick_count to zero and clear the packets_flooded counter
1870 * to zero. This supports the packet rate limit per address
1871 * while flooding unknowns.
1872 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1873 * than or equal to the path_switching_delay, change the status
1874 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1875 * regardless of the progress of the flush protocol.
1878 lec_arp_check_expire(unsigned long data)
1880 unsigned long flags;
1881 struct lec_priv *priv = (struct lec_priv *)data;
1882 struct lec_arp_table *entry, *next;
1884 unsigned long time_to_check;
1887 DPRINTK("lec_arp_check_expire %p\n",priv);
1888 DPRINTK("expire: eo:%p nf:%p\n",priv->lec_arp_empty_ones,
1889 priv->lec_no_forward);
1891 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1892 for(i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1893 for(entry = priv->lec_arp_tables[i]; entry != NULL; ) {
1894 if ((entry->flags) & LEC_REMOTE_FLAG &&
1895 priv->topology_change)
1896 time_to_check = priv->forward_delay_time;
1898 time_to_check = priv->aging_time;
1900 DPRINTK("About to expire: %lx - %lx > %lx\n",
1901 now,entry->last_used, time_to_check);
1902 if( time_after(now, entry->last_used+
1904 !(entry->flags & LEC_PERMANENT_FLAG) &&
1905 !(entry->mac_addr[0] & 0x01) ) { /* LANE2: 7.1.20 */
1907 DPRINTK("LEC:Entry timed out\n");
1909 lec_arp_remove(priv, entry);
1913 /* Something else */
1914 if ((entry->status == ESI_VC_PENDING ||
1915 entry->status == ESI_ARP_PENDING)
1916 && time_after_eq(now,
1918 priv->max_unknown_frame_time)) {
1919 entry->timestamp = jiffies;
1920 entry->packets_flooded = 0;
1921 if (entry->status == ESI_VC_PENDING)
1922 send_to_lecd(priv, l_svc_setup, entry->mac_addr, entry->atm_addr, NULL);
1924 if (entry->status == ESI_FLUSH_PENDING
1926 time_after_eq(now, entry->timestamp+
1927 priv->path_switching_delay)) {
1928 struct sk_buff *skb;
1930 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
1931 lec_send(entry->vcc, skb, entry->priv);
1932 entry->last_used = jiffies;
1936 entry = entry->next;
1940 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1942 mod_timer(&priv->lec_arp_timer, jiffies + LEC_ARP_REFRESH_INTERVAL);
1945 * Try to find vcc where mac_address is attached.
1949 lec_arp_resolve(struct lec_priv *priv, unsigned char *mac_to_find, int is_rdesc,
1950 struct lec_arp_table **ret_entry)
1952 unsigned long flags;
1953 struct lec_arp_table *entry;
1954 struct atm_vcc *found;
1956 if (mac_to_find[0] & 0x01) {
1957 switch (priv->lane_version) {
1959 return priv->mcast_vcc;
1961 case 2: /* LANE2 wants arp for multicast addresses */
1962 if ( memcmp(mac_to_find, bus_mac, ETH_ALEN) == 0)
1963 return priv->mcast_vcc;
1970 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1971 entry = lec_arp_find(priv, mac_to_find);
1974 if (entry->status == ESI_FORWARD_DIRECT) {
1976 entry->last_used = jiffies;
1981 /* Data direct VC not yet set up, check to see if the unknown
1982 frame count is greater than the limit. If the limit has
1983 not been reached, allow the caller to send packet to
1985 if (entry->status != ESI_FLUSH_PENDING &&
1986 entry->packets_flooded<priv->maximum_unknown_frame_count) {
1987 entry->packets_flooded++;
1988 DPRINTK("LEC_ARP: Flooding..\n");
1989 found = priv->mcast_vcc;
1992 /* We got here because entry->status == ESI_FLUSH_PENDING
1993 * or BUS flood limit was reached for an entry which is
1994 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1997 DPRINTK("lec: entry->status %d entry->vcc %p\n", entry->status, entry->vcc);
2000 /* No matching entry was found */
2001 entry = make_entry(priv, mac_to_find);
2002 DPRINTK("LEC_ARP: Making entry\n");
2004 found = priv->mcast_vcc;
2007 lec_arp_add(priv, entry);
2008 /* We want arp-request(s) to be sent */
2009 entry->packets_flooded =1;
2010 entry->status = ESI_ARP_PENDING;
2011 entry->no_tries = 1;
2012 entry->last_used = entry->timestamp = jiffies;
2013 entry->is_rdesc = is_rdesc;
2014 if (entry->is_rdesc)
2015 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL, NULL);
2017 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
2018 entry->timer.expires = jiffies + (1*HZ);
2019 entry->timer.function = lec_arp_expire_arp;
2020 add_timer(&entry->timer);
2021 found = priv->mcast_vcc;
2025 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2030 lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
2031 unsigned long permanent)
2033 unsigned long flags;
2034 struct lec_arp_table *entry, *next;
2037 DPRINTK("lec_addr_delete\n");
2038 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2039 for(i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2040 for(entry = priv->lec_arp_tables[i]; entry != NULL; entry = next) {
2042 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2044 !(entry->flags & LEC_PERMANENT_FLAG))) {
2045 lec_arp_remove(priv, entry);
2048 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2052 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2057 * Notifies: Response to arp_request (atm_addr != NULL)
2060 lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
2061 unsigned char *atm_addr, unsigned long remoteflag,
2062 unsigned int targetless_le_arp)
2064 unsigned long flags;
2065 struct lec_arp_table *entry, *tmp;
2068 DPRINTK("lec:%s", (targetless_le_arp) ? "targetless ": " ");
2069 DPRINTK("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2070 mac_addr[0],mac_addr[1],mac_addr[2],mac_addr[3],
2071 mac_addr[4],mac_addr[5]);
2073 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2074 entry = lec_arp_find(priv, mac_addr);
2075 if (entry == NULL && targetless_le_arp)
2076 goto out; /* LANE2: ignore targetless LE_ARPs for which
2077 * we have no entry in the cache. 7.1.30
2079 if (priv->lec_arp_empty_ones) {
2080 entry = priv->lec_arp_empty_ones;
2081 if (!memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN)) {
2082 priv->lec_arp_empty_ones = entry->next;
2084 while(entry->next && memcmp(entry->next->atm_addr,
2085 atm_addr, ATM_ESA_LEN))
2086 entry = entry->next;
2089 entry = entry->next;
2090 tmp->next = entry->next;
2096 del_timer(&entry->timer);
2097 tmp = lec_arp_find(priv, mac_addr);
2099 del_timer(&tmp->timer);
2100 tmp->status = ESI_FORWARD_DIRECT;
2101 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2102 tmp->vcc = entry->vcc;
2103 tmp->old_push = entry->old_push;
2104 tmp->last_used = jiffies;
2105 del_timer(&entry->timer);
2109 entry->status = ESI_FORWARD_DIRECT;
2110 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2111 entry->last_used = jiffies;
2112 lec_arp_add(priv, entry);
2115 entry->flags|=LEC_REMOTE_FLAG;
2117 entry->flags&=~LEC_REMOTE_FLAG;
2118 DPRINTK("After update\n");
2119 dump_arp_table(priv);
2123 entry = lec_arp_find(priv, mac_addr);
2125 entry = make_entry(priv, mac_addr);
2128 entry->status = ESI_UNKNOWN;
2129 lec_arp_add(priv, entry);
2130 /* Temporary, changes before end of function */
2132 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2133 del_timer(&entry->timer);
2134 for(i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2135 for(tmp = priv->lec_arp_tables[i]; tmp; tmp=tmp->next) {
2137 !memcmp(tmp->atm_addr, atm_addr,
2139 /* Vcc to this host exists */
2140 if (tmp->status > ESI_VC_PENDING) {
2142 * ESI_FLUSH_PENDING,
2143 * ESI_FORWARD_DIRECT
2145 entry->vcc = tmp->vcc;
2146 entry->old_push=tmp->old_push;
2148 entry->status=tmp->status;
2154 entry->flags|=LEC_REMOTE_FLAG;
2156 entry->flags&=~LEC_REMOTE_FLAG;
2157 if (entry->status == ESI_ARP_PENDING ||
2158 entry->status == ESI_UNKNOWN) {
2159 entry->status = ESI_VC_PENDING;
2160 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
2162 DPRINTK("After update2\n");
2163 dump_arp_table(priv);
2165 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2169 * Notifies: Vcc setup ready
2172 lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
2173 struct atm_vcc *vcc,
2174 void (*old_push)(struct atm_vcc *vcc, struct sk_buff *skb))
2176 unsigned long flags;
2177 struct lec_arp_table *entry;
2178 int i, found_entry=0;
2180 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2181 if (ioc_data->receive == 2) {
2182 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
2184 DPRINTK("LEC_ARP: Attaching mcast forward\n");
2186 entry = lec_arp_find(priv, bus_mac);
2188 printk("LEC_ARP: Multicast entry not found!\n");
2191 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2192 entry->recv_vcc = vcc;
2193 entry->old_recv_push = old_push;
2195 entry = make_entry(priv, bus_mac);
2198 del_timer(&entry->timer);
2199 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2200 entry->recv_vcc = vcc;
2201 entry->old_recv_push = old_push;
2202 entry->next = priv->mcast_fwds;
2203 priv->mcast_fwds = entry;
2205 } else if (ioc_data->receive == 1) {
2206 /* Vcc which we don't want to make default vcc, attach it
2208 DPRINTK("LEC_ARP:Attaching data direct, not default :%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2209 ioc_data->atm_addr[0],ioc_data->atm_addr[1],
2210 ioc_data->atm_addr[2],ioc_data->atm_addr[3],
2211 ioc_data->atm_addr[4],ioc_data->atm_addr[5],
2212 ioc_data->atm_addr[6],ioc_data->atm_addr[7],
2213 ioc_data->atm_addr[8],ioc_data->atm_addr[9],
2214 ioc_data->atm_addr[10],ioc_data->atm_addr[11],
2215 ioc_data->atm_addr[12],ioc_data->atm_addr[13],
2216 ioc_data->atm_addr[14],ioc_data->atm_addr[15],
2217 ioc_data->atm_addr[16],ioc_data->atm_addr[17],
2218 ioc_data->atm_addr[18],ioc_data->atm_addr[19]);
2219 entry = make_entry(priv, bus_mac);
2222 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2223 memset(entry->mac_addr, 0, ETH_ALEN);
2224 entry->recv_vcc = vcc;
2225 entry->old_recv_push = old_push;
2226 entry->status = ESI_UNKNOWN;
2227 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2228 entry->timer.function = lec_arp_expire_vcc;
2229 add_timer(&entry->timer);
2230 entry->next = priv->lec_no_forward;
2231 priv->lec_no_forward = entry;
2232 dump_arp_table(priv);
2235 DPRINTK("LEC_ARP:Attaching data direct, default:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2236 ioc_data->atm_addr[0],ioc_data->atm_addr[1],
2237 ioc_data->atm_addr[2],ioc_data->atm_addr[3],
2238 ioc_data->atm_addr[4],ioc_data->atm_addr[5],
2239 ioc_data->atm_addr[6],ioc_data->atm_addr[7],
2240 ioc_data->atm_addr[8],ioc_data->atm_addr[9],
2241 ioc_data->atm_addr[10],ioc_data->atm_addr[11],
2242 ioc_data->atm_addr[12],ioc_data->atm_addr[13],
2243 ioc_data->atm_addr[14],ioc_data->atm_addr[15],
2244 ioc_data->atm_addr[16],ioc_data->atm_addr[17],
2245 ioc_data->atm_addr[18],ioc_data->atm_addr[19]);
2246 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2247 for (entry = priv->lec_arp_tables[i]; entry; entry=entry->next) {
2248 if (memcmp(ioc_data->atm_addr, entry->atm_addr,
2250 DPRINTK("LEC_ARP: Attaching data direct\n");
2251 DPRINTK("Currently -> Vcc: %d, Rvcc:%d\n",
2252 entry->vcc?entry->vcc->vci:0,
2253 entry->recv_vcc?entry->recv_vcc->vci:0);
2255 del_timer(&entry->timer);
2257 entry->old_push = old_push;
2258 if (entry->status == ESI_VC_PENDING) {
2259 if(priv->maximum_unknown_frame_count
2264 entry->timestamp = jiffies;
2268 send_to_lecd(priv,l_flush_xmt,
2275 /* They were forming a connection
2276 to us, and we to them. Our
2277 ATM address is numerically lower
2278 than theirs, so we make connection
2279 we formed into default VCC (8.1.11).
2280 Connection they made gets torn
2281 down. This might confuse some
2282 clients. Can be changed if
2283 someone reports trouble... */
2290 DPRINTK("After vcc was added\n");
2291 dump_arp_table(priv);
2294 /* Not found, snatch address from first data packet that arrives from
2296 entry = make_entry(priv, bus_mac);
2300 entry->old_push = old_push;
2301 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2302 memset(entry->mac_addr, 0, ETH_ALEN);
2303 entry->status = ESI_UNKNOWN;
2304 entry->next = priv->lec_arp_empty_ones;
2305 priv->lec_arp_empty_ones = entry;
2306 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2307 entry->timer.function = lec_arp_expire_vcc;
2308 add_timer(&entry->timer);
2309 DPRINTK("After vcc was added\n");
2310 dump_arp_table(priv);
2312 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2316 lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
2318 unsigned long flags;
2319 struct lec_arp_table *entry;
2322 DPRINTK("LEC:lec_flush_complete %lx\n",tran_id);
2323 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2324 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2325 for (entry = priv->lec_arp_tables[i]; entry; entry=entry->next) {
2326 if (entry->flush_tran_id == tran_id &&
2327 entry->status == ESI_FLUSH_PENDING) {
2328 struct sk_buff *skb;
2330 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
2331 lec_send(entry->vcc, skb, entry->priv);
2332 entry->status = ESI_FORWARD_DIRECT;
2333 DPRINTK("LEC_ARP: Flushed\n");
2337 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2338 dump_arp_table(priv);
2342 lec_set_flush_tran_id(struct lec_priv *priv,
2343 unsigned char *atm_addr, unsigned long tran_id)
2345 unsigned long flags;
2346 struct lec_arp_table *entry;
2349 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2350 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
2351 for(entry = priv->lec_arp_tables[i]; entry; entry=entry->next)
2352 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2353 entry->flush_tran_id = tran_id;
2354 DPRINTK("Set flush transaction id to %lx for %p\n",tran_id,entry);
2356 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2360 lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
2362 unsigned long flags;
2363 unsigned char mac_addr[] = {
2364 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2365 struct lec_arp_table *to_add;
2366 struct lec_vcc_priv *vpriv;
2369 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2372 vpriv->old_pop = vcc->pop;
2373 vcc->user_back = vpriv;
2375 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2376 to_add = make_entry(priv, mac_addr);
2378 vcc->pop = vpriv->old_pop;
2383 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2384 to_add->status = ESI_FORWARD_DIRECT;
2385 to_add->flags |= LEC_PERMANENT_FLAG;
2387 to_add->old_push = vcc->push;
2388 vcc->push = lec_push;
2389 priv->mcast_vcc = vcc;
2390 lec_arp_add(priv, to_add);
2392 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2397 lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
2399 unsigned long flags;
2400 struct lec_arp_table *entry, *next;
2403 DPRINTK("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n",vcc->vpi,vcc->vci);
2404 dump_arp_table(priv);
2405 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2406 for(i=0;i<LEC_ARP_TABLE_SIZE;i++) {
2407 for(entry = priv->lec_arp_tables[i];entry; entry=next) {
2409 if (vcc == entry->vcc) {
2410 lec_arp_remove(priv, entry);
2412 if (priv->mcast_vcc == vcc) {
2413 priv->mcast_vcc = NULL;
2419 entry = priv->lec_arp_empty_ones;
2420 priv->lec_arp_empty_ones = NULL;
2421 while (entry != NULL) {
2423 if (entry->vcc == vcc) { /* leave it out from the list */
2424 lec_arp_clear_vccs(entry);
2425 del_timer(&entry->timer);
2428 else { /* put it back to the list */
2429 entry->next = priv->lec_arp_empty_ones;
2430 priv->lec_arp_empty_ones = entry;
2435 entry = priv->lec_no_forward;
2436 priv->lec_no_forward = NULL;
2437 while (entry != NULL) {
2439 if (entry->recv_vcc == vcc) {
2440 lec_arp_clear_vccs(entry);
2441 del_timer(&entry->timer);
2445 entry->next = priv->lec_no_forward;
2446 priv->lec_no_forward = entry;
2451 entry = priv->mcast_fwds;
2452 priv->mcast_fwds = NULL;
2453 while (entry != NULL) {
2455 if (entry->recv_vcc == vcc) {
2456 lec_arp_clear_vccs(entry);
2457 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
2461 entry->next = priv->mcast_fwds;
2462 priv->mcast_fwds = entry;
2467 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2468 dump_arp_table(priv);
2472 lec_arp_check_empties(struct lec_priv *priv,
2473 struct atm_vcc *vcc, struct sk_buff *skb)
2475 unsigned long flags;
2476 struct lec_arp_table *entry, *prev;
2477 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2480 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
2482 if (priv->is_trdev) src = tr_hdr->h_source;
2485 src = hdr->h_source;
2487 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2488 entry = priv->lec_arp_empty_ones;
2489 if (vcc == entry->vcc) {
2490 del_timer(&entry->timer);
2491 memcpy(entry->mac_addr, src, ETH_ALEN);
2492 entry->status = ESI_FORWARD_DIRECT;
2493 entry->last_used = jiffies;
2494 priv->lec_arp_empty_ones = entry->next;
2495 /* We might have got an entry */
2496 if ((prev = lec_arp_find(priv,src))) {
2497 lec_arp_remove(priv, prev);
2500 lec_arp_add(priv, entry);
2504 entry = entry->next;
2505 while (entry && entry->vcc != vcc) {
2507 entry = entry->next;
2510 DPRINTK("LEC_ARP: Arp_check_empties: entry not found!\n");
2513 del_timer(&entry->timer);
2514 memcpy(entry->mac_addr, src, ETH_ALEN);
2515 entry->status = ESI_FORWARD_DIRECT;
2516 entry->last_used = jiffies;
2517 prev->next = entry->next;
2518 if ((prev = lec_arp_find(priv, src))) {
2519 lec_arp_remove(priv, prev);
2522 lec_arp_add(priv, entry);
2524 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2526 MODULE_LICENSE("GPL");