mpc.c 39 KB

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