mpc.c 40 KB

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