mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-10-30 06:25:25 +03:00
libsystemd-network: don't use unaligned helpers in _packed_ structs
The compiler will do this for us.
This commit is contained in:
parent
617e794652
commit
c962cb68d5
@ -37,11 +37,11 @@ typedef struct DHCP6Option {
|
||||
be16_t code;
|
||||
be16_t len;
|
||||
uint8_t data[];
|
||||
} DHCP6Option;
|
||||
} _packed_ DHCP6Option;
|
||||
|
||||
static int option_append_hdr(uint8_t **buf, size_t *buflen, uint16_t optcode,
|
||||
size_t optlen) {
|
||||
DHCP6Option *option = (DHCP6Option*) *buf; /* unaligned! */
|
||||
DHCP6Option *option = (DHCP6Option*) *buf;
|
||||
|
||||
assert_return(buf, -EINVAL);
|
||||
assert_return(*buf, -EINVAL);
|
||||
@ -50,8 +50,8 @@ static int option_append_hdr(uint8_t **buf, size_t *buflen, uint16_t optcode,
|
||||
if (optlen > 0xffff || *buflen < optlen + sizeof(DHCP6Option))
|
||||
return -ENOBUFS;
|
||||
|
||||
unaligned_write_be16(&option->code, optcode);
|
||||
unaligned_write_be16(&option->len, (uint16_t) optlen);
|
||||
option->code = htobe16(optcode);
|
||||
option->len = htobe16(optlen);
|
||||
|
||||
*buf += sizeof(DHCP6Option);
|
||||
*buflen -= sizeof(DHCP6Option);
|
||||
@ -136,9 +136,8 @@ int dhcp6_option_append_ia(uint8_t **buf, size_t *buflen, DHCP6IA *ia) {
|
||||
}
|
||||
|
||||
|
||||
static int option_parse_hdr(uint8_t **buf, size_t *buflen, uint16_t *optcode,
|
||||
size_t *optlen) {
|
||||
DHCP6Option *option = (DHCP6Option*) *buf; /* unaligned! */
|
||||
static int option_parse_hdr(uint8_t **buf, size_t *buflen, uint16_t *optcode, size_t *optlen) {
|
||||
DHCP6Option *option = (DHCP6Option*) *buf;
|
||||
uint16_t len;
|
||||
|
||||
assert_return(buf, -EINVAL);
|
||||
@ -148,12 +147,12 @@ static int option_parse_hdr(uint8_t **buf, size_t *buflen, uint16_t *optcode,
|
||||
if (*buflen < sizeof(DHCP6Option))
|
||||
return -ENOMSG;
|
||||
|
||||
len = unaligned_read_be16(&option->len);
|
||||
len = be16toh(option->len);
|
||||
|
||||
if (len > *buflen)
|
||||
return -ENOMSG;
|
||||
|
||||
*optcode = unaligned_read_be16(&option->code);
|
||||
*optcode = be16toh(option->code);
|
||||
*optlen = len;
|
||||
|
||||
*buf += 4;
|
||||
|
@ -100,19 +100,13 @@ struct sd_pppoe {
|
||||
be16toh((header)->length)
|
||||
|
||||
#define PPPOE_PACKET_TAIL(packet) \
|
||||
(struct pppoe_tag *)((uint8_t*)(packet) + sizeof(struct pppoe_hdr) + PPPOE_PACKET_LENGTH(packet))
|
||||
(struct pppoe_tag*)((uint8_t*)(packet) + sizeof(struct pppoe_hdr) + PPPOE_PACKET_LENGTH(packet))
|
||||
|
||||
#define PPPOE_TAG_LENGTH(tag) \
|
||||
unaligned_read_be16(&(tag)->tag_len)
|
||||
#define PPPOE_TAG_LENGTH(tag) \
|
||||
be16toh((tag)->tag_len)
|
||||
|
||||
#define PPPOE_TAG_TYPE(tag) \
|
||||
htobe16(unaligned_read_be16(&(tag)->tag_type))
|
||||
|
||||
#define PPPOE_TAG_SET_LENGTH(tag, len) \
|
||||
unaligned_write_be16(&(tag)->tag_len, len)
|
||||
|
||||
#define PPPOE_TAG_SET_TYPE(tag, len) \
|
||||
unaligned_write_be16(&(tag)->tag_type, be16toh(len))
|
||||
#define PPPOE_TAG_TYPE(tag) \
|
||||
(tag)->tag_type
|
||||
|
||||
#define PPPOE_TAG_NEXT(tag) \
|
||||
(struct pppoe_tag *)((uint8_t *)(tag) + sizeof(struct pppoe_tag) + PPPOE_TAG_LENGTH(tag))
|
||||
@ -278,8 +272,8 @@ static void pppoe_tag_append(struct pppoe_hdr *packet, size_t packet_size, be16_
|
||||
|
||||
tag = PPPOE_PACKET_TAIL(packet);
|
||||
|
||||
PPPOE_TAG_SET_LENGTH(tag, tag_len);
|
||||
PPPOE_TAG_SET_TYPE(tag, tag_type);
|
||||
tag->tag_len = htobe16(tag_len);
|
||||
tag->tag_type = tag_type;
|
||||
if (tag_data)
|
||||
memcpy(tag->tag_data, tag_data, tag_len);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user