vport-gre.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (c) 2007-2014 Nicira, Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of version 2 of the GNU General Public
  6. * License as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. * 02110-1301, USA
  17. */
  18. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  19. #include <linux/if.h>
  20. #include <linux/skbuff.h>
  21. #include <linux/ip.h>
  22. #include <linux/if_tunnel.h>
  23. #include <linux/if_vlan.h>
  24. #include <linux/in.h>
  25. #include <linux/in_route.h>
  26. #include <linux/inetdevice.h>
  27. #include <linux/jhash.h>
  28. #include <linux/list.h>
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/workqueue.h>
  32. #include <linux/rculist.h>
  33. #include <net/route.h>
  34. #include <net/xfrm.h>
  35. #include <net/icmp.h>
  36. #include <net/ip.h>
  37. #include <net/ip_tunnels.h>
  38. #include <net/gre.h>
  39. #include <net/net_namespace.h>
  40. #include <net/netns/generic.h>
  41. #include <net/protocol.h>
  42. #include "datapath.h"
  43. #include "vport.h"
  44. #include "vport-netdev.h"
  45. static struct vport_ops ovs_gre_vport_ops;
  46. static struct vport *gre_tnl_create(const struct vport_parms *parms)
  47. {
  48. struct net *net = ovs_dp_get_net(parms->dp);
  49. struct net_device *dev;
  50. struct vport *vport;
  51. int err;
  52. vport = ovs_vport_alloc(0, &ovs_gre_vport_ops, parms);
  53. if (IS_ERR(vport))
  54. return vport;
  55. rtnl_lock();
  56. dev = gretap_fb_dev_create(net, parms->name, NET_NAME_USER);
  57. if (IS_ERR(dev)) {
  58. rtnl_unlock();
  59. ovs_vport_free(vport);
  60. return ERR_CAST(dev);
  61. }
  62. err = dev_change_flags(dev, dev->flags | IFF_UP);
  63. if (err < 0) {
  64. rtnl_delete_link(dev);
  65. rtnl_unlock();
  66. ovs_vport_free(vport);
  67. return ERR_PTR(err);
  68. }
  69. rtnl_unlock();
  70. return vport;
  71. }
  72. static struct vport *gre_create(const struct vport_parms *parms)
  73. {
  74. struct vport *vport;
  75. vport = gre_tnl_create(parms);
  76. if (IS_ERR(vport))
  77. return vport;
  78. return ovs_netdev_link(vport, parms->name);
  79. }
  80. static struct vport_ops ovs_gre_vport_ops = {
  81. .type = OVS_VPORT_TYPE_GRE,
  82. .create = gre_create,
  83. .send = dev_queue_xmit,
  84. .destroy = ovs_netdev_tunnel_destroy,
  85. };
  86. static int __init ovs_gre_tnl_init(void)
  87. {
  88. return ovs_vport_ops_register(&ovs_gre_vport_ops);
  89. }
  90. static void __exit ovs_gre_tnl_exit(void)
  91. {
  92. ovs_vport_ops_unregister(&ovs_gre_vport_ops);
  93. }
  94. module_init(ovs_gre_tnl_init);
  95. module_exit(ovs_gre_tnl_exit);
  96. MODULE_DESCRIPTION("OVS: GRE switching port");
  97. MODULE_LICENSE("GPL");
  98. MODULE_ALIAS("vport-type-3");