prp_netlink.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * prp_netlink.c: Routines for handling Netlink messages for PRP.
  4. * This is based on hsr_netlink.c from Arvid Brodin, arvid.brodin@alten.se
  5. *
  6. * Copyright (C) 2019 Texas Instruments Incorporated
  7. *
  8. * Author(s):
  9. * Murali Karicheri <m-karicheri2@ti.com>
  10. */
  11. #include <linux/kernel.h>
  12. #include <net/genetlink.h>
  13. #include <net/rtnetlink.h>
  14. #include "prp_netlink.h"
  15. #include "hsr_prp_device.h"
  16. #include "hsr_prp_framereg.h"
  17. #include "hsr_prp_main.h"
  18. #include "hsr_prp_netlink.h"
  19. static const struct nla_policy prp_policy[IFLA_HSR_PRP_MAX + 1] = {
  20. [IFLA_HSR_PRP_SLAVE1] = { .type = NLA_U32 },
  21. [IFLA_HSR_PRP_SLAVE2] = { .type = NLA_U32 },
  22. [IFLA_HSR_PRP_SF_MC_ADDR_LSB] = { .type = NLA_U8 },
  23. [IFLA_HSR_PRP_SF_MC_ADDR] = { .len = ETH_ALEN },
  24. [IFLA_HSR_PRP_SEQ_NR] = { .type = NLA_U16 },
  25. };
  26. static int prp_newlink(struct net *src_net, struct net_device *dev,
  27. struct nlattr *tb[], struct nlattr *data[],
  28. struct netlink_ext_ack *extack)
  29. {
  30. return hsr_prp_newlink(PRP, src_net, dev, tb, data, extack);
  31. }
  32. static struct rtnl_link_ops prp_link_ops __read_mostly = {
  33. .kind = "prp",
  34. .maxtype = IFLA_HSR_PRP_MAX,
  35. .policy = prp_policy,
  36. .priv_size = sizeof(struct hsr_prp_priv),
  37. .setup = prp_dev_setup,
  38. .newlink = prp_newlink,
  39. .fill_info = hsr_prp_fill_info,
  40. };
  41. /* NLA_BINARY missing in libnl; use NLA_UNSPEC in userspace instead. */
  42. static const struct nla_policy prp_genl_policy[HSR_PRP_A_MAX + 1] = {
  43. [HSR_PRP_A_NODE_ADDR] = { .type = NLA_BINARY, .len = ETH_ALEN },
  44. [HSR_PRP_A_NODE_ADDR_B] = { .type = NLA_BINARY, .len = ETH_ALEN },
  45. [HSR_PRP_A_IFINDEX] = { .type = NLA_U32 },
  46. [HSR_PRP_A_IF1_AGE] = { .type = NLA_U32 },
  47. [HSR_PRP_A_IF2_AGE] = { .type = NLA_U32 },
  48. [HSR_PRP_A_IF1_SEQ] = { .type = NLA_U16 },
  49. [HSR_PRP_A_IF2_SEQ] = { .type = NLA_U16 },
  50. };
  51. static struct genl_family prp_genl_family;
  52. static const struct genl_multicast_group prp_mcgrps[] = {
  53. { .name = "prp-network", },
  54. };
  55. /* This is called when we haven't heard from the node with MAC address addr for
  56. * some time (just before the node is removed from the node table/list).
  57. */
  58. void prp_nl_nodedown(struct hsr_prp_priv *priv, unsigned char addr[ETH_ALEN])
  59. {
  60. hsr_prp_nl_nodedown(priv, &prp_genl_family, addr);
  61. }
  62. static int prp_get_node_status(struct sk_buff *skb_in, struct genl_info *info)
  63. {
  64. return hsr_prp_get_node_status(&prp_genl_family, skb_in, info);
  65. }
  66. static int prp_get_node_list(struct sk_buff *skb_in, struct genl_info *info)
  67. {
  68. return hsr_prp_get_node_list(&prp_genl_family, skb_in, info);
  69. }
  70. static const struct genl_ops prp_ops[] = {
  71. {
  72. .cmd = HSR_PRP_C_GET_NODE_STATUS,
  73. .flags = 0,
  74. .policy = prp_genl_policy,
  75. .doit = prp_get_node_status,
  76. .dumpit = NULL,
  77. },
  78. {
  79. .cmd = HSR_PRP_C_GET_NODE_LIST,
  80. .flags = 0,
  81. .policy = prp_genl_policy,
  82. .doit = prp_get_node_list,
  83. .dumpit = NULL,
  84. },
  85. };
  86. static struct genl_family prp_genl_family __ro_after_init = {
  87. .hdrsize = 0,
  88. .name = "PRP",
  89. .version = 1,
  90. .maxattr = HSR_PRP_A_MAX,
  91. .module = THIS_MODULE,
  92. .ops = prp_ops,
  93. .n_ops = ARRAY_SIZE(prp_ops),
  94. .mcgrps = prp_mcgrps,
  95. .n_mcgrps = ARRAY_SIZE(prp_mcgrps),
  96. };
  97. int __init prp_netlink_init(void)
  98. {
  99. int rc;
  100. rc = rtnl_link_register(&prp_link_ops);
  101. if (rc)
  102. goto fail_rtnl_link_register;
  103. rc = genl_register_family(&prp_genl_family);
  104. if (rc)
  105. goto fail_genl_register_family;
  106. return 0;
  107. fail_genl_register_family:
  108. rtnl_link_unregister(&prp_link_ops);
  109. fail_rtnl_link_register:
  110. return rc;
  111. }
  112. void __exit prp_netlink_exit(void)
  113. {
  114. genl_unregister_family(&prp_genl_family);
  115. rtnl_link_unregister(&prp_link_ops);
  116. }
  117. MODULE_ALIAS_RTNL_LINK("prp");