lec.c 66 KB

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