lec.c 60 KB

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