Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  *  IEEE 802.1Q Multiple VLAN Registration Protocol (MVRP)
0004  *
0005  *  Copyright (c) 2012 Massachusetts Institute of Technology
0006  *
0007  *  Adapted from code in net/8021q/vlan_gvrp.c
0008  *  Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
0009  */
0010 #include <linux/types.h>
0011 #include <linux/if_ether.h>
0012 #include <linux/if_vlan.h>
0013 #include <net/mrp.h>
0014 #include "vlan.h"
0015 
0016 #define MRP_MVRP_ADDRESS    { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x21 }
0017 
0018 enum mvrp_attributes {
0019     MVRP_ATTR_INVALID,
0020     MVRP_ATTR_VID,
0021     __MVRP_ATTR_MAX
0022 };
0023 #define MVRP_ATTR_MAX   (__MVRP_ATTR_MAX - 1)
0024 
0025 static struct mrp_application vlan_mrp_app __read_mostly = {
0026     .type       = MRP_APPLICATION_MVRP,
0027     .maxattr    = MVRP_ATTR_MAX,
0028     .pkttype.type   = htons(ETH_P_MVRP),
0029     .group_address  = MRP_MVRP_ADDRESS,
0030     .version    = 0,
0031 };
0032 
0033 int vlan_mvrp_request_join(const struct net_device *dev)
0034 {
0035     const struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
0036     __be16 vlan_id = htons(vlan->vlan_id);
0037 
0038     if (vlan->vlan_proto != htons(ETH_P_8021Q))
0039         return 0;
0040     return mrp_request_join(vlan->real_dev, &vlan_mrp_app,
0041                 &vlan_id, sizeof(vlan_id), MVRP_ATTR_VID);
0042 }
0043 
0044 void vlan_mvrp_request_leave(const struct net_device *dev)
0045 {
0046     const struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
0047     __be16 vlan_id = htons(vlan->vlan_id);
0048 
0049     if (vlan->vlan_proto != htons(ETH_P_8021Q))
0050         return;
0051     mrp_request_leave(vlan->real_dev, &vlan_mrp_app,
0052               &vlan_id, sizeof(vlan_id), MVRP_ATTR_VID);
0053 }
0054 
0055 int vlan_mvrp_init_applicant(struct net_device *dev)
0056 {
0057     return mrp_init_applicant(dev, &vlan_mrp_app);
0058 }
0059 
0060 void vlan_mvrp_uninit_applicant(struct net_device *dev)
0061 {
0062     mrp_uninit_applicant(dev, &vlan_mrp_app);
0063 }
0064 
0065 int __init vlan_mvrp_init(void)
0066 {
0067     return mrp_register_application(&vlan_mrp_app);
0068 }
0069 
0070 void vlan_mvrp_uninit(void)
0071 {
0072     mrp_unregister_application(&vlan_mrp_app);
0073 }