lec.c 63 KB

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