mpc.c 38 KB

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