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)
425 struct net_device *dev = (struct net_device*)vcc->proto_data;
426 struct lec_priv *priv = (struct lec_priv*)dev->priv;
427 struct atmlec_msg *mesg;
428 struct lec_arp_table *entry;
430 char *tmp; /* FIXME */
432 atomic_sub(skb->truesize, &vcc->sk->sk_wmem_alloc);
433 mesg = (struct atmlec_msg *)skb->data;
435 tmp += sizeof(struct atmlec_msg);
436 DPRINTK("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
440 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
445 dev->dev_addr[i] = 0;
449 lec_addr_delete(priv, mesg->content.normal.atm_addr,
450 mesg->content.normal.flag);
452 case l_topology_change:
453 priv->topology_change = mesg->content.normal.flag;
455 case l_flush_complete:
456 lec_flush_complete(priv, mesg->content.normal.flag);
458 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
459 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
460 lec_arp_remove(priv, entry);
462 if (mesg->content.normal.no_source_le_narp)
466 lec_arp_update(priv, mesg->content.normal.mac_addr,
467 mesg->content.normal.atm_addr,
468 mesg->content.normal.flag,
469 mesg->content.normal.targetless_le_arp);
470 DPRINTK("lec: in l_arp_update\n");
471 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
472 DPRINTK("lec: LANE2 3.1.5, got tlvs, size %d\n", mesg->sizeoftlvs);
473 lane2_associate_ind(dev,
474 mesg->content.normal.mac_addr,
475 tmp, mesg->sizeoftlvs);
479 priv->maximum_unknown_frame_count =
480 mesg->content.config.maximum_unknown_frame_count;
481 priv->max_unknown_frame_time =
482 (mesg->content.config.max_unknown_frame_time*HZ);
483 priv->max_retry_count =
484 mesg->content.config.max_retry_count;
485 priv->aging_time = (mesg->content.config.aging_time*HZ);
486 priv->forward_delay_time =
487 (mesg->content.config.forward_delay_time*HZ);
488 priv->arp_response_time =
489 (mesg->content.config.arp_response_time*HZ);
490 priv->flush_timeout = (mesg->content.config.flush_timeout*HZ);
491 priv->path_switching_delay =
492 (mesg->content.config.path_switching_delay*HZ);
493 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
494 priv->lane2_ops = NULL;
495 if (priv->lane_version > 1)
496 priv->lane2_ops = &lane2_ops;
497 if (dev->change_mtu(dev, mesg->content.config.mtu))
498 printk("%s: change_mtu to %d failed\n", dev->name,
499 mesg->content.config.mtu);
500 priv->is_proxy = mesg->content.config.is_proxy;
502 case l_flush_tran_id:
503 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
504 mesg->content.normal.flag);
507 priv->lecid=(unsigned short)(0xffff&mesg->content.normal.flag);
509 case l_should_bridge: {
510 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
511 struct net_bridge_fdb_entry *f;
513 DPRINTK("%s: bridge zeppelin asks about 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
515 mesg->content.proxy.mac_addr[0], mesg->content.proxy.mac_addr[1],
516 mesg->content.proxy.mac_addr[2], mesg->content.proxy.mac_addr[3],
517 mesg->content.proxy.mac_addr[4], mesg->content.proxy.mac_addr[5]);
519 if (br_fdb_get_hook == NULL || dev->br_port == NULL)
522 f = br_fdb_get_hook(dev->br_port->br, mesg->content.proxy.mac_addr);
524 f->dst->dev != dev &&
525 f->dst->state == BR_STATE_FORWARDING) {
526 /* hit from bridge table, send LE_ARP_RESPONSE */
527 struct sk_buff *skb2;
529 DPRINTK("%s: entry found, responding to zeppelin\n", dev->name);
530 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
535 skb2->len = sizeof(struct atmlec_msg);
536 memcpy(skb2->data, mesg, sizeof(struct atmlec_msg));
537 atm_force_charge(priv->lecd, skb2->truesize);
538 skb_queue_tail(&priv->lecd->sk->sk_receive_queue, skb2);
539 priv->lecd->sk->sk_data_ready(priv->lecd->sk, skb2->len);
541 if (f != NULL) br_fdb_put_hook(f);
542 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
546 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
555 lec_atm_close(struct atm_vcc *vcc)
558 struct net_device *dev = (struct net_device *)vcc->proto_data;
559 struct lec_priv *priv = (struct lec_priv *)dev->priv;
562 /* Do something needful? */
564 netif_stop_queue(dev);
565 lec_arp_destroy(priv);
567 if (skb_peek(&vcc->sk->sk_receive_queue))
568 printk("%s lec_atm_close: closing with messages pending\n",
570 while ((skb = skb_dequeue(&vcc->sk->sk_receive_queue)) != NULL) {
571 atm_return(vcc, skb->truesize);
575 printk("%s: Shut down!\n", dev->name);
576 module_put(THIS_MODULE);
579 static struct atmdev_ops lecdev_ops = {
580 .close = lec_atm_close,
584 static struct atm_dev lecatm_dev = {
587 .number = 999, /* dummy device number */
588 .lock = SPIN_LOCK_UNLOCKED
592 * LANE2: new argument struct sk_buff *data contains
593 * the LE_ARP based TLVs introduced in the LANE2 spec
596 send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
597 unsigned char *mac_addr, unsigned char *atm_addr,
598 struct sk_buff *data)
601 struct atmlec_msg *mesg;
603 if (!priv || !priv->lecd) {
606 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
609 skb->len = sizeof(struct atmlec_msg);
610 mesg = (struct atmlec_msg *)skb->data;
611 memset(mesg, 0, sizeof(struct atmlec_msg));
614 mesg->sizeoftlvs = data->len;
616 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
618 mesg->content.normal.targetless_le_arp = 1;
620 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
622 atm_force_charge(priv->lecd, skb->truesize);
623 skb_queue_tail(&priv->lecd->sk->sk_receive_queue, skb);
624 priv->lecd->sk->sk_data_ready(priv->lecd->sk, skb->len);
627 DPRINTK("lec: about to send %d bytes of data\n", data->len);
628 atm_force_charge(priv->lecd, data->truesize);
629 skb_queue_tail(&priv->lecd->sk->sk_receive_queue, data);
630 priv->lecd->sk->sk_data_ready(priv->lecd->sk, skb->len);
636 /* shamelessly stolen from drivers/net/net_init.c */
637 static int lec_change_mtu(struct net_device *dev, int new_mtu)
639 if ((new_mtu < 68) || (new_mtu > 18190))
645 static void lec_set_multicast_list(struct net_device *dev)
647 /* by default, all multicast frames arrive over the bus.
648 * eventually support selective multicast service
654 lec_init(struct net_device *dev)
656 dev->change_mtu = lec_change_mtu;
657 dev->open = lec_open;
658 dev->stop = lec_close;
659 dev->hard_start_xmit = lec_start_xmit;
660 dev->tx_timeout = lec_tx_timeout;
662 dev->get_stats = lec_get_stats;
663 dev->set_multicast_list = lec_set_multicast_list;
664 dev->do_ioctl = NULL;
665 printk("%s: Initialized!\n",dev->name);
669 static unsigned char lec_ctrl_magic[] = {
676 lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
678 struct net_device *dev = (struct net_device *)vcc->proto_data;
679 struct lec_priv *priv = (struct lec_priv *)dev->priv;
685 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
689 DPRINTK("%s: null skb\n",dev->name);
690 lec_vcc_close(priv, vcc);
694 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
695 skb->len, priv->lecid);
696 #if DUMP_PACKETS >= 2
697 for(i=0;i<skb->len && i <99;i++) {
698 sprintf(buf+i*3,"%2.2x ",0xff&skb->data[i]);
700 #elif DUMP_PACKETS >= 1
701 for(i=0;i<skb->len && i < 30;i++) {
702 sprintf(buf+i*3,"%2.2x ", 0xff&skb->data[i]);
704 #endif /* DUMP_PACKETS >= 1 */
708 printk("%s...\n",buf);
709 #endif /* DUMP_PACKETS > 0 */
710 if (memcmp(skb->data, lec_ctrl_magic, 4) ==0) { /* Control frame, to daemon*/
711 DPRINTK("%s: To daemon\n",dev->name);
712 skb_queue_tail(&vcc->sk->sk_receive_queue, skb);
713 vcc->sk->sk_data_ready(vcc->sk, skb->len);
714 } else { /* Data frame, queue to protocol handlers */
717 atm_return(vcc,skb->truesize);
718 if (*(uint16_t *)skb->data == htons(priv->lecid) ||
720 !(dev->flags & IFF_UP)) {
721 /* Probably looping back, or if lecd is missing,
722 lecd has gone down */
723 DPRINTK("Ignoring frame...\n");
728 if (priv->is_trdev) dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
731 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
733 if (!(dst[0]&0x01) && /* Never filter Multi/Broadcast */
734 !priv->is_proxy && /* Proxy wants all the packets */
735 memcmp(dst, dev->dev_addr, dev->addr_len)) {
739 if (priv->lec_arp_empty_ones) {
740 lec_arp_check_empties(priv, vcc, skb);
743 skb_pull(skb, 2); /* skip lec_id */
745 if (priv->is_trdev) skb->protocol = tr_type_trans(skb, dev);
748 skb->protocol = eth_type_trans(skb, dev);
749 priv->stats.rx_packets++;
750 priv->stats.rx_bytes += skb->len;
751 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
757 lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
759 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
760 struct net_device *dev = skb->dev;
763 printk("lec_pop(): vpriv = NULL!?!?!?\n");
767 vpriv->old_pop(vcc, skb);
769 if (vpriv->xoff && atm_may_send(vcc, 0)) {
771 if (netif_running(dev) && netif_queue_stopped(dev))
772 netif_wake_queue(dev);
777 lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
779 struct lec_vcc_priv *vpriv;
781 struct atmlec_ioc ioc_data;
783 /* Lecd must be up in this case */
784 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
785 if (bytes_left != 0) {
786 printk("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
789 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
790 !dev_lec[ioc_data.dev_num])
792 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
795 vpriv->old_pop = vcc->pop;
796 vcc->user_back = vpriv;
798 lec_vcc_added(dev_lec[ioc_data.dev_num]->priv,
799 &ioc_data, vcc, vcc->push);
800 vcc->proto_data = dev_lec[ioc_data.dev_num];
801 vcc->push = lec_push;
806 lec_mcast_attach(struct atm_vcc *vcc, int arg)
808 if (arg <0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
810 vcc->proto_data = dev_lec[arg];
811 return (lec_mcast_make((struct lec_priv*)dev_lec[arg]->priv, vcc));
814 /* Initialize device. */
816 lecd_attach(struct atm_vcc *vcc, int arg)
819 struct lec_priv *priv;
826 if (arg >= MAX_LEC_ITF)
828 #else /* Reserve the top NUM_TR_DEVS for TR */
829 if (arg >= (MAX_LEC_ITF-NUM_TR_DEVS))
836 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
839 size = sizeof(struct lec_priv);
842 dev_lec[i] = alloc_trdev(size);
845 dev_lec[i] = alloc_etherdev(size);
848 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
849 if (register_netdev(dev_lec[i])) {
850 free_netdev(dev_lec[i]);
854 priv = dev_lec[i]->priv;
855 priv->is_trdev = is_trdev;
856 lec_init(dev_lec[i]);
858 priv = dev_lec[i]->priv;
863 priv->itfnum = i; /* LANE2 addition */
865 vcc->dev = &lecatm_dev;
866 vcc_insert_socket(vcc->sk);
868 vcc->proto_data = dev_lec[i];
869 set_bit(ATM_VF_META,&vcc->flags);
870 set_bit(ATM_VF_READY,&vcc->flags);
872 /* Set default values to these variables */
873 priv->maximum_unknown_frame_count = 1;
874 priv->max_unknown_frame_time = (1*HZ);
875 priv->vcc_timeout_period = (1200*HZ);
876 priv->max_retry_count = 1;
877 priv->aging_time = (300*HZ);
878 priv->forward_delay_time = (15*HZ);
879 priv->topology_change = 0;
880 priv->arp_response_time = (1*HZ);
881 priv->flush_timeout = (4*HZ);
882 priv->path_switching_delay = (6*HZ);
884 if (dev_lec[i]->flags & IFF_UP) {
885 netif_start_queue(dev_lec[i]);
887 __module_get(THIS_MODULE);
891 #ifdef CONFIG_PROC_FS
892 static char* lec_arp_get_status_string(unsigned char status)
894 static char *lec_arp_status_string[] = {
899 "ESI_FLUSH_PENDING ",
903 if (status > ESI_FORWARD_DIRECT)
904 status = 3; /* ESI_UNDEFINED */
905 return lec_arp_status_string[status];
908 static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
912 for (i = 0; i < ETH_ALEN; i++)
913 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
914 seq_printf(seq, " ");
915 for (i = 0; i < ATM_ESA_LEN; i++)
916 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
917 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
918 entry->flags & 0xffff);
920 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
922 seq_printf(seq, " ");
923 if (entry->recv_vcc) {
924 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
925 entry->recv_vcc->vci);
933 struct lec_priv *locked;
934 struct lec_arp_table *entry;
935 struct net_device *dev;
941 static void *lec_tbl_walk(struct lec_state *state, struct lec_arp_table *tbl,
944 struct lec_arp_table *e = state->entry;
948 if (e == (void *)1) {
952 for (; e; e = e->next) {
957 return (*l < 0) ? state : NULL;
960 static void *lec_arp_walk(struct lec_state *state, loff_t *l,
961 struct lec_priv *priv)
966 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
967 v = lec_tbl_walk(state, priv->lec_arp_tables[p], l);
971 state->arp_table = p;
975 static void *lec_misc_walk(struct lec_state *state, loff_t *l,
976 struct lec_priv *priv)
978 struct lec_arp_table *lec_misc_tables[] = {
979 priv->lec_arp_empty_ones,
980 priv->lec_no_forward,
986 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
987 v = lec_tbl_walk(state, lec_misc_tables[q], l);
991 state->misc_table = q;
995 static void *lec_priv_walk(struct lec_state *state, loff_t *l,
996 struct lec_priv *priv)
998 if (!state->locked) {
999 state->locked = priv;
1000 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1002 if (!lec_arp_walk(state, l, priv) &&
1003 !lec_misc_walk(state, l, priv)) {
1004 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1005 state->locked = NULL;
1006 /* Partial state reset for the next time we get called */
1007 state->arp_table = state->misc_table = 0;
1009 return state->locked;
1012 static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1014 struct net_device *dev;
1017 dev = state->dev ? state->dev : dev_lec[state->itf];
1018 v = (dev && dev->priv) ? lec_priv_walk(state, l, dev->priv) : NULL;
1021 /* Partial state reset for the next time we get called */
1028 static void *lec_get_idx(struct lec_state *state, loff_t l)
1032 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1033 v = lec_itf_walk(state, &l);
1040 static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1042 struct lec_state *state = seq->private;
1046 state->locked = NULL;
1047 state->arp_table = 0;
1048 state->misc_table = 0;
1049 state->entry = (void *)1;
1051 return *pos ? lec_get_idx(state, *pos) : (void*)1;
1054 static void lec_seq_stop(struct seq_file *seq, void *v)
1056 struct lec_state *state = seq->private;
1059 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1061 dev_put(state->dev);
1065 static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1067 struct lec_state *state = seq->private;
1069 v = lec_get_idx(state, 1);
1070 *pos += !!PTR_ERR(v);
1074 static int lec_seq_show(struct seq_file *seq, void *v)
1076 static char lec_banner[] = "Itf MAC ATM destination"
1078 "VPI/VCI Recv VPI/VCI\n";
1081 seq_puts(seq, lec_banner);
1083 struct lec_state *state = seq->private;
1084 struct net_device *dev = state->dev;
1086 seq_printf(seq, "%s ", dev->name);
1087 lec_info(seq, state->entry);
1092 static struct seq_operations lec_seq_ops = {
1093 .start = lec_seq_start,
1094 .next = lec_seq_next,
1095 .stop = lec_seq_stop,
1096 .show = lec_seq_show,
1099 static int lec_seq_open(struct inode *inode, struct file *file)
1101 struct lec_state *state;
1102 struct seq_file *seq;
1105 state = kmalloc(sizeof(*state), GFP_KERNEL);
1111 rc = seq_open(file, &lec_seq_ops);
1114 seq = file->private_data;
1115 seq->private = state;
1124 static int lec_seq_release(struct inode *inode, struct file *file)
1126 return seq_release_private(inode, file);
1129 static struct file_operations lec_seq_fops = {
1130 .owner = THIS_MODULE,
1131 .open = lec_seq_open,
1133 .llseek = seq_lseek,
1134 .release = lec_seq_release,
1138 static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1140 struct atm_vcc *vcc = ATM_SD(sock);
1147 if (!capable(CAP_NET_ADMIN))
1151 return -ENOIOCTLCMD;
1156 err = lecd_attach(vcc, (int) arg);
1158 sock->state = SS_CONNECTED;
1161 err = lec_mcast_attach(vcc, (int) arg);
1164 err = lec_vcc_attach(vcc, (void __user *) arg);
1171 static struct atm_ioctl lane_ioctl_ops = {
1172 .owner = THIS_MODULE,
1173 .ioctl = lane_ioctl,
1176 static int __init lane_module_init(void)
1178 #ifdef CONFIG_PROC_FS
1179 struct proc_dir_entry *p;
1181 p = create_proc_entry("lec", S_IRUGO, atm_proc_root);
1183 p->proc_fops = &lec_seq_fops;
1186 register_atm_ioctl(&lane_ioctl_ops);
1187 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1191 static void __exit lane_module_cleanup(void)
1194 struct lec_priv *priv;
1196 remove_proc_entry("lec", atm_proc_root);
1198 deregister_atm_ioctl(&lane_ioctl_ops);
1200 for (i = 0; i < MAX_LEC_ITF; i++) {
1201 if (dev_lec[i] != NULL) {
1202 priv = (struct lec_priv *)dev_lec[i]->priv;
1203 unregister_netdev(dev_lec[i]);
1204 free_netdev(dev_lec[i]);
1212 module_init(lane_module_init);
1213 module_exit(lane_module_cleanup);
1216 * LANE2: 3.1.3, LE_RESOLVE.request
1217 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1218 * If sizeoftlvs == NULL the default TLVs associated with with this
1220 * If dst_mac == NULL, targetless LE_ARP will be sent
1222 static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
1223 u8 **tlvs, u32 *sizeoftlvs)
1225 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1226 struct lec_arp_table *table;
1227 struct sk_buff *skb;
1231 table = lec_arp_find(priv, dst_mac);
1235 *tlvs = kmalloc(table->sizeoftlvs, GFP_KERNEL);
1239 memcpy(*tlvs, table->tlvs, table->sizeoftlvs);
1240 *sizeoftlvs = table->sizeoftlvs;
1245 if (sizeoftlvs == NULL)
1246 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
1249 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1252 skb->len = *sizeoftlvs;
1253 memcpy(skb->data, *tlvs, *sizeoftlvs);
1254 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1261 * LANE2: 3.1.4, LE_ASSOCIATE.request
1262 * Associate the *tlvs with the *lan_dst address.
1263 * Will overwrite any previous association
1264 * Returns 1 for success, 0 for failure (out of memory)
1267 static int lane2_associate_req (struct net_device *dev, u8 *lan_dst,
1268 u8 *tlvs, u32 sizeoftlvs)
1271 struct sk_buff *skb;
1272 struct lec_priv *priv = (struct lec_priv*)dev->priv;
1274 if ( memcmp(lan_dst, dev->dev_addr, ETH_ALEN) != 0 )
1275 return (0); /* not our mac address */
1277 kfree(priv->tlvs); /* NULL if there was no previous association */
1279 priv->tlvs = kmalloc(sizeoftlvs, GFP_KERNEL);
1280 if (priv->tlvs == NULL)
1282 priv->sizeoftlvs = sizeoftlvs;
1283 memcpy(priv->tlvs, tlvs, sizeoftlvs);
1285 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1288 skb->len = sizeoftlvs;
1289 memcpy(skb->data, tlvs, sizeoftlvs);
1290 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1292 printk("lec.c: lane2_associate_req() failed\n");
1293 /* If the previous association has changed we must
1294 * somehow notify other LANE entities about the change
1300 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1303 static void lane2_associate_ind (struct net_device *dev, u8 *mac_addr,
1304 u8 *tlvs, u32 sizeoftlvs)
1309 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1310 #if 0 /* Why have the TLVs in LE_ARP entries since we do not use them? When you
1311 uncomment this code, make sure the TLVs get freed when entry is killed */
1312 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
1315 return; /* should not happen */
1319 entry->tlvs = kmalloc(sizeoftlvs, GFP_KERNEL);
1320 if (entry->tlvs == NULL)
1323 entry->sizeoftlvs = sizeoftlvs;
1324 memcpy(entry->tlvs, tlvs, sizeoftlvs);
1327 printk("lec.c: lane2_associate_ind()\n");
1328 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1329 while (i < sizeoftlvs)
1330 printk("%02x ", tlvs[i++]);
1335 /* tell MPOA about the TLVs we saw */
1336 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1337 priv->lane2_ops->associate_indicator(dev, mac_addr,
1344 * Here starts what used to lec_arpc.c
1346 * lec_arpc.c was added here when making
1347 * lane client modular. October 1997
1351 #include <linux/types.h>
1352 #include <linux/sched.h>
1353 #include <linux/timer.h>
1354 #include <asm/param.h>
1355 #include <asm/atomic.h>
1356 #include <linux/inetdevice.h>
1357 #include <net/route.h>
1361 #define DPRINTK(format,args...)
1363 #define DPRINTK printk
1366 #define DEBUG_ARP_TABLE 0
1368 #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1370 static void lec_arp_check_expire(unsigned long data);
1371 static void lec_arp_expire_arp(unsigned long data);
1372 void dump_arp_table(struct lec_priv *priv);
1378 #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1380 static __inline__ void
1381 lec_arp_get(struct lec_priv *priv)
1383 atomic_inc(&priv->lec_arp_users);
1386 static __inline__ void
1387 lec_arp_put(struct lec_priv *priv)
1389 atomic_dec(&priv->lec_arp_users);
1393 * Initialization of arp-cache
1396 lec_arp_init(struct lec_priv *priv)
1400 for (i=0;i<LEC_ARP_TABLE_SIZE;i++) {
1401 priv->lec_arp_tables[i] = NULL;
1403 spin_lock_init(&priv->lec_arp_lock);
1404 init_timer(&priv->lec_arp_timer);
1405 priv->lec_arp_timer.expires = jiffies+LEC_ARP_REFRESH_INTERVAL;
1406 priv->lec_arp_timer.data = (unsigned long)priv;
1407 priv->lec_arp_timer.function = lec_arp_check_expire;
1408 add_timer(&priv->lec_arp_timer);
1412 lec_arp_clear_vccs(struct lec_arp_table *entry)
1415 struct atm_vcc *vcc = entry->vcc;
1416 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
1417 struct net_device *dev = (struct net_device*) vcc->proto_data;
1419 vcc->pop = vpriv->old_pop;
1421 netif_wake_queue(dev);
1423 vcc->user_back = NULL;
1424 vcc->push = entry->old_push;
1425 vcc_release_async(vcc, -EPIPE);
1428 if (entry->recv_vcc) {
1429 entry->recv_vcc->push = entry->old_recv_push;
1430 vcc_release_async(entry->recv_vcc, -EPIPE);
1431 entry->recv_vcc = NULL;
1436 * Insert entry to lec_arp_table
1437 * LANE2: Add to the end of the list to satisfy 8.1.13
1440 lec_arp_add(struct lec_priv *priv, struct lec_arp_table *to_add)
1442 unsigned long flags;
1443 unsigned short place;
1444 struct lec_arp_table *tmp;
1446 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1448 place = HASH(to_add->mac_addr[ETH_ALEN-1]);
1449 tmp = priv->lec_arp_tables[place];
1450 to_add->next = NULL;
1452 priv->lec_arp_tables[place] = to_add;
1454 else { /* add to the end */
1460 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1462 DPRINTK("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1463 0xff&to_add->mac_addr[0], 0xff&to_add->mac_addr[1],
1464 0xff&to_add->mac_addr[2], 0xff&to_add->mac_addr[3],
1465 0xff&to_add->mac_addr[4], 0xff&to_add->mac_addr[5]);
1469 * Remove entry from lec_arp_table
1472 lec_arp_remove(struct lec_priv *priv,
1473 struct lec_arp_table *to_remove)
1475 unsigned long flags;
1476 unsigned short place;
1477 struct lec_arp_table *tmp;
1480 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1483 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1486 place = HASH(to_remove->mac_addr[ETH_ALEN-1]);
1487 tmp = priv->lec_arp_tables[place];
1488 if (tmp == to_remove) {
1489 priv->lec_arp_tables[place] = tmp->next;
1491 while(tmp && tmp->next != to_remove) {
1494 if (!tmp) {/* Entry was not found */
1495 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1499 tmp->next = to_remove->next;
1500 del_timer(&to_remove->timer);
1502 /* If this is the only MAC connected to this VCC, also tear down
1504 if (to_remove->status >= ESI_FLUSH_PENDING) {
1506 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1508 for(place=0;place<LEC_ARP_TABLE_SIZE;place++) {
1509 for(tmp = priv->lec_arp_tables[place]; tmp != NULL; tmp = tmp->next) {
1510 if (memcmp(tmp->atm_addr, to_remove->atm_addr,
1518 lec_arp_clear_vccs(to_remove);
1520 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1522 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1524 DPRINTK("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1525 0xff&to_remove->mac_addr[0], 0xff&to_remove->mac_addr[1],
1526 0xff&to_remove->mac_addr[2], 0xff&to_remove->mac_addr[3],
1527 0xff&to_remove->mac_addr[4], 0xff&to_remove->mac_addr[5]);
1533 get_status_string(unsigned char st)
1537 return "ESI_UNKNOWN";
1538 case ESI_ARP_PENDING:
1539 return "ESI_ARP_PENDING";
1540 case ESI_VC_PENDING:
1541 return "ESI_VC_PENDING";
1542 case ESI_FLUSH_PENDING:
1543 return "ESI_FLUSH_PENDING";
1544 case ESI_FORWARD_DIRECT:
1545 return "ESI_FORWARD_DIRECT";
1553 dump_arp_table(struct lec_priv *priv)
1557 struct lec_arp_table *rulla;
1559 struct lec_arp_table **lec_arp_tables =
1560 (struct lec_arp_table **)priv->lec_arp_tables;
1561 struct lec_arp_table *lec_arp_empty_ones =
1562 (struct lec_arp_table *)priv->lec_arp_empty_ones;
1563 struct lec_arp_table *lec_no_forward =
1564 (struct lec_arp_table *)priv->lec_no_forward;
1565 struct lec_arp_table *mcast_fwds = priv->mcast_fwds;
1568 printk("Dump %p:\n",priv);
1569 for (i=0;i<LEC_ARP_TABLE_SIZE;i++) {
1570 rulla = lec_arp_tables[i];
1572 offset += sprintf(buf,"%d: %p\n",i, rulla);
1574 offset += sprintf(buf+offset,"Mac:");
1575 for(j=0;j<ETH_ALEN;j++) {
1576 offset+=sprintf(buf+offset,
1578 rulla->mac_addr[j]&0xff);
1580 offset +=sprintf(buf+offset,"Atm:");
1581 for(j=0;j<ATM_ESA_LEN;j++) {
1582 offset+=sprintf(buf+offset,
1584 rulla->atm_addr[j]&0xff);
1586 offset+=sprintf(buf+offset,
1587 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1588 rulla->vcc?rulla->vcc->vpi:0,
1589 rulla->vcc?rulla->vcc->vci:0,
1590 rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1591 rulla->recv_vcc?rulla->recv_vcc->vci:0,
1593 rulla->timestamp, rulla->no_tries);
1594 offset+=sprintf(buf+offset,
1595 "Flags:%x, Packets_flooded:%x, Status: %s ",
1596 rulla->flags, rulla->packets_flooded,
1597 get_status_string(rulla->status));
1598 offset+=sprintf(buf+offset,"->%p\n",rulla->next);
1599 rulla = rulla->next;
1603 rulla = lec_no_forward;
1605 printk("No forward\n");
1608 offset += sprintf(buf+offset,"Mac:");
1609 for(j=0;j<ETH_ALEN;j++) {
1610 offset+=sprintf(buf+offset,"%2.2x ",
1611 rulla->mac_addr[j]&0xff);
1613 offset +=sprintf(buf+offset,"Atm:");
1614 for(j=0;j<ATM_ESA_LEN;j++) {
1615 offset+=sprintf(buf+offset,"%2.2x ",
1616 rulla->atm_addr[j]&0xff);
1618 offset+=sprintf(buf+offset,
1619 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1620 rulla->vcc?rulla->vcc->vpi:0,
1621 rulla->vcc?rulla->vcc->vci:0,
1622 rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1623 rulla->recv_vcc?rulla->recv_vcc->vci:0,
1625 rulla->timestamp, rulla->no_tries);
1626 offset+=sprintf(buf+offset,
1627 "Flags:%x, Packets_flooded:%x, Status: %s ",
1628 rulla->flags, rulla->packets_flooded,
1629 get_status_string(rulla->status));
1630 offset+=sprintf(buf+offset,"->%lx\n",(long)rulla->next);
1631 rulla = rulla->next;
1634 rulla = lec_arp_empty_ones;
1636 printk("Empty ones\n");
1639 offset += sprintf(buf+offset,"Mac:");
1640 for(j=0;j<ETH_ALEN;j++) {
1641 offset+=sprintf(buf+offset,"%2.2x ",
1642 rulla->mac_addr[j]&0xff);
1644 offset +=sprintf(buf+offset,"Atm:");
1645 for(j=0;j<ATM_ESA_LEN;j++) {
1646 offset+=sprintf(buf+offset,"%2.2x ",
1647 rulla->atm_addr[j]&0xff);
1649 offset+=sprintf(buf+offset,
1650 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1651 rulla->vcc?rulla->vcc->vpi:0,
1652 rulla->vcc?rulla->vcc->vci:0,
1653 rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1654 rulla->recv_vcc?rulla->recv_vcc->vci:0,
1656 rulla->timestamp, rulla->no_tries);
1657 offset+=sprintf(buf+offset,
1658 "Flags:%x, Packets_flooded:%x, Status: %s ",
1659 rulla->flags, rulla->packets_flooded,
1660 get_status_string(rulla->status));
1661 offset+=sprintf(buf+offset,"->%lx\n",(long)rulla->next);
1662 rulla = rulla->next;
1668 printk("Multicast Forward VCCs\n");
1671 offset += sprintf(buf+offset,"Mac:");
1672 for(j=0;j<ETH_ALEN;j++) {
1673 offset+=sprintf(buf+offset,"%2.2x ",
1674 rulla->mac_addr[j]&0xff);
1676 offset +=sprintf(buf+offset,"Atm:");
1677 for(j=0;j<ATM_ESA_LEN;j++) {
1678 offset+=sprintf(buf+offset,"%2.2x ",
1679 rulla->atm_addr[j]&0xff);
1681 offset+=sprintf(buf+offset,
1682 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1683 rulla->vcc?rulla->vcc->vpi:0,
1684 rulla->vcc?rulla->vcc->vci:0,
1685 rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1686 rulla->recv_vcc?rulla->recv_vcc->vci:0,
1688 rulla->timestamp, rulla->no_tries);
1689 offset+=sprintf(buf+offset,
1690 "Flags:%x, Packets_flooded:%x, Status: %s ",
1691 rulla->flags, rulla->packets_flooded,
1692 get_status_string(rulla->status));
1693 offset+=sprintf(buf+offset,"->%lx\n",(long)rulla->next);
1694 rulla = rulla->next;
1702 * Destruction of arp-cache
1705 lec_arp_destroy(struct lec_priv *priv)
1707 struct lec_arp_table *entry, *next;
1710 del_timer_sync(&priv->lec_arp_timer);
1713 * Remove all entries
1715 for (i=0;i<LEC_ARP_TABLE_SIZE;i++) {
1716 for(entry =priv->lec_arp_tables[i];entry != NULL; entry=next) {
1718 lec_arp_remove(priv, entry);
1722 entry = priv->lec_arp_empty_ones;
1725 del_timer_sync(&entry->timer);
1726 lec_arp_clear_vccs(entry);
1730 priv->lec_arp_empty_ones = NULL;
1731 entry = priv->lec_no_forward;
1734 del_timer_sync(&entry->timer);
1735 lec_arp_clear_vccs(entry);
1739 priv->lec_no_forward = NULL;
1740 entry = priv->mcast_fwds;
1743 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1744 lec_arp_clear_vccs(entry);
1748 priv->mcast_fwds = NULL;
1749 priv->mcast_vcc = NULL;
1750 memset(priv->lec_arp_tables, 0,
1751 sizeof(struct lec_arp_table*)*LEC_ARP_TABLE_SIZE);
1756 * Find entry by mac_address
1758 static struct lec_arp_table*
1759 lec_arp_find(struct lec_priv *priv,
1760 unsigned char *mac_addr)
1762 unsigned short place;
1763 struct lec_arp_table *to_return;
1765 DPRINTK("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1766 mac_addr[0]&0xff, mac_addr[1]&0xff, mac_addr[2]&0xff,
1767 mac_addr[3]&0xff, mac_addr[4]&0xff, mac_addr[5]&0xff);
1769 place = HASH(mac_addr[ETH_ALEN-1]);
1771 to_return = priv->lec_arp_tables[place];
1773 if (memcmp(mac_addr, to_return->mac_addr, ETH_ALEN) == 0) {
1777 to_return = to_return->next;
1783 static struct lec_arp_table*
1784 make_entry(struct lec_priv *priv, unsigned char *mac_addr)
1786 struct lec_arp_table *to_return;
1788 to_return=(struct lec_arp_table *)kmalloc(sizeof(struct lec_arp_table),
1791 printk("LEC: Arp entry kmalloc failed\n");
1794 memset(to_return,0,sizeof(struct lec_arp_table));
1795 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
1796 init_timer(&to_return->timer);
1797 to_return->timer.function = lec_arp_expire_arp;
1798 to_return->timer.data = (unsigned long)to_return;
1799 to_return->last_used = jiffies;
1800 to_return->priv = priv;
1801 skb_queue_head_init(&to_return->tx_wait);
1807 * Arp sent timer expired
1811 lec_arp_expire_arp(unsigned long data)
1813 struct lec_arp_table *entry;
1815 entry = (struct lec_arp_table *)data;
1817 DPRINTK("lec_arp_expire_arp\n");
1818 if (entry->status == ESI_ARP_PENDING) {
1819 if (entry->no_tries <= entry->priv->max_retry_count) {
1820 if (entry->is_rdesc)
1821 send_to_lecd(entry->priv, l_rdesc_arp_xmt, entry->mac_addr, NULL, NULL);
1823 send_to_lecd(entry->priv, l_arp_xmt, entry->mac_addr, NULL, NULL);
1826 mod_timer(&entry->timer, jiffies + (1*HZ));
1832 * Unknown/unused vcc expire, remove associated entry
1836 lec_arp_expire_vcc(unsigned long data)
1838 struct lec_arp_table *to_remove = (struct lec_arp_table*)data;
1839 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
1840 struct lec_arp_table *entry = NULL;
1842 del_timer(&to_remove->timer);
1844 DPRINTK("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1846 to_remove->vcc?to_remove->recv_vcc->vpi:0,
1847 to_remove->vcc?to_remove->recv_vcc->vci:0);
1848 DPRINTK("eo:%p nf:%p\n",priv->lec_arp_empty_ones,priv->lec_no_forward);
1849 if (to_remove == priv->lec_arp_empty_ones)
1850 priv->lec_arp_empty_ones = to_remove->next;
1852 entry = priv->lec_arp_empty_ones;
1853 while (entry && entry->next != to_remove)
1854 entry = entry->next;
1856 entry->next = to_remove->next;
1859 if (to_remove == priv->lec_no_forward) {
1860 priv->lec_no_forward = to_remove->next;
1862 entry = priv->lec_no_forward;
1863 while (entry && entry->next != to_remove)
1864 entry = entry->next;
1866 entry->next = to_remove->next;
1869 lec_arp_clear_vccs(to_remove);
1876 * 2. For each entry, delete entries that have aged past the age limit.
1877 * 3. For each entry, depending on the status of the entry, perform
1878 * the following maintenance.
1879 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1880 * tick_count is above the max_unknown_frame_time, clear
1881 * the tick_count to zero and clear the packets_flooded counter
1882 * to zero. This supports the packet rate limit per address
1883 * while flooding unknowns.
1884 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1885 * than or equal to the path_switching_delay, change the status
1886 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1887 * regardless of the progress of the flush protocol.
1890 lec_arp_check_expire(unsigned long data)
1892 struct lec_priv *priv = (struct lec_priv *)data;
1893 struct lec_arp_table *entry, *next;
1895 unsigned long time_to_check;
1898 DPRINTK("lec_arp_check_expire %p,%d\n",priv,
1899 atomic_read(&priv->lec_arp_users));
1900 DPRINTK("expire: eo:%p nf:%p\n",priv->lec_arp_empty_ones,
1901 priv->lec_no_forward);
1902 if (!atomic_read(&priv->lec_arp_users)) {
1905 for(i=0;i<LEC_ARP_TABLE_SIZE;i++) {
1906 for(entry = priv->lec_arp_tables[i]; entry != NULL; ) {
1907 if ((entry->flags) & LEC_REMOTE_FLAG &&
1908 priv->topology_change)
1909 time_to_check=priv->forward_delay_time;
1911 time_to_check = priv->aging_time;
1913 DPRINTK("About to expire: %lx - %lx > %lx\n",
1914 now,entry->last_used, time_to_check);
1915 if( time_after(now, entry->last_used+
1917 !(entry->flags & LEC_PERMANENT_FLAG) &&
1918 !(entry->mac_addr[0] & 0x01) ) { /* LANE2: 7.1.20 */
1920 DPRINTK("LEC:Entry timed out\n");
1922 lec_arp_remove(priv, entry);
1926 /* Something else */
1927 if ((entry->status == ESI_VC_PENDING ||
1928 entry->status == ESI_ARP_PENDING)
1929 && time_after_eq(now,
1931 priv->max_unknown_frame_time)) {
1932 entry->timestamp = jiffies;
1933 entry->packets_flooded = 0;
1934 if (entry->status == ESI_VC_PENDING)
1935 send_to_lecd(priv, l_svc_setup, entry->mac_addr, entry->atm_addr, NULL);
1937 if (entry->status == ESI_FLUSH_PENDING
1939 time_after_eq(now, entry->timestamp+
1940 priv->path_switching_delay)) {
1941 struct sk_buff *skb;
1943 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
1944 lec_send(entry->vcc, skb, entry->priv);
1945 entry->last_used = jiffies;
1949 entry = entry->next;
1956 mod_timer(&priv->lec_arp_timer, jiffies + LEC_ARP_REFRESH_INTERVAL);
1959 * Try to find vcc where mac_address is attached.
1963 lec_arp_resolve(struct lec_priv *priv, unsigned char *mac_to_find, int is_rdesc,
1964 struct lec_arp_table **ret_entry)
1966 struct lec_arp_table *entry;
1968 if (mac_to_find[0]&0x01) {
1969 switch (priv->lane_version) {
1971 return priv->mcast_vcc;
1973 case 2: /* LANE2 wants arp for multicast addresses */
1974 if ( memcmp(mac_to_find, bus_mac, ETH_ALEN) == 0)
1975 return priv->mcast_vcc;
1982 entry = lec_arp_find(priv, mac_to_find);
1985 if (entry->status == ESI_FORWARD_DIRECT) {
1987 entry->last_used = jiffies;
1991 /* Data direct VC not yet set up, check to see if the unknown
1992 frame count is greater than the limit. If the limit has
1993 not been reached, allow the caller to send packet to
1995 if (entry->status != ESI_FLUSH_PENDING &&
1996 entry->packets_flooded<priv->maximum_unknown_frame_count) {
1997 entry->packets_flooded++;
1998 DPRINTK("LEC_ARP: Flooding..\n");
1999 return priv->mcast_vcc;
2001 /* We got here because entry->status == ESI_FLUSH_PENDING
2002 * or BUS flood limit was reached for an entry which is
2003 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
2006 DPRINTK("lec: entry->status %d entry->vcc %p\n", entry->status, entry->vcc);
2009 /* No matching entry was found */
2010 entry = make_entry(priv, mac_to_find);
2011 DPRINTK("LEC_ARP: Making entry\n");
2013 return priv->mcast_vcc;
2015 lec_arp_add(priv, entry);
2016 /* We want arp-request(s) to be sent */
2017 entry->packets_flooded =1;
2018 entry->status = ESI_ARP_PENDING;
2019 entry->no_tries = 1;
2020 entry->last_used = entry->timestamp = jiffies;
2021 entry->is_rdesc = is_rdesc;
2022 if (entry->is_rdesc)
2023 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL, NULL);
2025 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
2026 entry->timer.expires = jiffies + (1*HZ);
2027 entry->timer.function = lec_arp_expire_arp;
2028 add_timer(&entry->timer);
2029 return priv->mcast_vcc;
2034 lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
2035 unsigned long permanent)
2037 struct lec_arp_table *entry, *next;
2041 DPRINTK("lec_addr_delete\n");
2042 for(i=0;i<LEC_ARP_TABLE_SIZE;i++) {
2043 for(entry=priv->lec_arp_tables[i];entry != NULL; entry=next) {
2045 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2047 !(entry->flags & LEC_PERMANENT_FLAG))) {
2048 lec_arp_remove(priv, entry);
2060 * Notifies: Response to arp_request (atm_addr != NULL)
2063 lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
2064 unsigned char *atm_addr, unsigned long remoteflag,
2065 unsigned int targetless_le_arp)
2067 struct lec_arp_table *entry, *tmp;
2070 DPRINTK("lec:%s", (targetless_le_arp) ? "targetless ": " ");
2071 DPRINTK("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2072 mac_addr[0],mac_addr[1],mac_addr[2],mac_addr[3],
2073 mac_addr[4],mac_addr[5]);
2075 entry = lec_arp_find(priv, mac_addr);
2076 if (entry == NULL && targetless_le_arp)
2077 return; /* LANE2: ignore targetless LE_ARPs for which
2078 * we have no entry in the cache. 7.1.30
2081 if (priv->lec_arp_empty_ones) {
2082 entry = priv->lec_arp_empty_ones;
2083 if (!memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN)) {
2084 priv->lec_arp_empty_ones = entry->next;
2086 while(entry->next && memcmp(entry->next->atm_addr,
2087 atm_addr, ATM_ESA_LEN))
2088 entry = entry->next;
2091 entry = entry->next;
2092 tmp->next = entry->next;
2098 del_timer(&entry->timer);
2099 tmp = lec_arp_find(priv, mac_addr);
2101 del_timer(&tmp->timer);
2102 tmp->status = ESI_FORWARD_DIRECT;
2103 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2104 tmp->vcc = entry->vcc;
2105 tmp->old_push = entry->old_push;
2106 tmp->last_used = jiffies;
2107 del_timer(&entry->timer);
2111 entry->status = ESI_FORWARD_DIRECT;
2112 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2113 entry->last_used = jiffies;
2114 lec_arp_add(priv, entry);
2117 entry->flags|=LEC_REMOTE_FLAG;
2119 entry->flags&=~LEC_REMOTE_FLAG;
2121 DPRINTK("After update\n");
2122 dump_arp_table(priv);
2126 entry = lec_arp_find(priv, mac_addr);
2128 entry = make_entry(priv, mac_addr);
2133 entry->status = ESI_UNKNOWN;
2134 lec_arp_add(priv, entry);
2135 /* Temporary, changes before end of function */
2137 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2138 del_timer(&entry->timer);
2139 for(i=0;i<LEC_ARP_TABLE_SIZE;i++) {
2140 for(tmp=priv->lec_arp_tables[i];tmp;tmp=tmp->next) {
2142 !memcmp(tmp->atm_addr, atm_addr,
2144 /* Vcc to this host exists */
2145 if (tmp->status > ESI_VC_PENDING) {
2147 * ESI_FLUSH_PENDING,
2148 * ESI_FORWARD_DIRECT
2150 entry->vcc = tmp->vcc;
2151 entry->old_push=tmp->old_push;
2153 entry->status=tmp->status;
2159 entry->flags|=LEC_REMOTE_FLAG;
2161 entry->flags&=~LEC_REMOTE_FLAG;
2162 if (entry->status == ESI_ARP_PENDING ||
2163 entry->status == ESI_UNKNOWN) {
2164 entry->status = ESI_VC_PENDING;
2165 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
2167 DPRINTK("After update2\n");
2168 dump_arp_table(priv);
2173 * Notifies: Vcc setup ready
2176 lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
2177 struct atm_vcc *vcc,
2178 void (*old_push)(struct atm_vcc *vcc, struct sk_buff *skb))
2180 struct lec_arp_table *entry;
2181 int i, found_entry=0;
2184 if (ioc_data->receive == 2) {
2185 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
2187 DPRINTK("LEC_ARP: Attaching mcast forward\n");
2189 entry = lec_arp_find(priv, bus_mac);
2191 printk("LEC_ARP: Multicast entry not found!\n");
2195 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2196 entry->recv_vcc = vcc;
2197 entry->old_recv_push = old_push;
2199 entry = make_entry(priv, bus_mac);
2200 if (entry == NULL) {
2204 del_timer(&entry->timer);
2205 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2206 entry->recv_vcc = vcc;
2207 entry->old_recv_push = old_push;
2208 entry->next = priv->mcast_fwds;
2209 priv->mcast_fwds = entry;
2212 } else if (ioc_data->receive == 1) {
2213 /* Vcc which we don't want to make default vcc, attach it
2215 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",
2216 ioc_data->atm_addr[0],ioc_data->atm_addr[1],
2217 ioc_data->atm_addr[2],ioc_data->atm_addr[3],
2218 ioc_data->atm_addr[4],ioc_data->atm_addr[5],
2219 ioc_data->atm_addr[6],ioc_data->atm_addr[7],
2220 ioc_data->atm_addr[8],ioc_data->atm_addr[9],
2221 ioc_data->atm_addr[10],ioc_data->atm_addr[11],
2222 ioc_data->atm_addr[12],ioc_data->atm_addr[13],
2223 ioc_data->atm_addr[14],ioc_data->atm_addr[15],
2224 ioc_data->atm_addr[16],ioc_data->atm_addr[17],
2225 ioc_data->atm_addr[18],ioc_data->atm_addr[19]);
2226 entry = make_entry(priv, bus_mac);
2227 if (entry == NULL) {
2231 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2232 memset(entry->mac_addr, 0, ETH_ALEN);
2233 entry->recv_vcc = vcc;
2234 entry->old_recv_push = old_push;
2235 entry->status = ESI_UNKNOWN;
2236 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2237 entry->timer.function = lec_arp_expire_vcc;
2238 add_timer(&entry->timer);
2239 entry->next = priv->lec_no_forward;
2240 priv->lec_no_forward = entry;
2242 dump_arp_table(priv);
2245 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",
2246 ioc_data->atm_addr[0],ioc_data->atm_addr[1],
2247 ioc_data->atm_addr[2],ioc_data->atm_addr[3],
2248 ioc_data->atm_addr[4],ioc_data->atm_addr[5],
2249 ioc_data->atm_addr[6],ioc_data->atm_addr[7],
2250 ioc_data->atm_addr[8],ioc_data->atm_addr[9],
2251 ioc_data->atm_addr[10],ioc_data->atm_addr[11],
2252 ioc_data->atm_addr[12],ioc_data->atm_addr[13],
2253 ioc_data->atm_addr[14],ioc_data->atm_addr[15],
2254 ioc_data->atm_addr[16],ioc_data->atm_addr[17],
2255 ioc_data->atm_addr[18],ioc_data->atm_addr[19]);
2256 for (i=0;i<LEC_ARP_TABLE_SIZE;i++) {
2257 for (entry = priv->lec_arp_tables[i];entry;entry=entry->next) {
2258 if (memcmp(ioc_data->atm_addr, entry->atm_addr,
2260 DPRINTK("LEC_ARP: Attaching data direct\n");
2261 DPRINTK("Currently -> Vcc: %d, Rvcc:%d\n",
2262 entry->vcc?entry->vcc->vci:0,
2263 entry->recv_vcc?entry->recv_vcc->vci:0);
2265 del_timer(&entry->timer);
2267 entry->old_push = old_push;
2268 if (entry->status == ESI_VC_PENDING) {
2269 if(priv->maximum_unknown_frame_count
2274 entry->timestamp = jiffies;
2278 send_to_lecd(priv,l_flush_xmt,
2285 /* They were forming a connection
2286 to us, and we to them. Our
2287 ATM address is numerically lower
2288 than theirs, so we make connection
2289 we formed into default VCC (8.1.11).
2290 Connection they made gets torn
2291 down. This might confuse some
2292 clients. Can be changed if
2293 someone reports trouble... */
2301 DPRINTK("After vcc was added\n");
2302 dump_arp_table(priv);
2305 /* Not found, snatch address from first data packet that arrives from
2307 entry = make_entry(priv, bus_mac);
2313 entry->old_push = old_push;
2314 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2315 memset(entry->mac_addr, 0, ETH_ALEN);
2316 entry->status = ESI_UNKNOWN;
2317 entry->next = priv->lec_arp_empty_ones;
2318 priv->lec_arp_empty_ones = entry;
2319 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2320 entry->timer.function = lec_arp_expire_vcc;
2321 add_timer(&entry->timer);
2323 DPRINTK("After vcc was added\n");
2324 dump_arp_table(priv);
2328 lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
2330 struct lec_arp_table *entry;
2333 DPRINTK("LEC:lec_flush_complete %lx\n",tran_id);
2334 for (i=0;i<LEC_ARP_TABLE_SIZE;i++) {
2335 for (entry=priv->lec_arp_tables[i];entry;entry=entry->next) {
2336 if (entry->flush_tran_id == tran_id &&
2337 entry->status == ESI_FLUSH_PENDING) {
2338 struct sk_buff *skb;
2340 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
2341 lec_send(entry->vcc, skb, entry->priv);
2342 entry->status = ESI_FORWARD_DIRECT;
2343 DPRINTK("LEC_ARP: Flushed\n");
2347 dump_arp_table(priv);
2351 lec_set_flush_tran_id(struct lec_priv *priv,
2352 unsigned char *atm_addr, unsigned long tran_id)
2354 struct lec_arp_table *entry;
2357 for (i=0;i<LEC_ARP_TABLE_SIZE;i++)
2358 for(entry=priv->lec_arp_tables[i];entry;entry=entry->next)
2359 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2360 entry->flush_tran_id = tran_id;
2361 DPRINTK("Set flush transaction id to %lx for %p\n",tran_id,entry);
2366 lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
2368 unsigned char mac_addr[] = {
2369 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2370 struct lec_arp_table *to_add;
2371 struct lec_vcc_priv *vpriv;
2373 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2376 vpriv->old_pop = vcc->pop;
2377 vcc->user_back = vpriv;
2380 to_add = make_entry(priv, mac_addr);
2383 vcc->pop = vpriv->old_pop;
2387 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2388 to_add->status = ESI_FORWARD_DIRECT;
2389 to_add->flags |= LEC_PERMANENT_FLAG;
2391 to_add->old_push = vcc->push;
2392 vcc->push = lec_push;
2393 priv->mcast_vcc = vcc;
2394 lec_arp_add(priv, to_add);
2400 lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
2402 struct lec_arp_table *entry, *next;
2405 DPRINTK("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n",vcc->vpi,vcc->vci);
2406 dump_arp_table(priv);
2408 for(i=0;i<LEC_ARP_TABLE_SIZE;i++) {
2409 for(entry = priv->lec_arp_tables[i];entry; entry=next) {
2411 if (vcc == entry->vcc) {
2412 lec_arp_remove(priv, entry);
2414 if (priv->mcast_vcc == vcc) {
2415 priv->mcast_vcc = NULL;
2421 entry = priv->lec_arp_empty_ones;
2422 priv->lec_arp_empty_ones = NULL;
2423 while (entry != NULL) {
2425 if (entry->vcc == vcc) { /* leave it out from the list */
2426 lec_arp_clear_vccs(entry);
2427 del_timer(&entry->timer);
2430 else { /* put it back to the list */
2431 entry->next = priv->lec_arp_empty_ones;
2432 priv->lec_arp_empty_ones = entry;
2437 entry = priv->lec_no_forward;
2438 priv->lec_no_forward = NULL;
2439 while (entry != NULL) {
2441 if (entry->recv_vcc == vcc) {
2442 lec_arp_clear_vccs(entry);
2443 del_timer(&entry->timer);
2447 entry->next = priv->lec_no_forward;
2448 priv->lec_no_forward = entry;
2453 entry = priv->mcast_fwds;
2454 priv->mcast_fwds = NULL;
2455 while (entry != NULL) {
2457 if (entry->recv_vcc == vcc) {
2458 lec_arp_clear_vccs(entry);
2459 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
2463 entry->next = priv->mcast_fwds;
2464 priv->mcast_fwds = entry;
2470 dump_arp_table(priv);
2474 lec_arp_check_empties(struct lec_priv *priv,
2475 struct atm_vcc *vcc, struct sk_buff *skb)
2477 unsigned long flags;
2478 struct lec_arp_table *entry, *prev;
2479 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2482 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
2484 if (priv->is_trdev) src = tr_hdr->h_source;
2487 src = hdr->h_source;
2490 entry = priv->lec_arp_empty_ones;
2491 if (vcc == entry->vcc) {
2492 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2493 del_timer(&entry->timer);
2494 memcpy(entry->mac_addr, src, ETH_ALEN);
2495 entry->status = ESI_FORWARD_DIRECT;
2496 entry->last_used = jiffies;
2497 priv->lec_arp_empty_ones = entry->next;
2498 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2499 /* We might have got an entry */
2500 if ((prev=lec_arp_find(priv,src))) {
2501 lec_arp_remove(priv, prev);
2504 lec_arp_add(priv, entry);
2508 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2510 entry = entry->next;
2511 while (entry && entry->vcc != vcc) {
2513 entry = entry->next;
2516 DPRINTK("LEC_ARP: Arp_check_empties: entry not found!\n");
2518 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2521 del_timer(&entry->timer);
2522 memcpy(entry->mac_addr, src, ETH_ALEN);
2523 entry->status = ESI_FORWARD_DIRECT;
2524 entry->last_used = jiffies;
2525 prev->next = entry->next;
2526 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2527 if ((prev = lec_arp_find(priv, src))) {
2528 lec_arp_remove(priv, prev);
2531 lec_arp_add(priv, entry);
2534 MODULE_LICENSE("GPL");