]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - net/atm/lec.c
Merge branch 'origin' into devel-stable
[mirror_ubuntu-bionic-kernel.git] / net / atm / lec.c
1 /*
2 * lec.c: Lan Emulation driver
3 *
4 * Marko Kiiskila <mkiiskila@yahoo.com>
5 */
6
7 #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
8
9 #include <linux/kernel.h>
10 #include <linux/bitops.h>
11 #include <linux/capability.h>
12
13 /* We are ethernet device */
14 #include <linux/if_ether.h>
15 #include <linux/netdevice.h>
16 #include <linux/etherdevice.h>
17 #include <net/sock.h>
18 #include <linux/skbuff.h>
19 #include <linux/ip.h>
20 #include <asm/byteorder.h>
21 #include <linux/uaccess.h>
22 #include <net/arp.h>
23 #include <net/dst.h>
24 #include <linux/proc_fs.h>
25 #include <linux/spinlock.h>
26 #include <linux/seq_file.h>
27
28 /* TokenRing if needed */
29 #ifdef CONFIG_TR
30 #include <linux/trdevice.h>
31 #endif
32
33 /* And atm device */
34 #include <linux/atmdev.h>
35 #include <linux/atmlec.h>
36
37 /* Proxy LEC knows about bridging */
38 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
39 #include "../bridge/br_private.h"
40
41 static unsigned char bridge_ula_lec[] = { 0x01, 0x80, 0xc2, 0x00, 0x00 };
42 #endif
43
44 /* Modular too */
45 #include <linux/module.h>
46 #include <linux/init.h>
47
48 #include "lec.h"
49 #include "lec_arpc.h"
50 #include "resources.h"
51
52 #define DUMP_PACKETS 0 /*
53 * 0 = None,
54 * 1 = 30 first bytes
55 * 2 = Whole packet
56 */
57
58 #define LEC_UNRES_QUE_LEN 8 /*
59 * number of tx packets to queue for a
60 * single destination while waiting for SVC
61 */
62
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);
71 /* LANE2 functions */
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);
78
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,
87 int is_rdesc,
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,
91 unsigned long remoteflag,
92 unsigned int targetless_le_arp);
93 static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id);
94 static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc);
95 static void lec_set_flush_tran_id(struct lec_priv *priv,
96 const unsigned char *atm_addr,
97 unsigned long tran_id);
98 static void lec_vcc_added(struct lec_priv *priv,
99 const struct atmlec_ioc *ioc_data,
100 struct atm_vcc *vcc,
101 void (*old_push)(struct atm_vcc *vcc,
102 struct sk_buff *skb));
103 static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc);
104
105 /* must be done under lec_arp_lock */
106 static inline void lec_arp_hold(struct lec_arp_table *entry)
107 {
108 atomic_inc(&entry->usage);
109 }
110
111 static inline void lec_arp_put(struct lec_arp_table *entry)
112 {
113 if (atomic_dec_and_test(&entry->usage))
114 kfree(entry);
115 }
116
117 static struct lane2_ops lane2_ops = {
118 lane2_resolve, /* resolve, spec 3.1.3 */
119 lane2_associate_req, /* associate_req, spec 3.1.4 */
120 NULL /* associate indicator, spec 3.1.5 */
121 };
122
123 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
124
125 /* Device structures */
126 static struct net_device *dev_lec[MAX_LEC_ITF];
127
128 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
129 static void lec_handle_bridge(struct sk_buff *skb, struct net_device *dev)
130 {
131 struct ethhdr *eth;
132 char *buff;
133 struct lec_priv *priv;
134
135 /*
136 * Check if this is a BPDU. If so, ask zeppelin to send
137 * LE_TOPOLOGY_REQUEST with the same value of Topology Change bit
138 * as the Config BPDU has
139 */
140 eth = (struct ethhdr *)skb->data;
141 buff = skb->data + skb->dev->hard_header_len;
142 if (*buff++ == 0x42 && *buff++ == 0x42 && *buff++ == 0x03) {
143 struct sock *sk;
144 struct sk_buff *skb2;
145 struct atmlec_msg *mesg;
146
147 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
148 if (skb2 == NULL)
149 return;
150 skb2->len = sizeof(struct atmlec_msg);
151 mesg = (struct atmlec_msg *)skb2->data;
152 mesg->type = l_topology_change;
153 buff += 4;
154 mesg->content.normal.flag = *buff & 0x01;
155 /* 0x01 is topology change */
156
157 priv = netdev_priv(dev);
158 atm_force_charge(priv->lecd, skb2->truesize);
159 sk = sk_atm(priv->lecd);
160 skb_queue_tail(&sk->sk_receive_queue, skb2);
161 sk->sk_data_ready(sk, skb2->len);
162 }
163
164 return;
165 }
166 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
167
168 /*
169 * Modelled after tr_type_trans
170 * All multicast and ARE or STE frames go to BUS.
171 * Non source routed frames go by destination address.
172 * Last hop source routed frames go by destination address.
173 * Not last hop source routed frames go by _next_ route descriptor.
174 * Returns pointer to destination MAC address or fills in rdesc
175 * and returns NULL.
176 */
177 #ifdef CONFIG_TR
178 static unsigned char *get_tr_dst(unsigned char *packet, unsigned char *rdesc)
179 {
180 struct trh_hdr *trh;
181 unsigned int riflen, num_rdsc;
182
183 trh = (struct trh_hdr *)packet;
184 if (trh->daddr[0] & (uint8_t) 0x80)
185 return bus_mac; /* multicast */
186
187 if (trh->saddr[0] & TR_RII) {
188 riflen = (ntohs(trh->rcf) & TR_RCF_LEN_MASK) >> 8;
189 if ((ntohs(trh->rcf) >> 13) != 0)
190 return bus_mac; /* ARE or STE */
191 } else
192 return trh->daddr; /* not source routed */
193
194 if (riflen < 6)
195 return trh->daddr; /* last hop, source routed */
196
197 /* riflen is 6 or more, packet has more than one route descriptor */
198 num_rdsc = (riflen / 2) - 1;
199 memset(rdesc, 0, ETH_ALEN);
200 /* offset 4 comes from LAN destination field in LE control frames */
201 if (trh->rcf & htons((uint16_t) TR_RCF_DIR_BIT))
202 memcpy(&rdesc[4], &trh->rseg[num_rdsc - 2], sizeof(__be16));
203 else {
204 memcpy(&rdesc[4], &trh->rseg[1], sizeof(__be16));
205 rdesc[5] = ((ntohs(trh->rseg[0]) & 0x000f) | (rdesc[5] & 0xf0));
206 }
207
208 return NULL;
209 }
210 #endif /* CONFIG_TR */
211
212 /*
213 * Open/initialize the netdevice. This is called (in the current kernel)
214 * sometime after booting when the 'ifconfig' program is run.
215 *
216 * This routine should set everything up anew at each open, even
217 * registers that "should" only need to be set once at boot, so that
218 * there is non-reboot way to recover if something goes wrong.
219 */
220
221 static int lec_open(struct net_device *dev)
222 {
223 netif_start_queue(dev);
224 memset(&dev->stats, 0, sizeof(struct net_device_stats));
225
226 return 0;
227 }
228
229 static void
230 lec_send(struct atm_vcc *vcc, struct sk_buff *skb)
231 {
232 struct net_device *dev = skb->dev;
233
234 ATM_SKB(skb)->vcc = vcc;
235 ATM_SKB(skb)->atm_options = vcc->atm_options;
236
237 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
238 if (vcc->send(vcc, skb) < 0) {
239 dev->stats.tx_dropped++;
240 return;
241 }
242
243 dev->stats.tx_packets++;
244 dev->stats.tx_bytes += skb->len;
245 }
246
247 static void lec_tx_timeout(struct net_device *dev)
248 {
249 pr_info("%s\n", dev->name);
250 dev->trans_start = jiffies;
251 netif_wake_queue(dev);
252 }
253
254 static netdev_tx_t lec_start_xmit(struct sk_buff *skb,
255 struct net_device *dev)
256 {
257 struct sk_buff *skb2;
258 struct lec_priv *priv = netdev_priv(dev);
259 struct lecdatahdr_8023 *lec_h;
260 struct atm_vcc *vcc;
261 struct lec_arp_table *entry;
262 unsigned char *dst;
263 int min_frame_size;
264 #ifdef CONFIG_TR
265 unsigned char rdesc[ETH_ALEN]; /* Token Ring route descriptor */
266 #endif
267 int is_rdesc;
268
269 pr_debug("called\n");
270 if (!priv->lecd) {
271 pr_info("%s:No lecd attached\n", dev->name);
272 dev->stats.tx_errors++;
273 netif_stop_queue(dev);
274 kfree_skb(skb);
275 return NETDEV_TX_OK;
276 }
277
278 pr_debug("skbuff head:%lx data:%lx tail:%lx end:%lx\n",
279 (long)skb->head, (long)skb->data, (long)skb_tail_pointer(skb),
280 (long)skb_end_pointer(skb));
281 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
282 if (memcmp(skb->data, bridge_ula_lec, sizeof(bridge_ula_lec)) == 0)
283 lec_handle_bridge(skb, dev);
284 #endif
285
286 /* Make sure we have room for lec_id */
287 if (skb_headroom(skb) < 2) {
288 pr_debug("reallocating skb\n");
289 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
290 kfree_skb(skb);
291 if (skb2 == NULL)
292 return NETDEV_TX_OK;
293 skb = skb2;
294 }
295 skb_push(skb, 2);
296
297 /* Put le header to place, works for TokenRing too */
298 lec_h = (struct lecdatahdr_8023 *)skb->data;
299 lec_h->le_header = htons(priv->lecid);
300
301 #ifdef CONFIG_TR
302 /*
303 * Ugly. Use this to realign Token Ring packets for
304 * e.g. PCA-200E driver.
305 */
306 if (priv->is_trdev) {
307 skb2 = skb_realloc_headroom(skb, LEC_HEADER_LEN);
308 kfree_skb(skb);
309 if (skb2 == NULL)
310 return NETDEV_TX_OK;
311 skb = skb2;
312 }
313 #endif
314
315 #if DUMP_PACKETS >= 2
316 #define MAX_DUMP_SKB 99
317 #elif DUMP_PACKETS >= 1
318 #define MAX_DUMP_SKB 30
319 #endif
320 #if DUMP_PACKETS >= 1
321 printk(KERN_DEBUG "%s: send datalen:%ld lecid:%4.4x\n",
322 dev->name, skb->len, priv->lecid);
323 print_hex_dump(KERN_DEBUG, "", DUMP_OFFSET, 16, 1,
324 skb->data, min(skb->len, MAX_DUMP_SKB), true);
325 #endif /* DUMP_PACKETS >= 1 */
326
327 /* Minimum ethernet-frame size */
328 #ifdef CONFIG_TR
329 if (priv->is_trdev)
330 min_frame_size = LEC_MINIMUM_8025_SIZE;
331 else
332 #endif
333 min_frame_size = LEC_MINIMUM_8023_SIZE;
334 if (skb->len < min_frame_size) {
335 if ((skb->len + skb_tailroom(skb)) < min_frame_size) {
336 skb2 = skb_copy_expand(skb, 0,
337 min_frame_size - skb->truesize,
338 GFP_ATOMIC);
339 dev_kfree_skb(skb);
340 if (skb2 == NULL) {
341 dev->stats.tx_dropped++;
342 return NETDEV_TX_OK;
343 }
344 skb = skb2;
345 }
346 skb_put(skb, min_frame_size - skb->len);
347 }
348
349 /* Send to right vcc */
350 is_rdesc = 0;
351 dst = lec_h->h_dest;
352 #ifdef CONFIG_TR
353 if (priv->is_trdev) {
354 dst = get_tr_dst(skb->data + 2, rdesc);
355 if (dst == NULL) {
356 dst = rdesc;
357 is_rdesc = 1;
358 }
359 }
360 #endif
361 entry = NULL;
362 vcc = lec_arp_resolve(priv, dst, is_rdesc, &entry);
363 pr_debug("%s:vcc:%p vcc_flags:%lx, entry:%p\n",
364 dev->name, vcc, vcc ? vcc->flags : 0, entry);
365 if (!vcc || !test_bit(ATM_VF_READY, &vcc->flags)) {
366 if (entry && (entry->tx_wait.qlen < LEC_UNRES_QUE_LEN)) {
367 pr_debug("%s:queuing packet, MAC address %pM\n",
368 dev->name, lec_h->h_dest);
369 skb_queue_tail(&entry->tx_wait, skb);
370 } else {
371 pr_debug("%s:tx queue full or no arp entry, dropping, MAC address: %pM\n",
372 dev->name, lec_h->h_dest);
373 dev->stats.tx_dropped++;
374 dev_kfree_skb(skb);
375 }
376 goto out;
377 }
378 #if DUMP_PACKETS > 0
379 printk(KERN_DEBUG "%s:sending to vpi:%d vci:%d\n",
380 dev->name, vcc->vpi, vcc->vci);
381 #endif /* DUMP_PACKETS > 0 */
382
383 while (entry && (skb2 = skb_dequeue(&entry->tx_wait))) {
384 pr_debug("emptying tx queue, MAC address %pM\n", lec_h->h_dest);
385 lec_send(vcc, skb2);
386 }
387
388 lec_send(vcc, skb);
389
390 if (!atm_may_send(vcc, 0)) {
391 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
392
393 vpriv->xoff = 1;
394 netif_stop_queue(dev);
395
396 /*
397 * vcc->pop() might have occurred in between, making
398 * the vcc usuable again. Since xmit is serialized,
399 * this is the only situation we have to re-test.
400 */
401
402 if (atm_may_send(vcc, 0))
403 netif_wake_queue(dev);
404 }
405
406 out:
407 if (entry)
408 lec_arp_put(entry);
409 dev->trans_start = jiffies;
410 return NETDEV_TX_OK;
411 }
412
413 /* The inverse routine to net_open(). */
414 static int lec_close(struct net_device *dev)
415 {
416 netif_stop_queue(dev);
417 return 0;
418 }
419
420 static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)
421 {
422 unsigned long flags;
423 struct net_device *dev = (struct net_device *)vcc->proto_data;
424 struct lec_priv *priv = netdev_priv(dev);
425 struct atmlec_msg *mesg;
426 struct lec_arp_table *entry;
427 int i;
428 char *tmp; /* FIXME */
429
430 atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
431 mesg = (struct atmlec_msg *)skb->data;
432 tmp = skb->data;
433 tmp += sizeof(struct atmlec_msg);
434 pr_debug("%s: msg from zeppelin:%d\n", dev->name, mesg->type);
435 switch (mesg->type) {
436 case l_set_mac_addr:
437 for (i = 0; i < 6; i++)
438 dev->dev_addr[i] = mesg->content.normal.mac_addr[i];
439 break;
440 case l_del_mac_addr:
441 for (i = 0; i < 6; i++)
442 dev->dev_addr[i] = 0;
443 break;
444 case l_addr_delete:
445 lec_addr_delete(priv, mesg->content.normal.atm_addr,
446 mesg->content.normal.flag);
447 break;
448 case l_topology_change:
449 priv->topology_change = mesg->content.normal.flag;
450 break;
451 case l_flush_complete:
452 lec_flush_complete(priv, mesg->content.normal.flag);
453 break;
454 case l_narp_req: /* LANE2: see 7.1.35 in the lane2 spec */
455 spin_lock_irqsave(&priv->lec_arp_lock, flags);
456 entry = lec_arp_find(priv, mesg->content.normal.mac_addr);
457 lec_arp_remove(priv, entry);
458 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
459
460 if (mesg->content.normal.no_source_le_narp)
461 break;
462 /* FALL THROUGH */
463 case l_arp_update:
464 lec_arp_update(priv, mesg->content.normal.mac_addr,
465 mesg->content.normal.atm_addr,
466 mesg->content.normal.flag,
467 mesg->content.normal.targetless_le_arp);
468 pr_debug("in l_arp_update\n");
469 if (mesg->sizeoftlvs != 0) { /* LANE2 3.1.5 */
470 pr_debug("LANE2 3.1.5, got tlvs, size %d\n",
471 mesg->sizeoftlvs);
472 lane2_associate_ind(dev, mesg->content.normal.mac_addr,
473 tmp, mesg->sizeoftlvs);
474 }
475 break;
476 case l_config:
477 priv->maximum_unknown_frame_count =
478 mesg->content.config.maximum_unknown_frame_count;
479 priv->max_unknown_frame_time =
480 (mesg->content.config.max_unknown_frame_time * HZ);
481 priv->max_retry_count = mesg->content.config.max_retry_count;
482 priv->aging_time = (mesg->content.config.aging_time * HZ);
483 priv->forward_delay_time =
484 (mesg->content.config.forward_delay_time * HZ);
485 priv->arp_response_time =
486 (mesg->content.config.arp_response_time * HZ);
487 priv->flush_timeout = (mesg->content.config.flush_timeout * HZ);
488 priv->path_switching_delay =
489 (mesg->content.config.path_switching_delay * HZ);
490 priv->lane_version = mesg->content.config.lane_version;
491 /* LANE2 */
492 priv->lane2_ops = NULL;
493 if (priv->lane_version > 1)
494 priv->lane2_ops = &lane2_ops;
495 if (dev_set_mtu(dev, mesg->content.config.mtu))
496 pr_info("%s: change_mtu to %d failed\n",
497 dev->name, mesg->content.config.mtu);
498 priv->is_proxy = mesg->content.config.is_proxy;
499 break;
500 case l_flush_tran_id:
501 lec_set_flush_tran_id(priv, mesg->content.normal.atm_addr,
502 mesg->content.normal.flag);
503 break;
504 case l_set_lecid:
505 priv->lecid =
506 (unsigned short)(0xffff & mesg->content.normal.flag);
507 break;
508 case l_should_bridge:
509 #if defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE)
510 {
511 pr_debug("%s: bridge zeppelin asks about %pM\n",
512 dev->name, mesg->content.proxy.mac_addr);
513
514 if (br_fdb_test_addr_hook == NULL)
515 break;
516
517 if (br_fdb_test_addr_hook(dev, mesg->content.proxy.mac_addr)) {
518 /* hit from bridge table, send LE_ARP_RESPONSE */
519 struct sk_buff *skb2;
520 struct sock *sk;
521
522 pr_debug("%s: entry found, responding to zeppelin\n",
523 dev->name);
524 skb2 = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
525 if (skb2 == NULL)
526 break;
527 skb2->len = sizeof(struct atmlec_msg);
528 skb_copy_to_linear_data(skb2, mesg, sizeof(*mesg));
529 atm_force_charge(priv->lecd, skb2->truesize);
530 sk = sk_atm(priv->lecd);
531 skb_queue_tail(&sk->sk_receive_queue, skb2);
532 sk->sk_data_ready(sk, skb2->len);
533 }
534 }
535 #endif /* defined(CONFIG_BRIDGE) || defined(CONFIG_BRIDGE_MODULE) */
536 break;
537 default:
538 pr_info("%s: Unknown message type %d\n", dev->name, mesg->type);
539 dev_kfree_skb(skb);
540 return -EINVAL;
541 }
542 dev_kfree_skb(skb);
543 return 0;
544 }
545
546 static void lec_atm_close(struct atm_vcc *vcc)
547 {
548 struct sk_buff *skb;
549 struct net_device *dev = (struct net_device *)vcc->proto_data;
550 struct lec_priv *priv = netdev_priv(dev);
551
552 priv->lecd = NULL;
553 /* Do something needful? */
554
555 netif_stop_queue(dev);
556 lec_arp_destroy(priv);
557
558 if (skb_peek(&sk_atm(vcc)->sk_receive_queue))
559 pr_info("%s closing with messages pending\n", dev->name);
560 while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue))) {
561 atm_return(vcc, skb->truesize);
562 dev_kfree_skb(skb);
563 }
564
565 pr_info("%s: Shut down!\n", dev->name);
566 module_put(THIS_MODULE);
567 }
568
569 static struct atmdev_ops lecdev_ops = {
570 .close = lec_atm_close,
571 .send = lec_atm_send
572 };
573
574 static struct atm_dev lecatm_dev = {
575 .ops = &lecdev_ops,
576 .type = "lec",
577 .number = 999, /* dummy device number */
578 .lock = __SPIN_LOCK_UNLOCKED(lecatm_dev.lock)
579 };
580
581 /*
582 * LANE2: new argument struct sk_buff *data contains
583 * the LE_ARP based TLVs introduced in the LANE2 spec
584 */
585 static int
586 send_to_lecd(struct lec_priv *priv, atmlec_msg_type type,
587 const unsigned char *mac_addr, const unsigned char *atm_addr,
588 struct sk_buff *data)
589 {
590 struct sock *sk;
591 struct sk_buff *skb;
592 struct atmlec_msg *mesg;
593
594 if (!priv || !priv->lecd)
595 return -1;
596 skb = alloc_skb(sizeof(struct atmlec_msg), GFP_ATOMIC);
597 if (!skb)
598 return -1;
599 skb->len = sizeof(struct atmlec_msg);
600 mesg = (struct atmlec_msg *)skb->data;
601 memset(mesg, 0, sizeof(struct atmlec_msg));
602 mesg->type = type;
603 if (data != NULL)
604 mesg->sizeoftlvs = data->len;
605 if (mac_addr)
606 memcpy(&mesg->content.normal.mac_addr, mac_addr, ETH_ALEN);
607 else
608 mesg->content.normal.targetless_le_arp = 1;
609 if (atm_addr)
610 memcpy(&mesg->content.normal.atm_addr, atm_addr, ATM_ESA_LEN);
611
612 atm_force_charge(priv->lecd, skb->truesize);
613 sk = sk_atm(priv->lecd);
614 skb_queue_tail(&sk->sk_receive_queue, skb);
615 sk->sk_data_ready(sk, skb->len);
616
617 if (data != NULL) {
618 pr_debug("about to send %d bytes of data\n", data->len);
619 atm_force_charge(priv->lecd, data->truesize);
620 skb_queue_tail(&sk->sk_receive_queue, data);
621 sk->sk_data_ready(sk, skb->len);
622 }
623
624 return 0;
625 }
626
627 /* shamelessly stolen from drivers/net/net_init.c */
628 static int lec_change_mtu(struct net_device *dev, int new_mtu)
629 {
630 if ((new_mtu < 68) || (new_mtu > 18190))
631 return -EINVAL;
632 dev->mtu = new_mtu;
633 return 0;
634 }
635
636 static void lec_set_multicast_list(struct net_device *dev)
637 {
638 /*
639 * by default, all multicast frames arrive over the bus.
640 * eventually support selective multicast service
641 */
642 return;
643 }
644
645 static const struct net_device_ops lec_netdev_ops = {
646 .ndo_open = lec_open,
647 .ndo_stop = lec_close,
648 .ndo_start_xmit = lec_start_xmit,
649 .ndo_change_mtu = lec_change_mtu,
650 .ndo_tx_timeout = lec_tx_timeout,
651 .ndo_set_multicast_list = lec_set_multicast_list,
652 };
653
654 static const unsigned char lec_ctrl_magic[] = {
655 0xff,
656 0x00,
657 0x01,
658 0x01
659 };
660
661 #define LEC_DATA_DIRECT_8023 2
662 #define LEC_DATA_DIRECT_8025 3
663
664 static int lec_is_data_direct(struct atm_vcc *vcc)
665 {
666 return ((vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8023) ||
667 (vcc->sap.blli[0].l3.tr9577.snap[4] == LEC_DATA_DIRECT_8025));
668 }
669
670 static void lec_push(struct atm_vcc *vcc, struct sk_buff *skb)
671 {
672 unsigned long flags;
673 struct net_device *dev = (struct net_device *)vcc->proto_data;
674 struct lec_priv *priv = netdev_priv(dev);
675
676 #if DUMP_PACKETS > 0
677 printk(KERN_DEBUG "%s: vcc vpi:%d vci:%d\n",
678 dev->name, vcc->vpi, vcc->vci);
679 #endif
680 if (!skb) {
681 pr_debug("%s: null skb\n", dev->name);
682 lec_vcc_close(priv, vcc);
683 return;
684 }
685 #if DUMP_PACKETS >= 2
686 #define MAX_SKB_DUMP 99
687 #elif DUMP_PACKETS >= 1
688 #define MAX_SKB_DUMP 30
689 #endif
690 #if DUMP_PACKETS > 0
691 printk(KERN_DEBUG "%s: rcv datalen:%ld lecid:%4.4x\n",
692 dev->name, skb->len, priv->lecid);
693 print_hex_dump(KERN_DEBUG, "", DUMP_OFFSET, 16, 1,
694 skb->data, min(MAX_SKB_DUMP, skb->len), true);
695 #endif /* DUMP_PACKETS > 0 */
696 if (memcmp(skb->data, lec_ctrl_magic, 4) == 0) {
697 /* Control frame, to daemon */
698 struct sock *sk = sk_atm(vcc);
699
700 pr_debug("%s: To daemon\n", dev->name);
701 skb_queue_tail(&sk->sk_receive_queue, skb);
702 sk->sk_data_ready(sk, skb->len);
703 } else { /* Data frame, queue to protocol handlers */
704 struct lec_arp_table *entry;
705 unsigned char *src, *dst;
706
707 atm_return(vcc, skb->truesize);
708 if (*(__be16 *) skb->data == htons(priv->lecid) ||
709 !priv->lecd || !(dev->flags & IFF_UP)) {
710 /*
711 * Probably looping back, or if lecd is missing,
712 * lecd has gone down
713 */
714 pr_debug("Ignoring frame...\n");
715 dev_kfree_skb(skb);
716 return;
717 }
718 #ifdef CONFIG_TR
719 if (priv->is_trdev)
720 dst = ((struct lecdatahdr_8025 *)skb->data)->h_dest;
721 else
722 #endif
723 dst = ((struct lecdatahdr_8023 *)skb->data)->h_dest;
724
725 /*
726 * If this is a Data Direct VCC, and the VCC does not match
727 * the LE_ARP cache entry, delete the LE_ARP cache entry.
728 */
729 spin_lock_irqsave(&priv->lec_arp_lock, flags);
730 if (lec_is_data_direct(vcc)) {
731 #ifdef CONFIG_TR
732 if (priv->is_trdev)
733 src =
734 ((struct lecdatahdr_8025 *)skb->data)->
735 h_source;
736 else
737 #endif
738 src =
739 ((struct lecdatahdr_8023 *)skb->data)->
740 h_source;
741 entry = lec_arp_find(priv, src);
742 if (entry && entry->vcc != vcc) {
743 lec_arp_remove(priv, entry);
744 lec_arp_put(entry);
745 }
746 }
747 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
748
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)) {
752 dev_kfree_skb(skb);
753 return;
754 }
755 if (!hlist_empty(&priv->lec_arp_empty_ones))
756 lec_arp_check_empties(priv, vcc, skb);
757 skb_pull(skb, 2); /* skip lec_id */
758 #ifdef CONFIG_TR
759 if (priv->is_trdev)
760 skb->protocol = tr_type_trans(skb, dev);
761 else
762 #endif
763 skb->protocol = eth_type_trans(skb, dev);
764 dev->stats.rx_packets++;
765 dev->stats.rx_bytes += skb->len;
766 memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
767 netif_rx(skb);
768 }
769 }
770
771 static void lec_pop(struct atm_vcc *vcc, struct sk_buff *skb)
772 {
773 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
774 struct net_device *dev = skb->dev;
775
776 if (vpriv == NULL) {
777 pr_info("vpriv = NULL!?!?!?\n");
778 return;
779 }
780
781 vpriv->old_pop(vcc, skb);
782
783 if (vpriv->xoff && atm_may_send(vcc, 0)) {
784 vpriv->xoff = 0;
785 if (netif_running(dev) && netif_queue_stopped(dev))
786 netif_wake_queue(dev);
787 }
788 }
789
790 static int lec_vcc_attach(struct atm_vcc *vcc, void __user *arg)
791 {
792 struct lec_vcc_priv *vpriv;
793 int bytes_left;
794 struct atmlec_ioc ioc_data;
795
796 /* Lecd must be up in this case */
797 bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmlec_ioc));
798 if (bytes_left != 0)
799 pr_info("copy from user failed for %d bytes\n", bytes_left);
800 if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF ||
801 !dev_lec[ioc_data.dev_num])
802 return -EINVAL;
803 vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL);
804 if (!vpriv)
805 return -ENOMEM;
806 vpriv->xoff = 0;
807 vpriv->old_pop = vcc->pop;
808 vcc->user_back = vpriv;
809 vcc->pop = lec_pop;
810 lec_vcc_added(netdev_priv(dev_lec[ioc_data.dev_num]),
811 &ioc_data, vcc, vcc->push);
812 vcc->proto_data = dev_lec[ioc_data.dev_num];
813 vcc->push = lec_push;
814 return 0;
815 }
816
817 static int lec_mcast_attach(struct atm_vcc *vcc, int arg)
818 {
819 if (arg < 0 || arg >= MAX_LEC_ITF || !dev_lec[arg])
820 return -EINVAL;
821 vcc->proto_data = dev_lec[arg];
822 return lec_mcast_make((struct lec_priv *)netdev_priv(dev_lec[arg]),
823 vcc);
824 }
825
826 /* Initialize device. */
827 static int lecd_attach(struct atm_vcc *vcc, int arg)
828 {
829 int i;
830 struct lec_priv *priv;
831
832 if (arg < 0)
833 i = 0;
834 else
835 i = arg;
836 #ifdef CONFIG_TR
837 if (arg >= MAX_LEC_ITF)
838 return -EINVAL;
839 #else /* Reserve the top NUM_TR_DEVS for TR */
840 if (arg >= (MAX_LEC_ITF - NUM_TR_DEVS))
841 return -EINVAL;
842 #endif
843 if (!dev_lec[i]) {
844 int is_trdev, size;
845
846 is_trdev = 0;
847 if (i >= (MAX_LEC_ITF - NUM_TR_DEVS))
848 is_trdev = 1;
849
850 size = sizeof(struct lec_priv);
851 #ifdef CONFIG_TR
852 if (is_trdev)
853 dev_lec[i] = alloc_trdev(size);
854 else
855 #endif
856 dev_lec[i] = alloc_etherdev(size);
857 if (!dev_lec[i])
858 return -ENOMEM;
859 dev_lec[i]->netdev_ops = &lec_netdev_ops;
860 snprintf(dev_lec[i]->name, IFNAMSIZ, "lec%d", i);
861 if (register_netdev(dev_lec[i])) {
862 free_netdev(dev_lec[i]);
863 return -EINVAL;
864 }
865
866 priv = netdev_priv(dev_lec[i]);
867 priv->is_trdev = is_trdev;
868 } else {
869 priv = netdev_priv(dev_lec[i]);
870 if (priv->lecd)
871 return -EADDRINUSE;
872 }
873 lec_arp_init(priv);
874 priv->itfnum = i; /* LANE2 addition */
875 priv->lecd = vcc;
876 vcc->dev = &lecatm_dev;
877 vcc_insert_socket(sk_atm(vcc));
878
879 vcc->proto_data = dev_lec[i];
880 set_bit(ATM_VF_META, &vcc->flags);
881 set_bit(ATM_VF_READY, &vcc->flags);
882
883 /* Set default values to these variables */
884 priv->maximum_unknown_frame_count = 1;
885 priv->max_unknown_frame_time = (1 * HZ);
886 priv->vcc_timeout_period = (1200 * HZ);
887 priv->max_retry_count = 1;
888 priv->aging_time = (300 * HZ);
889 priv->forward_delay_time = (15 * HZ);
890 priv->topology_change = 0;
891 priv->arp_response_time = (1 * HZ);
892 priv->flush_timeout = (4 * HZ);
893 priv->path_switching_delay = (6 * HZ);
894
895 if (dev_lec[i]->flags & IFF_UP)
896 netif_start_queue(dev_lec[i]);
897 __module_get(THIS_MODULE);
898 return i;
899 }
900
901 #ifdef CONFIG_PROC_FS
902 static const char *lec_arp_get_status_string(unsigned char status)
903 {
904 static const char *const lec_arp_status_string[] = {
905 "ESI_UNKNOWN ",
906 "ESI_ARP_PENDING ",
907 "ESI_VC_PENDING ",
908 "<Undefined> ",
909 "ESI_FLUSH_PENDING ",
910 "ESI_FORWARD_DIRECT"
911 };
912
913 if (status > ESI_FORWARD_DIRECT)
914 status = 3; /* ESI_UNDEFINED */
915 return lec_arp_status_string[status];
916 }
917
918 static void lec_info(struct seq_file *seq, struct lec_arp_table *entry)
919 {
920 int i;
921
922 for (i = 0; i < ETH_ALEN; i++)
923 seq_printf(seq, "%2.2x", entry->mac_addr[i] & 0xff);
924 seq_printf(seq, " ");
925 for (i = 0; i < ATM_ESA_LEN; i++)
926 seq_printf(seq, "%2.2x", entry->atm_addr[i] & 0xff);
927 seq_printf(seq, " %s %4.4x", lec_arp_get_status_string(entry->status),
928 entry->flags & 0xffff);
929 if (entry->vcc)
930 seq_printf(seq, "%3d %3d ", entry->vcc->vpi, entry->vcc->vci);
931 else
932 seq_printf(seq, " ");
933 if (entry->recv_vcc) {
934 seq_printf(seq, " %3d %3d", entry->recv_vcc->vpi,
935 entry->recv_vcc->vci);
936 }
937 seq_putc(seq, '\n');
938 }
939
940 struct lec_state {
941 unsigned long flags;
942 struct lec_priv *locked;
943 struct hlist_node *node;
944 struct net_device *dev;
945 int itf;
946 int arp_table;
947 int misc_table;
948 };
949
950 static void *lec_tbl_walk(struct lec_state *state, struct hlist_head *tbl,
951 loff_t *l)
952 {
953 struct hlist_node *e = state->node;
954 struct lec_arp_table *tmp;
955
956 if (!e)
957 e = tbl->first;
958 if (e == SEQ_START_TOKEN) {
959 e = tbl->first;
960 --*l;
961 }
962
963 hlist_for_each_entry_from(tmp, e, next) {
964 if (--*l < 0)
965 break;
966 }
967 state->node = e;
968
969 return (*l < 0) ? state : NULL;
970 }
971
972 static void *lec_arp_walk(struct lec_state *state, loff_t *l,
973 struct lec_priv *priv)
974 {
975 void *v = NULL;
976 int p;
977
978 for (p = state->arp_table; p < LEC_ARP_TABLE_SIZE; p++) {
979 v = lec_tbl_walk(state, &priv->lec_arp_tables[p], l);
980 if (v)
981 break;
982 }
983 state->arp_table = p;
984 return v;
985 }
986
987 static void *lec_misc_walk(struct lec_state *state, loff_t *l,
988 struct lec_priv *priv)
989 {
990 struct hlist_head *lec_misc_tables[] = {
991 &priv->lec_arp_empty_ones,
992 &priv->lec_no_forward,
993 &priv->mcast_fwds
994 };
995 void *v = NULL;
996 int q;
997
998 for (q = state->misc_table; q < ARRAY_SIZE(lec_misc_tables); q++) {
999 v = lec_tbl_walk(state, lec_misc_tables[q], l);
1000 if (v)
1001 break;
1002 }
1003 state->misc_table = q;
1004 return v;
1005 }
1006
1007 static void *lec_priv_walk(struct lec_state *state, loff_t *l,
1008 struct lec_priv *priv)
1009 {
1010 if (!state->locked) {
1011 state->locked = priv;
1012 spin_lock_irqsave(&priv->lec_arp_lock, state->flags);
1013 }
1014 if (!lec_arp_walk(state, l, priv) && !lec_misc_walk(state, l, priv)) {
1015 spin_unlock_irqrestore(&priv->lec_arp_lock, state->flags);
1016 state->locked = NULL;
1017 /* Partial state reset for the next time we get called */
1018 state->arp_table = state->misc_table = 0;
1019 }
1020 return state->locked;
1021 }
1022
1023 static void *lec_itf_walk(struct lec_state *state, loff_t *l)
1024 {
1025 struct net_device *dev;
1026 void *v;
1027
1028 dev = state->dev ? state->dev : dev_lec[state->itf];
1029 v = (dev && netdev_priv(dev)) ?
1030 lec_priv_walk(state, l, netdev_priv(dev)) : NULL;
1031 if (!v && dev) {
1032 dev_put(dev);
1033 /* Partial state reset for the next time we get called */
1034 dev = NULL;
1035 }
1036 state->dev = dev;
1037 return v;
1038 }
1039
1040 static void *lec_get_idx(struct lec_state *state, loff_t l)
1041 {
1042 void *v = NULL;
1043
1044 for (; state->itf < MAX_LEC_ITF; state->itf++) {
1045 v = lec_itf_walk(state, &l);
1046 if (v)
1047 break;
1048 }
1049 return v;
1050 }
1051
1052 static void *lec_seq_start(struct seq_file *seq, loff_t *pos)
1053 {
1054 struct lec_state *state = seq->private;
1055
1056 state->itf = 0;
1057 state->dev = NULL;
1058 state->locked = NULL;
1059 state->arp_table = 0;
1060 state->misc_table = 0;
1061 state->node = SEQ_START_TOKEN;
1062
1063 return *pos ? lec_get_idx(state, *pos) : SEQ_START_TOKEN;
1064 }
1065
1066 static void lec_seq_stop(struct seq_file *seq, void *v)
1067 {
1068 struct lec_state *state = seq->private;
1069
1070 if (state->dev) {
1071 spin_unlock_irqrestore(&state->locked->lec_arp_lock,
1072 state->flags);
1073 dev_put(state->dev);
1074 }
1075 }
1076
1077 static void *lec_seq_next(struct seq_file *seq, void *v, loff_t *pos)
1078 {
1079 struct lec_state *state = seq->private;
1080
1081 v = lec_get_idx(state, 1);
1082 *pos += !!PTR_ERR(v);
1083 return v;
1084 }
1085
1086 static int lec_seq_show(struct seq_file *seq, void *v)
1087 {
1088 static const char lec_banner[] =
1089 "Itf MAC ATM destination"
1090 " Status Flags "
1091 "VPI/VCI Recv VPI/VCI\n";
1092
1093 if (v == SEQ_START_TOKEN)
1094 seq_puts(seq, lec_banner);
1095 else {
1096 struct lec_state *state = seq->private;
1097 struct net_device *dev = state->dev;
1098 struct lec_arp_table *entry = hlist_entry(state->node,
1099 struct lec_arp_table,
1100 next);
1101
1102 seq_printf(seq, "%s ", dev->name);
1103 lec_info(seq, entry);
1104 }
1105 return 0;
1106 }
1107
1108 static const 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,
1113 };
1114
1115 static int lec_seq_open(struct inode *inode, struct file *file)
1116 {
1117 return seq_open_private(file, &lec_seq_ops, sizeof(struct lec_state));
1118 }
1119
1120 static const struct file_operations lec_seq_fops = {
1121 .owner = THIS_MODULE,
1122 .open = lec_seq_open,
1123 .read = seq_read,
1124 .llseek = seq_lseek,
1125 .release = seq_release_private,
1126 };
1127 #endif
1128
1129 static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1130 {
1131 struct atm_vcc *vcc = ATM_SD(sock);
1132 int err = 0;
1133
1134 switch (cmd) {
1135 case ATMLEC_CTRL:
1136 case ATMLEC_MCAST:
1137 case ATMLEC_DATA:
1138 if (!capable(CAP_NET_ADMIN))
1139 return -EPERM;
1140 break;
1141 default:
1142 return -ENOIOCTLCMD;
1143 }
1144
1145 switch (cmd) {
1146 case ATMLEC_CTRL:
1147 err = lecd_attach(vcc, (int)arg);
1148 if (err >= 0)
1149 sock->state = SS_CONNECTED;
1150 break;
1151 case ATMLEC_MCAST:
1152 err = lec_mcast_attach(vcc, (int)arg);
1153 break;
1154 case ATMLEC_DATA:
1155 err = lec_vcc_attach(vcc, (void __user *)arg);
1156 break;
1157 }
1158
1159 return err;
1160 }
1161
1162 static struct atm_ioctl lane_ioctl_ops = {
1163 .owner = THIS_MODULE,
1164 .ioctl = lane_ioctl,
1165 };
1166
1167 static int __init lane_module_init(void)
1168 {
1169 #ifdef CONFIG_PROC_FS
1170 struct proc_dir_entry *p;
1171
1172 p = proc_create("lec", S_IRUGO, atm_proc_root, &lec_seq_fops);
1173 if (!p) {
1174 pr_err("Unable to initialize /proc/net/atm/lec\n");
1175 return -ENOMEM;
1176 }
1177 #endif
1178
1179 register_atm_ioctl(&lane_ioctl_ops);
1180 pr_info("lec.c: " __DATE__ " " __TIME__ " initialized\n");
1181 return 0;
1182 }
1183
1184 static void __exit lane_module_cleanup(void)
1185 {
1186 int i;
1187 struct lec_priv *priv;
1188
1189 remove_proc_entry("lec", atm_proc_root);
1190
1191 deregister_atm_ioctl(&lane_ioctl_ops);
1192
1193 for (i = 0; i < MAX_LEC_ITF; i++) {
1194 if (dev_lec[i] != NULL) {
1195 priv = netdev_priv(dev_lec[i]);
1196 unregister_netdev(dev_lec[i]);
1197 free_netdev(dev_lec[i]);
1198 dev_lec[i] = NULL;
1199 }
1200 }
1201
1202 return;
1203 }
1204
1205 module_init(lane_module_init);
1206 module_exit(lane_module_cleanup);
1207
1208 /*
1209 * LANE2: 3.1.3, LE_RESOLVE.request
1210 * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
1211 * If sizeoftlvs == NULL the default TLVs associated with with this
1212 * lec will be used.
1213 * If dst_mac == NULL, targetless LE_ARP will be sent
1214 */
1215 static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
1216 u8 **tlvs, u32 *sizeoftlvs)
1217 {
1218 unsigned long flags;
1219 struct lec_priv *priv = netdev_priv(dev);
1220 struct lec_arp_table *table;
1221 struct sk_buff *skb;
1222 int retval;
1223
1224 if (force == 0) {
1225 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1226 table = lec_arp_find(priv, dst_mac);
1227 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1228 if (table == NULL)
1229 return -1;
1230
1231 *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
1232 if (*tlvs == NULL)
1233 return -1;
1234
1235 *sizeoftlvs = table->sizeoftlvs;
1236
1237 return 0;
1238 }
1239
1240 if (sizeoftlvs == NULL)
1241 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
1242
1243 else {
1244 skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
1245 if (skb == NULL)
1246 return -1;
1247 skb->len = *sizeoftlvs;
1248 skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
1249 retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
1250 }
1251 return retval;
1252 }
1253
1254 /*
1255 * LANE2: 3.1.4, LE_ASSOCIATE.request
1256 * Associate the *tlvs with the *lan_dst address.
1257 * Will overwrite any previous association
1258 * Returns 1 for success, 0 for failure (out of memory)
1259 *
1260 */
1261 static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
1262 const u8 *tlvs, u32 sizeoftlvs)
1263 {
1264 int retval;
1265 struct sk_buff *skb;
1266 struct lec_priv *priv = netdev_priv(dev);
1267
1268 if (compare_ether_addr(lan_dst, dev->dev_addr))
1269 return 0; /* not our mac address */
1270
1271 kfree(priv->tlvs); /* NULL if there was no previous association */
1272
1273 priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
1274 if (priv->tlvs == NULL)
1275 return 0;
1276 priv->sizeoftlvs = sizeoftlvs;
1277
1278 skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
1279 if (skb == NULL)
1280 return 0;
1281 skb->len = sizeoftlvs;
1282 skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
1283 retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
1284 if (retval != 0)
1285 pr_info("lec.c: lane2_associate_req() failed\n");
1286 /*
1287 * If the previous association has changed we must
1288 * somehow notify other LANE entities about the change
1289 */
1290 return 1;
1291 }
1292
1293 /*
1294 * LANE2: 3.1.5, LE_ASSOCIATE.indication
1295 *
1296 */
1297 static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
1298 const u8 *tlvs, u32 sizeoftlvs)
1299 {
1300 #if 0
1301 int i = 0;
1302 #endif
1303 struct lec_priv *priv = netdev_priv(dev);
1304 #if 0 /*
1305 * Why have the TLVs in LE_ARP entries
1306 * since we do not use them? When you
1307 * uncomment this code, make sure the
1308 * TLVs get freed when entry is killed
1309 */
1310 struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
1311
1312 if (entry == NULL)
1313 return; /* should not happen */
1314
1315 kfree(entry->tlvs);
1316
1317 entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
1318 if (entry->tlvs == NULL)
1319 return;
1320 entry->sizeoftlvs = sizeoftlvs;
1321 #endif
1322 #if 0
1323 pr_info("\n");
1324 pr_info("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
1325 while (i < sizeoftlvs)
1326 pr_cont("%02x ", tlvs[i++]);
1327
1328 pr_cont("\n");
1329 #endif
1330
1331 /* tell MPOA about the TLVs we saw */
1332 if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
1333 priv->lane2_ops->associate_indicator(dev, mac_addr,
1334 tlvs, sizeoftlvs);
1335 }
1336 return;
1337 }
1338
1339 /*
1340 * Here starts what used to lec_arpc.c
1341 *
1342 * lec_arpc.c was added here when making
1343 * lane client modular. October 1997
1344 */
1345
1346 #include <linux/types.h>
1347 #include <linux/timer.h>
1348 #include <linux/param.h>
1349 #include <asm/atomic.h>
1350 #include <linux/inetdevice.h>
1351 #include <net/route.h>
1352
1353 #if 0
1354 #define pr_debug(format, args...)
1355 /*
1356 #define pr_debug printk
1357 */
1358 #endif
1359 #define DEBUG_ARP_TABLE 0
1360
1361 #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
1362
1363 static void lec_arp_check_expire(struct work_struct *work);
1364 static void lec_arp_expire_arp(unsigned long data);
1365
1366 /*
1367 * Arp table funcs
1368 */
1369
1370 #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE - 1))
1371
1372 /*
1373 * Initialization of arp-cache
1374 */
1375 static void lec_arp_init(struct lec_priv *priv)
1376 {
1377 unsigned short i;
1378
1379 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
1380 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
1381 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1382 INIT_HLIST_HEAD(&priv->lec_no_forward);
1383 INIT_HLIST_HEAD(&priv->mcast_fwds);
1384 spin_lock_init(&priv->lec_arp_lock);
1385 INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
1386 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
1387 }
1388
1389 static void lec_arp_clear_vccs(struct lec_arp_table *entry)
1390 {
1391 if (entry->vcc) {
1392 struct atm_vcc *vcc = entry->vcc;
1393 struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
1394 struct net_device *dev = (struct net_device *)vcc->proto_data;
1395
1396 vcc->pop = vpriv->old_pop;
1397 if (vpriv->xoff)
1398 netif_wake_queue(dev);
1399 kfree(vpriv);
1400 vcc->user_back = NULL;
1401 vcc->push = entry->old_push;
1402 vcc_release_async(vcc, -EPIPE);
1403 entry->vcc = NULL;
1404 }
1405 if (entry->recv_vcc) {
1406 entry->recv_vcc->push = entry->old_recv_push;
1407 vcc_release_async(entry->recv_vcc, -EPIPE);
1408 entry->recv_vcc = NULL;
1409 }
1410 }
1411
1412 /*
1413 * Insert entry to lec_arp_table
1414 * LANE2: Add to the end of the list to satisfy 8.1.13
1415 */
1416 static inline void
1417 lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
1418 {
1419 struct hlist_head *tmp;
1420
1421 tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
1422 hlist_add_head(&entry->next, tmp);
1423
1424 pr_debug("Added entry:%pM\n", entry->mac_addr);
1425 }
1426
1427 /*
1428 * Remove entry from lec_arp_table
1429 */
1430 static int
1431 lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
1432 {
1433 struct hlist_node *node;
1434 struct lec_arp_table *entry;
1435 int i, remove_vcc = 1;
1436
1437 if (!to_remove)
1438 return -1;
1439
1440 hlist_del(&to_remove->next);
1441 del_timer(&to_remove->timer);
1442
1443 /*
1444 * If this is the only MAC connected to this VCC,
1445 * also tear down the VCC
1446 */
1447 if (to_remove->status >= ESI_FLUSH_PENDING) {
1448 /*
1449 * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
1450 */
1451 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1452 hlist_for_each_entry(entry, node,
1453 &priv->lec_arp_tables[i], next) {
1454 if (memcmp(to_remove->atm_addr,
1455 entry->atm_addr, ATM_ESA_LEN) == 0) {
1456 remove_vcc = 0;
1457 break;
1458 }
1459 }
1460 }
1461 if (remove_vcc)
1462 lec_arp_clear_vccs(to_remove);
1463 }
1464 skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
1465
1466 pr_debug("Removed entry:%pM\n", to_remove->mac_addr);
1467 return 0;
1468 }
1469
1470 #if DEBUG_ARP_TABLE
1471 static const char *get_status_string(unsigned char st)
1472 {
1473 switch (st) {
1474 case ESI_UNKNOWN:
1475 return "ESI_UNKNOWN";
1476 case ESI_ARP_PENDING:
1477 return "ESI_ARP_PENDING";
1478 case ESI_VC_PENDING:
1479 return "ESI_VC_PENDING";
1480 case ESI_FLUSH_PENDING:
1481 return "ESI_FLUSH_PENDING";
1482 case ESI_FORWARD_DIRECT:
1483 return "ESI_FORWARD_DIRECT";
1484 }
1485 return "<UNKNOWN>";
1486 }
1487
1488 static void dump_arp_table(struct lec_priv *priv)
1489 {
1490 struct hlist_node *node;
1491 struct lec_arp_table *rulla;
1492 char buf[256];
1493 int i, j, offset;
1494
1495 pr_info("Dump %p:\n", priv);
1496 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1497 hlist_for_each_entry(rulla, node,
1498 &priv->lec_arp_tables[i], next) {
1499 offset = 0;
1500 offset += sprintf(buf, "%d: %p\n", i, rulla);
1501 offset += sprintf(buf + offset, "Mac: %pM",
1502 rulla->mac_addr);
1503 offset += sprintf(buf + offset, " Atm:");
1504 for (j = 0; j < ATM_ESA_LEN; j++) {
1505 offset += sprintf(buf + offset,
1506 "%2.2x ",
1507 rulla->atm_addr[j] & 0xff);
1508 }
1509 offset += sprintf(buf + offset,
1510 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1511 rulla->vcc ? rulla->vcc->vpi : 0,
1512 rulla->vcc ? rulla->vcc->vci : 0,
1513 rulla->recv_vcc ? rulla->recv_vcc->
1514 vpi : 0,
1515 rulla->recv_vcc ? rulla->recv_vcc->
1516 vci : 0, rulla->last_used,
1517 rulla->timestamp, rulla->no_tries);
1518 offset +=
1519 sprintf(buf + offset,
1520 "Flags:%x, Packets_flooded:%x, Status: %s ",
1521 rulla->flags, rulla->packets_flooded,
1522 get_status_string(rulla->status));
1523 pr_info("%s\n", buf);
1524 }
1525 }
1526
1527 if (!hlist_empty(&priv->lec_no_forward))
1528 pr_info("No forward\n");
1529 hlist_for_each_entry(rulla, node, &priv->lec_no_forward, next) {
1530 offset = 0;
1531 offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1532 offset += sprintf(buf + offset, " Atm:");
1533 for (j = 0; j < ATM_ESA_LEN; j++) {
1534 offset += sprintf(buf + offset, "%2.2x ",
1535 rulla->atm_addr[j] & 0xff);
1536 }
1537 offset += sprintf(buf + offset,
1538 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1539 rulla->vcc ? rulla->vcc->vpi : 0,
1540 rulla->vcc ? rulla->vcc->vci : 0,
1541 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1542 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1543 rulla->last_used,
1544 rulla->timestamp, rulla->no_tries);
1545 offset += sprintf(buf + offset,
1546 "Flags:%x, Packets_flooded:%x, Status: %s ",
1547 rulla->flags, rulla->packets_flooded,
1548 get_status_string(rulla->status));
1549 pr_info("%s\n", buf);
1550 }
1551
1552 if (!hlist_empty(&priv->lec_arp_empty_ones))
1553 pr_info("Empty ones\n");
1554 hlist_for_each_entry(rulla, node, &priv->lec_arp_empty_ones, next) {
1555 offset = 0;
1556 offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1557 offset += sprintf(buf + offset, " Atm:");
1558 for (j = 0; j < ATM_ESA_LEN; j++) {
1559 offset += sprintf(buf + offset, "%2.2x ",
1560 rulla->atm_addr[j] & 0xff);
1561 }
1562 offset += sprintf(buf + offset,
1563 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1564 rulla->vcc ? rulla->vcc->vpi : 0,
1565 rulla->vcc ? rulla->vcc->vci : 0,
1566 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1567 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1568 rulla->last_used,
1569 rulla->timestamp, rulla->no_tries);
1570 offset += sprintf(buf + offset,
1571 "Flags:%x, Packets_flooded:%x, Status: %s ",
1572 rulla->flags, rulla->packets_flooded,
1573 get_status_string(rulla->status));
1574 pr_info("%s", buf);
1575 }
1576
1577 if (!hlist_empty(&priv->mcast_fwds))
1578 pr_info("Multicast Forward VCCs\n");
1579 hlist_for_each_entry(rulla, node, &priv->mcast_fwds, next) {
1580 offset = 0;
1581 offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
1582 offset += sprintf(buf + offset, " Atm:");
1583 for (j = 0; j < ATM_ESA_LEN; j++) {
1584 offset += sprintf(buf + offset, "%2.2x ",
1585 rulla->atm_addr[j] & 0xff);
1586 }
1587 offset += sprintf(buf + offset,
1588 "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
1589 rulla->vcc ? rulla->vcc->vpi : 0,
1590 rulla->vcc ? rulla->vcc->vci : 0,
1591 rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
1592 rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
1593 rulla->last_used,
1594 rulla->timestamp, rulla->no_tries);
1595 offset += sprintf(buf + offset,
1596 "Flags:%x, Packets_flooded:%x, Status: %s ",
1597 rulla->flags, rulla->packets_flooded,
1598 get_status_string(rulla->status));
1599 pr_info("%s\n", buf);
1600 }
1601
1602 }
1603 #else
1604 #define dump_arp_table(priv) do { } while (0)
1605 #endif
1606
1607 /*
1608 * Destruction of arp-cache
1609 */
1610 static void lec_arp_destroy(struct lec_priv *priv)
1611 {
1612 unsigned long flags;
1613 struct hlist_node *node, *next;
1614 struct lec_arp_table *entry;
1615 int i;
1616
1617 cancel_rearming_delayed_work(&priv->lec_arp_work);
1618
1619 /*
1620 * Remove all entries
1621 */
1622
1623 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1624 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1625 hlist_for_each_entry_safe(entry, node, next,
1626 &priv->lec_arp_tables[i], next) {
1627 lec_arp_remove(priv, entry);
1628 lec_arp_put(entry);
1629 }
1630 INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
1631 }
1632
1633 hlist_for_each_entry_safe(entry, node, next,
1634 &priv->lec_arp_empty_ones, next) {
1635 del_timer_sync(&entry->timer);
1636 lec_arp_clear_vccs(entry);
1637 hlist_del(&entry->next);
1638 lec_arp_put(entry);
1639 }
1640 INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
1641
1642 hlist_for_each_entry_safe(entry, node, next,
1643 &priv->lec_no_forward, next) {
1644 del_timer_sync(&entry->timer);
1645 lec_arp_clear_vccs(entry);
1646 hlist_del(&entry->next);
1647 lec_arp_put(entry);
1648 }
1649 INIT_HLIST_HEAD(&priv->lec_no_forward);
1650
1651 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
1652 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
1653 lec_arp_clear_vccs(entry);
1654 hlist_del(&entry->next);
1655 lec_arp_put(entry);
1656 }
1657 INIT_HLIST_HEAD(&priv->mcast_fwds);
1658 priv->mcast_vcc = NULL;
1659 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1660 }
1661
1662 /*
1663 * Find entry by mac_address
1664 */
1665 static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
1666 const unsigned char *mac_addr)
1667 {
1668 struct hlist_node *node;
1669 struct hlist_head *head;
1670 struct lec_arp_table *entry;
1671
1672 pr_debug("%pM\n", mac_addr);
1673
1674 head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
1675 hlist_for_each_entry(entry, node, head, next) {
1676 if (!compare_ether_addr(mac_addr, entry->mac_addr))
1677 return entry;
1678 }
1679 return NULL;
1680 }
1681
1682 static struct lec_arp_table *make_entry(struct lec_priv *priv,
1683 const unsigned char *mac_addr)
1684 {
1685 struct lec_arp_table *to_return;
1686
1687 to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
1688 if (!to_return) {
1689 pr_info("LEC: Arp entry kmalloc failed\n");
1690 return NULL;
1691 }
1692 memcpy(to_return->mac_addr, mac_addr, ETH_ALEN);
1693 INIT_HLIST_NODE(&to_return->next);
1694 setup_timer(&to_return->timer, lec_arp_expire_arp,
1695 (unsigned long)to_return);
1696 to_return->last_used = jiffies;
1697 to_return->priv = priv;
1698 skb_queue_head_init(&to_return->tx_wait);
1699 atomic_set(&to_return->usage, 1);
1700 return to_return;
1701 }
1702
1703 /* Arp sent timer expired */
1704 static void lec_arp_expire_arp(unsigned long data)
1705 {
1706 struct lec_arp_table *entry;
1707
1708 entry = (struct lec_arp_table *)data;
1709
1710 pr_debug("\n");
1711 if (entry->status == ESI_ARP_PENDING) {
1712 if (entry->no_tries <= entry->priv->max_retry_count) {
1713 if (entry->is_rdesc)
1714 send_to_lecd(entry->priv, l_rdesc_arp_xmt,
1715 entry->mac_addr, NULL, NULL);
1716 else
1717 send_to_lecd(entry->priv, l_arp_xmt,
1718 entry->mac_addr, NULL, NULL);
1719 entry->no_tries++;
1720 }
1721 mod_timer(&entry->timer, jiffies + (1 * HZ));
1722 }
1723 }
1724
1725 /* Unknown/unused vcc expire, remove associated entry */
1726 static void lec_arp_expire_vcc(unsigned long data)
1727 {
1728 unsigned long flags;
1729 struct lec_arp_table *to_remove = (struct lec_arp_table *)data;
1730 struct lec_priv *priv = (struct lec_priv *)to_remove->priv;
1731
1732 del_timer(&to_remove->timer);
1733
1734 pr_debug("%p %p: vpi:%d vci:%d\n",
1735 to_remove, priv,
1736 to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
1737 to_remove->vcc ? to_remove->recv_vcc->vci : 0);
1738
1739 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1740 hlist_del(&to_remove->next);
1741 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1742
1743 lec_arp_clear_vccs(to_remove);
1744 lec_arp_put(to_remove);
1745 }
1746
1747 static bool __lec_arp_check_expire(struct lec_arp_table *entry,
1748 unsigned long now,
1749 struct lec_priv *priv)
1750 {
1751 unsigned long time_to_check;
1752
1753 if ((entry->flags) & LEC_REMOTE_FLAG && priv->topology_change)
1754 time_to_check = priv->forward_delay_time;
1755 else
1756 time_to_check = priv->aging_time;
1757
1758 pr_debug("About to expire: %lx - %lx > %lx\n",
1759 now, entry->last_used, time_to_check);
1760 if (time_after(now, entry->last_used + time_to_check) &&
1761 !(entry->flags & LEC_PERMANENT_FLAG) &&
1762 !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
1763 /* Remove entry */
1764 pr_debug("Entry timed out\n");
1765 lec_arp_remove(priv, entry);
1766 lec_arp_put(entry);
1767 } else {
1768 /* Something else */
1769 if ((entry->status == ESI_VC_PENDING ||
1770 entry->status == ESI_ARP_PENDING) &&
1771 time_after_eq(now, entry->timestamp +
1772 priv->max_unknown_frame_time)) {
1773 entry->timestamp = jiffies;
1774 entry->packets_flooded = 0;
1775 if (entry->status == ESI_VC_PENDING)
1776 send_to_lecd(priv, l_svc_setup,
1777 entry->mac_addr,
1778 entry->atm_addr,
1779 NULL);
1780 }
1781 if (entry->status == ESI_FLUSH_PENDING &&
1782 time_after_eq(now, entry->timestamp +
1783 priv->path_switching_delay)) {
1784 lec_arp_hold(entry);
1785 return true;
1786 }
1787 }
1788
1789 return false;
1790 }
1791 /*
1792 * Expire entries.
1793 * 1. Re-set timer
1794 * 2. For each entry, delete entries that have aged past the age limit.
1795 * 3. For each entry, depending on the status of the entry, perform
1796 * the following maintenance.
1797 * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
1798 * tick_count is above the max_unknown_frame_time, clear
1799 * the tick_count to zero and clear the packets_flooded counter
1800 * to zero. This supports the packet rate limit per address
1801 * while flooding unknowns.
1802 * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
1803 * than or equal to the path_switching_delay, change the status
1804 * to ESI_FORWARD_DIRECT. This causes the flush period to end
1805 * regardless of the progress of the flush protocol.
1806 */
1807 static void lec_arp_check_expire(struct work_struct *work)
1808 {
1809 unsigned long flags;
1810 struct lec_priv *priv =
1811 container_of(work, struct lec_priv, lec_arp_work.work);
1812 struct hlist_node *node, *next;
1813 struct lec_arp_table *entry;
1814 unsigned long now;
1815 int i;
1816
1817 pr_debug("%p\n", priv);
1818 now = jiffies;
1819 restart:
1820 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1821 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1822 hlist_for_each_entry_safe(entry, node, next,
1823 &priv->lec_arp_tables[i], next) {
1824 if (__lec_arp_check_expire(entry, now, priv)) {
1825 struct sk_buff *skb;
1826 struct atm_vcc *vcc = entry->vcc;
1827
1828 spin_unlock_irqrestore(&priv->lec_arp_lock,
1829 flags);
1830 while ((skb = skb_dequeue(&entry->tx_wait)))
1831 lec_send(vcc, skb);
1832 entry->last_used = jiffies;
1833 entry->status = ESI_FORWARD_DIRECT;
1834 lec_arp_put(entry);
1835
1836 goto restart;
1837 }
1838 }
1839 }
1840 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1841
1842 schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
1843 }
1844
1845 /*
1846 * Try to find vcc where mac_address is attached.
1847 *
1848 */
1849 static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
1850 const unsigned char *mac_to_find,
1851 int is_rdesc,
1852 struct lec_arp_table **ret_entry)
1853 {
1854 unsigned long flags;
1855 struct lec_arp_table *entry;
1856 struct atm_vcc *found;
1857
1858 if (mac_to_find[0] & 0x01) {
1859 switch (priv->lane_version) {
1860 case 1:
1861 return priv->mcast_vcc;
1862 case 2: /* LANE2 wants arp for multicast addresses */
1863 if (!compare_ether_addr(mac_to_find, bus_mac))
1864 return priv->mcast_vcc;
1865 break;
1866 default:
1867 break;
1868 }
1869 }
1870
1871 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1872 entry = lec_arp_find(priv, mac_to_find);
1873
1874 if (entry) {
1875 if (entry->status == ESI_FORWARD_DIRECT) {
1876 /* Connection Ok */
1877 entry->last_used = jiffies;
1878 lec_arp_hold(entry);
1879 *ret_entry = entry;
1880 found = entry->vcc;
1881 goto out;
1882 }
1883 /*
1884 * If the LE_ARP cache entry is still pending, reset count to 0
1885 * so another LE_ARP request can be made for this frame.
1886 */
1887 if (entry->status == ESI_ARP_PENDING)
1888 entry->no_tries = 0;
1889 /*
1890 * Data direct VC not yet set up, check to see if the unknown
1891 * frame count is greater than the limit. If the limit has
1892 * not been reached, allow the caller to send packet to
1893 * BUS.
1894 */
1895 if (entry->status != ESI_FLUSH_PENDING &&
1896 entry->packets_flooded <
1897 priv->maximum_unknown_frame_count) {
1898 entry->packets_flooded++;
1899 pr_debug("Flooding..\n");
1900 found = priv->mcast_vcc;
1901 goto out;
1902 }
1903 /*
1904 * We got here because entry->status == ESI_FLUSH_PENDING
1905 * or BUS flood limit was reached for an entry which is
1906 * in ESI_ARP_PENDING or ESI_VC_PENDING state.
1907 */
1908 lec_arp_hold(entry);
1909 *ret_entry = entry;
1910 pr_debug("entry->status %d entry->vcc %p\n", entry->status,
1911 entry->vcc);
1912 found = NULL;
1913 } else {
1914 /* No matching entry was found */
1915 entry = make_entry(priv, mac_to_find);
1916 pr_debug("Making entry\n");
1917 if (!entry) {
1918 found = priv->mcast_vcc;
1919 goto out;
1920 }
1921 lec_arp_add(priv, entry);
1922 /* We want arp-request(s) to be sent */
1923 entry->packets_flooded = 1;
1924 entry->status = ESI_ARP_PENDING;
1925 entry->no_tries = 1;
1926 entry->last_used = entry->timestamp = jiffies;
1927 entry->is_rdesc = is_rdesc;
1928 if (entry->is_rdesc)
1929 send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
1930 NULL);
1931 else
1932 send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
1933 entry->timer.expires = jiffies + (1 * HZ);
1934 entry->timer.function = lec_arp_expire_arp;
1935 add_timer(&entry->timer);
1936 found = priv->mcast_vcc;
1937 }
1938
1939 out:
1940 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1941 return found;
1942 }
1943
1944 static int
1945 lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
1946 unsigned long permanent)
1947 {
1948 unsigned long flags;
1949 struct hlist_node *node, *next;
1950 struct lec_arp_table *entry;
1951 int i;
1952
1953 pr_debug("\n");
1954 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1955 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
1956 hlist_for_each_entry_safe(entry, node, next,
1957 &priv->lec_arp_tables[i], next) {
1958 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN) &&
1959 (permanent ||
1960 !(entry->flags & LEC_PERMANENT_FLAG))) {
1961 lec_arp_remove(priv, entry);
1962 lec_arp_put(entry);
1963 }
1964 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1965 return 0;
1966 }
1967 }
1968 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
1969 return -1;
1970 }
1971
1972 /*
1973 * Notifies: Response to arp_request (atm_addr != NULL)
1974 */
1975 static void
1976 lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
1977 const unsigned char *atm_addr, unsigned long remoteflag,
1978 unsigned int targetless_le_arp)
1979 {
1980 unsigned long flags;
1981 struct hlist_node *node, *next;
1982 struct lec_arp_table *entry, *tmp;
1983 int i;
1984
1985 pr_debug("%smac:%pM\n",
1986 (targetless_le_arp) ? "targetless " : "", mac_addr);
1987
1988 spin_lock_irqsave(&priv->lec_arp_lock, flags);
1989 entry = lec_arp_find(priv, mac_addr);
1990 if (entry == NULL && targetless_le_arp)
1991 goto out; /*
1992 * LANE2: ignore targetless LE_ARPs for which
1993 * we have no entry in the cache. 7.1.30
1994 */
1995 if (!hlist_empty(&priv->lec_arp_empty_ones)) {
1996 hlist_for_each_entry_safe(entry, node, next,
1997 &priv->lec_arp_empty_ones, next) {
1998 if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
1999 hlist_del(&entry->next);
2000 del_timer(&entry->timer);
2001 tmp = lec_arp_find(priv, mac_addr);
2002 if (tmp) {
2003 del_timer(&tmp->timer);
2004 tmp->status = ESI_FORWARD_DIRECT;
2005 memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
2006 tmp->vcc = entry->vcc;
2007 tmp->old_push = entry->old_push;
2008 tmp->last_used = jiffies;
2009 del_timer(&entry->timer);
2010 lec_arp_put(entry);
2011 entry = tmp;
2012 } else {
2013 entry->status = ESI_FORWARD_DIRECT;
2014 memcpy(entry->mac_addr, mac_addr, ETH_ALEN);
2015 entry->last_used = jiffies;
2016 lec_arp_add(priv, entry);
2017 }
2018 if (remoteflag)
2019 entry->flags |= LEC_REMOTE_FLAG;
2020 else
2021 entry->flags &= ~LEC_REMOTE_FLAG;
2022 pr_debug("After update\n");
2023 dump_arp_table(priv);
2024 goto out;
2025 }
2026 }
2027 }
2028
2029 entry = lec_arp_find(priv, mac_addr);
2030 if (!entry) {
2031 entry = make_entry(priv, mac_addr);
2032 if (!entry)
2033 goto out;
2034 entry->status = ESI_UNKNOWN;
2035 lec_arp_add(priv, entry);
2036 /* Temporary, changes before end of function */
2037 }
2038 memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
2039 del_timer(&entry->timer);
2040 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2041 hlist_for_each_entry(tmp, node,
2042 &priv->lec_arp_tables[i], next) {
2043 if (entry != tmp &&
2044 !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
2045 /* Vcc to this host exists */
2046 if (tmp->status > ESI_VC_PENDING) {
2047 /*
2048 * ESI_FLUSH_PENDING,
2049 * ESI_FORWARD_DIRECT
2050 */
2051 entry->vcc = tmp->vcc;
2052 entry->old_push = tmp->old_push;
2053 }
2054 entry->status = tmp->status;
2055 break;
2056 }
2057 }
2058 }
2059 if (remoteflag)
2060 entry->flags |= LEC_REMOTE_FLAG;
2061 else
2062 entry->flags &= ~LEC_REMOTE_FLAG;
2063 if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
2064 entry->status = ESI_VC_PENDING;
2065 send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
2066 }
2067 pr_debug("After update2\n");
2068 dump_arp_table(priv);
2069 out:
2070 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2071 }
2072
2073 /*
2074 * Notifies: Vcc setup ready
2075 */
2076 static void
2077 lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
2078 struct atm_vcc *vcc,
2079 void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
2080 {
2081 unsigned long flags;
2082 struct hlist_node *node;
2083 struct lec_arp_table *entry;
2084 int i, found_entry = 0;
2085
2086 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2087 /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
2088 if (ioc_data->receive == 2) {
2089 pr_debug("LEC_ARP: Attaching mcast forward\n");
2090 #if 0
2091 entry = lec_arp_find(priv, bus_mac);
2092 if (!entry) {
2093 pr_info("LEC_ARP: Multicast entry not found!\n");
2094 goto out;
2095 }
2096 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2097 entry->recv_vcc = vcc;
2098 entry->old_recv_push = old_push;
2099 #endif
2100 entry = make_entry(priv, bus_mac);
2101 if (entry == NULL)
2102 goto out;
2103 del_timer(&entry->timer);
2104 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2105 entry->recv_vcc = vcc;
2106 entry->old_recv_push = old_push;
2107 hlist_add_head(&entry->next, &priv->mcast_fwds);
2108 goto out;
2109 } else if (ioc_data->receive == 1) {
2110 /*
2111 * Vcc which we don't want to make default vcc,
2112 * attach it anyway.
2113 */
2114 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",
2115 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2116 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2117 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2118 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2119 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2120 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2121 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2122 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2123 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2124 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2125 entry = make_entry(priv, bus_mac);
2126 if (entry == NULL)
2127 goto out;
2128 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2129 memset(entry->mac_addr, 0, ETH_ALEN);
2130 entry->recv_vcc = vcc;
2131 entry->old_recv_push = old_push;
2132 entry->status = ESI_UNKNOWN;
2133 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2134 entry->timer.function = lec_arp_expire_vcc;
2135 hlist_add_head(&entry->next, &priv->lec_no_forward);
2136 add_timer(&entry->timer);
2137 dump_arp_table(priv);
2138 goto out;
2139 }
2140 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",
2141 ioc_data->atm_addr[0], ioc_data->atm_addr[1],
2142 ioc_data->atm_addr[2], ioc_data->atm_addr[3],
2143 ioc_data->atm_addr[4], ioc_data->atm_addr[5],
2144 ioc_data->atm_addr[6], ioc_data->atm_addr[7],
2145 ioc_data->atm_addr[8], ioc_data->atm_addr[9],
2146 ioc_data->atm_addr[10], ioc_data->atm_addr[11],
2147 ioc_data->atm_addr[12], ioc_data->atm_addr[13],
2148 ioc_data->atm_addr[14], ioc_data->atm_addr[15],
2149 ioc_data->atm_addr[16], ioc_data->atm_addr[17],
2150 ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
2151 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2152 hlist_for_each_entry(entry, node,
2153 &priv->lec_arp_tables[i], next) {
2154 if (memcmp
2155 (ioc_data->atm_addr, entry->atm_addr,
2156 ATM_ESA_LEN) == 0) {
2157 pr_debug("LEC_ARP: Attaching data direct\n");
2158 pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
2159 entry->vcc ? entry->vcc->vci : 0,
2160 entry->recv_vcc ? entry->recv_vcc->
2161 vci : 0);
2162 found_entry = 1;
2163 del_timer(&entry->timer);
2164 entry->vcc = vcc;
2165 entry->old_push = old_push;
2166 if (entry->status == ESI_VC_PENDING) {
2167 if (priv->maximum_unknown_frame_count
2168 == 0)
2169 entry->status =
2170 ESI_FORWARD_DIRECT;
2171 else {
2172 entry->timestamp = jiffies;
2173 entry->status =
2174 ESI_FLUSH_PENDING;
2175 #if 0
2176 send_to_lecd(priv, l_flush_xmt,
2177 NULL,
2178 entry->atm_addr,
2179 NULL);
2180 #endif
2181 }
2182 } else {
2183 /*
2184 * They were forming a connection
2185 * to us, and we to them. Our
2186 * ATM address is numerically lower
2187 * than theirs, so we make connection
2188 * we formed into default VCC (8.1.11).
2189 * Connection they made gets torn
2190 * down. This might confuse some
2191 * clients. Can be changed if
2192 * someone reports trouble...
2193 */
2194 ;
2195 }
2196 }
2197 }
2198 }
2199 if (found_entry) {
2200 pr_debug("After vcc was added\n");
2201 dump_arp_table(priv);
2202 goto out;
2203 }
2204 /*
2205 * Not found, snatch address from first data packet that arrives
2206 * from this vcc
2207 */
2208 entry = make_entry(priv, bus_mac);
2209 if (!entry)
2210 goto out;
2211 entry->vcc = vcc;
2212 entry->old_push = old_push;
2213 memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
2214 memset(entry->mac_addr, 0, ETH_ALEN);
2215 entry->status = ESI_UNKNOWN;
2216 hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
2217 entry->timer.expires = jiffies + priv->vcc_timeout_period;
2218 entry->timer.function = lec_arp_expire_vcc;
2219 add_timer(&entry->timer);
2220 pr_debug("After vcc was added\n");
2221 dump_arp_table(priv);
2222 out:
2223 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2224 }
2225
2226 static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
2227 {
2228 unsigned long flags;
2229 struct hlist_node *node;
2230 struct lec_arp_table *entry;
2231 int i;
2232
2233 pr_debug("%lx\n", tran_id);
2234 restart:
2235 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2236 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2237 hlist_for_each_entry(entry, node,
2238 &priv->lec_arp_tables[i], next) {
2239 if (entry->flush_tran_id == tran_id &&
2240 entry->status == ESI_FLUSH_PENDING) {
2241 struct sk_buff *skb;
2242 struct atm_vcc *vcc = entry->vcc;
2243
2244 lec_arp_hold(entry);
2245 spin_unlock_irqrestore(&priv->lec_arp_lock,
2246 flags);
2247 while ((skb = skb_dequeue(&entry->tx_wait)))
2248 lec_send(vcc, skb);
2249 entry->last_used = jiffies;
2250 entry->status = ESI_FORWARD_DIRECT;
2251 lec_arp_put(entry);
2252 pr_debug("LEC_ARP: Flushed\n");
2253 goto restart;
2254 }
2255 }
2256 }
2257 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2258 dump_arp_table(priv);
2259 }
2260
2261 static void
2262 lec_set_flush_tran_id(struct lec_priv *priv,
2263 const unsigned char *atm_addr, unsigned long tran_id)
2264 {
2265 unsigned long flags;
2266 struct hlist_node *node;
2267 struct lec_arp_table *entry;
2268 int i;
2269
2270 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2271 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
2272 hlist_for_each_entry(entry, node,
2273 &priv->lec_arp_tables[i], next) {
2274 if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
2275 entry->flush_tran_id = tran_id;
2276 pr_debug("Set flush transaction id to %lx for %p\n",
2277 tran_id, entry);
2278 }
2279 }
2280 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2281 }
2282
2283 static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
2284 {
2285 unsigned long flags;
2286 unsigned char mac_addr[] = {
2287 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2288 };
2289 struct lec_arp_table *to_add;
2290 struct lec_vcc_priv *vpriv;
2291 int err = 0;
2292
2293 vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL);
2294 if (!vpriv)
2295 return -ENOMEM;
2296 vpriv->xoff = 0;
2297 vpriv->old_pop = vcc->pop;
2298 vcc->user_back = vpriv;
2299 vcc->pop = lec_pop;
2300 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2301 to_add = make_entry(priv, mac_addr);
2302 if (!to_add) {
2303 vcc->pop = vpriv->old_pop;
2304 kfree(vpriv);
2305 err = -ENOMEM;
2306 goto out;
2307 }
2308 memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
2309 to_add->status = ESI_FORWARD_DIRECT;
2310 to_add->flags |= LEC_PERMANENT_FLAG;
2311 to_add->vcc = vcc;
2312 to_add->old_push = vcc->push;
2313 vcc->push = lec_push;
2314 priv->mcast_vcc = vcc;
2315 lec_arp_add(priv, to_add);
2316 out:
2317 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2318 return err;
2319 }
2320
2321 static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
2322 {
2323 unsigned long flags;
2324 struct hlist_node *node, *next;
2325 struct lec_arp_table *entry;
2326 int i;
2327
2328 pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
2329 dump_arp_table(priv);
2330
2331 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2332
2333 for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
2334 hlist_for_each_entry_safe(entry, node, next,
2335 &priv->lec_arp_tables[i], next) {
2336 if (vcc == entry->vcc) {
2337 lec_arp_remove(priv, entry);
2338 lec_arp_put(entry);
2339 if (priv->mcast_vcc == vcc)
2340 priv->mcast_vcc = NULL;
2341 }
2342 }
2343 }
2344
2345 hlist_for_each_entry_safe(entry, node, next,
2346 &priv->lec_arp_empty_ones, next) {
2347 if (entry->vcc == vcc) {
2348 lec_arp_clear_vccs(entry);
2349 del_timer(&entry->timer);
2350 hlist_del(&entry->next);
2351 lec_arp_put(entry);
2352 }
2353 }
2354
2355 hlist_for_each_entry_safe(entry, node, next,
2356 &priv->lec_no_forward, next) {
2357 if (entry->recv_vcc == vcc) {
2358 lec_arp_clear_vccs(entry);
2359 del_timer(&entry->timer);
2360 hlist_del(&entry->next);
2361 lec_arp_put(entry);
2362 }
2363 }
2364
2365 hlist_for_each_entry_safe(entry, node, next, &priv->mcast_fwds, next) {
2366 if (entry->recv_vcc == vcc) {
2367 lec_arp_clear_vccs(entry);
2368 /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
2369 hlist_del(&entry->next);
2370 lec_arp_put(entry);
2371 }
2372 }
2373
2374 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2375 dump_arp_table(priv);
2376 }
2377
2378 static void
2379 lec_arp_check_empties(struct lec_priv *priv,
2380 struct atm_vcc *vcc, struct sk_buff *skb)
2381 {
2382 unsigned long flags;
2383 struct hlist_node *node, *next;
2384 struct lec_arp_table *entry, *tmp;
2385 struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
2386 unsigned char *src;
2387 #ifdef CONFIG_TR
2388 struct lecdatahdr_8025 *tr_hdr = (struct lecdatahdr_8025 *)skb->data;
2389
2390 if (priv->is_trdev)
2391 src = tr_hdr->h_source;
2392 else
2393 #endif
2394 src = hdr->h_source;
2395
2396 spin_lock_irqsave(&priv->lec_arp_lock, flags);
2397 hlist_for_each_entry_safe(entry, node, next,
2398 &priv->lec_arp_empty_ones, next) {
2399 if (vcc == entry->vcc) {
2400 del_timer(&entry->timer);
2401 memcpy(entry->mac_addr, src, ETH_ALEN);
2402 entry->status = ESI_FORWARD_DIRECT;
2403 entry->last_used = jiffies;
2404 /* We might have got an entry */
2405 tmp = lec_arp_find(priv, src);
2406 if (tmp) {
2407 lec_arp_remove(priv, tmp);
2408 lec_arp_put(tmp);
2409 }
2410 hlist_del(&entry->next);
2411 lec_arp_add(priv, entry);
2412 goto out;
2413 }
2414 }
2415 pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
2416 out:
2417 spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
2418 }
2419
2420 MODULE_LICENSE("GPL");