lec.c 60 KB

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