mpc.c 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494
  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(uint32_t 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(uint32_t 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. uint32_t ipaddr = 0;
  392. static struct {
  393. struct llc_snap_hdr hdr;
  394. uint32_t 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. memcpy(skb->data, &tagged_llc_snap_hdr, sizeof(tagged_llc_snap_hdr));
  430. } else {
  431. skb_pull(skb, ETH_HLEN); /* get rid of Eth header */
  432. skb_push(skb, sizeof(struct llc_snap_hdr)); /* add LLC/SNAP header + tag */
  433. memcpy(skb->data, &llc_snap_mpoa_data, sizeof(struct llc_snap_hdr));
  434. }
  435. atomic_add(skb->truesize, &sk_atm(entry->shortcut)->sk_wmem_alloc);
  436. ATM_SKB(skb)->atm_options = entry->shortcut->atm_options;
  437. entry->shortcut->send(entry->shortcut, skb);
  438. entry->packets_fwded++;
  439. mpc->in_ops->put(entry);
  440. return 0;
  441. }
  442. /*
  443. * Probably needs some error checks and locking, not sure...
  444. */
  445. static int mpc_send_packet(struct sk_buff *skb, struct net_device *dev)
  446. {
  447. int retval;
  448. struct mpoa_client *mpc;
  449. struct ethhdr *eth;
  450. int i = 0;
  451. mpc = find_mpc_by_lec(dev); /* this should NEVER fail */
  452. if(mpc == NULL) {
  453. printk("mpoa: (%s) mpc_send_packet: no MPC found\n", dev->name);
  454. goto non_ip;
  455. }
  456. eth = (struct ethhdr *)skb->data;
  457. if (eth->h_proto != htons(ETH_P_IP))
  458. goto non_ip; /* Multi-Protocol Over ATM :-) */
  459. while (i < mpc->number_of_mps_macs) {
  460. if (!compare_ether_addr(eth->h_dest, (mpc->mps_macs + i*ETH_ALEN)))
  461. if ( send_via_shortcut(skb, mpc) == 0 ) /* try shortcut */
  462. return 0; /* success! */
  463. i++;
  464. }
  465. non_ip:
  466. retval = mpc->old_hard_start_xmit(skb,dev);
  467. return retval;
  468. }
  469. static int atm_mpoa_vcc_attach(struct atm_vcc *vcc, void __user *arg)
  470. {
  471. int bytes_left;
  472. struct mpoa_client *mpc;
  473. struct atmmpc_ioc ioc_data;
  474. in_cache_entry *in_entry;
  475. uint32_t ipaddr;
  476. unsigned char *ip;
  477. bytes_left = copy_from_user(&ioc_data, arg, sizeof(struct atmmpc_ioc));
  478. if (bytes_left != 0) {
  479. printk("mpoa: mpc_vcc_attach: Short read (missed %d bytes) from userland\n", bytes_left);
  480. return -EFAULT;
  481. }
  482. ipaddr = ioc_data.ipaddr;
  483. if (ioc_data.dev_num < 0 || ioc_data.dev_num >= MAX_LEC_ITF)
  484. return -EINVAL;
  485. mpc = find_mpc_by_itfnum(ioc_data.dev_num);
  486. if (mpc == NULL)
  487. return -EINVAL;
  488. if (ioc_data.type == MPC_SOCKET_INGRESS) {
  489. in_entry = mpc->in_ops->get(ipaddr, mpc);
  490. if (in_entry == NULL || in_entry->entry_state < INGRESS_RESOLVED) {
  491. printk("mpoa: (%s) mpc_vcc_attach: did not find RESOLVED entry from ingress cache\n",
  492. mpc->dev->name);
  493. if (in_entry != NULL) mpc->in_ops->put(in_entry);
  494. return -EINVAL;
  495. }
  496. ip = (unsigned char*)&in_entry->ctrl_info.in_dst_ip;
  497. printk("mpoa: (%s) mpc_vcc_attach: attaching ingress SVC, entry = %u.%u.%u.%u\n",
  498. mpc->dev->name, ip[0], ip[1], ip[2], ip[3]);
  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. unsigned char *ip __attribute__ ((unused)) =
  525. (unsigned char *)&in_entry->ctrl_info.in_dst_ip;
  526. dprintk("mpoa: (%s) mpc_vcc_close: ingress SVC closed ip = %u.%u.%u.%u\n",
  527. mpc->dev->name, ip[0], ip[1], ip[2], ip[3]);
  528. in_entry->shortcut = NULL;
  529. mpc->in_ops->put(in_entry);
  530. }
  531. eg_entry = mpc->eg_ops->get_by_vcc(vcc, mpc);
  532. if (eg_entry) {
  533. dprintk("mpoa: (%s) mpc_vcc_close: egress SVC closed\n", mpc->dev->name);
  534. eg_entry->shortcut = NULL;
  535. mpc->eg_ops->put(eg_entry);
  536. }
  537. if (in_entry == NULL && eg_entry == NULL)
  538. dprintk("mpoa: (%s) mpc_vcc_close: unused vcc closed\n", dev->name);
  539. return;
  540. }
  541. static void mpc_push(struct atm_vcc *vcc, struct sk_buff *skb)
  542. {
  543. struct net_device *dev = (struct net_device *)vcc->proto_data;
  544. struct sk_buff *new_skb;
  545. eg_cache_entry *eg;
  546. struct mpoa_client *mpc;
  547. uint32_t tag;
  548. char *tmp;
  549. ddprintk("mpoa: (%s) mpc_push:\n", dev->name);
  550. if (skb == NULL) {
  551. dprintk("mpoa: (%s) mpc_push: null skb, closing VCC\n", dev->name);
  552. mpc_vcc_close(vcc, dev);
  553. return;
  554. }
  555. skb->dev = dev;
  556. if (memcmp(skb->data, &llc_snap_mpoa_ctrl, sizeof(struct llc_snap_hdr)) == 0) {
  557. struct sock *sk = sk_atm(vcc);
  558. dprintk("mpoa: (%s) mpc_push: control packet arrived\n", dev->name);
  559. /* Pass control packets to daemon */
  560. skb_queue_tail(&sk->sk_receive_queue, skb);
  561. sk->sk_data_ready(sk, skb->len);
  562. return;
  563. }
  564. /* data coming over the shortcut */
  565. atm_return(vcc, skb->truesize);
  566. mpc = find_mpc_by_lec(dev);
  567. if (mpc == NULL) {
  568. printk("mpoa: (%s) mpc_push: unknown MPC\n", dev->name);
  569. return;
  570. }
  571. if (memcmp(skb->data, &llc_snap_mpoa_data_tagged, sizeof(struct llc_snap_hdr)) == 0) { /* MPOA tagged data */
  572. ddprintk("mpoa: (%s) mpc_push: tagged data packet arrived\n", dev->name);
  573. } else if (memcmp(skb->data, &llc_snap_mpoa_data, sizeof(struct llc_snap_hdr)) == 0) { /* MPOA data */
  574. printk("mpoa: (%s) mpc_push: non-tagged data packet arrived\n", dev->name);
  575. printk(" mpc_push: non-tagged data unsupported, purging\n");
  576. dev_kfree_skb_any(skb);
  577. return;
  578. } else {
  579. printk("mpoa: (%s) mpc_push: garbage arrived, purging\n", dev->name);
  580. dev_kfree_skb_any(skb);
  581. return;
  582. }
  583. tmp = skb->data + sizeof(struct llc_snap_hdr);
  584. tag = *(uint32_t *)tmp;
  585. eg = mpc->eg_ops->get_by_tag(tag, mpc);
  586. if (eg == NULL) {
  587. printk("mpoa: (%s) mpc_push: Didn't find egress cache entry, tag = %u\n",
  588. dev->name,tag);
  589. purge_egress_shortcut(vcc, NULL);
  590. dev_kfree_skb_any(skb);
  591. return;
  592. }
  593. /*
  594. * See if ingress MPC is using shortcut we opened as a return channel.
  595. * This means we have a bi-directional vcc opened by us.
  596. */
  597. if (eg->shortcut == NULL) {
  598. eg->shortcut = vcc;
  599. printk("mpoa: (%s) mpc_push: egress SVC in use\n", dev->name);
  600. }
  601. skb_pull(skb, sizeof(struct llc_snap_hdr) + sizeof(tag)); /* get rid of LLC/SNAP header */
  602. new_skb = skb_realloc_headroom(skb, eg->ctrl_info.DH_length); /* LLC/SNAP is shorter than MAC header :( */
  603. dev_kfree_skb_any(skb);
  604. if (new_skb == NULL){
  605. mpc->eg_ops->put(eg);
  606. return;
  607. }
  608. skb_push(new_skb, eg->ctrl_info.DH_length); /* add MAC header */
  609. memcpy(new_skb->data, eg->ctrl_info.DLL_header, eg->ctrl_info.DH_length);
  610. new_skb->protocol = eth_type_trans(new_skb, dev);
  611. new_skb->nh.raw = new_skb->data;
  612. eg->latest_ip_addr = new_skb->nh.iph->saddr;
  613. eg->packets_rcvd++;
  614. mpc->eg_ops->put(eg);
  615. memset(ATM_SKB(skb), 0, sizeof(struct atm_skb_data));
  616. netif_rx(new_skb);
  617. return;
  618. }
  619. static struct atmdev_ops mpc_ops = { /* only send is required */
  620. .close = mpoad_close,
  621. .send = msg_from_mpoad
  622. };
  623. static struct atm_dev mpc_dev = {
  624. .ops = &mpc_ops,
  625. .type = "mpc",
  626. .number = 42,
  627. .lock = SPIN_LOCK_UNLOCKED
  628. /* members not explicitly initialised will be 0 */
  629. };
  630. static int atm_mpoa_mpoad_attach (struct atm_vcc *vcc, int arg)
  631. {
  632. struct mpoa_client *mpc;
  633. struct lec_priv *priv;
  634. int err;
  635. if (mpcs == NULL) {
  636. init_timer(&mpc_timer);
  637. mpc_timer_refresh();
  638. /* This lets us now how our LECs are doing */
  639. err = register_netdevice_notifier(&mpoa_notifier);
  640. if (err < 0) {
  641. del_timer(&mpc_timer);
  642. return err;
  643. }
  644. }
  645. mpc = find_mpc_by_itfnum(arg);
  646. if (mpc == NULL) {
  647. dprintk("mpoa: mpoad_attach: allocating new mpc for itf %d\n", arg);
  648. mpc = alloc_mpc();
  649. if (mpc == NULL)
  650. return -ENOMEM;
  651. mpc->dev_num = arg;
  652. mpc->dev = find_lec_by_itfnum(arg); /* NULL if there was no lec */
  653. }
  654. if (mpc->mpoad_vcc) {
  655. printk("mpoa: mpoad_attach: mpoad is already present for itf %d\n", arg);
  656. return -EADDRINUSE;
  657. }
  658. if (mpc->dev) { /* check if the lec is LANE2 capable */
  659. priv = (struct lec_priv *)mpc->dev->priv;
  660. if (priv->lane_version < 2) {
  661. dev_put(mpc->dev);
  662. mpc->dev = NULL;
  663. } else
  664. priv->lane2_ops->associate_indicator = lane2_assoc_ind;
  665. }
  666. mpc->mpoad_vcc = vcc;
  667. vcc->dev = &mpc_dev;
  668. vcc_insert_socket(sk_atm(vcc));
  669. set_bit(ATM_VF_META,&vcc->flags);
  670. set_bit(ATM_VF_READY,&vcc->flags);
  671. if (mpc->dev) {
  672. char empty[ATM_ESA_LEN];
  673. memset(empty, 0, ATM_ESA_LEN);
  674. start_mpc(mpc, mpc->dev);
  675. /* set address if mpcd e.g. gets killed and restarted.
  676. * If we do not do it now we have to wait for the next LE_ARP
  677. */
  678. if ( memcmp(mpc->mps_ctrl_addr, empty, ATM_ESA_LEN) != 0 )
  679. send_set_mps_ctrl_addr(mpc->mps_ctrl_addr, mpc);
  680. }
  681. __module_get(THIS_MODULE);
  682. return arg;
  683. }
  684. static void send_set_mps_ctrl_addr(char *addr, struct mpoa_client *mpc)
  685. {
  686. struct k_message mesg;
  687. memcpy (mpc->mps_ctrl_addr, addr, ATM_ESA_LEN);
  688. mesg.type = SET_MPS_CTRL_ADDR;
  689. memcpy(mesg.MPS_ctrl, addr, ATM_ESA_LEN);
  690. msg_to_mpoad(&mesg, mpc);
  691. return;
  692. }
  693. static void mpoad_close(struct atm_vcc *vcc)
  694. {
  695. struct mpoa_client *mpc;
  696. struct sk_buff *skb;
  697. mpc = find_mpc_by_vcc(vcc);
  698. if (mpc == NULL) {
  699. printk("mpoa: mpoad_close: did not find MPC\n");
  700. return;
  701. }
  702. if (!mpc->mpoad_vcc) {
  703. printk("mpoa: mpoad_close: close for non-present mpoad\n");
  704. return;
  705. }
  706. mpc->mpoad_vcc = NULL;
  707. if (mpc->dev) {
  708. struct lec_priv *priv = (struct lec_priv *)mpc->dev->priv;
  709. priv->lane2_ops->associate_indicator = NULL;
  710. stop_mpc(mpc);
  711. dev_put(mpc->dev);
  712. }
  713. mpc->in_ops->destroy_cache(mpc);
  714. mpc->eg_ops->destroy_cache(mpc);
  715. while ((skb = skb_dequeue(&sk_atm(vcc)->sk_receive_queue))) {
  716. atm_return(vcc, skb->truesize);
  717. kfree_skb(skb);
  718. }
  719. printk("mpoa: (%s) going down\n",
  720. (mpc->dev) ? mpc->dev->name : "<unknown>");
  721. module_put(THIS_MODULE);
  722. return;
  723. }
  724. /*
  725. *
  726. */
  727. static int msg_from_mpoad(struct atm_vcc *vcc, struct sk_buff *skb)
  728. {
  729. struct mpoa_client *mpc = find_mpc_by_vcc(vcc);
  730. struct k_message *mesg = (struct k_message*)skb->data;
  731. atomic_sub(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
  732. if (mpc == NULL) {
  733. printk("mpoa: msg_from_mpoad: no mpc found\n");
  734. return 0;
  735. }
  736. dprintk("mpoa: (%s) msg_from_mpoad:", (mpc->dev) ? mpc->dev->name : "<unknown>");
  737. switch(mesg->type) {
  738. case MPOA_RES_REPLY_RCVD:
  739. dprintk(" mpoa_res_reply_rcvd\n");
  740. MPOA_res_reply_rcvd(mesg, mpc);
  741. break;
  742. case MPOA_TRIGGER_RCVD:
  743. dprintk(" mpoa_trigger_rcvd\n");
  744. MPOA_trigger_rcvd(mesg, mpc);
  745. break;
  746. case INGRESS_PURGE_RCVD:
  747. dprintk(" nhrp_purge_rcvd\n");
  748. ingress_purge_rcvd(mesg, mpc);
  749. break;
  750. case EGRESS_PURGE_RCVD:
  751. dprintk(" egress_purge_reply_rcvd\n");
  752. egress_purge_rcvd(mesg, mpc);
  753. break;
  754. case MPS_DEATH:
  755. dprintk(" mps_death\n");
  756. mps_death(mesg, mpc);
  757. break;
  758. case CACHE_IMPOS_RCVD:
  759. dprintk(" cache_impos_rcvd\n");
  760. MPOA_cache_impos_rcvd(mesg, mpc);
  761. break;
  762. case SET_MPC_CTRL_ADDR:
  763. dprintk(" set_mpc_ctrl_addr\n");
  764. set_mpc_ctrl_addr_rcvd(mesg, mpc);
  765. break;
  766. case SET_MPS_MAC_ADDR:
  767. dprintk(" set_mps_mac_addr\n");
  768. set_mps_mac_addr_rcvd(mesg, mpc);
  769. break;
  770. case CLEAN_UP_AND_EXIT:
  771. dprintk(" clean_up_and_exit\n");
  772. clean_up(mesg, mpc, DIE);
  773. break;
  774. case RELOAD:
  775. dprintk(" reload\n");
  776. clean_up(mesg, mpc, RELOAD);
  777. break;
  778. case SET_MPC_PARAMS:
  779. dprintk(" set_mpc_params\n");
  780. mpc->parameters = mesg->content.params;
  781. break;
  782. default:
  783. dprintk(" unknown message %d\n", mesg->type);
  784. break;
  785. }
  786. kfree_skb(skb);
  787. return 0;
  788. }
  789. /* Remember that this function may not do things that sleep */
  790. int msg_to_mpoad(struct k_message *mesg, struct mpoa_client *mpc)
  791. {
  792. struct sk_buff *skb;
  793. struct sock *sk;
  794. if (mpc == NULL || !mpc->mpoad_vcc) {
  795. printk("mpoa: msg_to_mpoad: mesg %d to a non-existent mpoad\n", mesg->type);
  796. return -ENXIO;
  797. }
  798. skb = alloc_skb(sizeof(struct k_message), GFP_ATOMIC);
  799. if (skb == NULL)
  800. return -ENOMEM;
  801. skb_put(skb, sizeof(struct k_message));
  802. memcpy(skb->data, mesg, sizeof(struct k_message));
  803. atm_force_charge(mpc->mpoad_vcc, skb->truesize);
  804. sk = sk_atm(mpc->mpoad_vcc);
  805. skb_queue_tail(&sk->sk_receive_queue, skb);
  806. sk->sk_data_ready(sk, skb->len);
  807. return 0;
  808. }
  809. static int mpoa_event_listener(struct notifier_block *mpoa_notifier, unsigned long event, void *dev_ptr)
  810. {
  811. struct net_device *dev;
  812. struct mpoa_client *mpc;
  813. struct lec_priv *priv;
  814. dev = (struct net_device *)dev_ptr;
  815. if (dev->name == NULL || strncmp(dev->name, "lec", 3))
  816. return NOTIFY_DONE; /* we are only interested in lec:s */
  817. switch (event) {
  818. case NETDEV_REGISTER: /* a new lec device was allocated */
  819. priv = (struct lec_priv *)dev->priv;
  820. if (priv->lane_version < 2)
  821. break;
  822. priv->lane2_ops->associate_indicator = lane2_assoc_ind;
  823. mpc = find_mpc_by_itfnum(priv->itfnum);
  824. if (mpc == NULL) {
  825. dprintk("mpoa: mpoa_event_listener: allocating new mpc for %s\n",
  826. dev->name);
  827. mpc = alloc_mpc();
  828. if (mpc == NULL) {
  829. printk("mpoa: mpoa_event_listener: no new mpc");
  830. break;
  831. }
  832. }
  833. mpc->dev_num = priv->itfnum;
  834. mpc->dev = dev;
  835. dev_hold(dev);
  836. dprintk("mpoa: (%s) was initialized\n", dev->name);
  837. break;
  838. case NETDEV_UNREGISTER:
  839. /* the lec device was deallocated */
  840. mpc = find_mpc_by_lec(dev);
  841. if (mpc == NULL)
  842. break;
  843. dprintk("mpoa: device (%s) was deallocated\n", dev->name);
  844. stop_mpc(mpc);
  845. dev_put(mpc->dev);
  846. mpc->dev = NULL;
  847. break;
  848. case NETDEV_UP:
  849. /* the dev was ifconfig'ed up */
  850. mpc = find_mpc_by_lec(dev);
  851. if (mpc == NULL)
  852. break;
  853. if (mpc->mpoad_vcc != NULL) {
  854. start_mpc(mpc, dev);
  855. }
  856. break;
  857. case NETDEV_DOWN:
  858. /* the dev was ifconfig'ed down */
  859. /* this means that the flow of packets from the
  860. * upper layer stops
  861. */
  862. mpc = find_mpc_by_lec(dev);
  863. if (mpc == NULL)
  864. break;
  865. if (mpc->mpoad_vcc != NULL) {
  866. stop_mpc(mpc);
  867. }
  868. break;
  869. case NETDEV_REBOOT:
  870. case NETDEV_CHANGE:
  871. case NETDEV_CHANGEMTU:
  872. case NETDEV_CHANGEADDR:
  873. case NETDEV_GOING_DOWN:
  874. break;
  875. default:
  876. break;
  877. }
  878. return NOTIFY_DONE;
  879. }
  880. /*
  881. * Functions which are called after a message is received from mpcd.
  882. * Msg is reused on purpose.
  883. */
  884. static void MPOA_trigger_rcvd(struct k_message *msg, struct mpoa_client *mpc)
  885. {
  886. uint32_t dst_ip = msg->content.in_info.in_dst_ip;
  887. in_cache_entry *entry;
  888. entry = mpc->in_ops->get(dst_ip, mpc);
  889. if(entry == NULL){
  890. entry = mpc->in_ops->add_entry(dst_ip, mpc);
  891. entry->entry_state = INGRESS_RESOLVING;
  892. msg->type = SND_MPOA_RES_RQST;
  893. msg->content.in_info = entry->ctrl_info;
  894. msg_to_mpoad(msg, mpc);
  895. do_gettimeofday(&(entry->reply_wait));
  896. mpc->in_ops->put(entry);
  897. return;
  898. }
  899. if(entry->entry_state == INGRESS_INVALID){
  900. entry->entry_state = INGRESS_RESOLVING;
  901. msg->type = SND_MPOA_RES_RQST;
  902. msg->content.in_info = entry->ctrl_info;
  903. msg_to_mpoad(msg, mpc);
  904. do_gettimeofday(&(entry->reply_wait));
  905. mpc->in_ops->put(entry);
  906. return;
  907. }
  908. printk("mpoa: (%s) MPOA_trigger_rcvd: entry already in resolving state\n",
  909. (mpc->dev) ? mpc->dev->name : "<unknown>");
  910. mpc->in_ops->put(entry);
  911. return;
  912. }
  913. /*
  914. * Things get complicated because we have to check if there's an egress
  915. * shortcut with suitable traffic parameters we could use.
  916. */
  917. static void check_qos_and_open_shortcut(struct k_message *msg, struct mpoa_client *client, in_cache_entry *entry)
  918. {
  919. uint32_t dst_ip = msg->content.in_info.in_dst_ip;
  920. struct atm_mpoa_qos *qos = atm_mpoa_search_qos(dst_ip);
  921. eg_cache_entry *eg_entry = client->eg_ops->get_by_src_ip(dst_ip, client);
  922. if(eg_entry && eg_entry->shortcut){
  923. if(eg_entry->shortcut->qos.txtp.traffic_class &
  924. msg->qos.txtp.traffic_class &
  925. (qos ? qos->qos.txtp.traffic_class : ATM_UBR | ATM_CBR)){
  926. if(eg_entry->shortcut->qos.txtp.traffic_class == ATM_UBR)
  927. entry->shortcut = eg_entry->shortcut;
  928. else if(eg_entry->shortcut->qos.txtp.max_pcr > 0)
  929. entry->shortcut = eg_entry->shortcut;
  930. }
  931. if(entry->shortcut){
  932. dprintk("mpoa: (%s) using egress SVC to reach %u.%u.%u.%u\n",client->dev->name, NIPQUAD(dst_ip));
  933. client->eg_ops->put(eg_entry);
  934. return;
  935. }
  936. }
  937. if (eg_entry != NULL)
  938. client->eg_ops->put(eg_entry);
  939. /* No luck in the egress cache we must open an ingress SVC */
  940. msg->type = OPEN_INGRESS_SVC;
  941. if (qos && (qos->qos.txtp.traffic_class == msg->qos.txtp.traffic_class))
  942. {
  943. msg->qos = qos->qos;
  944. printk("mpoa: (%s) trying to get a CBR shortcut\n",client->dev->name);
  945. }
  946. else memset(&msg->qos,0,sizeof(struct atm_qos));
  947. msg_to_mpoad(msg, client);
  948. return;
  949. }
  950. static void MPOA_res_reply_rcvd(struct k_message *msg, struct mpoa_client *mpc)
  951. {
  952. uint32_t dst_ip = msg->content.in_info.in_dst_ip;
  953. in_cache_entry *entry = mpc->in_ops->get(dst_ip, mpc);
  954. dprintk("mpoa: (%s) MPOA_res_reply_rcvd: ip %u.%u.%u.%u\n", mpc->dev->name, NIPQUAD(dst_ip));
  955. ddprintk("mpoa: (%s) MPOA_res_reply_rcvd() entry = %p", mpc->dev->name, entry);
  956. if(entry == NULL){
  957. printk("\nmpoa: (%s) ARGH, received res. reply for an entry that doesn't exist.\n", mpc->dev->name);
  958. return;
  959. }
  960. ddprintk(" entry_state = %d ", entry->entry_state);
  961. if (entry->entry_state == INGRESS_RESOLVED) {
  962. printk("\nmpoa: (%s) MPOA_res_reply_rcvd for RESOLVED entry!\n", mpc->dev->name);
  963. mpc->in_ops->put(entry);
  964. return;
  965. }
  966. entry->ctrl_info = msg->content.in_info;
  967. do_gettimeofday(&(entry->tv));
  968. do_gettimeofday(&(entry->reply_wait)); /* Used in refreshing func from now on */
  969. entry->refresh_time = 0;
  970. ddprintk("entry->shortcut = %p\n", entry->shortcut);
  971. if(entry->entry_state == INGRESS_RESOLVING && entry->shortcut != NULL){
  972. entry->entry_state = INGRESS_RESOLVED;
  973. mpc->in_ops->put(entry);
  974. return; /* Shortcut already open... */
  975. }
  976. if (entry->shortcut != NULL) {
  977. printk("mpoa: (%s) MPOA_res_reply_rcvd: entry->shortcut != NULL, impossible!\n",
  978. mpc->dev->name);
  979. mpc->in_ops->put(entry);
  980. return;
  981. }
  982. check_qos_and_open_shortcut(msg, mpc, entry);
  983. entry->entry_state = INGRESS_RESOLVED;
  984. mpc->in_ops->put(entry);
  985. return;
  986. }
  987. static void ingress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc)
  988. {
  989. uint32_t dst_ip = msg->content.in_info.in_dst_ip;
  990. uint32_t mask = msg->ip_mask;
  991. unsigned char *ip = (unsigned char *)&dst_ip;
  992. in_cache_entry *entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask);
  993. if(entry == NULL){
  994. printk("mpoa: (%s) ingress_purge_rcvd: purge for a non-existing entry, ", mpc->dev->name);
  995. printk("ip = %u.%u.%u.%u\n", ip[0], ip[1], ip[2], ip[3]);
  996. return;
  997. }
  998. do {
  999. dprintk("mpoa: (%s) ingress_purge_rcvd: removing an ingress entry, ip = %u.%u.%u.%u\n" ,
  1000. mpc->dev->name, ip[0], ip[1], ip[2], ip[3]);
  1001. write_lock_bh(&mpc->ingress_lock);
  1002. mpc->in_ops->remove_entry(entry, mpc);
  1003. write_unlock_bh(&mpc->ingress_lock);
  1004. mpc->in_ops->put(entry);
  1005. entry = mpc->in_ops->get_with_mask(dst_ip, mpc, mask);
  1006. } while (entry != NULL);
  1007. return;
  1008. }
  1009. static void egress_purge_rcvd(struct k_message *msg, struct mpoa_client *mpc)
  1010. {
  1011. uint32_t cache_id = msg->content.eg_info.cache_id;
  1012. eg_cache_entry *entry = mpc->eg_ops->get_by_cache_id(cache_id, mpc);
  1013. if (entry == NULL) {
  1014. dprintk("mpoa: (%s) egress_purge_rcvd: purge for a non-existing entry\n", mpc->dev->name);
  1015. return;
  1016. }
  1017. write_lock_irq(&mpc->egress_lock);
  1018. mpc->eg_ops->remove_entry(entry, mpc);
  1019. write_unlock_irq(&mpc->egress_lock);
  1020. mpc->eg_ops->put(entry);
  1021. return;
  1022. }
  1023. static void purge_egress_shortcut(struct atm_vcc *vcc, eg_cache_entry *entry)
  1024. {
  1025. struct sock *sk;
  1026. struct k_message *purge_msg;
  1027. struct sk_buff *skb;
  1028. dprintk("mpoa: purge_egress_shortcut: entering\n");
  1029. if (vcc == NULL) {
  1030. printk("mpoa: purge_egress_shortcut: vcc == NULL\n");
  1031. return;
  1032. }
  1033. skb = alloc_skb(sizeof(struct k_message), GFP_ATOMIC);
  1034. if (skb == NULL) {
  1035. printk("mpoa: purge_egress_shortcut: out of memory\n");
  1036. return;
  1037. }
  1038. skb_put(skb, sizeof(struct k_message));
  1039. memset(skb->data, 0, sizeof(struct k_message));
  1040. purge_msg = (struct k_message *)skb->data;
  1041. purge_msg->type = DATA_PLANE_PURGE;
  1042. if (entry != NULL)
  1043. purge_msg->content.eg_info = entry->ctrl_info;
  1044. atm_force_charge(vcc, skb->truesize);
  1045. sk = sk_atm(vcc);
  1046. skb_queue_tail(&sk->sk_receive_queue, skb);
  1047. sk->sk_data_ready(sk, skb->len);
  1048. dprintk("mpoa: purge_egress_shortcut: exiting:\n");
  1049. return;
  1050. }
  1051. /*
  1052. * Our MPS died. Tell our daemon to send NHRP data plane purge to each
  1053. * of the egress shortcuts we have.
  1054. */
  1055. static void mps_death( struct k_message * msg, struct mpoa_client * mpc )
  1056. {
  1057. eg_cache_entry *entry;
  1058. dprintk("mpoa: (%s) mps_death:\n", mpc->dev->name);
  1059. if(memcmp(msg->MPS_ctrl, mpc->mps_ctrl_addr, ATM_ESA_LEN)){
  1060. printk("mpoa: (%s) mps_death: wrong MPS\n", mpc->dev->name);
  1061. return;
  1062. }
  1063. /* FIXME: This knows too much of the cache structure */
  1064. read_lock_irq(&mpc->egress_lock);
  1065. entry = mpc->eg_cache;
  1066. while (entry != NULL) {
  1067. purge_egress_shortcut(entry->shortcut, entry);
  1068. entry = entry->next;
  1069. }
  1070. read_unlock_irq(&mpc->egress_lock);
  1071. mpc->in_ops->destroy_cache(mpc);
  1072. mpc->eg_ops->destroy_cache(mpc);
  1073. return;
  1074. }
  1075. static void MPOA_cache_impos_rcvd( struct k_message * msg, struct mpoa_client * mpc)
  1076. {
  1077. uint16_t holding_time;
  1078. eg_cache_entry *entry = mpc->eg_ops->get_by_cache_id(msg->content.eg_info.cache_id, mpc);
  1079. holding_time = msg->content.eg_info.holding_time;
  1080. dprintk("mpoa: (%s) MPOA_cache_impos_rcvd: entry = %p, holding_time = %u\n",
  1081. mpc->dev->name, entry, holding_time);
  1082. if(entry == NULL && holding_time) {
  1083. entry = mpc->eg_ops->add_entry(msg, mpc);
  1084. mpc->eg_ops->put(entry);
  1085. return;
  1086. }
  1087. if(holding_time){
  1088. mpc->eg_ops->update(entry, holding_time);
  1089. return;
  1090. }
  1091. write_lock_irq(&mpc->egress_lock);
  1092. mpc->eg_ops->remove_entry(entry, mpc);
  1093. write_unlock_irq(&mpc->egress_lock);
  1094. mpc->eg_ops->put(entry);
  1095. return;
  1096. }
  1097. static void set_mpc_ctrl_addr_rcvd(struct k_message *mesg, struct mpoa_client *mpc)
  1098. {
  1099. struct lec_priv *priv;
  1100. int i, retval ;
  1101. uint8_t tlv[4 + 1 + 1 + 1 + ATM_ESA_LEN];
  1102. tlv[0] = 00; tlv[1] = 0xa0; tlv[2] = 0x3e; tlv[3] = 0x2a; /* type */
  1103. tlv[4] = 1 + 1 + ATM_ESA_LEN; /* length */
  1104. tlv[5] = 0x02; /* MPOA client */
  1105. tlv[6] = 0x00; /* number of MPS MAC addresses */
  1106. memcpy(&tlv[7], mesg->MPS_ctrl, ATM_ESA_LEN); /* MPC ctrl ATM addr */
  1107. memcpy(mpc->our_ctrl_addr, mesg->MPS_ctrl, ATM_ESA_LEN);
  1108. dprintk("mpoa: (%s) setting MPC ctrl ATM address to ",
  1109. (mpc->dev) ? mpc->dev->name : "<unknown>");
  1110. for (i = 7; i < sizeof(tlv); i++)
  1111. dprintk("%02x ", tlv[i]);
  1112. dprintk("\n");
  1113. if (mpc->dev) {
  1114. priv = (struct lec_priv *)mpc->dev->priv;
  1115. retval = priv->lane2_ops->associate_req(mpc->dev, mpc->dev->dev_addr, tlv, sizeof(tlv));
  1116. if (retval == 0)
  1117. printk("mpoa: (%s) MPOA device type TLV association failed\n", mpc->dev->name);
  1118. retval = priv->lane2_ops->resolve(mpc->dev, NULL, 1, NULL, NULL);
  1119. if (retval < 0)
  1120. printk("mpoa: (%s) targetless LE_ARP request failed\n", mpc->dev->name);
  1121. }
  1122. return;
  1123. }
  1124. static void set_mps_mac_addr_rcvd(struct k_message *msg, struct mpoa_client *client)
  1125. {
  1126. if(client->number_of_mps_macs)
  1127. kfree(client->mps_macs);
  1128. client->number_of_mps_macs = 0;
  1129. client->mps_macs = kmalloc(ETH_ALEN,GFP_KERNEL);
  1130. if (client->mps_macs == NULL) {
  1131. printk("mpoa: set_mps_mac_addr_rcvd: out of memory\n");
  1132. return;
  1133. }
  1134. client->number_of_mps_macs = 1;
  1135. memcpy(client->mps_macs, msg->MPS_ctrl, ETH_ALEN);
  1136. return;
  1137. }
  1138. /*
  1139. * purge egress cache and tell daemon to 'action' (DIE, RELOAD)
  1140. */
  1141. static void clean_up(struct k_message *msg, struct mpoa_client *mpc, int action)
  1142. {
  1143. eg_cache_entry *entry;
  1144. msg->type = SND_EGRESS_PURGE;
  1145. /* FIXME: This knows too much of the cache structure */
  1146. read_lock_irq(&mpc->egress_lock);
  1147. entry = mpc->eg_cache;
  1148. while (entry != NULL){
  1149. msg->content.eg_info = entry->ctrl_info;
  1150. dprintk("mpoa: cache_id %u\n", entry->ctrl_info.cache_id);
  1151. msg_to_mpoad(msg, mpc);
  1152. entry = entry->next;
  1153. }
  1154. read_unlock_irq(&mpc->egress_lock);
  1155. msg->type = action;
  1156. msg_to_mpoad(msg, mpc);
  1157. return;
  1158. }
  1159. static void mpc_timer_refresh(void)
  1160. {
  1161. mpc_timer.expires = jiffies + (MPC_P2 * HZ);
  1162. mpc_timer.data = mpc_timer.expires;
  1163. mpc_timer.function = mpc_cache_check;
  1164. add_timer(&mpc_timer);
  1165. return;
  1166. }
  1167. static void mpc_cache_check( unsigned long checking_time )
  1168. {
  1169. struct mpoa_client *mpc = mpcs;
  1170. static unsigned long previous_resolving_check_time;
  1171. static unsigned long previous_refresh_time;
  1172. while( mpc != NULL ){
  1173. mpc->in_ops->clear_count(mpc);
  1174. mpc->eg_ops->clear_expired(mpc);
  1175. if(checking_time - previous_resolving_check_time > mpc->parameters.mpc_p4 * HZ ){
  1176. mpc->in_ops->check_resolving(mpc);
  1177. previous_resolving_check_time = checking_time;
  1178. }
  1179. if(checking_time - previous_refresh_time > mpc->parameters.mpc_p5 * HZ ){
  1180. mpc->in_ops->refresh(mpc);
  1181. previous_refresh_time = checking_time;
  1182. }
  1183. mpc = mpc->next;
  1184. }
  1185. mpc_timer_refresh();
  1186. return;
  1187. }
  1188. static int atm_mpoa_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
  1189. {
  1190. int err = 0;
  1191. struct atm_vcc *vcc = ATM_SD(sock);
  1192. if (cmd != ATMMPC_CTRL && cmd != ATMMPC_DATA)
  1193. return -ENOIOCTLCMD;
  1194. if (!capable(CAP_NET_ADMIN))
  1195. return -EPERM;
  1196. switch (cmd) {
  1197. case ATMMPC_CTRL:
  1198. err = atm_mpoa_mpoad_attach(vcc, (int)arg);
  1199. if (err >= 0)
  1200. sock->state = SS_CONNECTED;
  1201. break;
  1202. case ATMMPC_DATA:
  1203. err = atm_mpoa_vcc_attach(vcc, (void __user *)arg);
  1204. break;
  1205. default:
  1206. break;
  1207. }
  1208. return err;
  1209. }
  1210. static struct atm_ioctl atm_ioctl_ops = {
  1211. .owner = THIS_MODULE,
  1212. .ioctl = atm_mpoa_ioctl,
  1213. };
  1214. static __init int atm_mpoa_init(void)
  1215. {
  1216. register_atm_ioctl(&atm_ioctl_ops);
  1217. if (mpc_proc_init() != 0)
  1218. printk(KERN_INFO "mpoa: failed to initialize /proc/mpoa\n");
  1219. printk("mpc.c: " __DATE__ " " __TIME__ " initialized\n");
  1220. return 0;
  1221. }
  1222. static void __exit atm_mpoa_cleanup(void)
  1223. {
  1224. struct mpoa_client *mpc, *tmp;
  1225. struct atm_mpoa_qos *qos, *nextqos;
  1226. struct lec_priv *priv;
  1227. mpc_proc_clean();
  1228. del_timer(&mpc_timer);
  1229. unregister_netdevice_notifier(&mpoa_notifier);
  1230. deregister_atm_ioctl(&atm_ioctl_ops);
  1231. mpc = mpcs;
  1232. mpcs = NULL;
  1233. while (mpc != NULL) {
  1234. tmp = mpc->next;
  1235. if (mpc->dev != NULL) {
  1236. stop_mpc(mpc);
  1237. priv = (struct lec_priv *)mpc->dev->priv;
  1238. if (priv->lane2_ops != NULL)
  1239. priv->lane2_ops->associate_indicator = NULL;
  1240. }
  1241. ddprintk("mpoa: cleanup_module: about to clear caches\n");
  1242. mpc->in_ops->destroy_cache(mpc);
  1243. mpc->eg_ops->destroy_cache(mpc);
  1244. ddprintk("mpoa: cleanup_module: caches cleared\n");
  1245. kfree(mpc->mps_macs);
  1246. memset(mpc, 0, sizeof(struct mpoa_client));
  1247. ddprintk("mpoa: cleanup_module: about to kfree %p\n", mpc);
  1248. kfree(mpc);
  1249. ddprintk("mpoa: cleanup_module: next mpc is at %p\n", tmp);
  1250. mpc = tmp;
  1251. }
  1252. qos = qos_head;
  1253. qos_head = NULL;
  1254. while (qos != NULL) {
  1255. nextqos = qos->next;
  1256. dprintk("mpoa: cleanup_module: freeing qos entry %p\n", qos);
  1257. kfree(qos);
  1258. qos = nextqos;
  1259. }
  1260. return;
  1261. }
  1262. module_init(atm_mpoa_init);
  1263. module_exit(atm_mpoa_cleanup);
  1264. MODULE_LICENSE("GPL");