Skip to content

Commit

Permalink
bonding,llc: Fix structure sizeof incompatibility for some PDUs
Browse files Browse the repository at this point in the history
With some combinations of arch/compiler (e.g. arm-linux-gcc) the sizeof
operator on structure returns value greater than expected. In cases when the
structure is used for mapping PDU fields it may lead to unexpected results
(such as holes and alignment problems in skb data). __packed prevents this
undesired behavior.

Signed-off-by: Vitalii Demianets <vitas@nppfactor.kiev.ua>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Vitalii Demianets authored and David S. Miller committed May 13, 2011
1 parent ca06707 commit a10e146
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions drivers/net/bonding/bond_3ad.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

typedef struct mac_addr {
u8 mac_addr_value[ETH_ALEN];
} mac_addr_t;
} __packed mac_addr_t;

enum {
BOND_AD_STABLE = 0,
Expand Down Expand Up @@ -134,12 +134,12 @@ typedef struct lacpdu {
u8 tlv_type_terminator; // = terminator
u8 terminator_length; // = 0
u8 reserved_50[50]; // = 0
} lacpdu_t;
} __packed lacpdu_t;

typedef struct lacpdu_header {
struct ethhdr hdr;
struct lacpdu lacpdu;
} lacpdu_header_t;
} __packed lacpdu_header_t;

// Marker Protocol Data Unit(PDU) structure(43.5.3.2 in the 802.3ad standard)
typedef struct bond_marker {
Expand All @@ -155,12 +155,12 @@ typedef struct bond_marker {
u8 tlv_type_terminator; // = 0x00
u8 terminator_length; // = 0x00
u8 reserved_90[90]; // = 0
} bond_marker_t;
} __packed bond_marker_t;

typedef struct bond_marker_header {
struct ethhdr hdr;
struct bond_marker marker;
} bond_marker_header_t;
} __packed bond_marker_header_t;

#pragma pack()

Expand Down
8 changes: 4 additions & 4 deletions include/net/llc_pdu.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ struct llc_pdu_sn {
u8 ssap;
u8 ctrl_1;
u8 ctrl_2;
};
} __packed;

static inline struct llc_pdu_sn *llc_pdu_sn_hdr(struct sk_buff *skb)
{
Expand All @@ -211,7 +211,7 @@ struct llc_pdu_un {
u8 dsap;
u8 ssap;
u8 ctrl_1;
};
} __packed;

static inline struct llc_pdu_un *llc_pdu_un_hdr(struct sk_buff *skb)
{
Expand Down Expand Up @@ -359,7 +359,7 @@ struct llc_xid_info {
u8 fmt_id; /* always 0x81 for LLC */
u8 type; /* different if NULL/non-NULL LSAP */
u8 rw; /* sender receive window */
};
} __packed;

/**
* llc_pdu_init_as_xid_cmd - sets bytes 3, 4 & 5 of LLC header as XID
Expand Down Expand Up @@ -415,7 +415,7 @@ struct llc_frmr_info {
u8 curr_ssv; /* current send state variable val */
u8 curr_rsv; /* current receive state variable */
u8 ind_bits; /* indicator bits set with macro */
};
} __packed;

extern void llc_pdu_set_cmd_rsp(struct sk_buff *skb, u8 type);
extern void llc_pdu_set_pf_bit(struct sk_buff *skb, u8 bit_value);
Expand Down

0 comments on commit a10e146

Please sign in to comment.