core.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* This program is free software; you can redistribute it and/or modify
  2. * it under the terms of the GNU General Public License version 2
  3. * as published by the Free Software Foundation.
  4. *
  5. * This program is distributed in the hope that it will be useful,
  6. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. * GNU General Public License for more details.
  9. *
  10. * Authors:
  11. * (C) 2015 Pengutronix, Alexander Aring <aar@pengutronix.de>
  12. */
  13. #include <linux/module.h>
  14. #include <net/6lowpan.h>
  15. #include "6lowpan_i.h"
  16. int lowpan_register_netdevice(struct net_device *dev,
  17. enum lowpan_lltypes lltype)
  18. {
  19. int ret;
  20. dev->addr_len = EUI64_ADDR_LEN;
  21. dev->type = ARPHRD_6LOWPAN;
  22. dev->mtu = IPV6_MIN_MTU;
  23. dev->priv_flags |= IFF_NO_QUEUE;
  24. lowpan_priv(dev)->lltype = lltype;
  25. ret = register_netdevice(dev);
  26. if (ret < 0)
  27. return ret;
  28. ret = lowpan_dev_debugfs_init(dev);
  29. if (ret < 0)
  30. unregister_netdevice(dev);
  31. return ret;
  32. }
  33. EXPORT_SYMBOL(lowpan_register_netdevice);
  34. int lowpan_register_netdev(struct net_device *dev,
  35. enum lowpan_lltypes lltype)
  36. {
  37. int ret;
  38. rtnl_lock();
  39. ret = lowpan_register_netdevice(dev, lltype);
  40. rtnl_unlock();
  41. return ret;
  42. }
  43. EXPORT_SYMBOL(lowpan_register_netdev);
  44. void lowpan_unregister_netdevice(struct net_device *dev)
  45. {
  46. unregister_netdevice(dev);
  47. lowpan_dev_debugfs_exit(dev);
  48. }
  49. EXPORT_SYMBOL(lowpan_unregister_netdevice);
  50. void lowpan_unregister_netdev(struct net_device *dev)
  51. {
  52. rtnl_lock();
  53. lowpan_unregister_netdevice(dev);
  54. rtnl_unlock();
  55. }
  56. EXPORT_SYMBOL(lowpan_unregister_netdev);
  57. static int __init lowpan_module_init(void)
  58. {
  59. int ret;
  60. ret = lowpan_debugfs_init();
  61. if (ret < 0)
  62. return ret;
  63. request_module_nowait("ipv6");
  64. request_module_nowait("nhc_dest");
  65. request_module_nowait("nhc_fragment");
  66. request_module_nowait("nhc_hop");
  67. request_module_nowait("nhc_ipv6");
  68. request_module_nowait("nhc_mobility");
  69. request_module_nowait("nhc_routing");
  70. request_module_nowait("nhc_udp");
  71. return 0;
  72. }
  73. static void __exit lowpan_module_exit(void)
  74. {
  75. lowpan_debugfs_exit();
  76. }
  77. module_init(lowpan_module_init);
  78. module_exit(lowpan_module_exit);
  79. MODULE_LICENSE("GPL");