Commit bf964cdd authored by Tomasz Bursztyka's avatar Tomasz Bursztyka Committed by Jukka Rissanen
Browse files

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: default avatarTomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
parent 9bf3ea07
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@

#include <zephyr.h>

#include <net/nbuf.h>
#include <net/net_pkt.h>
#include <net/net_core.h>
#include <net/net_context.h>

@@ -93,9 +93,9 @@ static struct net_buf *udp_recv(const char *name,
	int header_len, recv_len, reply_len;

	NET_INFO("%s received %u bytes", name,
	      net_nbuf_appdatalen(buf));
	      net_pkt_appdatalen(buf));

	reply_buf = net_nbuf_get_tx(context, K_FOREVER);
	reply_buf = net_pkt_get_tx(context, K_FOREVER);

	NET_ASSERT(reply_buf);

@@ -106,14 +106,14 @@ static struct net_buf *udp_recv(const char *name,
	/* First fragment will contain IP header so move the data
	 * down in order to get rid of it.
	 */
	header_len = net_nbuf_appdata(buf) - tmp->data;
	header_len = net_pkt_appdata(buf) - tmp->data;

	NET_ASSERT(header_len < CONFIG_NET_NBUF_DATA_SIZE);
	NET_ASSERT(header_len < CONFIG_NET_BUF_DATA_SIZE);

	net_buf_pull(tmp, header_len);

	while (tmp) {
		frag = net_nbuf_get_data(context, K_FOREVER);
		frag = net_pkt_get_data(context, K_FOREVER);

		memcpy(net_buf_add(frag, tmp->len), tmp->data, tmp->len);

@@ -162,7 +162,7 @@ static void udp_received(struct net_context *context,
{
	struct net_buf *reply_buf;
	struct sockaddr dst_addr;
	sa_family_t family = net_nbuf_family(buf);
	sa_family_t family = net_pkt_family(buf);
	static char dbg[MAX_DBG_PRINT + 1];
	int ret;

@@ -173,7 +173,7 @@ static void udp_received(struct net_context *context,

	reply_buf = udp_recv(dbg, context, buf);

	net_nbuf_unref(buf);
	net_pkt_unref(buf);

	ret = net_context_sendto(reply_buf, &dst_addr, udp_sent, 0,
				 UINT_TO_POINTER(net_buf_frags_len(reply_buf)),
@@ -181,7 +181,7 @@ static void udp_received(struct net_context *context,
	if (ret < 0) {
		NET_ERR("Cannot send data to peer (%d)", ret);

		net_nbuf_unref(reply_buf);
		net_pkt_unref(reply_buf);

		quit();
	}
+1 −1
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ connectivity APIs, following things will happen.
4) The application will then receive the data, which is stored inside a chain
   of net_bufs. The application now owns the data. After it has finished working
   with it, the application should release the net_bufs data by calling
   `net_nbuf_unref()`.
   `net_pkt_unref()`.

*Data sending (TX):*

+7 −7
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ how the L2 layer is supposed to behave. The generic L2 API has 3
functions:

- recv: All device drivers, once they receive a packet which they put
  into a :c:type:`struct net_nbuf`, will push this buffer to the IP
  into a :c:type:`struct net_pkt`, will push this buffer to the IP
  core stack via :c:func:`net_recv_data()`. At this point, the IP core
  stack does not know what to do with it. Instead, it passes the
  buffer along to the L2 stack's recv() function for handling. The L2
@@ -77,12 +77,12 @@ Ethernet device driver

On reception, it is up to the device driver to fill-in the buffer with
as many data fragments as required. The buffer itself is a
:c:type:`struct net_nbuf` and should be allocated through
:c:func:`net_nbuf_get_reserve_rx(0)`. Then all fragments will be
allocated through :c:func:`net_nbuf_get_reserve_data(0)`. Of course
:c:type:`struct net_pkt` and should be allocated through
:c:func:`net_pkt_get_reserve_rx(0)`. Then all fragments will be
allocated through :c:func:`net_pkt_get_reserve_data(0)`. Of course
the amount of required fragments depends on the size of the received
packet and on the size of a fragment, which is given by
`CONFIG_NET_NBUF_DATA_SIZE`.
`CONFIG_NET_PKT_DATA_SIZE`.

Note that it is not up to the device driver to decide on the
link-layer space to be reserved in the buffer. Hence the 0 given as
@@ -91,13 +91,13 @@ once the packet's Ethernet header has been successfully parsed.

In case :c:func:`net_recv_data()` call fails, it will be up to the
device driver to un-reference the buffer via
:c:func:`net_nbuf_unref()`.
:c:func:`net_pkt_unref()`.

On sending, it is up to the device driver to send the buffer all at
once, with all the fragments.

In case of a fully successful packet transmission only, the device
driver must un-reference the buffer via `net_nbuf_unref()`.
driver must un-reference the buffer via `net_pkt_unref()`.

Each Ethernet device driver will need, in the end, to call
`NET_DEVICE_INIT_INSTANCE()` like this:
+8 −8
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@

#include <console/console.h>
#include <net/buf.h>
#include <net/nbuf.h>
#include <net/net_pkt.h>
#include <net/net_ip.h>
#include <net/net_context.h>

@@ -125,9 +125,9 @@ static void telnet_end_client_connection(void)

static int telnet_setup_out_buf(struct net_context *client)
{
	out_buf = net_nbuf_get_tx(client, K_FOREVER);
	out_buf = net_pkt_get_tx(client, K_FOREVER);
	if (!out_buf) {
		/* Cannot happen atm, nbuf waits indefinitely */
		/* Cannot happen atm, net_pkt waits indefinitely */
		return -ENOBUFS;
	}

@@ -234,7 +234,7 @@ static inline bool telnet_send(void)
	struct line_buf *lb = telnet_rb_get_line_out();

	if (lb) {
		net_nbuf_append(out_buf, lb->len, lb->buf, K_FOREVER);
		net_pkt_append(out_buf, lb->len, lb->buf, K_FOREVER);

		/* We reinitialize the line buffer */
		lb->len = 0;
@@ -258,7 +258,7 @@ static int telnet_console_out_nothing(int c)

static inline void telnet_command_send_reply(uint8_t *msg, uint16_t len)
{
	net_nbuf_append(out_buf, len, msg, K_FOREVER);
	net_pkt_append(out_buf, len, msg, K_FOREVER);

	net_context_send(out_buf, telnet_sent_cb,
			 K_NO_WAIT, NULL, NULL);
@@ -329,7 +329,7 @@ out:
static inline bool telnet_handle_command(struct net_buf *buf)
{
	struct telnet_simple_command *cmd =
		(struct telnet_simple_command *)net_nbuf_appdata(buf);
		(struct telnet_simple_command *)net_pkt_appdata(buf);

	if (cmd->iac != NVT_CMD_IAC) {
		return false;
@@ -356,7 +356,7 @@ static inline void telnet_handle_input(struct net_buf *buf)
	struct console_input *input;
	uint16_t len, offset, pos;

	len = net_nbuf_appdatalen(buf);
	len = net_pkt_appdatalen(buf);
	if (len > CONSOLE_MAX_LINE_LEN || len < TELNET_MIN_MSG) {
		return;
	}
@@ -375,7 +375,7 @@ static inline void telnet_handle_input(struct net_buf *buf)
	}

	offset = net_buf_frags_len(buf) - len;
	net_nbuf_read(buf->frags, offset, &pos, len, input->line);
	net_pkt_read(buf->frags, offset, &pos, len, input->line);

	/* LF/CR will be removed if only the line is not NUL terminated */
	if (input->line[len-1] != NVT_NUL) {
+6 −6
Original line number Diff line number Diff line
@@ -20,18 +20,18 @@ config ETH_SAM_GMAC_NAME
	  Device name allows user to obtain a handle to the device object
	  required by all driver API functions. Device name has to be unique.

config ETH_SAM_GMAC_NBUF_RX_DATA_COUNT
	int "Network RX data buffers pre-allocated by the SAM ETH driver"
config ETH_SAM_GMAC_BUF_RX_COUNT
	int "Network RX buffers pre-allocated by the SAM ETH driver"
	default 18
	help
	  Number of network data buffers that will be permanently allocated by the
	  Ethernet driver. These data buffers are used in receive path. They are
	  Number of network buffers that will be permanently allocated by the
	  Ethernet driver. These buffers are used in receive path. They are
	  pre-alocated by the driver and made available to the GMAC module to be
	  filled in with incoming data. Their number has to be large enough to fit
	  at least one complete Ethernet frame. SAM ETH driver will always allocate
	  that amount of buffers for itself thus reducing the NET_NBUF_RX_DATA_COUNT
	  that amount of buffers for itself thus reducing the NET_BUF_RX_COUNT
	  which is a total amount of RX data buffers used by the whole networking
	  stack. One has to ensure that NET_NBUF_RX_DATA_COUNT is large enough to
	  stack. One has to ensure that NET_PKT_RX_COUNT is large enough to
	  fit at least two ethernet frames: one being received by the GMAC module
	  and the other being processed by the higer layer networking stack.

Loading