lec.c 65 KB

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