mpc.c 40 KB

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