net: nbuf: Pass ll_reserve when creating TX buffer
Instead of always calling net_nbuf_get_reserve_tx() with zero ll_reserve (first parameter) and then setting the link layer reserve separately, pass the reserve to that function which can then set the ll_reserve in buf itself. Change-Id: I21c14cb7e2e6c36d170c09998bca0207ecf65c75 Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
189ec2b6ad
commit
5032bdc46d
|
@ -287,9 +287,8 @@ static struct net_buf *prepare_message(struct net_if *iface, uint8_t type,
|
|||
struct net_buf *frag;
|
||||
struct dhcp_msg *msg;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, net_if_get_ll_reserve(iface, NULL));
|
||||
buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, NULL),
|
||||
K_FOREVER);
|
||||
|
||||
frag = net_nbuf_get_frag(buf, K_FOREVER);
|
||||
|
||||
|
|
|
@ -105,15 +105,13 @@ int net_icmpv4_send_echo_request(struct net_if *iface,
|
|||
/* Take the first address of the network interface */
|
||||
src = &iface->ipv4.unicast[0].address.in_addr;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
/* We cast to IPv6 address but that should be ok in this case
|
||||
* as IPv4 cannot be used in 802.15.4 where it is the reserve
|
||||
* size can change depending on address.
|
||||
*/
|
||||
net_nbuf_set_ll_reserve(buf,
|
||||
net_if_get_ll_reserve(iface,
|
||||
(const struct in6_addr *)dst));
|
||||
buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface,
|
||||
(const struct in6_addr *)dst),
|
||||
K_FOREVER);
|
||||
|
||||
frag = net_nbuf_get_frag(buf, K_FOREVER);
|
||||
|
||||
|
|
|
@ -290,14 +290,11 @@ int net_icmpv6_send_echo_request(struct net_if *iface,
|
|||
{
|
||||
const struct in6_addr *src;
|
||||
struct net_buf *buf;
|
||||
uint16_t reserve;
|
||||
|
||||
src = net_if_ipv6_select_src_addr(iface, dst);
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
reserve = net_if_get_ll_reserve(iface, dst);
|
||||
net_nbuf_set_ll_reserve(buf, reserve);
|
||||
buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, dst),
|
||||
K_FOREVER);
|
||||
|
||||
buf = net_ipv6_create_raw(buf, src, dst, iface, IPPROTO_ICMPV6);
|
||||
|
||||
|
|
|
@ -902,12 +902,11 @@ int net_ipv6_send_na(struct net_if *iface, struct in6_addr *src,
|
|||
struct net_buf *buf, *frag;
|
||||
uint8_t llao_len;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, dst),
|
||||
K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of TX buffers");
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, net_if_get_ll_reserve(iface, dst));
|
||||
|
||||
frag = net_nbuf_get_frag(buf, K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(frag, "Out of DATA buffers");
|
||||
|
@ -1505,12 +1504,11 @@ int net_ipv6_send_ns(struct net_if *iface,
|
|||
struct net_nbr *nbr;
|
||||
uint8_t llao_len;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, dst),
|
||||
K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of TX buffers");
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, net_if_get_ll_reserve(iface, dst));
|
||||
|
||||
frag = net_nbuf_get_frag(buf, K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(frag, "Out of DATA buffers");
|
||||
|
@ -1641,10 +1639,8 @@ int net_ipv6_send_rs(struct net_if *iface)
|
|||
bool unspec_src;
|
||||
uint8_t llao_len = 0;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, net_if_get_ll_reserve(iface,
|
||||
&NET_IPV6_BUF(buf)->dst));
|
||||
buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, NULL),
|
||||
K_FOREVER);
|
||||
|
||||
frag = net_nbuf_get_frag(buf, K_FOREVER);
|
||||
|
||||
|
|
|
@ -107,13 +107,11 @@ static inline struct net_buf *prepare_arp(struct net_if *iface,
|
|||
struct net_eth_hdr *eth;
|
||||
struct in_addr *my_addr;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
buf = net_nbuf_get_reserve_tx(sizeof(struct net_eth_hdr), K_FOREVER);
|
||||
if (!buf) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, sizeof(struct net_eth_hdr));
|
||||
|
||||
frag = net_nbuf_get_frag(buf, K_FOREVER);
|
||||
if (!frag) {
|
||||
goto fail;
|
||||
|
@ -374,13 +372,11 @@ static inline struct net_buf *prepare_arp_reply(struct net_if *iface,
|
|||
struct net_arp_hdr *hdr, *query;
|
||||
struct net_eth_hdr *eth, *eth_query;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
buf = net_nbuf_get_reserve_tx(sizeof(struct net_eth_hdr), K_FOREVER);
|
||||
if (!buf) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, sizeof(struct net_eth_hdr));
|
||||
|
||||
frag = net_nbuf_get_frag(buf, K_FOREVER);
|
||||
if (!frag) {
|
||||
goto fail;
|
||||
|
|
|
@ -92,13 +92,11 @@ static inline void ieee802154_acknowledge(struct net_if *iface,
|
|||
return;
|
||||
}
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
buf = net_nbuf_get_reserve_tx(IEEE802154_ACK_PKT_LENGTH, K_FOREVER);
|
||||
if (!buf) {
|
||||
return;
|
||||
}
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, IEEE802154_ACK_PKT_LENGTH);
|
||||
|
||||
frag = net_nbuf_get_frag(buf, K_FOREVER);
|
||||
|
||||
net_buf_frag_insert(buf, frag);
|
||||
|
|
|
@ -248,6 +248,8 @@ struct net_buf *net_nbuf_get_reserve(struct net_buf_pool *pool,
|
|||
} else {
|
||||
memset(net_buf_user_data(buf), 0, sizeof(struct net_nbuf));
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, reserve_head);
|
||||
|
||||
/* Remember the RX vs. TX so that the fragments can be
|
||||
* allocated from correct DATA pool.
|
||||
*/
|
||||
|
@ -399,7 +401,6 @@ static struct net_buf *net_nbuf_get(struct net_buf_pool *pool,
|
|||
struct in6_addr *addr6 = NULL;
|
||||
struct net_if *iface;
|
||||
struct net_buf *buf;
|
||||
uint16_t reserve;
|
||||
|
||||
if (!context) {
|
||||
return NULL;
|
||||
|
@ -413,12 +414,13 @@ static struct net_buf *net_nbuf_get(struct net_buf_pool *pool,
|
|||
addr6 = &((struct sockaddr_in6 *) &context->remote)->sin6_addr;
|
||||
}
|
||||
|
||||
reserve = net_if_get_ll_reserve(iface, addr6);
|
||||
|
||||
#if defined(CONFIG_NET_DEBUG_NET_BUF)
|
||||
buf = net_nbuf_get_reserve_debug(pool, reserve, timeout, caller, line);
|
||||
buf = net_nbuf_get_reserve_debug(pool,
|
||||
net_if_get_ll_reserve(iface, addr6),
|
||||
timeout, caller, line);
|
||||
#else
|
||||
buf = net_nbuf_get_reserve(pool, reserve, timeout);
|
||||
buf = net_nbuf_get_reserve(pool, net_if_get_ll_reserve(iface, addr6),
|
||||
timeout);
|
||||
#endif
|
||||
if (!buf) {
|
||||
return buf;
|
||||
|
@ -426,7 +428,6 @@ static struct net_buf *net_nbuf_get(struct net_buf_pool *pool,
|
|||
|
||||
if (!is_data_pool(pool)) {
|
||||
net_nbuf_set_context(buf, context);
|
||||
net_nbuf_set_ll_reserve(buf, reserve);
|
||||
net_nbuf_set_iface(buf, iface);
|
||||
|
||||
if (context) {
|
||||
|
|
|
@ -445,7 +445,8 @@ int net_rpl_dio_send(struct net_if *iface,
|
|||
uint16_t value;
|
||||
int ret;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, dst),
|
||||
K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -457,8 +458,6 @@ int net_rpl_dio_send(struct net_if *iface,
|
|||
dst_addr = dst;
|
||||
}
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, net_if_get_ll_reserve(iface, dst));
|
||||
|
||||
buf = net_ipv6_create_raw(buf, src, dst_addr, iface, IPPROTO_ICMPV6);
|
||||
|
||||
net_nbuf_set_iface(buf, iface);
|
||||
|
@ -721,11 +720,6 @@ int net_rpl_dis_send(struct in6_addr *dst, struct net_if *iface)
|
|||
return 0;
|
||||
}
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (!dst) {
|
||||
net_rpl_create_mcast_address(&addr);
|
||||
dst_addr = &addr;
|
||||
|
@ -733,9 +727,13 @@ int net_rpl_dis_send(struct in6_addr *dst, struct net_if *iface)
|
|||
dst_addr = dst;
|
||||
}
|
||||
|
||||
src = net_if_ipv6_select_src_addr(iface, dst_addr);
|
||||
buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, dst_addr),
|
||||
K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, net_if_get_ll_reserve(iface, dst_addr));
|
||||
src = net_if_ipv6_select_src_addr(iface, dst_addr);
|
||||
|
||||
buf = net_ipv6_create_raw(buf, src, dst_addr, iface, IPPROTO_ICMPV6);
|
||||
|
||||
|
@ -2966,13 +2964,12 @@ int net_rpl_dao_send(struct net_if *iface,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, dst),
|
||||
K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, net_if_get_ll_reserve(iface, dst));
|
||||
|
||||
buf = net_ipv6_create_raw(buf, src, dst, iface, IPPROTO_ICMPV6);
|
||||
|
||||
net_nbuf_set_iface(buf, iface);
|
||||
|
@ -3054,7 +3051,8 @@ static inline int dao_forward(struct net_if *iface,
|
|||
struct net_buf *buf;
|
||||
int ret;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, dst),
|
||||
K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
@ -3066,7 +3064,6 @@ static inline int dao_forward(struct net_if *iface,
|
|||
net_ipaddr_copy(&NET_IPV6_BUF(buf)->dst, dst);
|
||||
|
||||
net_nbuf_set_iface(buf, iface);
|
||||
net_nbuf_set_ll_reserve(buf, net_if_get_ll_reserve(iface, dst));
|
||||
|
||||
ret = net_send_data(buf);
|
||||
if (ret >= 0) {
|
||||
|
@ -3092,13 +3089,12 @@ static int dao_ack_send(struct net_buf *orig,
|
|||
NET_DBG("Sending a DAO ACK with sequence number %d to %s",
|
||||
sequence, net_sprint_ipv6_addr(dst));
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, dst),
|
||||
K_FOREVER);
|
||||
if (!buf) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, net_if_get_ll_reserve(iface, dst));
|
||||
|
||||
buf = net_ipv6_create_raw(buf, src, dst, iface, IPPROTO_ICMPV6);
|
||||
|
||||
net_nbuf_set_iface(buf, iface);
|
||||
|
|
|
@ -169,13 +169,11 @@ static inline struct net_buf *prepare_arp_reply(struct net_if *iface,
|
|||
struct net_arp_hdr *hdr;
|
||||
struct net_eth_hdr *eth;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
buf = net_nbuf_get_reserve_tx(sizeof(struct net_eth_hdr), K_FOREVER);
|
||||
if (!buf) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, sizeof(struct net_eth_hdr));
|
||||
|
||||
frag = net_nbuf_get_frag(buf, K_FOREVER);
|
||||
if (!frag) {
|
||||
goto fail;
|
||||
|
@ -224,13 +222,12 @@ static inline struct net_buf *prepare_arp_request(struct net_if *iface,
|
|||
struct net_arp_hdr *hdr, *req_hdr;
|
||||
struct net_eth_hdr *eth, *eth_req;
|
||||
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
buf = net_nbuf_get_reserve_rx(sizeof(struct net_eth_hdr),
|
||||
K_FOREVER);
|
||||
if (!buf) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, sizeof(struct net_eth_hdr));
|
||||
|
||||
frag = net_nbuf_get_frag(buf, K_FOREVER);
|
||||
if (!frag) {
|
||||
goto fail;
|
||||
|
@ -335,14 +332,12 @@ static bool run_tests(void)
|
|||
ifaddr->addr_state = NET_ADDR_PREFERRED;
|
||||
|
||||
/* Application data for testing */
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
buf = net_nbuf_get_reserve_tx(sizeof(struct net_eth_hdr), K_FOREVER);
|
||||
if (!buf) {
|
||||
printk("Out of mem TX\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, sizeof(struct net_eth_hdr));
|
||||
|
||||
frag = net_nbuf_get_frag(buf, K_FOREVER);
|
||||
if (!frag) {
|
||||
printk("Out of mem DATA\n");
|
||||
|
@ -562,15 +557,13 @@ static bool run_tests(void)
|
|||
/* The arp request packet is now verified, create an arp reply.
|
||||
* The previous value of buf is stored in arp table and is not lost.
|
||||
*/
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
buf = net_nbuf_get_reserve_rx(sizeof(struct net_eth_hdr), K_FOREVER);
|
||||
if (!buf) {
|
||||
printk("Out of mem RX reply\n");
|
||||
return false;
|
||||
}
|
||||
printk("%d buf %p\n", __LINE__, buf);
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, sizeof(struct net_eth_hdr));
|
||||
|
||||
frag = net_nbuf_get_frag(buf, K_FOREVER);
|
||||
if (!frag) {
|
||||
printk("Out of mem DATA reply\n");
|
||||
|
@ -619,14 +612,12 @@ static bool run_tests(void)
|
|||
net_nbuf_unref(buf);
|
||||
|
||||
/* Then feed in ARP request */
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
buf = net_nbuf_get_reserve_rx(sizeof(struct net_eth_hdr), K_FOREVER);
|
||||
if (!buf) {
|
||||
printk("Out of mem RX request\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, sizeof(struct net_eth_hdr));
|
||||
|
||||
frag = net_nbuf_get_frag(buf, K_FOREVER);
|
||||
if (!frag) {
|
||||
printk("Out of mem DATA request\n");
|
||||
|
|
|
@ -168,13 +168,12 @@ static struct net_buf *prepare_ra_message(void)
|
|||
struct net_buf *buf, *frag;
|
||||
struct net_if *iface;
|
||||
|
||||
buf = net_nbuf_get_reserve_rx(0, K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of RX buffers");
|
||||
|
||||
iface = net_if_get_default();
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, net_if_get_ll_reserve(iface, NULL));
|
||||
buf = net_nbuf_get_reserve_rx(net_if_get_ll_reserve(iface, NULL),
|
||||
K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of RX buffers");
|
||||
|
||||
frag = net_nbuf_get_frag(buf, K_FOREVER);
|
||||
|
||||
|
@ -411,13 +410,12 @@ static bool net_test_send_ns_extra_options(void)
|
|||
struct net_buf *buf, *frag;
|
||||
struct net_if *iface;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of TX buffers");
|
||||
|
||||
iface = net_if_get_default();
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, net_if_get_ll_reserve(iface, NULL));
|
||||
buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, NULL),
|
||||
K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of TX buffers");
|
||||
|
||||
frag = net_nbuf_get_frag(buf, K_FOREVER);
|
||||
|
||||
|
@ -445,13 +443,12 @@ static bool net_test_send_ns_no_options(void)
|
|||
struct net_buf *buf, *frag;
|
||||
struct net_if *iface;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of TX buffers");
|
||||
|
||||
iface = net_if_get_default();
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, net_if_get_ll_reserve(iface, NULL));
|
||||
buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, NULL),
|
||||
K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of TX buffers");
|
||||
|
||||
frag = net_nbuf_get_frag(buf, K_FOREVER);
|
||||
|
||||
|
@ -563,13 +560,12 @@ static bool net_test_hbho_message(void)
|
|||
struct net_buf *buf, *frag;
|
||||
struct net_if *iface;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of TX buffers");
|
||||
|
||||
iface = net_if_get_default();
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, net_if_get_ll_reserve(iface, NULL));
|
||||
buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, NULL),
|
||||
K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of TX buffers");
|
||||
|
||||
frag = net_nbuf_get_frag(buf, K_FOREVER);
|
||||
|
||||
|
@ -606,13 +602,12 @@ static bool net_test_change_ll_addr(void)
|
|||
|
||||
net_ipv6_addr_create(&dst, 0xff02, 0, 0, 0, 0, 0, 0, 1);
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of TX buffers");
|
||||
|
||||
iface = net_if_get_default();
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, net_if_get_ll_reserve(iface, NULL));
|
||||
buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, &dst),
|
||||
K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of TX buffers");
|
||||
|
||||
frag = net_nbuf_get_frag(buf, K_FOREVER);
|
||||
|
||||
|
|
|
@ -358,12 +358,11 @@ static bool net_test_send_na(struct net_if *iface,
|
|||
struct net_buf *buf, *frag;
|
||||
uint8_t llao_len;
|
||||
|
||||
buf = net_nbuf_get_reserve_tx(0, K_FOREVER);
|
||||
buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, dst),
|
||||
K_FOREVER);
|
||||
|
||||
NET_ASSERT_INFO(buf, "Out of TX buffers");
|
||||
|
||||
net_nbuf_set_ll_reserve(buf, net_if_get_ll_reserve(iface, dst));
|
||||
|
||||
buf = net_ipv6_create_raw(buf, addr, dst, iface, IPPROTO_ICMPV6);
|
||||
|
||||
frag = net_nbuf_get_frag(buf, K_FOREVER);
|
||||
|
|
Loading…
Reference in a new issue