Skip to content

Commit d30e086

Browse files
Fix issues with PDU structure alignment, IPC msg processing (#73)
Co-authored-by: Sandeep Kulambi <[email protected]>
1 parent e3626a4 commit d30e086

File tree

5 files changed

+34
-26
lines changed

5 files changed

+34
-26
lines changed

include/l2.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
BYTE destination_address_DSAP;
7575
BYTE source_address_SSAP;
7676
BYTE llc_frame_type;
77-
} __attribute__((aligned(1))) LLC_HEADER;
77+
} __attribute__((__packed__)) LLC_HEADER;
7878

7979
typedef struct SNAP_HEADER
8080
{
@@ -85,13 +85,13 @@
8585

8686
BYTE protocol_id_filler[3];
8787
UINT16 protocol_id;
88-
} __attribute__((aligned(2))) SNAP_HEADER;
88+
} __attribute__((__packed__)) SNAP_HEADER;
8989

9090
typedef struct MAC_ADDRESS
9191
{
9292
UINT32 _ulong;
9393
UINT16 _ushort;
94-
} __attribute__((aligned(4))) MAC_ADDRESS;
94+
} __attribute__((__packed__)) MAC_ADDRESS;
9595

9696
#define COPY_MAC(sptr_mac2, sptr_mac1) \
9797
(memcpy(sptr_mac2, sptr_mac1, sizeof(MAC_ADDRESS)))
@@ -111,7 +111,7 @@
111111
MAC_ADDRESS source_address;
112112

113113
USHORT length;
114-
} __attribute__((aligned(4))) MAC_HEADER;
114+
} __attribute__((__packed__)) MAC_HEADER;
115115

116116
#define STP_BPDU_OFFSET (sizeof(MAC_HEADER) + sizeof(LLC_HEADER))
117117
#define PVST_BPDU_OFFSET (sizeof(MAC_HEADER) + sizeof(SNAP_HEADER))
@@ -186,4 +186,4 @@
186186
memset(_instance_mask_ptr_, 0, sizeof(L2_PROTO_INSTANCE_MASK))
187187

188188
#endif //__L2_H__
189-
189+

include/mstp_common.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ typedef struct
4545
// mac-address for the bridge
4646
MAC_ADDRESS address;
4747

48-
}__attribute__((aligned(4))) MSTP_BRIDGE_IDENTIFIER;
48+
}__attribute__((__packed__)) MSTP_BRIDGE_IDENTIFIER;
4949

5050
/*****************************************************************************/
5151
/* msti configuration message structure */
@@ -69,7 +69,7 @@ typedef struct
6969
UINT8 agreement:1;
7070
UINT8 master:1;
7171
#endif
72-
} __attribute__((aligned(4)))MSTI_FLAGS;
72+
} __attribute__((__packed__))MSTI_FLAGS;
7373

7474
/*****************************************************************************/
7575
/* msti configuration message structure */
@@ -106,7 +106,7 @@ typedef struct
106106
// mst instance remaining hops
107107
UINT8 msti_remaining_hops;
108108

109-
} __attribute__((aligned(4))) MSTI_CONFIG_MESSAGE;
109+
} __attribute__((__packed__)) MSTI_CONFIG_MESSAGE;
110110

111111
/*****************************************************************************/
112112
/* mst configuration identification */
@@ -131,7 +131,7 @@ typedef struct
131131
// the mst configuration table.
132132
UINT8 config_digest[16];
133133

134-
} __attribute__((aligned(4))) MSTP_CONFIG_IDENTIFIER;
134+
} __attribute__((__packed__)) MSTP_CONFIG_IDENTIFIER;
135135

136136
typedef struct RSTP_BPDU_FLAGS
137137
{
@@ -152,7 +152,7 @@ typedef struct RSTP_BPDU_FLAGS
152152
UINT8 agreement:1;
153153
UINT8 topology_change_acknowledgement:1;
154154
#endif
155-
} __attribute__((aligned(4))) RSTP_BPDU_FLAGS;
155+
} __attribute__((__packed__)) RSTP_BPDU_FLAGS;
156156

157157

158158
/*****************************************************************************/
@@ -223,7 +223,7 @@ typedef struct
223223
// a sequence of zero or more msti configuration messages
224224
MSTI_CONFIG_MESSAGE msti_msgs[MSTP_MAX_INSTANCES_PER_REGION];
225225

226-
} __attribute__((aligned(4))) MSTP_BPDU;
226+
} __attribute__((__packed__)) MSTP_BPDU;
227227

228228
// rstp bpdu
229229
typedef struct RSTP_BPDU
@@ -243,6 +243,6 @@ typedef struct RSTP_BPDU
243243
UINT16 hello_time;
244244
UINT16 forward_delay;
245245
UINT8 version1_length;
246-
} __attribute__((aligned(4))) RSTP_BPDU;
246+
} __attribute__((__packed__)) RSTP_BPDU;
247247

248-
#endif // //__MSTP_COMMON_H__
248+
#endif // //__MSTP_COMMON_H__

include/stp_common.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ typedef struct BRIDGE_BPDU_FLAGS
6868
UINT8 blank : 6;
6969
UINT8 topology_change_acknowledgement : 1;
7070
#endif
71-
} __attribute__((aligned(1))) BRIDGE_BPDU_FLAGS;
71+
} __attribute__((__packed__)) BRIDGE_BPDU_FLAGS;
7272

7373
typedef struct BRIDGE_IDENTIFIER
7474
{
@@ -82,7 +82,7 @@ typedef struct BRIDGE_IDENTIFIER
8282

8383
MAC_ADDRESS address;
8484

85-
} __attribute__((aligned(4))) BRIDGE_IDENTIFIER;
85+
} __attribute__((__packed__)) BRIDGE_IDENTIFIER;
8686

8787
typedef struct PORT_IDENTIFIER
8888
{
@@ -93,7 +93,7 @@ typedef struct PORT_IDENTIFIER
9393
UINT16 number : 12;
9494
UINT16 priority : 4;
9595
#endif // BIG_ENDIAN
96-
} __attribute__((aligned(2))) PORT_IDENTIFIER;
96+
} __attribute__((__packed__)) PORT_IDENTIFIER;
9797

9898
// spanning-tree configuration bpdu
9999
typedef struct STP_CONFIG_BPDU
@@ -112,7 +112,7 @@ typedef struct STP_CONFIG_BPDU
112112
UINT16 max_age;
113113
UINT16 hello_time;
114114
UINT16 forward_delay;
115-
} __attribute__((aligned(4))) STP_CONFIG_BPDU;
115+
} __attribute__((__packed__)) STP_CONFIG_BPDU;
116116

117117
// spanning-tree topology change notification bpdu
118118
typedef struct STP_TCN_BPDU
@@ -123,7 +123,7 @@ typedef struct STP_TCN_BPDU
123123
UINT8 protocol_version_id;
124124
UINT8 type;
125125
UINT8 padding[3];
126-
} __attribute__((aligned(4))) STP_TCN_BPDU;
126+
} __attribute__((__packed__)) STP_TCN_BPDU;
127127

128128
// pvst configuration bpdu
129129
typedef struct PVST_CONFIG_BPDU
@@ -145,7 +145,7 @@ typedef struct PVST_CONFIG_BPDU
145145
UINT8 padding[3];
146146
UINT16 tag_length;
147147
UINT16 vlan_id;
148-
} __attribute__((aligned(4))) PVST_CONFIG_BPDU;
148+
} __attribute__((__packed__)) PVST_CONFIG_BPDU;
149149

150150
// pvst topology change notification bpdu
151151
typedef struct PVST_TCN_BPDU
@@ -156,6 +156,6 @@ typedef struct PVST_TCN_BPDU
156156
UINT8 protocol_version_id;
157157
UINT8 type;
158158
UINT8 padding[38];
159-
} __attribute__((aligned(4))) PVST_TCN_BPDU;
159+
} __attribute__((__packed__)) PVST_TCN_BPDU;
160160

161161
#endif //__STP_COMMON_H__

include/stp_ipc.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ typedef enum STP_CTL_TYPE
6262
STP_CTL_MAX
6363
} STP_CTL_TYPE;
6464

65+
typedef enum LinkType {
66+
AUTO = 0, // Auto
67+
POINT_TO_POINT = 1, // Point-to-point
68+
SHARED = 2 // Shared
69+
} LinkType;
70+
6571
typedef struct STP_IPC_MSG
6672
{
6773
int msg_type;
@@ -137,8 +143,8 @@ typedef struct STP_PORT_CONFIG_MSG
137143
uint8_t bpdu_guard_do_disable;
138144
uint8_t portfast;
139145
uint8_t uplink_fast;
140-
int edge;
141-
uint16_t padding;
146+
uint8_t edge;
147+
LinkType link_type; // MSTP only
142148
int path_cost;
143149
int priority;
144150
int count;

stp/stp_mgr.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,14 +1899,15 @@ static void stpmgr_process_ipc_msg(STP_IPC_MSG *msg, int len, struct sockaddr_un
18991899
}
19001900
case STP_BRIDGE_CONFIG:
19011901
{
1902-
if(msg->proto_mode == L2_PVSTP)
1902+
stpmgr_process_bridge_config_msg(msg->data);
1903+
/*if(msg->proto_mode == L2_PVSTP)
19031904
{
19041905
stpmgr_process_bridge_config_msg(msg->data);
19051906
}
19061907
else if(msg->proto_mode == L2_MSTP)
19071908
{
19081909
mstpmgr_process_bridge_config_msg(msg->data);
1909-
}
1910+
}*/
19101911
break;
19111912
}
19121913
case STP_VLAN_CONFIG:
@@ -1921,14 +1922,15 @@ static void stpmgr_process_ipc_msg(STP_IPC_MSG *msg, int len, struct sockaddr_un
19211922
}
19221923
case STP_PORT_CONFIG:
19231924
{
1924-
if(msg->proto_mode == L2_PVSTP)
1925+
stpmgr_process_intf_config_msg(msg->data);
1926+
/*if(msg->proto_mode == L2_PVSTP)
19251927
{
19261928
stpmgr_process_intf_config_msg(msg->data);
19271929
}
19281930
else if(msg->proto_mode == L2_MSTP)
19291931
{
19301932
mstpmgr_process_intf_config_msg(msg->data);
1931-
}
1933+
}*/
19321934
break;
19331935
}
19341936
case STP_VLAN_MEM_CONFIG:

0 commit comments

Comments
 (0)