lec.c 65 KB

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