lec.c 65 KB

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