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"
41 static unsigned char bridge_ula_lec[] = {0x01, 0x80, 0xc2, 0x00, 0x00};
45 #include <linux/module.h>
46 #include <linux/init.h>
50 #include "resources.h"
53 #define DPRINTK printk
55 #define DPRINTK(format,args...)
58 #define DUMP_PACKETS 0 /* 0 = None,
63 #define LEC_UNRES_QUE_LEN 8 /* number of tx packets to queue for a
64 single destination while waiting for SVC */
66 static int lec_open(struct net_device *dev);
67 static int lec_start_xmit(struct sk_buff *skb, struct net_device *dev);
68 static int lec_close(struct net_device *dev);
69 static struct net_device_stats *lec_get_stats(struct net_device *dev);
70 static void lec_init(struct net_device *dev);
71 static struct lec_arp_table* lec_arp_find(struct lec_priv *priv,
72 unsigned char *mac_addr);
73 static int lec_arp_remove(struct lec_priv *priv,
74 struct lec_arp_table *to_remove);
76 static void lane2_associate_ind (struct net_device *dev, u8 *mac_address,
77 u8 *tlvs, u32 sizeoftlvs);
78 static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
79 u8 **tlvs, u32 *sizeoftlvs);
80 static int lane2_associate_req (struct net_device *dev, u8 *lan_dst,
81 u8 *tlvs, u32 sizeoftlvs);
83 static int lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
84 unsigned long permanent);
85 static void lec_arp_check_empties(struct lec_priv *priv,
86 struct atm_vcc *vcc, struct sk_buff *skb);
87 static void lec_arp_destroy(struct lec_priv *priv);
88 static void lec_arp_init(struct lec_priv *priv);
89 static struct atm_vcc* lec_arp_resolve(struct lec_priv *priv,
90 unsigned char *mac_to_find,
92 struct lec_arp_table **ret_entry);
93 static void lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
94 unsigned char *atm_addr, unsigned long remoteflag,
95 unsigned int targetless_le_arp);
96 static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
97 static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
98 static void lec_set_flush_tran_id(struct lec_priv *priv,
99 unsigned char *atm_addr,
100 unsigned long tran_id);
101 static void lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
103 void (*old_push)(struct atm_vcc *vcc, struct sk_buff *skb));
104 static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
106 static struct lane2_ops lane2_ops = {
107 lane2_resolve, /* resolve, spec 3.1.3 */
108 lane2_associate_req, /* associate_req, spec 3.1.4 */
109 NULL /* associate indicator, spec 3.1.5 */
112 static unsigned char bus_mac[ETH_ALEN] = {0xff,0xff,0xff,0xff,0xff,0xff};
114 /* Device structures */
115 static struct net_device *dev_lec[MAX_LEC_ITF];
117 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
118 static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
122 struct lec_priv *priv;
124 /* Check if this is a BPDU. If so, ask zeppelin to send
125 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
126 * as the Config BPDU has */
127 eth = (struct ethhdr *)skb->data;
128 buff = skb->data + skb->dev->hard_header_len;
129 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
131 struct sk_buff *skb2;
132 struct atmlec_msg *mesg;
134 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
135 if (skb2 == NULL) return;
136 skb2->len = sizeof(struct atmlec_msg);
137 mesg = (struct atmlec_msg *)skb2->data;
138 mesg->type = l_topology_change;
140 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
142 priv = (struct lec_priv *)dev->priv;
143 atm_force_charge(priv->lecd, skb2->truesize);
144 sk = sk_atm(priv->lecd);
145 skb_queue_tail(&sk->sk_receive_queue, skb2);
146 sk->sk_data_ready(sk, skb2->len);
151 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
154 * Modelled after tr_type_trans
155 * All multicast and ARE or STE frames go to BUS.
156 * Non source routed frames go by destination address.
157 * Last hop source routed frames go by destination address.
158 * Not last hop source routed frames go by _next_ route descriptor.
159 * Returns pointer to destination MAC address or fills in rdesc
163 static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
166 int riflen, num_rdsc;
168 trh = (struct trh_hdr *)packet;
169 if (trh->daddr[0] & (uint8_t)0x80)
170 return bus_mac; /* multicast */
172 if (trh->saddr[0] & TR_RII) {
173 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
174 if ((ntohs(trh->rcf) >> 13) != 0)
175 return bus_mac; /* ARE or STE */
178 return trh->daddr; /* not source routed */
181 return trh->daddr; /* last hop, source routed */
183 /* riflen is 6 or more, packet has more than one route descriptor */
184 num_rdsc = (riflen/2) - 1;
185 memset(rdesc, 0, ETH_ALEN);
186 /* offset 4 comes from LAN destination field in LE control frames */
187 if (trh->rcf & htons((uint16_t)TR_RCF_DIR_BIT))
188 memcpy(&rdesc[4], &trh->rseg[num_rdsc-2], sizeof(uint16_t));
190 memcpy(&rdesc[4], &trh->rseg[1], sizeof(uint16_t));
191 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
196 #endif /* CONFIG_TR */
199 * Open/initialize the netdevice. This is called (in the current kernel)
200 * sometime after booting when the 'ifconfig' program is run.
202 * This routine should set everything up anew at each open, even
203 * registers that "should" only need to be set once at boot, so that
204 * there is non-reboot way to recover if something goes wrong.
208 lec_open(struct net_device *dev)
210 struct lec_priv *priv = (struct lec_priv *)dev->priv;
212 netif_start_queue(dev);
213 memset(&priv->stats,0,sizeof(struct net_device_stats));
218 static __inline__ void
219 lec_send(struct atm_vcc *vcc, struct sk_buff *skb, struct lec_priv *priv)
221 ATM_SKB(skb)->vcc = vcc;
222 ATM_SKB(skb)->atm_options = vcc->atm_options;
224 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
225 if (vcc->send(vcc, skb) < 0) {
226 priv->stats.tx_dropped++;
230 priv->stats.tx_packets++;
231 priv->stats.tx_bytes += skb->len;
235 lec_tx_timeout(struct net_device *dev)
237 printk(KERN_INFO "%s: tx timeout\n", dev->name);
238 dev->trans_start = jiffies;
239 netif_wake_queue(dev);
243 lec_start_xmit(struct sk_buff *skb, struct net_device *dev)
245 struct sk_buff *skb2;
246 struct lec_priv *priv = (struct lec_priv *)dev->priv;
247 struct lecdatahdr_8023 *lec_h;
249 struct lec_arp_table *entry;
253 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
259 #endif /* DUMP_PACKETS >0 */
261 DPRINTK("lec_start_xmit called\n");
263 printk("%s:No lecd attached\n",dev->name);
264 priv->stats.tx_errors++;
265 netif_stop_queue(dev);
269 DPRINTK("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
270 (long)skb->head, (long)skb->data, (long)skb->tail,
272 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
273 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
274 lec_handle_bridge(skb, dev);
277 /* Make sure we have room for lec_id */
278 if (skb_headroom(skb) < 2) {
280 DPRINTK("lec_start_xmit: reallocating skb\n");
281 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
283 if (skb2 == NULL) return 0;
288 /* Put le header to place, works for TokenRing too */
289 lec_h = (struct lecdatahdr_8023*)skb->data;
290 lec_h->le_header = htons(priv->lecid);
293 /* Ugly. Use this to realign Token Ring packets for
294 * e.g. PCA-200E driver. */
295 if (priv->is_trdev) {
296 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
298 if (skb2 == NULL) return 0;
304 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
305 skb->len, priv->lecid);
306 #if DUMP_PACKETS >= 2
307 for(i=0;i<skb->len && i <99;i++) {
308 sprintf(buf+i*3,"%2.2x ",0xff&skb->data[i]);
310 #elif DUMP_PACKETS >= 1
311 for(i=0;i<skb->len && i < 30;i++) {
312 sprintf(buf+i*3,"%2.2x ", 0xff&skb->data[i]);
314 #endif /* DUMP_PACKETS >= 1 */
318 printk("%s...\n",buf);
319 #endif /* DUMP_PACKETS > 0 */
321 /* Minimum ethernet-frame size */
324 min_frame_size = LEC_MINIMUM_8025_SIZE;
327 min_frame_size = LEC_MINIMUM_8023_SIZE;
328 if (skb->len < min_frame_size) {
329 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
330 skb2 = skb_copy_expand(skb, 0,
331 min_frame_size - skb->truesize, GFP_ATOMIC);
334 priv->stats.tx_dropped++;
339 skb_put(skb, min_frame_size - skb->len);
342 /* Send to right vcc */
346 if (priv->is_trdev) {
347 dst = get_tr_dst(skb->data+2, rdesc);
355 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
356 DPRINTK("%s:vcc:%p vcc_flags:%x, entry:%p\n", dev->name,
357 vcc, vcc?vcc->flags:0, entry);
358 if (!vcc || !test_bit(ATM_VF_READY,&vcc->flags)) {
359 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
360 DPRINTK("%s:lec_start_xmit: queuing packet, ", dev->name);
361 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
362 lec_h->h_dest[0], lec_h->h_dest[1], lec_h->h_dest[2],
363 lec_h->h_dest[3], lec_h->h_dest[4], lec_h->h_dest[5]);
364 skb_queue_tail(&entry->tx_wait, skb);
366 DPRINTK("%s:lec_start_xmit: tx queue full or no arp entry, dropping, ", dev->name);
367 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
368 lec_h->h_dest[0], lec_h->h_dest[1], lec_h->h_dest[2],
369 lec_h->h_dest[3], lec_h->h_dest[4], lec_h->h_dest[5]);
370 priv->stats.tx_dropped++;
377 printk("%s:sending to vpi:%d vci:%d\n", dev->name,
379 #endif /* DUMP_PACKETS > 0 */
381 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
382 DPRINTK("lec.c: emptying tx queue, ");
383 DPRINTK("MAC address 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
384 lec_h->h_dest[0], lec_h->h_dest[1], lec_h->h_dest[2],
385 lec_h->h_dest[3], lec_h->h_dest[4], lec_h->h_dest[5]);
386 lec_send(vcc, skb2, priv);
389 lec_send(vcc, skb, priv);
391 if (!atm_may_send(vcc, 0)) {
392 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
395 netif_stop_queue(dev);
398 * vcc->pop() might have occurred in between, making
399 * the vcc usuable again. Since xmit is serialized,
400 * this is the only situation we have to re-test.
403 if (atm_may_send(vcc, 0))
404 netif_wake_queue(dev);
407 dev->trans_start = jiffies;
411 /* The inverse routine to net_open(). */
413 lec_close(struct net_device *dev)
415 netif_stop_queue(dev);
420 * Get the current statistics.
421 * This may be called with the card open or closed.
423 static struct net_device_stats *
424 lec_get_stats(struct net_device *dev)
426 return &((struct lec_priv *)dev->priv)->stats;
430 lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
433 struct net_device *dev = (struct net_device*)vcc->proto_data;
434 struct lec_priv *priv = (struct lec_priv*)dev->priv;
435 struct atmlec_msg *mesg;
436 struct lec_arp_table *entry;
438 char *tmp; /* FIXME */
440 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
441 mesg = (struct atmlec_msg *)skb->data;
443 tmp += sizeof(struct atmlec_msg);
444 DPRINTK("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
448 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
453 dev->dev_addr[i] = 0;
457 lec_addr_delete(priv, mesg->content.normal.atm_addr,
458 mesg->content.normal.flag);
460 case l_topology_change:
461 priv->topology_change = mesg->content.normal.flag;
463 case l_flush_complete:
464 lec_flush_complete(priv, mesg->content.normal.flag);
466 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
467 spin_lock_irqsave(&priv->lec_arp_lock, flags);
468 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
469 lec_arp_remove(priv, entry);
470 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
472 if (mesg->content.normal.no_source_le_narp)
476 lec_arp_update(priv, mesg->content.normal.mac_addr,
477 mesg->content.normal.atm_addr,
478 mesg->content.normal.flag,
479 mesg->content.normal.targetless_le_arp);
480 DPRINTK("lec: in l_arp_update\n");
481 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
482 DPRINTK("lec: LANE2 3.1.5, got tlvs, size %d\n", mesg->sizeoftlvs);
483 lane2_associate_ind(dev,
484 mesg->content.normal.mac_addr,
485 tmp, mesg->sizeoftlvs);
489 priv->maximum_unknown_frame_count =
490 mesg->content.config.maximum_unknown_frame_count;
491 priv->max_unknown_frame_time =
492 (mesg->content.config.max_unknown_frame_time*HZ);
493 priv->max_retry_count =
494 mesg->content.config.max_retry_count;
495 priv->aging_time = (mesg->content.config.aging_time*HZ);
496 priv->forward_delay_time =
497 (mesg->content.config.forward_delay_time*HZ);
498 priv->arp_response_time =
499 (mesg->content.config.arp_response_time*HZ);
500 priv->flush_timeout = (mesg->content.config.flush_timeout*HZ);
501 priv->path_switching_delay =
502 (mesg->content.config.path_switching_delay*HZ);
503 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
504 priv->lane2_ops = NULL;
505 if (priv->lane_version > 1)
506 priv->lane2_ops = &lane2_ops;
507 if (dev->change_mtu(dev, mesg->content.config.mtu))
508 printk("%s: change_mtu to %d failed\n", dev->name,
509 mesg->content.config.mtu);
510 priv->is_proxy = mesg->content.config.is_proxy;
512 case l_flush_tran_id:
513 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
514 mesg->content.normal.flag);
517 priv->lecid=(unsigned short)(0xffff&mesg->content.normal.flag);
519 case l_should_bridge: {
520 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
521 struct net_bridge_fdb_entry *f;
523 DPRINTK("%s: bridge zeppelin asks about 0x%02x:%02x:%02x:%02x:%02x:%02x\n",
525 mesg->content.proxy.mac_addr[0], mesg->content.proxy.mac_addr[1],
526 mesg->content.proxy.mac_addr[2], mesg->content.proxy.mac_addr[3],
527 mesg->content.proxy.mac_addr[4], mesg->content.proxy.mac_addr[5]);
529 if (br_fdb_get_hook == NULL || dev->br_port == NULL)
532 f = br_fdb_get_hook(dev->br_port->br, mesg->content.proxy.mac_addr);
534 f->dst->dev != dev &&
535 f->dst->state == BR_STATE_FORWARDING) {
536 /* hit from bridge table, send LE_ARP_RESPONSE */
537 struct sk_buff *skb2;
540 DPRINTK("%s: entry found, responding to zeppelin\n", dev->name);
541 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
546 skb2->len = sizeof(struct atmlec_msg);
547 memcpy(skb2->data, mesg, sizeof(struct atmlec_msg));
548 atm_force_charge(priv->lecd, skb2->truesize);
549 sk = sk_atm(priv->lecd);
550 skb_queue_tail(&sk->sk_receive_queue, skb2);
551 sk->sk_data_ready(sk, skb2->len);
553 if (f != NULL) br_fdb_put_hook(f);
554 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
558 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
567 lec_atm_close(struct atm_vcc *vcc)
570 struct net_device *dev = (struct net_device *)vcc->proto_data;
571 struct lec_priv *priv = (struct lec_priv *)dev->priv;
574 /* Do something needful? */
576 netif_stop_queue(dev);
577 lec_arp_destroy(priv);
579 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
580 printk("%s lec_atm_close: closing with messages pending\n",
582 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
583 atm_return(vcc, skb->truesize);
587 printk("%s: Shut down!\n", dev->name);
588 module_put(THIS_MODULE);
591 static struct atmdev_ops lecdev_ops = {
592 .close = lec_atm_close,
596 static struct atm_dev lecatm_dev = {
599 .number = 999, /* dummy device number */
600 .lock = SPIN_LOCK_UNLOCKED
604 * LANE2: new argument struct sk_buff *data contains
605 * the LE_ARP based TLVs introduced in the LANE2 spec
608 send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
609 unsigned char *mac_addr, unsigned char *atm_addr,
610 struct sk_buff *data)
614 struct atmlec_msg *mesg;
616 if (!priv || !priv->lecd) {
619 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
622 skb->len = sizeof(struct atmlec_msg);
623 mesg = (struct atmlec_msg *)skb->data;
624 memset(mesg, 0, sizeof(struct atmlec_msg));
627 mesg->sizeoftlvs = data->len;
629 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
631 mesg->content.normal.targetless_le_arp = 1;
633 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
635 atm_force_charge(priv->lecd, skb->truesize);
636 sk = sk_atm(priv->lecd);
637 skb_queue_tail(&sk->sk_receive_queue, skb);
638 sk->sk_data_ready(sk, skb->len);
641 DPRINTK("lec: about to send %d bytes of data\n", data->len);
642 atm_force_charge(priv->lecd, data->truesize);
643 skb_queue_tail(&sk->sk_receive_queue, data);
644 sk->sk_data_ready(sk, skb->len);
650 /* shamelessly stolen from drivers/net/net_init.c */
651 static int lec_change_mtu(struct net_device *dev, int new_mtu)
653 if ((new_mtu < 68) || (new_mtu > 18190))
659 static void lec_set_multicast_list(struct net_device *dev)
661 /* by default, all multicast frames arrive over the bus.
662 * eventually support selective multicast service
668 lec_init(struct net_device *dev)
670 dev->change_mtu = lec_change_mtu;
671 dev->open = lec_open;
672 dev->stop = lec_close;
673 dev->hard_start_xmit = lec_start_xmit;
674 dev->tx_timeout = lec_tx_timeout;
676 dev->get_stats = lec_get_stats;
677 dev->set_multicast_list = lec_set_multicast_list;
678 dev->do_ioctl = NULL;
679 printk("%s: Initialized!\n",dev->name);
683 static unsigned char lec_ctrl_magic[] = {
690 lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
692 struct net_device *dev = (struct net_device *)vcc->proto_data;
693 struct lec_priv *priv = (struct lec_priv *)dev->priv;
699 printk("%s: lec_push vcc vpi:%d vci:%d\n", dev->name,
703 DPRINTK("%s: null skb\n",dev->name);
704 lec_vcc_close(priv, vcc);
708 printk("%s: rcv datalen:%ld lecid:%4.4x\n", dev->name,
709 skb->len, priv->lecid);
710 #if DUMP_PACKETS >= 2
711 for(i=0;i<skb->len && i <99;i++) {
712 sprintf(buf+i*3,"%2.2x ",0xff&skb->data[i]);
714 #elif DUMP_PACKETS >= 1
715 for(i=0;i<skb->len && i < 30;i++) {
716 sprintf(buf+i*3,"%2.2x ", 0xff&skb->data[i]);
718 #endif /* DUMP_PACKETS >= 1 */
722 printk("%s...\n",buf);
723 #endif /* DUMP_PACKETS > 0 */
724 if (memcmp(skb->data, lec_ctrl_magic, 4) ==0) { /* Control frame, to daemon*/
725 struct sock *sk = sk_atm(vcc);
727 DPRINTK("%s: To daemon\n",dev->name);
728 skb_queue_tail(&sk->sk_receive_queue, skb);
729 sk->sk_data_ready(sk, skb->len);
730 } else { /* Data frame, queue to protocol handlers */
733 atm_return(vcc,skb->truesize);
734 if (*(uint16_t *)skb->data == htons(priv->lecid) ||
736 !(dev->flags & IFF_UP)) {
737 /* Probably looping back, or if lecd is missing,
738 lecd has gone down */
739 DPRINTK("Ignoring frame...\n");
744 if (priv->is_trdev) dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
747 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
749 if (!(dst[0]&0x01) && /* Never filter Multi/Broadcast */
750 !priv->is_proxy && /* Proxy wants all the packets */
751 memcmp(dst, dev->dev_addr, dev->addr_len)) {
755 if (priv->lec_arp_empty_ones) {
756 lec_arp_check_empties(priv, vcc, skb);
759 skb_pull(skb, 2); /* skip lec_id */
761 if (priv->is_trdev) skb->protocol = tr_type_trans(skb, dev);
764 skb->protocol = eth_type_trans(skb, dev);
765 priv->stats.rx_packets++;
766 priv->stats.rx_bytes += skb->len;
767 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
773 lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
775 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
776 struct net_device *dev = skb->dev;
779 printk("lec_pop(): vpriv = NULL!?!?!?\n");
783 vpriv->old_pop(vcc, skb);
785 if (vpriv->xoff && atm_may_send(vcc, 0)) {
787 if (netif_running(dev) && netif_queue_stopped(dev))
788 netif_wake_queue(dev);
793 lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
795 struct lec_vcc_priv *vpriv;
797 struct atmlec_ioc ioc_data;
799 /* Lecd must be up in this case */
800 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
801 if (bytes_left != 0) {
802 printk("lec: lec_vcc_attach, copy from user failed for %d bytes\n",
805 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
806 !dev_lec[ioc_data.dev_num])
808 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
811 vpriv->old_pop = vcc->pop;
812 vcc->user_back = vpriv;
814 lec_vcc_added(dev_lec[ioc_data.dev_num]->priv,
815 &ioc_data, vcc, vcc->push);
816 vcc->proto_data = dev_lec[ioc_data.dev_num];
817 vcc->push = lec_push;
822 lec_mcast_attach(struct atm_vcc *vcc, int arg)
824 if (arg <0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
826 vcc->proto_data = dev_lec[arg];
827 return (lec_mcast_make((struct lec_priv*)dev_lec[arg]->priv, vcc));
830 /* Initialize device. */
832 lecd_attach(struct atm_vcc *vcc, int arg)
835 struct lec_priv *priv;
842 if (arg >= MAX_LEC_ITF)
844 #else /* Reserve the top NUM_TR_DEVS for TR */
845 if (arg >= (MAX_LEC_ITF-NUM_TR_DEVS))
852 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
855 size = sizeof(struct lec_priv);
858 dev_lec[i] = alloc_trdev(size);
861 dev_lec[i] = alloc_etherdev(size);
864 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
865 if (register_netdev(dev_lec[i])) {
866 free_netdev(dev_lec[i]);
870 priv = dev_lec[i]->priv;
871 priv->is_trdev = is_trdev;
872 lec_init(dev_lec[i]);
874 priv = dev_lec[i]->priv;
879 priv->itfnum = i; /* LANE2 addition */
881 vcc->dev = &lecatm_dev;
882 vcc_insert_socket(sk_atm(vcc));
884 vcc->proto_data = dev_lec[i];
885 set_bit(ATM_VF_META,&vcc->flags);
886 set_bit(ATM_VF_READY,&vcc->flags);
888 /* Set default values to these variables */
889 priv->maximum_unknown_frame_count = 1;
890 priv->max_unknown_frame_time = (1*HZ);
891 priv->vcc_timeout_period = (1200*HZ);
892 priv->max_retry_count = 1;
893 priv->aging_time = (300*HZ);
894 priv->forward_delay_time = (15*HZ);
895 priv->topology_change = 0;
896 priv->arp_response_time = (1*HZ);
897 priv->flush_timeout = (4*HZ);
898 priv->path_switching_delay = (6*HZ);
900 if (dev_lec[i]->flags & IFF_UP) {
901 netif_start_queue(dev_lec[i]);
903 __module_get(THIS_MODULE);
907 #ifdef CONFIG_PROC_FS
908 static char* lec_arp_get_status_string(unsigned char status)
910 static char *lec_arp_status_string[] = {
915 "ESI_FLUSH_PENDING ",
919 if (status > ESI_FORWARD_DIRECT)
920 status = 3; /* ESI_UNDEFINED */
921 return lec_arp_status_string[status];
924 static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
928 for (i = 0; i < ETH_ALEN; i++)
929 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
930 seq_printf(seq, " ");
931 for (i = 0; i < ATM_ESA_LEN; i++)
932 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
933 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
934 entry->flags & 0xffff);
936 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
938 seq_printf(seq, " ");
939 if (entry->recv_vcc) {
940 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
941 entry->recv_vcc->vci);
949 struct lec_priv *locked;
950 struct lec_arp_table *entry;
951 struct net_device *dev;
957 static void *lec_tbl_walk(struct lec_state *state, struct lec_arp_table *tbl,
960 struct lec_arp_table *e = state->entry;
964 if (e == (void *)1) {
968 for (; e; e = e->next) {
973 return (*l < 0) ? state : NULL;
976 static void *lec_arp_walk(struct lec_state *state, loff_t *l,
977 struct lec_priv *priv)
982 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
983 v = lec_tbl_walk(state, priv->lec_arp_tables[p], l);
987 state->arp_table = p;
991 static void *lec_misc_walk(struct lec_state *state, loff_t *l,
992 struct lec_priv *priv)
994 struct lec_arp_table *lec_misc_tables[] = {
995 priv->lec_arp_empty_ones,
996 priv->lec_no_forward,
1002 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1003 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1007 state->misc_table = q;
1011 static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1012 struct lec_priv *priv)
1014 if (!state->locked) {
1015 state->locked = priv;
1016 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1018 if (!lec_arp_walk(state, l, priv) &&
1019 !lec_misc_walk(state, l, priv)) {
1020 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1021 state->locked = NULL;
1022 /* Partial state reset for the next time we get called */
1023 state->arp_table = state->misc_table = 0;
1025 return state->locked;
1028 static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1030 struct net_device *dev;
1033 dev = state->dev ? state->dev : dev_lec[state->itf];
1034 v = (dev && dev->priv) ? lec_priv_walk(state, l, dev->priv) : NULL;
1037 /* Partial state reset for the next time we get called */
1044 static void *lec_get_idx(struct lec_state *state, loff_t l)
1048 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1049 v = lec_itf_walk(state, &l);
1056 static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1058 struct lec_state *state = seq->private;
1062 state->locked = NULL;
1063 state->arp_table = 0;
1064 state->misc_table = 0;
1065 state->entry = (void *)1;
1067 return *pos ? lec_get_idx(state, *pos) : (void*)1;
1070 static void lec_seq_stop(struct seq_file *seq, void *v)
1072 struct lec_state *state = seq->private;
1075 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1077 dev_put(state->dev);
1081 static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1083 struct lec_state *state = seq->private;
1085 v = lec_get_idx(state, 1);
1086 *pos += !!PTR_ERR(v);
1090 static int lec_seq_show(struct seq_file *seq, void *v)
1092 static char lec_banner[] = "Itf MAC ATM destination"
1094 "VPI/VCI Recv VPI/VCI\n";
1097 seq_puts(seq, lec_banner);
1099 struct lec_state *state = seq->private;
1100 struct net_device *dev = state->dev;
1102 seq_printf(seq, "%s ", dev->name);
1103 lec_info(seq, state->entry);
1108 static struct seq_operations lec_seq_ops = {
1109 .start = lec_seq_start,
1110 .next = lec_seq_next,
1111 .stop = lec_seq_stop,
1112 .show = lec_seq_show,
1115 static int lec_seq_open(struct inode *inode, struct file *file)
1117 struct lec_state *state;
1118 struct seq_file *seq;
1121 state = kmalloc(sizeof(*state), GFP_KERNEL);
1127 rc = seq_open(file, &lec_seq_ops);
1130 seq = file->private_data;
1131 seq->private = state;
1140 static int lec_seq_release(struct inode *inode, struct file *file)
1142 return seq_release_private(inode, file);
1145 static struct file_operations lec_seq_fops = {
1146 .owner = THIS_MODULE,
1147 .open = lec_seq_open,
1149 .llseek = seq_lseek,
1150 .release = lec_seq_release,
1154 static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1156 struct atm_vcc *vcc = ATM_SD(sock);
1163 if (!capable(CAP_NET_ADMIN))
1167 return -ENOIOCTLCMD;
1172 err = lecd_attach(vcc, (int) arg);
1174 sock->state = SS_CONNECTED;
1177 err = lec_mcast_attach(vcc, (int) arg);
1180 err = lec_vcc_attach(vcc, (void __user *) arg);
1187 static struct atm_ioctl lane_ioctl_ops = {
1188 .owner = THIS_MODULE,
1189 .ioctl = lane_ioctl,
1192 static int __init lane_module_init(void)
1194 #ifdef CONFIG_PROC_FS
1195 struct proc_dir_entry *p;
1197 p = create_proc_entry("lec", S_IRUGO, atm_proc_root);
1199 p->proc_fops = &lec_seq_fops;
1202 register_atm_ioctl(&lane_ioctl_ops);
1203 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1207 static void __exit lane_module_cleanup(void)
1210 struct lec_priv *priv;
1212 remove_proc_entry("lec", atm_proc_root);
1214 deregister_atm_ioctl(&lane_ioctl_ops);
1216 for (i = 0; i < MAX_LEC_ITF; i++) {
1217 if (dev_lec[i] != NULL) {
1218 priv = (struct lec_priv *)dev_lec[i]->priv;
1219 unregister_netdev(dev_lec[i]);
1220 free_netdev(dev_lec[i]);
1228 module_init(lane_module_init);
1229 module_exit(lane_module_cleanup);
1232 * LANE2: 3.1.3, LE_RESOLVE.request
1233 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1234 * If sizeoftlvs == NULL the default TLVs associated with with this
1236 * If dst_mac == NULL, targetless LE_ARP will be sent
1238 static int lane2_resolve(struct net_device *dev, u8 *dst_mac, int force,
1239 u8 **tlvs, u32 *sizeoftlvs)
1241 unsigned long flags;
1242 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1243 struct lec_arp_table *table;
1244 struct sk_buff *skb;
1248 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1249 table = lec_arp_find(priv, dst_mac);
1250 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1254 *tlvs = kmalloc(table->sizeoftlvs, GFP_ATOMIC);
1258 memcpy(*tlvs, table->tlvs, table->sizeoftlvs);
1259 *sizeoftlvs = table->sizeoftlvs;
1264 if (sizeoftlvs == NULL)
1265 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
1268 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1271 skb->len = *sizeoftlvs;
1272 memcpy(skb->data, *tlvs, *sizeoftlvs);
1273 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1280 * LANE2: 3.1.4, LE_ASSOCIATE.request
1281 * Associate the *tlvs with the *lan_dst address.
1282 * Will overwrite any previous association
1283 * Returns 1 for success, 0 for failure (out of memory)
1286 static int lane2_associate_req (struct net_device *dev, u8 *lan_dst,
1287 u8 *tlvs, u32 sizeoftlvs)
1290 struct sk_buff *skb;
1291 struct lec_priv *priv = (struct lec_priv*)dev->priv;
1293 if ( memcmp(lan_dst, dev->dev_addr, ETH_ALEN) != 0 )
1294 return (0); /* not our mac address */
1296 kfree(priv->tlvs); /* NULL if there was no previous association */
1298 priv->tlvs = kmalloc(sizeoftlvs, GFP_KERNEL);
1299 if (priv->tlvs == NULL)
1301 priv->sizeoftlvs = sizeoftlvs;
1302 memcpy(priv->tlvs, tlvs, sizeoftlvs);
1304 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1307 skb->len = sizeoftlvs;
1308 memcpy(skb->data, tlvs, sizeoftlvs);
1309 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1311 printk("lec.c: lane2_associate_req() failed\n");
1312 /* If the previous association has changed we must
1313 * somehow notify other LANE entities about the change
1319 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1322 static void lane2_associate_ind (struct net_device *dev, u8 *mac_addr,
1323 u8 *tlvs, u32 sizeoftlvs)
1328 struct lec_priv *priv = (struct lec_priv *)dev->priv;
1329 #if 0 /* Why have the TLVs in LE_ARP entries since we do not use them? When you
1330 uncomment this code, make sure the TLVs get freed when entry is killed */
1331 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
1334 return; /* should not happen */
1338 entry->tlvs = kmalloc(sizeoftlvs, GFP_KERNEL);
1339 if (entry->tlvs == NULL)
1342 entry->sizeoftlvs = sizeoftlvs;
1343 memcpy(entry->tlvs, tlvs, sizeoftlvs);
1346 printk("lec.c: lane2_associate_ind()\n");
1347 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1348 while (i < sizeoftlvs)
1349 printk("%02x ", tlvs[i++]);
1354 /* tell MPOA about the TLVs we saw */
1355 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1356 priv->lane2_ops->associate_indicator(dev, mac_addr,
1363 * Here starts what used to lec_arpc.c
1365 * lec_arpc.c was added here when making
1366 * lane client modular. October 1997
1370 #include <linux/types.h>
1371 #include <linux/sched.h>
1372 #include <linux/timer.h>
1373 #include <asm/param.h>
1374 #include <asm/atomic.h>
1375 #include <linux/inetdevice.h>
1376 #include <net/route.h>
1380 #define DPRINTK(format,args...)
1382 #define DPRINTK printk
1385 #define DEBUG_ARP_TABLE 0
1387 #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1389 static void lec_arp_check_expire(unsigned long data);
1390 static void lec_arp_expire_arp(unsigned long data);
1396 #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1399 * Initialization of arp-cache
1402 lec_arp_init(struct lec_priv *priv)
1406 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1407 priv->lec_arp_tables[i] = NULL;
1409 spin_lock_init(&priv->lec_arp_lock);
1410 init_timer(&priv->lec_arp_timer);
1411 priv->lec_arp_timer.expires = jiffies + LEC_ARP_REFRESH_INTERVAL;
1412 priv->lec_arp_timer.data = (unsigned long)priv;
1413 priv->lec_arp_timer.function = lec_arp_check_expire;
1414 add_timer(&priv->lec_arp_timer);
1418 lec_arp_clear_vccs(struct lec_arp_table *entry)
1421 struct atm_vcc *vcc = entry->vcc;
1422 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
1423 struct net_device *dev = (struct net_device*) vcc->proto_data;
1425 vcc->pop = vpriv->old_pop;
1427 netif_wake_queue(dev);
1429 vcc->user_back = NULL;
1430 vcc->push = entry->old_push;
1431 vcc_release_async(vcc, -EPIPE);
1434 if (entry->recv_vcc) {
1435 entry->recv_vcc->push = entry->old_recv_push;
1436 vcc_release_async(entry->recv_vcc, -EPIPE);
1437 entry->recv_vcc = NULL;
1442 * Insert entry to lec_arp_table
1443 * LANE2: Add to the end of the list to satisfy 8.1.13
1446 lec_arp_add(struct lec_priv *priv, struct lec_arp_table *to_add)
1448 unsigned short place;
1449 struct lec_arp_table *tmp;
1451 place = HASH(to_add->mac_addr[ETH_ALEN-1]);
1452 tmp = priv->lec_arp_tables[place];
1453 to_add->next = NULL;
1455 priv->lec_arp_tables[place] = to_add;
1457 else { /* add to the end */
1463 DPRINTK("LEC_ARP: Added entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1464 0xff&to_add->mac_addr[0], 0xff&to_add->mac_addr[1],
1465 0xff&to_add->mac_addr[2], 0xff&to_add->mac_addr[3],
1466 0xff&to_add->mac_addr[4], 0xff&to_add->mac_addr[5]);
1470 * Remove entry from lec_arp_table
1473 lec_arp_remove(struct lec_priv *priv,
1474 struct lec_arp_table *to_remove)
1476 unsigned short place;
1477 struct lec_arp_table *tmp;
1483 place = HASH(to_remove->mac_addr[ETH_ALEN-1]);
1484 tmp = priv->lec_arp_tables[place];
1485 if (tmp == to_remove) {
1486 priv->lec_arp_tables[place] = tmp->next;
1488 while(tmp && tmp->next != to_remove) {
1491 if (!tmp) {/* Entry was not found */
1495 tmp->next = to_remove->next;
1496 del_timer(&to_remove->timer);
1498 /* If this is the only MAC connected to this VCC, also tear down
1500 if (to_remove->status >= ESI_FLUSH_PENDING) {
1502 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1504 for(place = 0; place < LEC_ARP_TABLE_SIZE; place++) {
1505 for(tmp = priv->lec_arp_tables[place]; tmp != NULL; tmp = tmp->next) {
1506 if (memcmp(tmp->atm_addr, to_remove->atm_addr,
1514 lec_arp_clear_vccs(to_remove);
1516 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1518 DPRINTK("LEC_ARP: Removed entry:%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1519 0xff&to_remove->mac_addr[0], 0xff&to_remove->mac_addr[1],
1520 0xff&to_remove->mac_addr[2], 0xff&to_remove->mac_addr[3],
1521 0xff&to_remove->mac_addr[4], 0xff&to_remove->mac_addr[5]);
1527 get_status_string(unsigned char st)
1531 return "ESI_UNKNOWN";
1532 case ESI_ARP_PENDING:
1533 return "ESI_ARP_PENDING";
1534 case ESI_VC_PENDING:
1535 return "ESI_VC_PENDING";
1536 case ESI_FLUSH_PENDING:
1537 return "ESI_FLUSH_PENDING";
1538 case ESI_FORWARD_DIRECT:
1539 return "ESI_FORWARD_DIRECT";
1547 dump_arp_table(struct lec_priv *priv)
1551 struct lec_arp_table *rulla;
1553 struct lec_arp_table **lec_arp_tables =
1554 (struct lec_arp_table **)priv->lec_arp_tables;
1555 struct lec_arp_table *lec_arp_empty_ones =
1556 (struct lec_arp_table *)priv->lec_arp_empty_ones;
1557 struct lec_arp_table *lec_no_forward =
1558 (struct lec_arp_table *)priv->lec_no_forward;
1559 struct lec_arp_table *mcast_fwds = priv->mcast_fwds;
1562 printk("Dump %p:\n",priv);
1563 for (i=0;i<LEC_ARP_TABLE_SIZE;i++) {
1564 rulla = lec_arp_tables[i];
1566 offset += sprintf(buf,"%d: %p\n",i, rulla);
1568 offset += sprintf(buf+offset,"Mac:");
1569 for(j=0;j<ETH_ALEN;j++) {
1570 offset+=sprintf(buf+offset,
1572 rulla->mac_addr[j]&0xff);
1574 offset +=sprintf(buf+offset,"Atm:");
1575 for(j=0;j<ATM_ESA_LEN;j++) {
1576 offset+=sprintf(buf+offset,
1578 rulla->atm_addr[j]&0xff);
1580 offset+=sprintf(buf+offset,
1581 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1582 rulla->vcc?rulla->vcc->vpi:0,
1583 rulla->vcc?rulla->vcc->vci:0,
1584 rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1585 rulla->recv_vcc?rulla->recv_vcc->vci:0,
1587 rulla->timestamp, rulla->no_tries);
1588 offset+=sprintf(buf+offset,
1589 "Flags:%x, Packets_flooded:%x, Status: %s ",
1590 rulla->flags, rulla->packets_flooded,
1591 get_status_string(rulla->status));
1592 offset+=sprintf(buf+offset,"->%p\n",rulla->next);
1593 rulla = rulla->next;
1597 rulla = lec_no_forward;
1599 printk("No forward\n");
1602 offset += sprintf(buf+offset,"Mac:");
1603 for(j=0;j<ETH_ALEN;j++) {
1604 offset+=sprintf(buf+offset,"%2.2x ",
1605 rulla->mac_addr[j]&0xff);
1607 offset +=sprintf(buf+offset,"Atm:");
1608 for(j=0;j<ATM_ESA_LEN;j++) {
1609 offset+=sprintf(buf+offset,"%2.2x ",
1610 rulla->atm_addr[j]&0xff);
1612 offset+=sprintf(buf+offset,
1613 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1614 rulla->vcc?rulla->vcc->vpi:0,
1615 rulla->vcc?rulla->vcc->vci:0,
1616 rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1617 rulla->recv_vcc?rulla->recv_vcc->vci:0,
1619 rulla->timestamp, rulla->no_tries);
1620 offset+=sprintf(buf+offset,
1621 "Flags:%x, Packets_flooded:%x, Status: %s ",
1622 rulla->flags, rulla->packets_flooded,
1623 get_status_string(rulla->status));
1624 offset+=sprintf(buf+offset,"->%lx\n",(long)rulla->next);
1625 rulla = rulla->next;
1628 rulla = lec_arp_empty_ones;
1630 printk("Empty ones\n");
1633 offset += sprintf(buf+offset,"Mac:");
1634 for(j=0;j<ETH_ALEN;j++) {
1635 offset+=sprintf(buf+offset,"%2.2x ",
1636 rulla->mac_addr[j]&0xff);
1638 offset +=sprintf(buf+offset,"Atm:");
1639 for(j=0;j<ATM_ESA_LEN;j++) {
1640 offset+=sprintf(buf+offset,"%2.2x ",
1641 rulla->atm_addr[j]&0xff);
1643 offset+=sprintf(buf+offset,
1644 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1645 rulla->vcc?rulla->vcc->vpi:0,
1646 rulla->vcc?rulla->vcc->vci:0,
1647 rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1648 rulla->recv_vcc?rulla->recv_vcc->vci:0,
1650 rulla->timestamp, rulla->no_tries);
1651 offset+=sprintf(buf+offset,
1652 "Flags:%x, Packets_flooded:%x, Status: %s ",
1653 rulla->flags, rulla->packets_flooded,
1654 get_status_string(rulla->status));
1655 offset+=sprintf(buf+offset,"->%lx\n",(long)rulla->next);
1656 rulla = rulla->next;
1662 printk("Multicast Forward VCCs\n");
1665 offset += sprintf(buf+offset,"Mac:");
1666 for(j=0;j<ETH_ALEN;j++) {
1667 offset+=sprintf(buf+offset,"%2.2x ",
1668 rulla->mac_addr[j]&0xff);
1670 offset +=sprintf(buf+offset,"Atm:");
1671 for(j=0;j<ATM_ESA_LEN;j++) {
1672 offset+=sprintf(buf+offset,"%2.2x ",
1673 rulla->atm_addr[j]&0xff);
1675 offset+=sprintf(buf+offset,
1676 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1677 rulla->vcc?rulla->vcc->vpi:0,
1678 rulla->vcc?rulla->vcc->vci:0,
1679 rulla->recv_vcc?rulla->recv_vcc->vpi:0,
1680 rulla->recv_vcc?rulla->recv_vcc->vci:0,
1682 rulla->timestamp, rulla->no_tries);
1683 offset+=sprintf(buf+offset,
1684 "Flags:%x, Packets_flooded:%x, Status: %s ",
1685 rulla->flags, rulla->packets_flooded,
1686 get_status_string(rulla->status));
1687 offset+=sprintf(buf+offset,"->%lx\n",(long)rulla->next);
1688 rulla = rulla->next;
1696 * Destruction of arp-cache
1699 lec_arp_destroy(struct lec_priv *priv)
1701 unsigned long flags;
1702 struct lec_arp_table *entry, *next;
1705 del_timer_sync(&priv->lec_arp_timer);
1708 * Remove all entries
1711 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1712 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1713 for(entry = priv->lec_arp_tables[i]; entry != NULL; entry=next) {
1715 lec_arp_remove(priv, entry);
1719 entry = priv->lec_arp_empty_ones;
1722 del_timer_sync(&entry->timer);
1723 lec_arp_clear_vccs(entry);
1727 priv->lec_arp_empty_ones = NULL;
1728 entry = priv->lec_no_forward;
1731 del_timer_sync(&entry->timer);
1732 lec_arp_clear_vccs(entry);
1736 priv->lec_no_forward = NULL;
1737 entry = priv->mcast_fwds;
1740 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1741 lec_arp_clear_vccs(entry);
1745 priv->mcast_fwds = NULL;
1746 priv->mcast_vcc = NULL;
1747 memset(priv->lec_arp_tables, 0,
1748 sizeof(struct lec_arp_table *) * LEC_ARP_TABLE_SIZE);
1749 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1754 * Find entry by mac_address
1756 static struct lec_arp_table*
1757 lec_arp_find(struct lec_priv *priv,
1758 unsigned char *mac_addr)
1760 unsigned short place;
1761 struct lec_arp_table *to_return;
1763 DPRINTK("LEC_ARP: lec_arp_find :%2.2x %2.2x %2.2x %2.2x %2.2x %2.2x\n",
1764 mac_addr[0]&0xff, mac_addr[1]&0xff, mac_addr[2]&0xff,
1765 mac_addr[3]&0xff, mac_addr[4]&0xff, mac_addr[5]&0xff);
1766 place = HASH(mac_addr[ETH_ALEN-1]);
1768 to_return = priv->lec_arp_tables[place];
1770 if (memcmp(mac_addr, to_return->mac_addr, ETH_ALEN) == 0) {
1773 to_return = to_return->next;
1778 static struct lec_arp_table*
1779 make_entry(struct lec_priv *priv, unsigned char *mac_addr)
1781 struct lec_arp_table *to_return;
1783 to_return = (struct lec_arp_table *) kmalloc(sizeof(struct lec_arp_table),
1786 printk("LEC: Arp entry kmalloc failed\n");
1789 memset(to_return, 0, sizeof(struct lec_arp_table));
1790 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
1791 init_timer(&to_return->timer);
1792 to_return->timer.function = lec_arp_expire_arp;
1793 to_return->timer.data = (unsigned long) to_return;
1794 to_return->last_used = jiffies;
1795 to_return->priv = priv;
1796 skb_queue_head_init(&to_return->tx_wait);
1802 * Arp sent timer expired
1806 lec_arp_expire_arp(unsigned long data)
1808 struct lec_arp_table *entry;
1810 entry = (struct lec_arp_table *)data;
1812 DPRINTK("lec_arp_expire_arp\n");
1813 if (entry->status == ESI_ARP_PENDING) {
1814 if (entry->no_tries <= entry->priv->max_retry_count) {
1815 if (entry->is_rdesc)
1816 send_to_lecd(entry->priv, l_rdesc_arp_xmt, entry->mac_addr, NULL, NULL);
1818 send_to_lecd(entry->priv, l_arp_xmt, entry->mac_addr, NULL, NULL);
1821 mod_timer(&entry->timer, jiffies + (1*HZ));
1827 * Unknown/unused vcc expire, remove associated entry
1831 lec_arp_expire_vcc(unsigned long data)
1833 unsigned long flags;
1834 struct lec_arp_table *to_remove = (struct lec_arp_table*)data;
1835 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
1836 struct lec_arp_table *entry = NULL;
1838 del_timer(&to_remove->timer);
1840 DPRINTK("LEC_ARP %p %p: lec_arp_expire_vcc vpi:%d vci:%d\n",
1842 to_remove->vcc?to_remove->recv_vcc->vpi:0,
1843 to_remove->vcc?to_remove->recv_vcc->vci:0);
1844 DPRINTK("eo:%p nf:%p\n",priv->lec_arp_empty_ones,priv->lec_no_forward);
1846 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1847 if (to_remove == priv->lec_arp_empty_ones)
1848 priv->lec_arp_empty_ones = to_remove->next;
1850 entry = priv->lec_arp_empty_ones;
1851 while (entry && entry->next != to_remove)
1852 entry = entry->next;
1854 entry->next = to_remove->next;
1857 if (to_remove == priv->lec_no_forward) {
1858 priv->lec_no_forward = to_remove->next;
1860 entry = priv->lec_no_forward;
1861 while (entry && entry->next != to_remove)
1862 entry = entry->next;
1864 entry->next = to_remove->next;
1867 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
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 unsigned long flags;
1893 struct lec_priv *priv = (struct lec_priv *)data;
1894 struct lec_arp_table *entry, *next;
1896 unsigned long time_to_check;
1899 DPRINTK("lec_arp_check_expire %p\n",priv);
1900 DPRINTK("expire: eo:%p nf:%p\n",priv->lec_arp_empty_ones,
1901 priv->lec_no_forward);
1903 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1904 for(i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1905 for(entry = priv->lec_arp_tables[i]; entry != NULL; ) {
1906 if ((entry->flags) & LEC_REMOTE_FLAG &&
1907 priv->topology_change)
1908 time_to_check = priv->forward_delay_time;
1910 time_to_check = priv->aging_time;
1912 DPRINTK("About to expire: %lx - %lx > %lx\n",
1913 now,entry->last_used, time_to_check);
1914 if( time_after(now, entry->last_used+
1916 !(entry->flags & LEC_PERMANENT_FLAG) &&
1917 !(entry->mac_addr[0] & 0x01) ) { /* LANE2: 7.1.20 */
1919 DPRINTK("LEC:Entry timed out\n");
1921 lec_arp_remove(priv, entry);
1925 /* Something else */
1926 if ((entry->status == ESI_VC_PENDING ||
1927 entry->status == ESI_ARP_PENDING)
1928 && time_after_eq(now,
1930 priv->max_unknown_frame_time)) {
1931 entry->timestamp = jiffies;
1932 entry->packets_flooded = 0;
1933 if (entry->status == ESI_VC_PENDING)
1934 send_to_lecd(priv, l_svc_setup, entry->mac_addr, entry->atm_addr, NULL);
1936 if (entry->status == ESI_FLUSH_PENDING
1938 time_after_eq(now, entry->timestamp+
1939 priv->path_switching_delay)) {
1940 struct sk_buff *skb;
1942 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
1943 lec_send(entry->vcc, skb, entry->priv);
1944 entry->last_used = jiffies;
1948 entry = entry->next;
1952 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1954 mod_timer(&priv->lec_arp_timer, jiffies + LEC_ARP_REFRESH_INTERVAL);
1957 * Try to find vcc where mac_address is attached.
1960 static struct atm_vcc*
1961 lec_arp_resolve(struct lec_priv *priv, unsigned char *mac_to_find,
1962 int is_rdesc, struct lec_arp_table **ret_entry)
1964 unsigned long flags;
1965 struct lec_arp_table *entry;
1966 struct atm_vcc *found;
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 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1983 entry = lec_arp_find(priv, mac_to_find);
1986 if (entry->status == ESI_FORWARD_DIRECT) {
1988 entry->last_used = jiffies;
1993 /* Data direct VC not yet set up, check to see if the unknown
1994 frame count is greater than the limit. If the limit has
1995 not been reached, allow the caller to send packet to
1997 if (entry->status != ESI_FLUSH_PENDING &&
1998 entry->packets_flooded<priv->maximum_unknown_frame_count) {
1999 entry->packets_flooded++;
2000 DPRINTK("LEC_ARP: Flooding..\n");
2001 found = priv->mcast_vcc;
2004 /* We got here because entry->status == ESI_FLUSH_PENDING
2005 * or BUS flood limit was reached for an entry which is
2006 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
2009 DPRINTK("lec: entry->status %d entry->vcc %p\n", entry->status, entry->vcc);
2012 /* No matching entry was found */
2013 entry = make_entry(priv, mac_to_find);
2014 DPRINTK("LEC_ARP: Making entry\n");
2016 found = priv->mcast_vcc;
2019 lec_arp_add(priv, entry);
2020 /* We want arp-request(s) to be sent */
2021 entry->packets_flooded =1;
2022 entry->status = ESI_ARP_PENDING;
2023 entry->no_tries = 1;
2024 entry->last_used = entry->timestamp = jiffies;
2025 entry->is_rdesc = is_rdesc;
2026 if (entry->is_rdesc)
2027 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL, NULL);
2029 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
2030 entry->timer.expires = jiffies + (1*HZ);
2031 entry->timer.function = lec_arp_expire_arp;
2032 add_timer(&entry->timer);
2033 found = priv->mcast_vcc;
2037 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2042 lec_addr_delete(struct lec_priv *priv, unsigned char *atm_addr,
2043 unsigned long permanent)
2045 unsigned long flags;
2046 struct lec_arp_table *entry, *next;
2049 DPRINTK("lec_addr_delete\n");
2050 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2051 for(i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2052 for(entry = priv->lec_arp_tables[i]; entry != NULL; entry = next) {
2054 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
2056 !(entry->flags & LEC_PERMANENT_FLAG))) {
2057 lec_arp_remove(priv, entry);
2060 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2064 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2069 * Notifies: Response to arp_request (atm_addr != NULL)
2072 lec_arp_update(struct lec_priv *priv, unsigned char *mac_addr,
2073 unsigned char *atm_addr, unsigned long remoteflag,
2074 unsigned int targetless_le_arp)
2076 unsigned long flags;
2077 struct lec_arp_table *entry, *tmp;
2080 DPRINTK("lec:%s", (targetless_le_arp) ? "targetless ": " ");
2081 DPRINTK("lec_arp_update mac:%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x\n",
2082 mac_addr[0],mac_addr[1],mac_addr[2],mac_addr[3],
2083 mac_addr[4],mac_addr[5]);
2085 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2086 entry = lec_arp_find(priv, mac_addr);
2087 if (entry == NULL && targetless_le_arp)
2088 goto out; /* LANE2: ignore targetless LE_ARPs for which
2089 * we have no entry in the cache. 7.1.30
2091 if (priv->lec_arp_empty_ones) {
2092 entry = priv->lec_arp_empty_ones;
2093 if (!memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN)) {
2094 priv->lec_arp_empty_ones = entry->next;
2096 while(entry->next && memcmp(entry->next->atm_addr,
2097 atm_addr, ATM_ESA_LEN))
2098 entry = entry->next;
2101 entry = entry->next;
2102 tmp->next = entry->next;
2108 del_timer(&entry->timer);
2109 tmp = lec_arp_find(priv, mac_addr);
2111 del_timer(&tmp->timer);
2112 tmp->status = ESI_FORWARD_DIRECT;
2113 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2114 tmp->vcc = entry->vcc;
2115 tmp->old_push = entry->old_push;
2116 tmp->last_used = jiffies;
2117 del_timer(&entry->timer);
2121 entry->status = ESI_FORWARD_DIRECT;
2122 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2123 entry->last_used = jiffies;
2124 lec_arp_add(priv, entry);
2127 entry->flags|=LEC_REMOTE_FLAG;
2129 entry->flags&=~LEC_REMOTE_FLAG;
2130 DPRINTK("After update\n");
2131 dump_arp_table(priv);
2135 entry = lec_arp_find(priv, mac_addr);
2137 entry = make_entry(priv, mac_addr);
2140 entry->status = ESI_UNKNOWN;
2141 lec_arp_add(priv, entry);
2142 /* Temporary, changes before end of function */
2144 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2145 del_timer(&entry->timer);
2146 for(i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2147 for(tmp = priv->lec_arp_tables[i]; tmp; tmp=tmp->next) {
2149 !memcmp(tmp->atm_addr, atm_addr,
2151 /* Vcc to this host exists */
2152 if (tmp->status > ESI_VC_PENDING) {
2154 * ESI_FLUSH_PENDING,
2155 * ESI_FORWARD_DIRECT
2157 entry->vcc = tmp->vcc;
2158 entry->old_push=tmp->old_push;
2160 entry->status=tmp->status;
2166 entry->flags|=LEC_REMOTE_FLAG;
2168 entry->flags&=~LEC_REMOTE_FLAG;
2169 if (entry->status == ESI_ARP_PENDING ||
2170 entry->status == ESI_UNKNOWN) {
2171 entry->status = ESI_VC_PENDING;
2172 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
2174 DPRINTK("After update2\n");
2175 dump_arp_table(priv);
2177 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2181 * Notifies: Vcc setup ready
2184 lec_vcc_added(struct lec_priv *priv, struct atmlec_ioc *ioc_data,
2185 struct atm_vcc *vcc,
2186 void (*old_push)(struct atm_vcc *vcc, struct sk_buff *skb))
2188 unsigned long flags;
2189 struct lec_arp_table *entry;
2190 int i, found_entry=0;
2192 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2193 if (ioc_data->receive == 2) {
2194 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
2196 DPRINTK("LEC_ARP: Attaching mcast forward\n");
2198 entry = lec_arp_find(priv, bus_mac);
2200 printk("LEC_ARP: Multicast entry not found!\n");
2203 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2204 entry->recv_vcc = vcc;
2205 entry->old_recv_push = old_push;
2207 entry = make_entry(priv, bus_mac);
2210 del_timer(&entry->timer);
2211 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2212 entry->recv_vcc = vcc;
2213 entry->old_recv_push = old_push;
2214 entry->next = priv->mcast_fwds;
2215 priv->mcast_fwds = entry;
2217 } else if (ioc_data->receive == 1) {
2218 /* Vcc which we don't want to make default vcc, attach it
2220 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",
2221 ioc_data->atm_addr[0],ioc_data->atm_addr[1],
2222 ioc_data->atm_addr[2],ioc_data->atm_addr[3],
2223 ioc_data->atm_addr[4],ioc_data->atm_addr[5],
2224 ioc_data->atm_addr[6],ioc_data->atm_addr[7],
2225 ioc_data->atm_addr[8],ioc_data->atm_addr[9],
2226 ioc_data->atm_addr[10],ioc_data->atm_addr[11],
2227 ioc_data->atm_addr[12],ioc_data->atm_addr[13],
2228 ioc_data->atm_addr[14],ioc_data->atm_addr[15],
2229 ioc_data->atm_addr[16],ioc_data->atm_addr[17],
2230 ioc_data->atm_addr[18],ioc_data->atm_addr[19]);
2231 entry = make_entry(priv, bus_mac);
2234 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2235 memset(entry->mac_addr, 0, ETH_ALEN);
2236 entry->recv_vcc = vcc;
2237 entry->old_recv_push = old_push;
2238 entry->status = ESI_UNKNOWN;
2239 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2240 entry->timer.function = lec_arp_expire_vcc;
2241 add_timer(&entry->timer);
2242 entry->next = priv->lec_no_forward;
2243 priv->lec_no_forward = entry;
2244 dump_arp_table(priv);
2247 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",
2248 ioc_data->atm_addr[0],ioc_data->atm_addr[1],
2249 ioc_data->atm_addr[2],ioc_data->atm_addr[3],
2250 ioc_data->atm_addr[4],ioc_data->atm_addr[5],
2251 ioc_data->atm_addr[6],ioc_data->atm_addr[7],
2252 ioc_data->atm_addr[8],ioc_data->atm_addr[9],
2253 ioc_data->atm_addr[10],ioc_data->atm_addr[11],
2254 ioc_data->atm_addr[12],ioc_data->atm_addr[13],
2255 ioc_data->atm_addr[14],ioc_data->atm_addr[15],
2256 ioc_data->atm_addr[16],ioc_data->atm_addr[17],
2257 ioc_data->atm_addr[18],ioc_data->atm_addr[19]);
2258 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2259 for (entry = priv->lec_arp_tables[i]; entry; entry=entry->next) {
2260 if (memcmp(ioc_data->atm_addr, entry->atm_addr,
2262 DPRINTK("LEC_ARP: Attaching data direct\n");
2263 DPRINTK("Currently -> Vcc: %d, Rvcc:%d\n",
2264 entry->vcc?entry->vcc->vci:0,
2265 entry->recv_vcc?entry->recv_vcc->vci:0);
2267 del_timer(&entry->timer);
2269 entry->old_push = old_push;
2270 if (entry->status == ESI_VC_PENDING) {
2271 if(priv->maximum_unknown_frame_count
2276 entry->timestamp = jiffies;
2280 send_to_lecd(priv,l_flush_xmt,
2287 /* They were forming a connection
2288 to us, and we to them. Our
2289 ATM address is numerically lower
2290 than theirs, so we make connection
2291 we formed into default VCC (8.1.11).
2292 Connection they made gets torn
2293 down. This might confuse some
2294 clients. Can be changed if
2295 someone reports trouble... */
2302 DPRINTK("After vcc was added\n");
2303 dump_arp_table(priv);
2306 /* Not found, snatch address from first data packet that arrives from
2308 entry = make_entry(priv, bus_mac);
2312 entry->old_push = old_push;
2313 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2314 memset(entry->mac_addr, 0, ETH_ALEN);
2315 entry->status = ESI_UNKNOWN;
2316 entry->next = priv->lec_arp_empty_ones;
2317 priv->lec_arp_empty_ones = entry;
2318 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2319 entry->timer.function = lec_arp_expire_vcc;
2320 add_timer(&entry->timer);
2321 DPRINTK("After vcc was added\n");
2322 dump_arp_table(priv);
2324 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2328 lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
2330 unsigned long flags;
2331 struct lec_arp_table *entry;
2334 DPRINTK("LEC:lec_flush_complete %lx\n",tran_id);
2335 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2336 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2337 for (entry = priv->lec_arp_tables[i]; entry; entry=entry->next) {
2338 if (entry->flush_tran_id == tran_id &&
2339 entry->status == ESI_FLUSH_PENDING) {
2340 struct sk_buff *skb;
2342 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
2343 lec_send(entry->vcc, skb, entry->priv);
2344 entry->status = ESI_FORWARD_DIRECT;
2345 DPRINTK("LEC_ARP: Flushed\n");
2349 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2350 dump_arp_table(priv);
2354 lec_set_flush_tran_id(struct lec_priv *priv,
2355 unsigned char *atm_addr, unsigned long tran_id)
2357 unsigned long flags;
2358 struct lec_arp_table *entry;
2361 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2362 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
2363 for(entry = priv->lec_arp_tables[i]; entry; entry=entry->next)
2364 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2365 entry->flush_tran_id = tran_id;
2366 DPRINTK("Set flush transaction id to %lx for %p\n",tran_id,entry);
2368 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2372 lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
2374 unsigned long flags;
2375 unsigned char mac_addr[] = {
2376 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2377 struct lec_arp_table *to_add;
2378 struct lec_vcc_priv *vpriv;
2381 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2384 vpriv->old_pop = vcc->pop;
2385 vcc->user_back = vpriv;
2387 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2388 to_add = make_entry(priv, mac_addr);
2390 vcc->pop = vpriv->old_pop;
2395 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2396 to_add->status = ESI_FORWARD_DIRECT;
2397 to_add->flags |= LEC_PERMANENT_FLAG;
2399 to_add->old_push = vcc->push;
2400 vcc->push = lec_push;
2401 priv->mcast_vcc = vcc;
2402 lec_arp_add(priv, to_add);
2404 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2409 lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
2411 unsigned long flags;
2412 struct lec_arp_table *entry, *next;
2415 DPRINTK("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n",vcc->vpi,vcc->vci);
2416 dump_arp_table(priv);
2417 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2418 for(i=0;i<LEC_ARP_TABLE_SIZE;i++) {
2419 for(entry = priv->lec_arp_tables[i];entry; entry=next) {
2421 if (vcc == entry->vcc) {
2422 lec_arp_remove(priv, entry);
2424 if (priv->mcast_vcc == vcc) {
2425 priv->mcast_vcc = NULL;
2431 entry = priv->lec_arp_empty_ones;
2432 priv->lec_arp_empty_ones = NULL;
2433 while (entry != NULL) {
2435 if (entry->vcc == vcc) { /* leave it out from the list */
2436 lec_arp_clear_vccs(entry);
2437 del_timer(&entry->timer);
2440 else { /* put it back to the list */
2441 entry->next = priv->lec_arp_empty_ones;
2442 priv->lec_arp_empty_ones = entry;
2447 entry = priv->lec_no_forward;
2448 priv->lec_no_forward = NULL;
2449 while (entry != NULL) {
2451 if (entry->recv_vcc == vcc) {
2452 lec_arp_clear_vccs(entry);
2453 del_timer(&entry->timer);
2457 entry->next = priv->lec_no_forward;
2458 priv->lec_no_forward = entry;
2463 entry = priv->mcast_fwds;
2464 priv->mcast_fwds = NULL;
2465 while (entry != NULL) {
2467 if (entry->recv_vcc == vcc) {
2468 lec_arp_clear_vccs(entry);
2469 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
2473 entry->next = priv->mcast_fwds;
2474 priv->mcast_fwds = entry;
2479 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2480 dump_arp_table(priv);
2484 lec_arp_check_empties(struct lec_priv *priv,
2485 struct atm_vcc *vcc, struct sk_buff *skb)
2487 unsigned long flags;
2488 struct lec_arp_table *entry, *prev;
2489 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2492 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
2494 if (priv->is_trdev) src = tr_hdr->h_source;
2497 src = hdr->h_source;
2499 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2500 entry = priv->lec_arp_empty_ones;
2501 if (vcc == entry->vcc) {
2502 del_timer(&entry->timer);
2503 memcpy(entry->mac_addr, src, ETH_ALEN);
2504 entry->status = ESI_FORWARD_DIRECT;
2505 entry->last_used = jiffies;
2506 priv->lec_arp_empty_ones = entry->next;
2507 /* We might have got an entry */
2508 if ((prev = lec_arp_find(priv,src))) {
2509 lec_arp_remove(priv, prev);
2512 lec_arp_add(priv, entry);
2516 entry = entry->next;
2517 while (entry && entry->vcc != vcc) {
2519 entry = entry->next;
2522 DPRINTK("LEC_ARP: Arp_check_empties: entry not found!\n");
2525 del_timer(&entry->timer);
2526 memcpy(entry->mac_addr, src, ETH_ALEN);
2527 entry->status = ESI_FORWARD_DIRECT;
2528 entry->last_used = jiffies;
2529 prev->next = entry->next;
2530 if ((prev = lec_arp_find(priv, src))) {
2531 lec_arp_remove(priv, prev);
2534 lec_arp_add(priv, entry);
2536 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2538 MODULE_LICENSE("GPL");