lec.c 64 KB

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