lec.c 63 KB

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