lec.c 60 KB

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