Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions include/zephyr/net_buf.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ extern "C" {
.__buf = net_buf_data_##_name, \
}

#if defined(CONFIG_NET_BUF_LARGE_SIZE)
/** @brief net buf size type */
typedef uint32_t net_buf_size_t;
#else
/** @brief net buf size type */
typedef uint16_t net_buf_size_t;
#endif

/**
* @brief Simple network buffer representation.
*
Expand All @@ -95,10 +103,10 @@ struct net_buf_simple {
*
* To determine the max length, use net_buf_simple_max_len(), not #size!
*/
uint16_t len;
net_buf_size_t len;

/** Amount of data that net_buf_simple#__buf can store. */
uint16_t size;
net_buf_size_t size;

/** Start of the data storage. Not to be accessed directly
* (the data pointer should be used instead).
Expand Down Expand Up @@ -938,7 +946,7 @@ size_t net_buf_simple_tailroom(const struct net_buf_simple *buf);
*
* @return Number of bytes usable behind the net_buf_simple::data pointer.
*/
uint16_t net_buf_simple_max_len(const struct net_buf_simple *buf);
size_t net_buf_simple_max_len(const struct net_buf_simple *buf);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in a separate commit, with the commit message explaining that it's just aligning this with the rest of the net_buf APIs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still a breaking API change, though.


/**
* @brief Parsing state of a buffer.
Expand All @@ -949,9 +957,9 @@ uint16_t net_buf_simple_max_len(const struct net_buf_simple *buf);
*/
struct net_buf_simple_state {
/** Offset of the data pointer from the beginning of the storage */
uint16_t offset;
net_buf_size_t offset;
/** Length of data */
uint16_t len;
net_buf_size_t len;
};

/**
Expand All @@ -965,7 +973,7 @@ struct net_buf_simple_state {
static inline void net_buf_simple_save(const struct net_buf_simple *buf,
struct net_buf_simple_state *state)
{
state->offset = (uint16_t)net_buf_simple_headroom(buf);
state->offset = (net_buf_size_t)net_buf_simple_headroom(buf);
state->len = buf->len;
}

Expand Down Expand Up @@ -1032,10 +1040,10 @@ struct net_buf {
uint8_t *data;

/** Length of the data behind the data pointer. */
uint16_t len;
net_buf_size_t len;

/** Amount of data that this buffer can store. */
uint16_t size;
net_buf_size_t size;

/** Start of the data storage. Not to be accessed
* directly (the data pointer should be used
Expand Down Expand Up @@ -1097,7 +1105,7 @@ struct net_buf_pool {
atomic_t avail_count;

/** Total size of the pool. */
const uint16_t pool_size;
const net_buf_size_t pool_size;

/** Maximum count of used buffers. */
uint16_t max_used;
Expand Down Expand Up @@ -2523,7 +2531,7 @@ static inline size_t net_buf_headroom(const struct net_buf *buf)
*
* @return Number of bytes usable behind the net_buf::data pointer.
*/
static inline uint16_t net_buf_max_len(const struct net_buf *buf)
static inline size_t net_buf_max_len(const struct net_buf *buf)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{
return net_buf_simple_max_len(&buf->b);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/net_buf/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ config NET_BUF_ALIGNMENT
Default value of 0 means the alignment will be the size of a void pointer,
any other value will force the alignment of a net buffer in bytes.

config NET_BUF_LARGE_SIZE
bool "Network buffer large size"
help
Enable support for large network buffers.
Comment on lines +62 to +65
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this should specify exactly what the larger size is.


endif # NET_BUF
2 changes: 1 addition & 1 deletion lib/net_buf/buf_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ size_t net_buf_simple_tailroom(const struct net_buf_simple *buf)
return buf->size - net_buf_simple_headroom(buf) - buf->len;
}

uint16_t net_buf_simple_max_len(const struct net_buf_simple *buf)
size_t net_buf_simple_max_len(const struct net_buf_simple *buf)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate commit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{
return buf->size - net_buf_simple_headroom(buf);
}
2 changes: 1 addition & 1 deletion subsys/net/ip/net_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ static inline void net_pkt_print_buffer_info(struct net_pkt *pkt, const char *st
}

while (buf) {
printk("%p[%ld/%u (%u/%u)]", buf, atomic_get(&pkt->atomic_ref),
printk("%p[%ld/%u (%zu/%u)]", buf, atomic_get(&pkt->atomic_ref),
buf->len, net_buf_max_len(buf), buf->size);

buf = buf->frags;
Expand Down
2 changes: 1 addition & 1 deletion subsys/net/lib/shell/pkt.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static void net_pkt_buffer_info(const struct shell *sh, struct net_pkt *pkt)
}

while (buf) {
PR("%p[%ld/%u (%u/%u)]", buf, atomic_get(&pkt->atomic_ref),
PR("%p[%ld/%u (%zu/%u)]", buf, atomic_get(&pkt->atomic_ref),
buf->len, net_buf_max_len(buf), buf->size);

buf = buf->frags;
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/net_buf/buf/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ tests:
min_ram: 16
tags:
- net_buf
libraries.net_buf.large_buf:
min_ram: 16
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not so sure this will help. One memory constrained platform which uses net_bufs (for Bluetooth) is nRF51 with 16k RAM, so the above wouldn't exclude it. I'd propose to use 32.

extra_configs:
- CONFIG_NET_BUF_LARGE_SIZE=y
tags:
- net_buf
4 changes: 4 additions & 0 deletions tests/lib/net_buf/buf_simple/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ common:
tests:
libraries.net_buf.buf_simple:
type: unit
libraries.net_buf.large_buf_simple:
type: unit
extra_configs:
- CONFIG_NET_BUF_LARGE_SIZE=y