net/icmpv6: align structs to 2 bytes.

Fix following misaligned errors:

icmpv6/icmpv6_radvertise.c:145:21: runtime error: member access within misaligned address 0x573da9e6 for type 'struct icmpv6_router_advertise_s', which requires 4 byte alignment
0x573da9e6: note: pointer points here
 00 00 00 01 85 00  d6 14 00 00 00 00 01 01  12 8c 25 08 9c f8 04 00  00 00 ff 02 00 00 00 00  00 00
             ^
icmpv6/icmpv6_radvertise.c:167:21: runtime error: member access within misaligned address 0x573da9fe for type 'struct icmpv6_mtu_s', which requires 4 byte alignment
0x573da9fe: note: pointer points here
 af 78 ab 72 00 00  00 00 00 00 00 01 ff 00  00 01 04 00 00 00 ff 02  00 00 00 00 00 00 00 00  00 01
             ^
icmpv6/icmpv6_radvertise.c:176:23: runtime error: member access within misaligned address 0x573daa06 for type 'struct icmpv6_prefixinfo_s', which requires 4 byte alignment
0x573daa06: note: pointer points here
 00 00 05 dc ff 00  00 01 04 00 00 00 ff 02  00 00 00 00 00 00 00 00  00 01 ff 08 9c f8 04 00  00 00
             ^

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
Zhe Weng 2023-01-04 17:48:34 +08:00 committed by Alin Jerpelea
parent 61e996af33
commit 7b0d80c94a
3 changed files with 23 additions and 18 deletions

View File

@ -258,8 +258,8 @@ struct icmpv6_router_advertise_s
uint8_t hoplimit; /* Current hop limit */ uint8_t hoplimit; /* Current hop limit */
uint8_t flags; /* See ICMPv6_RADV_FLAG_* definitions */ uint8_t flags; /* See ICMPv6_RADV_FLAG_* definitions */
uint16_t lifetime; /* Router lifetime */ uint16_t lifetime; /* Router lifetime */
uint32_t reachable; /* Reachable time */ uint16_t reachable[2]; /* Reachable time */
uint32_t retrans; /* Retransmission timer */ uint16_t retrans[2]; /* Retransmission timer */
/* Options begin here */ /* Options begin here */
}; };
@ -329,8 +329,8 @@ struct icmpv6_prefixinfo_s
uint8_t optlen; /* " " ": Option length: 4 octets */ uint8_t optlen; /* " " ": Option length: 4 octets */
uint8_t preflen; /* " " ": Prefix length */ uint8_t preflen; /* " " ": Prefix length */
uint8_t flags; /* " " ": Flags */ uint8_t flags; /* " " ": Flags */
uint32_t vlifetime; /* " " ": Valid lifetime */ uint16_t vlifetime[2]; /* " " ": Valid lifetime */
uint32_t plifetime; /* Octet 2: Preferred lifetime */ uint16_t plifetime[2]; /* Octet 2: Preferred lifetime */
uint16_t reserved[2]; /* " " ": Reserved */ uint16_t reserved[2]; /* " " ": Reserved */
uint16_t prefix[8]; /* Octets 3-4: Prefix */ uint16_t prefix[8]; /* Octets 3-4: Prefix */
}; };
@ -348,7 +348,7 @@ struct icmpv6_mtu_s
uint8_t opttype; /* Octet 1: Option Type: ICMPv6_OPT_MTU */ uint8_t opttype; /* Octet 1: Option Type: ICMPv6_OPT_MTU */
uint8_t optlen; /* " " ": Option length: 1 octet */ uint8_t optlen; /* " " ": Option length: 1 octet */
uint16_t reserved; /* " " ": Reserved */ uint16_t reserved; /* " " ": Reserved */
uint32_t mtu; /* " " ": MTU */ uint16_t mtu[2]; /* " " ": MTU */
}; };
/* The structure holding the ICMP statistics that are gathered if /* The structure holding the ICMP statistics that are gathered if

View File

@ -353,7 +353,7 @@ void icmpv6_input(FAR struct net_driver_s *dev, unsigned int iplen)
{ {
FAR struct icmpv6_mtu_s *mtuopt = FAR struct icmpv6_mtu_s *mtuopt =
(FAR struct icmpv6_mtu_s *)opt; (FAR struct icmpv6_mtu_s *)opt;
dev->d_pktsize = NTOHL(mtuopt->mtu) + dev->d_llhdrlen; dev->d_pktsize = NTOHS(mtuopt->mtu[1]) + dev->d_llhdrlen;
} }
break; break;

View File

@ -147,8 +147,10 @@ void icmpv6_radvertise(FAR struct net_driver_s *dev)
adv->hoplimit = 64; /* Current hop limit */ adv->hoplimit = 64; /* Current hop limit */
adv->flags = ICMPv6_RADV_FLAG_M; /* Managed address flag. */ adv->flags = ICMPv6_RADV_FLAG_M; /* Managed address flag. */
adv->lifetime = HTONS(1800); /* Router lifetime */ adv->lifetime = HTONS(1800); /* Router lifetime */
adv->reachable = 0; /* Reachable time */ adv->reachable[0] = 0; /* Reachable time */
adv->retrans = 0; /* Retransmission timer */ adv->reachable[1] = 0;
adv->retrans[0] = 0; /* Retransmission timer */
adv->retrans[1] = 0;
/* Set up the source address option */ /* Set up the source address option */
@ -167,7 +169,8 @@ void icmpv6_radvertise(FAR struct net_driver_s *dev)
mtu->opttype = ICMPv6_OPT_MTU; mtu->opttype = ICMPv6_OPT_MTU;
mtu->optlen = 1; mtu->optlen = 1;
mtu->reserved = 0; mtu->reserved = 0;
mtu->mtu = HTONL(dev->d_pktsize - dev->d_llhdrlen); mtu->mtu[0] = 0;
mtu->mtu[1] = HTONS(dev->d_pktsize - dev->d_llhdrlen);
/* Set up the prefix option */ /* Set up the prefix option */
@ -176,8 +179,10 @@ void icmpv6_radvertise(FAR struct net_driver_s *dev)
prefix->opttype = ICMPv6_OPT_PREFIX; prefix->opttype = ICMPv6_OPT_PREFIX;
prefix->optlen = 4; prefix->optlen = 4;
prefix->flags = ICMPv6_PRFX_FLAG_L | ICMPv6_PRFX_FLAG_A; prefix->flags = ICMPv6_PRFX_FLAG_L | ICMPv6_PRFX_FLAG_A;
prefix->vlifetime = HTONL(2592000); prefix->vlifetime[0] = HTONS(2592000 >> 16);
prefix->plifetime = HTONL(604800); prefix->vlifetime[1] = HTONS(2592000 & 0xffff);
prefix->plifetime[0] = HTONS(604800 >> 16);
prefix->plifetime[1] = HTONS(604800 & 0xffff);
prefix->reserved[0] = 0; prefix->reserved[0] = 0;
prefix->reserved[1] = 0; prefix->reserved[1] = 0;