lec.c 65 KB

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