vlan_mvrp.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * IEEE 802.1Q Multiple VLAN Registration Protocol (MVRP)
  4. *
  5. * Copyright (c) 2012 Massachusetts Institute of Technology
  6. *
  7. * Adapted from code in net/8021q/vlan_gvrp.c
  8. * Copyright (c) 2008 Patrick McHardy <[email protected]>
  9. */
  10. #include <linux/types.h>
  11. #include <linux/if_ether.h>
  12. #include <linux/if_vlan.h>
  13. #include <net/mrp.h>
  14. #include "vlan.h"
  15. #define MRP_MVRP_ADDRESS { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x21 }
  16. enum mvrp_attributes {
  17. MVRP_ATTR_INVALID,
  18. MVRP_ATTR_VID,
  19. __MVRP_ATTR_MAX
  20. };
  21. #define MVRP_ATTR_MAX (__MVRP_ATTR_MAX - 1)
  22. static struct mrp_application vlan_mrp_app __read_mostly = {
  23. .type = MRP_APPLICATION_MVRP,
  24. .maxattr = MVRP_ATTR_MAX,
  25. .pkttype.type = htons(ETH_P_MVRP),
  26. .group_address = MRP_MVRP_ADDRESS,
  27. .version = 0,
  28. };
  29. int vlan_mvrp_request_join(const struct net_device *dev)
  30. {
  31. const struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
  32. __be16 vlan_id = htons(vlan->vlan_id);
  33. if (vlan->vlan_proto != htons(ETH_P_8021Q))
  34. return 0;
  35. return mrp_request_join(vlan->real_dev, &vlan_mrp_app,
  36. &vlan_id, sizeof(vlan_id), MVRP_ATTR_VID);
  37. }
  38. void vlan_mvrp_request_leave(const struct net_device *dev)
  39. {
  40. const struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
  41. __be16 vlan_id = htons(vlan->vlan_id);
  42. if (vlan->vlan_proto != htons(ETH_P_8021Q))
  43. return;
  44. mrp_request_leave(vlan->real_dev, &vlan_mrp_app,
  45. &vlan_id, sizeof(vlan_id), MVRP_ATTR_VID);
  46. }
  47. int vlan_mvrp_init_applicant(struct net_device *dev)
  48. {
  49. return mrp_init_applicant(dev, &vlan_mrp_app);
  50. }
  51. void vlan_mvrp_uninit_applicant(struct net_device *dev)
  52. {
  53. mrp_uninit_applicant(dev, &vlan_mrp_app);
  54. }
  55. int __init vlan_mvrp_init(void)
  56. {
  57. return mrp_register_application(&vlan_mrp_app);
  58. }
  59. void vlan_mvrp_uninit(void)
  60. {
  61. mrp_unregister_application(&vlan_mrp_app);
  62. }