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