M
Mark
Hi
Trying to understand some application dealing with VLANs and can't figure
out what this piece of code does:
#define MAX_PORTS_IN_UNIT 28
#define MAX_VLAN_ID 4095
#define VLAN_BITMAP_ARRAY_SIZE (MAX_VLAN_ID/32+1)
unsigned long vlan_member_array[VLAN_BITMAP_ARRAY_SIZE];
int sw_is_set_vlan_bit(unsigned long *VlanBitArray, int vlan_id)
{
return (VlanBitArray[(vlan_id - 1) / 32] & (1 << ((vlan_id - 1) % 32)));
}
....
int port;
for (port = 0; port < MAX_PORTS_IN_UNIT; port++) {
....
/* Set PVID for each port */
if (!sw_is_set_vlan_bit(vlan_member_array, pvid)) {
printf("PVID Error!\n");
} else {
.....
}
....
}
Here is a loop running through the ports (let's say 24) and calling
sw_is_set_vlan_bit() for each port:
The code is huge, I hope the snippet I'm providing will suffice. So my
questions are:
1) why to define an array of (MAX_VLAN_ID/32+1) size. What does it indicate?
2) what exactly does the function do?
Thanks!
Trying to understand some application dealing with VLANs and can't figure
out what this piece of code does:
#define MAX_PORTS_IN_UNIT 28
#define MAX_VLAN_ID 4095
#define VLAN_BITMAP_ARRAY_SIZE (MAX_VLAN_ID/32+1)
unsigned long vlan_member_array[VLAN_BITMAP_ARRAY_SIZE];
int sw_is_set_vlan_bit(unsigned long *VlanBitArray, int vlan_id)
{
return (VlanBitArray[(vlan_id - 1) / 32] & (1 << ((vlan_id - 1) % 32)));
}
....
int port;
for (port = 0; port < MAX_PORTS_IN_UNIT; port++) {
....
/* Set PVID for each port */
if (!sw_is_set_vlan_bit(vlan_member_array, pvid)) {
printf("PVID Error!\n");
} else {
.....
}
....
}
Here is a loop running through the ports (let's say 24) and calling
sw_is_set_vlan_bit() for each port:
The code is huge, I hope the snippet I'm providing will suffice. So my
questions are:
1) why to define an array of (MAX_VLAN_ID/32+1) size. What does it indicate?
2) what exactly does the function do?
Thanks!