lec.c 60 KB

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