diff mbox series

[libnetfilter_queue,1/3] pktbuff: add pktb_alloc_head() and pktb_build_data()

Message ID 20200426132356.8346-2-pablo@netfilter.org
State Changes Requested
Delegated to: Pablo Neira
Headers show
Series [libnetfilter_queue,1/3] pktbuff: add pktb_alloc_head() and pktb_build_data() | expand

Commit Message

Pablo Neira Ayuso April 26, 2020, 1:23 p.m. UTC
Add two new helper functions to skip memcpy()'ing the payload from the
netlink message.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 include/libnetfilter_queue/pktbuff.h |  3 +++
 src/extra/pktbuff.c                  | 20 ++++++++++++++++++++
 2 files changed, 23 insertions(+)

Comments

Duncan Roe April 30, 2020, 5:41 a.m. UTC | #1
On Sun, Apr 26, 2020 at 03:23:54PM +0200, Pablo Neira Ayuso wrote:
> Add two new helper functions to skip memcpy()'ing the payload from the
> netlink message.
>
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
> ---
>  include/libnetfilter_queue/pktbuff.h |  3 +++
>  src/extra/pktbuff.c                  | 20 ++++++++++++++++++++
>  2 files changed, 23 insertions(+)
>
> diff --git a/include/libnetfilter_queue/pktbuff.h b/include/libnetfilter_queue/pktbuff.h
> index 42bc153ec337..f9bddaf072fb 100644
> --- a/include/libnetfilter_queue/pktbuff.h
> +++ b/include/libnetfilter_queue/pktbuff.h
> @@ -4,8 +4,11 @@
>  struct pkt_buff;
>
>  struct pkt_buff *pktb_alloc(int family, void *data, size_t len, size_t extra);
> +struct pkt_buff *pktb_alloc_head(void);
>  void pktb_free(struct pkt_buff *pktb);
>
> +void pktb_build_data(struct pkt_buff *pktb, uint8_t *payload, uint32_t len);
> +
>  uint8_t *pktb_data(struct pkt_buff *pktb);
>  uint32_t pktb_len(struct pkt_buff *pktb);
>
> diff --git a/src/extra/pktbuff.c b/src/extra/pktbuff.c
> index 6dd0ca98aff2..a93e72ac7795 100644
> --- a/src/extra/pktbuff.c
> +++ b/src/extra/pktbuff.c
> @@ -93,6 +93,26 @@ struct pkt_buff *pktb_alloc(int family, void *data, size_t len, size_t extra)
>  	return pktb;
>  }
>
> +EXPORT_SYMBOL
> +struct pkt_buff *pktb_alloc_head(void)

I think we agreed to dispense with this function?
> +{
> +	struct pkt_buff *pktb;
> +
> +	pktb = calloc(1, sizeof(struct pkt_buff));
The callback (CB) needs to zeroise head: calling calloc() here is ineffective.
At least the *mangled* flag must be cleared, also the new *copy_done* flag.
> +	if (pktb == NULL)
> +		return NULL;
The above 2 lines are unnecessary
> +
> +	return pktb;
> +}
> +
> +EXPORT_SYMBOL
> +void pktb_build_data(struct pkt_buff *pktb, uint8_t *payload, uint32_t len)
> +{
> +	pktb->len = len;
> +	pktb->data_len = len;
> +	pktb->data = payload;
Also
+	mangled = false;
Maybe nullify the other pointers?
> +}
> +
>  /**
>   * pktb_data - get pointer to network packet
>   * \param pktb Pointer to userspace packet buffer
> --
> 2.20.1
>
-Duncan
diff mbox series

Patch

diff --git a/include/libnetfilter_queue/pktbuff.h b/include/libnetfilter_queue/pktbuff.h
index 42bc153ec337..f9bddaf072fb 100644
--- a/include/libnetfilter_queue/pktbuff.h
+++ b/include/libnetfilter_queue/pktbuff.h
@@ -4,8 +4,11 @@ 
 struct pkt_buff;
 
 struct pkt_buff *pktb_alloc(int family, void *data, size_t len, size_t extra);
+struct pkt_buff *pktb_alloc_head(void);
 void pktb_free(struct pkt_buff *pktb);
 
+void pktb_build_data(struct pkt_buff *pktb, uint8_t *payload, uint32_t len);
+
 uint8_t *pktb_data(struct pkt_buff *pktb);
 uint32_t pktb_len(struct pkt_buff *pktb);
 
diff --git a/src/extra/pktbuff.c b/src/extra/pktbuff.c
index 6dd0ca98aff2..a93e72ac7795 100644
--- a/src/extra/pktbuff.c
+++ b/src/extra/pktbuff.c
@@ -93,6 +93,26 @@  struct pkt_buff *pktb_alloc(int family, void *data, size_t len, size_t extra)
 	return pktb;
 }
 
+EXPORT_SYMBOL
+struct pkt_buff *pktb_alloc_head(void)
+{
+	struct pkt_buff *pktb;
+
+	pktb = calloc(1, sizeof(struct pkt_buff));
+	if (pktb == NULL)
+		return NULL;
+
+	return pktb;
+}
+
+EXPORT_SYMBOL
+void pktb_build_data(struct pkt_buff *pktb, uint8_t *payload, uint32_t len)
+{
+	pktb->len = len;
+	pktb->data_len = len;
+	pktb->data = payload;
+}
+
 /**
  * pktb_data - get pointer to network packet
  * \param pktb Pointer to userspace packet buffer