mpc.c 40 KB

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