diff options
author | Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com> | 2017-04-03 17:14:35 +0200 |
---|---|---|
committer | Jukka Rissanen <jukka.rissanen@linux.intel.com> | 2017-04-21 14:19:50 +0300 |
commit | bf964cdd4c42ea6a05e9579e5a7a64436abe5b6e (patch) | |
tree | 59c3f4523a2a3cac789fda6d3865e46999261aba /subsys | |
parent | 9bf3ea071ae098daeb06060debffa35a0337318f (diff) |
net: Renaming net nbuf API to net pkt API
There have been long lasting confusion between net_buf and net_nbuf.
While the first is actually a buffer, the second one is not. It's a
network buffer descriptor. More precisely it provides meta data about a
network packet, and holds the chain of buffer fragments made of net_buf.
Thus renaming net_nbuf to net_pkt and all names around it as well
(function, Kconfig option, ..).
Though net_pkt if the new name, it still inherit its logic from net_buf.
'
This patch is the first of a serie that will separate completely net_pkt
from net_buf.
Change-Id: Iecb32d2a0d8f4647692e5328e54b5c35454194cd
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
Diffstat (limited to 'subsys')
49 files changed, 1397 insertions, 1400 deletions
diff --git a/subsys/net/Makefile b/subsys/net/Makefile index c64bc9f4d..d723d8c98 100644 --- a/subsys/net/Makefile +++ b/subsys/net/Makefile @@ -2,7 +2,7 @@ obj-$(CONFIG_NET_BUF) += buf.o ifeq ($(CONFIG_NETWORKING),y) ifeq ($(CONFIG_NET_L2_RAW_CHANNEL),y) -obj-y += ip/nbuf.o +obj-y += ip/net_pkt.o else obj-y += ip/ endif diff --git a/subsys/net/ip/6lo.c b/subsys/net/ip/6lo.c index 07c939d9c..118761ada 100644 --- a/subsys/net/ip/6lo.c +++ b/subsys/net/ip/6lo.c @@ -15,7 +15,6 @@ #include <errno.h> #include <net/net_core.h> -#include <net/nbuf.h> #include <net/net_if.h> #include <net/net_stats.h> @@ -315,13 +314,13 @@ static inline uint8_t compress_sa(struct net_ipv6_hdr *ipv6, memcpy(&IPHC[offset], &ipv6->src.s6_addr[14], 2); offset += 2; } else { - if (!net_nbuf_ll_src(buf)) { + if (!net_pkt_ll_src(buf)) { NET_ERR("Invalid src ll address"); return 0; } if (net_ipv6_addr_based_on_ll(&ipv6->src, - net_nbuf_ll_src(buf))) { + net_pkt_ll_src(buf))) { NET_DBG("SAM_11 src address is fully elided"); /* Address is fully elided */ @@ -371,7 +370,7 @@ static inline uint8_t compress_sa_ctx(struct net_ipv6_hdr *ipv6, memcpy(&IPHC[offset], &ipv6->src.s6_addr[14], 2); offset += 2; } else if (net_ipv6_addr_based_on_ll(&ipv6->src, - net_nbuf_ll_src(buf))) { + net_pkt_ll_src(buf))) { NET_DBG("SAM_11 src address is fully elided"); /* Address is fully elided */ @@ -467,13 +466,13 @@ static inline uint8_t compress_da(struct net_ipv6_hdr *ipv6, memcpy(&IPHC[offset], &ipv6->dst.s6_addr[14], 2); offset += 2; } else { - if (!net_nbuf_ll_dst(buf)) { + if (!net_pkt_ll_dst(buf)) { NET_ERR("Invalid dst ll address"); return 0; } if (net_ipv6_addr_based_on_ll(&ipv6->dst, - net_nbuf_ll_dst(buf))) { + net_pkt_ll_dst(buf))) { NET_DBG("DAM_11 dst addr fully elided"); /* Address is fully elided */ @@ -522,8 +521,7 @@ static inline uint8_t compress_da_ctx(struct net_ipv6_hdr *ipv6, offset += 2; } else { if (net_ipv6_addr_based_on_ll(&ipv6->dst, - net_nbuf_ll_dst(buf))) { - + net_pkt_ll_dst(buf))) { NET_DBG("DAM_11 dst addr fully elided"); /* Address is fully elided */ @@ -636,12 +634,12 @@ static inline bool is_src_and_dst_addr_ctx_based(struct net_ipv6_hdr *ipv6, { /* If compress flag is unset means use only in uncompression. */ - *src = get_6lo_context_by_addr(net_nbuf_iface(buf), &ipv6->src); + *src = get_6lo_context_by_addr(net_pkt_iface(buf), &ipv6->src); if (*src && !((*src)->compress)) { *src = NULL; } - *dst = get_6lo_context_by_addr(net_nbuf_iface(buf), &ipv6->dst); + *dst = get_6lo_context_by_addr(net_pkt_iface(buf), &ipv6->dst); if (*dst && !((*dst)->compress)) { *dst = NULL; } @@ -703,7 +701,7 @@ static inline bool compress_IPHC_header(struct net_buf *buf, return false; } - frag = net_nbuf_get_frag(buf, K_FOREVER); + frag = net_pkt_get_frag(buf, K_FOREVER); IPHC[offset++] = NET_6LO_DISPATCH_IPHC; IPHC[offset++] = 0; @@ -730,7 +728,7 @@ static inline bool compress_IPHC_header(struct net_buf *buf, offset = compress_sa(ipv6, buf, frag, offset); #endif if (!offset) { - net_nbuf_unref(frag); + net_pkt_unref(frag); return false; } @@ -742,7 +740,7 @@ static inline bool compress_IPHC_header(struct net_buf *buf, #endif if (!offset) { - net_nbuf_unref(frag); + net_pkt_unref(frag); return false; } @@ -769,13 +767,13 @@ end: net_buf_add(frag, buf->frags->len - compressed); /* Delete uncompressed(original) header fragment */ - net_nbuf_frag_del(buf, buf->frags); + net_pkt_frag_del(buf, buf->frags); /* Insert compressed header fragment */ net_buf_frag_insert(buf, frag); /* Compact the fragments, so that gaps will be filled */ - net_nbuf_compact(buf); + net_pkt_compact(buf); if (fragment) { return fragment(buf, compressed - offset); @@ -902,7 +900,7 @@ static inline uint8_t uncompress_sa(struct net_buf *buf, case NET_6LO_IPHC_SAM_11: NET_DBG("SAM_11 generate src addr from ll"); - net_ipv6_addr_create_iid(&ipv6->src, net_nbuf_ll_src(buf)); + net_ipv6_addr_create_iid(&ipv6->src, net_pkt_ll_src(buf)); break; } @@ -952,7 +950,7 @@ static inline uint8_t uncompress_sa_ctx(struct net_buf *buf, * the encapsulating header. * (e.g., 802.15.4 or IPv6 source address). */ - net_ipv6_addr_create_iid(&ipv6->src, net_nbuf_ll_src(buf)); + net_ipv6_addr_create_iid(&ipv6->src, net_pkt_ll_src(buf)); /* net_ipv6_addr_create_iid will copy first 8 bytes * as link local prefix. @@ -1070,7 +1068,7 @@ static inline uint8_t uncompress_da(struct net_buf *buf, case NET_6LO_IPHC_DAM_11: NET_DBG("DAM_11 generate dst addr from ll"); - net_ipv6_addr_create_iid(&ipv6->dst, net_nbuf_ll_dst(buf)); + net_ipv6_addr_create_iid(&ipv6->dst, net_pkt_ll_dst(buf)); break; } @@ -1132,7 +1130,7 @@ static inline uint8_t uncompress_da_ctx(struct net_buf *buf, * the encapsulating header. * (e.g., 802.15.4 or IPv6 source address). */ - net_ipv6_addr_create_iid(&ipv6->dst, net_nbuf_ll_dst(buf)); + net_ipv6_addr_create_iid(&ipv6->dst, net_pkt_ll_dst(buf)); /* net_ipv6_addr_create_iid will copy first 8 bytes * as link local prefix. @@ -1216,13 +1214,13 @@ static inline bool uncompress_cid(struct net_buf *buf, * Either src or dest address is context based or both. */ cid = (CIPHC[2] >> 4) & 0x0F; - *src = get_6lo_context_by_cid(net_nbuf_iface(buf), cid); + *src = get_6lo_context_by_cid(net_pkt_iface(buf), cid); if (!(*src)) { NET_DBG("Unknown src cid %d", cid); } cid = CIPHC[2] & 0x0F; - *dst = get_6lo_context_by_cid(net_nbuf_iface(buf), cid); + *dst = get_6lo_context_by_cid(net_pkt_iface(buf), cid); if (!(*dst)) { NET_DBG("Unknown dst cid %d", cid); } @@ -1266,7 +1264,7 @@ static inline bool uncompress_IPHC_header(struct net_buf *buf) #endif } - frag = net_nbuf_get_frag(buf, NET_6LO_RX_NBUF_TIMEOUT); + frag = net_pkt_get_frag(buf, NET_6LO_RX_PKT_TIMEOUT); if (!frag) { return false; } @@ -1275,7 +1273,7 @@ static inline bool uncompress_IPHC_header(struct net_buf *buf) /* Version is always 6 */ ipv6->vtc = 0x60; - net_nbuf_set_ip_hdr_len(buf, NET_IPV6H_LEN); + net_pkt_set_ip_hdr_len(buf, NET_IPV6H_LEN); /* Uncompress Traffic class and Flow label */ offset = uncompress_tfl(buf, ipv6, offset); @@ -1352,14 +1350,14 @@ end: buf->frags->len -= offset; /* Copying ll part, if any */ - if (net_nbuf_ll_reserve(buf)) { - memcpy(frag->data - net_nbuf_ll_reserve(buf), - net_nbuf_ll(buf), net_nbuf_ll_reserve(buf)); + if (net_pkt_ll_reserve(buf)) { + memcpy(frag->data - net_pkt_ll_reserve(buf), + net_pkt_ll(buf), net_pkt_ll_reserve(buf)); } /* Insert the fragment (this one holds uncompressed headers) */ net_buf_frag_insert(buf, frag); - net_nbuf_compact(buf); + net_pkt_compact(buf); /* Set IPv6 header and UDP (if next header is) length */ len = net_buf_frags_len(buf) - NET_IPV6H_LEN; @@ -1377,7 +1375,7 @@ end: return true; fail: - net_nbuf_unref(frag); + net_pkt_unref(frag); return false; } @@ -1387,7 +1385,7 @@ static inline bool compress_ipv6_header(struct net_buf *buf, { struct net_buf *frag; - frag = net_nbuf_get_frag(buf, K_FOREVER); + frag = net_pkt_get_frag(buf, K_FOREVER); frag->data[0] = NET_6LO_DISPATCH_IPV6; net_buf_add(frag, 1); @@ -1395,7 +1393,7 @@ static inline bool compress_ipv6_header(struct net_buf *buf, net_buf_frag_insert(buf, frag); /* Compact the fragments, so that gaps will be filled */ - net_nbuf_compact(buf); + net_pkt_compact(buf); if (fragment) { return fragment(buf, -1); diff --git a/subsys/net/ip/6lo.h b/subsys/net/ip/6lo.h index 5808e5cea..a35cf4879 100644 --- a/subsys/net/ip/6lo.h +++ b/subsys/net/ip/6lo.h @@ -16,7 +16,7 @@ #include <misc/slist.h> #include <zephyr/types.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include "icmpv6.h" typedef bool (*fragment_handler_t)(struct net_buf *, int); diff --git a/subsys/net/ip/6lo_private.h b/subsys/net/ip/6lo_private.h index b325f2921..7d6278d77 100644 --- a/subsys/net/ip/6lo_private.h +++ b/subsys/net/ip/6lo_private.h @@ -97,4 +97,4 @@ * that can cause the stack to deadlock. This can happen if RX side is flooding * incoming data and we cannot get process the packet in 6lo side. */ -#define NET_6LO_RX_NBUF_TIMEOUT 100 /* in ms */ +#define NET_6LO_RX_PKT_TIMEOUT 100 /* in ms */ diff --git a/subsys/net/ip/Kconfig b/subsys/net/ip/Kconfig index 9a9b5b30d..4b5ed8e9c 100644 --- a/subsys/net/ip/Kconfig +++ b/subsys/net/ip/Kconfig @@ -159,15 +159,15 @@ config NET_MAX_CONTEXTS is used when listening or sending network traffic. This is very similar as one could call a network socket in some other systems. -config NET_CONTEXT_NBUF_POOL +config NET_CONTEXT_NET_PKT_POOL bool "Enable net_buf TX pool / context" default n default y if NET_TCP && NET_6LO help - If enabled, then it is possible to fine-tune network buffer pool + If enabled, then it is possible to fine-tune network packet pool for each context when sending network data. If this setting is enabled, then you should define the context pools in your application - using NET_NBUF_TX_POOL_DEFINE() and NET_NBUF_DATA_POOL_DEFINE() + using NET_PKT_TX_POOL_DEFINE() and NET_PKT_DATA_POOL_DEFINE() macros and tie these pools to desired context using the net_context_setup_pools() function. @@ -240,35 +240,35 @@ config NET_DEBUG_TRICKLE endif # NET_L2_RAW_CHANNEL -config NET_NBUF_RX_COUNT - int "How many network receives can be pending at the same time" +config NET_PKT_RX_COUNT + int "How many packet receives can be pending at the same time" default 4 help Each RX buffer will occupy smallish amount of memory. - See include/net/nbuf.h and the sizeof(struct nbuf) + See include/net/net_pkt.h and the sizeof(struct net_pkt) -config NET_NBUF_TX_COUNT - int "How many network sends can be pending at the same time" +config NET_PKT_TX_COUNT + int "How many packet sends can be pending at the same time" default 2 help Each TX buffer will occupy smallish amount of memory. - See include/net/nbuf.h and the sizeof(struct nbuf) + See include/net/net_pkt.h and the sizeof(struct net_pkt) -config NET_NBUF_RX_DATA_COUNT - int "How many network data buffers are allocated for receiving data" +config NET_BUF_RX_COUNT + int "How many network buffers are allocated for receiving data" default 16 help - Each data buffer will occupy CONFIG_NBUF_DATA_SIZE + smallish + Each data buffer will occupy CONFIG_NET_BUF_DATA_SIZE + smallish header (sizeof(struct net_buf)) amount of data. -config NET_NBUF_TX_DATA_COUNT - int "How many network data buffers are allocated for sending data" +config NET_BUF_TX_COUNT + int "How many network buffers are allocated for sending data" default 16 help - Each data buffer will occupy CONFIG_NBUF_DATA_SIZE + smallish + Each data buffer will occupy CONFIG_NET_BUF_DATA_SIZE + smallish header (sizeof(struct net_buf)) amount of data. -config NET_NBUF_DATA_SIZE +config NET_BUF_DATA_SIZE int "Size of each network data fragment" default 128 default 125 if NET_L2_IEEE802154 @@ -280,7 +280,7 @@ config NET_NBUF_DATA_SIZE In order to be able to receive at least full IPv6 packet which has a size of 1280 bytes, the one should allocate 16 fragments here. -config NET_NBUF_USER_DATA_SIZE +config NET_BUF_USER_DATA_SIZE int "Size of user_data reserved" default 0 default 4 if NET_L2_BLUETOOTH diff --git a/subsys/net/ip/Kconfig.debug b/subsys/net/ip/Kconfig.debug index da1954c38..c3ede5900 100644 --- a/subsys/net/ip/Kconfig.debug +++ b/subsys/net/ip/Kconfig.debug @@ -38,7 +38,7 @@ config NET_LOG_GLOBAL select NET_DEBUG_IF select NET_DEBUG_UTILS select NET_DEBUG_CONTEXT - select NET_DEBUG_NET_BUF + select NET_DEBUG_NET_PKT select NET_DEBUG_CONN select NET_DEBUG_ROUTE if NET_ROUTE select NET_DEBUG_IPV6 if NET_IPV6 @@ -85,19 +85,19 @@ config NET_DEBUG_CONTEXT help Enables printing of network context allocations and frees. -config NET_DEBUG_NET_BUF - bool "Debug network buffer allocation" +config NET_DEBUG_NET_PKT + bool "Debug network packet and buffer allocation" default n select NET_BUF_POOL_USAGE help - Enables printing of network buffer allocations and frees. + Enables printing of network packet and buffer allocations and frees. -config NET_DEBUG_NET_BUF_EXTERNALS - int "How many external network buffer allocations" +config NET_DEBUG_NET_PKT_EXTERNALS + int "How many external network packet allocations" default 0 - depends on NET_DEBUG_NET_BUF + depends on NET_DEBUG_NET_PKT help - How many external net_buf's are there in user specic pools. + How many external net_pkt's are there in user specic pools. This value is used when allocating space for tracking the memory allocations. diff --git a/subsys/net/ip/Makefile b/subsys/net/ip/Makefile index 611de0a75..fb852587d 100644 --- a/subsys/net/ip/Makefile +++ b/subsys/net/ip/Makefile @@ -2,7 +2,7 @@ ccflags-$(CONFIG_NEWLIB_LIBC) += -D__LINUX_ERRNO_EXTENSIONS__ obj-y = net_core.o \ net_if.o \ net_context.o \ - nbuf.o \ + net_pkt.o \ utils.o obj-y += l2/ diff --git a/subsys/net/ip/connection.c b/subsys/net/ip/connection.c index 56430fb0a..e6629cb3e 100644 --- a/subsys/net/ip/connection.c +++ b/subsys/net/ip/connection.c @@ -17,7 +17,7 @@ #include <misc/util.h> #include <net/net_core.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include "net_private.h" #include "icmpv6.h" @@ -48,7 +48,7 @@ static struct net_conn conns[CONFIG_NET_MAX_CONN]; * both TCP and UDP header have these in the same location, we can check * them both using the UDP struct. */ -#define NET_CONN_BUF(buf) ((struct net_udp_hdr *)(net_nbuf_udp_data(buf))) +#define NET_CONN_BUF(buf) ((struct net_udp_hdr *)(net_pkt_udp_data(buf))) #if defined(CONFIG_NET_CONN_CACHE) @@ -284,7 +284,7 @@ static inline enum net_verdict cache_check(enum net_ip_protocol proto, uint32_t *cache_value, int32_t *pos) { - *pos = get_conn(proto, net_nbuf_family(buf), buf, cache_value); + *pos = get_conn(proto, net_pkt_family(buf), buf, cache_value); if (*pos >= 0) { if (conn_cache[*pos].idx >= 0) { /* Connection is in the cache */ @@ -297,7 +297,7 @@ static inline enum net_verdict cache_check(enum net_ip_protocol proto, net_proto2str(proto), buf, ntohs(NET_CONN_BUF(buf)->src_port), ntohs(NET_CONN_BUF(buf)->dst_port), - net_nbuf_family(buf), *pos, + net_pkt_family(buf), *pos, conn_cache[*pos].value); return conn->cb(conn, buf, conn->user_data); @@ -561,12 +561,12 @@ static bool check_addr(struct net_buf *buf, struct sockaddr *addr, bool is_remote) { - if (addr->family != net_nbuf_family(buf)) { + if (addr->family != net_pkt_family(buf)) { return false; } #if defined(CONFIG_NET_IPV6) - if (net_nbuf_family(buf) == AF_INET6 && addr->family == AF_INET6) { + if (net_pkt_family(buf) == AF_INET6 && addr->family == AF_INET6) { struct in6_addr *addr6; if (is_remote) { @@ -588,7 +588,7 @@ static bool check_addr(struct net_buf *buf, #endif /* CONFIG_NET_IPV6 */ #if defined(CONFIG_NET_IPV4) - if (net_nbuf_family(buf) == AF_INET && addr->family == AF_INET) { + if (net_pkt_family(buf) == AF_INET && addr->family == AF_INET) { struct in_addr *addr4; if (is_remote) { @@ -611,7 +611,7 @@ static bool check_addr(struct net_buf *buf, static inline void send_icmp_error(struct net_buf *buf) { - if (net_nbuf_family(buf) == AF_INET6) { + if (net_pkt_family(buf) == AF_INET6) { #if defined(CONFIG_NET_IPV6) net_icmpv6_send_error(buf, NET_ICMPV6_DST_UNREACH, NET_ICMPV6_DST_UNREACH_NO_PORT, 0); @@ -655,7 +655,7 @@ enum net_verdict net_conn_input(enum net_ip_protocol proto, struct net_buf *buf) "family %d chksum 0x%04x", net_proto2str(proto), buf, ntohs(NET_CONN_BUF(buf)->src_port), ntohs(NET_CONN_BUF(buf)->dst_port), - net_nbuf_family(buf), ntohs(chksum)); + net_pkt_family(buf), ntohs(chksum)); } for (i = 0; i < CONFIG_NET_MAX_CONN; i++) { @@ -748,13 +748,13 @@ enum net_verdict net_conn_input(enum net_ip_protocol proto, struct net_buf *buf) /* If the destination address is multicast address, * we do not send ICMP error as that makes no sense. */ - if (net_nbuf_family(buf) == AF_INET6 && + if (net_pkt_family(buf) == AF_INET6 && net_is_ipv6_addr_mcast(&NET_IPV6_BUF(buf)->dst)) { ; } else #endif #if defined(CONFIG_NET_IPV4) - if (net_nbuf_family(buf) == AF_INET && + if (net_pkt_family(buf) == AF_INET && net_is_ipv4_addr_mcast(&NET_IPV4_BUF(buf)->dst)) { ; } else diff --git a/subsys/net/ip/connection.h b/subsys/net/ip/connection.h index b470d9f68..e7499cd22 100644 --- a/subsys/net/ip/connection.h +++ b/subsys/net/ip/connection.h @@ -19,7 +19,7 @@ #include <net/net_core.h> #include <net/net_ip.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #ifdef __cplusplus extern "C" { diff --git a/subsys/net/ip/dhcpv4.c b/subsys/net/ip/dhcpv4.c index b2cd83f80..0c82ae783 100644 --- a/subsys/net/ip/dhcpv4.c +++ b/subsys/net/ip/dhcpv4.c @@ -19,7 +19,7 @@ #include <errno.h> #include <inttypes.h> #include <net/net_core.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_if.h> #include "net_private.h" @@ -157,7 +157,7 @@ net_dhcpv4_msg_type_name(enum dhcpv4_msg_type msg_type) /* Add magic cookie to DCHPv4 messages */ static inline bool add_cookie(struct net_buf *buf) { - return net_nbuf_append(buf, sizeof(magic_cookie), magic_cookie, + return net_pkt_append(buf, sizeof(magic_cookie), magic_cookie, K_FOREVER); } @@ -165,15 +165,15 @@ static inline bool add_cookie(struct net_buf *buf) static bool add_option_length_value(struct net_buf *buf, uint8_t option, uint8_t size, const uint8_t *value) { - if (!net_nbuf_append_u8(buf, option)) { + if (!net_pkt_append_u8(buf, option)) { return false; } - if (!net_nbuf_append_u8(buf, size)) { + if (!net_pkt_append_u8(buf, size)) { return false; } - if (!net_nbuf_append(buf, size, value, K_FOREVER)) { + if (!net_pkt_append(buf, size, value, K_FOREVER)) { return false; } @@ -197,7 +197,7 @@ static bool add_req_options(struct net_buf *buf) DHCPV4_OPTIONS_ROUTER, DHCPV4_OPTIONS_DNS_SERVER }; - return net_nbuf_append(buf, sizeof(data), data, K_FOREVER); + return net_pkt_append(buf, sizeof(data), data, K_FOREVER); } static bool add_server_id(struct net_buf *buf, const struct in_addr *addr) @@ -215,7 +215,7 @@ static bool add_req_ipaddr(struct net_buf *buf, const struct in_addr *addr) /* Add DHCPv4 Options end, rest of the message can be padded wit zeros */ static inline bool add_end(struct net_buf *buf) { - return net_nbuf_append_u8(buf, DHCPV4_OPTIONS_END); + return net_pkt_append_u8(buf, DHCPV4_OPTIONS_END); } /* File is empty ATM */ @@ -224,7 +224,7 @@ static inline bool add_file(struct net_buf *buf) uint8_t len = SIZE_OF_FILE; while (len-- > 0) { - if (!net_nbuf_append_u8(buf, 0)) { + if (!net_pkt_append_u8(buf, 0)) { return false; } } @@ -238,7 +238,7 @@ static inline bool add_sname(struct net_buf *buf) uint8_t len = SIZE_OF_SNAME; while (len-- > 0) { - if (!net_nbuf_append_u8(buf, 0)) { + if (!net_pkt_append_u8(buf, 0)) { return false; } } @@ -287,14 +287,14 @@ 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(net_if_get_ll_reserve(iface, NULL), - K_FOREVER); + buf = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface, NULL), + K_FOREVER); - frag = net_nbuf_get_frag(buf, K_FOREVER); + frag = net_pkt_get_frag(buf, K_FOREVER); - net_nbuf_set_iface(buf, iface); - net_nbuf_set_family(buf, AF_INET); - net_nbuf_set_ip_hdr_len(buf, sizeof(struct net_ipv4_hdr)); + net_pkt_set_iface(buf, iface); + net_pkt_set_family(buf, AF_INET); + net_pkt_set_ip_hdr_len(buf, sizeof(struct net_ipv4_hdr)); net_buf_frag_add(buf, frag); @@ -338,7 +338,7 @@ static struct net_buf *prepare_message(struct net_if *iface, uint8_t type, return buf; fail: - net_nbuf_unref(buf); + net_pkt_unref(buf); return NULL; } @@ -442,7 +442,7 @@ fail: NET_DBG("Message preparation failed"); if (!buf) { - net_nbuf_unref(buf); + net_pkt_unref(buf); } } @@ -485,7 +485,7 @@ fail: NET_DBG("Message preparation failed"); if (!buf) { - net_nbuf_unref(buf); + net_pkt_unref(buf); } } @@ -672,8 +672,8 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf, uint8_t type; uint16_t pos; - frag = net_nbuf_read(buf, offset, &pos, sizeof(magic_cookie), - (uint8_t *)cookie); + frag = net_pkt_read(buf, offset, &pos, sizeof(magic_cookie), + (uint8_t *)cookie); if (!frag || memcmp(magic_cookie, cookie, sizeof(magic_cookie))) { NET_DBG("Incorrect magic cookie"); @@ -681,14 +681,14 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf, } while (frag) { - frag = net_nbuf_read_u8(frag, pos, &pos, &type); + frag = net_pkt_read_u8(frag, pos, &pos, &type); if (type == DHCPV4_OPTIONS_END) { NET_DBG("options_end"); return NET_OK; } - frag = net_nbuf_read_u8(frag, pos, &pos, &length); + frag = net_pkt_read_u8(frag, pos, &pos, &length); if (!frag) { NET_ERR("option parsing, bad length"); return NET_DROP; @@ -703,8 +703,8 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf, return NET_DROP; } - frag = net_nbuf_read(frag, pos, &pos, length, - netmask.s4_addr); + frag = net_pkt_read(frag, pos, &pos, length, + netmask.s4_addr); if (!frag && pos) { NET_ERR("options_subnet_mask, short packet"); return NET_DROP; @@ -728,9 +728,8 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf, return NET_DROP; } - frag = net_nbuf_read(frag, pos, &pos, 4, - router.s4_addr); - frag = net_nbuf_skip(frag, pos, &pos, length - 4); + frag = net_pkt_read(frag, pos, &pos, 4, router.s4_addr); + frag = net_pkt_skip(frag, pos, &pos, length - 4); if (!frag && pos) { NET_ERR("options_router, short packet"); return NET_DROP; @@ -747,8 +746,8 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf, return NET_DROP; } - frag = net_nbuf_read_be32(frag, pos, &pos, - &iface->dhcpv4.lease_time); + frag = net_pkt_read_be32(frag, pos, &pos, + &iface->dhcpv4.lease_time); NET_DBG("options_lease_time: %u", iface->dhcpv4.lease_time); if (!iface->dhcpv4.lease_time) { @@ -762,8 +761,8 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf, return NET_DROP; } - frag = net_nbuf_read_be32(frag, pos, &pos, - &iface->dhcpv4.renewal_time); + frag = net_pkt_read_be32(frag, pos, &pos, + &iface->dhcpv4.renewal_time); NET_DBG("options_renewal: %u", iface->dhcpv4.renewal_time); if (!iface->dhcpv4.renewal_time) { @@ -777,8 +776,8 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf, return NET_DROP; } - frag = net_nbuf_read_be32(frag, pos, &pos, - &iface->dhcpv4.rebinding_time); + frag = net_pkt_read_be32(frag, pos, &pos, + &iface->dhcpv4.rebinding_time); NET_DBG("options_rebinding: %u", iface->dhcpv4.rebinding_time); if (!iface->dhcpv4.rebinding_time) { @@ -792,8 +791,8 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf, return NET_DROP; } - frag = net_nbuf_read(frag, pos, &pos, length, - iface->dhcpv4.server_id.s4_addr); + frag = net_pkt_read(frag, pos, &pos, length, + iface->dhcpv4.server_id.s4_addr); NET_DBG("options_server_id: %s", net_sprint_ipv4_addr(&iface->dhcpv4.server_id)); break; @@ -805,13 +804,13 @@ static enum net_verdict parse_options(struct net_if *iface, struct net_buf *buf, return NET_DROP; } - frag = net_nbuf_read_u8(frag, pos, &pos, &v); + frag = net_pkt_read_u8(frag, pos, &pos, &v); *msg_type = v; break; } default: NET_DBG("option unknown: %d", type); - frag = net_nbuf_skip(frag, pos, &pos, length); + frag = net_pkt_skip(frag, pos, &pos, length); break; } @@ -939,7 +938,7 @@ static enum net_verdict net_dhcpv4_input(struct net_conn *conn, return NET_DROP; } - iface = net_nbuf_iface(buf); + iface = net_pkt_iface(buf); if (!iface) { NET_DBG("no iface"); return NET_DROP; @@ -984,7 +983,7 @@ static enum net_verdict net_dhcpv4_input(struct net_conn *conn, sizeof(msg->yiaddr)); /* SNAME, FILE are not used at the moment, skip it */ - frag = net_nbuf_skip(frag, min, &pos, SIZE_OF_SNAME + SIZE_OF_FILE); + frag = net_pkt_skip(frag, min, &pos, SIZE_OF_SNAME + SIZE_OF_FILE); if (!frag && pos) { NET_DBG("short packet while skipping sname"); goto drop; @@ -995,7 +994,7 @@ static enum net_verdict net_dhcpv4_input(struct net_conn *conn, goto drop; } - net_nbuf_unref(buf); + net_pkt_unref(buf); handle_dhcpv4_reply(iface, msg_type); diff --git a/subsys/net/ip/icmpv4.c b/subsys/net/ip/icmpv4.c index 523b62e9f..f0fec031a 100644 --- a/subsys/net/ip/icmpv4.c +++ b/subsys/net/ip/icmpv4.c @@ -16,7 +16,7 @@ #include <errno.h> #include <misc/slist.h> #include <net/net_core.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_if.h> #include "net_private.h" #include "icmpv4.h" @@ -86,7 +86,7 @@ static inline void setup_ipv4_header(struct net_buf *buf, uint8_t extra_len, NET_IPV4_BUF(buf)->offset[0] = NET_IPV4_BUF(buf)->offset[1] = 0; NET_IPV4_BUF(buf)->id[0] = NET_IPV4_BUF(buf)->id[1] = 0; - net_nbuf_set_ip_hdr_len(buf, sizeof(struct net_ipv4_hdr)); + net_pkt_set_ip_hdr_len(buf, sizeof(struct net_ipv4_hdr)); NET_IPV4_BUF(buf)->chksum = 0; NET_IPV4_BUF(buf)->chksum = ~net_calc_chksum_ipv4(buf); @@ -94,7 +94,7 @@ static inline void setup_ipv4_header(struct net_buf *buf, uint8_t extra_len, NET_ICMP_BUF(buf)->type = icmp_type; NET_ICMP_BUF(buf)->code = icmp_code; - memset(net_nbuf_icmp_data(buf) + sizeof(struct net_icmp_hdr), 0, + memset(net_pkt_icmp_data(buf) + sizeof(struct net_icmp_hdr), 0, NET_ICMPV4_UNUSED_LEN); } @@ -113,15 +113,15 @@ int net_icmpv4_send_echo_request(struct net_if *iface, * as IPv4 cannot be used in 802.15.4 where it is the reserve * size can change depending on address. */ - buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, + buf = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface, (const struct in6_addr *)dst), K_FOREVER); - frag = net_nbuf_get_frag(buf, K_FOREVER); + frag = net_pkt_get_frag(buf, K_FOREVER); net_buf_frag_add(buf, frag); - net_nbuf_set_family(buf, AF_INET); - net_nbuf_set_iface(buf, iface); + net_pkt_set_family(buf, AF_INET); + net_pkt_set_iface(buf, iface); setup_ipv4_header(buf, 0, net_if_ipv4_get_ttl(iface), NET_ICMPV4_ECHO_REQUEST, 0); @@ -157,7 +157,7 @@ int net_icmpv4_send_echo_request(struct net_if *iface, return 0; } - net_nbuf_unref(buf); + net_pkt_unref(buf); net_stats_update_icmp_drop(); return -EIO; @@ -166,7 +166,7 @@ int net_icmpv4_send_echo_request(struct net_if *iface, int net_icmpv4_send_error(struct net_buf *orig, uint8_t type, uint8_t code) { struct net_buf *buf, *frag; - struct net_if *iface = net_nbuf_iface(orig); + struct net_if *iface = net_pkt_iface(orig); size_t extra_len, reserve; struct in_addr addr, *src, *dst; int err = -EIO; @@ -179,9 +179,9 @@ int net_icmpv4_send_error(struct net_buf *orig, uint8_t type, uint8_t code) } } - iface = net_nbuf_iface(orig); + iface = net_pkt_iface(orig); - buf = net_nbuf_get_reserve_tx(0, BUF_WAIT_TIME); + buf = net_pkt_get_reserve_tx(0, BUF_WAIT_TIME); if (!buf) { err = -ENOMEM; goto drop_no_buf; @@ -197,7 +197,7 @@ int net_icmpv4_send_error(struct net_buf *orig, uint8_t type, uint8_t code) extra_len = sizeof(struct net_ipv4_hdr); /* FIXME, add TCP header length too */ } else { - size_t space = CONFIG_NET_NBUF_DATA_SIZE - + size_t space = CONFIG_NET_BUF_DATA_SIZE - net_if_get_ll_reserve(iface, NULL); if (reserve > space) { @@ -208,7 +208,7 @@ int net_icmpv4_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. + * addresses as the net_pkt_copy() will mangle the original buffer. */ src = &NET_IPV4_BUF(orig)->src; dst = &NET_IPV4_BUF(orig)->dst; @@ -216,16 +216,16 @@ int net_icmpv4_send_error(struct net_buf *orig, uint8_t type, uint8_t code) /* We only copy minimal IPv4 + next header from original message. * This is so that the memory pressure is minimized. */ - frag = net_nbuf_copy(orig, extra_len, reserve, BUF_WAIT_TIME); + frag = net_pkt_copy(orig, extra_len, reserve, BUF_WAIT_TIME); if (!frag) { err = -ENOMEM; goto drop; } net_buf_frag_add(buf, frag); - net_nbuf_set_family(buf, AF_INET); - net_nbuf_set_iface(buf, iface); - net_nbuf_set_ll_reserve(buf, net_buf_headroom(frag)); + net_pkt_set_family(buf, AF_INET); + net_pkt_set_iface(buf, iface); + net_pkt_set_ll_reserve(buf, net_buf_headroom(frag)); setup_ipv4_header(buf, extra_len, net_if_ipv4_get_ttl(iface), type, code); @@ -234,10 +234,10 @@ int net_icmpv4_send_error(struct net_buf *orig, uint8_t type, uint8_t code) net_ipaddr_copy(&NET_IPV4_BUF(buf)->src, dst); net_ipaddr_copy(&NET_IPV4_BUF(buf)->dst, &addr); - net_nbuf_ll_src(buf)->addr = net_nbuf_ll_dst(orig)->addr; - net_nbuf_ll_src(buf)->len = net_nbuf_ll_dst(orig)->len; - net_nbuf_ll_dst(buf)->addr = net_nbuf_ll_src(orig)->addr; - net_nbuf_ll_dst(buf)->len = net_nbuf_ll_src(orig)->len; + net_pkt_ll_src(buf)->addr = net_pkt_ll_dst(orig)->addr; + net_pkt_ll_src(buf)->len = net_pkt_ll_dst(orig)->len; + net_pkt_ll_dst(buf)->addr = net_pkt_ll_src(orig)->addr; + net_pkt_ll_dst(buf)->len = net_pkt_ll_src(orig)->len; NET_ICMP_BUF(buf)->chksum = 0; NET_ICMP_BUF(buf)->chksum = ~net_calc_chksum_icmpv4(buf); @@ -260,7 +260,7 @@ int net_icmpv4_send_error(struct net_buf *orig, uint8_t type, uint8_t code) } drop: - net_nbuf_unref(buf); + net_pkt_unref(buf); drop_no_buf: net_stats_update_icmp_drop(); diff --git a/subsys/net/ip/icmpv4.h b/subsys/net/ip/icmpv4.h index b26703af1..2938ad720 100644 --- a/subsys/net/ip/icmpv4.h +++ b/subsys/net/ip/icmpv4.h @@ -16,7 +16,7 @@ #include <zephyr/types.h> #include <net/net_ip.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #define NET_ICMPV4_DST_UNREACH 3 /* Destination unreachable */ #define NET_ICMPV4_ECHO_REQUEST 8 @@ -31,7 +31,7 @@ struct net_icmpv4_echo_req { } __packed; #define NET_ICMPV4_ECHO_REQ_BUF(buf) \ - ((struct net_icmpv4_echo_req *)(net_nbuf_icmp_data(buf) + \ + ((struct net_icmpv4_echo_req *)(net_pkt_icmp_data(buf) + \ sizeof(struct net_icmp_hdr))) typedef enum net_verdict (*icmpv4_callback_handler_t)(struct net_buf *buf); diff --git a/subsys/net/ip/icmpv6.c b/subsys/net/ip/icmpv6.c index 8913565cb..2897f2dd0 100644 --- a/subsys/net/ip/icmpv6.c +++ b/subsys/net/ip/icmpv6.c @@ -17,7 +17,7 @@ #include <misc/slist.h> #include <misc/byteorder.h> #include <net/net_core.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_if.h> #include "net_private.h" #include "icmpv6.h" @@ -88,14 +88,14 @@ static inline void setup_ipv6_header(struct net_buf *buf, uint16_t extra_len, NET_IPV6_BUF(buf)->nexthdr = IPPROTO_ICMPV6; NET_IPV6_BUF(buf)->hop_limit = hop_limit; - net_nbuf_set_ip_hdr_len(buf, sizeof(struct net_ipv6_hdr)); + net_pkt_set_ip_hdr_len(buf, sizeof(struct net_ipv6_hdr)); NET_ICMP_BUF(buf)->type = icmp_type; NET_ICMP_BUF(buf)->code = icmp_code; /* ICMPv6 header has 4 unused bytes that must be zero, RFC 4443 ch 3.1 */ - memset(net_nbuf_icmp_data(buf) + sizeof(struct net_icmp_hdr), 0, + memset(net_pkt_icmp_data(buf) + sizeof(struct net_icmp_hdr), 0, NET_ICMPV6_UNUSED_LEN); } @@ -133,9 +133,9 @@ static enum net_verdict handle_echo_request(struct net_buf *orig) echo_request_debug(orig); - iface = net_nbuf_iface(orig); + iface = net_pkt_iface(orig); - buf = net_nbuf_get_reserve_tx(0, BUF_WAIT_TIME); + buf = net_pkt_get_reserve_tx(0, BUF_WAIT_TIME); if (!buf) { goto drop_no_buf; } @@ -143,21 +143,21 @@ static enum net_verdict handle_echo_request(struct net_buf *orig) payload_len = sys_get_be16(NET_IPV6_BUF(orig)->len) - sizeof(NET_ICMPH_LEN) - NET_ICMPV6_UNUSED_LEN; - frag = net_nbuf_copy_all(orig, 0, BUF_WAIT_TIME); + frag = net_pkt_copy_all(orig, 0, BUF_WAIT_TIME); if (!frag) { goto drop; } net_buf_frag_add(buf, frag); - net_nbuf_set_family(buf, AF_INET6); - net_nbuf_set_iface(buf, iface); - net_nbuf_set_ll_reserve(buf, net_buf_headroom(frag)); - net_nbuf_set_ip_hdr_len(buf, sizeof(struct net_ipv6_hdr)); + net_pkt_set_family(buf, AF_INET6); + net_pkt_set_iface(buf, iface); + net_pkt_set_ll_reserve(buf, net_buf_headroom(frag)); + net_pkt_set_ip_hdr_len(buf, sizeof(struct net_ipv6_hdr)); - if (net_nbuf_ext_len(orig)) { - net_nbuf_set_ext_len(buf, net_nbuf_ext_len(orig)); + if (net_pkt_ext_len(orig)) { + net_pkt_set_ext_len(buf, net_pkt_ext_len(orig)); } else { - net_nbuf_set_ext_len(buf, 0); + net_pkt_set_ext_len(buf, 0); } /* Set up IPv6 Header fields */ @@ -198,13 +198,13 @@ static enum net_verdict handle_echo_request(struct net_buf *orig) #endif } - net_nbuf_ll_src(buf)->addr = net_nbuf_ll_dst(orig)->addr; - net_nbuf_ll_src(buf)->len = net_nbuf_ll_dst(orig)->len; + net_pkt_ll_src(buf)->addr = net_pkt_ll_dst(orig)->addr; + net_pkt_ll_src(buf)->len = net_pkt_ll_dst(orig)->len; /* We must not set the destination ll address here but trust * that it is set properly using a value from neighbor cache. */ - net_nbuf_ll_dst(buf)->addr = NULL; + net_pkt_ll_dst(buf)->addr = NULL; NET_ICMP_BUF(buf)->chksum = 0; NET_ICMP_BUF(buf)->chksum = ~net_calc_chksum_icmpv6(buf); @@ -215,13 +215,13 @@ static enum net_verdict handle_echo_request(struct net_buf *orig) goto drop; } - net_nbuf_unref(orig); + net_pkt_unref(orig); net_stats_update_icmp_sent(); return NET_OK; drop: - net_nbuf_unref(buf); + net_pkt_unref(buf); drop_no_buf: net_stats_update_icmp_drop(); @@ -245,9 +245,9 @@ int net_icmpv6_send_error(struct net_buf *orig, uint8_t type, uint8_t code, } } - iface = net_nbuf_iface(orig); + iface = net_pkt_iface(orig); - buf = net_nbuf_get_reserve_tx(0, BUF_WAIT_TIME); + buf = net_pkt_get_reserve_tx(0, BUF_WAIT_TIME); if (!buf) { err = -ENOMEM; goto drop_no_buf; @@ -266,7 +266,7 @@ int net_icmpv6_send_error(struct net_buf *orig, uint8_t type, uint8_t code, extra_len = sizeof(struct net_ipv6_hdr) + sizeof(struct net_tcp_hdr); } else { - size_t space = CONFIG_NET_NBUF_DATA_SIZE - + size_t space = CONFIG_NET_BUF_DATA_SIZE - net_if_get_ll_reserve(iface, &NET_IPV6_BUF(orig)->dst); @@ -280,17 +280,17 @@ int net_icmpv6_send_error(struct net_buf *orig, uint8_t type, uint8_t code, /* We only copy minimal IPv6 + next header from original message. * This is so that the memory pressure is minimized. */ - frag = net_nbuf_copy(orig, extra_len, reserve, BUF_WAIT_TIME); + frag = net_pkt_copy(orig, extra_len, reserve, BUF_WAIT_TIME); if (!frag) { err = -ENOMEM; goto drop; } net_buf_frag_add(buf, frag); - net_nbuf_set_family(buf, AF_INET6); - net_nbuf_set_iface(buf, iface); - net_nbuf_set_ll_reserve(buf, net_buf_headroom(frag)); - net_nbuf_set_ext_len(buf, 0); + net_pkt_set_family(buf, AF_INET6); + net_pkt_set_iface(buf, iface); + net_pkt_set_ll_reserve(buf, net_buf_headroom(frag)); + net_pkt_set_ext_len(buf, 0); setup_ipv6_header(buf, extra_len, net_if_ipv6_get_hop_limit(iface), type, code); @@ -298,7 +298,7 @@ int net_icmpv6_send_error(struct net_buf *orig, uint8_t type, uint8_t code, /* Depending on error option, we store the param into the ICMP message. */ if (type == NET_ICMPV6_PARAM_PROBLEM) { - sys_put_be32(param, net_nbuf_icmp_data(buf) + + sys_put_be32(param, net_pkt_icmp_data(buf) + sizeof(struct net_icmp_hdr)); } @@ -318,10 +318,10 @@ int net_icmpv6_send_error(struct net_buf *orig, uint8_t type, uint8_t code, net_ipaddr_copy(&NET_IPV6_BUF(buf)->dst, &addr); } - net_nbuf_ll_src(buf)->addr = net_nbuf_ll_dst(orig)->addr; - net_nbuf_ll_src(buf)->len = net_nbuf_ll_dst(orig)->len; - net_nbuf_ll_dst(buf)->addr = net_nbuf_ll_src(orig)->addr; - net_nbuf_ll_dst(buf)->len = net_nbuf_ll_src(orig)->len; + net_pkt_ll_src(buf)->addr = net_pkt_ll_dst(orig)->addr; + net_pkt_ll_src(buf)->len = net_pkt_ll_dst(orig)->len; + net_pkt_ll_dst(buf)->addr = net_pkt_ll_src(orig)->addr; + net_pkt_ll_dst(buf)->len = net_pkt_ll_src(orig)->len; NET_ICMP_BUF(buf)->chksum = 0; NET_ICMP_BUF(buf)->chksum = ~net_calc_chksum_icmpv6(buf); @@ -343,7 +343,7 @@ int net_icmpv6_send_error(struct net_buf *orig, uint8_t type, uint8_t code, } drop: - net_nbuf_unref(buf); + net_pkt_unref(buf); drop_no_buf: net_stats_update_icmp_drop(); @@ -361,19 +361,19 @@ int net_icmpv6_send_echo_request(struct net_if *iface, src = net_if_ipv6_select_src_addr(iface, dst); - buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, dst), + buf = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface, dst), K_FOREVER); buf = net_ipv6_create_raw(buf, src, dst, iface, IPPROTO_ICMPV6); - net_nbuf_set_family(buf, AF_INET6); - net_nbuf_set_iface(buf, iface); + net_pkt_set_family(buf, AF_INET6); + net_pkt_set_iface(buf, iface); - net_nbuf_append_u8(buf, NET_ICMPV6_ECHO_REQUEST); - net_nbuf_append_u8(buf, 0); /* code */ - net_nbuf_append_be16(buf, 0); /* checksum */ - net_nbuf_append_be16(buf, identifier); - net_nbuf_append_be16(buf, sequence); + net_pkt_append_u8(buf, NET_ICMPV6_ECHO_REQUEST); + net_pkt_append_u8(buf, 0); /* code */ + net_pkt_append_be16(buf, 0); /* checksum */ + net_pkt_append_be16(buf, identifier); + net_pkt_append_be16(buf, sequence); net_ipaddr_copy(&NET_IPV6_BUF(buf)->src, src); net_ipaddr_copy(&NET_IPV6_BUF(buf)->dst, dst); @@ -403,7 +403,7 @@ int net_icmpv6_send_echo_request(struct net_if *iface, } drop: - net_nbuf_unref(buf); + net_pkt_unref(buf); net_stats_update_icmp_drop(); return -EIO; diff --git a/subsys/net/ip/icmpv6.h b/subsys/net/ip/icmpv6.h index 4e6489888..a47aa273f 100644 --- a/subsys/net/ip/icmpv6.h +++ b/subsys/net/ip/icmpv6.h @@ -17,7 +17,7 @@ #include <zephyr/types.h> #include <net/net_ip.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> struct net_icmpv6_ns_hdr { uint32_t reserved; @@ -76,24 +76,24 @@ struct net_icmpv6_nd_opt_6co { } __packed; #define NET_ICMPV6_NS_BUF(buf) \ - ((struct net_icmpv6_ns_hdr *)(net_nbuf_icmp_data(buf) + \ + ((struct net_icmpv6_ns_hdr *)(net_pkt_icmp_data(buf) + \ sizeof(struct net_icmp_hdr))) #define NET_ICMPV6_ND_OPT_HDR_BUF(buf) \ - ((struct net_icmpv6_nd_opt_hdr *)(net_nbuf_icmp_data(buf) + \ + ((struct net_icmpv6_nd_opt_hdr *)(net_pkt_icmp_data(buf) + \ sizeof(struct net_icmp_hdr) + \ - net_nbuf_ext_opt_len(buf))) + net_pkt_ext_opt_len(buf))) #define NET_ICMPV6_NA_BUF(buf) \ - ((struct net_icmpv6_na_hdr *)(net_nbuf_icmp_data(buf) + \ + ((struct net_icmpv6_na_hdr *)(net_pkt_icmp_data(buf) + \ sizeof(struct net_icmp_hdr))) #define NET_ICMPV6_RS_BUF(buf) \ - ((struct net_icmpv6_rs_hdr *)(net_nbuf_icmp_data(buf) + \ + ((struct net_icmpv6_rs_hdr *)(net_pkt_icmp_data(buf) + \ sizeof(struct net_icmp_hdr))) #define NET_ICMPV6_RA_BUF(buf) \ - ((struct net_icmpv6_ra_hdr *)(net_nbuf_icmp_data(buf) + \ + ((struct net_icmpv6_ra_hdr *)(net_pkt_icmp_data(buf) + \ sizeof(struct net_icmp_hdr))) #define NET_ICMPV6_ND_O_FLAG(flag) ((flag) & 0x40) diff --git a/subsys/net/ip/ipv4.c b/subsys/net/ip/ipv4.c index 6ffc9e25d..40094bd4d 100644 --- a/subsys/net/ip/ipv4.c +++ b/subsys/net/ip/ipv4.c @@ -15,7 +15,7 @@ #include <errno.h> #include <net/net_core.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_stats.h> #include <net/net_context.h> #include "net_private.h" @@ -32,7 +32,7 @@ struct net_buf *net_ipv4_create_raw(struct net_buf *buf, { struct net_buf *header; - header = net_nbuf_get_frag(buf, K_FOREVER); + header = net_pkt_get_frag(buf, K_FOREVER); net_buf_frag_insert(buf, header); @@ -49,8 +49,8 @@ struct net_buf *net_ipv4_create_raw(struct net_buf *buf, NET_IPV4_BUF(buf)->proto = next_header; - net_nbuf_set_ip_hdr_len(buf, sizeof(struct net_ipv4_hdr)); - net_nbuf_set_family(buf, AF_INET); + net_pkt_set_ip_hdr_len(buf, sizeof(struct net_ipv4_hdr)); + net_pkt_set_family(buf, AF_INET); net_buf_add(header, sizeof(struct net_ipv4_hdr)); @@ -70,7 +70,7 @@ struct net_buf *net_ipv4_create(struct net_context *context, if (net_is_ipv4_addr_unspecified(src) || net_is_ipv4_addr_mcast(src)) { - src = &net_nbuf_iface(buf)->ipv4.unicast[0].address.in_addr; + src = &net_pkt_iface(buf)->ipv4.unicast[0].address.in_addr; } return net_ipv4_create_raw(buf, @@ -85,7 +85,7 @@ int net_ipv4_finalize_raw(struct net_buf *buf, uint8_t next_header) /* Set the length of the IPv4 header */ size_t total_len; - net_nbuf_compact(buf); + net_pkt_compact(buf); total_len = net_buf_frags_len(buf->frags); @@ -165,7 +165,7 @@ enum net_verdict net_ipv4_process_pkt(struct net_buf *buf) } while (0); #endif /* CONFIG_NET_DEBUG_IPV4 */ - net_nbuf_set_ip_hdr_len(buf, sizeof(struct net_ipv4_hdr)); + net_pkt_set_ip_hdr_len(buf, sizeof(struct net_ipv4_hdr)); if (!net_is_my_ipv4_addr(&hdr->dst)) { #if defined(CONFIG_NET_DHCPV4) diff --git a/subsys/net/ip/ipv4.h b/subsys/net/ip/ipv4.h index a46a5a777..ad5c3b98d 100644 --- a/subsys/net/ip/ipv4.h +++ b/subsys/net/ip/ipv4.h @@ -16,7 +16,7 @@ #include <zephyr/types.h> #include <net/net_ip.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_if.h> #include <net/net_context.h> diff --git a/subsys/net/ip/ipv6.c b/subsys/net/ip/ipv6.c index 9bb23e95d..bd4015dea 100644 --- a/subsys/net/ip/ipv6.c +++ b/subsys/net/ip/ipv6.c @@ -20,7 +20,7 @@ #include <errno.h> #include <net/net_core.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_stats.h> #include <net/net_context.h> #include <net/net_mgmt.h> @@ -213,7 +213,7 @@ static inline void nbr_clear_ns_pending(struct net_ipv6_nbr_data *data) } if (data->pending) { - net_nbuf_unref(data->pending); + net_pkt_unref(data->pending); data->pending = NULL; } } @@ -270,10 +270,10 @@ static void ns_reply_timeout(struct k_work *work) net_sprint_ipv6_addr(&NET_IPV6_BUF(data->pending)->dst)); /* To unref when pending variable was set */ - net_nbuf_unref(data->pending); + net_pkt_unref(data->pending); /* To unref the original buf allocation */ - net_nbuf_unref(data->pending); + net_pkt_unref(data->pending); data->pending = NULL; @@ -454,7 +454,7 @@ static inline struct net_nbr *nbr_add(struct net_buf *buf, bool is_router, enum net_ipv6_nbr_state state) { - return net_ipv6_nbr_add(net_nbuf_iface(buf), &NET_IPV6_BUF(buf)->src, + return net_ipv6_nbr_add(net_pkt_iface(buf), &NET_IPV6_BUF(buf)->src, lladdr, is_router, state); } @@ -513,12 +513,12 @@ int net_ipv6_find_last_ext_hdr(struct net_buf *buf) next = hdr->nexthdr; while (frag) { - frag = net_nbuf_read_u8(frag, offset, &offset, &next_hdr); + frag = net_pkt_read_u8(frag, offset, &offset, &next_hdr); if (frag != buf->frags) { break; } - frag = net_nbuf_read_u8(frag, offset, &offset, &length); + frag = net_pkt_read_u8(frag, offset, &offset, &length); if (!frag && offset == 0xffff) { pos = -EINVAL; goto fail; @@ -577,7 +577,7 @@ struct net_buf *net_ipv6_create_raw(struct net_buf *buf, { struct net_buf *header; - header = net_nbuf_get_frag(buf, K_FOREVER); + header = net_pkt_get_frag(buf, K_FOREVER); net_buf_frag_insert(buf, header); @@ -588,7 +588,7 @@ struct net_buf *net_ipv6_create_raw(struct net_buf *buf, NET_IPV6_BUF(buf)->nexthdr = 0; /* User can tweak the default hop limit if needed */ - NET_IPV6_BUF(buf)->hop_limit = net_nbuf_ipv6_hop_limit(buf); + NET_IPV6_BUF(buf)->hop_limit = net_pkt_ipv6_hop_limit(buf); if (NET_IPV6_BUF(buf)->hop_limit == 0) { NET_IPV6_BUF(buf)->hop_limit = net_if_ipv6_get_hop_limit(iface); @@ -597,11 +597,11 @@ struct net_buf *net_ipv6_create_raw(struct net_buf *buf, net_ipaddr_copy(&NET_IPV6_BUF(buf)->dst, dst); net_ipaddr_copy(&NET_IPV6_BUF(buf)->src, src); - net_nbuf_set_ext_len(buf, 0); + net_pkt_set_ext_len(buf, 0); NET_IPV6_BUF(buf)->nexthdr = next_header; - net_nbuf_set_ip_hdr_len(buf, sizeof(struct net_ipv6_hdr)); - net_nbuf_set_family(buf, AF_INET6); + net_pkt_set_ip_hdr_len(buf, sizeof(struct net_ipv6_hdr)); + net_pkt_set_family(buf, AF_INET6); net_buf_add(header, sizeof(struct net_ipv6_hdr)); @@ -621,7 +621,7 @@ struct net_buf *net_ipv6_create(struct net_context *context, if (net_is_ipv6_addr_unspecified(src) || net_is_ipv6_addr_mcast(src)) { - src = net_if_ipv6_select_src_addr(net_nbuf_iface(buf), + src = net_if_ipv6_select_src_addr(net_pkt_iface(buf), (struct in6_addr *)dst); } @@ -647,7 +647,7 @@ int net_ipv6_finalize_raw(struct net_buf *buf, uint8_t next_header) } #endif - net_nbuf_compact(buf); + net_pkt_compact(buf); total_len = net_buf_frags_len(buf->frags); @@ -725,19 +725,19 @@ static struct net_buf *update_ll_reserve(struct net_buf *buf, * as we already know everything about the destination of * the packet. */ - if (net_nbuf_forwarding(buf)) { + if (net_pkt_forwarding(buf)) { return buf; } - reserve = net_if_get_ll_reserve(net_nbuf_iface(buf), addr); - if (reserve == net_nbuf_ll_reserve(buf)) { + reserve = net_if_get_ll_reserve(net_pkt_iface(buf), addr); + if (reserve == net_pkt_ll_reserve(buf)) { return buf; } NET_DBG("Adjust reserve old %d new %d", - net_nbuf_ll_reserve(buf), reserve); + net_pkt_ll_reserve(buf), reserve); - net_nbuf_set_ll_reserve(buf, reserve); + net_pkt_set_ll_reserve(buf, reserve); orig_frag = buf->frags; copy_len = orig_frag->len; @@ -749,7 +749,7 @@ static struct net_buf *update_ll_reserve(struct net_buf *buf, while (orig_frag) { if (!room_len) { - frag = net_nbuf_get_frag(buf, K_FOREVER); + frag = net_pkt_get_frag(buf, K_FOREVER); net_buf_frag_add(buf, frag); @@ -777,7 +777,7 @@ static struct net_buf *update_ll_reserve(struct net_buf *buf, orig_frag = orig_frag->frags; tmp->frags = NULL; - net_nbuf_unref(tmp); + net_pkt_unref(tmp); if (!orig_frag) { break; @@ -803,16 +803,16 @@ struct net_buf *net_ipv6_prepare_for_send(struct net_buf *buf) /* If we have already fragmented the packet, the fragment id will * contain a proper value and we can skip other checks. */ - if (net_nbuf_ipv6_fragment_id(buf) == 0) { + if (net_pkt_ipv6_fragment_id(buf) == 0) { size_t pkt_len = net_buf_frags_len(buf); if (pkt_len > NET_IPV6_MTU) { int ret; - ret = net_ipv6_send_fragmented_pkt(net_nbuf_iface(buf), + ret = net_ipv6_send_fragmented_pkt(net_pkt_iface(buf), buf, pkt_len); if (ret < 0) { - net_nbuf_unref(buf); + net_pkt_unref(buf); } /* No need to continue with the sending as the packet @@ -827,11 +827,11 @@ struct net_buf *net_ipv6_prepare_for_send(struct net_buf *buf) /* Workaround Linux bug, see: * https://jira.zephyrproject.org/browse/ZEP-1656 */ - if (atomic_test_bit(net_nbuf_iface(buf)->flags, NET_IF_POINTOPOINT)) { + if (atomic_test_bit(net_pkt_iface(buf)->flags, NET_IF_POINTOPOINT)) { return buf; } - if (net_nbuf_ll_dst(buf)->addr || + if (net_pkt_ll_dst(buf)->addr || net_is_ipv6_addr_mcast(&NET_IPV6_BUF(buf)->dst)) { return update_ll_reserve(buf, &NET_IPV6_BUF(buf)->dst); } @@ -839,7 +839,7 @@ struct net_buf *net_ipv6_prepare_for_send(struct net_buf *buf) if (net_if_ipv6_addr_onlink(&iface, &NET_IPV6_BUF(buf)->dst)) { nexthop = &NET_IPV6_BUF(buf)->dst; - net_nbuf_set_iface(buf, iface); + net_pkt_set_iface(buf, iface); } else { /* We need to figure out where the destination * host is located. @@ -859,7 +859,7 @@ struct net_buf *net_ipv6_prepare_for_send(struct net_buf *buf) net_sprint_ipv6_addr( &NET_IPV6_BUF(buf)->dst)); - net_nbuf_unref(buf); + net_pkt_unref(buf); return NULL; } } else { @@ -883,7 +883,7 @@ struct net_buf *net_ipv6_prepare_for_send(struct net_buf *buf) } if (net_rpl_update_header(buf, nexthop) < 0) { - net_nbuf_unref(buf); + net_pkt_unref(buf); return NULL; } @@ -892,7 +892,7 @@ struct net_buf *net_ipv6_prepare_for_send(struct net_buf *buf) * figure out the interface using nexthop instead. */ if (net_if_ipv6_addr_onlink(&iface, nexthop)) { - net_nbuf_set_iface(buf, iface); + net_pkt_set_iface(buf, iface); } /* If the above check returns null, we try to send @@ -901,11 +901,11 @@ struct net_buf *net_ipv6_prepare_for_send(struct net_buf *buf) } try_send: - nbr = nbr_lookup(&net_neighbor.table, net_nbuf_iface(buf), nexthop); + nbr = nbr_lookup(&net_neighbor.table, net_pkt_iface(buf), nexthop); NET_DBG("Neighbor lookup %p (%d) iface %p addr %s state %s", nbr, nbr ? nbr->idx : NET_NBR_LLADDR_UNKNOWN, - net_nbuf_iface(buf), + net_pkt_iface(buf), net_sprint_ipv6_addr(nexthop), nbr ? net_ipv6_nbr_state2str(net_ipv6_nbr_data(nbr)->state) : "-"); @@ -915,8 +915,8 @@ try_send: lladdr = net_nbr_get_lladdr(nbr->idx); - net_nbuf_ll_dst(buf)->addr = lladdr->addr; - net_nbuf_ll_dst(buf)->len = lladdr->len; + net_pkt_ll_dst(buf)->addr = lladdr->addr; + net_pkt_ll_dst(buf)->len = lladdr->len; NET_DBG("Neighbor %p addr %s", nbr, net_sprint_ll_addr(lladdr->addr, lladdr->len)); @@ -939,7 +939,7 @@ try_send: #if defined(CONFIG_NET_IPV6_ND) /* We need to send NS and wait for NA before sending the packet. */ - if (net_ipv6_send_ns(net_nbuf_iface(buf), + if (net_ipv6_send_ns(net_pkt_iface(buf), buf, &NET_IPV6_BUF(buf)->src, NULL, @@ -956,7 +956,7 @@ try_send: NET_DBG("Buf %p (frag %p) cannot be sent, dropping it.", buf, buf->frags); - net_nbuf_unref(buf); + net_pkt_unref(buf); #endif /* CONFIG_NET_IPV6_ND */ return NULL; @@ -1049,8 +1049,8 @@ static inline void handle_ns_neighbor(struct net_buf *buf, * 2 * 8 bytes - 2 - padding. * The formula above needs to be adjusted. */ - if (net_nbuf_ll_src(buf)->len < lladdr.len) { - lladdr.len = net_nbuf_ll_src(buf)->len; + if (net_pkt_ll_src(buf)->len < lladdr.len) { + lladdr.len = net_pkt_ll_src(buf)->len; } nbr_add(buf, &lladdr, false, NET_IPV6_NBR_STATE_INCOMPLETE); @@ -1063,26 +1063,26 @@ 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(net_if_get_ll_reserve(iface, dst), + buf = net_pkt_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); + frag = net_pkt_get_frag(buf, K_FOREVER); NET_ASSERT_INFO(frag, "Out of DATA buffers"); net_buf_frag_add(buf, frag); - net_nbuf_set_iface(buf, iface); - net_nbuf_set_family(buf, AF_INET6); - net_nbuf_set_ip_hdr_len(buf, sizeof(struct net_ipv6_hdr)); + net_pkt_set_iface(buf, iface); + net_pkt_set_family(buf, AF_INET6); + net_pkt_set_ip_hdr_len(buf, sizeof(struct net_ipv6_hdr)); - net_nbuf_ll_clear(buf); + net_pkt_ll_clear(buf); llao_len = get_llao_len(iface); - net_nbuf_set_ext_len(buf, 0); + net_pkt_set_ext_len(buf, 0); setup_headers(buf, sizeof(struct net_icmpv6_na_hdr) + llao_len, NET_ICMPV6_NA); @@ -1091,14 +1091,14 @@ int net_ipv6_send_na(struct net_if *iface, struct in6_addr *src, net_ipaddr_copy(&NET_IPV6_BUF(buf)->dst, dst); net_ipaddr_copy(&NET_ICMPV6_NA_BUF(buf)->tgt, tgt); - set_llao(&net_nbuf_iface(buf)->link_addr, - net_nbuf_icmp_data(buf) + sizeof(struct net_icmp_hdr) + + set_llao(&net_pkt_iface(buf)->link_addr, + net_pkt_icmp_data(buf) + sizeof(struct net_icmp_hdr) + sizeof(struct net_icmpv6_na_hdr), llao_len, NET_ICMPV6_ND_OPT_TLLAO); NET_ICMPV6_NA_BUF(buf)->flags = flags; - net_nbuf_set_len(buf->frags, NET_IPV6ICMPH_LEN + + net_pkt_set_len(buf->frags, NET_IPV6ICMPH_LEN + sizeof(struct net_icmpv6_na_hdr) + llao_len); @@ -1119,7 +1119,7 @@ int net_ipv6_send_na(struct net_if *iface, struct in6_addr *src, return 0; drop: - net_nbuf_unref(buf); + net_pkt_unref(buf); net_stats_update_ipv6_nd_drop(); return -EINVAL; @@ -1155,7 +1155,7 @@ static enum net_verdict handle_ns_input(struct net_buf *buf) goto drop; } - net_nbuf_set_ext_opt_len(buf, sizeof(struct net_icmpv6_ns_hdr)); + net_pkt_set_ext_opt_len(buf, sizeof(struct net_icmpv6_ns_hdr)); hdr = NET_ICMPV6_ND_OPT_HDR_BUF(buf); /* The parsing gets tricky if the ND struct is split @@ -1169,7 +1169,7 @@ static enum net_verdict handle_ns_input(struct net_buf *buf) left_len = buf->frags->len - (sizeof(struct net_ipv6_hdr) + sizeof(struct net_icmp_hdr)); - while (net_nbuf_ext_opt_len(buf) < left_len && + while (net_pkt_ext_opt_len(buf) < left_len && left_len < buf->frags->len) { if (!hdr->len) { @@ -1191,12 +1191,12 @@ static enum net_verdict handle_ns_input(struct net_buf *buf) break; } - prev_opt_len = net_nbuf_ext_opt_len(buf); + prev_opt_len = net_pkt_ext_opt_len(buf); - net_nbuf_set_ext_opt_len(buf, net_nbuf_ext_opt_len(buf) + + net_pkt_set_ext_opt_len(buf, net_pkt_ext_opt_len(buf) + (hdr->len << 3)); - if (prev_opt_len == net_nbuf_ext_opt_len(buf)) { + if (prev_opt_len == net_pkt_ext_opt_len(buf)) { NET_ERR("Corrupted NS message"); goto drop; } @@ -1204,7 +1204,7 @@ static enum net_verdict handle_ns_input(struct net_buf *buf) hdr = NET_ICMPV6_ND_OPT_HDR_BUF(buf); } - ifaddr = net_if_ipv6_addr_lookup_by_iface(net_nbuf_iface(buf), + ifaddr = net_if_ipv6_addr_lookup_by_iface(net_pkt_iface(buf), &NET_ICMPV6_NS_BUF(buf)->tgt); if (!ifaddr) { NET_DBG("No such interface address %s", @@ -1231,9 +1231,9 @@ static enum net_verdict handle_ns_input(struct net_buf *buf) if (ifaddr->addr_state == NET_ADDR_TENTATIVE) { NET_DBG("DAD failed for %s iface %p", net_sprint_ipv6_addr(&ifaddr->address.in6_addr), - net_nbuf_iface(buf)); + net_pkt_iface(buf)); - dad_failed(net_nbuf_iface(buf), + dad_failed(net_pkt_iface(buf), &ifaddr->address.in6_addr); goto drop; } @@ -1241,7 +1241,7 @@ static enum net_verdict handle_ns_input(struct net_buf *buf) /* We reuse the received buffer to send the NA */ net_ipv6_addr_create_ll_allnodes_mcast(&NET_IPV6_BUF(buf)->dst); net_ipaddr_copy(&NET_IPV6_BUF(buf)->src, - net_if_ipv6_select_src_addr(net_nbuf_iface(buf), + net_if_ipv6_select_src_addr(net_pkt_iface(buf), &NET_IPV6_BUF(buf)->dst)); flags = NET_ICMPV6_NA_FLAG_OVERRIDE; goto send_na; @@ -1266,7 +1266,7 @@ static enum net_verdict handle_ns_input(struct net_buf *buf) } /* Neighbor Unreachability Detection (NUD) */ - if (net_if_ipv6_addr_lookup_by_iface(net_nbuf_iface(buf), + if (net_if_ipv6_addr_lookup_by_iface(net_pkt_iface(buf), &NET_IPV6_BUF(buf)->dst)) { net_ipaddr_copy(&NET_IPV6_BUF(buf)->dst, &NET_IPV6_BUF(buf)->src); @@ -1281,13 +1281,13 @@ static enum net_verdict handle_ns_input(struct net_buf *buf) } send_na: - ret = net_ipv6_send_na(net_nbuf_iface(buf), + ret = net_ipv6_send_na(net_pkt_iface(buf), &NET_IPV6_BUF(buf)->src, &NET_IPV6_BUF(buf)->dst, &ifaddr->address.in6_addr, flags); if (!ret) { - net_nbuf_unref(buf); + net_pkt_unref(buf); return NET_OK; } @@ -1411,11 +1411,11 @@ static inline bool handle_na_neighbor(struct net_buf *buf, ARG_UNUSED(hdr); - nbr = nbr_lookup(&net_neighbor.table, net_nbuf_iface(buf), + nbr = nbr_lookup(&net_neighbor.table, net_pkt_iface(buf), &NET_ICMPV6_NS_BUF(buf)->tgt); NET_DBG("Neighbor lookup %p iface %p addr %s", nbr, - net_nbuf_iface(buf), + net_pkt_iface(buf), net_sprint_ipv6_addr(&NET_ICMPV6_NS_BUF(buf)->tgt)); if (!nbr) { @@ -1433,10 +1433,10 @@ static inline bool handle_na_neighbor(struct net_buf *buf, return false; } - lladdr.len = net_nbuf_iface(buf)->link_addr.len; + lladdr.len = net_pkt_iface(buf)->link_addr.len; lladdr.addr = &tllao[NET_ICMPV6_OPT_DATA_OFFSET]; - if (net_nbr_link(nbr, net_nbuf_iface(buf), &lladdr)) { + if (net_nbr_link(nbr, net_pkt_iface(buf), &lladdr)) { nbr_free(nbr); return false; } @@ -1484,7 +1484,7 @@ static inline bool handle_na_neighbor(struct net_buf *buf, k_delayed_work_cancel( &net_ipv6_nbr_data(nbr)->reachable); - net_ipv6_nbr_set_reachable_timer(net_nbuf_iface(buf), + net_ipv6_nbr_set_reachable_timer(net_pkt_iface(buf), nbr); } else { ipv6_nbr_set_state(nbr, NET_IPV6_NBR_STATE_STALE); @@ -1528,7 +1528,7 @@ static inline bool handle_na_neighbor(struct net_buf *buf, k_delayed_work_cancel( &net_ipv6_nbr_data(nbr)->reachable); - net_ipv6_nbr_set_reachable_timer(net_nbuf_iface(buf), + net_ipv6_nbr_set_reachable_timer(net_pkt_iface(buf), nbr); } else { if (lladdr_changed) { @@ -1563,7 +1563,7 @@ send_pending: net_ipv6_nbr_data(nbr)->pending = NULL; } - net_nbuf_unref(pending); + net_pkt_unref(pending); } return true; @@ -1597,7 +1597,7 @@ static enum net_verdict handle_na_input(struct net_buf *buf) goto drop; } - net_nbuf_set_ext_opt_len(buf, sizeof(struct net_icmpv6_na_hdr)); + net_pkt_set_ext_opt_len(buf, sizeof(struct net_icmpv6_na_hdr)); hdr = NET_ICMPV6_ND_OPT_HDR_BUF(buf); /* The parsing gets tricky if the ND struct is split @@ -1611,7 +1611,7 @@ static enum net_verdict handle_na_input(struct net_buf *buf) left_len = buf->frags->len - (sizeof(struct net_ipv6_hdr) + sizeof(struct net_icmp_hdr)); - while (net_nbuf_ext_opt_len(buf) < left_len && + while (net_pkt_ext_opt_len(buf) < left_len && left_len < buf->frags->len) { if (!hdr->len) { @@ -1628,12 +1628,12 @@ static enum net_verdict handle_na_input(struct net_buf *buf) break; } - prev_opt_len = net_nbuf_ext_opt_len(buf); + prev_opt_len = net_pkt_ext_opt_len(buf); - net_nbuf_set_ext_opt_len(buf, net_nbuf_ext_opt_len(buf) + + net_pkt_set_ext_opt_len(buf, net_pkt_ext_opt_len(buf) + (hdr->len << 3)); - if (prev_opt_len == net_nbuf_ext_opt_len(buf)) { + if (prev_opt_len == net_pkt_ext_opt_len(buf)) { NET_ERR("Corrupted NA message"); goto drop; } @@ -1641,16 +1641,16 @@ static enum net_verdict handle_na_input(struct net_buf *buf) hdr = NET_ICMPV6_ND_OPT_HDR_BUF(buf); } - ifaddr = net_if_ipv6_addr_lookup_by_iface(net_nbuf_iface(buf), + ifaddr = net_if_ipv6_addr_lookup_by_iface(net_pkt_iface(buf), &NET_ICMPV6_NA_BUF(buf)->tgt); if (ifaddr) { NET_DBG("Interface %p already has address %s", - net_nbuf_iface(buf), + net_pkt_iface(buf), net_sprint_ipv6_addr(&NET_ICMPV6_NA_BUF(buf)->tgt)); #if defined(CONFIG_NET_IPV6_DAD) if (ifaddr->addr_state == NET_ADDR_TENTATIVE) { - dad_failed(net_nbuf_iface(buf), + dad_failed(net_pkt_iface(buf), &NET_ICMPV6_NA_BUF(buf)->tgt); } #endif /* CONFIG_NET_IPV6_DAD */ @@ -1662,7 +1662,7 @@ static enum net_verdict handle_na_input(struct net_buf *buf) goto drop; } - net_nbuf_unref(buf); + net_pkt_unref(buf); net_stats_update_ipv6_nd_sent(); @@ -1685,24 +1685,24 @@ int net_ipv6_send_ns(struct net_if *iface, struct net_nbr *nbr; uint8_t llao_len; - buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, dst), + buf = net_pkt_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); + frag = net_pkt_get_frag(buf, K_FOREVER); NET_ASSERT_INFO(frag, "Out of DATA buffers"); net_buf_frag_add(buf, frag); - net_nbuf_set_iface(buf, iface); - net_nbuf_set_family(buf, AF_INET6); - net_nbuf_set_ip_hdr_len(buf, sizeof(struct net_ipv6_hdr)); + net_pkt_set_iface(buf, iface); + net_pkt_set_family(buf, AF_INET6); + net_pkt_set_ip_hdr_len(buf, sizeof(struct net_ipv6_hdr)); - net_nbuf_ll_clear(buf); + net_pkt_ll_clear(buf); - llao_len = get_llao_len(net_nbuf_iface(buf)); + llao_len = get_llao_len(net_pkt_iface(buf)); setup_headers(buf, sizeof(struct net_icmpv6_ns_hdr) + llao_len, NET_ICMPV6_NS); @@ -1735,7 +1735,7 @@ int net_ipv6_send_ns(struct net_if *iface, } else { net_ipaddr_copy(&NET_IPV6_BUF(buf)->src, net_if_ipv6_select_src_addr( - net_nbuf_iface(buf), + net_pkt_iface(buf), &NET_IPV6_BUF(buf)->dst)); } @@ -1744,8 +1744,8 @@ int net_ipv6_send_ns(struct net_if *iface, goto drop; } - set_llao(&net_nbuf_iface(buf)->link_addr, - net_nbuf_icmp_data(buf) + + set_llao(&net_pkt_iface(buf)->link_addr, + net_pkt_icmp_data(buf) + sizeof(struct net_icmp_hdr) + sizeof(struct net_icmpv6_ns_hdr), llao_len, NET_ICMPV6_ND_OPT_SLLAO); @@ -1759,12 +1759,12 @@ int net_ipv6_send_ns(struct net_if *iface, NET_ICMP_BUF(buf)->chksum = 0; NET_ICMP_BUF(buf)->chksum = ~net_calc_chksum_icmpv6(buf); - nbr = nbr_lookup(&net_neighbor.table, net_nbuf_iface(buf), + nbr = nbr_lookup(&net_neighbor.table, net_pkt_iface(buf), &NET_ICMPV6_NS_BUF(buf)->tgt); if (!nbr) { nbr_print(); - nbr = nbr_new(net_nbuf_iface(buf), + nbr = nbr_new(net_pkt_iface(buf), &NET_ICMPV6_NS_BUF(buf)->tgt, false, NET_IPV6_NBR_STATE_INCOMPLETE); if (!nbr) { @@ -1777,12 +1777,12 @@ int net_ipv6_send_ns(struct net_if *iface, if (pending) { if (!net_ipv6_nbr_data(nbr)->pending) { - net_ipv6_nbr_data(nbr)->pending = net_nbuf_ref(pending); + net_ipv6_nbr_data(nbr)->pending = net_pkt_ref(pending); } else { NET_DBG("Buffer %p already pending for " "operation. Discarding pending %p and buf %p", net_ipv6_nbr_data(nbr)->pending, pending, buf); - net_nbuf_unref(pending); + net_pkt_unref(pending); goto drop; } @@ -1812,7 +1812,7 @@ int net_ipv6_send_ns(struct net_if *iface, return 0; drop: - net_nbuf_unref(buf); + net_pkt_unref(buf); net_stats_update_ipv6_nd_drop(); return -EINVAL; @@ -1826,18 +1826,18 @@ int net_ipv6_send_rs(struct net_if *iface) bool unspec_src; uint8_t llao_len = 0; - buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, NULL), + buf = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface, NULL), K_FOREVER); - frag = net_nbuf_get_frag(buf, K_FOREVER); + frag = net_pkt_get_frag(buf, K_FOREVER); net_buf_frag_add(buf, frag); - net_nbuf_set_iface(buf, iface); - net_nbuf_set_family(buf, AF_INET6); - net_nbuf_set_ip_hdr_len(buf, sizeof(struct net_ipv6_hdr)); + net_pkt_set_iface(buf, iface); + net_pkt_set_family(buf, AF_INET6); + net_pkt_set_ip_hdr_len(buf, sizeof(struct net_ipv6_hdr)); - net_nbuf_ll_clear(buf); + net_pkt_ll_clear(buf); net_ipv6_addr_create_ll_allnodes_mcast(&NET_IPV6_BUF(buf)->dst); @@ -1847,15 +1847,15 @@ int net_ipv6_send_rs(struct net_if *iface) unspec_src = net_is_ipv6_addr_unspecified(&NET_IPV6_BUF(buf)->src); if (!unspec_src) { - llao_len = get_llao_len(net_nbuf_iface(buf)); + llao_len = get_llao_len(net_pkt_iface(buf)); } setup_headers(buf, sizeof(struct net_icmpv6_rs_hdr) + llao_len, NET_ICMPV6_RS); if (!unspec_src) { - set_llao(&net_nbuf_iface(buf)->link_addr, - net_nbuf_icmp_data(buf) + + set_llao(&net_pkt_iface(buf)->link_addr, + net_pkt_icmp_data(buf) + sizeof(struct net_icmp_hdr) + sizeof(struct net_icmpv6_rs_hdr), llao_len, NET_ICMPV6_ND_OPT_SLLAO); @@ -1886,7 +1886,7 @@ int net_ipv6_send_rs(struct net_if *iface) return 0; drop: - net_nbuf_unref(buf); + net_pkt_unref(buf); net_stats_update_ipv6_nd_drop(); return -EINVAL; @@ -1915,18 +1915,18 @@ static inline struct net_buf *handle_ra_neighbor(struct net_buf *buf, llstorage.len = NET_LINK_ADDR_MAX_LENGTH; lladdr.len = NET_LINK_ADDR_MAX_LENGTH; lladdr.addr = llstorage.addr; - if (net_nbuf_ll_src(buf)->len < lladdr.len) { - lladdr.len = net_nbuf_ll_src(buf)->len; + if (net_pkt_ll_src(buf)->len < lladdr.len) { + lladdr.len = net_pkt_ll_src(buf)->len; } - frag = net_nbuf_read(frag, offset, pos, lladdr.len, lladdr.addr); + frag = net_pkt_read(frag, offset, pos, lladdr.len, lladdr.addr); if (!frag && offset) { return NULL; } padding = len * 8 - 2 - lladdr.len; if (padding) { - frag = net_nbuf_read(frag, *pos, pos, padding, NULL); + frag = net_pkt_read(frag, *pos, pos, padding, NULL); if (!frag && *pos) { return NULL; } @@ -1942,7 +1942,7 @@ static inline void handle_prefix_onlink(struct net_buf *buf, { struct net_if_ipv6_prefix *prefix; - prefix = net_if_ipv6_prefix_lookup(net_nbuf_iface(buf), + prefix = net_if_ipv6_prefix_lookup(net_pkt_iface(buf), &prefix_info->prefix, prefix_info->prefix_len); if (!prefix) { @@ -1950,13 +1950,13 @@ static inline void handle_prefix_onlink(struct net_buf *buf, return; } - prefix = net_if_ipv6_prefix_add(net_nbuf_iface(buf), + prefix = net_if_ipv6_prefix_add(net_pkt_iface(buf), &prefix_info->prefix, prefix_info->prefix_len, prefix_info->valid_lifetime); if (prefix) { NET_DBG("Interface %p add prefix %s/%d lifetime %u", - net_nbuf_iface(buf), + net_pkt_iface(buf), net_sprint_ipv6_addr(&prefix_info->prefix), prefix_info->prefix_len, prefix_info->valid_lifetime); @@ -1964,7 +1964,7 @@ static inline void handle_prefix_onlink(struct net_buf *buf, NET_ERR("Prefix %s/%d could not be added to iface %p", net_sprint_ipv6_addr(&prefix_info->prefix), prefix_info->prefix_len, - net_nbuf_iface(buf)); + net_pkt_iface(buf)); return; } @@ -1973,18 +1973,18 @@ static inline void handle_prefix_onlink(struct net_buf *buf, switch (prefix_info->valid_lifetime) { case 0: NET_DBG("Interface %p delete prefix %s/%d", - net_nbuf_iface(buf), + net_pkt_iface(buf), net_sprint_ipv6_addr(&prefix_info->prefix), prefix_info->prefix_len); - net_if_ipv6_prefix_rm(net_nbuf_iface(buf), + net_if_ipv6_prefix_rm(net_pkt_iface(buf), &prefix->prefix, prefix->len); break; case NET_IPV6_ND_INFINITE_LIFETIME: NET_DBG("Interface %p prefix %s/%d infinite", - net_nbuf_iface(buf), + net_pkt_iface(buf), net_sprint_ipv6_addr(&prefix->prefix), prefix->len); @@ -1993,7 +1993,7 @@ static inline void handle_prefix_onlink(struct net_buf *buf, default: NET_DBG("Interface %p update prefix %s/%u lifetime %u", - net_nbuf_iface(buf), + net_pkt_iface(buf), net_sprint_ipv6_addr(&prefix_info->prefix), prefix_info->prefix_len, prefix_info->valid_lifetime); @@ -2023,7 +2023,7 @@ static inline void handle_prefix_autonomous(struct net_buf *buf, * bytes of that address. */ net_ipv6_addr_create_iid(&addr, - net_if_get_link_addr(net_nbuf_iface(buf))); + net_if_get_link_addr(net_pkt_iface(buf))); memcpy(&addr, &prefix_info->prefix, sizeof(struct in6_addr) / 2); ifaddr = net_if_ipv6_addr_lookup(&addr, NULL); @@ -2057,10 +2057,10 @@ static inline void handle_prefix_autonomous(struct net_buf *buf, } else { if (prefix_info->valid_lifetime == NET_IPV6_ND_INFINITE_LIFETIME) { - net_if_ipv6_addr_add(net_nbuf_iface(buf), + net_if_ipv6_addr_add(net_pkt_iface(buf), &addr, NET_ADDR_AUTOCONF, 0); } else { - net_if_ipv6_addr_add(net_nbuf_iface(buf), + net_if_ipv6_addr_add(net_pkt_iface(buf), &addr, NET_ADDR_AUTOCONF, prefix_info->valid_lifetime); } @@ -2077,14 +2077,14 @@ static inline struct net_buf *handle_ra_prefix(struct net_buf *buf, prefix_info.type = NET_ICMPV6_ND_OPT_PREFIX_INFO; prefix_info.len = len * 8 - 2; - frag = net_nbuf_read(frag, offset, pos, 1, &prefix_info.prefix_len); - frag = net_nbuf_read(frag, *pos, pos, 1, &prefix_info.flags); - frag = net_nbuf_read_be32(frag, *pos, pos, &prefix_info.valid_lifetime); - frag = net_nbuf_read_be32(frag, *pos, pos, + frag = net_pkt_read(frag, offset, pos, 1, &prefix_info.prefix_len); + frag = net_pkt_read(frag, *pos, pos, 1, &prefix_info.flags); + frag = net_pkt_read_be32(frag, *pos, pos, &prefix_info.valid_lifetime); + frag = net_pkt_read_be32(frag, *pos, pos, &prefix_info.preferred_lifetime); /* Skip reserved bytes */ - frag = net_nbuf_skip(frag, *pos, pos, 4); - frag = net_nbuf_read(frag, *pos, pos, sizeof(struct in6_addr), + frag = net_pkt_skip(frag, *pos, pos, 4); + frag = net_pkt_read(frag, *pos, pos, sizeof(struct in6_addr), prefix_info.prefix.s6_addr); if (!frag && *pos) { return NULL; @@ -2119,7 +2119,7 @@ static inline struct net_buf *handle_ra_6co(struct net_buf *buf, context.type = NET_ICMPV6_ND_OPT_6CO; context.len = len * 8 - 2; - frag = net_nbuf_read_u8(frag, offset, pos, &context.context_len); + frag = net_pkt_read_u8(frag, offset, pos, &context.context_len); /* RFC 6775, 4.2 * Context Length: 8-bit unsigned integer. The number of leading @@ -2135,23 +2135,23 @@ static inline struct net_buf *handle_ra_6co(struct net_buf *buf, } context.context_len = context.context_len / 8; - frag = net_nbuf_read_u8(frag, *pos, pos, &context.flag); + frag = net_pkt_read_u8(frag, *pos, pos, &context.flag); /* Skip reserved bytes */ - frag = net_nbuf_skip(frag, *pos, pos, 2); - frag = net_nbuf_read_be16(frag, *pos, pos, &context.lifetime); + frag = net_pkt_skip(frag, *pos, pos, 2); + frag = net_pkt_read_be16(frag, *pos, pos, &context.lifetime); /* RFC 6775, 4.2 (Length field). Length can be 2 or 3 depending * on the length of context prefix field. */ if (len == 3) { - frag = net_nbuf_read(frag, *pos, pos, sizeof(struct in6_addr), + frag = net_pkt_read(frag, *pos, pos, sizeof(struct in6_addr), context.prefix.s6_addr); } else if (len == 2) { /* If length is 2 means only 64 bits of context prefix * is available, rest set to zeros. */ - frag = net_nbuf_read(frag, *pos, pos, 8, + frag = net_pkt_read(frag, *pos, pos, 8, context.prefix.s6_addr); } @@ -2167,7 +2167,7 @@ static inline struct net_buf *handle_ra_6co(struct net_buf *buf, sizeof(struct in6_addr) - context.context_len); } - net_6lo_set_context(net_nbuf_iface(buf), &context); + net_6lo_set_context(net_pkt_iface(buf), &context); return frag; } @@ -2205,45 +2205,45 @@ static enum net_verdict handle_ra_input(struct net_buf *buf) } frag = buf->frags; - offset = sizeof(struct net_ipv6_hdr) + net_nbuf_ext_len(buf) + + offset = sizeof(struct net_ipv6_hdr) + net_pkt_ext_len(buf) + sizeof(struct net_icmp_hdr); - frag = net_nbuf_read_u8(frag, offset, &offset, &hop_limit); - frag = net_nbuf_skip(frag, offset, &offset, 1); /* flags */ + frag = net_pkt_read_u8(frag, offset, &offset, &hop_limit); + frag = net_pkt_skip(frag, offset, &offset, 1); /* flags */ if (!frag) { goto drop; } if (hop_limit) { - net_ipv6_set_hop_limit(net_nbuf_iface(buf), hop_limit); + net_ipv6_set_hop_limit(net_pkt_iface(buf), hop_limit); NET_DBG("New hop limit %d", - net_if_ipv6_get_hop_limit(net_nbuf_iface(buf))); + net_if_ipv6_get_hop_limit(net_pkt_iface(buf))); } - frag = net_nbuf_read_be16(frag, offset, &offset, &router_lifetime); - frag = net_nbuf_read_be32(frag, offset, &offset, &reachable_time); - frag = net_nbuf_read_be32(frag, offset, &offset, &retrans_timer); + frag = net_pkt_read_be16(frag, offset, &offset, &router_lifetime); + frag = net_pkt_read_be32(frag, offset, &offset, &reachable_time); + frag = net_pkt_read_be32(frag, offset, &offset, &retrans_timer); if (!frag) { goto drop; } if (reachable_time && - (net_if_ipv6_get_reachable_time(net_nbuf_iface(buf)) != + (net_if_ipv6_get_reachable_time(net_pkt_iface(buf)) != NET_ICMPV6_RA_BUF(buf)->reachable_time)) { - net_if_ipv6_set_base_reachable_time(net_nbuf_iface(buf), + net_if_ipv6_set_base_reachable_time(net_pkt_iface(buf), reachable_time); - net_if_ipv6_set_reachable_time(net_nbuf_iface(buf)); + net_if_ipv6_set_reachable_time(net_pkt_iface(buf)); } if (retrans_timer) { - net_if_ipv6_set_retrans_timer(net_nbuf_iface(buf), + net_if_ipv6_set_retrans_timer(net_pkt_iface(buf), retrans_timer); } while (frag) { - frag = net_nbuf_read(frag, offset, &offset, 1, &type); - frag = net_nbuf_read(frag, offset, &offset, 1, &length); + frag = net_pkt_read(frag, offset, &offset, 1, &type); + frag = net_pkt_read(frag, offset, &offset, 1, &length); if (!frag) { goto drop; } @@ -2259,13 +2259,13 @@ static enum net_verdict handle_ra_input(struct net_buf *buf) break; case NET_ICMPV6_ND_OPT_MTU: /* MTU has reserved 2 bytes, so skip it. */ - frag = net_nbuf_skip(frag, offset, &offset, 2); - frag = net_nbuf_read_be32(frag, offset, &offset, &mtu); + frag = net_pkt_skip(frag, offset, &offset, 2); + frag = net_pkt_read_be32(frag, offset, &offset, &mtu); if (!frag && offset) { goto drop; } - net_if_set_mtu(net_nbuf_iface(buf), mtu); + net_if_set_mtu(net_pkt_iface(buf), mtu); if (mtu > 0xffff) { /* TODO: discard packet? */ @@ -2314,7 +2314,7 @@ static enum net_verdict handle_ra_input(struct net_buf *buf) default: NET_DBG("Unknown ND option 0x%x", type); skip: - frag = net_nbuf_skip(frag, offset, &offset, + frag = net_pkt_skip(frag, offset, &offset, length * 8 - 2); if (!frag && offset) { goto drop; @@ -2324,7 +2324,7 @@ static enum net_verdict handle_ra_input(struct net_buf *buf) } } - router = net_if_ipv6_router_lookup(net_nbuf_iface(buf), + router = net_if_ipv6_router_lookup(net_pkt_iface(buf), &NET_IPV6_BUF(buf)->src); if (router) { if (!router_lifetime) { @@ -2341,7 +2341,7 @@ static enum net_verdict handle_ra_input(struct net_buf *buf) router_lifetime); } } else { - net_if_ipv6_router_add(net_nbuf_iface(buf), + net_if_ipv6_router_add(net_pkt_iface(buf), &NET_IPV6_BUF(buf)->src, router_lifetime); } @@ -2353,16 +2353,16 @@ static enum net_verdict handle_ra_input(struct net_buf *buf) net_ipv6_nbr_data(nbr)->pending)->dst)); if (net_send_data(net_ipv6_nbr_data(nbr)->pending) < 0) { - net_nbuf_unref(net_ipv6_nbr_data(nbr)->pending); + net_pkt_unref(net_ipv6_nbr_data(nbr)->pending); } nbr_clear_ns_pending(net_ipv6_nbr_data(nbr)); } /* Cancel the RS timer on iface */ - k_delayed_work_cancel(&net_nbuf_iface(buf)->ipv6.rs_timer); + k_delayed_work_cancel(&net_pkt_iface(buf)->ipv6.rs_timer); - net_nbuf_unref(buf); + net_pkt_unref(buf); return NET_OK; @@ -2381,15 +2381,15 @@ static struct net_buf *create_mldv2(struct net_buf *buf, uint16_t record_type, uint8_t num_sources) { - net_nbuf_append_u8(buf, record_type); - net_nbuf_append_u8(buf, 0); /* aux data len */ - net_nbuf_append_be16(buf, num_sources); /* number of addresses */ - net_nbuf_append(buf, sizeof(struct in6_addr), addr->s6_addr, + net_pkt_append_u8(buf, record_type); + net_pkt_append_u8(buf, 0); /* aux data len */ + net_pkt_append_be16(buf, num_sources); /* number of addresses */ + net_pkt_append(buf, sizeof(struct in6_addr), addr->s6_addr, K_FOREVER); if (num_sources > 0) { /* All source addresses, RFC 3810 ch 3 */ - net_nbuf_append(buf, sizeof(struct in6_addr), + net_pkt_append(buf, sizeof(struct in6_addr), net_ipv6_unspecified_address()->s6_addr, K_FOREVER); } @@ -2407,7 +2407,7 @@ static int send_mldv2_raw(struct net_if *iface, struct net_buf *frags) /* Sent to all MLDv2-capable routers */ net_ipv6_addr_create(&dst, 0xff02, 0, 0, 0, 0, 0, 0, 0x0016); - buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, &dst), + buf = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface, &dst), K_FOREVER); buf = net_ipv6_create_raw(buf, @@ -2418,30 +2418,30 @@ static int send_mldv2_raw(struct net_if *iface, struct net_buf *frags) NET_IPV6_BUF(buf)->hop_limit = 1; /* RFC 3810 ch 7.4 */ - net_nbuf_set_ipv6_hdr_prev(buf, buf->len); + net_pkt_set_ipv6_hdr_prev(buf, buf->len); /* Add hop-by-hop option and router alert option, RFC 3810 ch 5. */ - net_nbuf_append_u8(buf, IPPROTO_ICMPV6); - net_nbuf_append_u8(buf, 0); /* length (0 means 8 bytes) */ + net_pkt_append_u8(buf, IPPROTO_ICMPV6); + net_pkt_append_u8(buf, 0); /* length (0 means 8 bytes) */ #define ROUTER_ALERT_LEN 8 /* IPv6 router alert option is described in RFC 2711. */ - net_nbuf_append_be16(buf, 0x0502); /* RFC 2711 ch 2.1 */ - net_nbuf_append_be16(buf, 0); /* pkt contains MLD msg */ + net_pkt_append_be16(buf, 0x0502); /* RFC 2711 ch 2.1 */ + net_pkt_append_be16(buf, 0); /* pkt contains MLD msg */ - net_nbuf_append_u8(buf, 0); /* padding */ - net_nbuf_append_u8(buf, 0); /* padding */ + net_pkt_append_u8(buf, 0); /* padding */ + net_pkt_append_u8(buf, 0); /* padding */ /* ICMPv6 header */ - net_nbuf_append_u8(buf, NET_ICMPV6_MLDv2); /* type */ - net_nbuf_append_u8(buf, 0); /* code */ - net_nbuf_append_be16(buf, 0); /* chksum */ + net_pkt_append_u8(buf, NET_ICMPV6_MLDv2); /* type */ + net_pkt_append_u8(buf, 0); /* code */ + net_pkt_append_be16(buf, 0); /* chksum */ - net_nbuf_set_len(buf->frags, NET_IPV6ICMPH_LEN + ROUTER_ALERT_LEN); - net_nbuf_set_iface(buf, iface); + net_pkt_set_len(buf->frags, NET_IPV6ICMPH_LEN + ROUTER_ALERT_LEN); + net_pkt_set_iface(buf, iface); - net_nbuf_append_be16(buf, 0); /* reserved field */ + net_pkt_append_be16(buf, 0); /* reserved field */ /* Insert the actual multicast record(s) here */ net_buf_frag_add(buf, frags); @@ -2451,9 +2451,9 @@ static int send_mldv2_raw(struct net_if *iface, struct net_buf *frags) goto drop; } - net_nbuf_set_ext_len(buf, ROUTER_ALERT_LEN); + net_pkt_set_ext_len(buf, ROUTER_ALERT_LEN); - net_nbuf_write_be16(buf, buf->frags, + net_pkt_write_be16(buf, buf->frags, NET_IPV6H_LEN + ROUTER_ALERT_LEN + 2, &pos, ntohs(~net_calc_chksum_icmpv6(buf))); @@ -2468,7 +2468,7 @@ static int send_mldv2_raw(struct net_if *iface, struct net_buf *frags) return 0; drop: - net_nbuf_unref(buf); + net_pkt_unref(buf); net_stats_update_icmp_drop(); net_stats_update_ipv6_mld_drop(); @@ -2481,10 +2481,10 @@ static int send_mldv2(struct net_if *iface, const struct in6_addr *addr, struct net_buf *buf; int ret; - buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, NULL), + buf = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface, NULL), K_FOREVER); - net_nbuf_append_be16(buf, 1); /* number of records */ + net_pkt_append_be16(buf, 1); /* number of records */ buf = create_mldv2(buf, addr, mode, 1); @@ -2492,7 +2492,7 @@ static int send_mldv2(struct net_if *iface, const struct in6_addr *addr, buf->frags = NULL; - net_nbuf_unref(buf); + net_pkt_unref(buf); return ret; } @@ -2549,10 +2549,10 @@ static void send_mld_report(struct net_if *iface) struct net_buf *buf; int i, count = 0; - buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, NULL), + buf = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface, NULL), K_FOREVER); - net_nbuf_append_u8(buf, 0); /* This will be the record count */ + net_pkt_append_u8(buf, 0); /* This will be the record count */ for (i = 0; i < NET_IF_MAX_IPV6_MADDR; i++) { if (!iface->ipv6.mcast[i].is_used || @@ -2569,14 +2569,14 @@ static void send_mld_report(struct net_if *iface) uint16_t pos; /* Write back the record count */ - net_nbuf_write_u8(buf, buf->frags, 0, &pos, count); + net_pkt_write_u8(buf, buf->frags, 0, &pos, count); send_mldv2_raw(iface, buf->frags); buf->frags = NULL; } - net_nbuf_unref(buf); + net_pkt_unref(buf); } static enum net_verdict handle_mld_query(struct net_buf *buf) @@ -2594,19 +2594,19 @@ static enum net_verdict handle_mld_query(struct net_buf *buf) net_stats_update_ipv6_mld_recv(); /* offset tells now where the ICMPv6 header is starting */ - offset = net_nbuf_icmp_data(buf) - net_nbuf_ip_data(buf); + offset = net_pkt_icmp_data(buf) - net_pkt_ip_data(buf); offset += sizeof(struct net_icmp_hdr); - frag = net_nbuf_read_be16(buf->frags, offset, &pos, &max_rsp_code); - frag = net_nbuf_skip(frag, pos, &pos, 2); /* two reserved bytes */ - frag = net_nbuf_read(frag, pos, &pos, sizeof(mcast), mcast.s6_addr); - frag = net_nbuf_skip(frag, pos, &pos, 2); /* skip S, QRV & QQIC */ - frag = net_nbuf_read_be16(buf->frags, pos, &pos, &num_src); + frag = net_pkt_read_be16(buf->frags, offset, &pos, &max_rsp_code); + frag = net_pkt_skip(frag, pos, &pos, 2); /* two reserved bytes */ + frag = net_pkt_read(frag, pos, &pos, sizeof(mcast), mcast.s6_addr); + frag = net_pkt_skip(frag, pos, &pos, 2); /* skip S, QRV & QQIC */ + frag = net_pkt_read_be16(buf->frags, pos, &pos, &num_src); if (!frag && pos == 0xffff) { goto drop; } - pkt_len = sizeof(struct net_ipv6_hdr) + net_nbuf_ext_len(buf) + + pkt_len = sizeof(struct net_ipv6_hdr) + net_pkt_ext_len(buf) + sizeof(struct net_icmp_hdr) + (2 + 2 + 16 + 2 + 2) + sizeof(struct in6_addr) * num_src; @@ -2626,7 +2626,7 @@ static enum net_verdict handle_mld_query(struct net_buf *buf) goto drop; } - send_mld_report(net_nbuf_iface(buf)); + send_mld_report(net_pkt_iface(buf)); drop: net_stats_update_ipv6_mld_drop(); @@ -2757,7 +2757,7 @@ static bool reassembly_cancel(uint32_t id, reassembly[i].buf[j], net_buf_frags_len(reassembly[i].buf[j])); - net_nbuf_unref(reassembly[i].buf[j]); + net_pkt_unref(reassembly[i].buf[j]); reassembly[i].buf[j] = NULL; } @@ -2817,7 +2817,7 @@ static void reassemble_packet(struct net_ipv6_reassembly *reass) /* Get rid of IPv6 and fragment header which are at * the beginning of the fragment. */ - removed_len = net_nbuf_ipv6_fragment_start(buf) + + removed_len = net_pkt_ipv6_fragment_start(buf) + sizeof(struct net_ipv6_frag_hdr) - buf->frags->data; @@ -2836,7 +2836,7 @@ static void reassemble_packet(struct net_ipv6_reassembly *reass) buf->frags = NULL; reass->buf[i] = NULL; - net_nbuf_unref(buf); + net_pkt_unref(buf); } buf = reass->buf[0]; @@ -2845,36 +2845,36 @@ static void reassemble_packet(struct net_ipv6_reassembly *reass) * and set the various pointers and values in buffer metadata. */ - next_hdr = net_nbuf_ipv6_fragment_start(buf)[0]; + next_hdr = net_pkt_ipv6_fragment_start(buf)[0]; /* How much data we need to move in order to get rid of the * fragmentation header. */ len = buf->frags->len - sizeof(struct net_ipv6_frag_hdr) - - (net_nbuf_ipv6_fragment_start(buf) - buf->frags->data); + (net_pkt_ipv6_fragment_start(buf) - buf->frags->data); - memmove(net_nbuf_ipv6_fragment_start(buf), - net_nbuf_ipv6_fragment_start(buf) + + memmove(net_pkt_ipv6_fragment_start(buf), + net_pkt_ipv6_fragment_start(buf) + sizeof(struct net_ipv6_frag_hdr), len); /* This one updates the previous header's nexthdr value */ - net_nbuf_write_u8(buf, buf->frags, net_nbuf_ipv6_hdr_prev(buf), + net_pkt_write_u8(buf, buf->frags, net_pkt_ipv6_hdr_prev(buf), &pos, next_hdr); buf->frags->len -= sizeof(struct net_ipv6_frag_hdr); - if (!net_nbuf_compact(buf)) { + if (!net_pkt_compact(buf)) { NET_ERR("Cannot compact reassembly buffer %p", buf); reassembly_cancel(reass->id, &reass->src, &reass->dst); return; } /* Fix the total length of the IPv6 packet. */ - len = net_nbuf_ext_len(buf); + len = net_pkt_ext_len(buf); if (len > 0) { NET_DBG("Old buf %p IPv6 ext len is %d bytes", buf, len); - net_nbuf_set_ext_len(buf, - len - sizeof(struct net_ipv6_frag_hdr)); + net_pkt_set_ext_len(buf, + len - sizeof(struct net_ipv6_frag_hdr)); } len = net_buf_frags_len(buf) - sizeof(struct net_ipv6_hdr); @@ -2890,7 +2890,7 @@ static void reassemble_packet(struct net_ipv6_reassembly *reass) * MUST NOT pass it to L2 so there will be a special check for that * in process_data() when handling the packet. */ - net_recv_data(net_nbuf_iface(buf), buf); + net_recv_data(net_pkt_iface(buf), buf); /* Make room for new packet that can be reassembled */ k_delayed_work_cancel(&reass->timer); @@ -2924,7 +2924,7 @@ static bool fragment_verify(struct net_ipv6_reassembly *reass) int i, prev_len; prev_len = net_buf_frags_len(reass->buf[0]); - offset = net_nbuf_ipv6_fragment_offset(reass->buf[0]); + offset = net_pkt_ipv6_fragment_offset(reass->buf[0]); NET_DBG("buf %p offset %u", reass->buf[0], offset); @@ -2933,7 +2933,7 @@ static bool fragment_verify(struct net_ipv6_reassembly *reass) } for (i = 1; i < NET_IPV6_FRAGMENTS_MAX_BUF; i++) { - offset = net_nbuf_ipv6_fragment_offset(reass->buf[i]); + offset = net_pkt_ipv6_fragment_offset(reass->buf[i]); NET_DBG("buf %p offset %u prev_len %d", reass->buf[i], offset, prev_len); @@ -2964,13 +2964,13 @@ static enum net_verdict handle_fragment_hdr(struct net_buf *buf, bool found; int i; - net_nbuf_set_ipv6_fragment_start(buf, frag->data + buf_offset); + net_pkt_set_ipv6_fragment_start(buf, frag->data + buf_offset); /* Each fragment has a fragment header. */ - frag = net_nbuf_read_u8(frag, buf_offset, &loc, &nexthdr); - frag = net_nbuf_skip(frag, loc, &loc, 1); /* reserved */ - frag = net_nbuf_read_be16(frag, loc, &loc, &flag); - frag = net_nbuf_read_be32(frag, loc, &loc, &id); + frag = net_pkt_read_u8(frag, buf_offset, &loc, &nexthdr); + frag = net_pkt_skip(frag, loc, &loc, 1); /* reserved */ + frag = net_pkt_read_be16(frag, loc, &loc, &flag); + frag = net_pkt_read_be32(frag, loc, &loc, &id); if (!frag && loc == 0xffff) { goto drop; } @@ -2985,7 +2985,7 @@ static enum net_verdict handle_fragment_hdr(struct net_buf *buf, offset = flag & 0xfff8; more = flag & 0x01; - net_nbuf_set_ipv6_fragment_offset(buf, offset); + net_pkt_set_ipv6_fragment_offset(buf, offset); if (!reass->buf[0]) { NET_DBG("Storing buf %p to slot %d", buf, 0); @@ -3011,7 +3011,7 @@ static enum net_verdict handle_fragment_hdr(struct net_buf *buf, break; } - if (net_nbuf_ipv6_fragment_offset(reass->buf[i]) < + if (net_pkt_ipv6_fragment_offset(reass->buf[i]) < offset) { continue; } @@ -3099,10 +3099,10 @@ static int send_ipv6_fragment(struct net_if *iface, /* Prepare the head buf so that the IPv6 packet will be sent properly * to the device driver. */ - if (net_nbuf_context(buf)) { - ipv6 = net_nbuf_get_tx(net_nbuf_context(buf), FRAG_BUF_WAIT); + if (net_pkt_context(buf)) { + ipv6 = net_pkt_get_tx(net_pkt_context(buf), FRAG_BUF_WAIT); } else { - ipv6 = net_nbuf_get_reserve_tx( + ipv6 = net_pkt_get_reserve_tx( net_if_get_ll_reserve(iface, &NET_IPV6_BUF(buf)->dst), FRAG_BUF_WAIT); } @@ -3120,8 +3120,8 @@ static int send_ipv6_fragment(struct net_if *iface, ipv6_len), "len %u, frag->len %d", len, frag->len); - ret = net_nbuf_split(buf, frag, len, &end, &rest, - FRAG_BUF_WAIT); + ret = net_pkt_split(buf, frag, len, &end, &rest, + FRAG_BUF_WAIT); if (ret < 0) { goto free_bufs; } @@ -3138,7 +3138,7 @@ static int send_ipv6_fragment(struct net_if *iface, if (rest) { rest->frags = frag->frags; frag->frags = NULL; - net_nbuf_unref(frag); + net_pkt_unref(frag); } if (prev) { @@ -3148,13 +3148,13 @@ static int send_ipv6_fragment(struct net_if *iface, } end->frags = NULL; - net_nbuf_copy_user_data(ipv6, buf); + net_pkt_copy_user_data(ipv6, buf); /* Update the extension length metadata so that upper layer checksum * will be calculated properly by net_ipv6_finalize_raw(). */ - ext_len = net_nbuf_ext_len(ipv6) + sizeof(struct net_ipv6_frag_hdr); - net_nbuf_set_ext_len(ipv6, ext_len); + ext_len = net_pkt_ext_len(ipv6) + sizeof(struct net_ipv6_frag_hdr); + net_pkt_set_ext_len(ipv6, ext_len); orig_copy = net_buf_clone(orig, FRAG_BUF_WAIT); if (!orig_copy) { @@ -3177,21 +3177,21 @@ static int send_ipv6_fragment(struct net_if *iface, } /* We need to update the next header of the packet. */ - net_nbuf_read_u8(ipv6->frags, prev_hdr, &pos, &hdr.nexthdr); + net_pkt_read_u8(ipv6->frags, prev_hdr, &pos, &hdr.nexthdr); hdr.reserved = 0; - hdr.id = net_nbuf_ipv6_fragment_id(buf); + hdr.id = net_pkt_ipv6_fragment_id(buf); hdr.offset = htons((offset & 0xfff8) | final); /* And we need to update the last header in the IPv6 packet to point to * fragment header. */ - net_nbuf_write_u8(ipv6, ipv6->frags, prev_hdr, &pos, - NET_IPV6_NEXTHDR_FRAG); + net_pkt_write_u8(ipv6, ipv6->frags, prev_hdr, &pos, + NET_IPV6_NEXTHDR_FRAG); /* Then just add the fragmentation header. */ - ret = net_nbuf_append(ipv6, sizeof(hdr), (uint8_t *)&hdr, - FRAG_BUF_WAIT); + ret = net_pkt_append(ipv6, sizeof(hdr), (uint8_t *)&hdr, + FRAG_BUF_WAIT); if (!ret) { ret = -ENOMEM; goto free_bufs; @@ -3227,14 +3227,14 @@ static int send_ipv6_fragment(struct net_if *iface, return 0; free_bufs: - net_nbuf_unref(ipv6); + net_pkt_unref(ipv6); if (rest) { - net_nbuf_unref(rest); + net_pkt_unref(rest); } if (orig_copy) { - net_nbuf_unref(orig_copy); + net_pkt_unref(orig_copy); } return ret; @@ -3257,9 +3257,9 @@ int net_ipv6_send_fragmented_pkt(struct net_if *iface, struct net_buf *buf, * header which is copied into each fragment together with * fragmentation header. */ - ret = net_nbuf_split(buf, frag, - net_nbuf_ip_hdr_len(buf) + net_nbuf_ext_len(buf), - &orig_ipv6, &rest, FRAG_BUF_WAIT); + ret = net_pkt_split(buf, frag, + net_pkt_ip_hdr_len(buf) + net_pkt_ext_len(buf), + &orig_ipv6, &rest, FRAG_BUF_WAIT); if (ret < 0) { return -ENOMEM; } @@ -3273,11 +3273,11 @@ int net_ipv6_send_fragmented_pkt(struct net_if *iface, struct net_buf *buf, buf->frags = rest; frag->frags = NULL; - net_nbuf_unref(frag); + net_pkt_unref(frag); frag = buf->frags; - net_nbuf_set_ipv6_fragment_id(buf, id); + net_pkt_set_ipv6_fragment_id(buf, id); /* Go through the fragment list, and create suitable IPv6 packet * from the data. @@ -3314,10 +3314,10 @@ int net_ipv6_send_fragmented_pkt(struct net_if *iface, struct net_buf *buf, status = send_ipv6_fragment(iface, buf, orig_ipv6, prev, prev, ipv6_len, offset, 0, true); - net_nbuf_unref(buf); + net_pkt_unref(buf); out: - net_nbuf_unref(orig_ipv6); + net_pkt_unref(orig_ipv6); return status; } @@ -3398,8 +3398,8 @@ static inline struct net_buf *handle_ext_hdr_options(struct net_buf *buf, length += 2; /* Each extension option has type and length */ - frag = net_nbuf_read_u8(frag, offset, &loc, &opt_type); - frag = net_nbuf_read_u8(frag, loc, &loc, &opt_len); + frag = net_pkt_read_u8(frag, offset, &loc, &opt_type); + frag = net_pkt_read_u8(frag, loc, &loc, &opt_len); if (!frag && loc == 0xffff) { goto drop; } @@ -3452,8 +3452,8 @@ static inline struct net_buf *handle_ext_hdr_options(struct net_buf *buf, break; } - frag = net_nbuf_read_u8(frag, loc, &loc, &opt_type); - frag = net_nbuf_read_u8(frag, loc, &loc, &opt_len); + frag = net_pkt_read_u8(frag, loc, &loc, &opt_type); + frag = net_pkt_read_u8(frag, loc, &loc, &opt_len); if (!frag && loc == 0xffff) { goto drop; } @@ -3522,12 +3522,12 @@ enum net_verdict net_ipv6_process_pkt(struct net_buf *buf) struct in6_addr *nexthop; /* Check if the packet can be routed */ - if (net_route_get_info(net_nbuf_iface(buf), &hdr->dst, &route, + if (net_route_get_info(net_pkt_iface(buf), &hdr->dst, &route, &nexthop)) { int ret; if (route) { - net_nbuf_set_iface(buf, route->iface); + net_pkt_set_iface(buf, route->iface); } ret = net_route_packet(buf, nexthop); @@ -3550,16 +3550,16 @@ enum net_verdict net_ipv6_process_pkt(struct net_buf *buf) } /* Check extension headers */ - net_nbuf_set_next_hdr(buf, &hdr->nexthdr); - net_nbuf_set_ext_len(buf, 0); - net_nbuf_set_ext_bitmap(buf, 0); - net_nbuf_set_ip_hdr_len(buf, sizeof(struct net_ipv6_hdr)); + net_pkt_set_next_hdr(buf, &hdr->nexthdr); + net_pkt_set_ext_len(buf, 0); + net_pkt_set_ext_bitmap(buf, 0); + net_pkt_set_ip_hdr_len(buf, sizeof(struct net_ipv6_hdr)); /* Fast path for main upper layer protocols. The handling of extension * headers can be slow so do this checking here. There cannot * be any extension headers after the upper layer protocol header. */ - next = *(net_nbuf_next_hdr(buf)); + next = *(net_pkt_next_hdr(buf)); if (is_upper_layer_protocol_header(next)) { goto upper_proto; } @@ -3576,15 +3576,15 @@ enum net_verdict net_ipv6_process_pkt(struct net_buf *buf) if (is_upper_layer_protocol_header(next)) { NET_DBG("IPv6 next header %d", next); - net_nbuf_set_ext_len(buf, offset - + net_pkt_set_ext_len(buf, offset - sizeof(struct net_ipv6_hdr)); goto upper_proto; } start_of_ext = offset; - frag = net_nbuf_read_u8(frag, offset, &offset, &next_hdr); - frag = net_nbuf_read_u8(frag, offset, &offset, &length); + frag = net_pkt_read_u8(frag, offset, &offset, &next_hdr); + frag = net_pkt_read_u8(frag, offset, &offset, &length); if (!frag && offset == 0xffff) { goto drop; } @@ -3617,12 +3617,12 @@ enum net_verdict net_ipv6_process_pkt(struct net_buf *buf) } /* Hop by hop option */ - if (net_nbuf_ext_bitmap(buf) & + if (net_pkt_ext_bitmap(buf) & NET_IPV6_EXT_HDR_BITMAP_HBHO) { goto bad_hdr; } - net_nbuf_add_ext_bitmap(buf, + net_pkt_add_ext_bitmap(buf, NET_IPV6_EXT_HDR_BITMAP_HBHO); frag = handle_ext_hdr_options(buf, frag, real_len, @@ -3632,7 +3632,7 @@ enum net_verdict net_ipv6_process_pkt(struct net_buf *buf) #if defined(CONFIG_NET_IPV6_FRAGMENT) case NET_IPV6_NEXTHDR_FRAG: - net_nbuf_set_ipv6_hdr_prev(buf, prev_hdr); + net_pkt_set_ipv6_hdr_prev(buf, prev_hdr); /* The fragment header does not have length field so * we need to step back two bytes and start from the @@ -3656,7 +3656,7 @@ enum net_verdict net_ipv6_process_pkt(struct net_buf *buf) upper_proto: if (total_len > 0) { NET_DBG("Extension len %d", total_len); - net_nbuf_set_ext_len(buf, total_len); + net_pkt_set_ext_len(buf, total_len); } switch (next) { diff --git a/subsys/net/ip/ipv6.h b/subsys/net/ip/ipv6.h index d25c9c042..2515c9623 100644 --- a/subsys/net/ip/ipv6.h +++ b/subsys/net/ip/ipv6.h @@ -16,7 +16,7 @@ #include <zephyr/types.h> #include <net/net_ip.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_if.h> #include <net/net_context.h> diff --git a/subsys/net/ip/l2/arp.c b/subsys/net/ip/l2/arp.c index d254c3fd8..18aa08de7 100644 --- a/subsys/net/ip/l2/arp.c +++ b/subsys/net/ip/l2/arp.c @@ -15,7 +15,7 @@ #include <errno.h> #include <net/net_core.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_if.h> #include <net/net_stats.h> #include <net/arp.h> @@ -107,19 +107,19 @@ 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(sizeof(struct net_eth_hdr), K_FOREVER); + buf = net_pkt_get_reserve_tx(sizeof(struct net_eth_hdr), K_FOREVER); if (!buf) { goto fail; } - frag = net_nbuf_get_frag(buf, K_FOREVER); + frag = net_pkt_get_frag(buf, K_FOREVER); if (!frag) { goto fail; } net_buf_frag_add(buf, frag); - net_nbuf_set_iface(buf, iface); - net_nbuf_set_family(buf, AF_INET); + net_pkt_set_iface(buf, iface); + net_pkt_set_family(buf, AF_INET); hdr = NET_ARP_BUF(buf); eth = NET_ETH_BUF(buf); @@ -130,8 +130,8 @@ static inline struct net_buf *prepare_arp(struct net_if *iface, * request and we want to send it again. */ if (entry) { - entry->pending = net_nbuf_ref(pending); - entry->iface = net_nbuf_iface(buf); + entry->pending = net_pkt_ref(pending); + entry->iface = net_pkt_iface(buf); net_ipaddr_copy(&entry->ip, next_addr); @@ -177,8 +177,8 @@ static inline struct net_buf *prepare_arp(struct net_if *iface, return buf; fail: - net_nbuf_unref(buf); - net_nbuf_unref(pending); + net_pkt_unref(buf); + net_pkt_unref(pending); return NULL; } @@ -194,27 +194,27 @@ struct net_buf *net_arp_prepare(struct net_buf *buf) return NULL; } - if (net_nbuf_ll_reserve(buf) != sizeof(struct net_eth_hdr)) { + if (net_pkt_ll_reserve(buf) != sizeof(struct net_eth_hdr)) { /* Add the ethernet header if it is missing. */ struct net_buf *header; struct net_linkaddr *ll; - net_nbuf_set_ll_reserve(buf, sizeof(struct net_eth_hdr)); + net_pkt_set_ll_reserve(buf, sizeof(struct net_eth_hdr)); - header = net_nbuf_get_frag(buf, K_FOREVER); + header = net_pkt_get_frag(buf, K_FOREVER); hdr = (struct net_eth_hdr *)(header->data - - net_nbuf_ll_reserve(buf)); + net_pkt_ll_reserve(buf)); hdr->type = htons(NET_ETH_PTYPE_IP); - ll = net_nbuf_ll_dst(buf); + ll = net_pkt_ll_dst(buf); if (ll->addr) { memcpy(&hdr->dst.addr, ll->addr, sizeof(struct net_eth_addr)); } - ll = net_nbuf_ll_src(buf); + ll = net_pkt_ll_src(buf); if (ll->addr) { memcpy(&hdr->src.addr, ll->addr, sizeof(struct net_eth_addr)); @@ -222,17 +222,17 @@ struct net_buf *net_arp_prepare(struct net_buf *buf) net_buf_frag_insert(buf, header); - net_nbuf_compact(buf); + net_pkt_compact(buf); } - hdr = (struct net_eth_hdr *)net_nbuf_ll(buf); + hdr = (struct net_eth_hdr *)net_pkt_ll(buf); /* Is the destination in the local network, if not route via * the gateway address. */ - if (!net_if_ipv4_addr_mask_cmp(net_nbuf_iface(buf), + if (!net_if_ipv4_addr_mask_cmp(net_pkt_iface(buf), &NET_IPV4_BUF(buf)->dst)) { - addr = &net_nbuf_iface(buf)->ipv4.gw; + addr = &net_pkt_iface(buf)->ipv4.gw; } else { addr = &NET_IPV4_BUF(buf)->dst; } @@ -240,7 +240,7 @@ struct net_buf *net_arp_prepare(struct net_buf *buf) /* If the destination address is already known, we do not need * to send any ARP packet. */ - entry = find_entry(net_nbuf_iface(buf), + entry = find_entry(net_pkt_iface(buf), addr, &free_entry, &non_pending); if (!entry) { if (!free_entry) { @@ -255,11 +255,11 @@ struct net_buf *net_arp_prepare(struct net_buf *buf) */ struct net_buf *req; - req = prepare_arp(net_nbuf_iface(buf), + req = prepare_arp(net_pkt_iface(buf), addr, NULL, buf); NET_DBG("Resending ARP %p", req); - net_nbuf_unref(buf); + net_pkt_unref(buf); return req; } @@ -267,7 +267,7 @@ struct net_buf *net_arp_prepare(struct net_buf *buf) free_entry = non_pending; } - return prepare_arp(net_nbuf_iface(buf), addr, free_entry, buf); + return prepare_arp(net_pkt_iface(buf), addr, free_entry, buf); } ll = net_if_get_link_addr(entry->iface); @@ -287,7 +287,7 @@ struct net_buf *net_arp_prepare(struct net_buf *buf) } hdr = (struct net_eth_hdr *)(frag->data - - net_nbuf_ll_reserve(buf)); + net_pkt_ll_reserve(buf)); hdr->type = htons(NET_ETH_PTYPE_IP); memcpy(&hdr->src.addr, ll->addr, @@ -313,7 +313,7 @@ static inline void send_pending(struct net_if *iface, struct net_buf **buf) if (net_if_send_data(iface, pending) == NET_DROP) { /* This is to unref the original ref */ - net_nbuf_unref(pending); + net_pkt_unref(pending); } /* The pending buf was referenced when @@ -321,7 +321,7 @@ static inline void send_pending(struct net_if *iface, struct net_buf **buf) * unref it now when it is removed from * the cache. */ - net_nbuf_unref(pending); + net_pkt_unref(pending); } static inline void arp_update(struct net_if *iface, @@ -351,9 +351,9 @@ static inline void arp_update(struct net_if *iface, sizeof(struct net_eth_addr)); /* Set the dst in the pending packet */ - net_nbuf_ll_dst(arp_table[i].pending)->len = + net_pkt_ll_dst(arp_table[i].pending)->len = sizeof(struct net_eth_addr); - net_nbuf_ll_dst(arp_table[i].pending)->addr = + net_pkt_ll_dst(arp_table[i].pending)->addr = (uint8_t *) &NET_ETH_BUF(arp_table[i].pending)->dst.addr; @@ -372,19 +372,19 @@ 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(sizeof(struct net_eth_hdr), K_FOREVER); + buf = net_pkt_get_reserve_tx(sizeof(struct net_eth_hdr), K_FOREVER); if (!buf) { goto fail; } - frag = net_nbuf_get_frag(buf, K_FOREVER); + frag = net_pkt_get_frag(buf, K_FOREVER); if (!frag) { goto fail; } net_buf_frag_add(buf, frag); - net_nbuf_set_iface(buf, iface); - net_nbuf_set_family(buf, AF_INET); + net_pkt_set_iface(buf, iface); + net_pkt_set_family(buf, AF_INET); hdr = NET_ARP_BUF(buf); eth = NET_ETH_BUF(buf); @@ -417,7 +417,7 @@ static inline struct net_buf *prepare_arp_reply(struct net_if *iface, return buf; fail: - net_nbuf_unref(buf); + net_pkt_unref(buf); return NULL; } @@ -427,11 +427,11 @@ enum net_verdict net_arp_input(struct net_buf *buf) struct net_buf *reply; if (net_buf_frags_len(buf) < (sizeof(struct net_arp_hdr) - - net_nbuf_ll_reserve(buf))) { + net_pkt_ll_reserve(buf))) { NET_DBG("Invalid ARP header (len %zu, min %zu bytes)", net_buf_frags_len(buf), sizeof(struct net_arp_hdr) - - net_nbuf_ll_reserve(buf)); + net_pkt_ll_reserve(buf)); return NET_DROP; } @@ -441,7 +441,7 @@ enum net_verdict net_arp_input(struct net_buf *buf) case NET_ARP_REQUEST: /* Someone wants to know our ll address */ if (!net_ipv4_addr_cmp(&arp_hdr->dst_ipaddr, - if_get_addr(net_nbuf_iface(buf)))) { + if_get_addr(net_pkt_iface(buf)))) { /* Not for us so drop the packet silently */ return NET_DROP; } @@ -461,21 +461,21 @@ enum net_verdict net_arp_input(struct net_buf *buf) #endif /* CONFIG_NET_DEBUG_ARP */ /* Send reply */ - reply = prepare_arp_reply(net_nbuf_iface(buf), buf); + reply = prepare_arp_reply(net_pkt_iface(buf), buf); if (reply) { - net_if_queue_tx(net_nbuf_iface(reply), reply); + net_if_queue_tx(net_pkt_iface(reply), reply); } break; case NET_ARP_REPLY: if (net_is_my_ipv4_addr(&arp_hdr->dst_ipaddr)) { - arp_update(net_nbuf_iface(buf), &arp_hdr->src_ipaddr, + arp_update(net_pkt_iface(buf), &arp_hdr->src_ipaddr, &arp_hdr->src_hwaddr); } break; } - net_nbuf_unref(buf); + net_pkt_unref(buf); return NET_OK; } diff --git a/subsys/net/ip/l2/bluetooth.c b/subsys/net/ip/l2/bluetooth.c index a4211b48c..a5efddd25 100644 --- a/subsys/net/ip/l2/bluetooth.c +++ b/subsys/net/ip/l2/bluetooth.c @@ -19,7 +19,7 @@ #include <device.h> #include <init.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_core.h> #include <net/net_l2.h> #include <net/net_if.h> @@ -69,7 +69,7 @@ static enum net_verdict net_bt_send(struct net_if *iface, struct net_buf *buf) NET_DBG("iface %p buf %p len %zu", iface, buf, net_buf_frags_len(buf)); /* Only accept IPv6 packets */ - if (net_nbuf_family(buf) != AF_INET6) { + if (net_pkt_family(buf) != AF_INET6) { return NET_DROP; } @@ -173,32 +173,32 @@ static void ipsp_disconnected(struct bt_l2cap_chan *chan) static void ipsp_recv(struct bt_l2cap_chan *chan, struct net_buf *buf) { struct bt_context *ctxt = CHAN_CTXT(chan); - struct net_buf *nbuf; + struct net_buf *pkt; NET_DBG("Incoming data channel %p len %zu", chan, net_buf_frags_len(buf)); /* Get buffer for bearer / protocol related data */ - nbuf = net_nbuf_get_reserve_rx(0, K_FOREVER); + pkt = net_pkt_get_reserve_rx(0, K_FOREVER); /* Set destination address */ - net_nbuf_ll_dst(nbuf)->addr = ctxt->src.val; - net_nbuf_ll_dst(nbuf)->len = sizeof(ctxt->src); - net_nbuf_ll_dst(nbuf)->type = NET_LINK_BLUETOOTH; + net_pkt_ll_dst(pkt)->addr = ctxt->src.val; + net_pkt_ll_dst(pkt)->len = sizeof(ctxt->src); + net_pkt_ll_dst(pkt)->type = NET_LINK_BLUETOOTH; /* Set source address */ - net_nbuf_ll_src(nbuf)->addr = ctxt->dst.val; - net_nbuf_ll_src(nbuf)->len = sizeof(ctxt->dst); - net_nbuf_ll_src(nbuf)->type = NET_LINK_BLUETOOTH; + net_pkt_ll_src(pkt)->addr = ctxt->dst.val; + net_pkt_ll_src(pkt)->len = sizeof(ctxt->dst); + net_pkt_ll_src(pkt)->type = NET_LINK_BLUETOOTH; /* Add data buffer as fragment of RX buffer, take a reference while * doing so since L2CAP will unref the buffer after return. */ - net_buf_frag_add(nbuf, net_nbuf_ref(buf)); + net_buf_frag_add(pkt, net_pkt_ref(buf)); - if (net_recv_data(ctxt->iface, nbuf) < 0) { + if (net_recv_data(ctxt->iface, pkt) < 0) { NET_DBG("Packet dropped by NET stack"); - net_nbuf_unref(nbuf); + net_pkt_unref(pkt); } } @@ -206,7 +206,7 @@ static struct net_buf *ipsp_alloc_buf(struct bt_l2cap_chan *chan) { NET_DBG("Channel %p requires buffer", chan); - return net_nbuf_get_reserve_rx_data(0, K_FOREVER); + return net_pkt_get_reserve_rx_data(0, K_FOREVER); } static struct bt_l2cap_chan_ops ipsp_ops = { diff --git a/subsys/net/ip/l2/dummy.c b/subsys/net/ip/l2/dummy.c index c718e329c..59de85fe6 100644 --- a/subsys/net/ip/l2/dummy.c +++ b/subsys/net/ip/l2/dummy.c @@ -7,17 +7,17 @@ #include <net/net_core.h> #include <net/net_l2.h> #include <net/net_if.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> static inline enum net_verdict dummy_recv(struct net_if *iface, struct net_buf *buf) { - net_nbuf_ll_src(buf)->addr = NULL; - net_nbuf_ll_src(buf)->len = 0; - net_nbuf_ll_src(buf)->type = NET_LINK_DUMMY; - net_nbuf_ll_dst(buf)->addr = NULL; - net_nbuf_ll_dst(buf)->len = 0; - net_nbuf_ll_dst(buf)->type = NET_LINK_DUMMY; + net_pkt_ll_src(buf)->addr = NULL; + net_pkt_ll_src(buf)->len = 0; + net_pkt_ll_src(buf)->type = NET_LINK_DUMMY; + net_pkt_ll_dst(buf)->addr = NULL; + net_pkt_ll_dst(buf)->len = 0; + net_pkt_ll_dst(buf)->type = NET_LINK_DUMMY; return NET_CONTINUE; } diff --git a/subsys/net/ip/l2/ethernet.c b/subsys/net/ip/l2/ethernet.c index 935b1c99b..1a28ae981 100644 --- a/subsys/net/ip/l2/ethernet.c +++ b/subsys/net/ip/l2/ethernet.c @@ -37,11 +37,11 @@ const struct net_eth_addr *net_eth_broadcast_addr(void) char out[sizeof("xx:xx:xx:xx:xx:xx")]; \ \ snprintk(out, sizeof(out), "%s", \ - net_sprint_ll_addr(net_nbuf_ll_src(buf)->addr, \ + net_sprint_ll_addr(net_pkt_ll_src(buf)->addr, \ sizeof(struct net_eth_addr))); \ \ NET_DBG("src %s dst %s type 0x%x len %zu", out, \ - net_sprint_ll_addr(net_nbuf_ll_dst(buf)->addr, \ + net_sprint_ll_addr(net_pkt_ll_dst(buf)->addr, \ sizeof(struct net_eth_addr)), \ type, (size_t)len); \ } while (0) @@ -60,7 +60,7 @@ static inline void ethernet_update_length(struct net_if *iface, * frame size of 60 bytes. In that case, we need to get rid of it. */ - if (net_nbuf_family(buf) == AF_INET) { + if (net_pkt_family(buf) == AF_INET) { len = ((NET_IPV4_BUF(buf)->len[0] << 8) + NET_IPV4_BUF(buf)->len[1]); } else { @@ -93,11 +93,11 @@ static enum net_verdict ethernet_recv(struct net_if *iface, switch (ntohs(hdr->type)) { case NET_ETH_PTYPE_IP: case NET_ETH_PTYPE_ARP: - net_nbuf_set_family(buf, AF_INET); + net_pkt_set_family(buf, AF_INET); family = AF_INET; break; case NET_ETH_PTYPE_IPV6: - net_nbuf_set_family(buf, AF_INET6); + net_pkt_set_family(buf, AF_INET6); family = AF_INET6; break; default: @@ -106,13 +106,13 @@ static enum net_verdict ethernet_recv(struct net_if *iface, } /* Set the pointers to ll src and dst addresses */ - lladdr = net_nbuf_ll_src(buf); - lladdr->addr = ((struct net_eth_hdr *)net_nbuf_ll(buf))->src.addr; + lladdr = net_pkt_ll_src(buf); + lladdr->addr = ((struct net_eth_hdr *)net_pkt_ll(buf))->src.addr; lladdr->len = sizeof(struct net_eth_addr); lladdr->type = NET_LINK_ETHERNET; - lladdr = net_nbuf_ll_dst(buf); - lladdr->addr = ((struct net_eth_hdr *)net_nbuf_ll(buf))->dst.addr; + lladdr = net_pkt_ll_dst(buf); + lladdr->addr = ((struct net_eth_hdr *)net_pkt_ll(buf))->dst.addr; lladdr->len = sizeof(struct net_eth_addr); lladdr->type = NET_LINK_ETHERNET; @@ -131,8 +131,8 @@ static enum net_verdict ethernet_recv(struct net_if *iface, return NET_DROP; } - net_nbuf_set_ll_reserve(buf, sizeof(struct net_eth_hdr)); - net_buf_pull(buf->frags, net_nbuf_ll_reserve(buf)); + net_pkt_set_ll_reserve(buf, sizeof(struct net_eth_hdr)); + net_buf_pull(buf->frags, net_pkt_ll_reserve(buf)); #ifdef CONFIG_NET_ARP if (family == AF_INET && hdr->type == htons(NET_ETH_PTYPE_ARP)) { @@ -155,10 +155,10 @@ static inline bool check_if_dst_is_broadcast_or_mcast(struct net_if *iface, if (net_ipv4_addr_cmp(&NET_IPV4_BUF(buf)->dst, net_ipv4_broadcast_address())) { /* Broadcast address */ - net_nbuf_ll_dst(buf)->addr = (uint8_t *)broadcast_eth_addr.addr; - net_nbuf_ll_dst(buf)->len = sizeof(struct net_eth_addr); - net_nbuf_ll_src(buf)->addr = net_if_get_link_addr(iface)->addr; - net_nbuf_ll_src(buf)->len = sizeof(struct net_eth_addr); + net_pkt_ll_dst(buf)->addr = (uint8_t *)broadcast_eth_addr.addr; + net_pkt_ll_dst(buf)->len = sizeof(struct net_eth_addr); + net_pkt_ll_src(buf)->addr = net_if_get_link_addr(iface)->addr; + net_pkt_ll_src(buf)->len = sizeof(struct net_eth_addr); return true; } else if (NET_IPV4_BUF(buf)->dst.s4_addr[0] == 224) { @@ -170,9 +170,9 @@ static inline bool check_if_dst_is_broadcast_or_mcast(struct net_if *iface, hdr->dst.addr[4] = NET_IPV4_BUF(buf)->dst.s4_addr[2]; hdr->dst.addr[5] = NET_IPV4_BUF(buf)->dst.s4_addr[3]; - net_nbuf_ll_dst(buf)->len = sizeof(struct net_eth_addr); - net_nbuf_ll_src(buf)->addr = net_if_get_link_addr(iface)->addr; - net_nbuf_ll_src(buf)->len = sizeof(struct net_eth_addr); + net_pkt_ll_dst(buf)->len = sizeof(struct net_eth_addr); + net_pkt_ll_src(buf)->addr = net_if_get_link_addr(iface)->addr; + net_pkt_ll_src(buf)->len = sizeof(struct net_eth_addr); return true; } @@ -188,7 +188,7 @@ static enum net_verdict ethernet_send(struct net_if *iface, uint16_t ptype; #ifdef CONFIG_NET_ARP - if (net_nbuf_family(buf) == AF_INET) { + if (net_pkt_family(buf) == AF_INET) { struct net_buf *arp_buf; if (check_if_dst_is_broadcast_or_mcast(iface, buf)) { @@ -205,10 +205,10 @@ static enum net_verdict ethernet_send(struct net_if *iface, buf = arp_buf; - net_nbuf_ll_src(buf)->addr = (uint8_t *)&NET_ETH_BUF(buf)->src; - net_nbuf_ll_src(buf)->len = sizeof(struct net_eth_addr); - net_nbuf_ll_dst(buf)->addr = (uint8_t *)&NET_ETH_BUF(buf)->dst; - net_nbuf_ll_dst(buf)->len = sizeof(struct net_eth_addr); + net_pkt_ll_src(buf)->addr = (uint8_t *)&NET_ETH_BUF(buf)->src; + net_pkt_ll_src(buf)->len = sizeof(struct net_eth_addr); + net_pkt_ll_dst(buf)->addr = (uint8_t *)&NET_ETH_BUF(buf)->dst; + net_pkt_ll_dst(buf)->len = sizeof(struct net_eth_addr); /* For ARP message, we do not touch the packet further but will * send it as it is because the arp.c has prepared the packet @@ -226,19 +226,19 @@ static enum net_verdict ethernet_send(struct net_if *iface, * substitute the src address using the real ll address. */ if (net_eth_is_addr_broadcast((struct net_eth_addr *) - net_nbuf_ll_src(buf)->addr) || + net_pkt_ll_src(buf)->addr) || net_eth_is_addr_multicast((struct net_eth_addr *) - net_nbuf_ll_src(buf)->addr)) { - net_nbuf_ll_src(buf)->addr = net_nbuf_ll_if(buf)->addr; - net_nbuf_ll_src(buf)->len = net_nbuf_ll_if(buf)->len; + net_pkt_ll_src(buf)->addr)) { + net_pkt_ll_src(buf)->addr = net_pkt_ll_if(buf)->addr; + net_pkt_ll_src(buf)->len = net_pkt_ll_if(buf)->len; } /* If the destination address is not set, then use broadcast * or multicast address. */ - if (!net_nbuf_ll_dst(buf)->addr) { + if (!net_pkt_ll_dst(buf)->addr) { #if defined(CONFIG_NET_IPV6) - if (net_nbuf_family(buf) == AF_INET6 && + if (net_pkt_family(buf) == AF_INET6 && net_is_ipv6_addr_mcast(&NET_IPV6_BUF(buf)->dst)) { struct net_eth_addr *dst = &NET_ETH_BUF(buf)->dst; @@ -248,25 +248,25 @@ static enum net_verdict ethernet_send(struct net_if *iface, (uint8_t *)(&NET_IPV6_BUF(buf)->dst) + 12, sizeof(struct net_eth_addr) - 2); - net_nbuf_ll_dst(buf)->addr = (uint8_t *)dst->addr; + net_pkt_ll_dst(buf)->addr = (uint8_t *)dst->addr; } else #endif { - net_nbuf_ll_dst(buf)->addr = + net_pkt_ll_dst(buf)->addr = (uint8_t *)broadcast_eth_addr.addr; } - net_nbuf_ll_dst(buf)->len = sizeof(struct net_eth_addr); + net_pkt_ll_dst(buf)->len = sizeof(struct net_eth_addr); NET_DBG("Destination address was not set, using %s", - net_sprint_ll_addr(net_nbuf_ll_dst(buf)->addr, - net_nbuf_ll_dst(buf)->len)); + net_sprint_ll_addr(net_pkt_ll_dst(buf)->addr, + net_pkt_ll_dst(buf)->len)); } setup_hdr: __unused; - if (net_nbuf_family(buf) == AF_INET) { + if (net_pkt_family(buf) == AF_INET) { ptype = htons(NET_ETH_PTYPE_IP); } else { ptype = htons(NET_ETH_PTYPE_IPV6); @@ -282,10 +282,10 @@ setup_hdr: NET_ASSERT(net_buf_headroom(frag) > sizeof(struct net_eth_addr)); hdr = (struct net_eth_hdr *)(frag->data - - net_nbuf_ll_reserve(buf)); - memcpy(&hdr->dst, net_nbuf_ll_dst(buf)->addr, + net_pkt_ll_reserve(buf)); + memcpy(&hdr->dst, net_pkt_ll_dst(buf)->addr, sizeof(struct net_eth_addr)); - memcpy(&hdr->src, net_nbuf_ll_src(buf)->addr, + memcpy(&hdr->src, net_pkt_ll_src(buf)->addr, sizeof(struct net_eth_addr)); hdr->type = ptype; print_ll_addrs(buf, ntohs(hdr->type), frag->len); diff --git a/subsys/net/ip/l2/ieee802154/ieee802154.c b/subsys/net/ip/l2/ieee802154/ieee802154.c index c5d32f5aa..69efd6ea5 100644 --- a/subsys/net/ip/l2/ieee802154/ieee802154.c +++ b/subsys/net/ip/l2/ieee802154/ieee802154.c @@ -65,7 +65,7 @@ static inline void hexdump(uint8_t *pkt, uint16_t length, uint8_t reserve) static void pkt_hexdump(struct net_buf *buf, bool each_frag_reserve) { - uint16_t reserve = each_frag_reserve ? net_nbuf_ll_reserve(buf) : 0; + uint16_t reserve = each_frag_reserve ? net_pkt_ll_reserve(buf) : 0; struct net_buf *frag; printk("IEEE 802.15.4 packet content:\n"); @@ -93,12 +93,12 @@ static inline void ieee802154_acknowledge(struct net_if *iface, return; } - buf = net_nbuf_get_reserve_tx(IEEE802154_ACK_PKT_LENGTH, K_FOREVER); + buf = net_pkt_get_reserve_tx(IEEE802154_ACK_PKT_LENGTH, K_FOREVER); if (!buf) { return; } - frag = net_nbuf_get_frag(buf, K_FOREVER); + frag = net_pkt_get_frag(buf, K_FOREVER); net_buf_frag_insert(buf, frag); @@ -111,7 +111,7 @@ static inline void ieee802154_acknowledge(struct net_if *iface, radio->tx(iface->dev, buf, frag); } - net_nbuf_unref(buf); + net_pkt_unref(buf); return; } @@ -156,25 +156,25 @@ enum net_verdict ieee802154_manage_recv_buffer(struct net_if *iface, /* Upper IP stack expects the link layer address to be in * big endian format so we must swap it here. */ - if (net_nbuf_ll_src(buf)->addr && - net_nbuf_ll_src(buf)->len == IEEE802154_EXT_ADDR_LENGTH) { - sys_mem_swap(net_nbuf_ll_src(buf)->addr, - net_nbuf_ll_src(buf)->len); + if (net_pkt_ll_src(buf)->addr && + net_pkt_ll_src(buf)->len == IEEE802154_EXT_ADDR_LENGTH) { + sys_mem_swap(net_pkt_ll_src(buf)->addr, + net_pkt_ll_src(buf)->len); } - if (net_nbuf_ll_dst(buf)->addr && - net_nbuf_ll_dst(buf)->len == IEEE802154_EXT_ADDR_LENGTH) { - sys_mem_swap(net_nbuf_ll_dst(buf)->addr, - net_nbuf_ll_dst(buf)->len); + if (net_pkt_ll_dst(buf)->addr && + net_pkt_ll_dst(buf)->len == IEEE802154_EXT_ADDR_LENGTH) { + sys_mem_swap(net_pkt_ll_dst(buf)->addr, + net_pkt_ll_dst(buf)->len); } /** Uncompress will drop the current fragment. Buf ll src/dst address * will then be wrong and must be updated according to the new fragment. */ - src = net_nbuf_ll_src(buf)->addr ? - net_nbuf_ll_src(buf)->addr - net_nbuf_ll(buf) : 0; - dst = net_nbuf_ll_dst(buf)->addr ? - net_nbuf_ll_dst(buf)->addr - net_nbuf_ll(buf) : 0; + src = net_pkt_ll_src(buf)->addr ? + net_pkt_ll_src(buf)->addr - net_pkt_ll(buf) : 0; + dst = net_pkt_ll_dst(buf)->addr ? + net_pkt_ll_dst(buf)->addr - net_pkt_ll(buf) : 0; #ifdef CONFIG_NET_L2_IEEE802154_FRAGMENT verdict = ieee802154_reassemble(buf); @@ -188,8 +188,8 @@ enum net_verdict ieee802154_manage_recv_buffer(struct net_if *iface, goto out; } #endif - net_nbuf_ll_src(buf)->addr = src ? net_nbuf_ll(buf) + src : NULL; - net_nbuf_ll_dst(buf)->addr = dst ? net_nbuf_ll(buf) + dst : NULL; + net_pkt_ll_src(buf)->addr = src ? net_pkt_ll(buf) + src : NULL; + net_pkt_ll_dst(buf)->addr = dst ? net_pkt_ll(buf) + dst : NULL; pkt_hexdump(buf, false); out: @@ -226,7 +226,7 @@ static enum net_verdict ieee802154_recv(struct net_if *iface, { struct ieee802154_mpdu mpdu; - if (!ieee802154_validate_frame(net_nbuf_ll(buf), + if (!ieee802154_validate_frame(net_pkt_ll(buf), net_buf_frags_len(buf), &mpdu)) { return NET_DROP; } @@ -247,13 +247,13 @@ static enum net_verdict ieee802154_recv(struct net_if *iface, ieee802154_acknowledge(iface, &mpdu); - net_nbuf_set_ll_reserve(buf, mpdu.payload - (void *)net_nbuf_ll(buf)); - net_buf_pull(buf->frags, net_nbuf_ll_reserve(buf)); + net_pkt_set_ll_reserve(buf, mpdu.payload - (void *)net_pkt_ll(buf)); + net_buf_pull(buf->frags, net_pkt_ll_reserve(buf)); - set_buf_ll_addr(net_nbuf_ll_src(buf), mpdu.mhr.fs->fc.pan_id_comp, + set_buf_ll_addr(net_pkt_ll_src(buf), mpdu.mhr.fs->fc.pan_id_comp, mpdu.mhr.fs->fc.src_addr_mode, mpdu.mhr.src_addr); - set_buf_ll_addr(net_nbuf_ll_dst(buf), false, + set_buf_ll_addr(net_pkt_ll_dst(buf), false, mpdu.mhr.fs->fc.dst_addr_mode, mpdu.mhr.dst_addr); if (!ieee802154_decipher_data_frame(iface, buf, &mpdu)) { @@ -269,10 +269,10 @@ static enum net_verdict ieee802154_send(struct net_if *iface, struct net_buf *buf) { struct ieee802154_context *ctx = net_if_l2_data(iface); - uint8_t reserved_space = net_nbuf_ll_reserve(buf); + uint8_t reserved_space = net_pkt_ll_reserve(buf); struct net_buf *frag; - if (net_nbuf_family(buf) != AF_INET6) { + if (net_pkt_family(buf) != AF_INET6) { return NET_DROP; } @@ -288,7 +288,7 @@ static enum net_verdict ieee802154_send(struct net_if *iface, return NET_DROP; } - if (!ieee802154_create_data_frame(ctx, net_nbuf_ll_dst(buf), + if (!ieee802154_create_data_frame(ctx, net_pkt_ll_dst(buf), frag, reserved_space)) { return NET_DROP; } diff --git a/subsys/net/ip/l2/ieee802154/ieee802154_fragment.c b/subsys/net/ip/l2/ieee802154/ieee802154_fragment.c index e7e587d09..5deaf284a 100644 --- a/subsys/net/ip/l2/ieee802154/ieee802154_fragment.c +++ b/subsys/net/ip/l2/ieee802154/ieee802154_fragment.c @@ -15,7 +15,7 @@ #include <errno.h> #include <net/net_core.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_if.h> #include <net/net_stats.h> @@ -83,7 +83,7 @@ static inline struct net_buf *prepare_new_fragment(struct net_buf *buf, { struct net_buf *frag; - frag = net_nbuf_get_frag(buf, K_FOREVER); + frag = net_pkt_get_frag(buf, K_FOREVER); if (!frag) { return NULL; } @@ -140,7 +140,7 @@ static inline uint8_t calc_max_payload(struct net_buf *buf, { uint8_t max; - max = frag->size - net_nbuf_ll_reserve(buf); + max = frag->size - net_pkt_ll_reserve(buf); max -= offset ? NET_6LO_FRAGN_HDR_LEN : NET_6LO_FRAG1_HDR_LEN; return (max & 0xF8); @@ -286,7 +286,7 @@ bool ieee802154_fragment(struct net_buf *buf, int hdr_diff) compact_frag(next, move); if (!next->len) { - next = net_nbuf_frag_del(NULL, next); + next = net_pkt_frag_del(NULL, next); if (!next) { break; } @@ -314,7 +314,7 @@ static inline void remove_frag_header(struct net_buf *frag, uint8_t hdr_len) static void update_protocol_header_lengths(struct net_buf *buf, uint16_t size) { - net_nbuf_set_ip_hdr_len(buf, NET_IPV6H_LEN); + net_pkt_set_ip_hdr_len(buf, NET_IPV6H_LEN); NET_IPV6_BUF(buf)->len[0] = (size - NET_IPV6H_LEN) >> 8; NET_IPV6_BUF(buf)->len[1] = (uint8_t) (size - NET_IPV6H_LEN); @@ -334,7 +334,7 @@ static inline void clear_reass_cache(uint16_t size, uint16_t tag) } if (cache[i].buf) { - net_nbuf_unref(cache[i].buf); + net_pkt_unref(cache[i].buf); } cache[i].buf = NULL; @@ -354,7 +354,7 @@ static void reass_timeout(struct k_work *work) struct frag_cache *cache = CONTAINER_OF(work, struct frag_cache, timer); if (cache->buf) { - net_nbuf_unref(cache->buf); + net_pkt_unref(cache->buf); } cache->buf = NULL; @@ -423,13 +423,13 @@ static inline bool copy_frag(struct net_buf *buf, write = buf->frags; while (input) { - write = net_nbuf_write(buf, write, pos, &pos, input->len, - input->data, NET_6LO_RX_NBUF_TIMEOUT); + write = net_pkt_write(buf, write, pos, &pos, input->len, + input->data, NET_6LO_RX_PKT_TIMEOUT); if (!write && pos == 0xffff) { /* Free the new bufs we tried to get, we need to discard * the whole fragment chain. */ - net_nbuf_unref(buf->frags); + net_pkt_unref(buf->frags); buf->frags = NULL; return false; @@ -438,7 +438,7 @@ static inline bool copy_frag(struct net_buf *buf, input = input->frags; } - net_nbuf_unref(frag); + net_pkt_unref(frag); return true; } @@ -553,7 +553,7 @@ static inline enum net_verdict add_frag_to_cache(struct net_buf *buf, } /* Unref Rx part of original buffer */ - net_nbuf_unref(buf); + net_pkt_unref(buf); return NET_OK; } diff --git a/subsys/net/ip/l2/ieee802154/ieee802154_fragment.h b/subsys/net/ip/l2/ieee802154/ieee802154_fragment.h index 251d88844..11f33e950 100644 --- a/subsys/net/ip/l2/ieee802154/ieee802154_fragment.h +++ b/subsys/net/ip/l2/ieee802154/ieee802154_fragment.h @@ -16,7 +16,7 @@ #include <misc/slist.h> #include <zephyr/types.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> /** * @brief Fragment IPv6 packet as per RFC 6282 diff --git a/subsys/net/ip/l2/ieee802154/ieee802154_frame.c b/subsys/net/ip/l2/ieee802154/ieee802154_frame.c index 8f3122a7a..5f2f81b63 100644 --- a/subsys/net/ip/l2/ieee802154/ieee802154_frame.c +++ b/subsys/net/ip/l2/ieee802154/ieee802154_frame.c @@ -817,18 +817,18 @@ ieee802154_create_mac_cmd_frame(struct ieee802154_context *ctx, struct net_buf *buf, *frag; uint8_t *p_buf; - buf = net_nbuf_get_reserve_tx(0, K_FOREVER); + buf = net_pkt_get_reserve_tx(0, K_FOREVER); if (!buf) { return NULL; } - frag = net_nbuf_get_frag(buf, K_FOREVER); + frag = net_pkt_get_frag(buf, K_FOREVER); if (!frag) { goto error; } net_buf_frag_add(buf, frag); - p_buf = net_nbuf_ll(buf); + p_buf = net_pkt_ll(buf); fs = generate_fcf_grounds(&p_buf, type == IEEE802154_CFI_BEACON_REQUEST ? @@ -851,20 +851,20 @@ ieee802154_create_mac_cmd_frame(struct ieee802154_context *ctx, * to be easy to handle afterwards to point directly to MAC * command space, in order to fill-in its content. */ - net_nbuf_set_ll_reserve(buf, p_buf - net_nbuf_ll(buf)); - net_buf_pull(frag, net_nbuf_ll_reserve(buf)); + net_pkt_set_ll_reserve(buf, p_buf - net_pkt_ll(buf)); + net_buf_pull(frag, net_pkt_ll_reserve(buf)); /* Thus setting the right MAC command length * Now up to the caller to fill-in this space relevantly. * See ieee802154_mac_command() helper. */ - net_nbuf_set_len(frag, mac_command_length(type)); + net_pkt_set_len(frag, mac_command_length(type)); dbg_print_fs(fs); return buf; error: - net_nbuf_unref(buf); + net_pkt_unref(buf); return NULL; } @@ -874,7 +874,7 @@ error: bool ieee802154_create_ack_frame(struct net_if *iface, struct net_buf *buf, uint8_t seq) { - uint8_t *p_buf = net_nbuf_ll(buf); + uint8_t *p_buf = net_pkt_ll(buf); struct ieee802154_fcf_seq *fs; if (!p_buf) { @@ -916,10 +916,10 @@ bool ieee802154_decipher_data_frame(struct net_if *iface, struct net_buf *buf, * This will require to look up in nbr cache with short addr * in order to get the extended address related to it */ - if (!ieee802154_decrypt_auth(&ctx->sec_ctx, net_nbuf_ll(buf), - net_nbuf_ll_reserve(buf), + if (!ieee802154_decrypt_auth(&ctx->sec_ctx, net_pkt_ll(buf), + net_pkt_ll_reserve(buf), net_buf_frags_len(buf), - net_nbuf_ll_src(buf)->addr, + net_pkt_ll_src(buf)->addr, sys_le32_to_cpu( mpdu->mhr.aux_sec->frame_counter))) { NET_ERR("Could not decipher the frame"); diff --git a/subsys/net/ip/l2/ieee802154/ieee802154_frame.h b/subsys/net/ip/l2/ieee802154/ieee802154_frame.h index 7892db487..bb6c3f203 100644 --- a/subsys/net/ip/l2/ieee802154/ieee802154_frame.h +++ b/subsys/net/ip/l2/ieee802154/ieee802154_frame.h @@ -13,7 +13,7 @@ #define __IEEE802154_FRAME_H__ #include <kernel.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #define IEEE802154_MTU 127 #define IEEE802154_MIN_LENGTH 3 @@ -472,7 +472,7 @@ ieee802154_create_mac_cmd_frame(struct ieee802154_context *ctx, static inline struct ieee802154_command *ieee802154_get_mac_command(struct net_buf *buf) { - return (struct ieee802154_command *)net_nbuf_ip_data(buf); + return (struct ieee802154_command *)net_pkt_ip_data(buf); } #ifdef CONFIG_NET_L2_IEEE802154_ACK_REPLY @@ -483,7 +483,7 @@ bool ieee802154_create_ack_frame(struct net_if *iface, static inline bool ieee802154_ack_required(struct net_buf *buf) { struct ieee802154_fcf_seq *fs = - (struct ieee802154_fcf_seq *)net_nbuf_ll(buf); + (struct ieee802154_fcf_seq *)net_pkt_ll(buf); return fs->fc.ar; } diff --git a/subsys/net/ip/l2/ieee802154/ieee802154_mgmt.c b/subsys/net/ip/l2/ieee802154/ieee802154_mgmt.c index f8844ff9d..162db50d0 100644 --- a/subsys/net/ip/l2/ieee802154/ieee802154_mgmt.c +++ b/subsys/net/ip/l2/ieee802154/ieee802154_mgmt.c @@ -138,14 +138,14 @@ static int ieee802154_scan(uint32_t mgmt_request, struct net_if *iface, /* Active scan sends a beacon request */ if (mgmt_request == NET_REQUEST_IEEE802154_ACTIVE_SCAN) { - net_nbuf_ref(buf); - net_nbuf_ref(buf->frags); + net_pkt_ref(buf); + net_pkt_ref(buf->frags); ret = ieee802154_radio_send(iface, buf); if (ret) { NET_DBG("Could not send Beacon Request (%d)", ret); - net_nbuf_unref(buf); + net_pkt_unref(buf); break; } @@ -169,7 +169,7 @@ out: ctx->scan_ctx = NULL; if (buf) { - net_nbuf_unref(buf); + net_pkt_unref(buf); } return ret; @@ -267,7 +267,7 @@ static int ieee802154_associate(uint32_t mgmt_request, struct net_if *iface, ctx->associated = false; if (net_if_send_data(iface, buf)) { - net_nbuf_unref(buf); + net_pkt_unref(buf); ret = -EIO; goto out; } @@ -331,7 +331,7 @@ static int ieee802154_disassociate(uint32_t mgmt_request, struct net_if *iface, cmd->disassoc_note.reason = IEEE802154_DRF_DEVICE_WISH; if (net_if_send_data(iface, buf)) { - net_nbuf_unref(buf); + net_pkt_unref(buf); return -EIO; } diff --git a/subsys/net/ip/l2/ieee802154/ieee802154_radio_utils.h b/subsys/net/ip/l2/ieee802154/ieee802154_radio_utils.h index e1a9f0e88..49c2c092d 100644 --- a/subsys/net/ip/l2/ieee802154/ieee802154_radio_utils.h +++ b/subsys/net/ip/l2/ieee802154/ieee802154_radio_utils.h @@ -73,7 +73,7 @@ static inline int tx_buffer_fragments(struct net_if *iface, } if (!ret) { - net_nbuf_unref(buf); + net_pkt_unref(buf); } return ret; diff --git a/subsys/net/ip/net_context.c b/subsys/net/ip/net_context.c index c8c96f20e..5d1450ad5 100644 --- a/subsys/net/ip/net_context.c +++ b/subsys/net/ip/net_context.c @@ -20,7 +20,7 @@ #include <errno.h> #include <stdbool.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_ip.h> #include <net/net_context.h> #include <net/net_offload.h> @@ -79,7 +79,7 @@ static struct sockaddr *create_sockaddr(struct net_buf *buf, struct sockaddr *addr) { #if defined(CONFIG_NET_IPV6) - if (net_nbuf_family(buf) == AF_INET6) { + if (net_pkt_family(buf) == AF_INET6) { net_ipaddr_copy(&net_sin6(addr)->sin6_addr, &NET_IPV6_BUF(buf)->src); net_sin6(addr)->sin6_port = NET_TCP_BUF(buf)->src_port; @@ -88,7 +88,7 @@ static struct sockaddr *create_sockaddr(struct net_buf *buf, #endif #if defined(CONFIG_NET_IPV4) - if (net_nbuf_family(buf) == AF_INET) { + if (net_pkt_family(buf) == AF_INET) { net_ipaddr_copy(&net_sin(addr)->sin_addr, &NET_IPV4_BUF(buf)->src); net_sin(addr)->sin_port = NET_TCP_BUF(buf)->src_port; @@ -357,7 +357,7 @@ static void queue_fin(struct net_context *ctx) ret = net_tcp_send_buf(buf); if (ret < 0) { - net_nbuf_unref(buf); + net_pkt_unref(buf); } } @@ -709,7 +709,7 @@ static inline int send_control_segment(struct net_context *context, ret = net_send_data(buf); if (ret < 0) { - net_nbuf_unref(buf); + net_pkt_unref(buf); } net_tcp_print_send_info(msg, buf, NET_TCP_BUF(buf)->dst_port); @@ -756,7 +756,7 @@ static inline int send_ack(struct net_context *context, ret = net_tcp_send_buf(buf); if (ret < 0) { - net_nbuf_unref(buf); + net_pkt_unref(buf); } return ret; @@ -777,7 +777,7 @@ static int send_reset(struct net_context *context, ret = net_send_data(buf); if (ret < 0) { - net_nbuf_unref(buf); + net_pkt_unref(buf); } return ret; @@ -786,7 +786,7 @@ static int send_reset(struct net_context *context, static int tcp_hdr_len(struct net_buf *buf) { /* "Offset": 4-bit field in high nibble, units of dwords */ - struct net_tcp_hdr *hdr = (void *)net_nbuf_tcp_data(buf); + struct net_tcp_hdr *hdr = (void *)net_pkt_tcp_data(buf); return 4 * (hdr->offset >> 4); } @@ -825,7 +825,7 @@ NET_CONN_CB(tcp_established) } set_appdata_values(buf, IPPROTO_TCP); - context->tcp->send_ack += net_nbuf_appdatalen(buf); + context->tcp->send_ack += net_pkt_appdatalen(buf); ret = packet_received(conn, buf, context->tcp->recv_user_data); @@ -868,7 +868,7 @@ NET_CONN_CB(tcp_synack_received) switch (net_tcp_get_state(context->tcp)) { case NET_TCP_SYN_SENT: - net_context_set_iface(context, net_nbuf_iface(buf)); + net_context_set_iface(context, net_pkt_iface(buf)); break; default: NET_DBG("Context %p in wrong state %d", @@ -876,9 +876,9 @@ NET_CONN_CB(tcp_synack_received) return NET_DROP; } - net_nbuf_set_context(buf, context); + net_pkt_set_context(buf, context); - NET_ASSERT(net_nbuf_iface(buf)); + NET_ASSERT(net_pkt_iface(buf)); if (NET_TCP_FLAGS(buf) & NET_TCP_RST) { if (context->connect_cb) { @@ -911,7 +911,7 @@ NET_CONN_CB(tcp_synack_received) #endif #if defined(CONFIG_NET_IPV6) - if (net_nbuf_family(buf) == AF_INET6) { + if (net_pkt_family(buf) == AF_INET6) { laddr = (struct sockaddr *)&l6addr; raddr = (struct sockaddr *)&r6addr; @@ -927,7 +927,7 @@ NET_CONN_CB(tcp_synack_received) } else #endif #if defined(CONFIG_NET_IPV4) - if (net_nbuf_family(buf) == AF_INET) { + if (net_pkt_family(buf) == AF_INET) { laddr = (struct sockaddr *)&l4addr; raddr = (struct sockaddr *)&r4addr; @@ -943,7 +943,7 @@ NET_CONN_CB(tcp_synack_received) } else #endif { - NET_DBG("Invalid family (%d)", net_nbuf_family(buf)); + NET_DBG("Invalid family (%d)", net_pkt_family(buf)); return NET_DROP; } @@ -1211,7 +1211,7 @@ static void buf_get_sockaddr(sa_family_t family, struct net_buf *buf, #endif } -#if defined(CONFIG_NET_CONTEXT_NBUF_POOL) +#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL) static inline void copy_pool_vars(struct net_context *new_context, struct net_context *listen_context) { @@ -1220,7 +1220,7 @@ static inline void copy_pool_vars(struct net_context *new_context, } #else #define copy_pool_vars(...) -#endif /* CONFIG_NET_CONTEXT_NBUF_POOL */ +#endif /* CONFIG_NET_CONTEXT_NET_PKT_POOL */ /* This callback is called when we are waiting connections and we receive * a packet. We need to check if we are receiving proper msg (SYN) here. @@ -1239,10 +1239,10 @@ NET_CONN_CB(tcp_syn_rcvd) switch (net_tcp_get_state(tcp)) { case NET_TCP_LISTEN: - net_context_set_iface(context, net_nbuf_iface(buf)); + net_context_set_iface(context, net_pkt_iface(buf)); break; case NET_TCP_SYN_RCVD: - if (net_nbuf_iface(buf) != net_context_get_iface(context)) { + if (net_pkt_iface(buf) != net_context_get_iface(context)) { return NET_DROP; } break; @@ -1252,9 +1252,9 @@ NET_CONN_CB(tcp_syn_rcvd) return NET_DROP; } - net_nbuf_set_context(buf, context); + net_pkt_set_context(buf, context); - NET_ASSERT(net_nbuf_iface(buf)); + NET_ASSERT(net_pkt_iface(buf)); /* * If we receive SYN, we send SYN-ACK and go to SYN_RCVD state. @@ -1330,7 +1330,7 @@ NET_CONN_CB(tcp_syn_rcvd) /* We create a new context that starts to wait data. */ - ret = net_context_get(net_nbuf_family(buf), + ret = net_context_get(net_pkt_family(buf), SOCK_STREAM, IPPROTO_TCP, &new_context); if (ret < 0) { @@ -1570,7 +1570,7 @@ static int send_data(struct net_context *context, { context->send_cb = cb; context->user_data = user_data; - net_nbuf_set_token(buf, token); + net_pkt_set_token(buf, token); if (net_context_get_ip_proto(context) == IPPROTO_UDP) { return net_send_data(buf); @@ -1606,7 +1606,7 @@ static int create_udp_packet(struct net_context *context, int r = 0; #if defined(CONFIG_NET_IPV6) - if (net_nbuf_family(buf) == AF_INET6) { + if (net_pkt_family(buf) == AF_INET6) { struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)dst_addr; buf = net_ipv6_create(context, buf, NULL, &addr6->sin6_addr); @@ -1616,7 +1616,7 @@ static int create_udp_packet(struct net_context *context, #endif /* CONFIG_NET_IPV6 */ #if defined(CONFIG_NET_IPV4) - if (net_nbuf_family(buf) == AF_INET) { + if (net_pkt_family(buf) == AF_INET) { struct sockaddr_in *addr4 = (struct sockaddr_in *)dst_addr; buf = net_ipv4_create(context, buf, NULL, &addr4->sin_addr); @@ -1642,7 +1642,7 @@ static int sendto(struct net_buf *buf, void *token, void *user_data) { - struct net_context *context = net_nbuf_context(buf); + struct net_context *context = net_pkt_context(buf); int ret; if (!net_context_is_used(context)) { @@ -1667,16 +1667,16 @@ static int sendto(struct net_buf *buf, } #if defined(CONFIG_NET_OFFLOAD) - if (net_if_is_ip_offloaded(net_nbuf_iface(buf))) { + if (net_if_is_ip_offloaded(net_pkt_iface(buf))) { return net_offload_sendto( - net_nbuf_iface(buf), + net_pkt_iface(buf), buf, dst_addr, addrlen, cb, timeout, token, user_data); } #endif /* CONFIG_NET_OFFLOAD */ #if defined(CONFIG_NET_IPV6) - if (net_nbuf_family(buf) == AF_INET6) { + if (net_pkt_family(buf) == AF_INET6) { struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)dst_addr; if (addrlen < sizeof(struct sockaddr_in6)) { @@ -1690,7 +1690,7 @@ static int sendto(struct net_buf *buf, #endif /* CONFIG_NET_IPV6 */ #if defined(CONFIG_NET_IPV4) - if (net_nbuf_family(buf) == AF_INET) { + if (net_pkt_family(buf) == AF_INET) { struct sockaddr_in *addr4 = (struct sockaddr_in *)dst_addr; if (addrlen < sizeof(struct sockaddr_in)) { @@ -1703,7 +1703,7 @@ static int sendto(struct net_buf *buf, } else #endif /* CONFIG_NET_IPV4 */ { - NET_DBG("Invalid protocol family %d", net_nbuf_family(buf)); + NET_DBG("Invalid protocol family %d", net_pkt_family(buf)); return -EINVAL; } @@ -1738,15 +1738,15 @@ int net_context_send(struct net_buf *buf, void *token, void *user_data) { - struct net_context *context = net_nbuf_context(buf); + struct net_context *context = net_pkt_context(buf); socklen_t addrlen; NET_ASSERT(PART_OF_ARRAY(contexts, context)); #if defined(CONFIG_NET_OFFLOAD) - if (net_if_is_ip_offloaded(net_nbuf_iface(buf))) { + if (net_if_is_ip_offloaded(net_pkt_iface(buf))) { return net_offload_send( - net_nbuf_iface(buf), + net_pkt_iface(buf), buf, cb, timeout, token, user_data); } @@ -1758,13 +1758,13 @@ int net_context_send(struct net_buf *buf, } #if defined(CONFIG_NET_IPV6) - if (net_nbuf_family(buf) == AF_INET6) { + if (net_pkt_family(buf) == AF_INET6) { addrlen = sizeof(struct sockaddr_in6); } else #endif /* CONFIG_NET_IPV6 */ #if defined(CONFIG_NET_IPV4) - if (net_nbuf_family(buf) == AF_INET) { + if (net_pkt_family(buf) == AF_INET) { addrlen = sizeof(struct sockaddr_in); } else #endif /* CONFIG_NET_IPV4 */ @@ -1785,7 +1785,7 @@ int net_context_sendto(struct net_buf *buf, void *user_data) { #if defined(CONFIG_NET_TCP) - struct net_context *context = net_nbuf_context(buf); + struct net_context *context = net_pkt_context(buf); NET_ASSERT(PART_OF_ARRAY(contexts, context)); @@ -1804,29 +1804,29 @@ static void set_appdata_values(struct net_buf *buf, enum net_ip_protocol proto) #if defined(CONFIG_NET_UDP) if (proto == IPPROTO_UDP) { - net_nbuf_set_appdata(buf, net_nbuf_udp_data(buf) + + net_pkt_set_appdata(buf, net_pkt_udp_data(buf) + sizeof(struct net_udp_hdr)); } else #endif /* CONFIG_NET_UDP */ #if defined(CONFIG_NET_TCP) if (proto == IPPROTO_TCP) { - net_nbuf_set_appdata(buf, net_nbuf_udp_data(buf) + + net_pkt_set_appdata(buf, net_pkt_udp_data(buf) + tcp_hdr_len(buf)); } else #endif /* CONFIG_NET_TCP */ { - net_nbuf_set_appdata(buf, net_nbuf_ip_data(buf) + - net_nbuf_ip_hdr_len(buf)); + net_pkt_set_appdata(buf, net_pkt_ip_data(buf) + + net_pkt_ip_hdr_len(buf)); } - net_nbuf_set_appdatalen(buf, total_len - - (net_nbuf_appdata(buf) - - net_nbuf_ip_data(buf))); + net_pkt_set_appdatalen(buf, total_len - + (net_pkt_appdata(buf) - + net_pkt_ip_data(buf))); - NET_ASSERT_INFO(net_nbuf_appdatalen(buf) < total_len, + NET_ASSERT_INFO(net_pkt_appdatalen(buf) < total_len, "Wrong appdatalen %u, total %zu", - net_nbuf_appdatalen(buf), total_len); + net_pkt_appdatalen(buf), total_len); } static enum net_verdict packet_received(struct net_conn *conn, @@ -1836,10 +1836,10 @@ static enum net_verdict packet_received(struct net_conn *conn, struct net_context *context = find_context(conn); NET_ASSERT(context); - NET_ASSERT(net_nbuf_iface(buf)); + NET_ASSERT(net_pkt_iface(buf)); - net_context_set_iface(context, net_nbuf_iface(buf)); - net_nbuf_set_context(buf, context); + net_context_set_iface(context, net_pkt_iface(buf)); + net_pkt_set_context(buf, context); /* If there is no callback registered, then we can only drop * the packet. @@ -1855,14 +1855,14 @@ static enum net_verdict packet_received(struct net_conn *conn, } #if defined(CONFIG_NET_TCP) else if (net_context_get_type(context) == SOCK_STREAM) { - if (net_nbuf_appdatalen(buf) == 0) { - net_nbuf_unref(buf); + if (net_pkt_appdatalen(buf) == 0) { + net_pkt_unref(buf); return NET_OK; } } #endif /* CONFIG_NET_TCP */ NET_DBG("Set appdata %p to len %u (total %zu)", - net_nbuf_appdata(buf), net_nbuf_appdatalen(buf), + net_pkt_appdata(buf), net_pkt_appdatalen(buf), net_buf_frags_len(buf)); context->recv_cb(context, buf, 0, user_data); diff --git a/subsys/net/ip/net_core.c b/subsys/net/ip/net_core.c index aa9b75d09..8a9eacdd6 100644 --- a/subsys/net/ip/net_core.c +++ b/subsys/net/ip/net_core.c @@ -26,7 +26,7 @@ #include <net/net_if.h> #include <net/net_mgmt.h> #include <net/arp.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_core.h> #include <net/dns_resolve.h> @@ -75,7 +75,7 @@ static inline enum net_verdict process_data(struct net_buf *buf, * an IPv6 packet, then do not pass it to L2 as the packet does * not have link layer headers in it. */ - if (net_nbuf_ipv6_fragment_start(buf)) { + if (net_pkt_ipv6_fragment_start(buf)) { locally_routed = true; } #endif @@ -95,7 +95,7 @@ static inline enum net_verdict process_data(struct net_buf *buf, } if (!is_loopback && !locally_routed) { - ret = net_if_recv_data(net_nbuf_iface(buf), buf); + ret = net_if_recv_data(net_pkt_iface(buf), buf); if (ret != NET_CONTINUE) { if (ret == NET_DROP) { NET_DBG("Buffer %p discarded by L2", buf); @@ -111,13 +111,13 @@ static inline enum net_verdict process_data(struct net_buf *buf, #if defined(CONFIG_NET_IPV6) case 0x60: net_stats_update_ipv6_recv(); - net_nbuf_set_family(buf, PF_INET6); + net_pkt_set_family(buf, PF_INET6); return net_ipv6_process_pkt(buf); #endif #if defined(CONFIG_NET_IPV4) case 0x40: net_stats_update_ipv4_recv(); - net_nbuf_set_family(buf, PF_INET); + net_pkt_set_family(buf, PF_INET); return net_ipv4_process_pkt(buf); #endif } @@ -139,7 +139,7 @@ static void processing_data(struct net_buf *buf, bool is_loopback) case NET_DROP: default: NET_DBG("Dropping buf %p", buf); - net_nbuf_unref(buf); + net_pkt_unref(buf); break; } } @@ -182,7 +182,7 @@ static void net_rx_thread(void) processing_data(buf, false); net_print_statistics(); - net_nbuf_print(); + net_pkt_print(); k_yield(); } @@ -205,7 +205,7 @@ static void init_rx_queue(void) static inline int check_ip_addr(struct net_buf *buf) { #if defined(CONFIG_NET_IPV6) - if (net_nbuf_family(buf) == AF_INET6) { + if (net_pkt_family(buf) == AF_INET6) { if (net_ipv6_addr_cmp(&NET_IPV6_BUF(buf)->dst, net_ipv6_unspecified_address())) { NET_DBG("IPv6 dst address missing"); @@ -241,7 +241,7 @@ static inline int check_ip_addr(struct net_buf *buf) #endif /* CONFIG_NET_IPV6 */ #if defined(CONFIG_NET_IPV4) - if (net_nbuf_family(buf) == AF_INET) { + if (net_pkt_family(buf) == AF_INET) { if (net_ipv4_addr_cmp(&NET_IPV4_BUF(buf)->dst, net_ipv4_unspecified_address())) { return -EADDRNOTAVAIL; @@ -295,12 +295,12 @@ int net_send_data(struct net_buf *buf) return -ENODATA; } - if (!net_nbuf_iface(buf)) { + if (!net_pkt_iface(buf)) { return -EINVAL; } #if defined(CONFIG_NET_STATISTICS) - switch (net_nbuf_family(buf)) { + switch (net_pkt_family(buf)) { case AF_INET: net_stats_update_ipv4_sent(); break; @@ -321,7 +321,7 @@ int net_send_data(struct net_buf *buf) return 0; } - if (net_if_send_data(net_nbuf_iface(buf), buf) == NET_DROP) { + if (net_if_send_data(net_pkt_iface(buf), buf) == NET_DROP) { return -EIO; } @@ -345,7 +345,7 @@ int net_recv_data(struct net_if *iface, struct net_buf *buf) NET_DBG("fifo %p iface %p buf %p len %zu", &rx_queue, iface, buf, net_buf_frags_len(buf)); - net_nbuf_set_iface(buf, iface); + net_pkt_set_iface(buf, iface); net_buf_put(&rx_queue, buf); @@ -386,7 +386,7 @@ static int net_init(struct device *unused) net_shell_init(); - net_nbuf_init(); + net_pkt_init(); net_context_init(); diff --git a/subsys/net/ip/net_if.c b/subsys/net/ip/net_if.c index 744a8fe2a..fd2fa4e39 100644 --- a/subsys/net/ip/net_if.c +++ b/subsys/net/ip/net_if.c @@ -14,7 +14,7 @@ #include <sections.h> #include <string.h> #include <net/net_core.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_if.h> #include <net/arp.h> #include <net/net_mgmt.h> @@ -92,9 +92,9 @@ static bool net_if_tx(struct net_if *iface) debug_check_packet(buf); - dst = net_nbuf_ll_dst(buf); - context = net_nbuf_context(buf); - context_token = net_nbuf_token(buf); + dst = net_pkt_ll_dst(buf); + context = net_pkt_context(buf); + context_token = net_pkt_token(buf); if (atomic_test_bit(iface->flags, NET_IF_UP)) { #if defined(CONFIG_NET_STATISTICS) @@ -108,7 +108,7 @@ static bool net_if_tx(struct net_if *iface) } if (status < 0) { - net_nbuf_unref(buf); + net_pkt_unref(buf); } else { net_stats_update_bytes_sent(pkt_len); } @@ -224,9 +224,9 @@ static inline void init_iface(struct net_if *iface) enum net_verdict net_if_send_data(struct net_if *iface, struct net_buf *buf) { - struct net_context *context = net_nbuf_context(buf); - struct net_linkaddr *dst = net_nbuf_ll_dst(buf); - void *token = net_nbuf_token(buf); + struct net_context *context = net_pkt_context(buf); + struct net_linkaddr *dst = net_pkt_ll_dst(buf); + void *token = net_pkt_token(buf); enum net_verdict verdict; int status = -EIO; @@ -244,16 +244,16 @@ enum net_verdict net_if_send_data(struct net_if *iface, struct net_buf *buf) * https://jira.zephyrproject.org/browse/ZEP-1656 */ if (!atomic_test_bit(iface->flags, NET_IF_POINTOPOINT) && - !net_nbuf_ll_src(buf)->addr) { - net_nbuf_ll_src(buf)->addr = net_nbuf_ll_if(buf)->addr; - net_nbuf_ll_src(buf)->len = net_nbuf_ll_if(buf)->len; + !net_pkt_ll_src(buf)->addr) { + net_pkt_ll_src(buf)->addr = net_pkt_ll_if(buf)->addr; + net_pkt_ll_src(buf)->len = net_pkt_ll_if(buf)->len; } #if defined(CONFIG_NET_IPV6) /* If the ll dst address is not set check if it is present in the nbr * cache. */ - if (net_nbuf_family(buf) == AF_INET6) { + if (net_pkt_family(buf) == AF_INET6) { buf = net_ipv6_prepare_for_send(buf); if (!buf) { verdict = NET_CONTINUE; diff --git a/subsys/net/ip/nbuf.c b/subsys/net/ip/net_pkt.c index 9c14dbb2a..a0e7e7c8f 100644 --- a/subsys/net/ip/nbuf.c +++ b/subsys/net/ip/net_pkt.c @@ -1,7 +1,7 @@ /** @file - @brief Network buffers for IP stack + @brief Network packet buffers for IP stack - Network data is passed between components using nbuf. + Network data is passed between components using net_pkt. */ /* @@ -10,8 +10,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#if defined(CONFIG_NET_DEBUG_NET_BUF) -#define SYS_LOG_DOMAIN "net/nbuf" +#if defined(CONFIG_NET_DEBUG_NET_PKT) +#define SYS_LOG_DOMAIN "net/net_pkt" #define NET_LOG_ENABLED 1 #endif @@ -26,17 +26,17 @@ #include <net/net_core.h> #include <net/net_ip.h> #include <net/buf.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include "net_private.h" /* Available (free) buffers queue */ -#define NBUF_RX_COUNT CONFIG_NET_NBUF_RX_COUNT -#define NBUF_TX_COUNT CONFIG_NET_NBUF_TX_COUNT -#define NBUF_RX_DATA_COUNT CONFIG_NET_NBUF_RX_DATA_COUNT -#define NBUF_TX_DATA_COUNT CONFIG_NET_NBUF_TX_DATA_COUNT -#define NBUF_DATA_LEN CONFIG_NET_NBUF_DATA_SIZE -#define NBUF_USER_DATA_LEN CONFIG_NET_NBUF_USER_DATA_SIZE +#define NET_PKT_RX_COUNT CONFIG_NET_PKT_RX_COUNT +#define NET_PKT_TX_COUNT CONFIG_NET_PKT_TX_COUNT +#define NET_BUF_RX_COUNT CONFIG_NET_BUF_RX_COUNT +#define NET_BUF_TX_COUNT CONFIG_NET_BUF_TX_COUNT +#define NET_BUF_DATA_LEN CONFIG_NET_BUF_DATA_SIZE +#define NET_BUF_USER_DATA_LEN CONFIG_NET_BUF_USER_DATA_SIZE #if defined(CONFIG_NET_TCP) #define APP_PROTO_LEN NET_TCPH_LEN @@ -64,7 +64,7 @@ * fragment. This makes possible to cast a protocol header * struct into memory area. */ -#if NBUF_DATA_LEN < (IP_PROTO_LEN + APP_PROTO_LEN) +#if NET_BUF_DATA_LEN < (IP_PROTO_LEN + APP_PROTO_LEN) #if defined(STRING2) #undef STRING2 #endif @@ -73,24 +73,24 @@ #endif #define STRING2(x) #x #define STRING(x) STRING2(x) -#pragma message "Data len " STRING(NBUF_DATA_LEN) +#pragma message "Data len " STRING(NET_BUF_DATA_LEN) #pragma message "Minimum len " STRING(IP_PROTO_LEN + APP_PROTO_LEN) #error "Too small net_buf fragment size" #endif -NET_BUF_POOL_DEFINE(rx_bufs, NBUF_RX_COUNT, 0, sizeof(struct net_nbuf), +NET_BUF_POOL_DEFINE(rx_pkts, NET_PKT_RX_COUNT, 0, sizeof(struct net_pkt), NULL); -NET_BUF_POOL_DEFINE(tx_bufs, NBUF_TX_COUNT, 0, sizeof(struct net_nbuf), +NET_BUF_POOL_DEFINE(tx_pkts, NET_PKT_TX_COUNT, 0, sizeof(struct net_pkt), NULL); /* The data fragment pool is for storing network data. */ -NET_BUF_POOL_DEFINE(data_rx_bufs, NBUF_RX_DATA_COUNT, NBUF_DATA_LEN, - NBUF_USER_DATA_LEN, NULL); +NET_BUF_POOL_DEFINE(rx_bufs, NET_BUF_RX_COUNT, NET_BUF_DATA_LEN, + NET_BUF_USER_DATA_LEN, NULL); -NET_BUF_POOL_DEFINE(data_tx_bufs, NBUF_TX_DATA_COUNT, NBUF_DATA_LEN, - NBUF_USER_DATA_LEN, NULL); +NET_BUF_POOL_DEFINE(tx_bufs, NET_BUF_TX_COUNT, NET_BUF_DATA_LEN, + NET_BUF_USER_DATA_LEN, NULL); -#if defined(CONFIG_NET_DEBUG_NET_BUF) +#if defined(CONFIG_NET_DEBUG_NET_PKT) #define NET_BUF_CHECK_IF_IN_USE(buf, ref) \ do { \ @@ -108,17 +108,17 @@ NET_BUF_POOL_DEFINE(data_tx_bufs, NBUF_TX_DATA_COUNT, NBUF_DATA_LEN, } \ } while (0) -#else /* CONFIG_NET_DEBUG_NET_BUF */ +#else /* CONFIG_NET_DEBUG_NET_PKT */ #define NET_BUF_CHECK_IF_IN_USE(buf, ref) #define NET_BUF_CHECK_IF_NOT_IN_USE(buf, ref) -#endif /* CONFIG_NET_DEBUG_NET_BUF */ +#endif /* CONFIG_NET_DEBUG_NET_PKT */ static inline bool is_data_pool(struct net_buf_pool *pool) { /* The user data can only be found in TX/RX pool and it - * is always the size of struct net_nbuf. + * is always the size of struct net_pkt. */ - if (pool->user_data_size != sizeof(struct net_nbuf)) { + if (pool->user_data_size != sizeof(struct net_pkt)) { return true; } @@ -130,8 +130,8 @@ static inline bool is_from_data_pool(struct net_buf *buf) return is_data_pool(buf->pool); } -#if defined(CONFIG_NET_DEBUG_NET_BUF) -struct nbuf_alloc { +#if defined(CONFIG_NET_DEBUG_NET_PKT) +struct net_pkt_alloc { struct net_buf *buf; const char *func_alloc; const char *func_free; @@ -140,27 +140,27 @@ struct nbuf_alloc { uint8_t in_use; }; -#define MAX_NBUF_ALLOCS (NBUF_RX_COUNT + NBUF_TX_COUNT + \ - NBUF_RX_DATA_COUNT + NBUF_TX_DATA_COUNT + \ - CONFIG_NET_DEBUG_NET_BUF_EXTERNALS) +#define MAX_NET_PKT_ALLOCS (NET_PKT_RX_COUNT + NET_PKT_TX_COUNT + \ + NET_BUF_RX_COUNT + NET_BUF_TX_COUNT + \ + CONFIG_NET_DEBUG_NET_PKT_EXTERNALS) -static struct nbuf_alloc nbuf_allocs[MAX_NBUF_ALLOCS]; +static struct net_pkt_alloc net_pkt_allocs[MAX_NET_PKT_ALLOCS]; -static bool nbuf_alloc_add(struct net_buf *buf, +static bool net_pkt_alloc_add(struct net_buf *buf, const char *func, int line) { int i; - for (i = 0; i < MAX_NBUF_ALLOCS; i++) { - if (nbuf_allocs[i].in_use) { + for (i = 0; i < MAX_NET_PKT_ALLOCS; i++) { + if (net_pkt_allocs[i].in_use) { continue; } - nbuf_allocs[i].in_use = true; - nbuf_allocs[i].buf = buf; - nbuf_allocs[i].func_alloc = func; - nbuf_allocs[i].line_alloc = line; + net_pkt_allocs[i].in_use = true; + net_pkt_allocs[i].buf = buf; + net_pkt_allocs[i].func_alloc = func; + net_pkt_allocs[i].line_alloc = line; return true; } @@ -168,17 +168,17 @@ static bool nbuf_alloc_add(struct net_buf *buf, return false; } -static bool nbuf_alloc_del(struct net_buf *buf, +static bool net_pkt_alloc_del(struct net_buf *buf, const char *func, int line) { int i; - for (i = 0; i < MAX_NBUF_ALLOCS; i++) { - if (nbuf_allocs[i].in_use && nbuf_allocs[i].buf == buf) { - nbuf_allocs[i].func_free = func; - nbuf_allocs[i].line_free = line; - nbuf_allocs[i].in_use = false; + for (i = 0; i < MAX_NET_PKT_ALLOCS; i++) { + if (net_pkt_allocs[i].in_use && net_pkt_allocs[i].buf == buf) { + net_pkt_allocs[i].func_free = func; + net_pkt_allocs[i].line_free = line; + net_pkt_allocs[i].in_use = false; return true; } @@ -187,16 +187,16 @@ static bool nbuf_alloc_del(struct net_buf *buf, return false; } -static bool nbuf_alloc_find(struct net_buf *buf, +static bool net_pkt_alloc_find(struct net_buf *buf, const char **func_free, int *line_free) { int i; - for (i = 0; i < MAX_NBUF_ALLOCS; i++) { - if (!nbuf_allocs[i].in_use && nbuf_allocs[i].buf == buf) { - *func_free = nbuf_allocs[i].func_free; - *line_free = nbuf_allocs[i].line_free; + for (i = 0; i < MAX_NET_PKT_ALLOCS; i++) { + if (!net_pkt_allocs[i].in_use && net_pkt_allocs[i].buf == buf) { + *func_free = net_pkt_allocs[i].func_free; + *line_free = net_pkt_allocs[i].line_free; return true; } @@ -205,44 +205,44 @@ static bool nbuf_alloc_find(struct net_buf *buf, return false; } -void net_nbuf_allocs_foreach(net_nbuf_allocs_cb_t cb, void *user_data) +void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb, void *user_data) { int i; - for (i = 0; i < MAX_NBUF_ALLOCS; i++) { - if (nbuf_allocs[i].in_use) { - cb(nbuf_allocs[i].buf, - nbuf_allocs[i].func_alloc, - nbuf_allocs[i].line_alloc, - nbuf_allocs[i].func_free, - nbuf_allocs[i].line_free, - nbuf_allocs[i].in_use, + for (i = 0; i < MAX_NET_PKT_ALLOCS; i++) { + if (net_pkt_allocs[i].in_use) { + cb(net_pkt_allocs[i].buf, + net_pkt_allocs[i].func_alloc, + net_pkt_allocs[i].line_alloc, + net_pkt_allocs[i].func_free, + net_pkt_allocs[i].line_free, + net_pkt_allocs[i].in_use, user_data); } } - for (i = 0; i < MAX_NBUF_ALLOCS; i++) { - if (!nbuf_allocs[i].in_use) { - cb(nbuf_allocs[i].buf, - nbuf_allocs[i].func_alloc, - nbuf_allocs[i].line_alloc, - nbuf_allocs[i].func_free, - nbuf_allocs[i].line_free, - nbuf_allocs[i].in_use, + for (i = 0; i < MAX_NET_PKT_ALLOCS; i++) { + if (!net_pkt_allocs[i].in_use) { + cb(net_pkt_allocs[i].buf, + net_pkt_allocs[i].func_alloc, + net_pkt_allocs[i].line_alloc, + net_pkt_allocs[i].func_free, + net_pkt_allocs[i].line_free, + net_pkt_allocs[i].in_use, user_data); } } } -const char *net_nbuf_pool2str(struct net_buf_pool *pool) +const char *net_pkt_pool2str(struct net_buf_pool *pool) { - if (pool == &rx_bufs) { + if (pool == &rx_pkts) { return "RX"; - } else if (pool == &tx_bufs) { + } else if (pool == &tx_pkts) { return "TX"; - } else if (pool == &data_rx_bufs) { + } else if (pool == &rx_bufs) { return "RDATA"; - } else if (pool == &data_tx_bufs) { + } else if (pool == &tx_bufs) { return "TDATA"; } else if (is_data_pool(pool)) { return "EDATA"; @@ -257,7 +257,7 @@ static inline int16_t get_frees(struct net_buf_pool *pool) } #endif -#if defined(CONFIG_NET_CONTEXT_NBUF_POOL) +#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL) static inline struct net_buf_pool *get_tx_pool(struct net_context *context) { if (context->tx_pool) { @@ -278,25 +278,25 @@ static inline struct net_buf_pool *get_data_pool(struct net_context *context) #else #define get_tx_pool(context) NULL #define get_data_pool(context) NULL -#endif /* CONFIG_NET_CONTEXT_NBUF_POOL */ +#endif /* CONFIG_NET_CONTEXT_PKT_POOL */ static inline bool is_external_pool(struct net_buf_pool *pool) { - if (pool != &rx_bufs && pool != &tx_bufs && - pool != &data_rx_bufs && pool != &data_tx_bufs) { + if (pool != &rx_pkts && pool != &tx_pkts && + pool != &rx_bufs && pool != &tx_bufs) { return true; } return false; } -#if defined(CONFIG_NET_DEBUG_NET_BUF) +#if defined(CONFIG_NET_DEBUG_NET_PKT) static inline const char *pool2str(struct net_buf_pool *pool) { - return net_nbuf_pool2str(pool); + return net_pkt_pool2str(pool); } -void net_nbuf_print_frags(struct net_buf *buf) +void net_pkt_print_frags(struct net_buf *buf) { struct net_buf *frag; size_t total = 0; @@ -331,21 +331,21 @@ void net_nbuf_print_frags(struct net_buf *buf) } NET_INFO("Total data size %zu, occupied %d bytes, ll overhead %d, " - "utilization %zu%%", - total, count * frag_size - count * ll_overhead, - count * ll_overhead, (total * 100) / (count * frag_size)); + "utilization %zu%%", + total, count * frag_size - count * ll_overhead, + count * ll_overhead, (total * 100) / (count * frag_size)); } -struct net_buf *net_nbuf_get_reserve_debug(struct net_buf_pool *pool, - uint16_t reserve_head, - int32_t timeout, - const char *caller, - int line) -#else /* CONFIG_NET_DEBUG_NET_BUF */ -struct net_buf *net_nbuf_get_reserve(struct net_buf_pool *pool, - uint16_t reserve_head, - int32_t timeout) -#endif /* CONFIG_NET_DEBUG_NET_BUF */ +struct net_buf *net_pkt_get_reserve_debug(struct net_buf_pool *pool, + uint16_t reserve_head, + int32_t timeout, + const char *caller, + int line) +#else /* CONFIG_NET_DEBUG_NET_PKT */ +struct net_buf *net_pkt_get_reserve(struct net_buf_pool *pool, + uint16_t reserve_head, + int32_t timeout) +#endif /* CONFIG_NET_DEBUG_NET_PKT */ { struct net_buf *buf; @@ -370,24 +370,24 @@ struct net_buf *net_nbuf_get_reserve(struct net_buf_pool *pool, */ net_buf_reserve(buf, reserve_head); } else { - memset(net_buf_user_data(buf), 0, sizeof(struct net_nbuf)); + memset(net_buf_user_data(buf), 0, sizeof(struct net_pkt)); - net_nbuf_set_ll_reserve(buf, reserve_head); + net_pkt_set_ll_reserve(buf, reserve_head); /* Remember the RX vs. TX so that the fragments can be * allocated from correct DATA pool. */ - if (pool == &rx_bufs) { - net_nbuf_set_dir(buf, NET_RX); + if (pool == &rx_pkts) { + net_pkt_set_dir(buf, NET_RX); } } NET_BUF_CHECK_IF_NOT_IN_USE(buf, buf->ref + 1); -#if defined(CONFIG_NET_DEBUG_NET_BUF) - nbuf_alloc_add(buf, caller, line); +#if defined(CONFIG_NET_DEBUG_NET_PKT) + net_pkt_alloc_add(buf, caller, line); - NET_DBG("%s (%s) [%d] buf %p reserve %u ref %d (%s():%d)", + NET_DBG("%s (%s) [%d] pkt %p reserve %u ref %d (%s():%d)", pool2str(pool), pool->name, get_frees(pool), buf, reserve_head, buf->ref, caller, line); #endif @@ -398,16 +398,16 @@ struct net_buf *net_nbuf_get_reserve(struct net_buf_pool *pool, /* Get a fragment, try to figure out the pool from where to get * the data. */ -#if defined(CONFIG_NET_DEBUG_NET_BUF) -struct net_buf *net_nbuf_get_frag_debug(struct net_buf *buf, - int32_t timeout, - const char *caller, int line) +#if defined(CONFIG_NET_DEBUG_NET_PKT) +struct net_buf *net_pkt_get_frag_debug(struct net_buf *buf, + int32_t timeout, + const char *caller, int line) #else -struct net_buf *net_nbuf_get_frag(struct net_buf *buf, - int32_t timeout) +struct net_buf *net_pkt_get_frag(struct net_buf *buf, + int32_t timeout) #endif { -#if defined(CONFIG_NET_CONTEXT_NBUF_POOL) +#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL) struct net_context *context; #endif @@ -418,111 +418,111 @@ struct net_buf *net_nbuf_get_frag(struct net_buf *buf, return NULL; } -#if defined(CONFIG_NET_CONTEXT_NBUF_POOL) - context = net_nbuf_context(buf); +#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL) + context = net_pkt_context(buf); if (context && context->data_pool) { -#if defined(CONFIG_NET_DEBUG_NET_BUF) - return net_nbuf_get_reserve_debug(context->data_pool(), - net_nbuf_ll_reserve(buf), - timeout, caller, line); +#if defined(CONFIG_NET_DEBUG_NET_PKT) + return net_pkt_get_reserve_debug(context->data_pool(), + net_pkt_ll_reserve(buf), + timeout, caller, line); #else - return net_nbuf_get_reserve(context->data_pool(), - net_nbuf_ll_reserve(buf), timeout); -#endif /* CONFIG_NET_DEBUG_NET_BUF */ + return net_pkt_get_reserve(context->data_pool(), + net_pkt_ll_reserve(buf), timeout); +#endif /* CONFIG_NET_DEBUG_NET_PKT */ } -#endif /* CONFIG_NET_CONTEXT_NBUF_POOL */ +#endif /* CONFIG_NET_CONTEXT_NET_PKT_POOL */ - if (net_nbuf_dir(buf) == NET_RX) { -#if defined(CONFIG_NET_DEBUG_NET_BUF) - return net_nbuf_get_reserve_rx_data_debug( - net_nbuf_ll_reserve(buf), timeout, caller, line); + if (net_pkt_dir(buf) == NET_RX) { +#if defined(CONFIG_NET_DEBUG_NET_PKT) + return net_pkt_get_reserve_rx_data_debug( + net_pkt_ll_reserve(buf), timeout, caller, line); #else - return net_nbuf_get_reserve_rx_data(net_nbuf_ll_reserve(buf), - timeout); + return net_pkt_get_reserve_rx_data(net_pkt_ll_reserve(buf), + timeout); #endif } -#if defined(CONFIG_NET_DEBUG_NET_BUF) - return net_nbuf_get_reserve_tx_data_debug(net_nbuf_ll_reserve(buf), - timeout, caller, line); +#if defined(CONFIG_NET_DEBUG_NET_PKT) + return net_pkt_get_reserve_tx_data_debug(net_pkt_ll_reserve(buf), + timeout, caller, line); #else - return net_nbuf_get_reserve_tx_data(net_nbuf_ll_reserve(buf), - timeout); + return net_pkt_get_reserve_tx_data(net_pkt_ll_reserve(buf), + timeout); #endif } -#if defined(CONFIG_NET_DEBUG_NET_BUF) -struct net_buf *net_nbuf_get_reserve_rx_debug(uint16_t reserve_head, - int32_t timeout, - const char *caller, int line) +#if defined(CONFIG_NET_DEBUG_NET_PKT) +struct net_buf *net_pkt_get_reserve_rx_debug(uint16_t reserve_head, + int32_t timeout, + const char *caller, int line) { - return net_nbuf_get_reserve_debug(&rx_bufs, reserve_head, timeout, - caller, line); + return net_pkt_get_reserve_debug(&rx_pkts, reserve_head, timeout, + caller, line); } -struct net_buf *net_nbuf_get_reserve_tx_debug(uint16_t reserve_head, - int32_t timeout, - const char *caller, int line) +struct net_buf *net_pkt_get_reserve_tx_debug(uint16_t reserve_head, + int32_t timeout, + const char *caller, int line) { - return net_nbuf_get_reserve_debug(&tx_bufs, reserve_head, timeout, - caller, line); + return net_pkt_get_reserve_debug(&tx_pkts, reserve_head, timeout, + caller, line); } -struct net_buf *net_nbuf_get_reserve_rx_data_debug(uint16_t reserve_head, - int32_t timeout, - const char *caller, int line) +struct net_buf *net_pkt_get_reserve_rx_data_debug(uint16_t reserve_head, + int32_t timeout, + const char *caller, int line) { - return net_nbuf_get_reserve_debug(&data_rx_bufs, reserve_head, - timeout, caller, line); + return net_pkt_get_reserve_debug(&rx_bufs, reserve_head, + timeout, caller, line); } -struct net_buf *net_nbuf_get_reserve_tx_data_debug(uint16_t reserve_head, - int32_t timeout, - const char *caller, int line) +struct net_buf *net_pkt_get_reserve_tx_data_debug(uint16_t reserve_head, + int32_t timeout, + const char *caller, int line) { - return net_nbuf_get_reserve_debug(&data_tx_bufs, reserve_head, - timeout, caller, line); + return net_pkt_get_reserve_debug(&tx_bufs, reserve_head, + timeout, caller, line); } -#else /* CONFIG_NET_DEBUG_NET_BUF */ +#else /* CONFIG_NET_DEBUG_NET_PKT */ -struct net_buf *net_nbuf_get_reserve_rx(uint16_t reserve_head, - int32_t timeout) +struct net_buf *net_pkt_get_reserve_rx(uint16_t reserve_head, + int32_t timeout) { - return net_nbuf_get_reserve(&rx_bufs, reserve_head, timeout); + return net_pkt_get_reserve(&rx_pkts, reserve_head, timeout); } -struct net_buf *net_nbuf_get_reserve_tx(uint16_t reserve_head, - int32_t timeout) +struct net_buf *net_pkt_get_reserve_tx(uint16_t reserve_head, + int32_t timeout) { - return net_nbuf_get_reserve(&tx_bufs, reserve_head, timeout); + return net_pkt_get_reserve(&tx_pkts, reserve_head, timeout); } -struct net_buf *net_nbuf_get_reserve_rx_data(uint16_t reserve_head, - int32_t timeout) +struct net_buf *net_pkt_get_reserve_rx_data(uint16_t reserve_head, + int32_t timeout) { - return net_nbuf_get_reserve(&data_rx_bufs, reserve_head, timeout); + return net_pkt_get_reserve(&rx_bufs, reserve_head, timeout); } -struct net_buf *net_nbuf_get_reserve_tx_data(uint16_t reserve_head, - int32_t timeout) +struct net_buf *net_pkt_get_reserve_tx_data(uint16_t reserve_head, + int32_t timeout) { - return net_nbuf_get_reserve(&data_tx_bufs, reserve_head, timeout); + return net_pkt_get_reserve(&tx_bufs, reserve_head, timeout); } -#endif /* CONFIG_NET_DEBUG_NET_BUF */ +#endif /* CONFIG_NET_DEBUG_NET_PKT */ -#if defined(CONFIG_NET_DEBUG_NET_BUF) -static struct net_buf *net_nbuf_get_debug(struct net_buf_pool *pool, - struct net_context *context, - int32_t timeout, - const char *caller, int line) +#if defined(CONFIG_NET_DEBUG_NET_PKT) +static struct net_buf *net_pkt_get_debug(struct net_buf_pool *pool, + struct net_context *context, + int32_t timeout, + const char *caller, int line) #else -static struct net_buf *net_nbuf_get(struct net_buf_pool *pool, - struct net_context *context, - int32_t timeout) -#endif /* CONFIG_NET_DEBUG_NET_BUF */ +static struct net_buf *net_pkt_get(struct net_buf_pool *pool, + struct net_context *context, + int32_t timeout) +#endif /* CONFIG_NET_DEBUG_NET_PKT */ { struct in6_addr *addr6 = NULL; struct net_if *iface; @@ -540,69 +540,69 @@ static struct net_buf *net_nbuf_get(struct net_buf_pool *pool, addr6 = &((struct sockaddr_in6 *) &context->remote)->sin6_addr; } -#if defined(CONFIG_NET_DEBUG_NET_BUF) - buf = net_nbuf_get_reserve_debug(pool, - net_if_get_ll_reserve(iface, addr6), - timeout, caller, line); +#if defined(CONFIG_NET_DEBUG_NET_PKT) + buf = net_pkt_get_reserve_debug(pool, + net_if_get_ll_reserve(iface, addr6), + timeout, caller, line); #else - buf = net_nbuf_get_reserve(pool, net_if_get_ll_reserve(iface, addr6), - timeout); + buf = net_pkt_get_reserve(pool, net_if_get_ll_reserve(iface, addr6), + timeout); #endif if (!buf) { return buf; } if (!is_data_pool(pool)) { - net_nbuf_set_context(buf, context); - net_nbuf_set_iface(buf, iface); + net_pkt_set_context(buf, context); + net_pkt_set_iface(buf, iface); if (context) { - net_nbuf_set_family(buf, - net_context_get_family(context)); + net_pkt_set_family(buf, + net_context_get_family(context)); } } return buf; } -#if defined(CONFIG_NET_DEBUG_NET_BUF) -struct net_buf *net_nbuf_get_rx_debug(struct net_context *context, - int32_t timeout, - const char *caller, int line) +#if defined(CONFIG_NET_DEBUG_NET_PKT) +struct net_buf *net_pkt_get_rx_debug(struct net_context *context, + int32_t timeout, + const char *caller, int line) { - return net_nbuf_get_debug(&rx_bufs, context, timeout, caller, line); + return net_pkt_get_debug(&rx_pkts, context, timeout, caller, line); } -struct net_buf *net_nbuf_get_tx_debug(struct net_context *context, - int32_t timeout, - const char *caller, int line) +struct net_buf *net_pkt_get_tx_debug(struct net_context *context, + int32_t timeout, + const char *caller, int line) { struct net_buf_pool *pool = get_tx_pool(context); - return net_nbuf_get_debug(pool ? pool : &tx_bufs, context, - timeout, caller, line); + return net_pkt_get_debug(pool ? pool : &tx_pkts, context, + timeout, caller, line); } -struct net_buf *net_nbuf_get_data_debug(struct net_context *context, - int32_t timeout, - const char *caller, int line) +struct net_buf *net_pkt_get_data_debug(struct net_context *context, + int32_t timeout, + const char *caller, int line) { struct net_buf_pool *pool = get_data_pool(context); - return net_nbuf_get_debug(pool ? pool : &data_tx_bufs, context, - timeout, caller, line); + return net_pkt_get_debug(pool ? pool : &tx_bufs, context, + timeout, caller, line); } -#else /* CONFIG_NET_DEBUG_NET_BUF */ +#else /* CONFIG_NET_DEBUG_NET_PKT */ -struct net_buf *net_nbuf_get_rx(struct net_context *context, int32_t timeout) +struct net_buf *net_pkt_get_rx(struct net_context *context, int32_t timeout) { NET_ASSERT_INFO(context, "RX context not set"); - return net_nbuf_get(&rx_bufs, context, timeout); + return net_pkt_get(&rx_pkts, context, timeout); } -struct net_buf *net_nbuf_get_tx(struct net_context *context, int32_t timeout) +struct net_buf *net_pkt_get_tx(struct net_context *context, int32_t timeout) { struct net_buf_pool *pool; @@ -610,10 +610,10 @@ struct net_buf *net_nbuf_get_tx(struct net_context *context, int32_t timeout) pool = get_tx_pool(context); - return net_nbuf_get(pool ? pool : &tx_bufs, context, timeout); + return net_pkt_get(pool ? pool : &tx_pkts, context, timeout); } -struct net_buf *net_nbuf_get_data(struct net_context *context, int32_t timeout) +struct net_buf *net_pkt_get_data(struct net_context *context, int32_t timeout) { struct net_buf_pool *pool; @@ -624,32 +624,32 @@ struct net_buf *net_nbuf_get_data(struct net_context *context, int32_t timeout) /* The context is not known in RX path so we can only have TX * data here. */ - return net_nbuf_get(pool ? pool : &data_tx_bufs, context, timeout); + return net_pkt_get(pool ? pool : &tx_bufs, context, timeout); } -#endif /* CONFIG_NET_DEBUG_NET_BUF */ +#endif /* CONFIG_NET_DEBUG_NET_PKT */ -#if defined(CONFIG_NET_DEBUG_NET_BUF) -void net_nbuf_unref_debug(struct net_buf *buf, const char *caller, int line) +#if defined(CONFIG_NET_DEBUG_NET_PKT) +void net_pkt_unref_debug(struct net_buf *buf, const char *caller, int line) { struct net_buf *frag; #else -void net_nbuf_unref(struct net_buf *buf) +void net_pkt_unref(struct net_buf *buf) { -#endif /* CONFIG_NET_DEBUG_NET_BUF */ +#endif /* CONFIG_NET_DEBUG_NET_PKT */ if (!buf) { NET_DBG("*** ERROR *** buf %p (%s():%d)", buf, caller, line); return; } if (!buf->ref) { -#if defined(CONFIG_NET_DEBUG_NET_BUF) +#if defined(CONFIG_NET_DEBUG_NET_PKT) const char *func_freed; int line_freed; - if (nbuf_alloc_find(buf, &func_freed, &line_freed)) { + if (net_pkt_alloc_find(buf, &func_freed, &line_freed)) { NET_DBG("*** ERROR *** buf %p is freed already by " "%s():%d (%s():%d)", buf, func_freed, line_freed, caller, line); @@ -661,7 +661,7 @@ void net_nbuf_unref(struct net_buf *buf) return; } -#if defined(CONFIG_NET_DEBUG_NET_BUF) +#if defined(CONFIG_NET_DEBUG_NET_PKT) NET_DBG("%s (%s) [%d] buf %p ref %d frags %p (%s():%d)", pool2str(buf->pool), buf->pool->name, get_frees(buf->pool), buf, buf->ref - 1, buf->frags, caller, line); @@ -681,7 +681,8 @@ void net_nbuf_unref(struct net_buf *buf) const char *func_freed; int line_freed; - if (nbuf_alloc_find(frag, &func_freed, &line_freed)) { + if (net_pkt_alloc_find(frag, + &func_freed, &line_freed)) { NET_DBG("*** ERROR *** frag %p is freed " "already by %s():%d (%s():%d)", frag, func_freed, line_freed, @@ -693,32 +694,32 @@ void net_nbuf_unref(struct net_buf *buf) } } - nbuf_alloc_del(frag, caller, line); + net_pkt_alloc_del(frag, caller, line); frag = frag->frags; } - nbuf_alloc_del(buf, caller, line); + net_pkt_alloc_del(buf, caller, line); done: -#endif /* CONFIG_NET_DEBUG_NET_BUF */ +#endif /* CONFIG_NET_DEBUG_NET_PKT */ net_buf_unref(buf); } -#if defined(CONFIG_NET_DEBUG_NET_BUF) -struct net_buf *net_nbuf_ref_debug(struct net_buf *buf, const char *caller, - int line) +#if defined(CONFIG_NET_DEBUG_NET_PKT) +struct net_buf *net_pkt_ref_debug(struct net_buf *buf, const char *caller, + int line) #else -struct net_buf *net_nbuf_ref(struct net_buf *buf) -#endif /* CONFIG_NET_DEBUG_NET_BUF */ +struct net_buf *net_pkt_ref(struct net_buf *buf) +#endif /* CONFIG_NET_DEBUG_NET_PKT */ { if (!buf) { NET_DBG("*** ERROR *** buf %p (%s():%d)", buf, caller, line); return NULL; } -#if defined(CONFIG_NET_DEBUG_NET_BUF) +#if defined(CONFIG_NET_DEBUG_NET_PKT) NET_DBG("%s (%s) [%d] buf %p ref %d (%s():%d)", pool2str(buf->pool), buf->pool->name, get_frees(buf->pool), buf, buf->ref + 1, caller, line); @@ -727,26 +728,26 @@ struct net_buf *net_nbuf_ref(struct net_buf *buf) return net_buf_ref(buf); } -#if defined(CONFIG_NET_DEBUG_NET_BUF) -struct net_buf *net_nbuf_frag_del_debug(struct net_buf *parent, - struct net_buf *frag, - const char *caller, int line) +#if defined(CONFIG_NET_DEBUG_NET_PKT) +struct net_buf *net_pkt_frag_del_debug(struct net_buf *parent, + struct net_buf *frag, + const char *caller, int line) #else -struct net_buf *net_nbuf_frag_del(struct net_buf *parent, - struct net_buf *frag) +struct net_buf *net_pkt_frag_del(struct net_buf *parent, + struct net_buf *frag) #endif { -#if defined(CONFIG_NET_DEBUG_NET_BUF) +#if defined(CONFIG_NET_DEBUG_NET_PKT) if (frag->ref == 1) { - nbuf_alloc_del(frag, caller, line); + net_pkt_alloc_del(frag, caller, line); } #endif return net_buf_frag_del(parent, frag); } -struct net_buf *net_nbuf_copy(struct net_buf *buf, size_t amount, - size_t reserve, int32_t timeout) +struct net_buf *net_pkt_copy(struct net_buf *buf, size_t amount, + size_t reserve, int32_t timeout) { struct net_buf *frag, *first, *orig; uint8_t *orig_data; @@ -759,7 +760,7 @@ struct net_buf *net_nbuf_copy(struct net_buf *buf, size_t amount, orig = buf->frags; - frag = net_nbuf_get_frag(buf, timeout); + frag = net_pkt_get_frag(buf, timeout); if (!frag) { return NULL; } @@ -767,7 +768,7 @@ struct net_buf *net_nbuf_copy(struct net_buf *buf, size_t amount, if (reserve > net_buf_tailroom(frag)) { NET_ERR("Reserve %zu is too long, max is %zu", reserve, net_buf_tailroom(frag)); - net_nbuf_unref(frag); + net_pkt_unref(frag); return NULL; } @@ -813,9 +814,9 @@ struct net_buf *net_nbuf_copy(struct net_buf *buf, size_t amount, * We must allocate a new one. */ struct net_buf *new_frag = - net_nbuf_get_frag(buf, timeout); + net_pkt_get_frag(buf, timeout); if (!new_frag) { - net_nbuf_unref(first); + net_pkt_unref(first); return NULL; } @@ -848,8 +849,8 @@ struct net_buf *net_nbuf_copy(struct net_buf *buf, size_t amount, return first; } -int net_nbuf_linear_copy(struct net_buf *dst, struct net_buf *src, - uint16_t offset, uint16_t len) +int net_pkt_linear_copy(struct net_buf *dst, struct net_buf *src, + uint16_t offset, uint16_t len) { uint16_t to_copy; uint16_t copied; @@ -887,7 +888,7 @@ int net_nbuf_linear_copy(struct net_buf *dst, struct net_buf *src, return 0; } -bool net_nbuf_is_compact(struct net_buf *buf) +bool net_pkt_is_compact(struct net_buf *buf) { struct net_buf *last; size_t total = 0, calc; @@ -927,7 +928,7 @@ bool net_nbuf_is_compact(struct net_buf *buf) return false; } -bool net_nbuf_compact(struct net_buf *buf) +bool net_pkt_compact(struct net_buf *buf) { struct net_buf *prev; @@ -969,7 +970,7 @@ bool net_nbuf_compact(struct net_buf *buf) * not have copied all data. Remove next * fragment as there is no data in it any more. */ - net_nbuf_frag_del(buf, buf->frags); + net_pkt_frag_del(buf, buf->frags); /* Then check next fragment */ continue; @@ -979,7 +980,7 @@ bool net_nbuf_compact(struct net_buf *buf) /* Remove the last fragment because there is no * data in it. */ - net_nbuf_frag_del(prev, buf); + net_pkt_frag_del(prev, buf); break; } @@ -992,7 +993,7 @@ bool net_nbuf_compact(struct net_buf *buf) return true; } -struct net_buf *net_nbuf_pull(struct net_buf *buf, size_t amount) +struct net_buf *net_pkt_pull(struct net_buf *buf, size_t amount) { struct net_buf *first; ssize_t count = amount; @@ -1025,9 +1026,9 @@ struct net_buf *net_nbuf_pull(struct net_buf *buf, size_t amount) tmp.frags = buf; first = buf->frags; - net_nbuf_frag_del(&tmp, buf); + net_pkt_frag_del(&tmp, buf); } else { - net_nbuf_frag_del(first, buf); + net_pkt_frag_del(first, buf); } return first; @@ -1040,10 +1041,10 @@ struct net_buf *net_nbuf_pull(struct net_buf *buf, size_t amount) tmp.frags = buf; first = buf->frags; - net_nbuf_frag_del(&tmp, buf); + net_pkt_frag_del(&tmp, buf); buf = first; } else { - net_nbuf_frag_del(first, buf); + net_pkt_frag_del(first, buf); buf = first->frags; } } @@ -1059,9 +1060,9 @@ struct net_buf *net_nbuf_pull(struct net_buf *buf, size_t amount) * the data in current fragment then create new fragment and add it to * the buffer. It assumes that the buffer has at least one fragment. */ -static inline bool net_nbuf_append_bytes(struct net_buf *buf, - const uint8_t *value, - uint16_t len, int32_t timeout) +static inline bool net_pkt_append_bytes(struct net_buf *buf, + const uint8_t *value, + uint16_t len, int32_t timeout) { struct net_buf *frag = net_buf_frag_last(buf); @@ -1077,7 +1078,7 @@ static inline bool net_nbuf_append_bytes(struct net_buf *buf, return true; } - frag = net_nbuf_get_frag(buf, timeout); + frag = net_pkt_get_frag(buf, timeout); if (!frag) { return false; } @@ -1088,8 +1089,8 @@ static inline bool net_nbuf_append_bytes(struct net_buf *buf, return false; } -bool net_nbuf_append(struct net_buf *buf, uint16_t len, const uint8_t *data, - int32_t timeout) +bool net_pkt_append(struct net_buf *buf, uint16_t len, const uint8_t *data, + int32_t timeout) { struct net_buf *frag; @@ -1099,7 +1100,7 @@ bool net_nbuf_append(struct net_buf *buf, uint16_t len, const uint8_t *data, if (is_from_data_pool(buf)) { /* The buf needs to be a net_buf that has user data - * part. Otherwise we cannot use the net_nbuf_ll_reserve() + * part. Otherwise we cannot use the net_pkt_ll_reserve() * function to figure out the reserve amount. */ NET_DBG("Buffer %p is a data fragment", buf); @@ -1107,7 +1108,7 @@ bool net_nbuf_append(struct net_buf *buf, uint16_t len, const uint8_t *data, } if (!buf->frags) { - frag = net_nbuf_get_frag(buf, timeout); + frag = net_pkt_get_frag(buf, timeout); if (!frag) { return false; } @@ -1115,17 +1116,17 @@ bool net_nbuf_append(struct net_buf *buf, uint16_t len, const uint8_t *data, net_buf_frag_add(buf, frag); } - return net_nbuf_append_bytes(buf, data, len, timeout); + return net_pkt_append_bytes(buf, data, len, timeout); } /* Helper routine to retrieve single byte from fragment and move * offset. If required byte is last byte in framgent then return * next fragment and set offset = 0. */ -static inline struct net_buf *net_nbuf_read_byte(struct net_buf *buf, - uint16_t offset, - uint16_t *pos, - uint8_t *data) +static inline struct net_buf *net_pkt_read_byte(struct net_buf *buf, + uint16_t offset, + uint16_t *pos, + uint8_t *data) { if (data) { *data = buf->data[offset]; @@ -1142,7 +1143,7 @@ static inline struct net_buf *net_nbuf_read_byte(struct net_buf *buf, return buf; } -/* Helper function to adjust offset in net_nbuf_read() call +/* Helper function to adjust offset in net_pkt_read() call * if given offset is more than current fragment length. */ static inline struct net_buf *adjust_offset(struct net_buf *buf, @@ -1173,8 +1174,8 @@ static inline struct net_buf *adjust_offset(struct net_buf *buf, return NULL; } -struct net_buf *net_nbuf_read(struct net_buf *buf, uint16_t offset, - uint16_t *pos, uint16_t len, uint8_t *data) +struct net_buf *net_pkt_read(struct net_buf *buf, uint16_t offset, + uint16_t *pos, uint16_t len, uint8_t *data) { uint16_t copy = 0; @@ -1185,9 +1186,9 @@ struct net_buf *net_nbuf_read(struct net_buf *buf, uint16_t offset, while (len-- > 0 && buf) { if (data) { - buf = net_nbuf_read_byte(buf, *pos, pos, data + copy++); + buf = net_pkt_read_byte(buf, *pos, pos, data + copy++); } else { - buf = net_nbuf_read_byte(buf, *pos, pos, NULL); + buf = net_pkt_read_byte(buf, *pos, pos, NULL); } /* Error: Still reamining length to be read, but no data. */ @@ -1205,26 +1206,26 @@ error: return NULL; } -struct net_buf *net_nbuf_read_be16(struct net_buf *buf, uint16_t offset, - uint16_t *pos, uint16_t *value) +struct net_buf *net_pkt_read_be16(struct net_buf *buf, uint16_t offset, + uint16_t *pos, uint16_t *value) { struct net_buf *retbuf; uint8_t v16[2]; - retbuf = net_nbuf_read(buf, offset, pos, sizeof(uint16_t), v16); + retbuf = net_pkt_read(buf, offset, pos, sizeof(uint16_t), v16); *value = v16[0] << 8 | v16[1]; return retbuf; } -struct net_buf *net_nbuf_read_be32(struct net_buf *buf, uint16_t offset, - uint16_t *pos, uint32_t *value) +struct net_buf *net_pkt_read_be32(struct net_buf *buf, uint16_t offset, + uint16_t *pos, uint32_t *value) { struct net_buf *retbuf; uint8_t v32[4]; - retbuf = net_nbuf_read(buf, offset, pos, sizeof(uint32_t), v32); + retbuf = net_pkt_read(buf, offset, pos, sizeof(uint32_t), v32); *value = v32[0] << 24 | v32[1] << 16 | v32[2] << 8 | v32[3]; @@ -1241,7 +1242,7 @@ static inline struct net_buf *check_and_create_data(struct net_buf *buf, return data; } - frag = net_nbuf_get_frag(buf, timeout); + frag = net_pkt_get_frag(buf, timeout); if (!frag) { return NULL; } @@ -1337,10 +1338,10 @@ static inline struct net_buf *adjust_write_offset(struct net_buf *buf, return NULL; } -struct net_buf *net_nbuf_write(struct net_buf *buf, struct net_buf *frag, - uint16_t offset, uint16_t *pos, - uint16_t len, uint8_t *data, - int32_t timeout) +struct net_buf *net_pkt_write(struct net_buf *buf, struct net_buf *frag, + uint16_t offset, uint16_t *pos, + uint16_t len, uint8_t *data, + int32_t timeout) { if (!buf || is_from_data_pool(buf)) { NET_ERR("Invalid buffer or it is data fragment"); @@ -1380,7 +1381,7 @@ struct net_buf *net_nbuf_write(struct net_buf *buf, struct net_buf *frag, frag = frag->frags; if (!frag) { - frag = net_nbuf_get_frag(buf, timeout); + frag = net_pkt_get_frag(buf, timeout); if (!frag) { goto error; } @@ -1422,7 +1423,7 @@ static inline bool insert_data(struct net_buf *buf, struct net_buf *frag, /* As we are creating temporary buffers to cache, * compact the fragments to save space. */ - net_nbuf_compact(buf->frags); + net_pkt_compact(buf->frags); return true; } @@ -1430,7 +1431,7 @@ static inline bool insert_data(struct net_buf *buf, struct net_buf *frag, data += count; offset = 0; - insert = net_nbuf_get_frag(buf, timeout); + insert = net_pkt_get_frag(buf, timeout); if (!insert) { return false; } @@ -1481,9 +1482,9 @@ static inline struct net_buf *adjust_insert_offset(struct net_buf *buf, return NULL; } -bool net_nbuf_insert(struct net_buf *buf, struct net_buf *frag, - uint16_t offset, uint16_t len, uint8_t *data, - int32_t timeout) +bool net_pkt_insert(struct net_buf *buf, struct net_buf *frag, + uint16_t offset, uint16_t len, uint8_t *data, + int32_t timeout) { struct net_buf *temp = NULL; uint16_t bytes; @@ -1502,7 +1503,7 @@ bool net_nbuf_insert(struct net_buf *buf, struct net_buf *frag, */ bytes = frag->len - offset; if (bytes) { - temp = net_nbuf_get_frag(buf, timeout); + temp = net_pkt_get_frag(buf, timeout); if (!temp) { return false; } @@ -1516,9 +1517,9 @@ bool net_nbuf_insert(struct net_buf *buf, struct net_buf *frag, return insert_data(buf, frag, temp, offset, len, data, timeout); } -int net_nbuf_split(struct net_buf *buf, struct net_buf *orig_frag, - uint16_t len, struct net_buf **fragA, - struct net_buf **fragB, int32_t timeout) +int net_pkt_split(struct net_buf *buf, struct net_buf *orig_frag, + uint16_t len, struct net_buf **fragA, + struct net_buf **fragB, int32_t timeout) { if (!buf || !orig_frag || is_from_data_pool(buf)) { return -EINVAL; @@ -1539,7 +1540,7 @@ int net_nbuf_split(struct net_buf *buf, struct net_buf *orig_frag, } if (len > orig_frag->len) { - *fragA = net_nbuf_get_frag(buf, timeout); + *fragA = net_pkt_get_frag(buf, timeout); if (!*fragA) { return -ENOMEM; } @@ -1551,14 +1552,14 @@ int net_nbuf_split(struct net_buf *buf, struct net_buf *orig_frag, return 0; } - *fragA = net_nbuf_get_frag(buf, timeout); + *fragA = net_pkt_get_frag(buf, timeout); if (!*fragA) { return -ENOMEM; } - *fragB = net_nbuf_get_frag(buf, timeout); + *fragB = net_pkt_get_frag(buf, timeout); if (!*fragB) { - net_nbuf_unref(*fragA); + net_pkt_unref(*fragA); return -ENOMEM; } @@ -1569,43 +1570,43 @@ int net_nbuf_split(struct net_buf *buf, struct net_buf *orig_frag, return 0; } -void net_nbuf_get_info(struct net_buf_pool **rx, - struct net_buf_pool **tx, - struct net_buf_pool **rx_data, - struct net_buf_pool **tx_data) +void net_pkt_get_info(struct net_buf_pool **rx, + struct net_buf_pool **tx, + struct net_buf_pool **rx_data, + struct net_buf_pool **tx_data) { if (rx) { - *rx = &rx_bufs; + *rx = &rx_pkts; } if (tx) { - *tx = &tx_bufs; + *tx = &tx_pkts; } if (rx_data) { - *rx_data = &data_rx_bufs; + *rx_data = &rx_bufs; } if (tx_data) { - *tx_data = &data_tx_bufs; + *tx_data = &tx_bufs; } } -#if defined(CONFIG_NET_DEBUG_NET_BUF) -void net_nbuf_print(void) +#if defined(CONFIG_NET_DEBUG_NET_PKT) +void net_pkt_print(void) { NET_DBG("TX %d RX %d RDATA %d TDATA %d", tx_bufs.avail_count, - rx_bufs.avail_count, data_rx_bufs.avail_count, - data_tx_bufs.avail_count); + rx_bufs.avail_count, rx_bufs.avail_count, + tx_bufs.avail_count); } -#endif /* CONFIG_NET_DEBUG_NET_BUF */ +#endif /* CONFIG_NET_DEBUG_NET_PKT */ -void net_nbuf_init(void) +void net_pkt_init(void) { NET_DBG("Allocating %d RX (%u bytes), %d TX (%u bytes), " "%d RX data (%u bytes) and %d TX data (%u bytes) buffers", + get_frees(&rx_pkts), rx_pkts.pool_size, + get_frees(&tx_pkts), tx_pkts.pool_size, get_frees(&rx_bufs), rx_bufs.pool_size, - get_frees(&tx_bufs), tx_bufs.pool_size, - get_frees(&data_rx_bufs), data_rx_bufs.pool_size, - get_frees(&data_tx_bufs), data_tx_bufs.pool_size); + get_frees(&tx_bufs), tx_bufs.pool_size); } diff --git a/subsys/net/ip/net_private.h b/subsys/net/ip/net_private.h index a75781189..423c7da6d 100644 --- a/subsys/net/ip/net_private.h +++ b/subsys/net/ip/net_private.h @@ -13,9 +13,9 @@ #include <errno.h> #include <misc/printk.h> #include <net/net_context.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> -extern void net_nbuf_init(void); +extern void net_pkt_init(void); extern void net_if_init(struct k_sem *startup_sync); extern void net_if_post_init(void); extern void net_context_init(void); @@ -148,7 +148,7 @@ static inline void net_hexdump_frags(const char *str, struct net_buf *buf) struct net_buf *frag = buf->frags; while (frag) { - net_hexdump(str, frag->data, net_nbuf_get_len(frag)); + net_hexdump(str, frag->data, net_pkt_get_len(frag)); frag = frag->frags; } } diff --git a/subsys/net/ip/net_shell.c b/subsys/net/ip/net_shell.c index 2b854cbac..61e482b89 100644 --- a/subsys/net/ip/net_shell.c +++ b/subsys/net/ip/net_shell.c @@ -508,7 +508,7 @@ static void ipv6_frag_cb(struct net_ipv6_reassembly *reass, } #endif /* CONFIG_NET_IPV6_FRAGMENT */ -#if defined(CONFIG_NET_DEBUG_NET_BUF) +#if defined(CONFIG_NET_DEBUG_NET_PKT) static void allocs_cb(struct net_buf *buf, const char *func_alloc, int line_alloc, @@ -532,16 +532,16 @@ static void allocs_cb(struct net_buf *buf, if (func_alloc) { if (in_use) { printk("%p/%d\t%5s\t%5s\t%s():%d\n", buf, buf->ref, - str, net_nbuf_pool2str(buf->pool), func_alloc, + str, net_pkt_pool2str(buf->pool), func_alloc, line_alloc); } else { printk("%p\t%5s\t%5s\t%s():%d -> %s():%d\n", buf, - str, net_nbuf_pool2str(buf->pool), func_alloc, + str, net_pkt_pool2str(buf->pool), func_alloc, line_alloc, func_free, line_free); } } } -#endif /* CONFIG_NET_DEBUG_NET_BUF */ +#endif /* CONFIG_NET_DEBUG_NET_PKT */ /* Put the actual shell commands after this */ @@ -550,13 +550,13 @@ static int shell_cmd_allocs(int argc, char *argv[]) ARG_UNUSED(argc); ARG_UNUSED(argv); -#if defined(CONFIG_NET_DEBUG_NET_BUF) +#if defined(CONFIG_NET_DEBUG_NET_PKT) printk("Network buffer allocations\n\n"); printk("net_buf\t\tStatus\tPool\tFunction alloc -> freed\n"); - net_nbuf_allocs_foreach(allocs_cb, NULL); + net_pkt_allocs_foreach(allocs_cb, NULL); #else - printk("Enable CONFIG_NET_DEBUG_NET_BUF to see allocations.\n"); -#endif /* CONFIG_NET_DEBUG_NET_BUF */ + printk("Enable CONFIG_NET_DEBUG_NET_PKT to see allocations.\n"); +#endif /* CONFIG_NET_DEBUG_NET_PKT */ return 0; } @@ -810,7 +810,7 @@ struct ctx_info { struct net_buf_pool *data_pools[CONFIG_NET_MAX_CONTEXTS]; }; -#if defined(CONFIG_NET_CONTEXT_NBUF_POOL) +#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL) static bool pool_found_already(struct ctx_info *info, struct net_buf_pool *pool) { @@ -829,7 +829,7 @@ static bool pool_found_already(struct ctx_info *info, static void context_info(struct net_context *context, void *user_data) { -#if defined(CONFIG_NET_CONTEXT_NBUF_POOL) +#if defined(CONFIG_NET_CONTEXT_NET_PKT_POOL) struct ctx_info *info = user_data; struct net_buf_pool *pool; @@ -844,7 +844,7 @@ static void context_info(struct net_context *context, void *user_data) return; } -#if defined(CONFIG_NET_DEBUG_NET_BUF) +#if defined(CONFIG_NET_DEBUG_NET_PKT) printk("ETX (%s)\t%d\t%d\t%d\t%p\n", pool->name, pool->pool_size, pool->buf_count, pool->avail_count, pool); @@ -862,7 +862,7 @@ static void context_info(struct net_context *context, void *user_data) return; } -#if defined(CONFIG_NET_DEBUG_NET_BUF) +#if defined(CONFIG_NET_DEBUG_NET_PKT) printk("EDATA (%s)\t%d\t%d\t%d\t%p\n", pool->name, pool->pool_size, pool->buf_count, pool->avail_count, pool); @@ -874,7 +874,7 @@ static void context_info(struct net_context *context, void *user_data) } info->pos++; -#endif /* CONFIG_NET_CONTEXT_NBUF_POOL */ +#endif /* CONFIG_NET_CONTEXT_NET_PKT_POOL */ } static int shell_cmd_mem(int argc, char *argv[]) @@ -884,13 +884,13 @@ static int shell_cmd_mem(int argc, char *argv[]) ARG_UNUSED(argc); ARG_UNUSED(argv); - net_nbuf_get_info(&rx, &tx, &rx_data, &tx_data); + net_pkt_get_info(&rx, &tx, &rx_data, &tx_data); - printk("Fragment length %d bytes\n", CONFIG_NET_NBUF_DATA_SIZE); + printk("Fragment length %d bytes\n", CONFIG_NET_BUF_DATA_SIZE); printk("Network buffer pools:\n"); -#if defined(CONFIG_NET_DEBUG_NET_BUF) +#if defined(CONFIG_NET_DEBUG_NET_PKT) printk("Name\t\t\tSize\tCount\tAvail\tAddress\n"); printk("RX (%s)\t\t%d\t%d\t%d\t%p\n", @@ -913,9 +913,9 @@ static int shell_cmd_mem(int argc, char *argv[]) printk("TX \t%d\t%p\n", tx->buf_count, tx); printk("RX DATA \t%d\t%p\n", rx_data->buf_count, rx_data); printk("TX DATA \t%d\t%p\n", tx_data->buf_count, tx_data); -#endif /* CONFIG_NET_DEBUG_NET_BUF */ +#endif /* CONFIG_NET_DEBUG_NET_PKT */ - if (IS_ENABLED(CONFIG_NET_CONTEXT_NBUF_POOL)) { + if (IS_ENABLED(CONFIG_NET_CONTEXT_NET_PKT_POOL)) { struct ctx_info info; memset(&info, 0, sizeof(info)); @@ -1482,17 +1482,17 @@ static int shell_cmd_tcp(int argc, char *argv[]) return 0; } - buf = net_nbuf_get_tx(tcp_ctx, TCP_TIMEOUT); + buf = net_pkt_get_tx(tcp_ctx, TCP_TIMEOUT); if (!buf) { printk("Out of bufs, msg cannot be sent.\n"); return 0; } - ret = net_nbuf_append(buf, strlen(argv[arg]), + ret = net_pkt_append(buf, strlen(argv[arg]), argv[arg], TCP_TIMEOUT); if (!ret) { printk("Cannot build msg (out of bufs)\n"); - net_nbuf_unref(buf); + net_pkt_unref(buf); return 0; } @@ -1500,7 +1500,7 @@ static int shell_cmd_tcp(int argc, char *argv[]) NULL, NULL); if (ret < 0) { printk("Cannot send msg (%d)\n", ret); - net_nbuf_unref(buf); + net_pkt_unref(buf); return 0; } diff --git a/subsys/net/ip/route.c b/subsys/net/ip/route.c index c86d4ee27..446ffe808 100644 --- a/subsys/net/ip/route.c +++ b/subsys/net/ip/route.c @@ -19,7 +19,7 @@ #include <zephyr/types.h> #include <misc/slist.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_core.h> #include <net/net_stats.h> #include <net/net_mgmt.h> @@ -721,7 +721,7 @@ int net_route_packet(struct net_buf *buf, struct in6_addr *nexthop) struct net_linkaddr_storage *lladdr; struct net_nbr *nbr; - nbr = net_ipv6_nbr_lookup(net_nbuf_iface(buf), nexthop); + nbr = net_ipv6_nbr_lookup(net_pkt_iface(buf), nexthop); if (!nbr) { NET_DBG("Cannot find %s neighbor.", net_sprint_ipv6_addr(nexthop)); @@ -738,23 +738,23 @@ int net_route_packet(struct net_buf *buf, struct in6_addr *nexthop) /* Sanitycheck: If src and dst ll addresses are going to be same, * then something went wrong in route lookup. */ - if (!memcmp(net_nbuf_ll_src(buf)->addr, lladdr->addr, lladdr->len)) { + if (!memcmp(net_pkt_ll_src(buf)->addr, lladdr->addr, lladdr->len)) { NET_ERR("Src ll and Dst ll are same"); return -EINVAL; } - net_nbuf_set_forwarding(buf, true); + net_pkt_set_forwarding(buf, true); /* Set the destination and source ll address in the packet. * We set the destination address to be the nexthop recipient. */ - net_nbuf_ll_src(buf)->addr = net_nbuf_ll_if(buf)->addr; - net_nbuf_ll_src(buf)->type = net_nbuf_ll_if(buf)->type; - net_nbuf_ll_src(buf)->len = net_nbuf_ll_if(buf)->len; + net_pkt_ll_src(buf)->addr = net_pkt_ll_if(buf)->addr; + net_pkt_ll_src(buf)->type = net_pkt_ll_if(buf)->type; + net_pkt_ll_src(buf)->len = net_pkt_ll_if(buf)->len; - net_nbuf_ll_dst(buf)->addr = lladdr->addr; - net_nbuf_ll_dst(buf)->type = lladdr->type; - net_nbuf_ll_dst(buf)->len = lladdr->len; + net_pkt_ll_dst(buf)->addr = lladdr->addr; + net_pkt_ll_dst(buf)->type = lladdr->type; + net_pkt_ll_dst(buf)->len = lladdr->len; return net_send_data(buf); } diff --git a/subsys/net/ip/rpl-mrhof.c b/subsys/net/ip/rpl-mrhof.c index a1b1c11db..27388aaa1 100644 --- a/subsys/net/ip/rpl-mrhof.c +++ b/subsys/net/ip/rpl-mrhof.c @@ -47,7 +47,6 @@ #include <limits.h> #include <zephyr/types.h> -#include <net/nbuf.h> #include <net/net_core.h> #include <net/net_stats.h> diff --git a/subsys/net/ip/rpl-of0.c b/subsys/net/ip/rpl-of0.c index 9a87a0014..51eb13ad2 100644 --- a/subsys/net/ip/rpl-of0.c +++ b/subsys/net/ip/rpl-of0.c @@ -47,7 +47,6 @@ #include <limits.h> #include <zephyr/types.h> -#include <net/nbuf.h> #include <net/net_core.h> #include <net/net_stats.h> diff --git a/subsys/net/ip/rpl.c b/subsys/net/ip/rpl.c index b809a22ec..7b1133fcd 100644 --- a/subsys/net/ip/rpl.c +++ b/subsys/net/ip/rpl.c @@ -47,7 +47,7 @@ #include <limits.h> #include <zephyr/types.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_core.h> #include "net_private.h" @@ -421,9 +421,9 @@ struct net_route_entry *net_rpl_add_route(struct net_rpl_dag *dag, static inline void setup_icmpv6_hdr(struct net_buf *buf, uint8_t type, uint8_t code) { - net_nbuf_append_u8(buf, type); - net_nbuf_append_u8(buf, code); - net_nbuf_append_be16(buf, 0); /* checksum */ + net_pkt_append_u8(buf, type); + net_pkt_append_u8(buf, code); + net_pkt_append_be16(buf, 0); /* checksum */ } int net_rpl_dio_send(struct net_if *iface, @@ -437,7 +437,7 @@ int net_rpl_dio_send(struct net_if *iface, uint16_t value; int ret; - buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, dst), + buf = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface, dst), K_FOREVER); if (!buf) { return -ENOMEM; @@ -452,88 +452,88 @@ int net_rpl_dio_send(struct net_if *iface, buf = net_ipv6_create_raw(buf, src, dst_addr, iface, IPPROTO_ICMPV6); - net_nbuf_set_iface(buf, iface); + net_pkt_set_iface(buf, iface); setup_icmpv6_hdr(buf, NET_ICMPV6_RPL, NET_RPL_DODAG_INFO_OBJ); - net_nbuf_append_u8(buf, instance->instance_id); - net_nbuf_append_u8(buf, dag->version); - net_nbuf_append_be16(buf, dag->rank); + net_pkt_append_u8(buf, instance->instance_id); + net_pkt_append_u8(buf, dag->version); + net_pkt_append_be16(buf, dag->rank); value = net_rpl_dag_is_grounded(dag) << 8; value |= instance->mop << NET_RPL_DIO_MOP_SHIFT; value |= net_rpl_dag_get_preference(dag) & NET_RPL_DIO_PREFERENCE_MASK; - net_nbuf_append_u8(buf, value); - net_nbuf_append_u8(buf, instance->dtsn); + net_pkt_append_u8(buf, value); + net_pkt_append_u8(buf, instance->dtsn); if (!dst) { net_rpl_lollipop_increment(&instance->dtsn); } /* Flags and reserved are set to 0 */ - net_nbuf_append_be16(buf, 0); + net_pkt_append_be16(buf, 0); - net_nbuf_append(buf, sizeof(struct in6_addr), dag->dag_id.s6_addr, + net_pkt_append(buf, sizeof(struct in6_addr), dag->dag_id.s6_addr, K_FOREVER); if (instance->mc.type != NET_RPL_MC_NONE) { net_rpl_of_update_mc(instance); - net_nbuf_append_u8(buf, NET_RPL_OPTION_DAG_METRIC_CONTAINER); - net_nbuf_append_u8(buf, 6); - net_nbuf_append_u8(buf, instance->mc.type); - net_nbuf_append_u8(buf, instance->mc.flags >> 1); + net_pkt_append_u8(buf, NET_RPL_OPTION_DAG_METRIC_CONTAINER); + net_pkt_append_u8(buf, 6); + net_pkt_append_u8(buf, instance->mc.type); + net_pkt_append_u8(buf, instance->mc.flags >> 1); value = (instance->mc.flags & 1) << 7; - net_nbuf_append_u8(buf, value | + net_pkt_append_u8(buf, value | (instance->mc.aggregated << 4) | instance->mc.precedence); if (instance->mc.type == NET_RPL_MC_ETX) { - net_nbuf_append_u8(buf, 2); - net_nbuf_append_be16(buf, instance->mc.obj.etx); + net_pkt_append_u8(buf, 2); + net_pkt_append_be16(buf, instance->mc.obj.etx); } else if (instance->mc.type == NET_RPL_MC_ENERGY) { - net_nbuf_append_u8(buf, 2); - net_nbuf_append_u8(buf, instance->mc.obj.energy.flags); - net_nbuf_append_u8(buf, + net_pkt_append_u8(buf, 2); + net_pkt_append_u8(buf, instance->mc.obj.energy.flags); + net_pkt_append_u8(buf, instance->mc.obj.energy.estimation); } else { NET_DBG("Cannot send DIO, unknown DAG MC type %u", instance->mc.type); - net_nbuf_unref(buf); + net_pkt_unref(buf); return -EINVAL; } } - net_nbuf_append_u8(buf, NET_RPL_OPTION_DAG_CONF); - net_nbuf_append_u8(buf, 14); - net_nbuf_append_u8(buf, 0); /* No Auth */ - net_nbuf_append_u8(buf, instance->dio_interval_doublings); - net_nbuf_append_u8(buf, instance->dio_interval_min); - net_nbuf_append_u8(buf, instance->dio_redundancy); - net_nbuf_append_be16(buf, instance->max_rank_inc); - net_nbuf_append_be16(buf, instance->min_hop_rank_inc); + net_pkt_append_u8(buf, NET_RPL_OPTION_DAG_CONF); + net_pkt_append_u8(buf, 14); + net_pkt_append_u8(buf, 0); /* No Auth */ + net_pkt_append_u8(buf, instance->dio_interval_doublings); + net_pkt_append_u8(buf, instance->dio_interval_min); + net_pkt_append_u8(buf, instance->dio_redundancy); + net_pkt_append_be16(buf, instance->max_rank_inc); + net_pkt_append_be16(buf, instance->min_hop_rank_inc); - net_nbuf_append_be16(buf, instance->ocp); - net_nbuf_append_u8(buf, 0); /* Reserved */ - net_nbuf_append_u8(buf, instance->default_lifetime); - net_nbuf_append_be16(buf, instance->lifetime_unit); + net_pkt_append_be16(buf, instance->ocp); + net_pkt_append_u8(buf, 0); /* Reserved */ + net_pkt_append_u8(buf, instance->default_lifetime); + net_pkt_append_be16(buf, instance->lifetime_unit); if (dag->prefix_info.length > 0) { - net_nbuf_append_u8(buf, NET_RPL_OPTION_PREFIX_INFO); - net_nbuf_append_u8(buf, 30); /* length */ - net_nbuf_append_u8(buf, dag->prefix_info.length); - net_nbuf_append_u8(buf, dag->prefix_info.flags); + net_pkt_append_u8(buf, NET_RPL_OPTION_PREFIX_INFO); + net_pkt_append_u8(buf, 30); /* length */ + net_pkt_append_u8(buf, dag->prefix_info.length); + net_pkt_append_u8(buf, dag->prefix_info.flags); /* First valid lifetime and the second one is * preferred lifetime. */ - net_nbuf_append_be32(buf, dag->prefix_info.lifetime); - net_nbuf_append_be32(buf, dag->prefix_info.lifetime); + net_pkt_append_be32(buf, dag->prefix_info.lifetime); + net_pkt_append_be32(buf, dag->prefix_info.lifetime); - net_nbuf_append_be32(buf, 0); /* reserved */ - net_nbuf_append(buf, sizeof(struct in6_addr), + net_pkt_append_be32(buf, 0); /* reserved */ + net_pkt_append(buf, sizeof(struct in6_addr), dag->prefix_info.prefix.s6_addr, K_FOREVER); @@ -546,7 +546,7 @@ int net_rpl_dio_send(struct net_if *iface, ret = net_ipv6_finalize_raw(buf, IPPROTO_ICMPV6); if (ret < 0) { - net_nbuf_unref(buf); + net_pkt_unref(buf); return ret; } @@ -567,7 +567,7 @@ int net_rpl_dio_send(struct net_if *iface, return 0; } - net_nbuf_unref(buf); + net_pkt_unref(buf); return ret; } @@ -721,7 +721,7 @@ int net_rpl_dis_send(struct in6_addr *dst, struct net_if *iface) dst_addr = dst; } - buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, dst_addr), + buf = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface, dst_addr), K_FOREVER); if (!buf) { return -ENOMEM; @@ -731,20 +731,20 @@ int net_rpl_dis_send(struct in6_addr *dst, struct net_if *iface) buf = net_ipv6_create_raw(buf, src, dst_addr, iface, IPPROTO_ICMPV6); - net_nbuf_set_iface(buf, iface); + net_pkt_set_iface(buf, iface); setup_icmpv6_hdr(buf, NET_ICMPV6_RPL, NET_RPL_DODAG_SOLICIT); /* Add flags and reserved fields */ - net_nbuf_write_u8(buf, buf->frags, + net_pkt_write_u8(buf, buf->frags, sizeof(struct net_ipv6_hdr) + sizeof(struct net_icmp_hdr), &pos, 0); - net_nbuf_write_u8(buf, buf->frags, pos, &pos, 0); + net_pkt_write_u8(buf, buf->frags, pos, &pos, 0); ret = net_ipv6_finalize_raw(buf, IPPROTO_ICMPV6); if (ret < 0) { - net_nbuf_unref(buf); + net_pkt_unref(buf); return ret; } @@ -756,7 +756,7 @@ int net_rpl_dis_send(struct in6_addr *dst, struct net_if *iface) net_stats_update_icmp_sent(); net_stats_update_rpl_dis_sent(); } else { - net_nbuf_unref(buf); + net_pkt_unref(buf); } return ret; @@ -778,14 +778,14 @@ static enum net_verdict handle_dis(struct net_buf *buf) if (net_is_ipv6_addr_mcast(&NET_IPV6_BUF(buf)->dst)) { net_rpl_dio_reset_timer(instance); } else { - net_rpl_dio_send(net_nbuf_iface(buf), + net_rpl_dio_send(net_pkt_iface(buf), instance, &NET_IPV6_BUF(buf)->src, &NET_IPV6_BUF(buf)->dst); } } - net_nbuf_unref(buf); + net_pkt_unref(buf); return NET_OK; } @@ -2732,15 +2732,15 @@ static enum net_verdict handle_dio(struct net_buf *buf) dio.default_lifetime = CONFIG_NET_RPL_DEFAULT_LIFETIME; dio.lifetime_unit = CONFIG_NET_RPL_DEFAULT_LIFETIME_UNIT; - nbr = net_ipv6_nbr_lookup(net_nbuf_iface(buf), + nbr = net_ipv6_nbr_lookup(net_pkt_iface(buf), &NET_IPV6_BUF(buf)->src); if (!nbr) { - NET_ASSERT_INFO(net_nbuf_ll_src(buf)->len, + NET_ASSERT_INFO(net_pkt_ll_src(buf)->len, "Link layer address not set"); - nbr = net_ipv6_nbr_add(net_nbuf_iface(buf), + nbr = net_ipv6_nbr_add(net_pkt_iface(buf), &NET_IPV6_BUF(buf)->src, - net_nbuf_ll_src(buf), + net_pkt_ll_src(buf), 0, NET_IPV6_NBR_STATE_REACHABLE); if (!nbr) { @@ -2748,35 +2748,35 @@ static enum net_verdict handle_dio(struct net_buf *buf) goto out; } - net_ipv6_nbr_set_reachable_timer(net_nbuf_iface(buf), nbr); + net_ipv6_nbr_set_reachable_timer(net_pkt_iface(buf), nbr); } /* offset tells now where the ICMPv6 header is starting */ - offset = net_nbuf_icmp_data(buf) - net_nbuf_ip_data(buf); + offset = net_pkt_icmp_data(buf) - net_pkt_ip_data(buf); offset += sizeof(struct net_icmp_hdr); /* First the DIO option. */ - frag = net_nbuf_read_u8(buf->frags, offset, &pos, &dio.instance_id); - frag = net_nbuf_read_u8(frag, pos, &pos, &dio.version); - frag = net_nbuf_read_be16(frag, pos, &pos, &dio.rank); + frag = net_pkt_read_u8(buf->frags, offset, &pos, &dio.instance_id); + frag = net_pkt_read_u8(frag, pos, &pos, &dio.version); + frag = net_pkt_read_be16(frag, pos, &pos, &dio.rank); NET_DBG("Incoming DIO len %zu id %d ver %d rank %d", net_buf_frags_len(buf) - offset, dio.instance_id, dio.version, dio.rank); - frag = net_nbuf_read_u8(frag, pos, &pos, &flags); + frag = net_pkt_read_u8(frag, pos, &pos, &flags); dio.grounded = flags & NET_RPL_DIO_GROUNDED; dio.mop = (flags & NET_RPL_DIO_MOP_MASK) >> NET_RPL_DIO_MOP_SHIFT; dio.preference = flags & NET_RPL_DIO_PREFERENCE_MASK; - frag = net_nbuf_read_u8(frag, pos, &pos, &dio.dtsn); + frag = net_pkt_read_u8(frag, pos, &pos, &dio.dtsn); /* two reserved bytes */ - frag = net_nbuf_skip(frag, pos, &pos, 2); + frag = net_pkt_skip(frag, pos, &pos, 2); - frag = net_nbuf_read(frag, pos, &pos, sizeof(dio.dag_id), + frag = net_pkt_read(frag, pos, &pos, sizeof(dio.dag_id), dio.dag_id.s6_addr); NET_DBG("Incoming DIO dag_id %s pref %d", @@ -2785,7 +2785,7 @@ static enum net_verdict handle_dio(struct net_buf *buf) /* Handle any DIO suboptions */ while (frag) { len = 0; - frag = net_nbuf_read_u8(frag, pos, &pos, &subopt_type); + frag = net_pkt_read_u8(frag, pos, &pos, &subopt_type); if (!frag && pos == 0) { /* We are at the end of the message */ break; @@ -2797,7 +2797,7 @@ static enum net_verdict handle_dio(struct net_buf *buf) if (subopt_type != NET_RPL_OPTION_PAD1) { /* Suboption with a two-byte header + payload */ - frag = net_nbuf_read_u8(frag, pos, &pos, &len); + frag = net_pkt_read_u8(frag, pos, &pos, &len); len += 2; } @@ -2810,7 +2810,7 @@ static enum net_verdict handle_dio(struct net_buf *buf) break; case NET_RPL_OPTION_PADN: /* Skip padding bytes */ - frag = net_nbuf_skip(frag, pos, &pos, len - 2); + frag = net_pkt_skip(frag, pos, &pos, len - 2); break; case NET_RPL_OPTION_DAG_METRIC_CONTAINER: if (len < 6) { @@ -2819,19 +2819,19 @@ static enum net_verdict handle_dio(struct net_buf *buf) goto out; } - frag = net_nbuf_read_u8(frag, pos, &pos, &dio.mc.type); - frag = net_nbuf_read_u8(frag, pos, &pos, &tmp); + frag = net_pkt_read_u8(frag, pos, &pos, &dio.mc.type); + frag = net_pkt_read_u8(frag, pos, &pos, &tmp); dio.mc.flags = tmp << 1; - frag = net_nbuf_read_u8(frag, pos, &pos, &tmp); + frag = net_pkt_read_u8(frag, pos, &pos, &tmp); dio.mc.flags |= tmp >> 7; dio.mc.aggregated = (tmp >> 4) & 0x3; dio.mc.precedence = tmp & 0xf; - frag = net_nbuf_read_u8(frag, pos, &pos, + frag = net_pkt_read_u8(frag, pos, &pos, &dio.mc.length); if (dio.mc.type == NET_RPL_MC_ETX) { - frag = net_nbuf_read_be16(frag, pos, &pos, - &dio.mc.obj.etx); + frag = net_pkt_read_be16(frag, pos, &pos, + &dio.mc.obj.etx); NET_DBG("DAG MC type %d flags %d aggr %d " "prec %d length %d ETX %d", @@ -2841,9 +2841,9 @@ static enum net_verdict handle_dio(struct net_buf *buf) dio.mc.obj.etx); } else if (dio.mc.type == NET_RPL_MC_ENERGY) { - frag = net_nbuf_read_u8(frag, pos, &pos, + frag = net_pkt_read_u8(frag, pos, &pos, &dio.mc.obj.energy.flags); - frag = net_nbuf_read_u8(frag, pos, &pos, + frag = net_pkt_read_u8(frag, pos, &pos, &dio.mc.obj.energy.estimation); } else { NET_DBG("Unhandled DAG MC type %d", @@ -2860,16 +2860,16 @@ static enum net_verdict handle_dio(struct net_buf *buf) goto out; } - frag = net_nbuf_read_u8(frag, pos, &pos, + frag = net_pkt_read_u8(frag, pos, &pos, &dio.destination_prefix.length); - frag = net_nbuf_read_u8(frag, pos, &pos, + frag = net_pkt_read_u8(frag, pos, &pos, &dio.destination_prefix.flags); - frag = net_nbuf_read_be32(frag, pos, &pos, + frag = net_pkt_read_be32(frag, pos, &pos, &dio.destination_prefix.lifetime); if (((dio.destination_prefix.length + 7) / 8) + 8 <= len && dio.destination_prefix.length <= 128) { - frag = net_nbuf_read(frag, pos, &pos, + frag = net_pkt_read(frag, pos, &pos, (dio.destination_prefix.length + 7) / 8, dio.destination_prefix.prefix.s6_addr); @@ -2894,28 +2894,28 @@ static enum net_verdict handle_dio(struct net_buf *buf) } /* Path control field not yet implemented (1 byte) */ - frag = net_nbuf_skip(frag, pos, &pos, 1); - - frag = net_nbuf_read_u8(frag, pos, &pos, - &dio.dag_interval_doublings); - frag = net_nbuf_read_u8(frag, pos, &pos, - &dio.dag_interval_min); - frag = net_nbuf_read_u8(frag, pos, &pos, - &dio.dag_redundancy); - frag = net_nbuf_read_be16(frag, pos, &pos, - &dio.max_rank_inc); - frag = net_nbuf_read_be16(frag, pos, &pos, - &dio.min_hop_rank_inc); - frag = net_nbuf_read_be16(frag, pos, &pos, - &dio.ocp); + frag = net_pkt_skip(frag, pos, &pos, 1); + + frag = net_pkt_read_u8(frag, pos, &pos, + &dio.dag_interval_doublings); + frag = net_pkt_read_u8(frag, pos, &pos, + &dio.dag_interval_min); + frag = net_pkt_read_u8(frag, pos, &pos, + &dio.dag_redundancy); + frag = net_pkt_read_be16(frag, pos, &pos, + &dio.max_rank_inc); + frag = net_pkt_read_be16(frag, pos, &pos, + &dio.min_hop_rank_inc); + frag = net_pkt_read_be16(frag, pos, &pos, + &dio.ocp); /* one reserved byte */ - frag = net_nbuf_skip(frag, pos, &pos, 1); + frag = net_pkt_skip(frag, pos, &pos, 1); - frag = net_nbuf_read_u8(frag, pos, &pos, - &dio.default_lifetime); - frag = net_nbuf_read_be16(frag, pos, &pos, - &dio.lifetime_unit); + frag = net_pkt_read_u8(frag, pos, &pos, + &dio.default_lifetime); + frag = net_pkt_read_be16(frag, pos, &pos, + &dio.lifetime_unit); NET_DBG("DAG conf dbl %d min %d red %d maxinc %d " "mininc %d ocp %d d_l %d l_u %d", @@ -2934,24 +2934,24 @@ static enum net_verdict handle_dio(struct net_buf *buf) goto out; } - frag = net_nbuf_read_u8(frag, pos, &pos, - &dio.prefix_info.length); - frag = net_nbuf_read_u8(frag, pos, &pos, - &dio.prefix_info.flags); + frag = net_pkt_read_u8(frag, pos, &pos, + &dio.prefix_info.length); + frag = net_pkt_read_u8(frag, pos, &pos, + &dio.prefix_info.flags); /* skip valid lifetime atm */ - frag = net_nbuf_skip(frag, pos, &pos, 4); + frag = net_pkt_skip(frag, pos, &pos, 4); /* preferred lifetime stored in lifetime */ - frag = net_nbuf_read_be32(frag, pos, &pos, - &dio.prefix_info.lifetime); + frag = net_pkt_read_be32(frag, pos, &pos, + &dio.prefix_info.lifetime); /* 32-bit reserved */ - frag = net_nbuf_skip(frag, pos, &pos, 4); + frag = net_pkt_skip(frag, pos, &pos, 4); - frag = net_nbuf_read(frag, pos, &pos, - sizeof(struct in6_addr), - dio.prefix_info.prefix.s6_addr); + frag = net_pkt_read(frag, pos, &pos, + sizeof(struct in6_addr), + dio.prefix_info.prefix.s6_addr); NET_DBG("Prefix %s/%d", net_sprint_ipv6_addr(&dio.prefix_info.prefix), @@ -2961,14 +2961,14 @@ static enum net_verdict handle_dio(struct net_buf *buf) default: NET_DBG("Unsupported suboption type in DIO %d", subopt_type); - frag = net_nbuf_skip(frag, pos, &pos, len - 2); + frag = net_pkt_skip(frag, pos, &pos, len - 2); break; } } NET_ASSERT_INFO(!pos && !frag, "DIO reading failure"); - net_rpl_process_dio(net_nbuf_iface(buf), &NET_IPV6_BUF(buf)->src, &dio); + net_rpl_process_dio(net_pkt_iface(buf), &NET_IPV6_BUF(buf)->src, &dio); out: return NET_DROP; @@ -3022,21 +3022,21 @@ int net_rpl_dao_send(struct net_if *iface, return -EINVAL; } - buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, dst), - K_FOREVER); + buf = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface, dst), + K_FOREVER); if (!buf) { return -ENOMEM; } buf = net_ipv6_create_raw(buf, src, dst, iface, IPPROTO_ICMPV6); - net_nbuf_set_iface(buf, iface); + net_pkt_set_iface(buf, iface); setup_icmpv6_hdr(buf, NET_ICMPV6_RPL, NET_RPL_DEST_ADV_OBJ); net_rpl_lollipop_increment(&rpl_dao_sequence); - net_nbuf_append_u8(buf, instance->instance_id); + net_pkt_append_u8(buf, instance->instance_id); #if defined(CONFIG_NET_RPL_DAO_SPECIFY_DAG) value |= NET_RPL_DAO_D_FLAG; @@ -3045,34 +3045,34 @@ int net_rpl_dao_send(struct net_if *iface, #if defined(CONFIG_NET_RPL_DAO_ACK) value |= NET_RPL_DAO_K_FLAG; #endif - net_nbuf_append_u8(buf, value); - net_nbuf_append_u8(buf, 0); /* reserved */ - net_nbuf_append_u8(buf, rpl_dao_sequence); + net_pkt_append_u8(buf, value); + net_pkt_append_u8(buf, 0); /* reserved */ + net_pkt_append_u8(buf, rpl_dao_sequence); #if defined(CONFIG_NET_RPL_DAO_SPECIFY_DAG) - net_nbuf_append(buf, sizeof(dag->dag_id), dag->dag_id.s6_addr, + net_pkt_append(buf, sizeof(dag->dag_id), dag->dag_id.s6_addr, K_FOREVER); #endif prefixlen = sizeof(*prefix) * CHAR_BIT; prefix_bytes = (prefixlen + 7) / CHAR_BIT; - net_nbuf_append_u8(buf, NET_RPL_OPTION_TARGET); - net_nbuf_append_u8(buf, 2 + prefix_bytes); - net_nbuf_append_u8(buf, 0); /* reserved */ - net_nbuf_append_u8(buf, prefixlen); - net_nbuf_append(buf, prefix_bytes, prefix->s6_addr, K_FOREVER); + net_pkt_append_u8(buf, NET_RPL_OPTION_TARGET); + net_pkt_append_u8(buf, 2 + prefix_bytes); + net_pkt_append_u8(buf, 0); /* reserved */ + net_pkt_append_u8(buf, prefixlen); + net_pkt_append(buf, prefix_bytes, prefix->s6_addr, K_FOREVER); - net_nbuf_append_u8(buf, NET_RPL_OPTION_TRANSIT); - net_nbuf_append_u8(buf, 4); /* length */ - net_nbuf_append_u8(buf, 0); /* flags */ - net_nbuf_append_u8(buf, 0); /* path control */ - net_nbuf_append_u8(buf, 0); /* path seq */ - net_nbuf_append_u8(buf, lifetime); + net_pkt_append_u8(buf, NET_RPL_OPTION_TRANSIT); + net_pkt_append_u8(buf, 4); /* length */ + net_pkt_append_u8(buf, 0); /* flags */ + net_pkt_append_u8(buf, 0); /* path control */ + net_pkt_append_u8(buf, 0); /* path seq */ + net_pkt_append_u8(buf, lifetime); ret = net_ipv6_finalize_raw(buf, IPPROTO_ICMPV6); if (ret < 0) { - net_nbuf_unref(buf); + net_pkt_unref(buf); return ret; } @@ -3083,7 +3083,7 @@ int net_rpl_dao_send(struct net_if *iface, net_stats_update_icmp_sent(); net_stats_update_rpl_dao_sent(); } else { - net_nbuf_unref(buf); + net_pkt_unref(buf); } return ret; @@ -3113,8 +3113,8 @@ static inline int dao_forward(struct net_if *iface, struct net_buf *buf; int ret; - buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, dst), - K_FOREVER); + buf = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface, dst), + K_FOREVER); if (!buf) { return -ENOMEM; } @@ -3125,9 +3125,9 @@ static inline int dao_forward(struct net_if *iface, net_ipaddr_copy(&NET_IPV6_BUF(buf)->dst, dst); - net_nbuf_set_ip_hdr_len(buf, sizeof(struct net_ipv6_hdr)); - net_nbuf_set_family(buf, AF_INET6); - net_nbuf_set_iface(buf, iface); + net_pkt_set_ip_hdr_len(buf, sizeof(struct net_ipv6_hdr)); + net_pkt_set_family(buf, AF_INET6); + net_pkt_set_iface(buf, iface); NET_ICMP_BUF(buf)->chksum = 0; NET_ICMP_BUF(buf)->chksum = ~net_calc_chksum_icmpv6(buf); @@ -3137,7 +3137,7 @@ static inline int dao_forward(struct net_if *iface, net_stats_update_icmp_sent(); net_stats_update_rpl_dao_forwarded(); } else { - net_nbuf_unref(buf); + net_pkt_unref(buf); } return ret; @@ -3156,26 +3156,26 @@ static int dao_ack_send(struct in6_addr *src, NET_DBG("Sending a DAO ACK with sequence number %d to %s", sequence, net_sprint_ipv6_addr(dst)); - buf = net_nbuf_get_reserve_tx(net_if_get_ll_reserve(iface, dst), - K_FOREVER); + buf = net_pkt_get_reserve_tx(net_if_get_ll_reserve(iface, dst), + K_FOREVER); if (!buf) { return -ENOMEM; } buf = net_ipv6_create_raw(buf, src, dst, iface, IPPROTO_ICMPV6); - net_nbuf_set_iface(buf, iface); + net_pkt_set_iface(buf, iface); setup_icmpv6_hdr(buf, NET_ICMPV6_RPL, NET_RPL_DEST_ADV_OBJ_ACK); - net_nbuf_append_u8(buf, instance->instance_id); - net_nbuf_append_u8(buf, 0); /* reserved */ - net_nbuf_append_u8(buf, sequence); - net_nbuf_append_u8(buf, status); /* status */ + net_pkt_append_u8(buf, instance->instance_id); + net_pkt_append_u8(buf, 0); /* reserved */ + net_pkt_append_u8(buf, sequence); + net_pkt_append_u8(buf, status); /* status */ ret = net_ipv6_finalize_raw(buf, IPPROTO_ICMPV6); if (ret < 0) { - net_nbuf_unref(buf); + net_pkt_unref(buf); return ret; } @@ -3187,7 +3187,7 @@ static int dao_ack_send(struct in6_addr *src, net_stats_update_icmp_sent(); net_stats_update_rpl_dao_ack_sent(); } else { - net_nbuf_unref(buf); + net_pkt_unref(buf); } return 0; @@ -3222,7 +3222,7 @@ static int forwarding_dao(struct net_rpl_instance *instance, * original DAO message. */ if (flags & NET_RPL_DAO_K_FLAG) { - r = dao_ack_send(&dst, &src, net_nbuf_iface(buf), + r = dao_ack_send(&dst, &src, net_pkt_iface(buf), instance, sequence, 128); } } @@ -3256,11 +3256,11 @@ static enum net_verdict handle_dao(struct net_buf *buf) net_rpl_info(buf, "Destination Advertisement Object"); /* offset tells now where the ICMPv6 header is starting */ - offset = net_nbuf_icmp_data(buf) - net_nbuf_ip_data(buf); + offset = net_pkt_icmp_data(buf) - net_pkt_ip_data(buf); offset += sizeof(struct net_icmp_hdr); - frag = net_nbuf_read_u8(buf->frags, offset, &pos, &instance_id); + frag = net_pkt_read_u8(buf->frags, offset, &pos, &instance_id); instance = net_rpl_get_instance(instance_id); if (!instance) { @@ -3271,15 +3271,15 @@ static enum net_verdict handle_dao(struct net_buf *buf) lifetime = instance->default_lifetime; - frag = net_nbuf_read_u8(frag, pos, &pos, &flags); - frag = net_nbuf_skip(frag, pos, &pos, 1); /* reserved */ - frag = net_nbuf_read_u8(frag, pos, &pos, &sequence); + frag = net_pkt_read_u8(frag, pos, &pos, &flags); + frag = net_pkt_skip(frag, pos, &pos, 1); /* reserved */ + frag = net_pkt_read_u8(frag, pos, &pos, &sequence); dag = instance->current_dag; /* Is the DAG ID present? */ if (flags & NET_RPL_DAO_D_FLAG) { - frag = net_nbuf_read(frag, pos, &pos, sizeof(addr), + frag = net_pkt_read(frag, pos, &pos, sizeof(addr), addr.s6_addr); if (memcmp(&dag->dag_id, &addr, sizeof(dag->dag_id))) { @@ -3330,7 +3330,7 @@ static enum net_verdict handle_dao(struct net_buf *buf) /* Handle any DAO suboptions */ while (frag) { len = 0; - frag = net_nbuf_read_u8(frag, pos, &pos, &subopt_type); + frag = net_pkt_read_u8(frag, pos, &pos, &subopt_type); if (!frag && pos == 0) { /* We are at the end of the message */ break; @@ -3343,7 +3343,7 @@ static enum net_verdict handle_dao(struct net_buf *buf) if (subopt_type != NET_RPL_OPTION_PAD1) { /* Suboption with a two-byte header + payload */ - frag = net_nbuf_read_u8(frag, pos, &pos, &len); + frag = net_pkt_read_u8(frag, pos, &pos, &len); len += 2; } @@ -3356,23 +3356,23 @@ static enum net_verdict handle_dao(struct net_buf *buf) break; case NET_RPL_OPTION_PADN: /* Skip padding bytes */ - frag = net_nbuf_skip(frag, pos, &pos, len - 2); + frag = net_pkt_skip(frag, pos, &pos, len - 2); break; case NET_RPL_OPTION_TARGET: - frag = net_nbuf_skip(frag, pos, &pos, 1); /* reserved */ - frag = net_nbuf_read_u8(frag, pos, &pos, &target_len); - frag = net_nbuf_read(frag, pos, &pos, + frag = net_pkt_skip(frag, pos, &pos, 1); /* reserved */ + frag = net_pkt_read_u8(frag, pos, &pos, &target_len); + frag = net_pkt_read(frag, pos, &pos, (target_len + 7) / 8, addr.s6_addr); break; case NET_RPL_OPTION_TRANSIT: /* The flags, path sequence and control are ignored. */ - frag = net_nbuf_skip(frag, pos, &pos, 3); - frag = net_nbuf_read_u8(frag, pos, &pos, &lifetime); + frag = net_pkt_skip(frag, pos, &pos, 3); + frag = net_pkt_read_u8(frag, pos, &pos, &lifetime); break; default: /* Skip unknown sub options */ - frag = net_nbuf_skip(frag, pos, &pos, len - 2); + frag = net_pkt_skip(frag, pos, &pos, len - 2); break; } } @@ -3384,7 +3384,7 @@ static enum net_verdict handle_dao(struct net_buf *buf) if (net_is_ipv6_addr_mcast_global(&addr)) { struct net_route_entry_mcast *mcast_group; - mcast_group = net_route_mcast_add(net_nbuf_iface(buf), &addr); + mcast_group = net_route_mcast_add(net_pkt_iface(buf), &addr); if (mcast_group) { mcast_group->data = (void *)dag; mcast_group->lifetime = net_rpl_lifetime(instance, @@ -3400,7 +3400,7 @@ static enum net_verdict handle_dao(struct net_buf *buf) NET_DBG("No-Path DAO received"); - route = net_route_lookup(net_nbuf_iface(buf), &addr); + route = net_route_lookup(net_pkt_iface(buf), &addr); nbr = net_route_get_nbr(route); extra = net_nbr_extra_data(nbr); nexthop = net_route_get_nexthop(route); @@ -3429,7 +3429,7 @@ static enum net_verdict handle_dao(struct net_buf *buf) #endif ); if (r >= 0) { - net_nbuf_unref(buf); + net_pkt_unref(buf); return NET_OK; } } @@ -3440,35 +3440,35 @@ static enum net_verdict handle_dao(struct net_buf *buf) NET_DBG("Adding DAO route"); - nbr = net_ipv6_nbr_lookup(net_nbuf_iface(buf), dao_sender); + nbr = net_ipv6_nbr_lookup(net_pkt_iface(buf), dao_sender); if (!nbr) { - nbr = net_ipv6_nbr_add(net_nbuf_iface(buf), dao_sender, - net_nbuf_ll_src(buf), false, + nbr = net_ipv6_nbr_add(net_pkt_iface(buf), dao_sender, + net_pkt_ll_src(buf), false, NET_IPV6_NBR_STATE_REACHABLE); if (nbr) { /* Set reachable timer */ - net_ipv6_nbr_set_reachable_timer(net_nbuf_iface(buf), + net_ipv6_nbr_set_reachable_timer(net_pkt_iface(buf), nbr); NET_DBG("Neighbor %s [%s] added to neighbor cache", net_sprint_ipv6_addr(dao_sender), - net_sprint_ll_addr(net_nbuf_ll_src(buf)->addr, - net_nbuf_ll_src(buf)->len)); + net_sprint_ll_addr(net_pkt_ll_src(buf)->addr, + net_pkt_ll_src(buf)->len)); } else { NET_DBG("Out of memory, dropping DAO from %s [%s]", net_sprint_ipv6_addr(dao_sender), - net_sprint_ll_addr(net_nbuf_ll_src(buf)->addr, - net_nbuf_ll_src(buf)->len)); + net_sprint_ll_addr(net_pkt_ll_src(buf)->addr, + net_pkt_ll_src(buf)->len)); return NET_DROP; } } else { NET_DBG("Neighbor %s [%s] already in neighbor cache", net_sprint_ipv6_addr(dao_sender), - net_sprint_ll_addr(net_nbuf_ll_src(buf)->addr, - net_nbuf_ll_src(buf)->len)); + net_sprint_ll_addr(net_pkt_ll_src(buf)->addr, + net_pkt_ll_src(buf)->len)); } - route = net_rpl_add_route(dag, net_nbuf_iface(buf), + route = net_rpl_add_route(dag, net_pkt_iface(buf), &addr, target_len, dao_sender); if (!route) { net_stats_update_rpl_mem_overflows(); @@ -3498,7 +3498,7 @@ fwd_dao: #endif ); if (r >= 0) { - net_nbuf_unref(buf); + net_pkt_unref(buf); return NET_OK; } } @@ -3520,11 +3520,11 @@ static enum net_verdict handle_dao_ack(struct net_buf *buf) net_rpl_info(buf, "Destination Advertisement Object Ack"); /* offset tells now where the ICMPv6 header is starting */ - offset = net_nbuf_icmp_data(buf) - net_nbuf_ip_data(buf); + offset = net_pkt_icmp_data(buf) - net_pkt_ip_data(buf); offset += sizeof(struct net_icmp_hdr); - frag = net_nbuf_read_u8(buf->frags, offset, &pos, &instance_id); + frag = net_pkt_read_u8(buf->frags, offset, &pos, &instance_id); if (!frag && pos == 0xffff) { /* Read error */ return NET_DROP; @@ -3538,9 +3538,9 @@ static enum net_verdict handle_dao_ack(struct net_buf *buf) } /* Skip reserved byte */ - frag = net_nbuf_skip(frag, pos, &pos, 1); - frag = net_nbuf_read_u8(frag, pos, &pos, &sequence); - frag = net_nbuf_read_u8(frag, pos, &pos, &status); + frag = net_pkt_skip(frag, pos, &pos, 1); + frag = net_pkt_read_u8(frag, pos, &pos, &sequence); + frag = net_pkt_read_u8(frag, pos, &pos, &status); if (!frag && pos == 0xffff) { return NET_DROP; } @@ -3560,7 +3560,7 @@ static enum net_verdict handle_dao_ack(struct net_buf *buf) * to act as a parent. * Trigger a local repair since we can not get our DAO. */ - net_rpl_local_repair(net_nbuf_iface(buf), instance); + net_rpl_local_repair(net_pkt_iface(buf), instance); return NET_DROP; } } else { @@ -3570,7 +3570,7 @@ static enum net_verdict handle_dao_ack(struct net_buf *buf) net_stats_update_rpl_dao_ack_recv(); - net_nbuf_unref(buf); + net_pkt_unref(buf); return NET_OK; } @@ -3619,8 +3619,8 @@ int net_rpl_update_header(struct net_buf *buf, struct in6_addr *addr) * next header. */ pos = sizeof(struct net_ipv6_hdr) + 1; - frag = net_nbuf_read(frag, pos, &pos, 1, &len); /* HBH length */ - frag = net_nbuf_read(frag, pos, &pos, 1, &opt); /* Opt type */ + frag = net_pkt_read(frag, pos, &pos, 1, &len); /* HBH length */ + frag = net_pkt_read(frag, pos, &pos, 1, &opt); /* Opt type */ if (!frag && pos) { /* Not enough data in the message */ return -EMSGSIZE; @@ -3636,15 +3636,15 @@ int net_rpl_update_header(struct net_buf *buf, struct in6_addr *addr) return 0; } - frag = net_nbuf_skip(frag, pos, &pos, 1); /* opt len */ + frag = net_pkt_skip(frag, pos, &pos, 1); /* opt len */ /* Where the flags is located in the packet, that info is * need few lines below. */ offset = pos; - frag = net_nbuf_skip(frag, pos, &pos, 1); /* flags */ - frag = net_nbuf_skip(frag, pos, &pos, 1); /* instance */ - frag = net_nbuf_read(frag, pos, &pos, 2, (uint8_t *)&sender_rank); + frag = net_pkt_skip(frag, pos, &pos, 1); /* flags */ + frag = net_pkt_skip(frag, pos, &pos, 1); /* instance */ + frag = net_pkt_read(frag, pos, &pos, 2, (uint8_t *)&sender_rank); if (!frag && pos) { return -EMSGSIZE; } @@ -3661,19 +3661,19 @@ int net_rpl_update_header(struct net_buf *buf, struct in6_addr *addr) return -EINVAL; } - parent = find_parent(net_nbuf_iface(buf), + parent = find_parent(net_pkt_iface(buf), rpl_default_instance->current_dag, addr); if (!parent || parent != parent->dag->preferred_parent) { - net_nbuf_write_u8(buf, buf->frags, offset, &pos, - NET_RPL_HDR_OPT_DOWN); + net_pkt_write_u8(buf, buf->frags, offset, &pos, + NET_RPL_HDR_OPT_DOWN); } offset++; - net_nbuf_write_u8(buf, buf->frags, offset, &pos, - rpl_default_instance->instance_id); - net_nbuf_write_be16(buf, buf->frags, pos, &pos, - htons(rpl_default_instance-> - current_dag->rank)); + net_pkt_write_u8(buf, buf->frags, offset, &pos, + rpl_default_instance->instance_id); + net_pkt_write_be16(buf, buf->frags, pos, &pos, + htons(rpl_default_instance-> + current_dag->rank)); return 0; } @@ -3686,9 +3686,9 @@ struct net_buf *net_rpl_verify_header(struct net_buf *buf, struct net_buf *frag, uint8_t instance_id, flags; bool down, sender_closer; - frag = net_nbuf_read_u8(frag, offset, pos, &flags); - frag = net_nbuf_read_u8(frag, *pos, pos, &instance_id); - frag = net_nbuf_read_be16(frag, *pos, pos, &sender_rank); + frag = net_pkt_read_u8(frag, offset, pos, &flags); + frag = net_pkt_read_u8(frag, *pos, pos, &instance_id); + frag = net_pkt_read_be16(frag, *pos, pos, &sender_rank); if (!frag && *pos == 0xffff) { *result = false; @@ -3712,7 +3712,7 @@ struct net_buf *net_rpl_verify_header(struct net_buf *buf, struct net_buf *frag, */ NET_DBG("Forward error!"); - route = net_route_lookup(net_nbuf_iface(buf), + route = net_route_lookup(net_pkt_iface(buf), &NET_IPV6_BUF(buf)->dst); if (route) { net_route_del(route); @@ -3783,60 +3783,60 @@ struct net_buf *net_rpl_verify_header(struct net_buf *buf, struct net_buf *frag, static inline int add_rpl_opt(struct net_buf *buf, uint16_t offset) { - int ext_len = net_nbuf_ext_len(buf); + int ext_len = net_pkt_ext_len(buf); bool ret; /* next header */ - net_nbuf_set_ipv6_hdr_prev(buf, offset); + net_pkt_set_ipv6_hdr_prev(buf, offset); - ret = net_nbuf_insert_u8(buf, buf->frags, offset++, - NET_IPV6_BUF(buf)->nexthdr); + ret = net_pkt_insert_u8(buf, buf->frags, offset++, + NET_IPV6_BUF(buf)->nexthdr); if (!ret) { return -EINVAL; } /* Option len */ - ret = net_nbuf_insert_u8(buf, buf->frags, offset++, - NET_RPL_HOP_BY_HOP_LEN - 8); + ret = net_pkt_insert_u8(buf, buf->frags, offset++, + NET_RPL_HOP_BY_HOP_LEN - 8); if (!ret) { return -EINVAL; } /* Sub-option type */ - ret = net_nbuf_insert_u8(buf, buf->frags, offset++, - NET_IPV6_EXT_HDR_OPT_RPL); + ret = net_pkt_insert_u8(buf, buf->frags, offset++, + NET_IPV6_EXT_HDR_OPT_RPL); if (!ret) { return -EINVAL; } /* Sub-option length */ - ret = net_nbuf_insert_u8(buf, buf->frags, offset++, - NET_RPL_HDR_OPT_LEN); + ret = net_pkt_insert_u8(buf, buf->frags, offset++, + NET_RPL_HDR_OPT_LEN); if (!ret) { return -EINVAL; } /* RPL option flags */ - ret = net_nbuf_insert_u8(buf, buf->frags, offset++, 0); + ret = net_pkt_insert_u8(buf, buf->frags, offset++, 0); if (!ret) { return -EINVAL; } /* RPL Instance id */ - ret = net_nbuf_insert_u8(buf, buf->frags, offset++, 0); + ret = net_pkt_insert_u8(buf, buf->frags, offset++, 0); if (!ret) { return -EINVAL; } /* RPL sender rank */ - ret = net_nbuf_insert_be16(buf, buf->frags, offset++, 0); + ret = net_pkt_insert_be16(buf, buf->frags, offset++, 0); if (!ret) { return -EINVAL; } NET_IPV6_BUF(buf)->nexthdr = NET_IPV6_NEXTHDR_HBHO; - net_nbuf_set_ext_len(buf, ext_len + NET_RPL_HOP_BY_HOP_LEN); + net_pkt_set_ext_len(buf, ext_len + NET_RPL_HOP_BY_HOP_LEN); return 0; } @@ -3867,10 +3867,10 @@ static int net_rpl_update_header_empty(struct net_buf *buf) return 0; } - net_nbuf_set_ipv6_hdr_prev(buf, offset); + net_pkt_set_ipv6_hdr_prev(buf, offset); - frag = net_nbuf_read_u8(frag, offset, &offset, &next_hdr); - frag = net_nbuf_read_u8(frag, offset, &offset, &len); + frag = net_pkt_read_u8(frag, offset, &offset, &next_hdr); + frag = net_pkt_read_u8(frag, offset, &offset, &len); if (!frag) { return 0; } @@ -3888,8 +3888,8 @@ static int net_rpl_update_header_empty(struct net_buf *buf) length += 2; /* Each extension option has type and length */ - frag = net_nbuf_read_u8(frag, offset, &offset, &opt_type); - frag = net_nbuf_read_u8(frag, offset, &offset, &opt_len); + frag = net_pkt_read_u8(frag, offset, &offset, &opt_type); + frag = net_pkt_read_u8(frag, offset, &offset, &opt_len); if (opt_type != NET_IPV6_EXT_HDR_OPT_RPL) { /* FIXME: go through all the options instead */ @@ -3903,8 +3903,8 @@ static int net_rpl_update_header_empty(struct net_buf *buf) return 0; } - frag = net_nbuf_read_u8(buf, offset, &offset, &flags); - frag = net_nbuf_read_u8(frag, offset, &offset, &instance_id); + frag = net_pkt_read_u8(buf, offset, &offset, &flags); + frag = net_pkt_read_u8(frag, offset, &offset, &instance_id); instance = net_rpl_get_instance(instance_id); if (!instance || !instance->is_used || @@ -3922,12 +3922,12 @@ static int net_rpl_update_header_empty(struct net_buf *buf) NET_DBG("Updating RPL option"); /* The offset should point to "rank" right now */ - net_nbuf_write_be16(buf, frag, offset, &pos, + net_pkt_write_be16(buf, frag, offset, &pos, instance->current_dag->rank); offset -= 2; /* move back to flags */ - route = net_route_lookup(net_nbuf_iface(buf), &NET_IPV6_BUF(buf)->dst); + route = net_route_lookup(net_pkt_iface(buf), &NET_IPV6_BUF(buf)->dst); /* * Check the direction of the down flag, as per @@ -3939,7 +3939,7 @@ static int net_rpl_update_header_empty(struct net_buf *buf) struct net_nbr *nbr; if (!route) { - net_nbuf_write_u8(buf, frag, offset, &pos, + net_pkt_write_u8(buf, frag, offset, &pos, flags |= NET_RPL_HDR_OPT_FWD_ERR); NET_DBG("RPL forwarding error"); @@ -3952,12 +3952,12 @@ static int net_rpl_update_header_empty(struct net_buf *buf) NET_DBG("RPL generate No-Path DAO"); nbr = net_nbr_lookup(&net_rpl_parents.table, - net_nbuf_iface(buf), - net_nbuf_ll_src(buf)); + net_pkt_iface(buf), + net_pkt_ll_src(buf)); parent = nbr_data(nbr); if (parent) { - net_rpl_dao_send(net_nbuf_iface(buf), + net_rpl_dao_send(net_pkt_iface(buf), parent, &NET_IPV6_BUF(buf)->dst, NET_RPL_ZERO_LIFETIME); @@ -3981,7 +3981,7 @@ static int net_rpl_update_header_empty(struct net_buf *buf) * towards the RPL root. If so, we should not * set the down flag. */ - net_nbuf_write_u8(buf, frag, offset, &pos, + net_pkt_write_u8(buf, frag, offset, &pos, flags &= ~NET_RPL_HDR_OPT_DOWN); NET_DBG("RPL option going up"); @@ -3989,7 +3989,7 @@ static int net_rpl_update_header_empty(struct net_buf *buf) /* A DAO route was found so we set the down * flag. */ - net_nbuf_write_u8(buf, frag, offset, &pos, + net_pkt_write_u8(buf, frag, offset, &pos, flags |= NET_RPL_HDR_OPT_DOWN); NET_DBG("RPL option going down"); @@ -4010,17 +4010,17 @@ int net_rpl_revert_header(struct net_buf *buf, uint16_t offset, uint16_t *pos) uint8_t opt; /* Skip HBHO next header and length */ - frag = net_nbuf_skip(buf->frags, offset, pos, 2); - frag = net_nbuf_read_u8(frag, *pos, pos, &opt); - frag = net_nbuf_read_u8(frag, *pos, pos, &opt_len); + frag = net_pkt_skip(buf->frags, offset, pos, 2); + frag = net_pkt_read_u8(frag, *pos, pos, &opt); + frag = net_pkt_read_u8(frag, *pos, pos, &opt_len); if (opt != NET_IPV6_EXT_HDR_OPT_RPL) { return -EINVAL; } revert_pos = *pos; - frag = net_nbuf_read_u8(frag, *pos, pos, &flags); - frag = net_nbuf_read_u8(frag, *pos, pos, &instance_id); + frag = net_pkt_read_u8(frag, *pos, pos, &flags); + frag = net_pkt_read_u8(frag, *pos, pos, &instance_id); if (!frag && *pos == 0xffff) { return -EINVAL; } @@ -4045,9 +4045,9 @@ int net_rpl_revert_header(struct net_buf *buf, uint16_t offset, uint16_t *pos) *pos = revert_pos; /* Update flags, instance id, sender rank */ - frag = net_nbuf_write_u8(buf, frag, *pos, pos, flags); - frag = net_nbuf_write_u8(buf, frag, *pos, pos, instance_id); - frag = net_nbuf_write_be16(buf, frag, *pos, pos, sender_rank); + frag = net_pkt_write_u8(buf, frag, *pos, pos, flags); + frag = net_pkt_write_u8(buf, frag, *pos, pos, instance_id); + frag = net_pkt_write_be16(buf, frag, *pos, pos, sender_rank); if (!frag && *pos == 0xffff) { return -EINVAL; } diff --git a/subsys/net/ip/tcp.c b/subsys/net/ip/tcp.c index deb4a3f29..cc58c395b 100644 --- a/subsys/net/ip/tcp.c +++ b/subsys/net/ip/tcp.c @@ -23,7 +23,7 @@ #include <errno.h> #include <stdbool.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_ip.h> #include <net/net_context.h> #include <misc/byteorder.h> @@ -119,11 +119,11 @@ static inline uint32_t retry_timeout(const struct net_tcp *tcp) } #define is_6lo_technology(buf) \ - (IS_ENABLED(CONFIG_NET_IPV6) && net_nbuf_family(buf) == AF_INET6 && \ + (IS_ENABLED(CONFIG_NET_IPV6) && net_pkt_family(buf) == AF_INET6 && \ ((IS_ENABLED(CONFIG_NET_L2_BLUETOOTH) && \ - net_nbuf_ll_dst(buf)->type == NET_LINK_BLUETOOTH) || \ + net_pkt_ll_dst(buf)->type == NET_LINK_BLUETOOTH) || \ (IS_ENABLED(CONFIG_NET_L2_IEEE802154) && \ - net_nbuf_ll_dst(buf)->type == NET_LINK_IEEE802154))) + net_pkt_ll_dst(buf)->type == NET_LINK_IEEE802154))) static inline void do_ref_if_needed(struct net_buf *buf) { @@ -134,7 +134,7 @@ static inline void do_ref_if_needed(struct net_buf *buf) * need to take a reference of it. See also net_tcp_send_buf(). */ if (!is_6lo_technology(buf)) { - buf = net_nbuf_ref(buf); + buf = net_pkt_ref(buf); } } @@ -155,7 +155,7 @@ static void tcp_retry_expired(struct k_timer *timer) do_ref_if_needed(buf); if (net_tcp_send_buf(buf) < 0 && !is_6lo_technology(buf)) { - net_nbuf_unref(buf); + net_pkt_unref(buf); } } else if (IS_ENABLED(CONFIG_NET_TCP_TIME_WAIT)) { if (tcp->fin_sent && tcp->fin_rcvd) { @@ -211,7 +211,7 @@ int net_tcp_release(struct net_tcp *tcp) SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&tcp->sent_list, buf, tmp, sent_list) { sys_slist_remove(&tcp->sent_list, NULL, &buf->sent_list); - net_nbuf_unref(buf); + net_pkt_unref(buf); } k_delayed_work_cancel(&tcp->ack_timer); @@ -250,12 +250,12 @@ static inline uint8_t net_tcp_add_options(struct net_buf *header, size_t len, static int finalize_segment(struct net_context *context, struct net_buf *buf) { #if defined(CONFIG_NET_IPV4) - if (net_nbuf_family(buf) == AF_INET) { + if (net_pkt_family(buf) == AF_INET) { return net_ipv4_finalize(context, buf); } else #endif #if defined(CONFIG_NET_IPV6) - if (net_nbuf_family(buf) == AF_INET6) { + if (net_pkt_family(buf) == AF_INET6) { return net_ipv6_finalize(context, buf); } #endif @@ -279,18 +279,18 @@ static struct net_buf *prepare_segment(struct net_tcp *tcp, if (buf) { /* TCP transmit data comes in with a pre-allocated - * nbuf at the head (so that net_context_send can find + * net_pkt at the head (so that net_context_send can find * the context), and the data after. Rejigger so we * can insert a TCP header cleanly */ tail = buf->frags; buf->frags = NULL; } else { - buf = net_nbuf_get_tx(context, K_FOREVER); + buf = net_pkt_get_tx(context, K_FOREVER); } #if defined(CONFIG_NET_IPV4) - if (net_nbuf_family(buf) == AF_INET) { + if (net_pkt_family(buf) == AF_INET) { net_ipv4_create(context, buf, net_sin_ptr(segment->src_addr)->sin_addr, &(net_sin(segment->dst_addr)->sin_addr)); @@ -301,7 +301,7 @@ static struct net_buf *prepare_segment(struct net_tcp *tcp, } else #endif #if defined(CONFIG_NET_IPV6) - if (net_nbuf_family(buf) == AF_INET6) { + if (net_pkt_family(buf) == AF_INET6) { net_ipv6_create(tcp->context, buf, net_sin6_ptr(segment->src_addr)->sin6_addr, &(net_sin6(segment->dst_addr)->sin6_addr)); @@ -313,12 +313,12 @@ static struct net_buf *prepare_segment(struct net_tcp *tcp, #endif { NET_DBG("Protocol family %d not supported", - net_nbuf_family(buf)); - net_nbuf_unref(buf); + net_pkt_family(buf)); + net_pkt_unref(buf); return NULL; } - header = net_nbuf_get_data(context, K_FOREVER); + header = net_pkt_get_data(context, K_FOREVER); net_buf_frag_add(buf, header); tcphdr = (struct net_tcp_hdr *)net_buf_add(header, NET_TCPH_LEN); @@ -344,7 +344,7 @@ static struct net_buf *prepare_segment(struct net_tcp *tcp, } if (finalize_segment(context, buf) < 0) { - net_nbuf_unref(buf); + net_pkt_unref(buf); return NULL; } @@ -663,7 +663,7 @@ int net_tcp_queue_data(struct net_context *context, struct net_buf *buf) int net_tcp_send_buf(struct net_buf *buf) { - struct net_context *ctx = net_nbuf_context(buf); + struct net_context *ctx = net_pkt_context(buf); struct net_tcp_hdr *tcphdr = NET_TCP_BUF(buf); sys_put_be32(ctx->tcp->send_ack, tcphdr->ack); @@ -683,7 +683,7 @@ int net_tcp_send_buf(struct net_buf *buf) ctx->tcp->sent_ack = ctx->tcp->send_ack; - net_nbuf_set_buf_sent(buf, true); + net_pkt_set_buf_sent(buf, true); /* We must have special handling for some network technologies that * tweak the IP protocol headers during packet sending. This happens @@ -713,10 +713,10 @@ int net_tcp_send_buf(struct net_buf *buf) } if (buf_in_slist) { - new_buf = net_nbuf_get_tx(ctx, K_FOREVER); + new_buf = net_pkt_get_tx(ctx, K_FOREVER); - new_buf->frags = net_nbuf_copy_all(buf, 0, K_FOREVER); - net_nbuf_copy_user_data(new_buf, buf); + new_buf->frags = net_pkt_copy_all(buf, 0, K_FOREVER); + net_pkt_copy_user_data(new_buf, buf); NET_DBG("Copied %zu bytes from %p to %p", net_buf_frags_len(new_buf), buf, new_buf); @@ -727,7 +727,7 @@ int net_tcp_send_buf(struct net_buf *buf) */ ret = net_send_data(new_buf); if (ret < 0) { - net_nbuf_unref(new_buf); + net_pkt_unref(new_buf); } return ret; @@ -765,10 +765,10 @@ int net_tcp_send_data(struct net_context *context) * add window handling and retry/ACK logic. */ SYS_SLIST_FOR_EACH_CONTAINER(&context->tcp->sent_list, buf, sent_list) { - if (!net_nbuf_buf_sent(buf)) { + if (!net_pkt_buf_sent(buf)) { if (net_tcp_send_buf(buf) < 0 && !is_6lo_technology(buf)) { - net_nbuf_unref(buf); + net_pkt_unref(buf); } } } @@ -791,7 +791,7 @@ void net_tcp_ack_received(struct net_context *ctx, uint32_t ack) buf = CONTAINER_OF(head, struct net_buf, sent_list); tcphdr = NET_TCP_BUF(buf); - seq = sys_get_be32(tcphdr->seq) + net_nbuf_appdatalen(buf) - 1; + seq = sys_get_be32(tcphdr->seq) + net_pkt_appdatalen(buf) - 1; if (!seq_greater(ack, seq)) { break; @@ -808,7 +808,7 @@ void net_tcp_ack_received(struct net_context *ctx, uint32_t ack) } sys_slist_remove(list, NULL, head); - net_nbuf_unref(buf); + net_pkt_unref(buf); valid_ack = true; } @@ -831,9 +831,9 @@ void net_tcp_ack_received(struct net_context *ctx, uint32_t ack) SYS_SLIST_FOR_EACH_CONTAINER(&ctx->tcp->sent_list, buf, sent_list) { - if (net_nbuf_buf_sent(buf)) { + if (net_pkt_buf_sent(buf)) { do_ref_if_needed(buf); - net_nbuf_set_buf_sent(buf, false); + net_pkt_set_buf_sent(buf, false); } } diff --git a/subsys/net/ip/tcp.h b/subsys/net/ip/tcp.h index fb7baa6d2..8c8ee184f 100644 --- a/subsys/net/ip/tcp.h +++ b/subsys/net/ip/tcp.h @@ -17,7 +17,7 @@ #include <net/net_core.h> #include <net/net_ip.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_context.h> #include "connection.h" @@ -70,7 +70,7 @@ enum net_tcp_state { #define NET_TCP_URG 0x20 #define NET_TCP_CTL 0x3f -#define NET_TCP_FLAGS(nbuf) (NET_TCP_BUF(nbuf)->flags & NET_TCP_CTL) +#define NET_TCP_FLAGS(net_pkt) (NET_TCP_BUF(net_pkt)->flags & NET_TCP_CTL) /* TCP max window size */ #define NET_TCP_MAX_WIN (4 * 1024) diff --git a/subsys/net/ip/udp.h b/subsys/net/ip/udp.h index 63a573686..92db38d4c 100644 --- a/subsys/net/ip/udp.h +++ b/subsys/net/ip/udp.h @@ -17,7 +17,7 @@ #include <net/net_core.h> #include <net/net_ip.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_context.h> #include "connection.h" @@ -46,10 +46,10 @@ static inline struct net_buf *net_udp_append_raw(struct net_buf *buf, net_buf_add(buf->frags, sizeof(struct net_udp_hdr)); NET_UDP_BUF(buf)->len = htons(net_buf_frags_len(buf) - - net_nbuf_ip_hdr_len(buf)); + net_pkt_ip_hdr_len(buf)); - net_nbuf_set_appdata(buf, net_nbuf_udp_data(buf) + - sizeof(struct net_udp_hdr)); + net_pkt_set_appdata(buf, net_pkt_udp_data(buf) + + sizeof(struct net_udp_hdr)); return buf; } diff --git a/subsys/net/ip/utils.c b/subsys/net/ip/utils.c index 85c75c395..491bbfead 100644 --- a/subsys/net/ip/utils.c +++ b/subsys/net/ip/utils.c @@ -21,7 +21,7 @@ #include <errno.h> #include <net/net_ip.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_core.h> const char *net_proto2str(enum net_ip_protocol proto) @@ -404,7 +404,8 @@ static inline uint16_t calc_chksum_buf(uint16_t sum, struct net_buf *buf, uint16_t upper_layer_len) { struct net_buf *frag = buf->frags; - uint16_t proto_len = net_nbuf_ip_hdr_len(buf) + net_nbuf_ext_len(buf); + uint16_t proto_len = net_pkt_ip_hdr_len(buf) + + net_pkt_ext_len(buf); int16_t len = frag->len - proto_len; uint8_t *ptr = frag->data + proto_len; @@ -447,17 +448,17 @@ uint16_t net_calc_chksum(struct net_buf *buf, uint8_t proto) uint16_t upper_layer_len; uint16_t sum; - switch (net_nbuf_family(buf)) { + switch (net_pkt_family(buf)) { #if defined(CONFIG_NET_IPV4) case AF_INET: upper_layer_len = (NET_IPV4_BUF(buf)->len[0] << 8) + NET_IPV4_BUF(buf)->len[1] - - net_nbuf_ext_len(buf) - - net_nbuf_ip_hdr_len(buf); + net_pkt_ext_len(buf) - + net_pkt_ip_hdr_len(buf); if (proto == IPPROTO_ICMP) { - return htons(calc_chksum(0, net_nbuf_ip_data(buf) + - net_nbuf_ip_hdr_len(buf), + return htons(calc_chksum(0, net_pkt_ip_data(buf) + + net_pkt_ip_hdr_len(buf), upper_layer_len)); } else { sum = calc_chksum(upper_layer_len + proto, @@ -469,14 +470,14 @@ uint16_t net_calc_chksum(struct net_buf *buf, uint8_t proto) #if defined(CONFIG_NET_IPV6) case AF_INET6: upper_layer_len = (NET_IPV6_BUF(buf)->len[0] << 8) + - NET_IPV6_BUF(buf)->len[1] - net_nbuf_ext_len(buf); + NET_IPV6_BUF(buf)->len[1] - net_pkt_ext_len(buf); sum = calc_chksum(upper_layer_len + proto, (uint8_t *)&NET_IPV6_BUF(buf)->src, 2 * sizeof(struct in6_addr)); break; #endif default: - NET_DBG("Unknown protocol family %d", net_nbuf_family(buf)); + NET_DBG("Unknown protocol family %d", net_pkt_family(buf)); return 0; } diff --git a/subsys/net/lib/dns/resolve.c b/subsys/net/lib/dns/resolve.c index 3a13428a2..da4efc477 100644 --- a/subsys/net/lib/dns/resolve.c +++ b/subsys/net/lib/dns/resolve.c @@ -21,7 +21,7 @@ #include <stdlib.h> #include <net/net_ip.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/dns_resolve.h> #include "dns_pack.h" @@ -377,12 +377,12 @@ static int dns_read(struct dns_resolve_context *ctx, int ret; int server_idx, query_idx; - data_len = min(net_nbuf_appdatalen(buf), DNS_RESOLVER_MAX_BUF_SIZE); + data_len = min(net_pkt_appdatalen(buf), DNS_RESOLVER_MAX_BUF_SIZE); offset = net_buf_frags_len(buf) - data_len; /* TODO: Instead of this temporary copy, just use the net_buf directly. */ - ret = net_nbuf_linear_copy(dns_data, buf, offset, data_len); + ret = net_pkt_linear_copy(dns_data, buf, offset, data_len); if (ret < 0) { ret = DNS_EAI_MEMORY; goto quit; @@ -526,7 +526,7 @@ static int dns_read(struct dns_resolve_context *ctx, ctx->queries[query_idx].cb = NULL; - net_nbuf_unref(buf); + net_pkt_unref(buf); return 0; @@ -534,7 +534,7 @@ finished: dns_resolve_cancel(ctx, *dns_id); quit: - net_nbuf_unref(buf); + net_pkt_unref(buf); return ret; } @@ -661,13 +661,13 @@ static int dns_write(struct dns_resolve_context *ctx, goto quit; } - buf = net_nbuf_get_tx(net_ctx, ctx->buf_timeout); + buf = net_pkt_get_tx(net_ctx, ctx->buf_timeout); if (!buf) { ret = -ENOMEM; goto quit; } - ret = net_nbuf_append(buf, dns_data->len, dns_data->data, + ret = net_pkt_append(buf, dns_data->len, dns_data->data, ctx->buf_timeout); if (ret < 0) { ret = -ENOMEM; @@ -686,7 +686,7 @@ static int dns_write(struct dns_resolve_context *ctx, K_NO_WAIT, NULL, NULL); if (ret < 0) { NET_DBG("Cannot send query (%d)", ret); - net_nbuf_unref(buf); + net_pkt_unref(buf); goto quit; } diff --git a/subsys/net/lib/http/http_client.c b/subsys/net/lib/http/http_client.c index b9ec29381..71d3642e4 100644 --- a/subsys/net/lib/http/http_client.c +++ b/subsys/net/lib/http/http_client.c @@ -6,7 +6,7 @@ #include <net/http.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <misc/printk.h> /* HTTP client defines */ @@ -22,42 +22,42 @@ int http_request(struct net_context *net_ctx, int32_t timeout, struct net_buf *tx; int rc = -ENOMEM; - tx = net_nbuf_get_tx(net_ctx, timeout); + tx = net_pkt_get_tx(net_ctx, timeout); if (!tx) { return -ENOMEM; } - if (!net_nbuf_append(tx, strlen(req->method), (uint8_t *)req->method, - timeout)) { + if (!net_pkt_append(tx, strlen(req->method), (uint8_t *)req->method, + timeout)) { goto lb_exit; } - if (!net_nbuf_append(tx, strlen(req->url), (uint8_t *)req->url, - timeout)) { + if (!net_pkt_append(tx, strlen(req->url), (uint8_t *)req->url, + timeout)) { goto lb_exit; } - if (!net_nbuf_append(tx, strlen(req->protocol), - (uint8_t *)req->protocol, timeout)) { + if (!net_pkt_append(tx, strlen(req->protocol), + (uint8_t *)req->protocol, timeout)) { goto lb_exit; } - if (!net_nbuf_append(tx, strlen(req->header_fields), - (uint8_t *)req->header_fields, - timeout)) { + if (!net_pkt_append(tx, strlen(req->header_fields), + (uint8_t *)req->header_fields, + timeout)) { goto lb_exit; } if (req->content_type_value) { - if (!net_nbuf_append(tx, strlen(HTTP_CONTENT_TYPE), - (uint8_t *)HTTP_CONTENT_TYPE, - timeout)) { + if (!net_pkt_append(tx, strlen(HTTP_CONTENT_TYPE), + (uint8_t *)HTTP_CONTENT_TYPE, + timeout)) { goto lb_exit; } - if (!net_nbuf_append(tx, strlen(req->content_type_value), - (uint8_t *)req->content_type_value, - timeout)) { + if (!net_pkt_append(tx, strlen(req->content_type_value), + (uint8_t *)req->content_type_value, + timeout)) { goto lb_exit; } } @@ -73,23 +73,23 @@ int http_request(struct net_context *net_ctx, int32_t timeout, goto lb_exit; } - if (!net_nbuf_append(tx, rc, (uint8_t *)content_len_str, - timeout)) { + if (!net_pkt_append(tx, rc, (uint8_t *)content_len_str, + timeout)) { rc = -ENOMEM; goto lb_exit; } - if (!net_nbuf_append(tx, req->payload_size, - (uint8_t *)req->payload, - timeout)) { + if (!net_pkt_append(tx, req->payload_size, + (uint8_t *)req->payload, + timeout)) { rc = -ENOMEM; goto lb_exit; } } else { - if (!net_nbuf_append(tx, strlen(HTTP_EOF), - (uint8_t *)HTTP_EOF, - timeout)) { + if (!net_pkt_append(tx, strlen(HTTP_EOF), + (uint8_t *)HTTP_EOF, + timeout)) { goto lb_exit; } } diff --git a/subsys/net/lib/http/http_server.c b/subsys/net/lib/http/http_server.c index df866fd10..18589e3dc 100644 --- a/subsys/net/lib/http/http_server.c +++ b/subsys/net/lib/http/http_server.c @@ -6,7 +6,7 @@ #include <net/http.h> #include <misc/printk.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_context.h> #define HTTP_STATUS_200_OK "HTTP/1.1 200 OK\r\n" \ @@ -34,7 +34,7 @@ static inline uint16_t http_strlen(const char *str) static int http_add_header(struct net_buf *tx, int32_t timeout, const char *str) { - if (net_nbuf_append(tx, strlen(str), (uint8_t *)str, timeout)) { + if (net_pkt_append(tx, strlen(str), (uint8_t *)str, timeout)) { return 0; } @@ -51,17 +51,17 @@ static int http_add_chunk(struct net_buf *tx, int32_t timeout, const char *str) snprintk(chunk_header, sizeof(chunk_header), "%x\r\n", str_len); - if (!net_nbuf_append(tx, strlen(chunk_header), chunk_header, timeout)) { + if (!net_pkt_append(tx, strlen(chunk_header), chunk_header, timeout)) { return -ENOMEM; } if (str_len > 0) { - if (!net_nbuf_append(tx, str_len, (uint8_t *)str, timeout)) { + if (!net_pkt_append(tx, str_len, (uint8_t *)str, timeout)) { return -ENOMEM; } } - if (!net_nbuf_append(tx, strlen(rn), rn, timeout)) { + if (!net_pkt_append(tx, strlen(rn), rn, timeout)) { return -ENOMEM; } @@ -74,7 +74,7 @@ int http_response(struct http_server_ctx *ctx, const char *http_header, struct net_buf *tx; int rc = -EINVAL; - tx = net_nbuf_get_tx(ctx->net_ctx, ctx->timeout); + tx = net_pkt_get_tx(ctx->net_ctx, ctx->timeout); if (!tx) { goto exit_routine; } @@ -106,7 +106,7 @@ int http_response(struct http_server_ctx *ctx, const char *http_header, exit_routine: /* unref can handle NULL buffers, so we are covered */ - net_nbuf_unref(tx); + net_pkt_unref(tx); return rc; } diff --git a/subsys/net/lib/mqtt/mqtt.c b/subsys/net/lib/mqtt/mqtt.c index a6500bc9e..86da072a9 100644 --- a/subsys/net/lib/mqtt/mqtt.c +++ b/subsys/net/lib/mqtt/mqtt.c @@ -8,7 +8,7 @@ #include "mqtt_pkt.h" #include <net/net_ip.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/buf.h> #include <errno.h> @@ -43,7 +43,7 @@ int mqtt_tx_connect(struct mqtt_ctx *ctx, struct mqtt_connect_msg *msg) goto exit_connect; } - tx = net_nbuf_get_tx(ctx->net_ctx, ctx->net_timeout); + tx = net_pkt_get_tx(ctx->net_ctx, ctx->net_timeout); if (tx == NULL) { rc = -ENOMEM; goto exit_connect; @@ -61,8 +61,8 @@ int mqtt_tx_connect(struct mqtt_ctx *ctx, struct mqtt_connect_msg *msg) tx = NULL; exit_connect: - net_nbuf_unref(data); - net_nbuf_unref(tx); + net_pkt_unref(data); + net_pkt_unref(tx); return rc; } @@ -81,13 +81,13 @@ int mqtt_tx_disconnect(struct mqtt_ctx *ctx) goto exit_disconnect; } - tx = net_nbuf_get_tx(ctx->net_ctx, ctx->net_timeout); + tx = net_pkt_get_tx(ctx->net_ctx, ctx->net_timeout); if (tx == NULL) { rc = -ENOMEM; goto exit_disconnect; } - rc = net_nbuf_append(tx, len, msg, ctx->net_timeout); + rc = net_pkt_append(tx, len, msg, ctx->net_timeout); if (rc != true) { rc = -ENOMEM; goto exit_disconnect; @@ -107,7 +107,7 @@ int mqtt_tx_disconnect(struct mqtt_ctx *ctx) } exit_disconnect: - net_nbuf_unref(tx); + net_pkt_unref(tx); return rc; } @@ -154,13 +154,13 @@ int mqtt_tx_pub_msgs(struct mqtt_ctx *ctx, uint16_t id, return -EINVAL; } - tx = net_nbuf_get_tx(ctx->net_ctx, ctx->net_timeout); + tx = net_pkt_get_tx(ctx->net_ctx, ctx->net_timeout); if (tx == NULL) { rc = -ENOMEM; goto exit_send; } - rc = net_nbuf_append(tx, len, msg, ctx->net_timeout); + rc = net_pkt_append(tx, len, msg, ctx->net_timeout); if (rc != true) { rc = -ENOMEM; goto exit_send; @@ -175,7 +175,7 @@ int mqtt_tx_pub_msgs(struct mqtt_ctx *ctx, uint16_t id, tx = NULL; exit_send: - net_nbuf_unref(tx); + net_pkt_unref(tx); return rc; } @@ -218,7 +218,7 @@ int mqtt_tx_publish(struct mqtt_ctx *ctx, struct mqtt_publish_msg *msg) goto exit_publish; } - tx = net_nbuf_get_tx(ctx->net_ctx, ctx->net_timeout); + tx = net_pkt_get_tx(ctx->net_ctx, ctx->net_timeout); if (tx == NULL) { rc = -ENOMEM; goto exit_publish; @@ -236,8 +236,8 @@ int mqtt_tx_publish(struct mqtt_ctx *ctx, struct mqtt_publish_msg *msg) tx = NULL; exit_publish: - net_nbuf_unref(data); - net_nbuf_unref(tx); + net_pkt_unref(data); + net_pkt_unref(tx); return rc; } @@ -255,13 +255,13 @@ int mqtt_tx_pingreq(struct mqtt_ctx *ctx) goto exit_pingreq; } - tx = net_nbuf_get_tx(ctx->net_ctx, ctx->net_timeout); + tx = net_pkt_get_tx(ctx->net_ctx, ctx->net_timeout); if (tx == NULL) { rc = -ENOMEM; goto exit_pingreq; } - rc = net_nbuf_append(tx, len, msg, ctx->net_timeout); + rc = net_pkt_append(tx, len, msg, ctx->net_timeout); if (rc != true) { rc = -ENOMEM; goto exit_pingreq; @@ -276,7 +276,7 @@ int mqtt_tx_pingreq(struct mqtt_ctx *ctx) tx = NULL; exit_pingreq: - net_nbuf_unref(tx); + net_pkt_unref(tx); return rc; } @@ -297,12 +297,12 @@ int mqtt_tx_subscribe(struct mqtt_ctx *ctx, uint16_t pkt_id, uint8_t items, rc = mqtt_pack_subscribe(data->data, &data->len, data->size, pkt_id, items, topics, qos); if (rc != 0) { - net_nbuf_unref(data); + net_pkt_unref(data); rc = -EINVAL; goto exit_subs; } - tx = net_nbuf_get_tx(ctx->net_ctx, ctx->net_timeout); + tx = net_pkt_get_tx(ctx->net_ctx, ctx->net_timeout); if (tx == NULL) { rc = -ENOMEM; goto exit_subs; @@ -320,8 +320,8 @@ int mqtt_tx_subscribe(struct mqtt_ctx *ctx, uint16_t pkt_id, uint8_t items, tx = NULL; exit_subs: - net_nbuf_unref(data); - net_nbuf_unref(tx); + net_pkt_unref(data); + net_pkt_unref(tx); return rc; } @@ -346,7 +346,7 @@ int mqtt_tx_unsubscribe(struct mqtt_ctx *ctx, uint16_t pkt_id, uint8_t items, goto exit_unsub; } - tx = net_nbuf_get_tx(ctx->net_ctx, ctx->net_timeout); + tx = net_pkt_get_tx(ctx->net_ctx, ctx->net_timeout); if (tx == NULL) { rc = -ENOMEM; goto exit_unsub; @@ -652,7 +652,7 @@ struct net_buf *mqtt_linearize_buffer(struct mqtt_ctx *ctx, struct net_buf *rx, * determined if the input buffer could fit our data buffer or if * it has the expected size. */ - data_len = net_nbuf_appdatalen(rx); + data_len = net_pkt_appdatalen(rx); if (data_len < min_size || data_len > CONFIG_MQTT_MSG_MAX_SIZE) { return NULL; } @@ -663,7 +663,7 @@ struct net_buf *mqtt_linearize_buffer(struct mqtt_ctx *ctx, struct net_buf *rx, } offset = net_buf_frags_len(rx) - data_len; - rc = net_nbuf_linear_copy(data, rx, offset, data_len); + rc = net_pkt_linear_copy(data, rx, offset, data_len); if (rc != 0) { goto exit_error; } @@ -671,7 +671,7 @@ struct net_buf *mqtt_linearize_buffer(struct mqtt_ctx *ctx, struct net_buf *rx, return data; exit_error: - net_nbuf_unref(data); + net_pkt_unref(data); return NULL; } @@ -736,7 +736,7 @@ exit_parser: ctx->malformed(ctx, pkt_type); } - net_nbuf_unref(data); + net_pkt_unref(data); return rc; } @@ -803,7 +803,7 @@ exit_parser: ctx->malformed(ctx, pkt_type); } - net_nbuf_unref(data); + net_pkt_unref(data); return rc; } @@ -821,14 +821,14 @@ void mqtt_recv(struct net_context *net_ctx, struct net_buf *buf, int status, return; } - if (net_nbuf_appdatalen(buf) == 0) { + if (net_pkt_appdatalen(buf) == 0) { goto lb_exit; } mqtt->rcv(mqtt, buf); lb_exit: - net_nbuf_unref(buf); + net_pkt_unref(buf); } int mqtt_init(struct mqtt_ctx *ctx, enum mqtt_app app_type) diff --git a/subsys/net/lib/zoap/zoap.c b/subsys/net/lib/zoap/zoap.c index 8197c5548..396866b23 100644 --- a/subsys/net/lib/zoap/zoap.c +++ b/subsys/net/lib/zoap/zoap.c @@ -13,7 +13,7 @@ #include <misc/byteorder.h> #include <net/buf.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <net/net_ip.h> #include <net/zoap.h> @@ -472,7 +472,7 @@ bool zoap_pending_cycle(struct zoap_pending *pending) * When it it is the last retransmission, the buffer * will be destroyed when it is transmitted. */ - net_nbuf_ref(pending->buf); + net_pkt_ref(pending->buf); } return cont; @@ -481,7 +481,7 @@ bool zoap_pending_cycle(struct zoap_pending *pending) void zoap_pending_clear(struct zoap_pending *pending) { pending->timeout = 0; - net_nbuf_unref(pending->buf); + net_pkt_unref(pending->buf); pending->buf = NULL; } diff --git a/subsys/net/lib/zoap/zoap_link_format.c b/subsys/net/lib/zoap/zoap_link_format.c index 60ffaf887..ce845832c 100644 --- a/subsys/net/lib/zoap/zoap_link_format.c +++ b/subsys/net/lib/zoap/zoap_link_format.c @@ -13,7 +13,7 @@ #include <misc/byteorder.h> #include <net/buf.h> -#include <net/nbuf.h> +#include <net/net_pkt.h> #include <misc/printk.h> @@ -229,16 +229,16 @@ static int send_error_response(struct zoap_resource *resource, id = zoap_header_get_id(request); - context = net_nbuf_context(request->buf); + context = net_pkt_context(request->buf); - buf = net_nbuf_get_tx(context, K_FOREVER); + buf = net_pkt_get_tx(context, K_FOREVER); if (!buf) { return -ENOMEM; } - frag = net_nbuf_get_data(context, K_FOREVER); + frag = net_pkt_get_data(context, K_FOREVER); if (!frag) { - net_nbuf_unref(buf); + net_pkt_unref(buf); return -ENOMEM; } @@ -246,7 +246,7 @@ static int send_error_response(struct zoap_resource *resource, r = zoap_packet_init(&response, buf); if (r < 0) { - net_nbuf_unref(buf); + net_pkt_unref(buf); return r; } @@ -259,7 +259,7 @@ static int send_error_response(struct zoap_resource *resource, r = net_context_sendto(buf, from, sizeof(struct sockaddr_in6), NULL, 0, NULL, NULL); if (r < 0) { - net_nbuf_unref(buf); + net_pkt_unref(buf); } return r; @@ -293,16 +293,16 @@ int _zoap_well_known_core_get(struct zoap_resource *resource, num_queries = r; - context = net_nbuf_context(request->buf); + context = net_pkt_context(request->buf); - buf = net_nbuf_get_tx(context, K_FOREVER); + buf = net_pkt_get_tx(context, K_FOREVER); if (!buf) { return -ENOMEM; } - frag = net_nbuf_get_data(context, K_FOREVER); + frag = net_pkt_get_data(context, K_FOREVER); if (!frag) { - net_nbuf_unref(buf); + net_pkt_unref(buf); return -ENOMEM; } @@ -323,7 +323,7 @@ int _zoap_well_known_core_get(struct zoap_resource *resource, r = zoap_add_option(&response, ZOAP_OPTION_CONTENT_FORMAT, &format, sizeof(format)); if (r < 0) { - net_nbuf_unref(buf); + net_pkt_unref(buf); return -EINVAL; } @@ -347,9 +347,9 @@ int _zoap_well_known_core_get(struct zoap_resource *resource, *str = 0xFF; response.start = str + 1; } else { - temp = net_nbuf_get_data(context, K_FOREVER); + temp = net_pkt_get_data(context, K_FOREVER); if (!temp) { - net_nbuf_unref(buf); + net_pkt_unref(buf); return -ENOMEM; } @@ -362,18 +362,18 @@ int _zoap_well_known_core_get(struct zoap_resource *resource, } } - net_nbuf_compact(buf); + net_pkt_compact(buf); done: if (r < 0) { - net_nbuf_unref(buf); + net_pkt_unref(buf); return send_error_response(resource, request, from); } r = net_context_sendto(buf, from, sizeof(struct sockaddr_in6), NULL, 0, NULL, NULL); if (r < 0) { - net_nbuf_unref(buf); + net_pkt_unref(buf); } return r; |