lec.c 64 KB

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