mpc.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534
  1. #define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
  2. #include <linux/kernel.h>
  3. #include <linux/string.h>
  4. #include <linux/slab.h>
  5. #include <linux/timer.h>
  6. #include <linux/init.h>
  7. #include <linux/bitops.h>
  8. #include <linux/capability.h>
  9. #include <linux/seq_file.h>
  10. /* We are an ethernet device */
  11. #include <linux/if_ether.h>
  12. #include <linux/netdevice.h>
  13. #include <linux/etherdevice.h>
  14. #include <net/sock.h>
  15. #include <linux/skbuff.h>
  16. #include <linux/ip.h>
  17. #include <linux/uaccess.h>
  18. #include <asm/byteorder.h>
  19. #include <net/checksum.h> /* for ip_fast_csum() */
  20. #include <net/arp.h>
  21. #include <net/dst.h>
  22. #include <linux/proc_fs.h>
  23. /* And atm device */
  24. #include <linux/atmdev.h>
  25. #include <linux/atmlec.h>
  26. #include <linux/atmmpc.h>
  27. /* Modular too */
  28. #include <linux/module.h>
  29. #include "lec.h"
  30. #include "mpc.h"
  31. #include "resources.h"
  32. /*
  33. * mpc.c: Implementation of MPOA client kernel part
  34. */
  35. #if 0
  36. #define dprintk(format, args...) \
  37. printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args)
  38. #define dprintk_cont(format, args...) printk(KERN_CONT format, ##args)
  39. #else
  40. #define dprintk(format, args...) \
  41. do { if (0) \
  42. printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args);\
  43. } while (0)
  44. #define dprintk_cont(format, args...) \
  45. do { if (0) printk(KERN_CONT format, ##args); } while (0)
  46. #endif
  47. #if 0
  48. #define ddprintk(format, args...) \
  49. printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args)
  50. #define ddprintk_cont(format, args...) printk(KERN_CONT format, ##args)
  51. #else
  52. #define ddprintk(format, args...) \
  53. do { if (0) \
  54. printk(KERN_DEBUG "mpoa:%s: " format, __func__, ##args);\
  55. } while (0)
  56. #define ddprintk_cont(format, args...) \
  57. do { if (0) printk(KERN_CONT format, ##args); } while (0)
  58. #endif
  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. }
  393. /*
  394. * Store at least advertizing router's MAC address
  395. * plus the possible MAC address(es) to mpc->mps_macs.
  396. * For a freshly allocated MPOA client mpc->mps_macs == 0.
  397. */
  398. static const uint8_t *copy_macs(struct mpoa_client *mpc,
  399. const uint8_t *router_mac,
  400. const uint8_t *tlvs, uint8_t mps_macs,
  401. uint8_t device_type)
  402. {
  403. int num_macs;
  404. num_macs = (mps_macs > 1) ? mps_macs : 1;
  405. if (mpc->number_of_mps_macs != num_macs) { /* need to reallocate? */
  406. if (mpc->number_of_mps_macs != 0)
  407. kfree(mpc->mps_macs);
  408. mpc->number_of_mps_macs = 0;
  409. mpc->mps_macs = kmalloc(num_macs * ETH_ALEN, GFP_KERNEL);
  410. if (mpc->mps_macs == NULL) {
  411. pr_info("(%s) out of mem\n", mpc->dev->name);
  412. return NULL;
  413. }
  414. }
  415. ether_addr_copy(mpc->mps_macs, router_mac);
  416. tlvs += 20; if (device_type == MPS_AND_MPC) tlvs += 20;
  417. if (mps_macs > 0)
  418. memcpy(mpc->mps_macs, tlvs, mps_macs*ETH_ALEN);
  419. tlvs += mps_macs*ETH_ALEN;
  420. mpc->number_of_mps_macs = num_macs;
  421. return tlvs;
  422. }
  423. static int send_via_shortcut(struct sk_buff *skb, struct mpoa_client *mpc)
  424. {
  425. in_cache_entry *entry;
  426. struct iphdr *iph;
  427. char *buff;
  428. __be32 ipaddr = 0;
  429. static struct {
  430. struct llc_snap_hdr hdr;
  431. __be32 tag;
  432. } tagged_llc_snap_hdr = {
  433. {0xaa, 0xaa, 0x03, {0x00, 0x00, 0x00}, {0x88, 0x4c}},
  434. 0
  435. };
  436. buff = skb->data + mpc->dev->hard_header_len;
  437. iph = (struct iphdr *)buff;
  438. ipaddr = iph->daddr;
  439. ddprintk("(%s) ipaddr 0x%x\n",
  440. mpc->dev->name, ipaddr);
  441. entry = mpc->in_ops->get(ipaddr, mpc);
  442. if (entry == NULL) {
  443. entry = mpc->in_ops->add_entry(ipaddr, mpc);
  444. if (entry != NULL)
  445. mpc->in_ops->put(entry);
  446. return 1;
  447. }
  448. /* threshold not exceeded or VCC not ready */
  449. if (mpc->in_ops->cache_hit(entry, mpc) != OPEN) {
  450. ddprintk("(%s) cache_hit: returns != OPEN\n",
  451. mpc->dev->name);
  452. mpc->in_ops->put(entry);
  453. return 1;
  454. }
  455. ddprintk("(%s) using shortcut\n",
  456. mpc->dev->name);
  457. /* MPOA spec A.1.4, MPOA client must decrement IP ttl at least by one */
  458. if (iph->ttl <= 1) {
  459. ddprintk("(%s) IP ttl = %u, using LANE\n",
  460. mpc->dev->name, iph->ttl);
  461. mpc->in_ops->put(entry);
  462. return 1;
  463. }
  464. iph->ttl--;
  465. iph->check = 0;
  466. iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
  467. if (entry->ctrl_info.tag != 0) {
  468. ddprintk("(%s) adding tag 0x%x\n",
  469. mpc->dev->name, entry->ctrl_info.tag);
  470. tagged_llc_snap_hdr.tag = entry->ctrl_info.tag;
  471. skb_pull(skb, ETH_HLEN); /* get rid of Eth header */
  472. skb_push(skb, sizeof(tagged_llc_snap_hdr));
  473. /* add LLC/SNAP header */
  474. skb_copy_to_linear_data(skb, &tagged_llc_snap_hdr,
  475. sizeof(tagged_llc_snap_hdr));
  476. } else {
  477. skb_pull(skb, ETH_HLEN); /* get rid of Eth header */
  478. skb_push(skb, sizeof(struct llc_snap_hdr));
  479. /* add LLC/SNAP header + tag */
  480. skb_copy_to_linear_data(skb, &llc_snap_mpoa_data,
  481. sizeof(struct llc_snap_hdr));
  482. }
  483. atomic_add(skb->truesize, &sk_atm(entry->shortcut)->sk_wmem_alloc);
  484. ATM_SKB(skb)->atm_options = entry->shortcut->atm_options;
  485. entry->shortcut->send(entry->shortcut, skb);
  486. entry->packets_fwded++;
  487. mpc->in_ops->put(entry);
  488. return 0;
  489. }
  490. /*
  491. * Probably needs some error checks and locking, not sure...
  492. */
  493. static netdev_tx_t mpc_send_packet(struct sk_buff *skb,
  494. struct net_device *dev)
  495. {
  496. struct mpoa_client *mpc;
  497. struct ethhdr *eth;
  498. int i = 0;
  499. mpc = find_mpc_by_lec(dev); /* this should NEVER fail */
  500. if (mpc == NULL) {
  501. pr_info("(%s) no MPC found\n", dev->name);
  502. goto non_ip;
  503. }
  504. eth = (struct ethhdr *)skb->data;
  505. if (eth->h_proto != htons(ETH_P_IP))
  506. goto non_ip; /* Multi-Protocol Over ATM :-) */
  507. /* Weed out funny packets (e.g., AF_PACKET or raw). */
  508. if (skb->len < ETH_HLEN + sizeof(struct iphdr))
  509. goto non_ip;
  510. skb_set_network_header(skb, ETH_HLEN);
  511. if (skb->len < ETH_HLEN + ip_hdr(skb)->ihl * 4 || ip_hdr(skb)->ihl < 5)
  512. goto non_ip;
  513. while (i < mpc->number_of_mps_macs) {
  514. if (ether_addr_equal(eth->h_dest, mpc->mps_macs + i * ETH_ALEN))
  515. if (send_via_shortcut(skb, mpc) == 0) /* try shortcut */
  516. return NETDEV_TX_OK;
  517. i++;
  518. }
  519. non_ip:
  520. return __netdev_start_xmit(mpc->old_ops, skb, dev, false);
  521. }
  522. static int atm_mpoa_vcc_attach(struct atm_vcc *vcc, void __user *arg)
  523. {
  524. int bytes_left;
  525. struct mpoa_client *mpc;
  526. struct atmmpc_ioc ioc_data;
  527. in_cache_entry *in_entry;
  528. __be32 ipaddr;
  529. bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmmpc_ioc));
  530. if (bytes_left != 0) {
  531. pr_info("mpoa:Short read (missed %d bytes) from userland\n",
  532. bytes_left);
  533. return -EFAULT;
  534. }
  535. ipaddr = ioc_data.ipaddr;
  536. if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF)
  537. return -EINVAL;
  538. mpc = find_mpc_by_itfnum(ioc_data.dev_num);
  539. if (mpc == NULL)
  540. return -EINVAL;
  541. if (ioc_data.type == MPC_SOCKET_INGRESS) {
  542. in_entry = mpc->in_ops->get(ipaddr, mpc);
  543. if (in_entry == NULL ||
  544. in_entry->entry_state < INGRESS_RESOLVED) {
  545. pr_info("(%s) did not find RESOLVED entry from ingress cache\n",
  546. mpc->dev->name);
  547. if (in_entry != NULL)
  548. mpc->in_ops->put(in_entry);
  549. return -EINVAL;
  550. }
  551. pr_info("(%s) attaching ingress SVC, entry = %pI4\n",
  552. mpc->dev->name, &in_entry->ctrl_info.in_dst_ip);
  553. in_entry->shortcut = vcc;
  554. mpc->in_ops->put(in_entry);
  555. } else {
  556. pr_info("(%s) attaching egress SVC\n", mpc->dev->name);
  557. }
  558. vcc->proto_data = mpc->dev;
  559. vcc->push = mpc_push;
  560. return 0;
  561. }
  562. /*
  563. *
  564. */
  565. static void mpc_vcc_close(struct atm_vcc *vcc, struct net_device *dev)
  566. {
  567. struct mpoa_client *mpc;
  568. in_cache_entry *in_entry;
  569. eg_cache_entry *eg_entry;
  570. mpc = find_mpc_by_lec(dev);
  571. if (mpc == NULL) {
  572. pr_info("(%s) close for unknown MPC\n", dev->name);
  573. return;
  574. }
  575. dprintk("(%s)\n", dev->name);
  576. in_entry = mpc->in_ops->get_by_vcc(vcc, mpc);
  577. if (in_entry) {
  578. dprintk("(%s) ingress SVC closed ip = %pI4\n",
  579. mpc->dev->name, &in_entry->ctrl_info.in_dst_ip);
  580. in_entry->shortcut = NULL;
  581. mpc->in_ops->put(in_entry);
  582. }
  583. eg_entry = mpc->eg_ops->get_by_vcc(vcc, mpc);
  584. if (eg_entry) {
  585. dprintk("(%s) egress SVC closed\n", mpc->dev->name);
  586. eg_entry->shortcut = NULL;
  587. mpc->eg_ops->put(eg_entry);
  588. }
  589. if (in_entry == NULL && eg_entry == NULL)
  590. dprintk("(%s) unused vcc closed\n", dev->name);
  591. }
  592. static void mpc_push(struct atm_vcc *vcc, struct sk_buff *skb)
  593. {
  594. struct net_device *dev = (struct net_device *)vcc->proto_data;
  595. struct sk_buff *new_skb;
  596. eg_cache_entry *eg;
  597. struct mpoa_client *mpc;
  598. __be32 tag;
  599. char *tmp;
  600. ddprintk("(%s)\n", dev->name);
  601. if (skb == NULL) {
  602. dprintk("(%s) null skb, closing VCC\n", dev->name);
  603. mpc_vcc_close(vcc, dev);
  604. return;
  605. }
  606. skb->dev = dev;
  607. if (memcmp(skb->data, &llc_snap_mpoa_ctrl,
  608. sizeof(struct llc_snap_hdr)) == 0) {
  609. struct sock *sk = sk_atm(vcc);
  610. dprintk("(%s) control packet arrived\n", dev->name);
  611. /* Pass control packets to daemon */
  612. skb_queue_tail(&sk->sk_receive_queue, skb);
  613. sk->sk_data_ready(sk);
  614. return;
  615. }
  616. /* data coming over the shortcut */
  617. atm_return(vcc, skb->truesize);
  618. mpc = find_mpc_by_lec(dev);
  619. if (mpc == NULL) {
  620. pr_info("(%s) unknown MPC\n", dev->name);
  621. return;
  622. }
  623. if (memcmp(skb->data, &llc_snap_mpoa_data_tagged,
  624. sizeof(struct llc_snap_hdr)) == 0) { /* MPOA tagged data */
  625. ddprintk("(%s) tagged data packet arrived\n", dev->name);
  626. } else if (memcmp(skb->data, &llc_snap_mpoa_data,
  627. sizeof(struct llc_snap_hdr)) == 0) { /* MPOA data */
  628. pr_info("(%s) Unsupported non-tagged data packet arrived. Purging\n",
  629. dev->name);
  630. dev_kfree_skb_any(skb);
  631. return;
  632. } else {
  633. pr_info("(%s) garbage arrived, purging\n", dev->name);
  634. dev_kfree_skb_any(skb);
  635. return;
  636. }
  637. tmp = skb->data + sizeof(struct llc_snap_hdr);
  638. tag = *(__be32 *)tmp;
  639. eg = mpc->eg_ops->get_by_tag(tag, mpc);
  640. if (eg == NULL) {
  641. pr_info("mpoa: (%s) Didn't find egress cache entry, tag = %u\n",
  642. dev->name, tag);
  643. purge_egress_shortcut(vcc, NULL);
  644. dev_kfree_skb_any(skb);
  645. return;
  646. }
  647. /*
  648. * See if ingress MPC is using shortcut we opened as a return channel.
  649. * This means we have a bi-directional vcc opened by us.
  650. */
  651. if (eg->shortcut == NULL) {
  652. eg->shortcut = vcc;
  653. pr_info("(%s) egress SVC in use\n", dev->name);
  654. }
  655. skb_pull(skb, sizeof(struct llc_snap_hdr) + sizeof(tag));
  656. /* get rid of LLC/SNAP header */
  657. new_skb = skb_realloc_headroom(skb, eg->ctrl_info.DH_length);
  658. /* LLC/SNAP is shorter than MAC header :( */
  659. dev_kfree_skb_any(skb);
  660. if (new_skb == NULL) {
  661. mpc->eg_ops->put(eg);
  662. return;
  663. }
  664. skb_push(new_skb, eg->ctrl_info.DH_length); /* add MAC header */
  665. skb_copy_to_linear_data(new_skb, eg->ctrl_info.DLL_header,
  666. eg->ctrl_info.DH_length);
  667. new_skb->protocol = eth_type_trans(new_skb, dev);
  668. skb_reset_network_header(new_skb);
  669. eg->latest_ip_addr = ip_hdr(new_skb)->saddr;
  670. eg->packets_rcvd++;
  671. mpc->eg_ops->put(eg);
  672. memset(ATM_SKB(new_skb), 0, sizeof(struct atm_skb_data));
  673. netif_rx(new_skb);
  674. }
  675. static struct atmdev_ops mpc_ops = { /* only send is required */
  676. .close = mpoad_close,
  677. .send = msg_from_mpoad
  678. };
  679. static struct atm_dev mpc_dev = {
  680. .ops = &mpc_ops,
  681. .type = "mpc",
  682. .number = 42,
  683. .lock = __SPIN_LOCK_UNLOCKED(mpc_dev.lock)
  684. /* members not explicitly initialised will be 0 */
  685. };
  686. static int atm_mpoa_mpoad_attach(struct atm_vcc *vcc, int arg)
  687. {
  688. struct mpoa_client *mpc;
  689. struct lec_priv *priv;
  690. int err;
  691. if (mpcs == NULL) {
  692. init_timer(&mpc_timer);
  693. mpc_timer_refresh();
  694. /* This lets us now how our LECs are doing */
  695. err = register_netdevice_notifier(&mpoa_notifier);
  696. if (err < 0) {
  697. del_timer(&mpc_timer);
  698. return err;
  699. }
  700. }
  701. mpc = find_mpc_by_itfnum(arg);
  702. if (mpc == NULL) {
  703. dprintk("allocating new mpc for itf %d\n", arg);
  704. mpc = alloc_mpc();
  705. if (mpc == NULL)
  706. return -ENOMEM;
  707. mpc->dev_num = arg;
  708. mpc->dev = find_lec_by_itfnum(arg);
  709. /* NULL if there was no lec */
  710. }
  711. if (mpc->mpoad_vcc) {
  712. pr_info("mpoad is already present for itf %d\n", arg);
  713. return -EADDRINUSE;
  714. }
  715. if (mpc->dev) { /* check if the lec is LANE2 capable */
  716. priv = netdev_priv(mpc->dev);
  717. if (priv->lane_version < 2) {
  718. dev_put(mpc->dev);
  719. mpc->dev = NULL;
  720. } else
  721. priv->lane2_ops->associate_indicator = lane2_assoc_ind;
  722. }
  723. mpc->mpoad_vcc = vcc;
  724. vcc->dev = &mpc_dev;
  725. vcc_insert_socket(sk_atm(vcc));
  726. set_bit(ATM_VF_META, &vcc->flags);
  727. set_bit(ATM_VF_READY, &vcc->flags);
  728. if (mpc->dev) {
  729. char empty[ATM_ESA_LEN];
  730. memset(empty, 0, ATM_ESA_LEN);
  731. start_mpc(mpc, mpc->dev);
  732. /* set address if mpcd e.g. gets killed and restarted.
  733. * If we do not do it now we have to wait for the next LE_ARP
  734. */
  735. if (memcmp(mpc->mps_ctrl_addr, empty, ATM_ESA_LEN) != 0)
  736. send_set_mps_ctrl_addr(mpc->mps_ctrl_addr, mpc);
  737. }
  738. __module_get(THIS_MODULE);
  739. return arg;
  740. }
  741. static void send_set_mps_ctrl_addr(const char *addr, struct mpoa_client *mpc)
  742. {
  743. struct k_message mesg;
  744. memcpy(mpc->mps_ctrl_addr, addr, ATM_ESA_LEN);
  745. mesg.type = SET_MPS_CTRL_ADDR;
  746. memcpy(mesg.MPS_ctrl, addr, ATM_ESA_LEN);
  747. msg_to_mpoad(&mesg, mpc);
  748. }
  749. static void mpoad_close(struct atm_vcc *vcc)
  750. {
  751. struct mpoa_client *mpc;
  752. struct sk_buff *skb;
  753. mpc = find_mpc_by_vcc(vcc);
  754. if (mpc == NULL) {
  755. pr_info("did not find MPC\n");
  756. return;
  757. }
  758. if (!mpc->mpoad_vcc) {
  759. pr_info("close for non-present mpoad\n");
  760. return;
  761. }
  762. mpc->mpoad_vcc = NULL;
  763. if (mpc->dev) {
  764. struct lec_priv *priv = netdev_priv(mpc->dev);
  765. priv->lane2_ops->associate_indicator = NULL;
  766. stop_mpc(mpc);
  767. dev_put(mpc->dev);
  768. }
  769. mpc->in_ops->destroy_cache(mpc);
  770. mpc->eg_ops->destroy_cache(mpc);
  771. while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue))) {
  772. atm_return(vcc, skb->truesize);
  773. kfree_skb(skb);
  774. }
  775. pr_info("(%s) going down\n",
  776. (mpc->dev) ? mpc->dev->name : "<unknown>");
  777. module_put(THIS_MODULE);
  778. }
  779. /*
  780. *
  781. */
  782. static int msg_from_mpoad(struct atm_vcc *vcc, struct sk_buff *skb)
  783. {
  784. struct mpoa_client *mpc = find_mpc_by_vcc(vcc);
  785. struct k_message *mesg = (struct k_message *)skb->data;
  786. atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
  787. if (mpc == NULL) {
  788. pr_info("no mpc found\n");
  789. return 0;
  790. }
  791. dprintk("(%s)", mpc->dev ? mpc->dev->name : "<unknown>");
  792. switch (mesg->type) {
  793. case MPOA_RES_REPLY_RCVD:
  794. dprintk_cont("mpoa_res_reply_rcvd\n");
  795. MPOA_res_reply_rcvd(mesg, mpc);
  796. break;
  797. case MPOA_TRIGGER_RCVD:
  798. dprintk_cont("mpoa_trigger_rcvd\n");
  799. MPOA_trigger_rcvd(mesg, mpc);
  800. break;
  801. case INGRESS_PURGE_RCVD:
  802. dprintk_cont("nhrp_purge_rcvd\n");
  803. ingress_purge_rcvd(mesg, mpc);
  804. break;
  805. case EGRESS_PURGE_RCVD:
  806. dprintk_cont("egress_purge_reply_rcvd\n");
  807. egress_purge_rcvd(mesg, mpc);
  808. break;
  809. case MPS_DEATH:
  810. dprintk_cont("mps_death\n");
  811. mps_death(mesg, mpc);
  812. break;
  813. case CACHE_IMPOS_RCVD:
  814. dprintk_cont("cache_impos_rcvd\n");
  815. MPOA_cache_impos_rcvd(mesg, mpc);
  816. break;
  817. case SET_MPC_CTRL_ADDR:
  818. dprintk_cont("set_mpc_ctrl_addr\n");
  819. set_mpc_ctrl_addr_rcvd(mesg, mpc);
  820. break;
  821. case SET_MPS_MAC_ADDR:
  822. dprintk_cont("set_mps_mac_addr\n");
  823. set_mps_mac_addr_rcvd(mesg, mpc);
  824. break;
  825. case CLEAN_UP_AND_EXIT:
  826. dprintk_cont("clean_up_and_exit\n");
  827. clean_up(mesg, mpc, DIE);
  828. break;
  829. case RELOAD:
  830. dprintk_cont("reload\n");
  831. clean_up(mesg, mpc, RELOAD);
  832. break;
  833. case SET_MPC_PARAMS:
  834. dprintk_cont("set_mpc_params\n");
  835. mpc->parameters = mesg->content.params;
  836. break;
  837. default:
  838. dprintk_cont("unknown message %d\n", mesg->type);
  839. break;
  840. }
  841. kfree_skb(skb);
  842. return 0;
  843. }
  844. /* Remember that this function may not do things that sleep */
  845. int msg_to_mpoad(struct k_message *mesg, struct mpoa_client *mpc)
  846. {
  847. struct sk_buff *skb;
  848. struct sock *sk;
  849. if (mpc == NULL || !mpc->mpoad_vcc) {
  850. pr_info("mesg %d to a non-existent mpoad\n", mesg->type);
  851. return -ENXIO;
  852. }
  853. skb = alloc_skb(sizeof(struct k_message), GFP_ATOMIC);
  854. if (skb == NULL)
  855. return -ENOMEM;
  856. skb_put(skb, sizeof(struct k_message));
  857. skb_copy_to_linear_data(skb, mesg, sizeof(*mesg));
  858. atm_force_charge(mpc->mpoad_vcc, skb->truesize);
  859. sk = sk_atm(mpc->mpoad_vcc);
  860. skb_queue_tail(&sk->sk_receive_queue, skb);
  861. sk->sk_data_ready(sk);
  862. return 0;
  863. }
  864. static int mpoa_event_listener(struct notifier_block *mpoa_notifier,
  865. unsigned long event, void *ptr)
  866. {
  867. struct net_device *dev = netdev_notifier_info_to_dev(ptr);
  868. struct mpoa_client *mpc;
  869. struct lec_priv *priv;
  870. if (!net_eq(dev_net(dev), &init_net))
  871. return NOTIFY_DONE;
  872. if (dev->name == NULL || strncmp(dev->name, "lec", 3))
  873. return NOTIFY_DONE; /* we are only interested in lec:s */
  874. switch (event) {
  875. case NETDEV_REGISTER: /* a new lec device was allocated */
  876. priv = netdev_priv(dev);
  877. if (priv->lane_version < 2)
  878. break;
  879. priv->lane2_ops->associate_indicator = lane2_assoc_ind;
  880. mpc = find_mpc_by_itfnum(priv->itfnum);
  881. if (mpc == NULL) {
  882. dprintk("allocating new mpc for %s\n", dev->name);
  883. mpc = alloc_mpc();
  884. if (mpc == NULL) {
  885. pr_info("no new mpc");
  886. break;
  887. }
  888. }
  889. mpc->dev_num = priv->itfnum;
  890. mpc->dev = dev;
  891. dev_hold(dev);
  892. dprintk("(%s) was initialized\n", dev->name);
  893. break;
  894. case NETDEV_UNREGISTER:
  895. /* the lec device was deallocated */
  896. mpc = find_mpc_by_lec(dev);
  897. if (mpc == NULL)
  898. break;
  899. dprintk("device (%s) was deallocated\n", dev->name);
  900. stop_mpc(mpc);
  901. dev_put(mpc->dev);
  902. mpc->dev = NULL;
  903. break;
  904. case NETDEV_UP:
  905. /* the dev was ifconfig'ed up */
  906. mpc = find_mpc_by_lec(dev);
  907. if (mpc == NULL)
  908. break;
  909. if (mpc->mpoad_vcc != NULL)
  910. start_mpc(mpc, dev);
  911. break;
  912. case NETDEV_DOWN:
  913. /* the dev was ifconfig'ed down */
  914. /* this means that the flow of packets from the
  915. * upper layer stops
  916. */
  917. mpc = find_mpc_by_lec(dev);
  918. if (mpc == NULL)
  919. break;
  920. if (mpc->mpoad_vcc != NULL)
  921. stop_mpc(mpc);
  922. break;
  923. case NETDEV_REBOOT:
  924. case NETDEV_CHANGE:
  925. case NETDEV_CHANGEMTU:
  926. case NETDEV_CHANGEADDR:
  927. case NETDEV_GOING_DOWN:
  928. break;
  929. default:
  930. break;
  931. }
  932. return NOTIFY_DONE;
  933. }
  934. /*
  935. * Functions which are called after a message is received from mpcd.
  936. * Msg is reused on purpose.
  937. */
  938. static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc)
  939. {
  940. __be32 dst_ip = msg->content.in_info.in_dst_ip;
  941. in_cache_entry *entry;
  942. entry = mpc->in_ops->get(dst_ip, mpc);
  943. if (entry == NULL) {
  944. entry = mpc->in_ops->add_entry(dst_ip, mpc);
  945. entry->entry_state = INGRESS_RESOLVING;
  946. msg->type = SND_MPOA_RES_RQST;
  947. msg->content.in_info = entry->ctrl_info;
  948. msg_to_mpoad(msg, mpc);
  949. do_gettimeofday(&(entry->reply_wait));
  950. mpc->in_ops->put(entry);
  951. return;
  952. }
  953. if (entry->entry_state == INGRESS_INVALID) {
  954. entry->entry_state = INGRESS_RESOLVING;
  955. msg->type = SND_MPOA_RES_RQST;
  956. msg->content.in_info = entry->ctrl_info;
  957. msg_to_mpoad(msg, mpc);
  958. do_gettimeofday(&(entry->reply_wait));
  959. mpc->in_ops->put(entry);
  960. return;
  961. }
  962. pr_info("(%s) entry already in resolving state\n",
  963. (mpc->dev) ? mpc->dev->name : "<unknown>");
  964. mpc->in_ops->put(entry);
  965. }
  966. /*
  967. * Things get complicated because we have to check if there's an egress
  968. * shortcut with suitable traffic parameters we could use.
  969. */
  970. static void check_qos_and_open_shortcut(struct k_message *msg,
  971. struct mpoa_client *client,
  972. in_cache_entry *entry)
  973. {
  974. __be32 dst_ip = msg->content.in_info.in_dst_ip;
  975. struct atm_mpoa_qos *qos = atm_mpoa_search_qos(dst_ip);
  976. eg_cache_entry *eg_entry = client->eg_ops->get_by_src_ip(dst_ip, client);
  977. if (eg_entry && eg_entry->shortcut) {
  978. if (eg_entry->shortcut->qos.txtp.traffic_class &
  979. msg->qos.txtp.traffic_class &
  980. (qos ? qos->qos.txtp.traffic_class : ATM_UBR | ATM_CBR)) {
  981. if (eg_entry->shortcut->qos.txtp.traffic_class == ATM_UBR)
  982. entry->shortcut = eg_entry->shortcut;
  983. else if (eg_entry->shortcut->qos.txtp.max_pcr > 0)
  984. entry->shortcut = eg_entry->shortcut;
  985. }
  986. if (entry->shortcut) {
  987. dprintk("(%s) using egress SVC to reach %pI4\n",
  988. client->dev->name, &dst_ip);
  989. client->eg_ops->put(eg_entry);
  990. return;
  991. }
  992. }
  993. if (eg_entry != NULL)
  994. client->eg_ops->put(eg_entry);
  995. /* No luck in the egress cache we must open an ingress SVC */
  996. msg->type = OPEN_INGRESS_SVC;
  997. if (qos &&
  998. (qos->qos.txtp.traffic_class == msg->qos.txtp.traffic_class)) {
  999. msg->qos = qos->qos;
  1000. pr_info("(%s) trying to get a CBR shortcut\n",
  1001. client->dev->name);
  1002. } else
  1003. memset(&msg->qos, 0, sizeof(struct atm_qos));
  1004. msg_to_mpoad(msg, client);
  1005. }
  1006. static void MPOA_res_reply_rcvd(struct k_message *msg, struct mpoa_client *mpc)
  1007. {
  1008. __be32 dst_ip = msg->content.in_info.in_dst_ip;
  1009. in_cache_entry *entry = mpc->in_ops->get(dst_ip, mpc);
  1010. dprintk("(%s) ip %pI4\n",
  1011. mpc->dev->name, &dst_ip);
  1012. ddprintk("(%s) entry = %p",
  1013. mpc->dev->name, entry);
  1014. if (entry == NULL) {
  1015. pr_info("(%s) ARGH, received res. reply for an entry that doesn't exist.\n",
  1016. mpc->dev->name);
  1017. return;
  1018. }
  1019. ddprintk_cont(" entry_state = %d ", entry->entry_state);
  1020. if (entry->entry_state == INGRESS_RESOLVED) {
  1021. pr_info("(%s) RESOLVED entry!\n", mpc->dev->name);
  1022. mpc->in_ops->put(entry);
  1023. return;
  1024. }
  1025. entry->ctrl_info = msg->content.in_info;
  1026. do_gettimeofday(&(entry->tv));
  1027. do_gettimeofday(&(entry->reply_wait)); /* Used in refreshing func from now on */
  1028. entry->refresh_time = 0;
  1029. ddprintk_cont("entry->shortcut = %p\n", entry->shortcut);
  1030. if (entry->entry_state == INGRESS_RESOLVING &&
  1031. entry->shortcut != NULL) {
  1032. entry->entry_state = INGRESS_RESOLVED;
  1033. mpc->in_ops->put(entry);
  1034. return; /* Shortcut already open... */
  1035. }
  1036. if (entry->shortcut != NULL) {
  1037. pr_info("(%s) entry->shortcut != NULL, impossible!\n",
  1038. mpc->dev->name);
  1039. mpc->in_ops->put(entry);
  1040. return;
  1041. }
  1042. check_qos_and_open_shortcut(msg, mpc, entry);
  1043. entry->entry_state = INGRESS_RESOLVED;
  1044. mpc->in_ops->put(entry);
  1045. return;
  1046. }
  1047. static void ingress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc)
  1048. {
  1049. __be32 dst_ip = msg->content.in_info.in_dst_ip;
  1050. __be32 mask = msg->ip_mask;
  1051. in_cache_entry *entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask);
  1052. if (entry == NULL) {
  1053. pr_info("(%s) purge for a non-existing entry, ip = %pI4\n",
  1054. mpc->dev->name, &dst_ip);
  1055. return;
  1056. }
  1057. do {
  1058. dprintk("(%s) removing an ingress entry, ip = %pI4\n",
  1059. mpc->dev->name, &dst_ip);
  1060. write_lock_bh(&mpc->ingress_lock);
  1061. mpc->in_ops->remove_entry(entry, mpc);
  1062. write_unlock_bh(&mpc->ingress_lock);
  1063. mpc->in_ops->put(entry);
  1064. entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask);
  1065. } while (entry != NULL);
  1066. }
  1067. static void egress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc)
  1068. {
  1069. __be32 cache_id = msg->content.eg_info.cache_id;
  1070. eg_cache_entry *entry = mpc->eg_ops->get_by_cache_id(cache_id, mpc);
  1071. if (entry == NULL) {
  1072. dprintk("(%s) purge for a non-existing entry\n",
  1073. mpc->dev->name);
  1074. return;
  1075. }
  1076. write_lock_irq(&mpc->egress_lock);
  1077. mpc->eg_ops->remove_entry(entry, mpc);
  1078. write_unlock_irq(&mpc->egress_lock);
  1079. mpc->eg_ops->put(entry);
  1080. }
  1081. static void purge_egress_shortcut(struct atm_vcc *vcc, eg_cache_entry *entry)
  1082. {
  1083. struct sock *sk;
  1084. struct k_message *purge_msg;
  1085. struct sk_buff *skb;
  1086. dprintk("entering\n");
  1087. if (vcc == NULL) {
  1088. pr_info("vcc == NULL\n");
  1089. return;
  1090. }
  1091. skb = alloc_skb(sizeof(struct k_message), GFP_ATOMIC);
  1092. if (skb == NULL) {
  1093. pr_info("out of memory\n");
  1094. return;
  1095. }
  1096. skb_put(skb, sizeof(struct k_message));
  1097. memset(skb->data, 0, sizeof(struct k_message));
  1098. purge_msg = (struct k_message *)skb->data;
  1099. purge_msg->type = DATA_PLANE_PURGE;
  1100. if (entry != NULL)
  1101. purge_msg->content.eg_info = entry->ctrl_info;
  1102. atm_force_charge(vcc, skb->truesize);
  1103. sk = sk_atm(vcc);
  1104. skb_queue_tail(&sk->sk_receive_queue, skb);
  1105. sk->sk_data_ready(sk);
  1106. dprintk("exiting\n");
  1107. }
  1108. /*
  1109. * Our MPS died. Tell our daemon to send NHRP data plane purge to each
  1110. * of the egress shortcuts we have.
  1111. */
  1112. static void mps_death(struct k_message *msg, struct mpoa_client *mpc)
  1113. {
  1114. eg_cache_entry *entry;
  1115. dprintk("(%s)\n", mpc->dev->name);
  1116. if (memcmp(msg->MPS_ctrl, mpc->mps_ctrl_addr, ATM_ESA_LEN)) {
  1117. pr_info("(%s) wrong MPS\n", mpc->dev->name);
  1118. return;
  1119. }
  1120. /* FIXME: This knows too much of the cache structure */
  1121. read_lock_irq(&mpc->egress_lock);
  1122. entry = mpc->eg_cache;
  1123. while (entry != NULL) {
  1124. purge_egress_shortcut(entry->shortcut, entry);
  1125. entry = entry->next;
  1126. }
  1127. read_unlock_irq(&mpc->egress_lock);
  1128. mpc->in_ops->destroy_cache(mpc);
  1129. mpc->eg_ops->destroy_cache(mpc);
  1130. }
  1131. static void MPOA_cache_impos_rcvd(struct k_message *msg,
  1132. struct mpoa_client *mpc)
  1133. {
  1134. uint16_t holding_time;
  1135. eg_cache_entry *entry = mpc->eg_ops->get_by_cache_id(msg->content.eg_info.cache_id, mpc);
  1136. holding_time = msg->content.eg_info.holding_time;
  1137. dprintk("(%s) entry = %p, holding_time = %u\n",
  1138. mpc->dev->name, entry, holding_time);
  1139. if (entry == NULL && holding_time) {
  1140. entry = mpc->eg_ops->add_entry(msg, mpc);
  1141. mpc->eg_ops->put(entry);
  1142. return;
  1143. }
  1144. if (holding_time) {
  1145. mpc->eg_ops->update(entry, holding_time);
  1146. return;
  1147. }
  1148. write_lock_irq(&mpc->egress_lock);
  1149. mpc->eg_ops->remove_entry(entry, mpc);
  1150. write_unlock_irq(&mpc->egress_lock);
  1151. mpc->eg_ops->put(entry);
  1152. }
  1153. static void set_mpc_ctrl_addr_rcvd(struct k_message *mesg,
  1154. struct mpoa_client *mpc)
  1155. {
  1156. struct lec_priv *priv;
  1157. int i, retval ;
  1158. uint8_t tlv[4 + 1 + 1 + 1 + ATM_ESA_LEN];
  1159. tlv[0] = 00; tlv[1] = 0xa0; tlv[2] = 0x3e; tlv[3] = 0x2a; /* type */
  1160. tlv[4] = 1 + 1 + ATM_ESA_LEN; /* length */
  1161. tlv[5] = 0x02; /* MPOA client */
  1162. tlv[6] = 0x00; /* number of MPS MAC addresses */
  1163. memcpy(&tlv[7], mesg->MPS_ctrl, ATM_ESA_LEN); /* MPC ctrl ATM addr */
  1164. memcpy(mpc->our_ctrl_addr, mesg->MPS_ctrl, ATM_ESA_LEN);
  1165. dprintk("(%s) setting MPC ctrl ATM address to",
  1166. mpc->dev ? mpc->dev->name : "<unknown>");
  1167. for (i = 7; i < sizeof(tlv); i++)
  1168. dprintk_cont(" %02x", tlv[i]);
  1169. dprintk_cont("\n");
  1170. if (mpc->dev) {
  1171. priv = netdev_priv(mpc->dev);
  1172. retval = priv->lane2_ops->associate_req(mpc->dev,
  1173. mpc->dev->dev_addr,
  1174. tlv, sizeof(tlv));
  1175. if (retval == 0)
  1176. pr_info("(%s) MPOA device type TLV association failed\n",
  1177. mpc->dev->name);
  1178. retval = priv->lane2_ops->resolve(mpc->dev, NULL, 1, NULL, NULL);
  1179. if (retval < 0)
  1180. pr_info("(%s) targetless LE_ARP request failed\n",
  1181. mpc->dev->name);
  1182. }
  1183. }
  1184. static void set_mps_mac_addr_rcvd(struct k_message *msg,
  1185. struct mpoa_client *client)
  1186. {
  1187. if (client->number_of_mps_macs)
  1188. kfree(client->mps_macs);
  1189. client->number_of_mps_macs = 0;
  1190. client->mps_macs = kmemdup(msg->MPS_ctrl, ETH_ALEN, GFP_KERNEL);
  1191. if (client->mps_macs == NULL) {
  1192. pr_info("out of memory\n");
  1193. return;
  1194. }
  1195. client->number_of_mps_macs = 1;
  1196. }
  1197. /*
  1198. * purge egress cache and tell daemon to 'action' (DIE, RELOAD)
  1199. */
  1200. static void clean_up(struct k_message *msg, struct mpoa_client *mpc, int action)
  1201. {
  1202. eg_cache_entry *entry;
  1203. msg->type = SND_EGRESS_PURGE;
  1204. /* FIXME: This knows too much of the cache structure */
  1205. read_lock_irq(&mpc->egress_lock);
  1206. entry = mpc->eg_cache;
  1207. while (entry != NULL) {
  1208. msg->content.eg_info = entry->ctrl_info;
  1209. dprintk("cache_id %u\n", entry->ctrl_info.cache_id);
  1210. msg_to_mpoad(msg, mpc);
  1211. entry = entry->next;
  1212. }
  1213. read_unlock_irq(&mpc->egress_lock);
  1214. msg->type = action;
  1215. msg_to_mpoad(msg, mpc);
  1216. }
  1217. static void mpc_timer_refresh(void)
  1218. {
  1219. mpc_timer.expires = jiffies + (MPC_P2 * HZ);
  1220. mpc_timer.data = mpc_timer.expires;
  1221. mpc_timer.function = mpc_cache_check;
  1222. add_timer(&mpc_timer);
  1223. }
  1224. static void mpc_cache_check(unsigned long checking_time)
  1225. {
  1226. struct mpoa_client *mpc = mpcs;
  1227. static unsigned long previous_resolving_check_time;
  1228. static unsigned long previous_refresh_time;
  1229. while (mpc != NULL) {
  1230. mpc->in_ops->clear_count(mpc);
  1231. mpc->eg_ops->clear_expired(mpc);
  1232. if (checking_time - previous_resolving_check_time >
  1233. mpc->parameters.mpc_p4 * HZ) {
  1234. mpc->in_ops->check_resolving(mpc);
  1235. previous_resolving_check_time = checking_time;
  1236. }
  1237. if (checking_time - previous_refresh_time >
  1238. mpc->parameters.mpc_p5 * HZ) {
  1239. mpc->in_ops->refresh(mpc);
  1240. previous_refresh_time = checking_time;
  1241. }
  1242. mpc = mpc->next;
  1243. }
  1244. mpc_timer_refresh();
  1245. }
  1246. static int atm_mpoa_ioctl(struct socket *sock, unsigned int cmd,
  1247. unsigned long arg)
  1248. {
  1249. int err = 0;
  1250. struct atm_vcc *vcc = ATM_SD(sock);
  1251. if (cmd != ATMMPC_CTRL && cmd != ATMMPC_DATA)
  1252. return -ENOIOCTLCMD;
  1253. if (!capable(CAP_NET_ADMIN))
  1254. return -EPERM;
  1255. switch (cmd) {
  1256. case ATMMPC_CTRL:
  1257. err = atm_mpoa_mpoad_attach(vcc, (int)arg);
  1258. if (err >= 0)
  1259. sock->state = SS_CONNECTED;
  1260. break;
  1261. case ATMMPC_DATA:
  1262. err = atm_mpoa_vcc_attach(vcc, (void __user *)arg);
  1263. break;
  1264. default:
  1265. break;
  1266. }
  1267. return err;
  1268. }
  1269. static struct atm_ioctl atm_ioctl_ops = {
  1270. .owner = THIS_MODULE,
  1271. .ioctl = atm_mpoa_ioctl,
  1272. };
  1273. static __init int atm_mpoa_init(void)
  1274. {
  1275. register_atm_ioctl(&atm_ioctl_ops);
  1276. if (mpc_proc_init() != 0)
  1277. pr_info("failed to initialize /proc/mpoa\n");
  1278. pr_info("mpc.c: initialized\n");
  1279. return 0;
  1280. }
  1281. static void __exit atm_mpoa_cleanup(void)
  1282. {
  1283. struct mpoa_client *mpc, *tmp;
  1284. struct atm_mpoa_qos *qos, *nextqos;
  1285. struct lec_priv *priv;
  1286. mpc_proc_clean();
  1287. del_timer_sync(&mpc_timer);
  1288. unregister_netdevice_notifier(&mpoa_notifier);
  1289. deregister_atm_ioctl(&atm_ioctl_ops);
  1290. mpc = mpcs;
  1291. mpcs = NULL;
  1292. while (mpc != NULL) {
  1293. tmp = mpc->next;
  1294. if (mpc->dev != NULL) {
  1295. stop_mpc(mpc);
  1296. priv = netdev_priv(mpc->dev);
  1297. if (priv->lane2_ops != NULL)
  1298. priv->lane2_ops->associate_indicator = NULL;
  1299. }
  1300. ddprintk("about to clear caches\n");
  1301. mpc->in_ops->destroy_cache(mpc);
  1302. mpc->eg_ops->destroy_cache(mpc);
  1303. ddprintk("caches cleared\n");
  1304. kfree(mpc->mps_macs);
  1305. memset(mpc, 0, sizeof(struct mpoa_client));
  1306. ddprintk("about to kfree %p\n", mpc);
  1307. kfree(mpc);
  1308. ddprintk("next mpc is at %p\n", tmp);
  1309. mpc = tmp;
  1310. }
  1311. qos = qos_head;
  1312. qos_head = NULL;
  1313. while (qos != NULL) {
  1314. nextqos = qos->next;
  1315. dprintk("freeing qos entry %p\n", qos);
  1316. kfree(qos);
  1317. qos = nextqos;
  1318. }
  1319. }
  1320. module_init(atm_mpoa_init);
  1321. module_exit(atm_mpoa_cleanup);
  1322. MODULE_LICENSE("GPL");