mpc.c 39 KB

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