mpc.c 40 KB

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