net: l2 layer reserve size might need extra parameter
The dst_ip6 is a parameter, required for future 802.15.4 L2 layer. At some point such parameter could be changed to a void pointer, and a utility function would populate it depending on L2 layer, if such parameter needs someday to be variable and complex (some specific struct or else). Also make sure we use ARG_UNUSED() relevantly, and using proper prefix to functions. Change-Id: I43297bb4fb48a8f1bb5075c216342db16261cbb8 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
parent
56d3dfdeb9
commit
f7a9b07a84
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue