mpc.c 39 KB

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