2 * lec.c: Lan Emulation driver
4 * Marko Kiiskila <mkiiskila@yahoo.com>
7 #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
9 #include <linux/kernel.h>
10 #include <linux/bitops.h>
11 #include <linux/capability.h>
13 /* We are ethernet device */
14 #include <linux/if_ether.h>
15 #include <linux/netdevice.h>
16 #include <linux/etherdevice.h>
18 #include <linux/skbuff.h>
20 #include <asm/byteorder.h>
21 #include <asm/uaccess.h>
24 #include <linux/proc_fs.h>
25 #include <linux/spinlock.h>
26 #include <linux/seq_file.h>
28 /* TokenRing if needed */
30 #include <linux/trdevice.h>
34 #include <linux/atmdev.h>
35 #include <linux/atmlec.h>
37 /* Proxy LEC knows about bridging */
38 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
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"
52 #define DUMP_PACKETS 0 /*
58 #define LEC_UNRES_QUE_LEN 8 /*
59 * number of tx packets to queue for a
60 * single destination while waiting for SVC
63 static int lec_open(struct net_device *dev);
64 static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
65 struct net_device *dev);
66 static int lec_close(struct net_device *dev);
67 static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
68 const unsigned char *mac_addr);
69 static int lec_arp_remove(struct lec_priv *priv,
70 struct lec_arp_table *to_remove);
72 static void lane2_associate_ind(struct net_device *dev, const u8 *mac_address,
73 const u8 *tlvs, u32 sizeoftlvs);
74 static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
75 u8 **tlvs, u32 *sizeoftlvs);
76 static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
77 const u8 *tlvs, u32 sizeoftlvs);
79 static int lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
80 unsigned long permanent);
81 static void lec_arp_check_empties(struct lec_priv *priv,
82 struct atm_vcc *vcc, struct sk_buff *skb);
83 static void lec_arp_destroy(struct lec_priv *priv);
84 static void lec_arp_init(struct lec_priv *priv);
85 static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
86 const unsigned char *mac_to_find,
88 struct lec_arp_table **ret_entry);
89 static void lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
90 const unsigned char *atm_addr, unsigned long remoteflag,
91 unsigned int targetless_le_arp);
92 static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
93 static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
94 static void lec_set_flush_tran_id(struct lec_priv *priv,
95 const unsigned char *atm_addr,
96 unsigned long tran_id);
97 static void lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
99 void (*old_push) (struct atm_vcc *vcc,
100 struct sk_buff *skb));
101 static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
103 /* must be done under lec_arp_lock */
104 static inline void lec_arp_hold(struct lec_arp_table *entry)
106 atomic_inc(&entry->usage);
109 static inline void lec_arp_put(struct lec_arp_table *entry)
111 if (atomic_dec_and_test(&entry->usage))
116 static struct lane2_ops lane2_ops = {
117 lane2_resolve, /* resolve, spec 3.1.3 */
118 lane2_associate_req, /* associate_req, spec 3.1.4 */
119 NULL /* associate indicator, spec 3.1.5 */
122 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
124 /* Device structures */
125 static struct net_device *dev_lec[MAX_LEC_ITF];
127 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
128 static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
132 struct lec_priv *priv;
135 * Check if this is a BPDU. If so, ask zeppelin to send
136 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
137 * as the Config BPDU has
139 eth = (struct ethhdr *)skb->data;
140 buff = skb->data + skb->dev->hard_header_len;
141 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
143 struct sk_buff *skb2;
144 struct atmlec_msg *mesg;
146 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
149 skb2->len = sizeof(struct atmlec_msg);
150 mesg = (struct atmlec_msg *)skb2->data;
151 mesg->type = l_topology_change;
153 mesg->content.normal.flag = *buff & 0x01; /* 0x01 is topology change */
155 priv = netdev_priv(dev);
156 atm_force_charge(priv->lecd, skb2->truesize);
157 sk = sk_atm(priv->lecd);
158 skb_queue_tail(&sk->sk_receive_queue, skb2);
159 sk->sk_data_ready(sk, skb2->len);
164 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
167 * Modelled after tr_type_trans
168 * All multicast and ARE or STE frames go to BUS.
169 * Non source routed frames go by destination address.
170 * Last hop source routed frames go by destination address.
171 * Not last hop source routed frames go by _next_ route descriptor.
172 * Returns pointer to destination MAC address or fills in rdesc
176 static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
179 unsigned int riflen, num_rdsc;
181 trh = (struct trh_hdr *)packet;
182 if (trh->daddr[0] & (uint8_t) 0x80)
183 return bus_mac; /* multicast */
185 if (trh->saddr[0] & TR_RII) {
186 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
187 if ((ntohs(trh->rcf) >> 13) != 0)
188 return bus_mac; /* ARE or STE */
190 return trh->daddr; /* not source routed */
193 return trh->daddr; /* last hop, source routed */
195 /* riflen is 6 or more, packet has more than one route descriptor */
196 num_rdsc = (riflen / 2) - 1;
197 memset(rdesc, 0, ETH_ALEN);
198 /* offset 4 comes from LAN destination field in LE control frames */
199 if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
200 memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16));
202 memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16));
203 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
208 #endif /* CONFIG_TR */
211 * Open/initialize the netdevice. This is called (in the current kernel)
212 * sometime after booting when the 'ifconfig' program is run.
214 * This routine should set everything up anew at each open, even
215 * registers that "should" only need to be set once at boot, so that
216 * there is non-reboot way to recover if something goes wrong.
219 static int lec_open(struct net_device *dev)
221 netif_start_queue(dev);
222 memset(&dev->stats, 0, sizeof(struct net_device_stats));
228 lec_send(struct atm_vcc *vcc, struct sk_buff *skb)
230 struct net_device *dev = skb->dev;
232 ATM_SKB(skb)->vcc = vcc;
233 ATM_SKB(skb)->atm_options = vcc->atm_options;
235 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
236 if (vcc->send(vcc, skb) < 0) {
237 dev->stats.tx_dropped++;
241 dev->stats.tx_packets++;
242 dev->stats.tx_bytes += skb->len;
245 static void lec_tx_timeout(struct net_device *dev)
247 pr_info("%s\n", dev->name);
248 dev->trans_start = jiffies;
249 netif_wake_queue(dev);
252 static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
253 struct net_device *dev)
255 struct sk_buff *skb2;
256 struct lec_priv *priv = netdev_priv(dev);
257 struct lecdatahdr_8023 *lec_h;
259 struct lec_arp_table *entry;
263 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
269 #endif /* DUMP_PACKETS >0 */
271 pr_debug("called\n");
273 printk("%s:No lecd attached\n", dev->name);
274 dev->stats.tx_errors++;
275 netif_stop_queue(dev);
280 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
281 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
282 (long)skb_end_pointer(skb));
283 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
284 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
285 lec_handle_bridge(skb, dev);
288 /* Make sure we have room for lec_id */
289 if (skb_headroom(skb) < 2) {
291 pr_debug("reallocating skb\n");
292 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
300 /* Put le header to place, works for TokenRing too */
301 lec_h = (struct lecdatahdr_8023 *)skb->data;
302 lec_h->le_header = htons(priv->lecid);
306 * Ugly. Use this to realign Token Ring packets for
307 * e.g. PCA-200E driver.
309 if (priv->is_trdev) {
310 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
319 printk("%s: send datalen:%ld lecid:%4.4x\n", dev->name,
320 skb->len, priv->lecid);
321 #if DUMP_PACKETS >= 2
322 for (i = 0; i < skb->len && i < 99; i++) {
323 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
325 #elif DUMP_PACKETS >= 1
326 for (i = 0; i < skb->len && i < 30; i++) {
327 sprintf(buf + i * 3, "%2.2x ", 0xff & skb->data[i]);
329 #endif /* DUMP_PACKETS >= 1 */
333 printk("%s...\n", buf);
334 #endif /* DUMP_PACKETS > 0 */
336 /* Minimum ethernet-frame size */
339 min_frame_size = LEC_MINIMUM_8025_SIZE;
342 min_frame_size = LEC_MINIMUM_8023_SIZE;
343 if (skb->len < min_frame_size) {
344 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
345 skb2 = skb_copy_expand(skb, 0,
346 min_frame_size - skb->truesize,
350 dev->stats.tx_dropped++;
355 skb_put(skb, min_frame_size - skb->len);
358 /* Send to right vcc */
362 if (priv->is_trdev) {
363 dst = get_tr_dst(skb->data + 2, rdesc);
371 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
372 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n",
373 dev->name, vcc, vcc ? vcc->flags : 0, entry);
374 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
375 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
376 pr_debug("%s:queuing packet, MAC address %pM\n",
377 dev->name, lec_h->h_dest);
378 skb_queue_tail(&entry->tx_wait, skb);
380 pr_debug("%s:tx queue full or no arp entry, dropping, MAC address: %pM\n",
381 dev->name, lec_h->h_dest);
382 dev->stats.tx_dropped++;
388 printk("%s:sending to vpi:%d vci:%d\n", dev->name, vcc->vpi, vcc->vci);
389 #endif /* DUMP_PACKETS > 0 */
391 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
392 pr_debug("emptying tx queue, MAC address %pM\n", lec_h->h_dest);
398 if (!atm_may_send(vcc, 0)) {
399 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
402 netif_stop_queue(dev);
405 * vcc->pop() might have occurred in between, making
406 * the vcc usuable again. Since xmit is serialized,
407 * this is the only situation we have to re-test.
410 if (atm_may_send(vcc, 0))
411 netif_wake_queue(dev);
417 dev->trans_start = jiffies;
421 /* The inverse routine to net_open(). */
422 static int lec_close(struct net_device *dev)
424 netif_stop_queue(dev);
428 static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
431 struct net_device *dev = (struct net_device *)vcc->proto_data;
432 struct lec_priv *priv = netdev_priv(dev);
433 struct atmlec_msg *mesg;
434 struct lec_arp_table *entry;
436 char *tmp; /* FIXME */
438 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
439 mesg = (struct atmlec_msg *)skb->data;
441 tmp += sizeof(struct atmlec_msg);
442 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
443 switch (mesg->type) {
445 for (i = 0; i < 6; i++) {
446 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
450 for (i = 0; i < 6; i++) {
451 dev->dev_addr[i] = 0;
455 lec_addr_delete(priv, mesg->content.normal.atm_addr,
456 mesg->content.normal.flag);
458 case l_topology_change:
459 priv->topology_change = mesg->content.normal.flag;
461 case l_flush_complete:
462 lec_flush_complete(priv, mesg->content.normal.flag);
464 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
465 spin_lock_irqsave(&priv->lec_arp_lock, flags);
466 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
467 lec_arp_remove(priv, entry);
468 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
470 if (mesg->content.normal.no_source_le_narp)
474 lec_arp_update(priv, mesg->content.normal.mac_addr,
475 mesg->content.normal.atm_addr,
476 mesg->content.normal.flag,
477 mesg->content.normal.targetless_le_arp);
478 pr_debug("in l_arp_update\n");
479 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
480 pr_debug("LANE2 3.1.5, got tlvs, size %d\n",
482 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
483 tmp, mesg->sizeoftlvs);
487 priv->maximum_unknown_frame_count =
488 mesg->content.config.maximum_unknown_frame_count;
489 priv->max_unknown_frame_time =
490 (mesg->content.config.max_unknown_frame_time * HZ);
491 priv->max_retry_count = mesg->content.config.max_retry_count;
492 priv->aging_time = (mesg->content.config.aging_time * HZ);
493 priv->forward_delay_time =
494 (mesg->content.config.forward_delay_time * HZ);
495 priv->arp_response_time =
496 (mesg->content.config.arp_response_time * HZ);
497 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
498 priv->path_switching_delay =
499 (mesg->content.config.path_switching_delay * HZ);
500 priv->lane_version = mesg->content.config.lane_version; /* LANE2 */
501 priv->lane2_ops = NULL;
502 if (priv->lane_version > 1)
503 priv->lane2_ops = &lane2_ops;
504 if (dev_set_mtu(dev, mesg->content.config.mtu))
505 printk("%s: change_mtu to %d failed\n", dev->name,
506 mesg->content.config.mtu);
507 priv->is_proxy = mesg->content.config.is_proxy;
509 case l_flush_tran_id:
510 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
511 mesg->content.normal.flag);
515 (unsigned short)(0xffff & mesg->content.normal.flag);
517 case l_should_bridge:
518 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
520 pr_debug("%s: bridge zeppelin asks about %pM\n",
521 dev->name, mesg->content.proxy.mac_addr);
523 if (br_fdb_test_addr_hook == NULL)
526 if (br_fdb_test_addr_hook(dev,
527 mesg->content.proxy.mac_addr)) {
528 /* hit from bridge table, send LE_ARP_RESPONSE */
529 struct sk_buff *skb2;
532 pr_debug("%s: entry found, responding to zeppelin\n",
535 alloc_skb(sizeof(struct atmlec_msg),
539 skb2->len = sizeof(struct atmlec_msg);
540 skb_copy_to_linear_data(skb2, mesg,
542 atm_force_charge(priv->lecd, skb2->truesize);
543 sk = sk_atm(priv->lecd);
544 skb_queue_tail(&sk->sk_receive_queue, skb2);
545 sk->sk_data_ready(sk, skb2->len);
548 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
551 printk("%s: Unknown message type %d\n", dev->name, mesg->type);
559 static void lec_atm_close(struct atm_vcc *vcc)
562 struct net_device *dev = (struct net_device *)vcc->proto_data;
563 struct lec_priv *priv = netdev_priv(dev);
566 /* Do something needful? */
568 netif_stop_queue(dev);
569 lec_arp_destroy(priv);
571 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
572 printk("%s lec_atm_close: closing with messages pending\n",
574 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue)) != NULL) {
575 atm_return(vcc, skb->truesize);
579 printk("%s: Shut down!\n", dev->name);
580 module_put(THIS_MODULE);
583 static struct atmdev_ops lecdev_ops = {
584 .close = lec_atm_close,
588 static struct atm_dev lecatm_dev = {
591 .number = 999, /* dummy device number */
592 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
596 * LANE2: new argument struct sk_buff *data contains
597 * the LE_ARP based TLVs introduced in the LANE2 spec
600 send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
601 const unsigned char *mac_addr, const unsigned char *atm_addr,
602 struct sk_buff *data)
606 struct atmlec_msg *mesg;
608 if (!priv || !priv->lecd) {
611 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
614 skb->len = sizeof(struct atmlec_msg);
615 mesg = (struct atmlec_msg *)skb->data;
616 memset(mesg, 0, sizeof(struct atmlec_msg));
619 mesg->sizeoftlvs = data->len;
621 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
623 mesg->content.normal.targetless_le_arp = 1;
625 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
627 atm_force_charge(priv->lecd, skb->truesize);
628 sk = sk_atm(priv->lecd);
629 skb_queue_tail(&sk->sk_receive_queue, skb);
630 sk->sk_data_ready(sk, skb->len);
633 pr_debug("about to send %d bytes of data\n", data->len);
634 atm_force_charge(priv->lecd, data->truesize);
635 skb_queue_tail(&sk->sk_receive_queue, data);
636 sk->sk_data_ready(sk, skb->len);
642 /* shamelessly stolen from drivers/net/net_init.c */
643 static int lec_change_mtu(struct net_device *dev, int new_mtu)
645 if ((new_mtu < 68) || (new_mtu > 18190))
651 static void lec_set_multicast_list(struct net_device *dev)
654 * by default, all multicast frames arrive over the bus.
655 * eventually support selective multicast service
660 static const struct net_device_ops lec_netdev_ops = {
661 .ndo_open = lec_open,
662 .ndo_stop = lec_close,
663 .ndo_start_xmit = lec_start_xmit,
664 .ndo_change_mtu = lec_change_mtu,
665 .ndo_tx_timeout = lec_tx_timeout,
666 .ndo_set_multicast_list = lec_set_multicast_list,
669 static const unsigned char lec_ctrl_magic[] = {
676 #define LEC_DATA_DIRECT_8023 2
677 #define LEC_DATA_DIRECT_8025 3
679 static int lec_is_data_direct(struct atm_vcc *vcc)
681 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
682 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
685 static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
688 struct net_device *dev = (struct net_device *)vcc->proto_data;
689 struct lec_priv *priv = netdev_priv(dev);
692 printk(KERN_DEBUG "%s: vcc vpi:%d vci:%d\n",
693 dev->name, vcc->vpi, vcc->vci);
696 pr_debug("%s: null skb\n", dev->name);
697 lec_vcc_close(priv, vcc);
700 #if DUMP_PACKETS >= 2
701 #define MAX_SKB_DUMP 99
702 #elif DUMP_PACKETS >= 1
703 #define MAX_SKB_DUMP 30
706 printk(KERN_DEBUG "%s: rcv datalen:%ld lecid:%4.4x\n",
707 dev->name, skb->len, priv->lecid);
708 print_hex_dump(KERN_DEBUG, "", DUMP_OFFSET, 16, 1,
709 skb->data, min(MAX_SKB_DUMP, skb->len), true);
710 #endif /* DUMP_PACKETS > 0 */
711 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) {
712 /* Control frame, to daemon */
713 struct sock *sk = sk_atm(vcc);
715 pr_debug("%s: To daemon\n", dev->name);
716 skb_queue_tail(&sk->sk_receive_queue, skb);
717 sk->sk_data_ready(sk, skb->len);
718 } else { /* Data frame, queue to protocol handlers */
719 struct lec_arp_table *entry;
720 unsigned char *src, *dst;
722 atm_return(vcc, skb->truesize);
723 if (*(__be16 *) skb->data == htons(priv->lecid) ||
724 !priv->lecd || !(dev->flags & IFF_UP)) {
726 * Probably looping back, or if lecd is missing,
729 pr_debug("Ignoring frame...\n");
735 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
738 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
741 * If this is a Data Direct VCC, and the VCC does not match
742 * the LE_ARP cache entry, delete the LE_ARP cache entry.
744 spin_lock_irqsave(&priv->lec_arp_lock, flags);
745 if (lec_is_data_direct(vcc)) {
749 ((struct lecdatahdr_8025 *)skb->data)->
754 ((struct lecdatahdr_8023 *)skb->data)->
756 entry = lec_arp_find(priv, src);
757 if (entry && entry->vcc != vcc) {
758 lec_arp_remove(priv, entry);
762 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
764 if (!(dst[0] & 0x01) && /* Never filter Multi/Broadcast */
765 !priv->is_proxy && /* Proxy wants all the packets */
766 memcmp(dst, dev->dev_addr, dev->addr_len)) {
770 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
771 lec_arp_check_empties(priv, vcc, skb);
773 skb_pull(skb, 2); /* skip lec_id */
776 skb->protocol = tr_type_trans(skb, dev);
779 skb->protocol = eth_type_trans(skb, dev);
780 dev->stats.rx_packets++;
781 dev->stats.rx_bytes += skb->len;
782 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
787 static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
789 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
790 struct net_device *dev = skb->dev;
793 pr_info("vpriv = NULL!?!?!?\n");
797 vpriv->old_pop(vcc, skb);
799 if (vpriv->xoff && atm_may_send(vcc, 0)) {
801 if (netif_running(dev) && netif_queue_stopped(dev))
802 netif_wake_queue(dev);
806 static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
808 struct lec_vcc_priv *vpriv;
810 struct atmlec_ioc ioc_data;
812 /* Lecd must be up in this case */
813 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
815 pr_info("copy from user failed for %d bytes\n", bytes_left);
816 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
817 !dev_lec[ioc_data.dev_num])
819 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
822 vpriv->old_pop = vcc->pop;
823 vcc->user_back = vpriv;
825 lec_vcc_added(netdev_priv(dev_lec[ioc_data.dev_num]),
826 &ioc_data, vcc, vcc->push);
827 vcc->proto_data = dev_lec[ioc_data.dev_num];
828 vcc->push = lec_push;
832 static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
834 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
836 vcc->proto_data = dev_lec[arg];
837 return lec_mcast_make((struct lec_priv *)netdev_priv(dev_lec[arg]),
841 /* Initialize device. */
842 static int lecd_attach(struct atm_vcc *vcc, int arg)
845 struct lec_priv *priv;
852 if (arg >= MAX_LEC_ITF)
854 #else /* Reserve the top NUM_TR_DEVS for TR */
855 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
862 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
865 size = sizeof(struct lec_priv);
868 dev_lec[i] = alloc_trdev(size);
871 dev_lec[i] = alloc_etherdev(size);
874 dev_lec[i]->netdev_ops = &lec_netdev_ops;
875 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
876 if (register_netdev(dev_lec[i])) {
877 free_netdev(dev_lec[i]);
881 priv = netdev_priv(dev_lec[i]);
882 priv->is_trdev = is_trdev;
884 priv = netdev_priv(dev_lec[i]);
889 priv->itfnum = i; /* LANE2 addition */
891 vcc->dev = &lecatm_dev;
892 vcc_insert_socket(sk_atm(vcc));
894 vcc->proto_data = dev_lec[i];
895 set_bit(ATM_VF_META, &vcc->flags);
896 set_bit(ATM_VF_READY, &vcc->flags);
898 /* Set default values to these variables */
899 priv->maximum_unknown_frame_count = 1;
900 priv->max_unknown_frame_time = (1 * HZ);
901 priv->vcc_timeout_period = (1200 * HZ);
902 priv->max_retry_count = 1;
903 priv->aging_time = (300 * HZ);
904 priv->forward_delay_time = (15 * HZ);
905 priv->topology_change = 0;
906 priv->arp_response_time = (1 * HZ);
907 priv->flush_timeout = (4 * HZ);
908 priv->path_switching_delay = (6 * HZ);
910 if (dev_lec[i]->flags & IFF_UP) {
911 netif_start_queue(dev_lec[i]);
913 __module_get(THIS_MODULE);
917 #ifdef CONFIG_PROC_FS
918 static const char *lec_arp_get_status_string(unsigned char status)
920 static const char *const lec_arp_status_string[] = {
925 "ESI_FLUSH_PENDING ",
929 if (status > ESI_FORWARD_DIRECT)
930 status = 3; /* ESI_UNDEFINED */
931 return lec_arp_status_string[status];
934 static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
938 for (i = 0; i < ETH_ALEN; i++)
939 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
940 seq_printf(seq, " ");
941 for (i = 0; i < ATM_ESA_LEN; i++)
942 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
943 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
944 entry->flags & 0xffff);
946 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
948 seq_printf(seq, " ");
949 if (entry->recv_vcc) {
950 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
951 entry->recv_vcc->vci);
958 struct lec_priv *locked;
959 struct hlist_node *node;
960 struct net_device *dev;
966 static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
969 struct hlist_node *e = state->node;
970 struct lec_arp_table *tmp;
974 if (e == SEQ_START_TOKEN) {
979 hlist_for_each_entry_from(tmp, e, next) {
985 return (*l < 0) ? state : NULL;
988 static void *lec_arp_walk(struct lec_state *state, loff_t *l,
989 struct lec_priv *priv)
994 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
995 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
999 state->arp_table = p;
1003 static void *lec_misc_walk(struct lec_state *state, loff_t *l,
1004 struct lec_priv *priv)
1006 struct hlist_head *lec_misc_tables[] = {
1007 &priv->lec_arp_empty_ones,
1008 &priv->lec_no_forward,
1014 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
1015 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1019 state->misc_table = q;
1023 static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1024 struct lec_priv *priv)
1026 if (!state->locked) {
1027 state->locked = priv;
1028 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1030 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
1031 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1032 state->locked = NULL;
1033 /* Partial state reset for the next time we get called */
1034 state->arp_table = state->misc_table = 0;
1036 return state->locked;
1039 static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1041 struct net_device *dev;
1044 dev = state->dev ? state->dev : dev_lec[state->itf];
1045 v = (dev && netdev_priv(dev)) ?
1046 lec_priv_walk(state, l, netdev_priv(dev)) : NULL;
1049 /* Partial state reset for the next time we get called */
1056 static void *lec_get_idx(struct lec_state *state, loff_t l)
1060 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1061 v = lec_itf_walk(state, &l);
1068 static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1070 struct lec_state *state = seq->private;
1074 state->locked = NULL;
1075 state->arp_table = 0;
1076 state->misc_table = 0;
1077 state->node = SEQ_START_TOKEN;
1079 return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN;
1082 static void lec_seq_stop(struct seq_file *seq, void *v)
1084 struct lec_state *state = seq->private;
1087 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1089 dev_put(state->dev);
1093 static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1095 struct lec_state *state = seq->private;
1097 v = lec_get_idx(state, 1);
1098 *pos += !!PTR_ERR(v);
1102 static int lec_seq_show(struct seq_file *seq, void *v)
1104 static const char lec_banner[] =
1105 "Itf MAC ATM destination"
1107 "VPI/VCI Recv VPI/VCI\n";
1109 if (v == SEQ_START_TOKEN)
1110 seq_puts(seq, lec_banner);
1112 struct lec_state *state = seq->private;
1113 struct net_device *dev = state->dev;
1114 struct lec_arp_table *entry = hlist_entry(state->node, struct lec_arp_table, next);
1116 seq_printf(seq, "%s ", dev->name);
1117 lec_info(seq, entry);
1122 static const struct seq_operations lec_seq_ops = {
1123 .start = lec_seq_start,
1124 .next = lec_seq_next,
1125 .stop = lec_seq_stop,
1126 .show = lec_seq_show,
1129 static int lec_seq_open(struct inode *inode, struct file *file)
1131 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
1134 static const struct file_operations lec_seq_fops = {
1135 .owner = THIS_MODULE,
1136 .open = lec_seq_open,
1138 .llseek = seq_lseek,
1139 .release = seq_release_private,
1143 static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1145 struct atm_vcc *vcc = ATM_SD(sock);
1152 if (!capable(CAP_NET_ADMIN))
1156 return -ENOIOCTLCMD;
1161 err = lecd_attach(vcc, (int)arg);
1163 sock->state = SS_CONNECTED;
1166 err = lec_mcast_attach(vcc, (int)arg);
1169 err = lec_vcc_attach(vcc, (void __user *)arg);
1176 static struct atm_ioctl lane_ioctl_ops = {
1177 .owner = THIS_MODULE,
1178 .ioctl = lane_ioctl,
1181 static int __init lane_module_init(void)
1183 #ifdef CONFIG_PROC_FS
1184 struct proc_dir_entry *p;
1186 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
1188 pr_err("Unable to initialize /proc/net/atm/lec\n");
1193 register_atm_ioctl(&lane_ioctl_ops);
1194 printk("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1198 static void __exit lane_module_cleanup(void)
1201 struct lec_priv *priv;
1203 remove_proc_entry("lec", atm_proc_root);
1205 deregister_atm_ioctl(&lane_ioctl_ops);
1207 for (i = 0; i < MAX_LEC_ITF; i++) {
1208 if (dev_lec[i] != NULL) {
1209 priv = netdev_priv(dev_lec[i]);
1210 unregister_netdev(dev_lec[i]);
1211 free_netdev(dev_lec[i]);
1219 module_init(lane_module_init);
1220 module_exit(lane_module_cleanup);
1223 * LANE2: 3.1.3, LE_RESOLVE.request
1224 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1225 * If sizeoftlvs == NULL the default TLVs associated with with this
1227 * If dst_mac == NULL, targetless LE_ARP will be sent
1229 static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
1230 u8 **tlvs, u32 *sizeoftlvs)
1232 unsigned long flags;
1233 struct lec_priv *priv = netdev_priv(dev);
1234 struct lec_arp_table *table;
1235 struct sk_buff *skb;
1239 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1240 table = lec_arp_find(priv, dst_mac);
1241 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1245 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
1249 *sizeoftlvs = table->sizeoftlvs;
1254 if (sizeoftlvs == NULL)
1255 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
1258 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1261 skb->len = *sizeoftlvs;
1262 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
1263 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1269 * LANE2: 3.1.4, LE_ASSOCIATE.request
1270 * Associate the *tlvs with the *lan_dst address.
1271 * Will overwrite any previous association
1272 * Returns 1 for success, 0 for failure (out of memory)
1275 static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1276 const u8 *tlvs, u32 sizeoftlvs)
1279 struct sk_buff *skb;
1280 struct lec_priv *priv = netdev_priv(dev);
1282 if (compare_ether_addr(lan_dst, dev->dev_addr))
1283 return (0); /* not our mac address */
1285 kfree(priv->tlvs); /* NULL if there was no previous association */
1287 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
1288 if (priv->tlvs == NULL)
1290 priv->sizeoftlvs = sizeoftlvs;
1292 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1295 skb->len = sizeoftlvs;
1296 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
1297 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1299 printk("lec.c: lane2_associate_req() failed\n");
1301 * If the previous association has changed we must
1302 * somehow notify other LANE entities about the change
1308 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1311 static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1312 const u8 *tlvs, u32 sizeoftlvs)
1317 struct lec_priv *priv = netdev_priv(dev);
1319 * Why have the TLVs in LE_ARP entries
1320 * since we do not use them? When you
1321 * uncomment this code, make sure the
1322 * TLVs get freed when entry is killed
1324 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
1327 return; /* should not happen */
1331 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
1332 if (entry->tlvs == NULL)
1334 entry->sizeoftlvs = sizeoftlvs;
1337 printk("lec.c: lane2_associate_ind()\n");
1338 printk("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1339 while (i < sizeoftlvs)
1340 printk("%02x ", tlvs[i++]);
1345 /* tell MPOA about the TLVs we saw */
1346 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1347 priv->lane2_ops->associate_indicator(dev, mac_addr,
1354 * Here starts what used to lec_arpc.c
1356 * lec_arpc.c was added here when making
1357 * lane client modular. October 1997
1360 #include <linux/types.h>
1361 #include <linux/timer.h>
1362 #include <asm/param.h>
1363 #include <asm/atomic.h>
1364 #include <linux/inetdevice.h>
1365 #include <net/route.h>
1368 #define pr_debug(format,args...)
1370 #define pr_debug printk
1373 #define DEBUG_ARP_TABLE 0
1375 #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1377 static void lec_arp_check_expire(struct work_struct *work);
1378 static void lec_arp_expire_arp(unsigned long data);
1384 #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE -1))
1387 * Initialization of arp-cache
1389 static void lec_arp_init(struct lec_priv *priv)
1393 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1394 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
1396 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1397 INIT_HLIST_HEAD(&priv->lec_no_forward);
1398 INIT_HLIST_HEAD(&priv->mcast_fwds);
1399 spin_lock_init(&priv->lec_arp_lock);
1400 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
1401 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
1404 static void lec_arp_clear_vccs(struct lec_arp_table *entry)
1407 struct atm_vcc *vcc = entry->vcc;
1408 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
1409 struct net_device *dev = (struct net_device *)vcc->proto_data;
1411 vcc->pop = vpriv->old_pop;
1413 netif_wake_queue(dev);
1415 vcc->user_back = NULL;
1416 vcc->push = entry->old_push;
1417 vcc_release_async(vcc, -EPIPE);
1420 if (entry->recv_vcc) {
1421 entry->recv_vcc->push = entry->old_recv_push;
1422 vcc_release_async(entry->recv_vcc, -EPIPE);
1423 entry->recv_vcc = NULL;
1428 * Insert entry to lec_arp_table
1429 * LANE2: Add to the end of the list to satisfy 8.1.13
1432 lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
1434 struct hlist_head *tmp;
1436 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1437 hlist_add_head(&entry->next, tmp);
1439 pr_debug("Added entry:%pM\n", entry->mac_addr);
1443 * Remove entry from lec_arp_table
1446 lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
1448 struct hlist_node *node;
1449 struct lec_arp_table *entry;
1450 int i, remove_vcc = 1;
1456 hlist_del(&to_remove->next);
1457 del_timer(&to_remove->timer);
1459 /* If this is the only MAC connected to this VCC, also tear down the VCC */
1460 if (to_remove->status >= ESI_FLUSH_PENDING) {
1462 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1464 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1465 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
1466 if (memcmp(to_remove->atm_addr,
1467 entry->atm_addr, ATM_ESA_LEN) == 0) {
1474 lec_arp_clear_vccs(to_remove);
1476 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1478 pr_debug("Removed entry:%pM\n", to_remove->mac_addr);
1483 static const char *get_status_string(unsigned char st)
1487 return "ESI_UNKNOWN";
1488 case ESI_ARP_PENDING:
1489 return "ESI_ARP_PENDING";
1490 case ESI_VC_PENDING:
1491 return "ESI_VC_PENDING";
1492 case ESI_FLUSH_PENDING:
1493 return "ESI_FLUSH_PENDING";
1494 case ESI_FORWARD_DIRECT:
1495 return "ESI_FORWARD_DIRECT";
1501 static void dump_arp_table(struct lec_priv *priv)
1503 struct hlist_node *node;
1504 struct lec_arp_table *rulla;
1508 printk("Dump %p:\n", priv);
1509 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1510 hlist_for_each_entry(rulla, node, &priv->lec_arp_tables[i], next) {
1512 offset += sprintf(buf, "%d: %p\n", i, rulla);
1513 offset += sprintf(buf + offset, "Mac:");
1514 for (j = 0; j < ETH_ALEN; j++) {
1515 offset += sprintf(buf + offset,
1517 rulla->mac_addr[j] & 0xff);
1519 offset += sprintf(buf + offset, "Atm:");
1520 for (j = 0; j < ATM_ESA_LEN; j++) {
1521 offset += sprintf(buf + offset,
1523 rulla->atm_addr[j] & 0xff);
1525 offset += sprintf(buf + offset,
1526 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1527 rulla->vcc ? rulla->vcc->vpi : 0,
1528 rulla->vcc ? rulla->vcc->vci : 0,
1529 rulla->recv_vcc ? rulla->recv_vcc->
1531 rulla->recv_vcc ? rulla->recv_vcc->
1532 vci : 0, rulla->last_used,
1533 rulla->timestamp, rulla->no_tries);
1535 sprintf(buf + offset,
1536 "Flags:%x, Packets_flooded:%x, Status: %s ",
1537 rulla->flags, rulla->packets_flooded,
1538 get_status_string(rulla->status));
1539 printk("%s\n", buf);
1543 if (!hlist_empty(&priv->lec_no_forward))
1544 printk("No forward\n");
1545 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
1547 offset += sprintf(buf + offset, "Mac:");
1548 for (j = 0; j < ETH_ALEN; j++) {
1549 offset += sprintf(buf + offset, "%2.2x ",
1550 rulla->mac_addr[j] & 0xff);
1552 offset += sprintf(buf + offset, "Atm:");
1553 for (j = 0; j < ATM_ESA_LEN; j++) {
1554 offset += sprintf(buf + offset, "%2.2x ",
1555 rulla->atm_addr[j] & 0xff);
1557 offset += sprintf(buf + offset,
1558 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1559 rulla->vcc ? rulla->vcc->vpi : 0,
1560 rulla->vcc ? rulla->vcc->vci : 0,
1561 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1562 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1564 rulla->timestamp, rulla->no_tries);
1565 offset += sprintf(buf + offset,
1566 "Flags:%x, Packets_flooded:%x, Status: %s ",
1567 rulla->flags, rulla->packets_flooded,
1568 get_status_string(rulla->status));
1569 printk("%s\n", buf);
1572 if (!hlist_empty(&priv->lec_arp_empty_ones))
1573 printk("Empty ones\n");
1574 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
1576 offset += sprintf(buf + offset, "Mac:");
1577 for (j = 0; j < ETH_ALEN; j++) {
1578 offset += sprintf(buf + offset, "%2.2x ",
1579 rulla->mac_addr[j] & 0xff);
1581 offset += sprintf(buf + offset, "Atm:");
1582 for (j = 0; j < ATM_ESA_LEN; j++) {
1583 offset += sprintf(buf + offset, "%2.2x ",
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));
1601 if (!hlist_empty(&priv->mcast_fwds))
1602 printk("Multicast Forward VCCs\n");
1603 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
1605 offset += sprintf(buf + offset, "Mac:");
1606 for (j = 0; j < ETH_ALEN; j++) {
1607 offset += sprintf(buf + offset, "%2.2x ",
1608 rulla->mac_addr[j] & 0xff);
1610 offset += sprintf(buf + offset, "Atm:");
1611 for (j = 0; j < ATM_ESA_LEN; j++) {
1612 offset += sprintf(buf + offset, "%2.2x ",
1613 rulla->atm_addr[j] & 0xff);
1615 offset += sprintf(buf + offset,
1616 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1617 rulla->vcc ? rulla->vcc->vpi : 0,
1618 rulla->vcc ? rulla->vcc->vci : 0,
1619 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1620 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1622 rulla->timestamp, rulla->no_tries);
1623 offset += sprintf(buf + offset,
1624 "Flags:%x, Packets_flooded:%x, Status: %s ",
1625 rulla->flags, rulla->packets_flooded,
1626 get_status_string(rulla->status));
1627 printk("%s\n", buf);
1632 #define dump_arp_table(priv) do { } while (0)
1636 * Destruction of arp-cache
1638 static void lec_arp_destroy(struct lec_priv *priv)
1640 unsigned long flags;
1641 struct hlist_node *node, *next;
1642 struct lec_arp_table *entry;
1645 cancel_rearming_delayed_work(&priv->lec_arp_work);
1648 * Remove all entries
1651 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1652 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1653 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
1654 lec_arp_remove(priv, entry);
1657 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
1660 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
1661 del_timer_sync(&entry->timer);
1662 lec_arp_clear_vccs(entry);
1663 hlist_del(&entry->next);
1666 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1668 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
1669 del_timer_sync(&entry->timer);
1670 lec_arp_clear_vccs(entry);
1671 hlist_del(&entry->next);
1674 INIT_HLIST_HEAD(&priv->lec_no_forward);
1676 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
1677 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1678 lec_arp_clear_vccs(entry);
1679 hlist_del(&entry->next);
1682 INIT_HLIST_HEAD(&priv->mcast_fwds);
1683 priv->mcast_vcc = NULL;
1684 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1688 * Find entry by mac_address
1690 static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
1691 const unsigned char *mac_addr)
1693 struct hlist_node *node;
1694 struct hlist_head *head;
1695 struct lec_arp_table *entry;
1697 pr_debug("%pM\n", mac_addr);
1699 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1700 hlist_for_each_entry(entry, node, head, next) {
1701 if (!compare_ether_addr(mac_addr, entry->mac_addr)) {
1708 static struct lec_arp_table *make_entry(struct lec_priv *priv,
1709 const unsigned char *mac_addr)
1711 struct lec_arp_table *to_return;
1713 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1715 printk("LEC: Arp entry kmalloc failed\n");
1718 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
1719 INIT_HLIST_NODE(&to_return->next);
1720 setup_timer(&to_return->timer, lec_arp_expire_arp,
1721 (unsigned long)to_return);
1722 to_return->last_used = jiffies;
1723 to_return->priv = priv;
1724 skb_queue_head_init(&to_return->tx_wait);
1725 atomic_set(&to_return->usage, 1);
1729 /* Arp sent timer expired */
1730 static void lec_arp_expire_arp(unsigned long data)
1732 struct lec_arp_table *entry;
1734 entry = (struct lec_arp_table *)data;
1737 if (entry->status == ESI_ARP_PENDING) {
1738 if (entry->no_tries <= entry->priv->max_retry_count) {
1739 if (entry->is_rdesc)
1740 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1741 entry->mac_addr, NULL, NULL);
1743 send_to_lecd(entry->priv, l_arp_xmt,
1744 entry->mac_addr, NULL, NULL);
1747 mod_timer(&entry->timer, jiffies + (1 * HZ));
1751 /* Unknown/unused vcc expire, remove associated entry */
1752 static void lec_arp_expire_vcc(unsigned long data)
1754 unsigned long flags;
1755 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1756 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
1758 del_timer(&to_remove->timer);
1760 pr_debug("%p %p: vpi:%d vci:%d\n",
1762 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1763 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
1765 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1766 hlist_del(&to_remove->next);
1767 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1769 lec_arp_clear_vccs(to_remove);
1770 lec_arp_put(to_remove);
1776 * 2. For each entry, delete entries that have aged past the age limit.
1777 * 3. For each entry, depending on the status of the entry, perform
1778 * the following maintenance.
1779 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1780 * tick_count is above the max_unknown_frame_time, clear
1781 * the tick_count to zero and clear the packets_flooded counter
1782 * to zero. This supports the packet rate limit per address
1783 * while flooding unknowns.
1784 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1785 * than or equal to the path_switching_delay, change the status
1786 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1787 * regardless of the progress of the flush protocol.
1789 static void lec_arp_check_expire(struct work_struct *work)
1791 unsigned long flags;
1792 struct lec_priv *priv =
1793 container_of(work, struct lec_priv, lec_arp_work.work);
1794 struct hlist_node *node, *next;
1795 struct lec_arp_table *entry;
1797 unsigned long time_to_check;
1800 pr_debug("%p\n", priv);
1803 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1804 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1805 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
1806 if ((entry->flags) & LEC_REMOTE_FLAG &&
1807 priv->topology_change)
1808 time_to_check = priv->forward_delay_time;
1810 time_to_check = priv->aging_time;
1812 pr_debug("About to expire: %lx - %lx > %lx\n",
1813 now, entry->last_used, time_to_check);
1814 if (time_after(now, entry->last_used + time_to_check)
1815 && !(entry->flags & LEC_PERMANENT_FLAG)
1816 && !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
1818 pr_debug("Entry timed out\n");
1819 lec_arp_remove(priv, entry);
1822 /* Something else */
1823 if ((entry->status == ESI_VC_PENDING ||
1824 entry->status == ESI_ARP_PENDING)
1825 && time_after_eq(now,
1828 max_unknown_frame_time)) {
1829 entry->timestamp = jiffies;
1830 entry->packets_flooded = 0;
1831 if (entry->status == ESI_VC_PENDING)
1832 send_to_lecd(priv, l_svc_setup,
1837 if (entry->status == ESI_FLUSH_PENDING
1839 time_after_eq(now, entry->timestamp +
1840 priv->path_switching_delay)) {
1841 struct sk_buff *skb;
1842 struct atm_vcc *vcc = entry->vcc;
1844 lec_arp_hold(entry);
1845 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1846 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
1848 entry->last_used = jiffies;
1849 entry->status = ESI_FORWARD_DIRECT;
1856 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1858 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
1862 * Try to find vcc where mac_address is attached.
1865 static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
1866 const unsigned char *mac_to_find, int is_rdesc,
1867 struct lec_arp_table **ret_entry)
1869 unsigned long flags;
1870 struct lec_arp_table *entry;
1871 struct atm_vcc *found;
1873 if (mac_to_find[0] & 0x01) {
1874 switch (priv->lane_version) {
1876 return priv->mcast_vcc;
1877 case 2: /* LANE2 wants arp for multicast addresses */
1878 if (!compare_ether_addr(mac_to_find, bus_mac))
1879 return priv->mcast_vcc;
1886 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1887 entry = lec_arp_find(priv, mac_to_find);
1890 if (entry->status == ESI_FORWARD_DIRECT) {
1892 entry->last_used = jiffies;
1893 lec_arp_hold(entry);
1899 * If the LE_ARP cache entry is still pending, reset count to 0
1900 * so another LE_ARP request can be made for this frame.
1902 if (entry->status == ESI_ARP_PENDING) {
1903 entry->no_tries = 0;
1906 * Data direct VC not yet set up, check to see if the unknown
1907 * frame count is greater than the limit. If the limit has
1908 * not been reached, allow the caller to send packet to
1911 if (entry->status != ESI_FLUSH_PENDING &&
1912 entry->packets_flooded <
1913 priv->maximum_unknown_frame_count) {
1914 entry->packets_flooded++;
1915 pr_debug("Flooding..\n");
1916 found = priv->mcast_vcc;
1920 * We got here because entry->status == ESI_FLUSH_PENDING
1921 * or BUS flood limit was reached for an entry which is
1922 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1924 lec_arp_hold(entry);
1926 pr_debug("entry->status %d entry->vcc %p\n", entry->status,
1930 /* No matching entry was found */
1931 entry = make_entry(priv, mac_to_find);
1932 pr_debug("Making entry\n");
1934 found = priv->mcast_vcc;
1937 lec_arp_add(priv, entry);
1938 /* We want arp-request(s) to be sent */
1939 entry->packets_flooded = 1;
1940 entry->status = ESI_ARP_PENDING;
1941 entry->no_tries = 1;
1942 entry->last_used = entry->timestamp = jiffies;
1943 entry->is_rdesc = is_rdesc;
1944 if (entry->is_rdesc)
1945 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
1948 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1949 entry->timer.expires = jiffies + (1 * HZ);
1950 entry->timer.function = lec_arp_expire_arp;
1951 add_timer(&entry->timer);
1952 found = priv->mcast_vcc;
1956 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1961 lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
1962 unsigned long permanent)
1964 unsigned long flags;
1965 struct hlist_node *node, *next;
1966 struct lec_arp_table *entry;
1970 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1971 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1972 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
1973 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)
1975 !(entry->flags & LEC_PERMANENT_FLAG))) {
1976 lec_arp_remove(priv, entry);
1979 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1983 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1988 * Notifies: Response to arp_request (atm_addr != NULL)
1991 lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
1992 const unsigned char *atm_addr, unsigned long remoteflag,
1993 unsigned int targetless_le_arp)
1995 unsigned long flags;
1996 struct hlist_node *node, *next;
1997 struct lec_arp_table *entry, *tmp;
2000 pr_debug("%smac:%pM\n",
2001 (targetless_le_arp) ? "targetless " : "", mac_addr);
2003 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2004 entry = lec_arp_find(priv, mac_addr);
2005 if (entry == NULL && targetless_le_arp)
2007 * LANE2: ignore targetless LE_ARPs for which
2008 * we have no entry in the cache. 7.1.30
2010 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
2011 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2012 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
2013 hlist_del(&entry->next);
2014 del_timer(&entry->timer);
2015 tmp = lec_arp_find(priv, mac_addr);
2017 del_timer(&tmp->timer);
2018 tmp->status = ESI_FORWARD_DIRECT;
2019 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2020 tmp->vcc = entry->vcc;
2021 tmp->old_push = entry->old_push;
2022 tmp->last_used = jiffies;
2023 del_timer(&entry->timer);
2027 entry->status = ESI_FORWARD_DIRECT;
2028 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2029 entry->last_used = jiffies;
2030 lec_arp_add(priv, entry);
2033 entry->flags |= LEC_REMOTE_FLAG;
2035 entry->flags &= ~LEC_REMOTE_FLAG;
2036 pr_debug("After update\n");
2037 dump_arp_table(priv);
2043 entry = lec_arp_find(priv, mac_addr);
2045 entry = make_entry(priv, mac_addr);
2048 entry->status = ESI_UNKNOWN;
2049 lec_arp_add(priv, entry);
2050 /* Temporary, changes before end of function */
2052 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2053 del_timer(&entry->timer);
2054 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2055 hlist_for_each_entry(tmp, node, &priv->lec_arp_tables[i], next) {
2057 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2058 /* Vcc to this host exists */
2059 if (tmp->status > ESI_VC_PENDING) {
2061 * ESI_FLUSH_PENDING,
2062 * ESI_FORWARD_DIRECT
2064 entry->vcc = tmp->vcc;
2065 entry->old_push = tmp->old_push;
2067 entry->status = tmp->status;
2073 entry->flags |= LEC_REMOTE_FLAG;
2075 entry->flags &= ~LEC_REMOTE_FLAG;
2076 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2077 entry->status = ESI_VC_PENDING;
2078 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
2080 pr_debug("After update2\n");
2081 dump_arp_table(priv);
2083 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2087 * Notifies: Vcc setup ready
2090 lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
2091 struct atm_vcc *vcc,
2092 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
2094 unsigned long flags;
2095 struct hlist_node *node;
2096 struct lec_arp_table *entry;
2097 int i, found_entry = 0;
2099 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2100 if (ioc_data->receive == 2) {
2101 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
2103 pr_debug("LEC_ARP: Attaching mcast forward\n");
2105 entry = lec_arp_find(priv, bus_mac);
2107 printk("LEC_ARP: Multicast entry not found!\n");
2110 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2111 entry->recv_vcc = vcc;
2112 entry->old_recv_push = old_push;
2114 entry = make_entry(priv, bus_mac);
2117 del_timer(&entry->timer);
2118 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2119 entry->recv_vcc = vcc;
2120 entry->old_recv_push = old_push;
2121 hlist_add_head(&entry->next, &priv->mcast_fwds);
2123 } else if (ioc_data->receive == 1) {
2125 * Vcc which we don't want to make default vcc,
2128 pr_debug("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",
2129 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2130 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2131 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2132 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2133 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2134 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2135 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2136 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2137 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2138 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2139 entry = make_entry(priv, bus_mac);
2142 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2143 memset(entry->mac_addr, 0, ETH_ALEN);
2144 entry->recv_vcc = vcc;
2145 entry->old_recv_push = old_push;
2146 entry->status = ESI_UNKNOWN;
2147 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2148 entry->timer.function = lec_arp_expire_vcc;
2149 hlist_add_head(&entry->next, &priv->lec_no_forward);
2150 add_timer(&entry->timer);
2151 dump_arp_table(priv);
2154 pr_debug("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",
2155 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2156 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2157 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2158 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2159 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2160 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2161 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2162 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2163 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2164 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2165 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2166 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
2168 (ioc_data->atm_addr, entry->atm_addr,
2169 ATM_ESA_LEN) == 0) {
2170 pr_debug("LEC_ARP: Attaching data direct\n");
2171 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
2172 entry->vcc ? entry->vcc->vci : 0,
2173 entry->recv_vcc ? entry->recv_vcc->
2176 del_timer(&entry->timer);
2178 entry->old_push = old_push;
2179 if (entry->status == ESI_VC_PENDING) {
2180 if (priv->maximum_unknown_frame_count
2185 entry->timestamp = jiffies;
2189 send_to_lecd(priv, l_flush_xmt,
2197 * They were forming a connection
2198 * to us, and we to them. Our
2199 * ATM address is numerically lower
2200 * than theirs, so we make connection
2201 * we formed into default VCC (8.1.11).
2202 * Connection they made gets torn
2203 * down. This might confuse some
2204 * clients. Can be changed if
2205 * someone reports trouble...
2213 pr_debug("After vcc was added\n");
2214 dump_arp_table(priv);
2218 * Not found, snatch address from first data packet that arrives
2221 entry = make_entry(priv, bus_mac);
2225 entry->old_push = old_push;
2226 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2227 memset(entry->mac_addr, 0, ETH_ALEN);
2228 entry->status = ESI_UNKNOWN;
2229 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
2230 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2231 entry->timer.function = lec_arp_expire_vcc;
2232 add_timer(&entry->timer);
2233 pr_debug("After vcc was added\n");
2234 dump_arp_table(priv);
2236 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2239 static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
2241 unsigned long flags;
2242 struct hlist_node *node;
2243 struct lec_arp_table *entry;
2246 pr_debug("%lx\n", tran_id);
2248 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2249 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2250 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
2251 if (entry->flush_tran_id == tran_id
2252 && entry->status == ESI_FLUSH_PENDING) {
2253 struct sk_buff *skb;
2254 struct atm_vcc *vcc = entry->vcc;
2256 lec_arp_hold(entry);
2257 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2258 while ((skb = skb_dequeue(&entry->tx_wait)) != NULL)
2260 entry->last_used = jiffies;
2261 entry->status = ESI_FORWARD_DIRECT;
2263 pr_debug("LEC_ARP: Flushed\n");
2268 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2269 dump_arp_table(priv);
2273 lec_set_flush_tran_id(struct lec_priv *priv,
2274 const unsigned char *atm_addr, unsigned long tran_id)
2276 unsigned long flags;
2277 struct hlist_node *node;
2278 struct lec_arp_table *entry;
2281 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2282 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
2283 hlist_for_each_entry(entry, node, &priv->lec_arp_tables[i], next) {
2284 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2285 entry->flush_tran_id = tran_id;
2286 pr_debug("Set flush transaction id to %lx for %p\n",
2290 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2293 static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
2295 unsigned long flags;
2296 unsigned char mac_addr[] = {
2297 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2299 struct lec_arp_table *to_add;
2300 struct lec_vcc_priv *vpriv;
2303 if (!(vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL)))
2306 vpriv->old_pop = vcc->pop;
2307 vcc->user_back = vpriv;
2309 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2310 to_add = make_entry(priv, mac_addr);
2312 vcc->pop = vpriv->old_pop;
2317 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2318 to_add->status = ESI_FORWARD_DIRECT;
2319 to_add->flags |= LEC_PERMANENT_FLAG;
2321 to_add->old_push = vcc->push;
2322 vcc->push = lec_push;
2323 priv->mcast_vcc = vcc;
2324 lec_arp_add(priv, to_add);
2326 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2330 static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
2332 unsigned long flags;
2333 struct hlist_node *node, *next;
2334 struct lec_arp_table *entry;
2337 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
2338 dump_arp_table(priv);
2340 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2342 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2343 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_tables[i], next) {
2344 if (vcc == entry->vcc) {
2345 lec_arp_remove(priv, entry);
2347 if (priv->mcast_vcc == vcc) {
2348 priv->mcast_vcc = NULL;
2354 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2355 if (entry->vcc == vcc) {
2356 lec_arp_clear_vccs(entry);
2357 del_timer(&entry->timer);
2358 hlist_del(&entry->next);
2363 hlist_for_each_entry_safe(entry, node, next, &priv->lec_no_forward, next) {
2364 if (entry->recv_vcc == vcc) {
2365 lec_arp_clear_vccs(entry);
2366 del_timer(&entry->timer);
2367 hlist_del(&entry->next);
2372 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
2373 if (entry->recv_vcc == vcc) {
2374 lec_arp_clear_vccs(entry);
2375 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
2376 hlist_del(&entry->next);
2381 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2382 dump_arp_table(priv);
2386 lec_arp_check_empties(struct lec_priv *priv,
2387 struct atm_vcc *vcc, struct sk_buff *skb)
2389 unsigned long flags;
2390 struct hlist_node *node, *next;
2391 struct lec_arp_table *entry, *tmp;
2392 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2395 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
2398 src = tr_hdr->h_source;
2401 src = hdr->h_source;
2403 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2404 hlist_for_each_entry_safe(entry, node, next, &priv->lec_arp_empty_ones, next) {
2405 if (vcc == entry->vcc) {
2406 del_timer(&entry->timer);
2407 memcpy(entry->mac_addr, src, ETH_ALEN);
2408 entry->status = ESI_FORWARD_DIRECT;
2409 entry->last_used = jiffies;
2410 /* We might have got an entry */
2411 if ((tmp = lec_arp_find(priv, src))) {
2412 lec_arp_remove(priv, tmp);
2415 hlist_del(&entry->next);
2416 lec_arp_add(priv, entry);
2420 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
2422 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2425 MODULE_LICENSE("GPL");