mpc.c 39 KB

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