mpc.c 39 KB

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