[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Minios-devel] [UNIKRAFT PATCH v4 05/11] lib/uknetdev: Netbuf headroom and tailroom helpers
Hello Simon,There are minor typos in the comments which can be fixed while we pushing them. Please find them inline Reviewed-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx> On 10/10/2018 02:00 PM, Simon Kuenzer wrote: Introduce helpers for calculating available headroom and tailroom on a Netbuf's data buffer. A header manipulation function is added to simplify prepending bytes to the packet data or claiming bytes back to the headroom. Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx> --- lib/uknetdev/include/uk/netbuf.h | 86 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/lib/uknetdev/include/uk/netbuf.h b/lib/uknetdev/include/uk/netbuf.h index 5b0907c..0f8f6a3 100644 --- a/lib/uknetdev/include/uk/netbuf.h +++ b/lib/uknetdev/include/uk/netbuf.h @@ -308,6 +308,18 @@ static inline struct uk_netbuf *uk_netbuf_ref_single(struct uk_netbuf *m) }/**+ * Returns the reference to private data of a netbuf + * @param m + * uk_netbuf to return private data of + */ +static inline void *uk_netbuf_get_priv(struct uk_netbuf *m) +{ + UK_ASSERT(m); + + return (m)->priv; +} + +/** * Returns the current reference count of a single netbuf * @param m * uk_netbuf to return the reference count of @@ -422,6 +434,80 @@ void uk_netbuf_free_single(struct uk_netbuf *m); (__ret); \ })+/**+ * Calculates the current available headroom bytes of a netbuf + * @param m + * uk_netbuf to return headroom bytes of + * @returns + * available headroom bytes + */ +static inline size_t uk_netbuf_headroom(struct uk_netbuf *m) +{ + UK_ASSERT(m); + UK_ASSERT(m->buf); + UK_ASSERT(m->data); + + return (size_t) ((uintptr_t) (m)->data - (uintptr_t) (m)->buf); +} + +/** + * Calculates the current available tailroom bytes of a netbuf + * @param m + * uk_netbuf to return tailroom bytes of + * @returns + * available tailroom bytes + */ +static inline size_t uk_netbuf_tailroom(struct uk_netbuf *m) +{ + UK_ASSERT(m); + UK_ASSERT(m->buf); + UK_ASSERT(m->data); + + return ((size_t) (((uintptr_t) (m)->buf + (uintptr_t) (m)->buflen) + - ((uintptr_t) (m)->data + (uintptr_t) (m)->len))); +} + replace m with head +/** + * Prepends (or returns) bytes from the headroom (back) to the data area. + * It basically moves m->data. + * @param head + * uk_netbuf to modify (has to be the first netbuf of a chain) + * @param len + * If > 0 takes bytes from the headroom and prepends them to data + * If < 0 releases the -len first bytes from data to headroom + * @returns + * - (-ENOSPC): Operation could not be perform within buffer bounds + * - (-EFAULT): Operation could not be performed because data would get > 64kB + * - (1): netbuf successfully modified + */ +static inline int uk_netbuf_header(struct uk_netbuf *head, int16_t len) +{ + UK_ASSERT(head); + UK_ASSERT(head->buf); + UK_ASSERT(head->data); + replace m with head + /* m has to be the first element of a netbuf chain. */ + UK_ASSERT(head->prev == NULL); + + /* If len > 0, we take bytes from the headroom and add + * them to data. We are limited to the available headroom size. + * If len < 0, we return bytes back to the headroom. + * We are limited to the available data length. + */ + if (unlikely((len > (ssize_t) uk_netbuf_headroom(head)) + || (-len > head->len))) + return -ENOSPC; + + /* We should never make the packet bigger than 64kB */ + if (unlikely((int32_t) len + (int32_t) head->len + > (int32_t) UINT16_MAX)) + return -EFAULT; + + head->data -= len; + head->len += len; + return 1; +} + #ifdef __cplusplus } #endif Thanks & Regards Sharan _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |