mpc.c 39 KB

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