lec.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279
  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. #endif
  879. static int lane_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  880. {
  881. struct atm_vcc *vcc = ATM_SD(sock);
  882. int err = 0;
  883. switch (cmd) {
  884. case ATMLEC_CTRL:
  885. case ATMLEC_MCAST:
  886. case ATMLEC_DATA:
  887. if (!capable(CAP_NET_ADMIN))
  888. return -EPERM;
  889. break;
  890. default:
  891. return -ENOIOCTLCMD;
  892. }
  893. switch (cmd) {
  894. case ATMLEC_CTRL:
  895. err = lecd_attach(vcc, (int)arg);
  896. if (err >= 0)
  897. sock->state = SS_CONNECTED;
  898. break;
  899. case ATMLEC_MCAST:
  900. err = lec_mcast_attach(vcc, (int)arg);
  901. break;
  902. case ATMLEC_DATA:
  903. err = lec_vcc_attach(vcc, (void __user *)arg);
  904. break;
  905. }
  906. return err;
  907. }
  908. static struct atm_ioctl lane_ioctl_ops = {
  909. .owner = THIS_MODULE,
  910. .ioctl = lane_ioctl,
  911. };
  912. static int __init lane_module_init(void)
  913. {
  914. #ifdef CONFIG_PROC_FS
  915. struct proc_dir_entry *p;
  916. p = proc_create_seq_private("lec", 0444, atm_proc_root, &lec_seq_ops,
  917. sizeof(struct lec_state), NULL);
  918. if (!p) {
  919. pr_err("Unable to initialize /proc/net/atm/lec\n");
  920. return -ENOMEM;
  921. }
  922. #endif
  923. register_atm_ioctl(&lane_ioctl_ops);
  924. pr_info("lec.c: initialized\n");
  925. return 0;
  926. }
  927. static void __exit lane_module_cleanup(void)
  928. {
  929. int i;
  930. #ifdef CONFIG_PROC_FS
  931. remove_proc_entry("lec", atm_proc_root);
  932. #endif
  933. deregister_atm_ioctl(&lane_ioctl_ops);
  934. for (i = 0; i < MAX_LEC_ITF; i++) {
  935. if (dev_lec[i] != NULL) {
  936. unregister_netdev(dev_lec[i]);
  937. free_netdev(dev_lec[i]);
  938. dev_lec[i] = NULL;
  939. }
  940. }
  941. }
  942. module_init(lane_module_init);
  943. module_exit(lane_module_cleanup);
  944. /*
  945. * LANE2: 3.1.3, LE_RESOLVE.request
  946. * Non force allocates memory and fills in *tlvs, fills in *sizeoftlvs.
  947. * If sizeoftlvs == NULL the default TLVs associated with with this
  948. * lec will be used.
  949. * If dst_mac == NULL, targetless LE_ARP will be sent
  950. */
  951. static int lane2_resolve(struct net_device *dev, const u8 *dst_mac, int force,
  952. u8 **tlvs, u32 *sizeoftlvs)
  953. {
  954. unsigned long flags;
  955. struct lec_priv *priv = netdev_priv(dev);
  956. struct lec_arp_table *table;
  957. struct sk_buff *skb;
  958. int retval;
  959. if (force == 0) {
  960. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  961. table = lec_arp_find(priv, dst_mac);
  962. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  963. if (table == NULL)
  964. return -1;
  965. *tlvs = kmemdup(table->tlvs, table->sizeoftlvs, GFP_ATOMIC);
  966. if (*tlvs == NULL)
  967. return -1;
  968. *sizeoftlvs = table->sizeoftlvs;
  969. return 0;
  970. }
  971. if (sizeoftlvs == NULL)
  972. retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, NULL);
  973. else {
  974. skb = alloc_skb(*sizeoftlvs, GFP_ATOMIC);
  975. if (skb == NULL)
  976. return -1;
  977. skb->len = *sizeoftlvs;
  978. skb_copy_to_linear_data(skb, *tlvs, *sizeoftlvs);
  979. retval = send_to_lecd(priv, l_arp_xmt, dst_mac, NULL, skb);
  980. }
  981. return retval;
  982. }
  983. /*
  984. * LANE2: 3.1.4, LE_ASSOCIATE.request
  985. * Associate the *tlvs with the *lan_dst address.
  986. * Will overwrite any previous association
  987. * Returns 1 for success, 0 for failure (out of memory)
  988. *
  989. */
  990. static int lane2_associate_req(struct net_device *dev, const u8 *lan_dst,
  991. const u8 *tlvs, u32 sizeoftlvs)
  992. {
  993. int retval;
  994. struct sk_buff *skb;
  995. struct lec_priv *priv = netdev_priv(dev);
  996. if (!ether_addr_equal(lan_dst, dev->dev_addr))
  997. return 0; /* not our mac address */
  998. kfree(priv->tlvs); /* NULL if there was no previous association */
  999. priv->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
  1000. if (priv->tlvs == NULL)
  1001. return 0;
  1002. priv->sizeoftlvs = sizeoftlvs;
  1003. skb = alloc_skb(sizeoftlvs, GFP_ATOMIC);
  1004. if (skb == NULL)
  1005. return 0;
  1006. skb->len = sizeoftlvs;
  1007. skb_copy_to_linear_data(skb, tlvs, sizeoftlvs);
  1008. retval = send_to_lecd(priv, l_associate_req, NULL, NULL, skb);
  1009. if (retval != 0)
  1010. pr_info("lec.c: lane2_associate_req() failed\n");
  1011. /*
  1012. * If the previous association has changed we must
  1013. * somehow notify other LANE entities about the change
  1014. */
  1015. return 1;
  1016. }
  1017. /*
  1018. * LANE2: 3.1.5, LE_ASSOCIATE.indication
  1019. *
  1020. */
  1021. static void lane2_associate_ind(struct net_device *dev, const u8 *mac_addr,
  1022. const u8 *tlvs, u32 sizeoftlvs)
  1023. {
  1024. #if 0
  1025. int i = 0;
  1026. #endif
  1027. struct lec_priv *priv = netdev_priv(dev);
  1028. #if 0 /*
  1029. * Why have the TLVs in LE_ARP entries
  1030. * since we do not use them? When you
  1031. * uncomment this code, make sure the
  1032. * TLVs get freed when entry is killed
  1033. */
  1034. struct lec_arp_table *entry = lec_arp_find(priv, mac_addr);
  1035. if (entry == NULL)
  1036. return; /* should not happen */
  1037. kfree(entry->tlvs);
  1038. entry->tlvs = kmemdup(tlvs, sizeoftlvs, GFP_KERNEL);
  1039. if (entry->tlvs == NULL)
  1040. return;
  1041. entry->sizeoftlvs = sizeoftlvs;
  1042. #endif
  1043. #if 0
  1044. pr_info("\n");
  1045. pr_info("dump of tlvs, sizeoftlvs=%d\n", sizeoftlvs);
  1046. while (i < sizeoftlvs)
  1047. pr_cont("%02x ", tlvs[i++]);
  1048. pr_cont("\n");
  1049. #endif
  1050. /* tell MPOA about the TLVs we saw */
  1051. if (priv->lane2_ops && priv->lane2_ops->associate_indicator) {
  1052. priv->lane2_ops->associate_indicator(dev, mac_addr,
  1053. tlvs, sizeoftlvs);
  1054. }
  1055. }
  1056. /*
  1057. * Here starts what used to lec_arpc.c
  1058. *
  1059. * lec_arpc.c was added here when making
  1060. * lane client modular. October 1997
  1061. */
  1062. #include <linux/types.h>
  1063. #include <linux/timer.h>
  1064. #include <linux/param.h>
  1065. #include <linux/atomic.h>
  1066. #include <linux/inetdevice.h>
  1067. #include <net/route.h>
  1068. #if 0
  1069. #define pr_debug(format, args...)
  1070. /*
  1071. #define pr_debug printk
  1072. */
  1073. #endif
  1074. #define DEBUG_ARP_TABLE 0
  1075. #define LEC_ARP_REFRESH_INTERVAL (3*HZ)
  1076. static void lec_arp_check_expire(struct work_struct *work);
  1077. static void lec_arp_expire_arp(struct timer_list *t);
  1078. /*
  1079. * Arp table funcs
  1080. */
  1081. #define HASH(ch) (ch & (LEC_ARP_TABLE_SIZE - 1))
  1082. /*
  1083. * Initialization of arp-cache
  1084. */
  1085. static void lec_arp_init(struct lec_priv *priv)
  1086. {
  1087. unsigned short i;
  1088. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
  1089. INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
  1090. INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
  1091. INIT_HLIST_HEAD(&priv->lec_no_forward);
  1092. INIT_HLIST_HEAD(&priv->mcast_fwds);
  1093. spin_lock_init(&priv->lec_arp_lock);
  1094. INIT_DELAYED_WORK(&priv->lec_arp_work, lec_arp_check_expire);
  1095. schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
  1096. }
  1097. static void lec_arp_clear_vccs(struct lec_arp_table *entry)
  1098. {
  1099. if (entry->vcc) {
  1100. struct atm_vcc *vcc = entry->vcc;
  1101. struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
  1102. struct net_device *dev = (struct net_device *)vcc->proto_data;
  1103. vcc->pop = vpriv->old_pop;
  1104. if (vpriv->xoff)
  1105. netif_wake_queue(dev);
  1106. kfree(vpriv);
  1107. vcc->user_back = NULL;
  1108. vcc->push = entry->old_push;
  1109. vcc_release_async(vcc, -EPIPE);
  1110. entry->vcc = NULL;
  1111. }
  1112. if (entry->recv_vcc) {
  1113. struct atm_vcc *vcc = entry->recv_vcc;
  1114. struct lec_vcc_priv *vpriv = LEC_VCC_PRIV(vcc);
  1115. kfree(vpriv);
  1116. vcc->user_back = NULL;
  1117. entry->recv_vcc->push = entry->old_recv_push;
  1118. vcc_release_async(entry->recv_vcc, -EPIPE);
  1119. entry->recv_vcc = NULL;
  1120. }
  1121. }
  1122. /*
  1123. * Insert entry to lec_arp_table
  1124. * LANE2: Add to the end of the list to satisfy 8.1.13
  1125. */
  1126. static inline void
  1127. lec_arp_add(struct lec_priv *priv, struct lec_arp_table *entry)
  1128. {
  1129. struct hlist_head *tmp;
  1130. tmp = &priv->lec_arp_tables[HASH(entry->mac_addr[ETH_ALEN - 1])];
  1131. hlist_add_head(&entry->next, tmp);
  1132. pr_debug("Added entry:%pM\n", entry->mac_addr);
  1133. }
  1134. /*
  1135. * Remove entry from lec_arp_table
  1136. */
  1137. static int
  1138. lec_arp_remove(struct lec_priv *priv, struct lec_arp_table *to_remove)
  1139. {
  1140. struct lec_arp_table *entry;
  1141. int i, remove_vcc = 1;
  1142. if (!to_remove)
  1143. return -1;
  1144. hlist_del(&to_remove->next);
  1145. del_timer(&to_remove->timer);
  1146. /*
  1147. * If this is the only MAC connected to this VCC,
  1148. * also tear down the VCC
  1149. */
  1150. if (to_remove->status >= ESI_FLUSH_PENDING) {
  1151. /*
  1152. * ESI_FLUSH_PENDING, ESI_FORWARD_DIRECT
  1153. */
  1154. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1155. hlist_for_each_entry(entry,
  1156. &priv->lec_arp_tables[i], next) {
  1157. if (memcmp(to_remove->atm_addr,
  1158. entry->atm_addr, ATM_ESA_LEN) == 0) {
  1159. remove_vcc = 0;
  1160. break;
  1161. }
  1162. }
  1163. }
  1164. if (remove_vcc)
  1165. lec_arp_clear_vccs(to_remove);
  1166. }
  1167. skb_queue_purge(&to_remove->tx_wait); /* FIXME: good place for this? */
  1168. pr_debug("Removed entry:%pM\n", to_remove->mac_addr);
  1169. return 0;
  1170. }
  1171. #if DEBUG_ARP_TABLE
  1172. static const char *get_status_string(unsigned char st)
  1173. {
  1174. switch (st) {
  1175. case ESI_UNKNOWN:
  1176. return "ESI_UNKNOWN";
  1177. case ESI_ARP_PENDING:
  1178. return "ESI_ARP_PENDING";
  1179. case ESI_VC_PENDING:
  1180. return "ESI_VC_PENDING";
  1181. case ESI_FLUSH_PENDING:
  1182. return "ESI_FLUSH_PENDING";
  1183. case ESI_FORWARD_DIRECT:
  1184. return "ESI_FORWARD_DIRECT";
  1185. }
  1186. return "<UNKNOWN>";
  1187. }
  1188. static void dump_arp_table(struct lec_priv *priv)
  1189. {
  1190. struct lec_arp_table *rulla;
  1191. char buf[256];
  1192. int i, j, offset;
  1193. pr_info("Dump %p:\n", priv);
  1194. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1195. hlist_for_each_entry(rulla,
  1196. &priv->lec_arp_tables[i], next) {
  1197. offset = 0;
  1198. offset += sprintf(buf, "%d: %p\n", i, rulla);
  1199. offset += sprintf(buf + offset, "Mac: %pM",
  1200. rulla->mac_addr);
  1201. offset += sprintf(buf + offset, " Atm:");
  1202. for (j = 0; j < ATM_ESA_LEN; j++) {
  1203. offset += sprintf(buf + offset,
  1204. "%2.2x ",
  1205. rulla->atm_addr[j] & 0xff);
  1206. }
  1207. offset += sprintf(buf + offset,
  1208. "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
  1209. rulla->vcc ? rulla->vcc->vpi : 0,
  1210. rulla->vcc ? rulla->vcc->vci : 0,
  1211. rulla->recv_vcc ? rulla->recv_vcc->
  1212. vpi : 0,
  1213. rulla->recv_vcc ? rulla->recv_vcc->
  1214. vci : 0, rulla->last_used,
  1215. rulla->timestamp, rulla->no_tries);
  1216. offset +=
  1217. sprintf(buf + offset,
  1218. "Flags:%x, Packets_flooded:%x, Status: %s ",
  1219. rulla->flags, rulla->packets_flooded,
  1220. get_status_string(rulla->status));
  1221. pr_info("%s\n", buf);
  1222. }
  1223. }
  1224. if (!hlist_empty(&priv->lec_no_forward))
  1225. pr_info("No forward\n");
  1226. hlist_for_each_entry(rulla, &priv->lec_no_forward, next) {
  1227. offset = 0;
  1228. offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
  1229. offset += sprintf(buf + offset, " Atm:");
  1230. for (j = 0; j < ATM_ESA_LEN; j++) {
  1231. offset += sprintf(buf + offset, "%2.2x ",
  1232. rulla->atm_addr[j] & 0xff);
  1233. }
  1234. offset += sprintf(buf + offset,
  1235. "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
  1236. rulla->vcc ? rulla->vcc->vpi : 0,
  1237. rulla->vcc ? rulla->vcc->vci : 0,
  1238. rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
  1239. rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
  1240. rulla->last_used,
  1241. rulla->timestamp, rulla->no_tries);
  1242. offset += sprintf(buf + offset,
  1243. "Flags:%x, Packets_flooded:%x, Status: %s ",
  1244. rulla->flags, rulla->packets_flooded,
  1245. get_status_string(rulla->status));
  1246. pr_info("%s\n", buf);
  1247. }
  1248. if (!hlist_empty(&priv->lec_arp_empty_ones))
  1249. pr_info("Empty ones\n");
  1250. hlist_for_each_entry(rulla, &priv->lec_arp_empty_ones, next) {
  1251. offset = 0;
  1252. offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
  1253. offset += sprintf(buf + offset, " Atm:");
  1254. for (j = 0; j < ATM_ESA_LEN; j++) {
  1255. offset += sprintf(buf + offset, "%2.2x ",
  1256. rulla->atm_addr[j] & 0xff);
  1257. }
  1258. offset += sprintf(buf + offset,
  1259. "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
  1260. rulla->vcc ? rulla->vcc->vpi : 0,
  1261. rulla->vcc ? rulla->vcc->vci : 0,
  1262. rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
  1263. rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
  1264. rulla->last_used,
  1265. rulla->timestamp, rulla->no_tries);
  1266. offset += sprintf(buf + offset,
  1267. "Flags:%x, Packets_flooded:%x, Status: %s ",
  1268. rulla->flags, rulla->packets_flooded,
  1269. get_status_string(rulla->status));
  1270. pr_info("%s", buf);
  1271. }
  1272. if (!hlist_empty(&priv->mcast_fwds))
  1273. pr_info("Multicast Forward VCCs\n");
  1274. hlist_for_each_entry(rulla, &priv->mcast_fwds, next) {
  1275. offset = 0;
  1276. offset += sprintf(buf + offset, "Mac: %pM", rulla->mac_addr);
  1277. offset += sprintf(buf + offset, " Atm:");
  1278. for (j = 0; j < ATM_ESA_LEN; j++) {
  1279. offset += sprintf(buf + offset, "%2.2x ",
  1280. rulla->atm_addr[j] & 0xff);
  1281. }
  1282. offset += sprintf(buf + offset,
  1283. "Vcc vpi:%d vci:%d, Recv_vcc vpi:%d vci:%d Last_used:%lx, Timestamp:%lx, No_tries:%d ",
  1284. rulla->vcc ? rulla->vcc->vpi : 0,
  1285. rulla->vcc ? rulla->vcc->vci : 0,
  1286. rulla->recv_vcc ? rulla->recv_vcc->vpi : 0,
  1287. rulla->recv_vcc ? rulla->recv_vcc->vci : 0,
  1288. rulla->last_used,
  1289. rulla->timestamp, rulla->no_tries);
  1290. offset += sprintf(buf + offset,
  1291. "Flags:%x, Packets_flooded:%x, Status: %s ",
  1292. rulla->flags, rulla->packets_flooded,
  1293. get_status_string(rulla->status));
  1294. pr_info("%s\n", buf);
  1295. }
  1296. }
  1297. #else
  1298. #define dump_arp_table(priv) do { } while (0)
  1299. #endif
  1300. /*
  1301. * Destruction of arp-cache
  1302. */
  1303. static void lec_arp_destroy(struct lec_priv *priv)
  1304. {
  1305. unsigned long flags;
  1306. struct hlist_node *next;
  1307. struct lec_arp_table *entry;
  1308. int i;
  1309. cancel_delayed_work_sync(&priv->lec_arp_work);
  1310. /*
  1311. * Remove all entries
  1312. */
  1313. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1314. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1315. hlist_for_each_entry_safe(entry, next,
  1316. &priv->lec_arp_tables[i], next) {
  1317. lec_arp_remove(priv, entry);
  1318. lec_arp_put(entry);
  1319. }
  1320. INIT_HLIST_HEAD(&priv->lec_arp_tables[i]);
  1321. }
  1322. hlist_for_each_entry_safe(entry, next,
  1323. &priv->lec_arp_empty_ones, next) {
  1324. del_timer_sync(&entry->timer);
  1325. lec_arp_clear_vccs(entry);
  1326. hlist_del(&entry->next);
  1327. lec_arp_put(entry);
  1328. }
  1329. INIT_HLIST_HEAD(&priv->lec_arp_empty_ones);
  1330. hlist_for_each_entry_safe(entry, next,
  1331. &priv->lec_no_forward, next) {
  1332. del_timer_sync(&entry->timer);
  1333. lec_arp_clear_vccs(entry);
  1334. hlist_del(&entry->next);
  1335. lec_arp_put(entry);
  1336. }
  1337. INIT_HLIST_HEAD(&priv->lec_no_forward);
  1338. hlist_for_each_entry_safe(entry, next, &priv->mcast_fwds, next) {
  1339. /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
  1340. lec_arp_clear_vccs(entry);
  1341. hlist_del(&entry->next);
  1342. lec_arp_put(entry);
  1343. }
  1344. INIT_HLIST_HEAD(&priv->mcast_fwds);
  1345. priv->mcast_vcc = NULL;
  1346. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1347. }
  1348. /*
  1349. * Find entry by mac_address
  1350. */
  1351. static struct lec_arp_table *lec_arp_find(struct lec_priv *priv,
  1352. const unsigned char *mac_addr)
  1353. {
  1354. struct hlist_head *head;
  1355. struct lec_arp_table *entry;
  1356. pr_debug("%pM\n", mac_addr);
  1357. head = &priv->lec_arp_tables[HASH(mac_addr[ETH_ALEN - 1])];
  1358. hlist_for_each_entry(entry, head, next) {
  1359. if (ether_addr_equal(mac_addr, entry->mac_addr))
  1360. return entry;
  1361. }
  1362. return NULL;
  1363. }
  1364. static struct lec_arp_table *make_entry(struct lec_priv *priv,
  1365. const unsigned char *mac_addr)
  1366. {
  1367. struct lec_arp_table *to_return;
  1368. to_return = kzalloc(sizeof(struct lec_arp_table), GFP_ATOMIC);
  1369. if (!to_return) {
  1370. pr_info("LEC: Arp entry kmalloc failed\n");
  1371. return NULL;
  1372. }
  1373. ether_addr_copy(to_return->mac_addr, mac_addr);
  1374. INIT_HLIST_NODE(&to_return->next);
  1375. timer_setup(&to_return->timer, lec_arp_expire_arp, 0);
  1376. to_return->last_used = jiffies;
  1377. to_return->priv = priv;
  1378. skb_queue_head_init(&to_return->tx_wait);
  1379. refcount_set(&to_return->usage, 1);
  1380. return to_return;
  1381. }
  1382. /* Arp sent timer expired */
  1383. static void lec_arp_expire_arp(struct timer_list *t)
  1384. {
  1385. struct lec_arp_table *entry;
  1386. entry = from_timer(entry, t, timer);
  1387. pr_debug("\n");
  1388. if (entry->status == ESI_ARP_PENDING) {
  1389. if (entry->no_tries <= entry->priv->max_retry_count) {
  1390. if (entry->is_rdesc)
  1391. send_to_lecd(entry->priv, l_rdesc_arp_xmt,
  1392. entry->mac_addr, NULL, NULL);
  1393. else
  1394. send_to_lecd(entry->priv, l_arp_xmt,
  1395. entry->mac_addr, NULL, NULL);
  1396. entry->no_tries++;
  1397. }
  1398. mod_timer(&entry->timer, jiffies + (1 * HZ));
  1399. }
  1400. }
  1401. /* Unknown/unused vcc expire, remove associated entry */
  1402. static void lec_arp_expire_vcc(struct timer_list *t)
  1403. {
  1404. unsigned long flags;
  1405. struct lec_arp_table *to_remove = from_timer(to_remove, t, timer);
  1406. struct lec_priv *priv = to_remove->priv;
  1407. del_timer(&to_remove->timer);
  1408. pr_debug("%p %p: vpi:%d vci:%d\n",
  1409. to_remove, priv,
  1410. to_remove->vcc ? to_remove->recv_vcc->vpi : 0,
  1411. to_remove->vcc ? to_remove->recv_vcc->vci : 0);
  1412. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1413. hlist_del(&to_remove->next);
  1414. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1415. lec_arp_clear_vccs(to_remove);
  1416. lec_arp_put(to_remove);
  1417. }
  1418. static bool __lec_arp_check_expire(struct lec_arp_table *entry,
  1419. unsigned long now,
  1420. struct lec_priv *priv)
  1421. {
  1422. unsigned long time_to_check;
  1423. if ((entry->flags) & LEC_REMOTE_FLAG && priv->topology_change)
  1424. time_to_check = priv->forward_delay_time;
  1425. else
  1426. time_to_check = priv->aging_time;
  1427. pr_debug("About to expire: %lx - %lx > %lx\n",
  1428. now, entry->last_used, time_to_check);
  1429. if (time_after(now, entry->last_used + time_to_check) &&
  1430. !(entry->flags & LEC_PERMANENT_FLAG) &&
  1431. !(entry->mac_addr[0] & 0x01)) { /* LANE2: 7.1.20 */
  1432. /* Remove entry */
  1433. pr_debug("Entry timed out\n");
  1434. lec_arp_remove(priv, entry);
  1435. lec_arp_put(entry);
  1436. } else {
  1437. /* Something else */
  1438. if ((entry->status == ESI_VC_PENDING ||
  1439. entry->status == ESI_ARP_PENDING) &&
  1440. time_after_eq(now, entry->timestamp +
  1441. priv->max_unknown_frame_time)) {
  1442. entry->timestamp = jiffies;
  1443. entry->packets_flooded = 0;
  1444. if (entry->status == ESI_VC_PENDING)
  1445. send_to_lecd(priv, l_svc_setup,
  1446. entry->mac_addr,
  1447. entry->atm_addr,
  1448. NULL);
  1449. }
  1450. if (entry->status == ESI_FLUSH_PENDING &&
  1451. time_after_eq(now, entry->timestamp +
  1452. priv->path_switching_delay)) {
  1453. lec_arp_hold(entry);
  1454. return true;
  1455. }
  1456. }
  1457. return false;
  1458. }
  1459. /*
  1460. * Expire entries.
  1461. * 1. Re-set timer
  1462. * 2. For each entry, delete entries that have aged past the age limit.
  1463. * 3. For each entry, depending on the status of the entry, perform
  1464. * the following maintenance.
  1465. * a. If status is ESI_VC_PENDING or ESI_ARP_PENDING then if the
  1466. * tick_count is above the max_unknown_frame_time, clear
  1467. * the tick_count to zero and clear the packets_flooded counter
  1468. * to zero. This supports the packet rate limit per address
  1469. * while flooding unknowns.
  1470. * b. If the status is ESI_FLUSH_PENDING and the tick_count is greater
  1471. * than or equal to the path_switching_delay, change the status
  1472. * to ESI_FORWARD_DIRECT. This causes the flush period to end
  1473. * regardless of the progress of the flush protocol.
  1474. */
  1475. static void lec_arp_check_expire(struct work_struct *work)
  1476. {
  1477. unsigned long flags;
  1478. struct lec_priv *priv =
  1479. container_of(work, struct lec_priv, lec_arp_work.work);
  1480. struct hlist_node *next;
  1481. struct lec_arp_table *entry;
  1482. unsigned long now;
  1483. int i;
  1484. pr_debug("%p\n", priv);
  1485. now = jiffies;
  1486. restart:
  1487. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1488. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1489. hlist_for_each_entry_safe(entry, next,
  1490. &priv->lec_arp_tables[i], next) {
  1491. if (__lec_arp_check_expire(entry, now, priv)) {
  1492. struct sk_buff *skb;
  1493. struct atm_vcc *vcc = entry->vcc;
  1494. spin_unlock_irqrestore(&priv->lec_arp_lock,
  1495. flags);
  1496. while ((skb = skb_dequeue(&entry->tx_wait)))
  1497. lec_send(vcc, skb);
  1498. entry->last_used = jiffies;
  1499. entry->status = ESI_FORWARD_DIRECT;
  1500. lec_arp_put(entry);
  1501. goto restart;
  1502. }
  1503. }
  1504. }
  1505. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1506. schedule_delayed_work(&priv->lec_arp_work, LEC_ARP_REFRESH_INTERVAL);
  1507. }
  1508. /*
  1509. * Try to find vcc where mac_address is attached.
  1510. *
  1511. */
  1512. static struct atm_vcc *lec_arp_resolve(struct lec_priv *priv,
  1513. const unsigned char *mac_to_find,
  1514. int is_rdesc,
  1515. struct lec_arp_table **ret_entry)
  1516. {
  1517. unsigned long flags;
  1518. struct lec_arp_table *entry;
  1519. struct atm_vcc *found;
  1520. if (mac_to_find[0] & 0x01) {
  1521. switch (priv->lane_version) {
  1522. case 1:
  1523. return priv->mcast_vcc;
  1524. case 2: /* LANE2 wants arp for multicast addresses */
  1525. if (ether_addr_equal(mac_to_find, bus_mac))
  1526. return priv->mcast_vcc;
  1527. break;
  1528. default:
  1529. break;
  1530. }
  1531. }
  1532. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1533. entry = lec_arp_find(priv, mac_to_find);
  1534. if (entry) {
  1535. if (entry->status == ESI_FORWARD_DIRECT) {
  1536. /* Connection Ok */
  1537. entry->last_used = jiffies;
  1538. lec_arp_hold(entry);
  1539. *ret_entry = entry;
  1540. found = entry->vcc;
  1541. goto out;
  1542. }
  1543. /*
  1544. * If the LE_ARP cache entry is still pending, reset count to 0
  1545. * so another LE_ARP request can be made for this frame.
  1546. */
  1547. if (entry->status == ESI_ARP_PENDING)
  1548. entry->no_tries = 0;
  1549. /*
  1550. * Data direct VC not yet set up, check to see if the unknown
  1551. * frame count is greater than the limit. If the limit has
  1552. * not been reached, allow the caller to send packet to
  1553. * BUS.
  1554. */
  1555. if (entry->status != ESI_FLUSH_PENDING &&
  1556. entry->packets_flooded <
  1557. priv->maximum_unknown_frame_count) {
  1558. entry->packets_flooded++;
  1559. pr_debug("Flooding..\n");
  1560. found = priv->mcast_vcc;
  1561. goto out;
  1562. }
  1563. /*
  1564. * We got here because entry->status == ESI_FLUSH_PENDING
  1565. * or BUS flood limit was reached for an entry which is
  1566. * in ESI_ARP_PENDING or ESI_VC_PENDING state.
  1567. */
  1568. lec_arp_hold(entry);
  1569. *ret_entry = entry;
  1570. pr_debug("entry->status %d entry->vcc %p\n", entry->status,
  1571. entry->vcc);
  1572. found = NULL;
  1573. } else {
  1574. /* No matching entry was found */
  1575. entry = make_entry(priv, mac_to_find);
  1576. pr_debug("Making entry\n");
  1577. if (!entry) {
  1578. found = priv->mcast_vcc;
  1579. goto out;
  1580. }
  1581. lec_arp_add(priv, entry);
  1582. /* We want arp-request(s) to be sent */
  1583. entry->packets_flooded = 1;
  1584. entry->status = ESI_ARP_PENDING;
  1585. entry->no_tries = 1;
  1586. entry->last_used = entry->timestamp = jiffies;
  1587. entry->is_rdesc = is_rdesc;
  1588. if (entry->is_rdesc)
  1589. send_to_lecd(priv, l_rdesc_arp_xmt, mac_to_find, NULL,
  1590. NULL);
  1591. else
  1592. send_to_lecd(priv, l_arp_xmt, mac_to_find, NULL, NULL);
  1593. entry->timer.expires = jiffies + (1 * HZ);
  1594. entry->timer.function = lec_arp_expire_arp;
  1595. add_timer(&entry->timer);
  1596. found = priv->mcast_vcc;
  1597. }
  1598. out:
  1599. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1600. return found;
  1601. }
  1602. static int
  1603. lec_addr_delete(struct lec_priv *priv, const unsigned char *atm_addr,
  1604. unsigned long permanent)
  1605. {
  1606. unsigned long flags;
  1607. struct hlist_node *next;
  1608. struct lec_arp_table *entry;
  1609. int i;
  1610. pr_debug("\n");
  1611. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1612. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1613. hlist_for_each_entry_safe(entry, next,
  1614. &priv->lec_arp_tables[i], next) {
  1615. if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN) &&
  1616. (permanent ||
  1617. !(entry->flags & LEC_PERMANENT_FLAG))) {
  1618. lec_arp_remove(priv, entry);
  1619. lec_arp_put(entry);
  1620. }
  1621. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1622. return 0;
  1623. }
  1624. }
  1625. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1626. return -1;
  1627. }
  1628. /*
  1629. * Notifies: Response to arp_request (atm_addr != NULL)
  1630. */
  1631. static void
  1632. lec_arp_update(struct lec_priv *priv, const unsigned char *mac_addr,
  1633. const unsigned char *atm_addr, unsigned long remoteflag,
  1634. unsigned int targetless_le_arp)
  1635. {
  1636. unsigned long flags;
  1637. struct hlist_node *next;
  1638. struct lec_arp_table *entry, *tmp;
  1639. int i;
  1640. pr_debug("%smac:%pM\n",
  1641. (targetless_le_arp) ? "targetless " : "", mac_addr);
  1642. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1643. entry = lec_arp_find(priv, mac_addr);
  1644. if (entry == NULL && targetless_le_arp)
  1645. goto out; /*
  1646. * LANE2: ignore targetless LE_ARPs for which
  1647. * we have no entry in the cache. 7.1.30
  1648. */
  1649. if (!hlist_empty(&priv->lec_arp_empty_ones)) {
  1650. hlist_for_each_entry_safe(entry, next,
  1651. &priv->lec_arp_empty_ones, next) {
  1652. if (memcmp(entry->atm_addr, atm_addr, ATM_ESA_LEN) == 0) {
  1653. hlist_del(&entry->next);
  1654. del_timer(&entry->timer);
  1655. tmp = lec_arp_find(priv, mac_addr);
  1656. if (tmp) {
  1657. del_timer(&tmp->timer);
  1658. tmp->status = ESI_FORWARD_DIRECT;
  1659. memcpy(tmp->atm_addr, atm_addr, ATM_ESA_LEN);
  1660. tmp->vcc = entry->vcc;
  1661. tmp->old_push = entry->old_push;
  1662. tmp->last_used = jiffies;
  1663. del_timer(&entry->timer);
  1664. lec_arp_put(entry);
  1665. entry = tmp;
  1666. } else {
  1667. entry->status = ESI_FORWARD_DIRECT;
  1668. ether_addr_copy(entry->mac_addr,
  1669. mac_addr);
  1670. entry->last_used = jiffies;
  1671. lec_arp_add(priv, entry);
  1672. }
  1673. if (remoteflag)
  1674. entry->flags |= LEC_REMOTE_FLAG;
  1675. else
  1676. entry->flags &= ~LEC_REMOTE_FLAG;
  1677. pr_debug("After update\n");
  1678. dump_arp_table(priv);
  1679. goto out;
  1680. }
  1681. }
  1682. }
  1683. entry = lec_arp_find(priv, mac_addr);
  1684. if (!entry) {
  1685. entry = make_entry(priv, mac_addr);
  1686. if (!entry)
  1687. goto out;
  1688. entry->status = ESI_UNKNOWN;
  1689. lec_arp_add(priv, entry);
  1690. /* Temporary, changes before end of function */
  1691. }
  1692. memcpy(entry->atm_addr, atm_addr, ATM_ESA_LEN);
  1693. del_timer(&entry->timer);
  1694. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1695. hlist_for_each_entry(tmp,
  1696. &priv->lec_arp_tables[i], next) {
  1697. if (entry != tmp &&
  1698. !memcmp(tmp->atm_addr, atm_addr, ATM_ESA_LEN)) {
  1699. /* Vcc to this host exists */
  1700. if (tmp->status > ESI_VC_PENDING) {
  1701. /*
  1702. * ESI_FLUSH_PENDING,
  1703. * ESI_FORWARD_DIRECT
  1704. */
  1705. entry->vcc = tmp->vcc;
  1706. entry->old_push = tmp->old_push;
  1707. }
  1708. entry->status = tmp->status;
  1709. break;
  1710. }
  1711. }
  1712. }
  1713. if (remoteflag)
  1714. entry->flags |= LEC_REMOTE_FLAG;
  1715. else
  1716. entry->flags &= ~LEC_REMOTE_FLAG;
  1717. if (entry->status == ESI_ARP_PENDING || entry->status == ESI_UNKNOWN) {
  1718. entry->status = ESI_VC_PENDING;
  1719. send_to_lecd(priv, l_svc_setup, entry->mac_addr, atm_addr, NULL);
  1720. }
  1721. pr_debug("After update2\n");
  1722. dump_arp_table(priv);
  1723. out:
  1724. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1725. }
  1726. /*
  1727. * Notifies: Vcc setup ready
  1728. */
  1729. static void
  1730. lec_vcc_added(struct lec_priv *priv, const struct atmlec_ioc *ioc_data,
  1731. struct atm_vcc *vcc,
  1732. void (*old_push) (struct atm_vcc *vcc, struct sk_buff *skb))
  1733. {
  1734. unsigned long flags;
  1735. struct lec_arp_table *entry;
  1736. int i, found_entry = 0;
  1737. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1738. /* Vcc for Multicast Forward. No timer, LANEv2 7.1.20 and 2.3.5.3 */
  1739. if (ioc_data->receive == 2) {
  1740. pr_debug("LEC_ARP: Attaching mcast forward\n");
  1741. #if 0
  1742. entry = lec_arp_find(priv, bus_mac);
  1743. if (!entry) {
  1744. pr_info("LEC_ARP: Multicast entry not found!\n");
  1745. goto out;
  1746. }
  1747. memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
  1748. entry->recv_vcc = vcc;
  1749. entry->old_recv_push = old_push;
  1750. #endif
  1751. entry = make_entry(priv, bus_mac);
  1752. if (entry == NULL)
  1753. goto out;
  1754. del_timer(&entry->timer);
  1755. memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
  1756. entry->recv_vcc = vcc;
  1757. entry->old_recv_push = old_push;
  1758. hlist_add_head(&entry->next, &priv->mcast_fwds);
  1759. goto out;
  1760. } else if (ioc_data->receive == 1) {
  1761. /*
  1762. * Vcc which we don't want to make default vcc,
  1763. * attach it anyway.
  1764. */
  1765. 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",
  1766. ioc_data->atm_addr[0], ioc_data->atm_addr[1],
  1767. ioc_data->atm_addr[2], ioc_data->atm_addr[3],
  1768. ioc_data->atm_addr[4], ioc_data->atm_addr[5],
  1769. ioc_data->atm_addr[6], ioc_data->atm_addr[7],
  1770. ioc_data->atm_addr[8], ioc_data->atm_addr[9],
  1771. ioc_data->atm_addr[10], ioc_data->atm_addr[11],
  1772. ioc_data->atm_addr[12], ioc_data->atm_addr[13],
  1773. ioc_data->atm_addr[14], ioc_data->atm_addr[15],
  1774. ioc_data->atm_addr[16], ioc_data->atm_addr[17],
  1775. ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
  1776. entry = make_entry(priv, bus_mac);
  1777. if (entry == NULL)
  1778. goto out;
  1779. memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
  1780. eth_zero_addr(entry->mac_addr);
  1781. entry->recv_vcc = vcc;
  1782. entry->old_recv_push = old_push;
  1783. entry->status = ESI_UNKNOWN;
  1784. entry->timer.expires = jiffies + priv->vcc_timeout_period;
  1785. entry->timer.function = lec_arp_expire_vcc;
  1786. hlist_add_head(&entry->next, &priv->lec_no_forward);
  1787. add_timer(&entry->timer);
  1788. dump_arp_table(priv);
  1789. goto out;
  1790. }
  1791. 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",
  1792. ioc_data->atm_addr[0], ioc_data->atm_addr[1],
  1793. ioc_data->atm_addr[2], ioc_data->atm_addr[3],
  1794. ioc_data->atm_addr[4], ioc_data->atm_addr[5],
  1795. ioc_data->atm_addr[6], ioc_data->atm_addr[7],
  1796. ioc_data->atm_addr[8], ioc_data->atm_addr[9],
  1797. ioc_data->atm_addr[10], ioc_data->atm_addr[11],
  1798. ioc_data->atm_addr[12], ioc_data->atm_addr[13],
  1799. ioc_data->atm_addr[14], ioc_data->atm_addr[15],
  1800. ioc_data->atm_addr[16], ioc_data->atm_addr[17],
  1801. ioc_data->atm_addr[18], ioc_data->atm_addr[19]);
  1802. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1803. hlist_for_each_entry(entry,
  1804. &priv->lec_arp_tables[i], next) {
  1805. if (memcmp
  1806. (ioc_data->atm_addr, entry->atm_addr,
  1807. ATM_ESA_LEN) == 0) {
  1808. pr_debug("LEC_ARP: Attaching data direct\n");
  1809. pr_debug("Currently -> Vcc: %d, Rvcc:%d\n",
  1810. entry->vcc ? entry->vcc->vci : 0,
  1811. entry->recv_vcc ? entry->recv_vcc->
  1812. vci : 0);
  1813. found_entry = 1;
  1814. del_timer(&entry->timer);
  1815. entry->vcc = vcc;
  1816. entry->old_push = old_push;
  1817. if (entry->status == ESI_VC_PENDING) {
  1818. if (priv->maximum_unknown_frame_count
  1819. == 0)
  1820. entry->status =
  1821. ESI_FORWARD_DIRECT;
  1822. else {
  1823. entry->timestamp = jiffies;
  1824. entry->status =
  1825. ESI_FLUSH_PENDING;
  1826. #if 0
  1827. send_to_lecd(priv, l_flush_xmt,
  1828. NULL,
  1829. entry->atm_addr,
  1830. NULL);
  1831. #endif
  1832. }
  1833. } else {
  1834. /*
  1835. * They were forming a connection
  1836. * to us, and we to them. Our
  1837. * ATM address is numerically lower
  1838. * than theirs, so we make connection
  1839. * we formed into default VCC (8.1.11).
  1840. * Connection they made gets torn
  1841. * down. This might confuse some
  1842. * clients. Can be changed if
  1843. * someone reports trouble...
  1844. */
  1845. ;
  1846. }
  1847. }
  1848. }
  1849. }
  1850. if (found_entry) {
  1851. pr_debug("After vcc was added\n");
  1852. dump_arp_table(priv);
  1853. goto out;
  1854. }
  1855. /*
  1856. * Not found, snatch address from first data packet that arrives
  1857. * from this vcc
  1858. */
  1859. entry = make_entry(priv, bus_mac);
  1860. if (!entry)
  1861. goto out;
  1862. entry->vcc = vcc;
  1863. entry->old_push = old_push;
  1864. memcpy(entry->atm_addr, ioc_data->atm_addr, ATM_ESA_LEN);
  1865. eth_zero_addr(entry->mac_addr);
  1866. entry->status = ESI_UNKNOWN;
  1867. hlist_add_head(&entry->next, &priv->lec_arp_empty_ones);
  1868. entry->timer.expires = jiffies + priv->vcc_timeout_period;
  1869. entry->timer.function = lec_arp_expire_vcc;
  1870. add_timer(&entry->timer);
  1871. pr_debug("After vcc was added\n");
  1872. dump_arp_table(priv);
  1873. out:
  1874. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1875. }
  1876. static void lec_flush_complete(struct lec_priv *priv, unsigned long tran_id)
  1877. {
  1878. unsigned long flags;
  1879. struct lec_arp_table *entry;
  1880. int i;
  1881. pr_debug("%lx\n", tran_id);
  1882. restart:
  1883. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1884. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1885. hlist_for_each_entry(entry,
  1886. &priv->lec_arp_tables[i], next) {
  1887. if (entry->flush_tran_id == tran_id &&
  1888. entry->status == ESI_FLUSH_PENDING) {
  1889. struct sk_buff *skb;
  1890. struct atm_vcc *vcc = entry->vcc;
  1891. lec_arp_hold(entry);
  1892. spin_unlock_irqrestore(&priv->lec_arp_lock,
  1893. flags);
  1894. while ((skb = skb_dequeue(&entry->tx_wait)))
  1895. lec_send(vcc, skb);
  1896. entry->last_used = jiffies;
  1897. entry->status = ESI_FORWARD_DIRECT;
  1898. lec_arp_put(entry);
  1899. pr_debug("LEC_ARP: Flushed\n");
  1900. goto restart;
  1901. }
  1902. }
  1903. }
  1904. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1905. dump_arp_table(priv);
  1906. }
  1907. static void
  1908. lec_set_flush_tran_id(struct lec_priv *priv,
  1909. const unsigned char *atm_addr, unsigned long tran_id)
  1910. {
  1911. unsigned long flags;
  1912. struct lec_arp_table *entry;
  1913. int i;
  1914. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1915. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++)
  1916. hlist_for_each_entry(entry,
  1917. &priv->lec_arp_tables[i], next) {
  1918. if (!memcmp(atm_addr, entry->atm_addr, ATM_ESA_LEN)) {
  1919. entry->flush_tran_id = tran_id;
  1920. pr_debug("Set flush transaction id to %lx for %p\n",
  1921. tran_id, entry);
  1922. }
  1923. }
  1924. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1925. }
  1926. static int lec_mcast_make(struct lec_priv *priv, struct atm_vcc *vcc)
  1927. {
  1928. unsigned long flags;
  1929. unsigned char mac_addr[] = {
  1930. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  1931. };
  1932. struct lec_arp_table *to_add;
  1933. struct lec_vcc_priv *vpriv;
  1934. int err = 0;
  1935. vpriv = kmalloc(sizeof(struct lec_vcc_priv), GFP_KERNEL);
  1936. if (!vpriv)
  1937. return -ENOMEM;
  1938. vpriv->xoff = 0;
  1939. vpriv->old_pop = vcc->pop;
  1940. vcc->user_back = vpriv;
  1941. vcc->pop = lec_pop;
  1942. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1943. to_add = make_entry(priv, mac_addr);
  1944. if (!to_add) {
  1945. vcc->pop = vpriv->old_pop;
  1946. kfree(vpriv);
  1947. err = -ENOMEM;
  1948. goto out;
  1949. }
  1950. memcpy(to_add->atm_addr, vcc->remote.sas_addr.prv, ATM_ESA_LEN);
  1951. to_add->status = ESI_FORWARD_DIRECT;
  1952. to_add->flags |= LEC_PERMANENT_FLAG;
  1953. to_add->vcc = vcc;
  1954. to_add->old_push = vcc->push;
  1955. vcc->push = lec_push;
  1956. priv->mcast_vcc = vcc;
  1957. lec_arp_add(priv, to_add);
  1958. out:
  1959. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  1960. return err;
  1961. }
  1962. static void lec_vcc_close(struct lec_priv *priv, struct atm_vcc *vcc)
  1963. {
  1964. unsigned long flags;
  1965. struct hlist_node *next;
  1966. struct lec_arp_table *entry;
  1967. int i;
  1968. pr_debug("LEC_ARP: lec_vcc_close vpi:%d vci:%d\n", vcc->vpi, vcc->vci);
  1969. dump_arp_table(priv);
  1970. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  1971. for (i = 0; i < LEC_ARP_TABLE_SIZE; i++) {
  1972. hlist_for_each_entry_safe(entry, next,
  1973. &priv->lec_arp_tables[i], next) {
  1974. if (vcc == entry->vcc) {
  1975. lec_arp_remove(priv, entry);
  1976. lec_arp_put(entry);
  1977. if (priv->mcast_vcc == vcc)
  1978. priv->mcast_vcc = NULL;
  1979. }
  1980. }
  1981. }
  1982. hlist_for_each_entry_safe(entry, next,
  1983. &priv->lec_arp_empty_ones, next) {
  1984. if (entry->vcc == vcc) {
  1985. lec_arp_clear_vccs(entry);
  1986. del_timer(&entry->timer);
  1987. hlist_del(&entry->next);
  1988. lec_arp_put(entry);
  1989. }
  1990. }
  1991. hlist_for_each_entry_safe(entry, next,
  1992. &priv->lec_no_forward, next) {
  1993. if (entry->recv_vcc == vcc) {
  1994. lec_arp_clear_vccs(entry);
  1995. del_timer(&entry->timer);
  1996. hlist_del(&entry->next);
  1997. lec_arp_put(entry);
  1998. }
  1999. }
  2000. hlist_for_each_entry_safe(entry, next, &priv->mcast_fwds, next) {
  2001. if (entry->recv_vcc == vcc) {
  2002. lec_arp_clear_vccs(entry);
  2003. /* No timer, LANEv2 7.1.20 and 2.3.5.3 */
  2004. hlist_del(&entry->next);
  2005. lec_arp_put(entry);
  2006. }
  2007. }
  2008. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  2009. dump_arp_table(priv);
  2010. }
  2011. static void
  2012. lec_arp_check_empties(struct lec_priv *priv,
  2013. struct atm_vcc *vcc, struct sk_buff *skb)
  2014. {
  2015. unsigned long flags;
  2016. struct hlist_node *next;
  2017. struct lec_arp_table *entry, *tmp;
  2018. struct lecdatahdr_8023 *hdr = (struct lecdatahdr_8023 *)skb->data;
  2019. unsigned char *src = hdr->h_source;
  2020. spin_lock_irqsave(&priv->lec_arp_lock, flags);
  2021. hlist_for_each_entry_safe(entry, next,
  2022. &priv->lec_arp_empty_ones, next) {
  2023. if (vcc == entry->vcc) {
  2024. del_timer(&entry->timer);
  2025. ether_addr_copy(entry->mac_addr, src);
  2026. entry->status = ESI_FORWARD_DIRECT;
  2027. entry->last_used = jiffies;
  2028. /* We might have got an entry */
  2029. tmp = lec_arp_find(priv, src);
  2030. if (tmp) {
  2031. lec_arp_remove(priv, tmp);
  2032. lec_arp_put(tmp);
  2033. }
  2034. hlist_del(&entry->next);
  2035. lec_arp_add(priv, entry);
  2036. goto out;
  2037. }
  2038. }
  2039. pr_debug("LEC_ARP: Arp_check_empties: entry not found!\n");
  2040. out:
  2041. spin_unlock_irqrestore(&priv->lec_arp_lock, flags);
  2042. }
  2043. MODULE_LICENSE("GPL");