lec.c 63 KB

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