net: ipv4: Remove in_addr from packed net_ipv4_hdr struct

Replace unpacked in_addr structures with raw buffers in net_ipv4_hdr
struct, to prevent compiler warnings about unaligned access.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2021-10-04 14:40:22 +02:00 committed by Anas Nashif
commit 064200b420
18 changed files with 94 additions and 88 deletions

View file

@ -86,10 +86,10 @@ static int loopback_send(const struct device *dev, struct net_pkt *pkt)
} else { } else {
struct in_addr addr; struct in_addr addr;
net_ipaddr_copy(&addr, &NET_IPV4_HDR(pkt)->src); net_ipv4_addr_copy_raw((uint8_t *)&addr, NET_IPV4_HDR(pkt)->src);
net_ipaddr_copy(&NET_IPV4_HDR(pkt)->src, net_ipv4_addr_copy_raw(NET_IPV4_HDR(pkt)->src,
&NET_IPV4_HDR(pkt)->dst); NET_IPV4_HDR(pkt)->dst);
net_ipaddr_copy(&NET_IPV4_HDR(pkt)->dst, &addr); net_ipv4_addr_copy_raw(NET_IPV4_HDR(pkt)->dst, (uint8_t *)&addr);
} }
/* We should simulate normal driver meaning that if the packet is /* We should simulate normal driver meaning that if the packet is

View file

@ -486,8 +486,8 @@ struct net_ipv4_hdr {
uint8_t ttl; uint8_t ttl;
uint8_t proto; uint8_t proto;
uint16_t chksum; uint16_t chksum;
struct in_addr src; uint8_t src[NET_IPV4_ADDR_SIZE];
struct in_addr dst; uint8_t dst[NET_IPV4_ADDR_SIZE];
} __packed; } __packed;
struct net_icmp_hdr { struct net_icmp_hdr {

View file

@ -50,7 +50,7 @@ struct session *get_session(struct net_pkt *pkt,
if (net_pkt_family(pkt) == AF_INET6) { if (net_pkt_family(pkt) == AF_INET6) {
net_ipaddr_copy(&ipv6, &ip_hdr->ipv6->src); net_ipaddr_copy(&ipv6, &ip_hdr->ipv6->src);
} else if (net_pkt_family(pkt) == AF_INET) { } else if (net_pkt_family(pkt) == AF_INET) {
net_ipaddr_copy(&ipv4, &ip_hdr->ipv4->src); net_ipv4_addr_copy_raw((uint8_t *)&ipv4, ip_hdr->ipv4->src);
} else { } else {
printk("Error! unsupported protocol %d\n", printk("Error! unsupported protocol %d\n",
net_pkt_family(pkt)); net_pkt_family(pkt));

View file

@ -44,8 +44,8 @@ static inline void set_dst_addr(const struct shell *shell,
} }
if (IS_ENABLED(CONFIG_NET_IPV4) && family == AF_INET) { if (IS_ENABLED(CONFIG_NET_IPV4) && family == AF_INET) {
net_ipaddr_copy(&net_sin(dst_addr)->sin_addr, net_ipv4_addr_copy_raw((uint8_t *)&net_sin(dst_addr)->sin_addr,
&ip_hdr->ipv4->src); ip_hdr->ipv4->src);
net_sin(dst_addr)->sin_family = AF_INET; net_sin(dst_addr)->sin_family = AF_INET;
net_sin(dst_addr)->sin_port = udp_hdr->src_port; net_sin(dst_addr)->sin_port = udp_hdr->src_port;
} }

View file

@ -440,17 +440,17 @@ static bool conn_addr_cmp(struct net_pkt *pkt,
} else if (IS_ENABLED(CONFIG_NET_IPV4) && } else if (IS_ENABLED(CONFIG_NET_IPV4) &&
net_pkt_family(pkt) == AF_INET && net_pkt_family(pkt) == AF_INET &&
addr->sa_family == AF_INET) { addr->sa_family == AF_INET) {
struct in_addr *addr4; uint8_t *addr4;
if (is_remote) { if (is_remote) {
addr4 = &ip_hdr->ipv4->src; addr4 = ip_hdr->ipv4->src;
} else { } else {
addr4 = &ip_hdr->ipv4->dst; addr4 = ip_hdr->ipv4->dst;
} }
if (net_sin(addr)->sin_addr.s_addr) { if (net_sin(addr)->sin_addr.s_addr) {
if (!net_ipv4_addr_cmp(&net_sin(addr)->sin_addr, if (!net_ipv4_addr_cmp_raw((uint8_t *)&net_sin(addr)->sin_addr,
addr4)) { addr4)) {
return false; return false;
} }
} }
@ -494,9 +494,9 @@ static bool conn_are_end_points_valid(struct net_pkt *pkt,
} }
if (IS_ENABLED(CONFIG_NET_IPV4) && net_pkt_family(pkt) == AF_INET) { if (IS_ENABLED(CONFIG_NET_IPV4) && net_pkt_family(pkt) == AF_INET) {
if (net_ipv4_addr_cmp(&ip_hdr->ipv4->src, if (net_ipv4_addr_cmp_raw(ip_hdr->ipv4->src,
&ip_hdr->ipv4->dst) || ip_hdr->ipv4->dst) ||
net_ipv4_is_my_addr(&ip_hdr->ipv4->src)) { net_ipv4_is_my_addr((struct in_addr *)ip_hdr->ipv4->src)) {
my_src_addr = true; my_src_addr = true;
} }
} else if (IS_ENABLED(CONFIG_NET_IPV6) && } else if (IS_ENABLED(CONFIG_NET_IPV6) &&
@ -614,10 +614,10 @@ enum net_verdict net_conn_input(struct net_pkt *pkt,
* need to deliver the packet to multiple recipients. * need to deliver the packet to multiple recipients.
*/ */
if (IS_ENABLED(CONFIG_NET_IPV4) && net_pkt_family(pkt) == AF_INET) { if (IS_ENABLED(CONFIG_NET_IPV4) && net_pkt_family(pkt) == AF_INET) {
if (net_ipv4_is_addr_mcast(&ip_hdr->ipv4->dst)) { if (net_ipv4_is_addr_mcast((struct in_addr *)ip_hdr->ipv4->dst)) {
is_mcast_pkt = true; is_mcast_pkt = true;
} else if (net_if_ipv4_is_addr_bcast(pkt_iface, } else if (net_if_ipv4_is_addr_bcast(
&ip_hdr->ipv4->dst)) { pkt_iface, (struct in_addr *)ip_hdr->ipv4->dst)) {
is_bcast_pkt = true; is_bcast_pkt = true;
} }
} else if (IS_ENABLED(CONFIG_NET_IPV6) && } else if (IS_ENABLED(CONFIG_NET_IPV6) &&

View file

@ -418,7 +418,7 @@ static enum net_verdict icmpv4_handle_echo_request(struct net_pkt *pkt,
/* If interface can not select src address based on dst addr /* If interface can not select src address based on dst addr
* and src address is unspecified, drop the echo request. * and src address is unspecified, drop the echo request.
*/ */
if (net_ipv4_is_addr_unspecified(&ip_hdr->src)) { if (net_ipv4_is_addr_unspecified((struct in_addr *)ip_hdr->src)) {
NET_DBG("DROP: src addr is unspecified"); NET_DBG("DROP: src addr is unspecified");
goto drop; goto drop;
} }
@ -445,15 +445,16 @@ static enum net_verdict icmpv4_handle_echo_request(struct net_pkt *pkt,
goto drop; goto drop;
} }
if (net_ipv4_is_addr_mcast(&ip_hdr->dst) || if (net_ipv4_is_addr_mcast((struct in_addr *)ip_hdr->dst) ||
net_ipv4_is_addr_bcast(net_pkt_iface(pkt), &ip_hdr->dst)) { net_ipv4_is_addr_bcast(net_pkt_iface(pkt),
(struct in_addr *)ip_hdr->dst)) {
src = net_if_ipv4_select_src_addr(net_pkt_iface(pkt), src = net_if_ipv4_select_src_addr(net_pkt_iface(pkt),
&ip_hdr->dst); (struct in_addr *)ip_hdr->dst);
} else { } else {
src = &ip_hdr->dst; src = (struct in_addr *)ip_hdr->dst;
} }
if (net_ipv4_create(reply, src, &ip_hdr->src)) { if (net_ipv4_create(reply, src, (struct in_addr *)ip_hdr->src)) {
goto drop; goto drop;
} }
@ -618,7 +619,8 @@ int net_icmpv4_send_error(struct net_pkt *orig, uint8_t type, uint8_t code)
goto drop_no_pkt; goto drop_no_pkt;
} }
if (net_ipv4_create(pkt, &ip_hdr->dst, &ip_hdr->src) || if (net_ipv4_create(pkt, (struct in_addr *)ip_hdr->dst,
(struct in_addr *)ip_hdr->src) ||
icmpv4_create(pkt, type, code) || icmpv4_create(pkt, type, code) ||
net_pkt_memset(pkt, 0, NET_ICMPV4_UNUSED_LEN) || net_pkt_memset(pkt, 0, NET_ICMPV4_UNUSED_LEN) ||
net_pkt_copy(pkt, orig, copy_len)) { net_pkt_copy(pkt, orig, copy_len)) {
@ -680,7 +682,8 @@ enum net_verdict net_icmpv4_input(struct net_pkt *pkt,
goto drop; goto drop;
} }
if (net_ipv4_is_addr_bcast(net_pkt_iface(pkt), &ip_hdr->dst) && if (net_ipv4_is_addr_bcast(net_pkt_iface(pkt),
(struct in_addr *)ip_hdr->dst) &&
(!IS_ENABLED(CONFIG_NET_ICMPV4_ACCEPT_BROADCAST) || (!IS_ENABLED(CONFIG_NET_ICMPV4_ACCEPT_BROADCAST) ||
icmp_hdr->type != NET_ICMPV4_ECHO_REQUEST)) { icmp_hdr->type != NET_ICMPV4_ECHO_REQUEST)) {
NET_DBG("DROP: broadcast pkt"); NET_DBG("DROP: broadcast pkt");

View file

@ -189,7 +189,7 @@ enum net_verdict net_ipv4_igmp_input(struct net_pkt *pkt,
/* TODO: receive from arbitrary group address instead of /* TODO: receive from arbitrary group address instead of
* all_systems * all_systems
*/ */
if (!net_ipv4_addr_cmp(&ip_hdr->dst, &all_systems)) { if (!net_ipv4_addr_cmp_raw(ip_hdr->dst, (uint8_t *)&all_systems)) {
NET_DBG("DROP: Invalid dst address"); NET_DBG("DROP: Invalid dst address");
return NET_DROP; return NET_DROP;
} }

View file

@ -63,8 +63,8 @@ int net_ipv4_create_full(struct net_pkt *pkt,
ipv4_hdr->proto = 0U; ipv4_hdr->proto = 0U;
ipv4_hdr->chksum = 0U; ipv4_hdr->chksum = 0U;
net_ipaddr_copy(&ipv4_hdr->dst, dst); net_ipv4_addr_copy_raw(ipv4_hdr->dst, (uint8_t *)dst);
net_ipaddr_copy(&ipv4_hdr->src, src); net_ipv4_addr_copy_raw(ipv4_hdr->src, (uint8_t *)src);
net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv4_hdr)); net_pkt_set_ip_hdr_len(pkt, sizeof(struct net_ipv4_hdr));
@ -268,17 +268,17 @@ enum net_verdict net_ipv4_input(struct net_pkt *pkt)
net_pkt_update_length(pkt, pkt_len); net_pkt_update_length(pkt, pkt_len);
} }
if (net_ipv4_is_addr_mcast(&hdr->src)) { if (net_ipv4_is_addr_mcast((struct in_addr *)hdr->src)) {
NET_DBG("DROP: src addr is %s", "mcast"); NET_DBG("DROP: src addr is %s", "mcast");
goto drop; goto drop;
} }
if (net_ipv4_is_addr_bcast(net_pkt_iface(pkt), &hdr->src)) { if (net_ipv4_is_addr_bcast(net_pkt_iface(pkt), (struct in_addr *)hdr->src)) {
NET_DBG("DROP: src addr is %s", "bcast"); NET_DBG("DROP: src addr is %s", "bcast");
goto drop; goto drop;
} }
if (net_ipv4_is_addr_unspecified(&hdr->src)) { if (net_ipv4_is_addr_unspecified((struct in_addr *)hdr->src)) {
NET_DBG("DROP: src addr is %s", "unspecified"); NET_DBG("DROP: src addr is %s", "unspecified");
goto drop; goto drop;
} }
@ -289,16 +289,16 @@ enum net_verdict net_ipv4_input(struct net_pkt *pkt)
goto drop; goto drop;
} }
if ((!net_ipv4_is_my_addr(&hdr->dst) && if ((!net_ipv4_is_my_addr((struct in_addr *)hdr->dst) &&
!net_ipv4_is_addr_mcast(&hdr->dst) && !net_ipv4_is_addr_mcast((struct in_addr *)hdr->dst) &&
!(hdr->proto == IPPROTO_UDP && !(hdr->proto == IPPROTO_UDP &&
(net_ipv4_addr_cmp(&hdr->dst, net_ipv4_broadcast_address()) || (net_ipv4_addr_cmp((struct in_addr *)hdr->dst, net_ipv4_broadcast_address()) ||
/* RFC 1122 ch. 3.3.6 The 0.0.0.0 is non-standard bcast addr */ /* RFC 1122 ch. 3.3.6 The 0.0.0.0 is non-standard bcast addr */
(IS_ENABLED(CONFIG_NET_IPV4_ACCEPT_ZERO_BROADCAST) && (IS_ENABLED(CONFIG_NET_IPV4_ACCEPT_ZERO_BROADCAST) &&
net_ipv4_addr_cmp(&hdr->dst, net_ipv4_addr_cmp((struct in_addr *)hdr->dst,
net_ipv4_unspecified_address()))))) || net_ipv4_unspecified_address()))))) ||
(hdr->proto == IPPROTO_TCP && (hdr->proto == IPPROTO_TCP &&
net_ipv4_is_addr_bcast(net_pkt_iface(pkt), &hdr->dst))) { net_ipv4_is_addr_bcast(net_pkt_iface(pkt), (struct in_addr *)hdr->dst))) {
NET_DBG("DROP: not for me"); NET_DBG("DROP: not for me");
goto drop; goto drop;
} }
@ -355,7 +355,7 @@ enum net_verdict net_ipv4_input(struct net_pkt *pkt)
struct net_addr remote_addr; struct net_addr remote_addr;
remote_addr.family = AF_INET; remote_addr.family = AF_INET;
net_ipaddr_copy(&remote_addr.in_addr, &hdr->src); net_ipv4_addr_copy_raw((uint8_t *)&remote_addr.in_addr, hdr->src);
/* Get rid of the old IP header */ /* Get rid of the old IP header */
net_pkt_cursor_restore(pkt, &hdr_start); net_pkt_cursor_restore(pkt, &hdr_start);

View file

@ -246,7 +246,7 @@ static inline int check_ip_addr(struct net_pkt *pkt)
#if defined(CONFIG_NET_IPV4) #if defined(CONFIG_NET_IPV4)
if (net_pkt_family(pkt) == AF_INET) { if (net_pkt_family(pkt) == AF_INET) {
if (net_ipv4_addr_cmp(&NET_IPV4_HDR(pkt)->dst, if (net_ipv4_addr_cmp((struct in_addr *)NET_IPV4_HDR(pkt)->dst,
net_ipv4_unspecified_address())) { net_ipv4_unspecified_address())) {
NET_DBG("IPv4 dst address missing"); NET_DBG("IPv4 dst address missing");
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
@ -255,19 +255,19 @@ static inline int check_ip_addr(struct net_pkt *pkt)
/* If the destination address is our own, then route it /* If the destination address is our own, then route it
* back to us. * back to us.
*/ */
if (net_ipv4_is_addr_loopback(&NET_IPV4_HDR(pkt)->dst) || if (net_ipv4_is_addr_loopback((struct in_addr *)NET_IPV4_HDR(pkt)->dst) ||
(net_ipv4_is_addr_bcast(net_pkt_iface(pkt), (net_ipv4_is_addr_bcast(net_pkt_iface(pkt),
&NET_IPV4_HDR(pkt)->dst) == false && (struct in_addr *)NET_IPV4_HDR(pkt)->dst) == false &&
net_ipv4_is_my_addr(&NET_IPV4_HDR(pkt)->dst))) { net_ipv4_is_my_addr((struct in_addr *)NET_IPV4_HDR(pkt)->dst))) {
struct in_addr addr; struct in_addr addr;
/* Swap the addresses so that in receiving side /* Swap the addresses so that in receiving side
* the packet is accepted. * the packet is accepted.
*/ */
net_ipaddr_copy(&addr, &NET_IPV4_HDR(pkt)->src); net_ipv4_addr_copy_raw((uint8_t *)&addr, NET_IPV4_HDR(pkt)->src);
net_ipaddr_copy(&NET_IPV4_HDR(pkt)->src, net_ipv4_addr_copy_raw(NET_IPV4_HDR(pkt)->src,
&NET_IPV4_HDR(pkt)->dst); NET_IPV4_HDR(pkt)->dst);
net_ipaddr_copy(&NET_IPV4_HDR(pkt)->dst, &addr); net_ipv4_addr_copy_raw(NET_IPV4_HDR(pkt)->dst, (uint8_t *)&addr);
return 1; return 1;
} }
@ -276,7 +276,7 @@ static inline int check_ip_addr(struct net_pkt *pkt)
* as having src 127.0.0.0/8 is perfectly ok if dst is in * as having src 127.0.0.0/8 is perfectly ok if dst is in
* localhost subnet too. * localhost subnet too.
*/ */
if (net_ipv4_is_addr_loopback(&NET_IPV4_HDR(pkt)->src)) { if (net_ipv4_is_addr_loopback((struct in_addr *)NET_IPV4_HDR(pkt)->src)) {
NET_DBG("IPv4 loopback src address"); NET_DBG("IPv4 loopback src address");
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
} }

View file

@ -161,9 +161,9 @@ static int tcp_endpoint_set(union tcp_endpoint *ep, struct net_pkt *pkt,
ep->sin.sin_port = src == TCP_EP_SRC ? th_sport(th) : ep->sin.sin_port = src == TCP_EP_SRC ? th_sport(th) :
th_dport(th); th_dport(th);
net_ipaddr_copy(&ep->sin.sin_addr, net_ipv4_addr_copy_raw((uint8_t *)&ep->sin.sin_addr,
src == TCP_EP_SRC ? src == TCP_EP_SRC ?
&ip->src : &ip->dst); ip->src : ip->dst);
ep->sa.sa_family = AF_INET; ep->sa.sa_family = AF_INET;
} else { } else {
ret = -EINVAL; ret = -EINVAL;
@ -828,8 +828,10 @@ static int net_tcp_set_mss_opt(struct tcp *conn, struct net_pkt *pkt)
static bool is_destination_local(struct net_pkt *pkt) static bool is_destination_local(struct net_pkt *pkt)
{ {
if (IS_ENABLED(CONFIG_NET_IPV4) && net_pkt_family(pkt) == AF_INET) { if (IS_ENABLED(CONFIG_NET_IPV4) && net_pkt_family(pkt) == AF_INET) {
if (net_ipv4_is_addr_loopback(&NET_IPV4_HDR(pkt)->dst) || if (net_ipv4_is_addr_loopback(
net_ipv4_is_my_addr(&NET_IPV4_HDR(pkt)->dst)) { (struct in_addr *)NET_IPV4_HDR(pkt)->dst) ||
net_ipv4_is_my_addr(
(struct in_addr *)NET_IPV4_HDR(pkt)->dst)) {
return true; return true;
} }
} }

View file

@ -179,9 +179,9 @@ enum net_verdict ethernet_check_ipv4_bcast_addr(struct net_pkt *pkt,
struct net_eth_hdr *hdr) struct net_eth_hdr *hdr)
{ {
if (net_eth_is_addr_broadcast(&hdr->dst) && if (net_eth_is_addr_broadcast(&hdr->dst) &&
!(net_ipv4_is_addr_mcast(&NET_IPV4_HDR(pkt)->dst) || !(net_ipv4_is_addr_mcast((struct in_addr *)NET_IPV4_HDR(pkt)->dst) ||
net_ipv4_is_addr_bcast(net_pkt_iface(pkt), net_ipv4_is_addr_bcast(net_pkt_iface(pkt),
&NET_IPV4_HDR(pkt)->dst))) { (struct in_addr *)NET_IPV4_HDR(pkt)->dst))) {
return NET_DROP; return NET_DROP;
} }
@ -353,8 +353,8 @@ drop:
static inline bool ethernet_ipv4_dst_is_broadcast_or_mcast(struct net_pkt *pkt) static inline bool ethernet_ipv4_dst_is_broadcast_or_mcast(struct net_pkt *pkt)
{ {
if (net_ipv4_is_addr_bcast(net_pkt_iface(pkt), if (net_ipv4_is_addr_bcast(net_pkt_iface(pkt),
&NET_IPV4_HDR(pkt)->dst) || (struct in_addr *)NET_IPV4_HDR(pkt)->dst) ||
net_ipv4_is_addr_mcast(&NET_IPV4_HDR(pkt)->dst)) { net_ipv4_is_addr_mcast((struct in_addr *)NET_IPV4_HDR(pkt)->dst)) {
return true; return true;
} }
@ -365,9 +365,10 @@ static bool ethernet_fill_in_dst_on_ipv4_mcast(struct net_pkt *pkt,
struct net_eth_addr *dst) struct net_eth_addr *dst)
{ {
if (net_pkt_family(pkt) == AF_INET && if (net_pkt_family(pkt) == AF_INET &&
net_ipv4_is_addr_mcast(&NET_IPV4_HDR(pkt)->dst)) { net_ipv4_is_addr_mcast((struct in_addr *)NET_IPV4_HDR(pkt)->dst)) {
/* Multicast address */ /* Multicast address */
net_eth_ipv4_mcast_to_mac_addr(&NET_IPV4_HDR(pkt)->dst, dst); net_eth_ipv4_mcast_to_mac_addr(
(struct in_addr *)NET_IPV4_HDR(pkt)->dst, dst);
return true; return true;
} }
@ -385,7 +386,7 @@ static struct net_pkt *ethernet_ll_prepare_on_ipv4(struct net_if *iface,
if (IS_ENABLED(CONFIG_NET_ARP)) { if (IS_ENABLED(CONFIG_NET_ARP)) {
struct net_pkt *arp_pkt; struct net_pkt *arp_pkt;
arp_pkt = net_arp_prepare(pkt, &NET_IPV4_HDR(pkt)->dst, NULL); arp_pkt = net_arp_prepare(pkt, (struct in_addr *)NET_IPV4_HDR(pkt)->dst, NULL);
if (!arp_pkt) { if (!arp_pkt) {
return NULL; return NULL;
} }
@ -461,7 +462,7 @@ static enum net_verdict set_vlan_tag(struct ethernet_context *ctx,
if (net_pkt_family(pkt) == AF_INET) { if (net_pkt_family(pkt) == AF_INET) {
struct net_if *target; struct net_if *target;
if (net_if_ipv4_addr_lookup(&NET_IPV4_HDR(pkt)->src, if (net_if_ipv4_addr_lookup((struct in_addr *)NET_IPV4_HDR(pkt)->src,
&target)) { &target)) {
if (target != iface) { if (target != iface) {
NET_DBG("Iface %p should be %p", iface, NET_DBG("Iface %p should be %p", iface,

View file

@ -368,7 +368,7 @@ static enum net_verdict interface_input(struct net_if *input_iface,
return NET_DROP; return NET_DROP;
} }
iface = net_if_ipv4_select_src_iface(&hdr->dst); iface = net_if_ipv4_select_src_iface((struct in_addr *)hdr->dst);
if (iface == NULL) { if (iface == NULL) {
NET_DBG("DROP: not for me (dst %s)", NET_DBG("DROP: not for me (dst %s)",
net_sprint_ipv4_addr(&hdr->dst)); net_sprint_ipv4_addr(&hdr->dst));

View file

@ -104,7 +104,7 @@ static void create_ipv4_dst_addr(struct net_pkt *pkt,
addr->sin_family = AF_INET; addr->sin_family = AF_INET;
addr->sin_port = udp_hdr->src_port; addr->sin_port = udp_hdr->src_port;
net_ipaddr_copy(&addr->sin_addr, &NET_IPV4_HDR(pkt)->src); net_ipv4_addr_copy_raw((uint8_t *)&addr->sin_addr, NET_IPV4_HDR(pkt)->src);
} }
#endif #endif
@ -352,7 +352,7 @@ static int create_ipv6_answer(struct net_context *ctx,
} else if (qtype == DNS_RR_TYPE_A) { } else if (qtype == DNS_RR_TYPE_A) {
#if defined(CONFIG_NET_IPV4) #if defined(CONFIG_NET_IPV4)
addr = get_ipv4_src(net_pkt_iface(pkt), addr = get_ipv4_src(net_pkt_iface(pkt),
&ip_hdr->ipv4->src); (struct in_addr *)ip_hdr->ipv4->src);
if (!addr) { if (!addr) {
return -ENOENT; return -ENOENT;
} }

View file

@ -253,7 +253,7 @@ static int send_response(struct net_context *ctx,
const struct in_addr *addr; const struct in_addr *addr;
addr = net_if_ipv4_select_src_addr(net_pkt_iface(pkt), addr = net_if_ipv4_select_src_addr(net_pkt_iface(pkt),
&ip_hdr->ipv4->src); (struct in_addr *)ip_hdr->ipv4->src);
ret = create_answer(ctx, query, qtype, ret = create_answer(ctx, query, qtype,
sizeof(struct in_addr), (uint8_t *)addr); sizeof(struct in_addr), (uint8_t *)addr);
@ -347,7 +347,7 @@ static void send_sd_response(struct net_context *ctx,
if (IS_ENABLED(CONFIG_NET_IPV4)) { if (IS_ENABLED(CONFIG_NET_IPV4)) {
/* Look up the local IPv4 address */ /* Look up the local IPv4 address */
addr4 = net_if_ipv4_select_src_addr(net_pkt_iface(pkt), addr4 = net_if_ipv4_select_src_addr(net_pkt_iface(pkt),
&ip_hdr->ipv4->src); (struct in_addr *)ip_hdr->ipv4->src);
} }
if (IS_ENABLED(CONFIG_NET_IPV6)) { if (IS_ENABLED(CONFIG_NET_IPV6)) {

View file

@ -866,7 +866,7 @@ static int sock_get_pkt_src_addr(struct net_pkt *pkt,
goto error; goto error;
} }
net_ipaddr_copy(&addr4->sin_addr, &ipv4_hdr->src); net_ipv4_addr_copy_raw((uint8_t *)&addr4->sin_addr, ipv4_hdr->src);
port = &addr4->sin_port; port = &addr4->sin_port;
} else if (IS_ENABLED(CONFIG_NET_IPV6) && } else if (IS_ENABLED(CONFIG_NET_IPV6) &&
net_pkt_family(pkt) == AF_INET6) { net_pkt_family(pkt) == AF_INET6) {

View file

@ -369,12 +369,12 @@ void test_arp(void)
ipv4 = (struct net_ipv4_hdr *)net_buf_add(pkt->buffer, ipv4 = (struct net_ipv4_hdr *)net_buf_add(pkt->buffer,
sizeof(struct net_ipv4_hdr)); sizeof(struct net_ipv4_hdr));
net_ipaddr_copy(&ipv4->src, &src); net_ipv4_addr_copy_raw(ipv4->src, (uint8_t *)&src);
net_ipaddr_copy(&ipv4->dst, &dst); net_ipv4_addr_copy_raw(ipv4->dst, (uint8_t *)&dst);
memcpy(net_buf_add(pkt->buffer, len), app_data, len); memcpy(net_buf_add(pkt->buffer, len), app_data, len);
pkt2 = net_arp_prepare(pkt, &NET_IPV4_HDR(pkt)->dst, NULL); pkt2 = net_arp_prepare(pkt, &dst, NULL);
/* pkt2 is the ARP packet and pkt is the IPv4 packet and it was /* pkt2 is the ARP packet and pkt is the IPv4 packet and it was
* stored in ARP table. * stored in ARP table.
@ -431,7 +431,7 @@ void test_arp(void)
} }
if (!net_ipv4_addr_cmp_raw(arp_hdr->dst_ipaddr, if (!net_ipv4_addr_cmp_raw(arp_hdr->dst_ipaddr,
(uint8_t *)&NET_IPV4_HDR(pkt)->dst)) { NET_IPV4_HDR(pkt)->dst)) {
printk("ARP IP dest invalid %s, should be %s", printk("ARP IP dest invalid %s, should be %s",
net_sprint_ipv4_addr(&arp_hdr->dst_ipaddr), net_sprint_ipv4_addr(&arp_hdr->dst_ipaddr),
net_sprint_ipv4_addr(&NET_IPV4_HDR(pkt)->dst)); net_sprint_ipv4_addr(&NET_IPV4_HDR(pkt)->dst));
@ -439,7 +439,7 @@ void test_arp(void)
} }
if (!net_ipv4_addr_cmp_raw(arp_hdr->src_ipaddr, if (!net_ipv4_addr_cmp_raw(arp_hdr->src_ipaddr,
(uint8_t *)&NET_IPV4_HDR(pkt)->src)) { NET_IPV4_HDR(pkt)->src)) {
printk("ARP IP src invalid %s, should be %s", printk("ARP IP src invalid %s, should be %s",
net_sprint_ipv4_addr(&arp_hdr->src_ipaddr), net_sprint_ipv4_addr(&arp_hdr->src_ipaddr),
net_sprint_ipv4_addr(&NET_IPV4_HDR(pkt)->src)); net_sprint_ipv4_addr(&NET_IPV4_HDR(pkt)->src));
@ -455,9 +455,9 @@ void test_arp(void)
"ARP cache should own the original packet"); "ARP cache should own the original packet");
/* Then a case where target is not in the same subnet */ /* Then a case where target is not in the same subnet */
net_ipaddr_copy(&ipv4->dst, &dst_far); net_ipv4_addr_copy_raw(ipv4->dst, (uint8_t *)&dst_far);
pkt2 = net_arp_prepare(pkt, &NET_IPV4_HDR(pkt)->dst, NULL); pkt2 = net_arp_prepare(pkt, &dst_far, NULL);
zassert_not_equal((void *)(pkt2), (void *)(pkt), zassert_not_equal((void *)(pkt2), (void *)(pkt),
"ARP cache should not find anything"); "ARP cache should not find anything");
@ -481,14 +481,14 @@ void test_arp(void)
/* Try to find the same destination again, this should fail as there /* Try to find the same destination again, this should fail as there
* is a pending request in ARP cache. * is a pending request in ARP cache.
*/ */
net_ipaddr_copy(&ipv4->dst, &dst_far); net_ipv4_addr_copy_raw(ipv4->dst, (uint8_t *)&dst_far);
/* Make sure prepare will not free the pkt because it will be /* Make sure prepare will not free the pkt because it will be
* needed in the later test case. * needed in the later test case.
*/ */
net_pkt_ref(pkt); net_pkt_ref(pkt);
pkt2 = net_arp_prepare(pkt, &NET_IPV4_HDR(pkt)->dst, NULL); pkt2 = net_arp_prepare(pkt, &dst_far, NULL);
zassert_not_null(pkt2, zassert_not_null(pkt2,
"ARP cache is not sending the request again"); "ARP cache is not sending the request again");
@ -498,14 +498,14 @@ void test_arp(void)
/* Try to find the different destination, this should fail too /* Try to find the different destination, this should fail too
* as the cache table should be full. * as the cache table should be full.
*/ */
net_ipaddr_copy(&ipv4->dst, &dst_far2); net_ipv4_addr_copy_raw(ipv4->dst, (uint8_t *)&dst_far2);
/* Make sure prepare will not free the pkt because it will be /* Make sure prepare will not free the pkt because it will be
* needed in the next test case. * needed in the next test case.
*/ */
net_pkt_ref(pkt); net_pkt_ref(pkt);
pkt2 = net_arp_prepare(pkt, &NET_IPV4_HDR(pkt)->dst, NULL); pkt2 = net_arp_prepare(pkt, &dst_far2, NULL);
zassert_not_null(pkt2, zassert_not_null(pkt2,
"ARP cache did not send a req"); "ARP cache did not send a req");
@ -513,7 +513,7 @@ void test_arp(void)
/* Restore the original address so that following test case can /* Restore the original address so that following test case can
* work properly. * work properly.
*/ */
net_ipaddr_copy(&ipv4->dst, &dst); net_ipv4_addr_copy_raw(ipv4->dst, (uint8_t *)&dst);
/* The arp request packet is now verified, create an arp reply. /* The arp request packet is now verified, create an arp reply.
* The previous value of pkt is stored in arp table and is not lost. * The previous value of pkt is stored in arp table and is not lost.

View file

@ -170,10 +170,10 @@ static int eth_tx_offloading_disabled(const struct device *dev,
} else { } else {
struct in_addr addr; struct in_addr addr;
net_ipaddr_copy(&addr, &NET_IPV4_HDR(pkt)->src); net_ipv4_addr_copy_raw((uint8_t *)&addr, NET_IPV4_HDR(pkt)->src);
net_ipaddr_copy(&NET_IPV4_HDR(pkt)->src, net_ipv4_addr_copy_raw(NET_IPV4_HDR(pkt)->src,
&NET_IPV4_HDR(pkt)->dst); NET_IPV4_HDR(pkt)->dst);
net_ipaddr_copy(&NET_IPV4_HDR(pkt)->dst, &addr); net_ipv4_addr_copy_raw(NET_IPV4_HDR(pkt)->dst, (uint8_t *)&addr);
} }
udp_hdr = net_udp_get_hdr(pkt, &hdr); udp_hdr = net_udp_get_hdr(pkt, &hdr);

View file

@ -921,10 +921,10 @@ static int tester_send(const struct device *dev, struct net_pkt *pkt)
} else { } else {
struct in_addr addr; struct in_addr addr;
net_ipaddr_copy(&addr, &NET_IPV4_HDR(pkt)->src); net_ipv4_addr_copy_raw((uint8_t *)&addr, NET_IPV4_HDR(pkt)->src);
net_ipaddr_copy(&NET_IPV4_HDR(pkt)->src, net_ipv4_addr_copy_raw(NET_IPV4_HDR(pkt)->src,
&NET_IPV4_HDR(pkt)->dst); NET_IPV4_HDR(pkt)->dst);
net_ipaddr_copy(&NET_IPV4_HDR(pkt)->dst, &addr); net_ipv4_addr_copy_raw(NET_IPV4_HDR(pkt)->dst, (uint8_t *)&addr);
} }
udp_hdr = net_udp_get_hdr(pkt, &hdr); udp_hdr = net_udp_get_hdr(pkt, &hdr);