mpc.c 38 KB

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