lec.c 60 KB

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