diff --git a/include/net/yaip/net_if.h b/include/net/yaip/net_if.h index 0eeac39aa0e..b61d853f84f 100644 --- a/include/net/yaip/net_if.h +++ b/include/net/yaip/net_if.h @@ -252,12 +252,16 @@ static inline enum net_verdict net_if_recv_data(struct net_if *iface, /** * @brief Get link layer header size for this network interface + * * @param iface Pointer to a network interface structure + * @param dst_ip6 Pointer on the distant IPv6 or NULL if not relevant + * * @return Return the link layer header size */ -static inline uint16_t net_if_get_ll_reserve(struct net_if *iface) +static inline uint16_t net_if_get_ll_reserve(struct net_if *iface, + struct in6_addr *dst_ip6) { - return iface->l2->get_reserve(iface); + return iface->l2->reserve(iface, (void *)dst_ip6); } /** diff --git a/include/net/yaip/net_l2.h b/include/net/yaip/net_l2.h index 81b6c5474cf..b1b02d4ccfe 100644 --- a/include/net/yaip/net_l2.h +++ b/include/net/yaip/net_l2.h @@ -33,7 +33,7 @@ struct net_if; struct net_l2 { enum net_verdict (*recv)(struct net_if *iface, struct net_buf *buf); enum net_verdict (*send)(struct net_if *iface, struct net_buf *buf); - uint16_t (*get_reserve)(struct net_if *iface); + uint16_t (*reserve)(struct net_if *iface, void *data); }; #define NET_L2_GET_NAME(_name) (__net_l2_##_name) @@ -59,7 +59,7 @@ extern struct net_l2 __net_l2_end[]; __attribute__((__section__(".net_l2.init"))) = { \ .recv = (_recv_fn), \ .send = (_send_fn), \ - .get_reserve = (_reserve_fn), \ + .reserve = (_reserve_fn), \ } #ifdef __cplusplus diff --git a/net/yaip/icmpv4.c b/net/yaip/icmpv4.c index 818f5a836b2..e49915cf22a 100644 --- a/net/yaip/icmpv4.c +++ b/net/yaip/icmpv4.c @@ -141,7 +141,7 @@ int net_icmpv4_send_error(struct net_buf *orig, uint8_t type, uint8_t code) /* FIXME, add TCP header length too */ } else { size_t space = CONFIG_NET_NBUF_DATA_SIZE - - net_if_get_ll_reserve(iface); + net_if_get_ll_reserve(iface, NULL); if (reserve > space) { extra_len = 0; diff --git a/net/yaip/icmpv6.c b/net/yaip/icmpv6.c index 04f9ef1a54c..9f0bfe6bd5b 100644 --- a/net/yaip/icmpv6.c +++ b/net/yaip/icmpv6.c @@ -141,6 +141,12 @@ int net_icmpv6_send_error(struct net_buf *orig, uint8_t type, uint8_t code) buf = net_nbuf_get_reserve_tx(0); + /* We need to remember the original location of source and destination + * addresses as the net_nbuf_copy() will mangle the original buffer. + */ + src = &NET_IPV6_BUF(orig)->src; + dst = &NET_IPV6_BUF(orig)->dst; + /* There is unsed part in ICMPv6 error msg header */ reserve = sizeof(struct net_ipv6_hdr) + sizeof(struct net_icmp_hdr) + NET_ICMPV6_UNUSED_LEN; @@ -153,7 +159,7 @@ int net_icmpv6_send_error(struct net_buf *orig, uint8_t type, uint8_t code) /* FIXME, add TCP header length too */ } else { size_t space = CONFIG_NET_NBUF_DATA_SIZE - - net_if_get_ll_reserve(iface); + net_if_get_ll_reserve(iface, dst); if (reserve > space) { extra_len = 0; @@ -162,12 +168,6 @@ int net_icmpv6_send_error(struct net_buf *orig, uint8_t type, uint8_t code) } } - /* We need to remember the original location of source and destination - * addresses as the net_nbuf_copy() will mangle the original buffer. - */ - src = &NET_IPV6_BUF(orig)->src; - dst = &NET_IPV6_BUF(orig)->dst; - /* We only copy minimal IPv6 + next header from original message. * This is so that the memory pressure is minimized. */ diff --git a/net/yaip/ipv6.c b/net/yaip/ipv6.c index cb2bfca386e..6ffc357e736 100644 --- a/net/yaip/ipv6.c +++ b/net/yaip/ipv6.c @@ -895,7 +895,7 @@ int net_ipv6_send_ns(struct net_if *iface, NET_ASSERT_INFO(buf, "Out of TX buffers"); - frag = net_nbuf_get_reserve_data(net_if_get_ll_reserve(iface)); + frag = net_nbuf_get_reserve_data(net_if_get_ll_reserve(iface, dst)); NET_ASSERT_INFO(frag, "Out of DATA buffers"); @@ -1010,7 +1010,8 @@ int net_ipv6_send_rs(struct net_if *iface) buf = net_nbuf_get_reserve_tx(0); - frag = net_nbuf_get_reserve_data(net_if_get_ll_reserve(iface)); + frag = net_nbuf_get_reserve_data( + net_if_get_ll_reserve(iface, &NET_IPV6_BUF(buf)->dst)); net_buf_frag_add(buf, frag); diff --git a/net/yaip/l2/dummy.c b/net/yaip/l2/dummy.c index 2c12d7a517c..e19be7b00d8 100644 --- a/net/yaip/l2/dummy.c +++ b/net/yaip/l2/dummy.c @@ -38,9 +38,12 @@ static inline enum net_verdict dummy_send(struct net_if *iface, return NET_OK; } -static inline uint16_t get_reserve(struct net_if *iface) +static inline uint16_t dummy_reserve(struct net_if *iface, void *unused) { + ARG_UNUSED(iface); + ARG_UNUSED(unused); + return 0; } -NET_L2_INIT(DUMMY_L2, dummy_recv, dummy_send, get_reserve); +NET_L2_INIT(DUMMY_L2, dummy_recv, dummy_send, dummy_reserve); diff --git a/net/yaip/l2/ethernet.c b/net/yaip/l2/ethernet.c index 6535612ab65..cc991b85de2 100644 --- a/net/yaip/l2/ethernet.c +++ b/net/yaip/l2/ethernet.c @@ -232,9 +232,12 @@ send: return NET_OK; } -static inline uint16_t get_reserve(struct net_if *iface) +static inline uint16_t ethernet_reserve(struct net_if *iface, void *unused) { + ARG_UNUSED(iface); + ARG_UNUSED(unused); + return sizeof(struct net_eth_hdr); } -NET_L2_INIT(ETHERNET_L2, ethernet_recv, ethernet_send, get_reserve); +NET_L2_INIT(ETHERNET_L2, ethernet_recv, ethernet_send, ethernet_reserve); diff --git a/net/yaip/nbuf.c b/net/yaip/nbuf.c index cec92d68c30..5e6b53888d3 100644 --- a/net/yaip/nbuf.c +++ b/net/yaip/nbuf.c @@ -462,13 +462,20 @@ static struct net_buf *net_nbuf_get(enum net_nbuf_type type, struct net_context *context) #endif /* NET_DEBUG */ { - struct net_buf *buf; struct net_if *iface = net_context_get_iface(context); - uint16_t reserve = net_if_get_ll_reserve(iface); + struct in6_addr *addr6 = NULL; + struct net_buf *buf; + uint16_t reserve; NET_ASSERT_INFO(context && iface, "context %p iface %p", context, iface); + if (context && net_context_get_family(context) == AF_INET6) { + addr6 = &((struct sockaddr_in6 *) &context->remote)->sin6_addr; + } + + reserve = net_if_get_ll_reserve(iface, addr6); + #if NET_DEBUG buf = net_nbuf_get_reserve_debug(type, reserve, caller, line); #else