ipoib_netlink.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (c) 2012 Mellanox Technologies. - All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/netdevice.h>
  33. #include <linux/module.h>
  34. #include <net/rtnetlink.h>
  35. #include "ipoib.h"
  36. static const struct nla_policy ipoib_policy[IFLA_IPOIB_MAX + 1] = {
  37. [IFLA_IPOIB_PKEY] = { .type = NLA_U16 },
  38. };
  39. static int ipoib_new_child_link(struct net *src_net, struct net_device *dev,
  40. struct nlattr *tb[], struct nlattr *data[])
  41. {
  42. struct net_device *pdev;
  43. struct ipoib_dev_priv *ppriv;
  44. u16 child_pkey;
  45. int err;
  46. if (!tb[IFLA_LINK])
  47. return -EINVAL;
  48. pdev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK]));
  49. if (!pdev)
  50. return -ENODEV;
  51. ppriv = netdev_priv(pdev);
  52. if (test_bit(IPOIB_FLAG_SUBINTERFACE, &ppriv->flags)) {
  53. ipoib_warn(ppriv, "child creation disallowed for child devices\n");
  54. return -EINVAL;
  55. }
  56. if (!data || !data[IFLA_IPOIB_PKEY]) {
  57. ipoib_dbg(ppriv, "no pkey specified, using parent pkey\n");
  58. child_pkey = ppriv->pkey;
  59. } else
  60. child_pkey = nla_get_u16(data[IFLA_IPOIB_PKEY]);
  61. err = __ipoib_vlan_add(ppriv, netdev_priv(dev), child_pkey, IPOIB_RTNL_CHILD);
  62. return err;
  63. }
  64. static void ipoib_unregister_child_dev(struct net_device *dev, struct list_head *head)
  65. {
  66. struct ipoib_dev_priv *priv, *ppriv;
  67. priv = netdev_priv(dev);
  68. ppriv = netdev_priv(priv->parent);
  69. mutex_lock(&ppriv->vlan_mutex);
  70. unregister_netdevice_queue(dev, head);
  71. list_del(&priv->list);
  72. mutex_unlock(&ppriv->vlan_mutex);
  73. }
  74. static size_t ipoib_get_size(const struct net_device *dev)
  75. {
  76. return nla_total_size(2); /* IFLA_IPOIB_PKEY */
  77. }
  78. static struct rtnl_link_ops ipoib_link_ops __read_mostly = {
  79. .kind = "ipoib",
  80. .maxtype = IFLA_IPOIB_MAX,
  81. .policy = ipoib_policy,
  82. .priv_size = sizeof(struct ipoib_dev_priv),
  83. .setup = ipoib_setup,
  84. .newlink = ipoib_new_child_link,
  85. .dellink = ipoib_unregister_child_dev,
  86. .get_size = ipoib_get_size,
  87. };
  88. int __init ipoib_netlink_init(void)
  89. {
  90. return rtnl_link_register(&ipoib_link_ops);
  91. }
  92. void __exit ipoib_netlink_fini(void)
  93. {
  94. rtnl_link_unregister(&ipoib_link_ops);
  95. }
  96. MODULE_ALIAS_RTNL_LINK("ipoib");