mpc.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570
  1. #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
  2. #include <linux/kernel.h>
  3. #include <linux/string.h>
  4. #include <linux/timer.h>
  5. #include <linux/init.h>
  6. #include <linux/bitops.h>
  7. #include <linux/capability.h>
  8. #include <linux/seq_file.h>
  9. /* We are an ethernet device */
  10. #include <linux/if_ether.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/etherdevice.h>
  13. #include <net/sock.h>
  14. #include <linux/skbuff.h>
  15. #include <linux/ip.h>
  16. #include <linux/uaccess.h>
  17. #include <asm/byteorder.h>
  18. #include <net/checksum.h> /* for ip_fast_csum() */
  19. #include <net/arp.h>
  20. #include <net/dst.h>
  21. #include <linux/proc_fs.h>
  22. /* And atm device */
  23. #include <linux/atmdev.h>
  24. #include <linux/atmlec.h>
  25. #include <linux/atmmpc.h>
  26. /* Modular too */
  27. #include <linux/module.h>
  28. #include "lec.h"
  29. #include "mpc.h"
  30. #include "resources.h"
  31. /*
  32. * mpc.c: Implementation of MPOA client kernel part
  33. */
  34. #if 0
  35. #define dprintk(format, args...) \
  36. printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args)
  37. #define dprintk_cont(format, args...) printk(KERN_CONT format, ##args)
  38. #else
  39. #define dprintk(format, args...) \
  40. do { if (0) \
  41. printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args);\
  42. } while (0)
  43. #define dprintk_cont(format, args...) \
  44. do { if (0) printk(KERN_CONT format, ##args); } while (0)
  45. #endif
  46. #if 0
  47. #define ddprintk(format, args...) \
  48. printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args)
  49. #define ddprintk_cont(format, args...) printk(KERN_CONT format, ##args)
  50. #else
  51. #define ddprintk(format, args...) \
  52. do { if (0) \
  53. printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args);\
  54. } while (0)
  55. #define ddprintk_cont(format, args...) \
  56. do { if (0) printk(KERN_CONT format, ##args); } while (0)
  57. #endif
  58. #define MPOA_TAG_LEN 4
  59. /* mpc_daemon -> kernel */
  60. static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc);
  61. static void MPOA_res_reply_rcvd(struct k_message *msg, struct mpoa_client *mpc);
  62. static void ingress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc);
  63. static void egress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc);
  64. static void mps_death(struct k_message *msg, struct mpoa_client *mpc);
  65. static void clean_up(struct k_message *msg, struct mpoa_client *mpc,
  66. int action);
  67. static void MPOA_cache_impos_rcvd(struct k_message *msg,
  68. struct mpoa_client *mpc);
  69. static void set_mpc_ctrl_addr_rcvd(struct k_message *mesg,
  70. struct mpoa_client *mpc);
  71. static void set_mps_mac_addr_rcvd(struct k_message *mesg,
  72. struct mpoa_client *mpc);
  73. static const uint8_t *copy_macs(struct mpoa_client *mpc,
  74. const uint8_t *router_mac,
  75. const uint8_t *tlvs, uint8_t mps_macs,
  76. uint8_t device_type);
  77. static void purge_egress_shortcut(struct atm_vcc *vcc, eg_cache_entry *entry);
  78. static void send_set_mps_ctrl_addr(const char *addr, struct mpoa_client *mpc);
  79. static void mpoad_close(struct atm_vcc *vcc);
  80. static int msg_from_mpoad(struct atm_vcc *vcc, struct sk_buff *skb);
  81. static void mpc_push(struct atm_vcc *vcc, struct sk_buff *skb);
  82. static netdev_tx_t mpc_send_packet(struct sk_buff *skb,
  83. struct net_device *dev);
  84. static int mpoa_event_listener(struct notifier_block *mpoa_notifier,
  85. unsigned long event, void *dev);
  86. static void mpc_timer_refresh(void);
  87. static void mpc_cache_check(unsigned long checking_time);
  88. static struct llc_snap_hdr llc_snap_mpoa_ctrl = {
  89. 0xaa, 0xaa, 0x03,
  90. {0x00, 0x00, 0x5e},
  91. {0x00, 0x03} /* For MPOA control PDUs */
  92. };
  93. static struct llc_snap_hdr llc_snap_mpoa_data = {
  94. 0xaa, 0xaa, 0x03,
  95. {0x00, 0x00, 0x00},
  96. {0x08, 0x00} /* This is for IP PDUs only */
  97. };
  98. static struct llc_snap_hdr llc_snap_mpoa_data_tagged = {
  99. 0xaa, 0xaa, 0x03,
  100. {0x00, 0x00, 0x00},
  101. {0x88, 0x4c} /* This is for tagged data PDUs */
  102. };
  103. static struct notifier_block mpoa_notifier = {
  104. mpoa_event_listener,
  105. NULL,
  106. 0
  107. };
  108. struct mpoa_client *mpcs = NULL; /* FIXME */
  109. static struct atm_mpoa_qos *qos_head = NULL;
  110. static DEFINE_TIMER(mpc_timer, NULL, 0, 0);
  111. static struct mpoa_client *find_mpc_by_itfnum(int itf)
  112. {
  113. struct mpoa_client *mpc;
  114. mpc = mpcs; /* our global linked list */
  115. while (mpc != NULL) {
  116. if (mpc->dev_num == itf)
  117. return mpc;
  118. mpc = mpc->next;
  119. }
  120. return NULL; /* not found */
  121. }
  122. static struct mpoa_client *find_mpc_by_vcc(struct atm_vcc *vcc)
  123. {
  124. struct mpoa_client *mpc;
  125. mpc = mpcs; /* our global linked list */
  126. while (mpc != NULL) {
  127. if (mpc->mpoad_vcc == vcc)
  128. return mpc;
  129. mpc = mpc->next;
  130. }
  131. return NULL; /* not found */
  132. }
  133. static struct mpoa_client *find_mpc_by_lec(struct net_device *dev)
  134. {
  135. struct mpoa_client *mpc;
  136. mpc = mpcs; /* our global linked list */
  137. while (mpc != NULL) {
  138. if (mpc->dev == dev)
  139. return mpc;
  140. mpc = mpc->next;
  141. }
  142. return NULL; /* not found */
  143. }
  144. /*
  145. * Functions for managing QoS list
  146. */
  147. /*
  148. * Overwrites the old entry or makes a new one.
  149. */
  150. struct atm_mpoa_qos *atm_mpoa_add_qos(__be32 dst_ip, struct atm_qos *qos)
  151. {
  152. struct atm_mpoa_qos *entry;
  153. entry = atm_mpoa_search_qos(dst_ip);
  154. if (entry != NULL) {
  155. entry->qos = *qos;
  156. return entry;
  157. }
  158. entry = kmalloc(sizeof(struct atm_mpoa_qos), GFP_KERNEL);
  159. if (entry == NULL) {
  160. pr_info("mpoa: out of memory\n");
  161. return entry;
  162. }
  163. entry->ipaddr = dst_ip;
  164. entry->qos = *qos;
  165. entry->next = qos_head;
  166. qos_head = entry;
  167. return entry;
  168. }
  169. struct atm_mpoa_qos *atm_mpoa_search_qos(__be32 dst_ip)
  170. {
  171. struct atm_mpoa_qos *qos;
  172. qos = qos_head;
  173. while (qos) {
  174. if (qos->ipaddr == dst_ip)
  175. break;
  176. qos = qos->next;
  177. }
  178. return qos;
  179. }
  180. /*
  181. * Returns 0 for failure
  182. */
  183. int atm_mpoa_delete_qos(struct atm_mpoa_qos *entry)
  184. {
  185. struct atm_mpoa_qos *curr;
  186. if (entry == NULL)
  187. return 0;
  188. if (entry == qos_head) {
  189. qos_head = qos_head->next;
  190. kfree(entry);
  191. return 1;
  192. }
  193. curr = qos_head;
  194. while (curr != NULL) {
  195. if (curr->next == entry) {
  196. curr->next = entry->next;
  197. kfree(entry);
  198. return 1;
  199. }
  200. curr = curr->next;
  201. }
  202. return 0;
  203. }
  204. /* this is buggered - we need locking for qos_head */
  205. void atm_mpoa_disp_qos(struct seq_file *m)
  206. {
  207. struct atm_mpoa_qos *qos;
  208. qos = qos_head;
  209. seq_printf(m, "QoS entries for shortcuts:\n");
  210. seq_printf(m, "IP address\n TX:max_pcr pcr min_pcr max_cdv max_sdu\n RX:max_pcr pcr min_pcr max_cdv max_sdu\n");
  211. while (qos != NULL) {
  212. seq_printf(m, "%pI4\n %-7d %-7d %-7d %-7d %-7d\n %-7d %-7d %-7d %-7d %-7d\n",
  213. &qos->ipaddr,
  214. qos->qos.txtp.max_pcr,
  215. qos->qos.txtp.pcr,
  216. qos->qos.txtp.min_pcr,
  217. qos->qos.txtp.max_cdv,
  218. qos->qos.txtp.max_sdu,
  219. qos->qos.rxtp.max_pcr,
  220. qos->qos.rxtp.pcr,
  221. qos->qos.rxtp.min_pcr,
  222. qos->qos.rxtp.max_cdv,
  223. qos->qos.rxtp.max_sdu);
  224. qos = qos->next;
  225. }
  226. }
  227. static struct net_device *find_lec_by_itfnum(int itf)
  228. {
  229. struct net_device *dev;
  230. char name[IFNAMSIZ];
  231. sprintf(name, "lec%d", itf);
  232. dev = dev_get_by_name(&init_net, name);
  233. return dev;
  234. }
  235. static struct mpoa_client *alloc_mpc(void)
  236. {
  237. struct mpoa_client *mpc;
  238. mpc = kzalloc(sizeof(struct mpoa_client), GFP_KERNEL);
  239. if (mpc == NULL)
  240. return NULL;
  241. rwlock_init(&mpc->ingress_lock);
  242. rwlock_init(&mpc->egress_lock);
  243. mpc->next = mpcs;
  244. atm_mpoa_init_cache(mpc);
  245. mpc->parameters.mpc_p1 = MPC_P1;
  246. mpc->parameters.mpc_p2 = MPC_P2;
  247. memset(mpc->parameters.mpc_p3, 0, sizeof(mpc->parameters.mpc_p3));
  248. mpc->parameters.mpc_p4 = MPC_P4;
  249. mpc->parameters.mpc_p5 = MPC_P5;
  250. mpc->parameters.mpc_p6 = MPC_P6;
  251. mpcs = mpc;
  252. return mpc;
  253. }
  254. /*
  255. *
  256. * start_mpc() puts the MPC on line. All the packets destined
  257. * to the lec underneath us are now being monitored and
  258. * shortcuts will be established.
  259. *
  260. */
  261. static void start_mpc(struct mpoa_client *mpc, struct net_device *dev)
  262. {
  263. dprintk("(%s)\n", mpc->dev->name);
  264. if (!dev->netdev_ops)
  265. pr_info("(%s) not starting\n", dev->name);
  266. else {
  267. mpc->old_ops = dev->netdev_ops;
  268. mpc->new_ops = *mpc->old_ops;
  269. mpc->new_ops.ndo_start_xmit = mpc_send_packet;
  270. dev->netdev_ops = &mpc->new_ops;
  271. }
  272. }
  273. static void stop_mpc(struct mpoa_client *mpc)
  274. {
  275. struct net_device *dev = mpc->dev;
  276. dprintk("(%s)", mpc->dev->name);
  277. /* Lets not nullify lec device's dev->hard_start_xmit */
  278. if (dev->netdev_ops != &mpc->new_ops) {
  279. dprintk_cont(" mpc already stopped, not fatal\n");
  280. return;
  281. }
  282. dprintk_cont("\n");
  283. dev->netdev_ops = mpc->old_ops;
  284. mpc->old_ops = NULL;
  285. /* close_shortcuts(mpc); ??? FIXME */
  286. }
  287. static const char *mpoa_device_type_string(char type) __attribute__ ((unused));
  288. static const char *mpoa_device_type_string(char type)
  289. {
  290. switch (type) {
  291. case NON_MPOA:
  292. return "non-MPOA device";
  293. case MPS:
  294. return "MPS";
  295. case MPC:
  296. return "MPC";
  297. case MPS_AND_MPC:
  298. return "both MPS and MPC";
  299. }
  300. return "unspecified (non-MPOA) device";
  301. }
  302. /*
  303. * lec device calls this via its netdev_priv(dev)->lane2_ops
  304. * ->associate_indicator() when it sees a TLV in LE_ARP packet.
  305. * We fill in the pointer above when we see a LANE2 lec initializing
  306. * See LANE2 spec 3.1.5
  307. *
  308. * Quite a big and ugly function but when you look at it
  309. * all it does is to try to locate and parse MPOA Device
  310. * Type TLV.
  311. * We give our lec a pointer to this function and when the
  312. * lec sees a TLV it uses the pointer to call this function.
  313. *
  314. */
  315. static void lane2_assoc_ind(struct net_device *dev, const u8 *mac_addr,
  316. const u8 *tlvs, u32 sizeoftlvs)
  317. {
  318. uint32_t type;
  319. uint8_t length, mpoa_device_type, number_of_mps_macs;
  320. const uint8_t *end_of_tlvs;
  321. struct mpoa_client *mpc;
  322. mpoa_device_type = number_of_mps_macs = 0; /* silence gcc */
  323. dprintk("(%s) received TLV(s), ", dev->name);
  324. dprintk("total length of all TLVs %d\n", sizeoftlvs);
  325. mpc = find_mpc_by_lec(dev); /* Sampo-Fix: moved here from below */
  326. if (mpc == NULL) {
  327. pr_info("(%s) no mpc\n", dev->name);
  328. return;
  329. }
  330. end_of_tlvs = tlvs + sizeoftlvs;
  331. while (end_of_tlvs - tlvs >= 5) {
  332. type = ((tlvs[0] << 24) | (tlvs[1] << 16) |
  333. (tlvs[2] << 8) | tlvs[3]);
  334. length = tlvs[4];
  335. tlvs += 5;
  336. dprintk(" type 0x%x length %02x\n", type, length);
  337. if (tlvs + length > end_of_tlvs) {
  338. pr_info("TLV value extends past its buffer, aborting parse\n");
  339. return;
  340. }
  341. if (type == 0) {
  342. pr_info("mpoa: (%s) TLV type was 0, returning\n",
  343. dev->name);
  344. return;
  345. }
  346. if (type != TLV_MPOA_DEVICE_TYPE) {
  347. tlvs += length;
  348. continue; /* skip other TLVs */
  349. }
  350. mpoa_device_type = *tlvs++;
  351. number_of_mps_macs = *tlvs++;
  352. dprintk("(%s) MPOA device type '%s', ",
  353. dev->name, mpoa_device_type_string(mpoa_device_type));
  354. if (mpoa_device_type == MPS_AND_MPC &&
  355. length < (42 + number_of_mps_macs*ETH_ALEN)) { /* :) */
  356. pr_info("(%s) short MPOA Device Type TLV\n",
  357. dev->name);
  358. continue;
  359. }
  360. if ((mpoa_device_type == MPS || mpoa_device_type == MPC) &&
  361. length < 22 + number_of_mps_macs*ETH_ALEN) {
  362. pr_info("(%s) short MPOA Device Type TLV\n", dev->name);
  363. continue;
  364. }
  365. if (mpoa_device_type != MPS &&
  366. mpoa_device_type != MPS_AND_MPC) {
  367. dprintk("ignoring non-MPS device ");
  368. if (mpoa_device_type == MPC)
  369. tlvs += 20;
  370. continue; /* we are only interested in MPSs */
  371. }
  372. if (number_of_mps_macs == 0 &&
  373. mpoa_device_type == MPS_AND_MPC) {
  374. pr_info("(%s) MPS_AND_MPC has zero MACs\n", dev->name);
  375. continue; /* someone should read the spec */
  376. }
  377. dprintk_cont("this MPS has %d MAC addresses\n",
  378. number_of_mps_macs);
  379. /*
  380. * ok, now we can go and tell our daemon
  381. * the control address of MPS
  382. */
  383. send_set_mps_ctrl_addr(tlvs, mpc);
  384. tlvs = copy_macs(mpc, mac_addr, tlvs,
  385. number_of_mps_macs, mpoa_device_type);
  386. if (tlvs == NULL)
  387. return;
  388. }
  389. if (end_of_tlvs - tlvs != 0)
  390. pr_info("(%s) ignoring %Zd bytes of trailing TLV garbage\n",
  391. dev->name, end_of_tlvs - tlvs);
  392. return;
  393. }
  394. /*
  395. * Store at least advertizing router's MAC address
  396. * plus the possible MAC address(es) to mpc->mps_macs.
  397. * For a freshly allocated MPOA client mpc->mps_macs == 0.
  398. */
  399. static const uint8_t *copy_macs(struct mpoa_client *mpc,
  400. const uint8_t *router_mac,
  401. const uint8_t *tlvs, uint8_t mps_macs,
  402. uint8_t device_type)
  403. {
  404. int num_macs;
  405. num_macs = (mps_macs > 1) ? mps_macs : 1;
  406. if (mpc->number_of_mps_macs != num_macs) { /* need to reallocate? */
  407. if (mpc->number_of_mps_macs != 0)
  408. kfree(mpc->mps_macs);
  409. mpc->number_of_mps_macs = 0;
  410. mpc->mps_macs = kmalloc(num_macs * ETH_ALEN, GFP_KERNEL);
  411. if (mpc->mps_macs == NULL) {
  412. pr_info("(%s) out of mem\n", mpc->dev->name);
  413. return NULL;
  414. }
  415. }
  416. memcpy(mpc->mps_macs, router_mac, ETH_ALEN);
  417. tlvs += 20; if (device_type == MPS_AND_MPC) tlvs += 20;
  418. if (mps_macs > 0)
  419. memcpy(mpc->mps_macs, tlvs, mps_macs*ETH_ALEN);
  420. tlvs += mps_macs*ETH_ALEN;
  421. mpc->number_of_mps_macs = num_macs;
  422. return tlvs;
  423. }
  424. static int send_via_shortcut(struct sk_buff *skb, struct mpoa_client *mpc)
  425. {
  426. in_cache_entry *entry;
  427. struct iphdr *iph;
  428. char *buff;
  429. __be32 ipaddr = 0;
  430. static struct {
  431. struct llc_snap_hdr hdr;
  432. __be32 tag;
  433. } tagged_llc_snap_hdr = {
  434. {0xaa, 0xaa, 0x03, {0x00, 0x00, 0x00}, {0x88, 0x4c}},
  435. 0
  436. };
  437. buff = skb->data + mpc->dev->hard_header_len;
  438. iph = (struct iphdr *)buff;
  439. ipaddr = iph->daddr;
  440. ddprintk("(%s) ipaddr 0x%x\n",
  441. mpc->dev->name, ipaddr);
  442. entry = mpc->in_ops->get(ipaddr, mpc);
  443. if (entry == NULL) {
  444. entry = mpc->in_ops->add_entry(ipaddr, mpc);
  445. if (entry != NULL)
  446. mpc->in_ops->put(entry);
  447. return 1;
  448. }
  449. /* threshold not exceeded or VCC not ready */
  450. if (mpc->in_ops->cache_hit(entry, mpc) != OPEN) {
  451. ddprintk("(%s) cache_hit: returns != OPEN\n",
  452. mpc->dev->name);
  453. mpc->in_ops->put(entry);
  454. return 1;
  455. }
  456. ddprintk("(%s) using shortcut\n",
  457. mpc->dev->name);
  458. /* MPOA spec A.1.4, MPOA client must decrement IP ttl at least by one */
  459. if (iph->ttl <= 1) {
  460. ddprintk("(%s) IP ttl = %u, using LANE\n",
  461. mpc->dev->name, iph->ttl);
  462. mpc->in_ops->put(entry);
  463. return 1;
  464. }
  465. iph->ttl--;
  466. iph->check = 0;
  467. iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
  468. if (entry->ctrl_info.tag != 0) {
  469. ddprintk("(%s) adding tag 0x%x\n",
  470. mpc->dev->name, entry->ctrl_info.tag);
  471. tagged_llc_snap_hdr.tag = entry->ctrl_info.tag;
  472. skb_pull(skb, ETH_HLEN); /* get rid of Eth header */
  473. skb_push(skb, sizeof(tagged_llc_snap_hdr));
  474. /* add LLC/SNAP header */
  475. skb_copy_to_linear_data(skb, &tagged_llc_snap_hdr,
  476. sizeof(tagged_llc_snap_hdr));
  477. } else {
  478. skb_pull(skb, ETH_HLEN); /* get rid of Eth header */
  479. skb_push(skb, sizeof(struct llc_snap_hdr));
  480. /* add LLC/SNAP header + tag */
  481. skb_copy_to_linear_data(skb, &llc_snap_mpoa_data,
  482. sizeof(struct llc_snap_hdr));
  483. }
  484. atomic_add(skb->truesize, &sk_atm(entry->shortcut)->sk_wmem_alloc);
  485. ATM_SKB(skb)->atm_options = entry->shortcut->atm_options;
  486. entry->shortcut->send(entry->shortcut, skb);
  487. entry->packets_fwded++;
  488. mpc->in_ops->put(entry);
  489. return 0;
  490. }
  491. /*
  492. * Probably needs some error checks and locking, not sure...
  493. */
  494. static netdev_tx_t mpc_send_packet(struct sk_buff *skb,
  495. struct net_device *dev)
  496. {
  497. struct mpoa_client *mpc;
  498. struct ethhdr *eth;
  499. int i = 0;
  500. mpc = find_mpc_by_lec(dev); /* this should NEVER fail */
  501. if (mpc == NULL) {
  502. pr_info("(%s) no MPC found\n", dev->name);
  503. goto non_ip;
  504. }
  505. eth = (struct ethhdr *)skb->data;
  506. if (eth->h_proto != htons(ETH_P_IP))
  507. goto non_ip; /* Multi-Protocol Over ATM :-) */
  508. /* Weed out funny packets (e.g., AF_PACKET or raw). */
  509. if (skb->len < ETH_HLEN + sizeof(struct iphdr))
  510. goto non_ip;
  511. skb_set_network_header(skb, ETH_HLEN);
  512. if (skb->len < ETH_HLEN + ip_hdr(skb)->ihl * 4 || ip_hdr(skb)->ihl < 5)
  513. goto non_ip;
  514. while (i < mpc->number_of_mps_macs) {
  515. if (!compare_ether_addr(eth->h_dest,
  516. (mpc->mps_macs + i*ETH_ALEN)))
  517. if (send_via_shortcut(skb, mpc) == 0) /* try shortcut */
  518. return NETDEV_TX_OK;
  519. i++;
  520. }
  521. non_ip:
  522. return mpc->old_ops->ndo_start_xmit(skb, dev);
  523. }
  524. static int atm_mpoa_vcc_attach(struct atm_vcc *vcc, void __user *arg)
  525. {
  526. int bytes_left;
  527. struct mpoa_client *mpc;
  528. struct atmmpc_ioc ioc_data;
  529. in_cache_entry *in_entry;
  530. __be32 ipaddr;
  531. bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmmpc_ioc));
  532. if (bytes_left != 0) {
  533. pr_info("mpoa:Short read (missed %d bytes) from userland\n",
  534. bytes_left);
  535. return -EFAULT;
  536. }
  537. ipaddr = ioc_data.ipaddr;
  538. if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF)
  539. return -EINVAL;
  540. mpc = find_mpc_by_itfnum(ioc_data.dev_num);
  541. if (mpc == NULL)
  542. return -EINVAL;
  543. if (ioc_data.type == MPC_SOCKET_INGRESS) {
  544. in_entry = mpc->in_ops->get(ipaddr, mpc);
  545. if (in_entry == NULL ||
  546. in_entry->entry_state < INGRESS_RESOLVED) {
  547. pr_info("(%s) did not find RESOLVED entry from ingress cache\n",
  548. mpc->dev->name);
  549. if (in_entry != NULL)
  550. mpc->in_ops->put(in_entry);
  551. return -EINVAL;
  552. }
  553. pr_info("(%s) attaching ingress SVC, entry = %pI4\n",
  554. mpc->dev->name, &in_entry->ctrl_info.in_dst_ip);
  555. in_entry->shortcut = vcc;
  556. mpc->in_ops->put(in_entry);
  557. } else {
  558. pr_info("(%s) attaching egress SVC\n", mpc->dev->name);
  559. }
  560. vcc->proto_data = mpc->dev;
  561. vcc->push = mpc_push;
  562. return 0;
  563. }
  564. /*
  565. *
  566. */
  567. static void mpc_vcc_close(struct atm_vcc *vcc, struct net_device *dev)
  568. {
  569. struct mpoa_client *mpc;
  570. in_cache_entry *in_entry;
  571. eg_cache_entry *eg_entry;
  572. mpc = find_mpc_by_lec(dev);
  573. if (mpc == NULL) {
  574. pr_info("(%s) close for unknown MPC\n", dev->name);
  575. return;
  576. }
  577. dprintk("(%s)\n", dev->name);
  578. in_entry = mpc->in_ops->get_by_vcc(vcc, mpc);
  579. if (in_entry) {
  580. dprintk("(%s) ingress SVC closed ip = %pI4\n",
  581. mpc->dev->name, &in_entry->ctrl_info.in_dst_ip);
  582. in_entry->shortcut = NULL;
  583. mpc->in_ops->put(in_entry);
  584. }
  585. eg_entry = mpc->eg_ops->get_by_vcc(vcc, mpc);
  586. if (eg_entry) {
  587. dprintk("(%s) egress SVC closed\n", mpc->dev->name);
  588. eg_entry->shortcut = NULL;
  589. mpc->eg_ops->put(eg_entry);
  590. }
  591. if (in_entry == NULL && eg_entry == NULL)
  592. dprintk("(%s) unused vcc closed\n", dev->name);
  593. return;
  594. }
  595. static void mpc_push(struct atm_vcc *vcc, struct sk_buff *skb)
  596. {
  597. struct net_device *dev = (struct net_device *)vcc->proto_data;
  598. struct sk_buff *new_skb;
  599. eg_cache_entry *eg;
  600. struct mpoa_client *mpc;
  601. __be32 tag;
  602. char *tmp;
  603. ddprintk("(%s)\n", dev->name);
  604. if (skb == NULL) {
  605. dprintk("(%s) null skb, closing VCC\n", dev->name);
  606. mpc_vcc_close(vcc, dev);
  607. return;
  608. }
  609. skb->dev = dev;
  610. if (memcmp(skb->data, &llc_snap_mpoa_ctrl,
  611. sizeof(struct llc_snap_hdr)) == 0) {
  612. struct sock *sk = sk_atm(vcc);
  613. dprintk("(%s) control packet arrived\n", dev->name);
  614. /* Pass control packets to daemon */
  615. skb_queue_tail(&sk->sk_receive_queue, skb);
  616. sk->sk_data_ready(sk, skb->len);
  617. return;
  618. }
  619. /* data coming over the shortcut */
  620. atm_return(vcc, skb->truesize);
  621. mpc = find_mpc_by_lec(dev);
  622. if (mpc == NULL) {
  623. pr_info("(%s) unknown MPC\n", dev->name);
  624. return;
  625. }
  626. if (memcmp(skb->data, &llc_snap_mpoa_data_tagged,
  627. sizeof(struct llc_snap_hdr)) == 0) { /* MPOA tagged data */
  628. ddprintk("(%s) tagged data packet arrived\n", dev->name);
  629. } else if (memcmp(skb->data, &llc_snap_mpoa_data,
  630. sizeof(struct llc_snap_hdr)) == 0) { /* MPOA data */
  631. pr_info("(%s) Unsupported non-tagged data packet arrived. Purging\n",
  632. dev->name);
  633. dev_kfree_skb_any(skb);
  634. return;
  635. } else {
  636. pr_info("(%s) garbage arrived, purging\n", dev->name);
  637. dev_kfree_skb_any(skb);
  638. return;
  639. }
  640. tmp = skb->data + sizeof(struct llc_snap_hdr);
  641. tag = *(__be32 *)tmp;
  642. eg = mpc->eg_ops->get_by_tag(tag, mpc);
  643. if (eg == NULL) {
  644. pr_info("mpoa: (%s) Didn't find egress cache entry, tag = %u\n",
  645. dev->name, tag);
  646. purge_egress_shortcut(vcc, NULL);
  647. dev_kfree_skb_any(skb);
  648. return;
  649. }
  650. /*
  651. * See if ingress MPC is using shortcut we opened as a return channel.
  652. * This means we have a bi-directional vcc opened by us.
  653. */
  654. if (eg->shortcut == NULL) {
  655. eg->shortcut = vcc;
  656. pr_info("(%s) egress SVC in use\n", dev->name);
  657. }
  658. skb_pull(skb, sizeof(struct llc_snap_hdr) + sizeof(tag));
  659. /* get rid of LLC/SNAP header */
  660. new_skb = skb_realloc_headroom(skb, eg->ctrl_info.DH_length);
  661. /* LLC/SNAP is shorter than MAC header :( */
  662. dev_kfree_skb_any(skb);
  663. if (new_skb == NULL) {
  664. mpc->eg_ops->put(eg);
  665. return;
  666. }
  667. skb_push(new_skb, eg->ctrl_info.DH_length); /* add MAC header */
  668. skb_copy_to_linear_data(new_skb, eg->ctrl_info.DLL_header,
  669. eg->ctrl_info.DH_length);
  670. new_skb->protocol = eth_type_trans(new_skb, dev);
  671. skb_reset_network_header(new_skb);
  672. eg->latest_ip_addr = ip_hdr(new_skb)->saddr;
  673. eg->packets_rcvd++;
  674. mpc->eg_ops->put(eg);
  675. memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
  676. netif_rx(new_skb);
  677. return;
  678. }
  679. static struct atmdev_ops mpc_ops = { /* only send is required */
  680. .close = mpoad_close,
  681. .send = msg_from_mpoad
  682. };
  683. static struct atm_dev mpc_dev = {
  684. .ops = &mpc_ops,
  685. .type = "mpc",
  686. .number = 42,
  687. .lock = __SPIN_LOCK_UNLOCKED(mpc_dev.lock)
  688. /* members not explicitly initialised will be 0 */
  689. };
  690. static int atm_mpoa_mpoad_attach(struct atm_vcc *vcc, int arg)
  691. {
  692. struct mpoa_client *mpc;
  693. struct lec_priv *priv;
  694. int err;
  695. if (mpcs == NULL) {
  696. init_timer(&mpc_timer);
  697. mpc_timer_refresh();
  698. /* This lets us now how our LECs are doing */
  699. err = register_netdevice_notifier(&mpoa_notifier);
  700. if (err < 0) {
  701. del_timer(&mpc_timer);
  702. return err;
  703. }
  704. }
  705. mpc = find_mpc_by_itfnum(arg);
  706. if (mpc == NULL) {
  707. dprintk("allocating new mpc for itf %d\n", arg);
  708. mpc = alloc_mpc();
  709. if (mpc == NULL)
  710. return -ENOMEM;
  711. mpc->dev_num = arg;
  712. mpc->dev = find_lec_by_itfnum(arg);
  713. /* NULL if there was no lec */
  714. }
  715. if (mpc->mpoad_vcc) {
  716. pr_info("mpoad is already present for itf %d\n", arg);
  717. return -EADDRINUSE;
  718. }
  719. if (mpc->dev) { /* check if the lec is LANE2 capable */
  720. priv = netdev_priv(mpc->dev);
  721. if (priv->lane_version < 2) {
  722. dev_put(mpc->dev);
  723. mpc->dev = NULL;
  724. } else
  725. priv->lane2_ops->associate_indicator = lane2_assoc_ind;
  726. }
  727. mpc->mpoad_vcc = vcc;
  728. vcc->dev = &mpc_dev;
  729. vcc_insert_socket(sk_atm(vcc));
  730. set_bit(ATM_VF_META, &vcc->flags);
  731. set_bit(ATM_VF_READY, &vcc->flags);
  732. if (mpc->dev) {
  733. char empty[ATM_ESA_LEN];
  734. memset(empty, 0, ATM_ESA_LEN);
  735. start_mpc(mpc, mpc->dev);
  736. /* set address if mpcd e.g. gets killed and restarted.
  737. * If we do not do it now we have to wait for the next LE_ARP
  738. */
  739. if (memcmp(mpc->mps_ctrl_addr, empty, ATM_ESA_LEN) != 0)
  740. send_set_mps_ctrl_addr(mpc->mps_ctrl_addr, mpc);
  741. }
  742. __module_get(THIS_MODULE);
  743. return arg;
  744. }
  745. static void send_set_mps_ctrl_addr(const char *addr, struct mpoa_client *mpc)
  746. {
  747. struct k_message mesg;
  748. memcpy(mpc->mps_ctrl_addr, addr, ATM_ESA_LEN);
  749. mesg.type = SET_MPS_CTRL_ADDR;
  750. memcpy(mesg.MPS_ctrl, addr, ATM_ESA_LEN);
  751. msg_to_mpoad(&mesg, mpc);
  752. return;
  753. }
  754. static void mpoad_close(struct atm_vcc *vcc)
  755. {
  756. struct mpoa_client *mpc;
  757. struct sk_buff *skb;
  758. mpc = find_mpc_by_vcc(vcc);
  759. if (mpc == NULL) {
  760. pr_info("did not find MPC\n");
  761. return;
  762. }
  763. if (!mpc->mpoad_vcc) {
  764. pr_info("close for non-present mpoad\n");
  765. return;
  766. }
  767. mpc->mpoad_vcc = NULL;
  768. if (mpc->dev) {
  769. struct lec_priv *priv = netdev_priv(mpc->dev);
  770. priv->lane2_ops->associate_indicator = NULL;
  771. stop_mpc(mpc);
  772. dev_put(mpc->dev);
  773. }
  774. mpc->in_ops->destroy_cache(mpc);
  775. mpc->eg_ops->destroy_cache(mpc);
  776. while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue))) {
  777. atm_return(vcc, skb->truesize);
  778. kfree_skb(skb);
  779. }
  780. pr_info("(%s) going down\n",
  781. (mpc->dev) ? mpc->dev->name : "<unknown>");
  782. module_put(THIS_MODULE);
  783. return;
  784. }
  785. /*
  786. *
  787. */
  788. static int msg_from_mpoad(struct atm_vcc *vcc, struct sk_buff *skb)
  789. {
  790. struct mpoa_client *mpc = find_mpc_by_vcc(vcc);
  791. struct k_message *mesg = (struct k_message *)skb->data;
  792. atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
  793. if (mpc == NULL) {
  794. pr_info("no mpc found\n");
  795. return 0;
  796. }
  797. dprintk("(%s)", mpc->dev ? mpc->dev->name : "<unknown>");
  798. switch (mesg->type) {
  799. case MPOA_RES_REPLY_RCVD:
  800. dprintk_cont("mpoa_res_reply_rcvd\n");
  801. MPOA_res_reply_rcvd(mesg, mpc);
  802. break;
  803. case MPOA_TRIGGER_RCVD:
  804. dprintk_cont("mpoa_trigger_rcvd\n");
  805. MPOA_trigger_rcvd(mesg, mpc);
  806. break;
  807. case INGRESS_PURGE_RCVD:
  808. dprintk_cont("nhrp_purge_rcvd\n");
  809. ingress_purge_rcvd(mesg, mpc);
  810. break;
  811. case EGRESS_PURGE_RCVD:
  812. dprintk_cont("egress_purge_reply_rcvd\n");
  813. egress_purge_rcvd(mesg, mpc);
  814. break;
  815. case MPS_DEATH:
  816. dprintk_cont("mps_death\n");
  817. mps_death(mesg, mpc);
  818. break;
  819. case CACHE_IMPOS_RCVD:
  820. dprintk_cont("cache_impos_rcvd\n");
  821. MPOA_cache_impos_rcvd(mesg, mpc);
  822. break;
  823. case SET_MPC_CTRL_ADDR:
  824. dprintk_cont("set_mpc_ctrl_addr\n");
  825. set_mpc_ctrl_addr_rcvd(mesg, mpc);
  826. break;
  827. case SET_MPS_MAC_ADDR:
  828. dprintk_cont("set_mps_mac_addr\n");
  829. set_mps_mac_addr_rcvd(mesg, mpc);
  830. break;
  831. case CLEAN_UP_AND_EXIT:
  832. dprintk_cont("clean_up_and_exit\n");
  833. clean_up(mesg, mpc, DIE);
  834. break;
  835. case RELOAD:
  836. dprintk_cont("reload\n");
  837. clean_up(mesg, mpc, RELOAD);
  838. break;
  839. case SET_MPC_PARAMS:
  840. dprintk_cont("set_mpc_params\n");
  841. mpc->parameters = mesg->content.params;
  842. break;
  843. default:
  844. dprintk_cont("unknown message %d\n", mesg->type);
  845. break;
  846. }
  847. kfree_skb(skb);
  848. return 0;
  849. }
  850. /* Remember that this function may not do things that sleep */
  851. int msg_to_mpoad(struct k_message *mesg, struct mpoa_client *mpc)
  852. {
  853. struct sk_buff *skb;
  854. struct sock *sk;
  855. if (mpc == NULL || !mpc->mpoad_vcc) {
  856. pr_info("mesg %d to a non-existent mpoad\n", mesg->type);
  857. return -ENXIO;
  858. }
  859. skb = alloc_skb(sizeof(struct k_message), GFP_ATOMIC);
  860. if (skb == NULL)
  861. return -ENOMEM;
  862. skb_put(skb, sizeof(struct k_message));
  863. skb_copy_to_linear_data(skb, mesg, sizeof(*mesg));
  864. atm_force_charge(mpc->mpoad_vcc, skb->truesize);
  865. sk = sk_atm(mpc->mpoad_vcc);
  866. skb_queue_tail(&sk->sk_receive_queue, skb);
  867. sk->sk_data_ready(sk, skb->len);
  868. return 0;
  869. }
  870. static int mpoa_event_listener(struct notifier_block *mpoa_notifier,
  871. unsigned long event, void *dev_ptr)
  872. {
  873. struct net_device *dev;
  874. struct mpoa_client *mpc;
  875. struct lec_priv *priv;
  876. dev = (struct net_device *)dev_ptr;
  877. if (!net_eq(dev_net(dev), &init_net))
  878. return NOTIFY_DONE;
  879. if (dev->name == NULL || strncmp(dev->name, "lec", 3))
  880. return NOTIFY_DONE; /* we are only interested in lec:s */
  881. switch (event) {
  882. case NETDEV_REGISTER: /* a new lec device was allocated */
  883. priv = netdev_priv(dev);
  884. if (priv->lane_version < 2)
  885. break;
  886. priv->lane2_ops->associate_indicator = lane2_assoc_ind;
  887. mpc = find_mpc_by_itfnum(priv->itfnum);
  888. if (mpc == NULL) {
  889. dprintk("allocating new mpc for %s\n", dev->name);
  890. mpc = alloc_mpc();
  891. if (mpc == NULL) {
  892. pr_info("no new mpc");
  893. break;
  894. }
  895. }
  896. mpc->dev_num = priv->itfnum;
  897. mpc->dev = dev;
  898. dev_hold(dev);
  899. dprintk("(%s) was initialized\n", dev->name);
  900. break;
  901. case NETDEV_UNREGISTER:
  902. /* the lec device was deallocated */
  903. mpc = find_mpc_by_lec(dev);
  904. if (mpc == NULL)
  905. break;
  906. dprintk("device (%s) was deallocated\n", dev->name);
  907. stop_mpc(mpc);
  908. dev_put(mpc->dev);
  909. mpc->dev = NULL;
  910. break;
  911. case NETDEV_UP:
  912. /* the dev was ifconfig'ed up */
  913. mpc = find_mpc_by_lec(dev);
  914. if (mpc == NULL)
  915. break;
  916. if (mpc->mpoad_vcc != NULL)
  917. start_mpc(mpc, dev);
  918. break;
  919. case NETDEV_DOWN:
  920. /* the dev was ifconfig'ed down */
  921. /* this means that the flow of packets from the
  922. * upper layer stops
  923. */
  924. mpc = find_mpc_by_lec(dev);
  925. if (mpc == NULL)
  926. break;
  927. if (mpc->mpoad_vcc != NULL)
  928. stop_mpc(mpc);
  929. break;
  930. case NETDEV_REBOOT:
  931. case NETDEV_CHANGE:
  932. case NETDEV_CHANGEMTU:
  933. case NETDEV_CHANGEADDR:
  934. case NETDEV_GOING_DOWN:
  935. break;
  936. default:
  937. break;
  938. }
  939. return NOTIFY_DONE;
  940. }
  941. /*
  942. * Functions which are called after a message is received from mpcd.
  943. * Msg is reused on purpose.
  944. */
  945. static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc)
  946. {
  947. __be32 dst_ip = msg->content.in_info.in_dst_ip;
  948. in_cache_entry *entry;
  949. entry = mpc->in_ops->get(dst_ip, mpc);
  950. if (entry == NULL) {
  951. entry = mpc->in_ops->add_entry(dst_ip, mpc);
  952. entry->entry_state = INGRESS_RESOLVING;
  953. msg->type = SND_MPOA_RES_RQST;
  954. msg->content.in_info = entry->ctrl_info;
  955. msg_to_mpoad(msg, mpc);
  956. do_gettimeofday(&(entry->reply_wait));
  957. mpc->in_ops->put(entry);
  958. return;
  959. }
  960. if (entry->entry_state == INGRESS_INVALID) {
  961. entry->entry_state = INGRESS_RESOLVING;
  962. msg->type = SND_MPOA_RES_RQST;
  963. msg->content.in_info = entry->ctrl_info;
  964. msg_to_mpoad(msg, mpc);
  965. do_gettimeofday(&(entry->reply_wait));
  966. mpc->in_ops->put(entry);
  967. return;
  968. }
  969. pr_info("(%s) entry already in resolving state\n",
  970. (mpc->dev) ? mpc->dev->name : "<unknown>");
  971. mpc->in_ops->put(entry);
  972. return;
  973. }
  974. /*
  975. * Things get complicated because we have to check if there's an egress
  976. * shortcut with suitable traffic parameters we could use.
  977. */
  978. static void check_qos_and_open_shortcut(struct k_message *msg,
  979. struct mpoa_client *client,
  980. in_cache_entry *entry)
  981. {
  982. __be32 dst_ip = msg->content.in_info.in_dst_ip;
  983. struct atm_mpoa_qos *qos = atm_mpoa_search_qos(dst_ip);
  984. eg_cache_entry *eg_entry = client->eg_ops->get_by_src_ip(dst_ip, client);
  985. if (eg_entry && eg_entry->shortcut) {
  986. if (eg_entry->shortcut->qos.txtp.traffic_class &
  987. msg->qos.txtp.traffic_class &
  988. (qos ? qos->qos.txtp.traffic_class : ATM_UBR | ATM_CBR)) {
  989. if (eg_entry->shortcut->qos.txtp.traffic_class == ATM_UBR)
  990. entry->shortcut = eg_entry->shortcut;
  991. else if (eg_entry->shortcut->qos.txtp.max_pcr > 0)
  992. entry->shortcut = eg_entry->shortcut;
  993. }
  994. if (entry->shortcut) {
  995. dprintk("(%s) using egress SVC to reach %pI4\n",
  996. client->dev->name, &dst_ip);
  997. client->eg_ops->put(eg_entry);
  998. return;
  999. }
  1000. }
  1001. if (eg_entry != NULL)
  1002. client->eg_ops->put(eg_entry);
  1003. /* No luck in the egress cache we must open an ingress SVC */
  1004. msg->type = OPEN_INGRESS_SVC;
  1005. if (qos &&
  1006. (qos->qos.txtp.traffic_class == msg->qos.txtp.traffic_class)) {
  1007. msg->qos = qos->qos;
  1008. pr_info("(%s) trying to get a CBR shortcut\n",
  1009. client->dev->name);
  1010. } else
  1011. memset(&msg->qos, 0, sizeof(struct atm_qos));
  1012. msg_to_mpoad(msg, client);
  1013. return;
  1014. }
  1015. static void MPOA_res_reply_rcvd(struct k_message *msg, struct mpoa_client *mpc)
  1016. {
  1017. __be32 dst_ip = msg->content.in_info.in_dst_ip;
  1018. in_cache_entry *entry = mpc->in_ops->get(dst_ip, mpc);
  1019. dprintk("(%s) ip %pI4\n",
  1020. mpc->dev->name, &dst_ip);
  1021. ddprintk("(%s) entry = %p",
  1022. mpc->dev->name, entry);
  1023. if (entry == NULL) {
  1024. pr_info("(%s) ARGH, received res. reply for an entry that doesn't exist.\n",
  1025. mpc->dev->name);
  1026. return;
  1027. }
  1028. ddprintk_cont(" entry_state = %d ", entry->entry_state);
  1029. if (entry->entry_state == INGRESS_RESOLVED) {
  1030. pr_info("(%s) RESOLVED entry!\n", mpc->dev->name);
  1031. mpc->in_ops->put(entry);
  1032. return;
  1033. }
  1034. entry->ctrl_info = msg->content.in_info;
  1035. do_gettimeofday(&(entry->tv));
  1036. do_gettimeofday(&(entry->reply_wait)); /* Used in refreshing func from now on */
  1037. entry->refresh_time = 0;
  1038. ddprintk_cont("entry->shortcut = %p\n", entry->shortcut);
  1039. if (entry->entry_state == INGRESS_RESOLVING &&
  1040. entry->shortcut != NULL) {
  1041. entry->entry_state = INGRESS_RESOLVED;
  1042. mpc->in_ops->put(entry);
  1043. return; /* Shortcut already open... */
  1044. }
  1045. if (entry->shortcut != NULL) {
  1046. pr_info("(%s) entry->shortcut != NULL, impossible!\n",
  1047. mpc->dev->name);
  1048. mpc->in_ops->put(entry);
  1049. return;
  1050. }
  1051. check_qos_and_open_shortcut(msg, mpc, entry);
  1052. entry->entry_state = INGRESS_RESOLVED;
  1053. mpc->in_ops->put(entry);
  1054. return;
  1055. }
  1056. static void ingress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc)
  1057. {
  1058. __be32 dst_ip = msg->content.in_info.in_dst_ip;
  1059. __be32 mask = msg->ip_mask;
  1060. in_cache_entry *entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask);
  1061. if (entry == NULL) {
  1062. pr_info("(%s) purge for a non-existing entry, ip = %pI4\n",
  1063. mpc->dev->name, &dst_ip);
  1064. return;
  1065. }
  1066. do {
  1067. dprintk("(%s) removing an ingress entry, ip = %pI4\n",
  1068. mpc->dev->name, &dst_ip);
  1069. write_lock_bh(&mpc->ingress_lock);
  1070. mpc->in_ops->remove_entry(entry, mpc);
  1071. write_unlock_bh(&mpc->ingress_lock);
  1072. mpc->in_ops->put(entry);
  1073. entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask);
  1074. } while (entry != NULL);
  1075. return;
  1076. }
  1077. static void egress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc)
  1078. {
  1079. __be32 cache_id = msg->content.eg_info.cache_id;
  1080. eg_cache_entry *entry = mpc->eg_ops->get_by_cache_id(cache_id, mpc);
  1081. if (entry == NULL) {
  1082. dprintk("(%s) purge for a non-existing entry\n",
  1083. mpc->dev->name);
  1084. return;
  1085. }
  1086. write_lock_irq(&mpc->egress_lock);
  1087. mpc->eg_ops->remove_entry(entry, mpc);
  1088. write_unlock_irq(&mpc->egress_lock);
  1089. mpc->eg_ops->put(entry);
  1090. return;
  1091. }
  1092. static void purge_egress_shortcut(struct atm_vcc *vcc, eg_cache_entry *entry)
  1093. {
  1094. struct sock *sk;
  1095. struct k_message *purge_msg;
  1096. struct sk_buff *skb;
  1097. dprintk("entering\n");
  1098. if (vcc == NULL) {
  1099. pr_info("vcc == NULL\n");
  1100. return;
  1101. }
  1102. skb = alloc_skb(sizeof(struct k_message), GFP_ATOMIC);
  1103. if (skb == NULL) {
  1104. pr_info("out of memory\n");
  1105. return;
  1106. }
  1107. skb_put(skb, sizeof(struct k_message));
  1108. memset(skb->data, 0, sizeof(struct k_message));
  1109. purge_msg = (struct k_message *)skb->data;
  1110. purge_msg->type = DATA_PLANE_PURGE;
  1111. if (entry != NULL)
  1112. purge_msg->content.eg_info = entry->ctrl_info;
  1113. atm_force_charge(vcc, skb->truesize);
  1114. sk = sk_atm(vcc);
  1115. skb_queue_tail(&sk->sk_receive_queue, skb);
  1116. sk->sk_data_ready(sk, skb->len);
  1117. dprintk("exiting\n");
  1118. return;
  1119. }
  1120. /*
  1121. * Our MPS died. Tell our daemon to send NHRP data plane purge to each
  1122. * of the egress shortcuts we have.
  1123. */
  1124. static void mps_death(struct k_message *msg, struct mpoa_client *mpc)
  1125. {
  1126. eg_cache_entry *entry;
  1127. dprintk("(%s)\n", mpc->dev->name);
  1128. if (memcmp(msg->MPS_ctrl, mpc->mps_ctrl_addr, ATM_ESA_LEN)) {
  1129. pr_info("(%s) wrong MPS\n", mpc->dev->name);
  1130. return;
  1131. }
  1132. /* FIXME: This knows too much of the cache structure */
  1133. read_lock_irq(&mpc->egress_lock);
  1134. entry = mpc->eg_cache;
  1135. while (entry != NULL) {
  1136. purge_egress_shortcut(entry->shortcut, entry);
  1137. entry = entry->next;
  1138. }
  1139. read_unlock_irq(&mpc->egress_lock);
  1140. mpc->in_ops->destroy_cache(mpc);
  1141. mpc->eg_ops->destroy_cache(mpc);
  1142. return;
  1143. }
  1144. static void MPOA_cache_impos_rcvd(struct k_message *msg,
  1145. struct mpoa_client *mpc)
  1146. {
  1147. uint16_t holding_time;
  1148. eg_cache_entry *entry = mpc->eg_ops->get_by_cache_id(msg->content.eg_info.cache_id, mpc);
  1149. holding_time = msg->content.eg_info.holding_time;
  1150. dprintk("(%s) entry = %p, holding_time = %u\n",
  1151. mpc->dev->name, entry, holding_time);
  1152. if (entry == NULL && holding_time) {
  1153. entry = mpc->eg_ops->add_entry(msg, mpc);
  1154. mpc->eg_ops->put(entry);
  1155. return;
  1156. }
  1157. if (holding_time) {
  1158. mpc->eg_ops->update(entry, holding_time);
  1159. return;
  1160. }
  1161. write_lock_irq(&mpc->egress_lock);
  1162. mpc->eg_ops->remove_entry(entry, mpc);
  1163. write_unlock_irq(&mpc->egress_lock);
  1164. mpc->eg_ops->put(entry);
  1165. return;
  1166. }
  1167. static void set_mpc_ctrl_addr_rcvd(struct k_message *mesg,
  1168. struct mpoa_client *mpc)
  1169. {
  1170. struct lec_priv *priv;
  1171. int i, retval ;
  1172. uint8_t tlv[4 + 1 + 1 + 1 + ATM_ESA_LEN];
  1173. tlv[0] = 00; tlv[1] = 0xa0; tlv[2] = 0x3e; tlv[3] = 0x2a; /* type */
  1174. tlv[4] = 1 + 1 + ATM_ESA_LEN; /* length */
  1175. tlv[5] = 0x02; /* MPOA client */
  1176. tlv[6] = 0x00; /* number of MPS MAC addresses */
  1177. memcpy(&tlv[7], mesg->MPS_ctrl, ATM_ESA_LEN); /* MPC ctrl ATM addr */
  1178. memcpy(mpc->our_ctrl_addr, mesg->MPS_ctrl, ATM_ESA_LEN);
  1179. dprintk("(%s) setting MPC ctrl ATM address to",
  1180. mpc->dev ? mpc->dev->name : "<unknown>");
  1181. for (i = 7; i < sizeof(tlv); i++)
  1182. dprintk_cont(" %02x", tlv[i]);
  1183. dprintk_cont("\n");
  1184. if (mpc->dev) {
  1185. priv = netdev_priv(mpc->dev);
  1186. retval = priv->lane2_ops->associate_req(mpc->dev,
  1187. mpc->dev->dev_addr,
  1188. tlv, sizeof(tlv));
  1189. if (retval == 0)
  1190. pr_info("(%s) MPOA device type TLV association failed\n",
  1191. mpc->dev->name);
  1192. retval = priv->lane2_ops->resolve(mpc->dev, NULL, 1, NULL, NULL);
  1193. if (retval < 0)
  1194. pr_info("(%s) targetless LE_ARP request failed\n",
  1195. mpc->dev->name);
  1196. }
  1197. return;
  1198. }
  1199. static void set_mps_mac_addr_rcvd(struct k_message *msg,
  1200. struct mpoa_client *client)
  1201. {
  1202. if (client->number_of_mps_macs)
  1203. kfree(client->mps_macs);
  1204. client->number_of_mps_macs = 0;
  1205. client->mps_macs = kmemdup(msg->MPS_ctrl, ETH_ALEN, GFP_KERNEL);
  1206. if (client->mps_macs == NULL) {
  1207. pr_info("out of memory\n");
  1208. return;
  1209. }
  1210. client->number_of_mps_macs = 1;
  1211. return;
  1212. }
  1213. /*
  1214. * purge egress cache and tell daemon to 'action' (DIE, RELOAD)
  1215. */
  1216. static void clean_up(struct k_message *msg, struct mpoa_client *mpc, int action)
  1217. {
  1218. eg_cache_entry *entry;
  1219. msg->type = SND_EGRESS_PURGE;
  1220. /* FIXME: This knows too much of the cache structure */
  1221. read_lock_irq(&mpc->egress_lock);
  1222. entry = mpc->eg_cache;
  1223. while (entry != NULL) {
  1224. msg->content.eg_info = entry->ctrl_info;
  1225. dprintk("cache_id %u\n", entry->ctrl_info.cache_id);
  1226. msg_to_mpoad(msg, mpc);
  1227. entry = entry->next;
  1228. }
  1229. read_unlock_irq(&mpc->egress_lock);
  1230. msg->type = action;
  1231. msg_to_mpoad(msg, mpc);
  1232. return;
  1233. }
  1234. static void mpc_timer_refresh(void)
  1235. {
  1236. mpc_timer.expires = jiffies + (MPC_P2 * HZ);
  1237. mpc_timer.data = mpc_timer.expires;
  1238. mpc_timer.function = mpc_cache_check;
  1239. add_timer(&mpc_timer);
  1240. return;
  1241. }
  1242. static void mpc_cache_check(unsigned long checking_time)
  1243. {
  1244. struct mpoa_client *mpc = mpcs;
  1245. static unsigned long previous_resolving_check_time;
  1246. static unsigned long previous_refresh_time;
  1247. while (mpc != NULL) {
  1248. mpc->in_ops->clear_count(mpc);
  1249. mpc->eg_ops->clear_expired(mpc);
  1250. if (checking_time - previous_resolving_check_time >
  1251. mpc->parameters.mpc_p4 * HZ) {
  1252. mpc->in_ops->check_resolving(mpc);
  1253. previous_resolving_check_time = checking_time;
  1254. }
  1255. if (checking_time - previous_refresh_time >
  1256. mpc->parameters.mpc_p5 * HZ) {
  1257. mpc->in_ops->refresh(mpc);
  1258. previous_refresh_time = checking_time;
  1259. }
  1260. mpc = mpc->next;
  1261. }
  1262. mpc_timer_refresh();
  1263. return;
  1264. }
  1265. static int atm_mpoa_ioctl(struct socket *sock, unsigned int cmd,
  1266. unsigned long arg)
  1267. {
  1268. int err = 0;
  1269. struct atm_vcc *vcc = ATM_SD(sock);
  1270. if (cmd != ATMMPC_CTRL && cmd != ATMMPC_DATA)
  1271. return -ENOIOCTLCMD;
  1272. if (!capable(CAP_NET_ADMIN))
  1273. return -EPERM;
  1274. switch (cmd) {
  1275. case ATMMPC_CTRL:
  1276. err = atm_mpoa_mpoad_attach(vcc, (int)arg);
  1277. if (err >= 0)
  1278. sock->state = SS_CONNECTED;
  1279. break;
  1280. case ATMMPC_DATA:
  1281. err = atm_mpoa_vcc_attach(vcc, (void __user *)arg);
  1282. break;
  1283. default:
  1284. break;
  1285. }
  1286. return err;
  1287. }
  1288. static struct atm_ioctl atm_ioctl_ops = {
  1289. .owner = THIS_MODULE,
  1290. .ioctl = atm_mpoa_ioctl,
  1291. };
  1292. static __init int atm_mpoa_init(void)
  1293. {
  1294. register_atm_ioctl(&atm_ioctl_ops);
  1295. if (mpc_proc_init() != 0)
  1296. pr_info("failed to initialize /proc/mpoa\n");
  1297. pr_info("mpc.c: " __DATE__ " " __TIME__ " initialized\n");
  1298. return 0;
  1299. }
  1300. static void __exit atm_mpoa_cleanup(void)
  1301. {
  1302. struct mpoa_client *mpc, *tmp;
  1303. struct atm_mpoa_qos *qos, *nextqos;
  1304. struct lec_priv *priv;
  1305. mpc_proc_clean();
  1306. del_timer(&mpc_timer);
  1307. unregister_netdevice_notifier(&mpoa_notifier);
  1308. deregister_atm_ioctl(&atm_ioctl_ops);
  1309. mpc = mpcs;
  1310. mpcs = NULL;
  1311. while (mpc != NULL) {
  1312. tmp = mpc->next;
  1313. if (mpc->dev != NULL) {
  1314. stop_mpc(mpc);
  1315. priv = netdev_priv(mpc->dev);
  1316. if (priv->lane2_ops != NULL)
  1317. priv->lane2_ops->associate_indicator = NULL;
  1318. }
  1319. ddprintk("about to clear caches\n");
  1320. mpc->in_ops->destroy_cache(mpc);
  1321. mpc->eg_ops->destroy_cache(mpc);
  1322. ddprintk("caches cleared\n");
  1323. kfree(mpc->mps_macs);
  1324. memset(mpc, 0, sizeof(struct mpoa_client));
  1325. ddprintk("about to kfree %p\n", mpc);
  1326. kfree(mpc);
  1327. ddprintk("next mpc is at %p\n", tmp);
  1328. mpc = tmp;
  1329. }
  1330. qos = qos_head;
  1331. qos_head = NULL;
  1332. while (qos != NULL) {
  1333. nextqos = qos->next;
  1334. dprintk("freeing qos entry %p\n", qos);
  1335. kfree(qos);
  1336. qos = nextqos;
  1337. }
  1338. return;
  1339. }
  1340. module_init(atm_mpoa_init);
  1341. module_exit(atm_mpoa_cleanup);
  1342. MODULE_LICENSE("GPL");