[Bridge] STP Explanation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

    I'm trying to modify the stp kernel files in order to implements the RSTP. I've already modify the bpdu format like this :
------------------------------------------------------------------------------------------------------------------------------------
typedef struct
{
  int	topo_change = 0;
  int	proposal = 0;
  int	port_role[2] = {0,0} ; //role du port émetteur du BPDU initialisé à UNKNOWN
  int	learning = 0;
  int   forwarding = 0;
  int   agreement = 0;
  int   topo_change_ack = 0;
}bpdu_flag;

typedef struct 
{
  unsigned char protocol[2]= {0x00,0x00}; // le type unsigned char peut être assimilé à un octet
  unsigned char version = 0x02; //convention
  unsigned char bpdu_type;
} bpdu_header;

typedef struct 
{
  bpdu_flag 	flags;
  unsigned char root_id[8];
  unsigned char root_path_cost[4];
  unsigned char bridge_id[8];
  unsigned char port_id[2];
  unsigned char message_age[2];
  unsigned char max_age[2];
  unsigned char hello_time[2];
  unsigned char forward_delay[2];
} bpdu_body;

typedef struct
{
  bpdu_header hdr;
  bpdu_body   body;
  unsigned char ver_1_len[2];// ?
}bpdu;
--------------------------------------------------------------------------------------------------------------------------

but i'm perplex with this following function in br_stp_bpdu.c :
-------------------------------------------------------------------------------------------------------------------------
void br_send_config_bpdu(struct net_bridge_port *p, struct bpdu *bpdu)
{
	unsigned char buf[38];

	buf[0] = 0x42;
	buf[1] = 0x42;
	buf[2] = 0x03;
	buf[3] = 0;
	buf[4] = 0;
	buf[5] = 0;
	buf[6] = BPDU_TYPE_CONFIG;
	buf[7] = (bpdu->topology_change ? 0x01 : 0) |
		(bpdu->topology_change_ack ? 0x80 : 0);
	buf[8] = bpdu->root.prio[0];
	buf[9] = bpdu->root.prio[1];
	buf[10] = bpdu->root.addr[0];
	buf[11] = bpdu->root.addr[1];
	buf[12] = bpdu->root.addr[2];
	buf[13] = bpdu->root.addr[3];
	buf[14] = bpdu->root.addr[4];
	buf[15] = bpdu->root.addr[5];
	buf[16] = (bpdu->root_path_cost >> 24) & 0xFF;
	buf[17] = (bpdu->root_path_cost >> 16) & 0xFF;
	buf[18] = (bpdu->root_path_cost >> 8) & 0xFF;
	buf[19] = bpdu->root_path_cost & 0xFF;
	buf[20] = bpdu->bridge_id.prio[0];
	buf[21] = bpdu->bridge_id.prio[1];
	buf[22] = bpdu->bridge_id.addr[0];
	buf[23] = bpdu->bridge_id.addr[1];
	buf[24] = bpdu->bridge_id.addr[2];
	buf[25] = bpdu->bridge_id.addr[3];
	buf[26] = bpdu->bridge_id.addr[4];
	buf[27] = bpdu->bridge_id.addr[5];
	buf[28] = (bpdu->port_id >> 8) & 0xFF;
	buf[29] = bpdu->port_id & 0xFF;

	br_set_ticks(buf+30, bpdu->message_age);
	br_set_ticks(buf+32, bpdu->max_age);
	br_set_ticks(buf+34, bpdu->hello_time);
	br_set_ticks(buf+36, bpdu->forward_delay);

	br_send_bpdu(p, buf, 38);
}
--------------------------------------------------------------------------------

Indeed I don't understand the default value from buffer[0] to buffer[7] because if I follow my new structure of bpdu i would have :
--------------------------------------------------------------------------------------------------------------------------------
void br_send_config_bpdu(struct net_bridge_port *p, struct bpdu *bpdu)
{
	unsigned char buf[42];

	buf[0] = bpdu->bpdu_header->protocol[0]; //0x00
	buf[1] = bpdu->bpdu_header->protocol[1]; //0x00
	buf[2] = bpdu->bpdu_header->version; //0x02
	buf[3] = BPDU_TYPE_CONFIG;
	buf[4] = bpdu->bpdu_body->flags->topo_change;
	buf[5] = bpdu->bpdu_body->flags->proposal;
	buf[6] = bpdu->bpdu_body->flags->port_role[0];
	buf[7] = bpdu->bpdu_body->flags->port_role[1];
	buf[8] = bpdu->bpdu_body->flags->learning;
	buf[9] = bpdu->bpdu_body->flags->forwarding;
	buf[10] = bpdu->bpdu_body->flags->agreement;
	buf[11] = bpdu->bpdu_body->flags->topo_change_ack;	
	buf[12] = bpdu->root.prio[0];
	buf[13] = bpdu->root.prio[1];
	buf[14] = bpdu->root.addr[0];
	buf[15] = bpdu->root.addr[1];
	buf[16] = bpdu->root.addr[2];
	buf[17] = bpdu->root.addr[3];
	buf[18] = bpdu->root.addr[4];
	buf[19] = bpdu->root.addr[5];
	buf[20] = (bpdu->root_path_cost >> 24) & 0xFF;
	buf[21] = (bpdu->root_path_cost >> 16) & 0xFF;
	buf[22] = (bpdu->root_path_cost >> 8) & 0xFF;
	buf[23] = bpdu->root_path_cost & 0xFF;
	buf[24] = bpdu->bridge_id.prio[0];
	buf[25] = bpdu->bridge_id.prio[1];
	buf[26] = bpdu->bridge_id.addr[0];
	buf[27] = bpdu->bridge_id.addr[1];
	buf[28] = bpdu->bridge_id.addr[2];
	buf[29] = bpdu->bridge_id.addr[3];
	buf[30] = bpdu->bridge_id.addr[4];
	buf[31] = bpdu->bridge_id.addr[5];
	buf[32] = (bpdu->port_id >> 8) & 0xFF;
	buf[33] = bpdu->port_id & 0xFF;

	br_set_ticks(buf+34, bpdu->message_age);
	br_set_ticks(buf+36, bpdu->max_age);
	br_set_ticks(buf+38, bpdu->hello_time);
	br_set_ticks(buf+40, bpdu->forward_delay);

	br_send_bpdu(p, buf, 42);
}
-------------------------------------------------------------------------------------------------

what do you think of it ?

thanks

Simon Henry


------------------------------------------

Faites un voeu et puis Voila ! www.voila.fr 





[Index of Archives]     [Netdev]     [AoE Tools]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux