netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH libnetfilter_queue] src: add pkt_buff function for ICMP
@ 2021-01-13  9:37 Etan Kissling
  2021-01-19 15:05 ` Etan Kissling
  2021-02-09 16:32 ` Pablo Neira Ayuso
  0 siblings, 2 replies; 3+ messages in thread
From: Etan Kissling @ 2021-01-13  9:37 UTC (permalink / raw)
  To: netfilter-devel; +Cc: laforge

Add support for processing ICMP packets using pkt_buff, similar to
existing library support for TCP and UDP.

Signed-off-by: Etan Kissling <etan_kissling@apple.com>
---
 include/libnetfilter_queue/Makefile.am        |  1 +
 .../libnetfilter_queue_icmp.h                 |  8 ++++
 src/Makefile.am                               |  1 +
 src/extra/icmp.c                              | 48 +++++++++++++++++++
 4 files changed, 58 insertions(+)
 create mode 100644 include/libnetfilter_queue/libnetfilter_queue_icmp.h
 create mode 100644 src/extra/icmp.c

diff --git a/include/libnetfilter_queue/Makefile.am b/include/libnetfilter_queue/Makefile.am
index 902fbf9..e436bab 100644
--- a/include/libnetfilter_queue/Makefile.am
+++ b/include/libnetfilter_queue/Makefile.am
@@ -1,5 +1,6 @@
 pkginclude_HEADERS = libnetfilter_queue.h	\
 		     linux_nfnetlink_queue.h	\
+		     libnetfilter_queue_icmp.h	\
 		     libnetfilter_queue_ipv4.h	\
 		     libnetfilter_queue_ipv6.h	\
 		     libnetfilter_queue_tcp.h	\
diff --git a/include/libnetfilter_queue/libnetfilter_queue_icmp.h b/include/libnetfilter_queue/libnetfilter_queue_icmp.h
new file mode 100644
index 0000000..9a8bd52
--- /dev/null
+++ b/include/libnetfilter_queue/libnetfilter_queue_icmp.h
@@ -0,0 +1,8 @@
+#ifndef _LIBNFQUEUE_ICMP_H_
+#define _LIBNFQUEUE_ICMP_H_
+
+struct pkt_buff;
+
+struct icmphdr *nfq_icmp_get_hdr(struct pkt_buff *pktb);
+
+#endif
diff --git a/src/Makefile.am b/src/Makefile.am
index 8cede12..471c02c 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -31,6 +31,7 @@ libnetfilter_queue_la_LDFLAGS = -Wc,-nostartfiles \
 libnetfilter_queue_la_SOURCES = libnetfilter_queue.c	\
 				nlmsg.c			\
 				extra/checksum.c	\
+				extra/icmp.c	\
 				extra/ipv6.c		\
 				extra/tcp.c		\
 				extra/ipv4.c		\
diff --git a/src/extra/icmp.c b/src/extra/icmp.c
new file mode 100644
index 0000000..c0d42ac
--- /dev/null
+++ b/src/extra/icmp.c
@@ -0,0 +1,48 @@
+/*
+ * (C) 2012 by Pablo Neira Ayuso <pablo@netfilter.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This code has been sponsored by Vyatta Inc. <http://www.vyatta.com>
+ */
+
+#include <stdio.h>
+#define _GNU_SOURCE
+#include <netinet/ip_icmp.h>
+
+#include <libnetfilter_queue/libnetfilter_queue_icmp.h>
+
+#include "internal.h"
+
+/**
+ * \defgroup icmp ICMP helper functions
+ * @{
+ */
+
+/**
+ * nfq_icmp_get_hdr - get the ICMP header.
+ * \param head: pointer to the beginning of the packet
+ * \param tail: pointer to the tail of the packet
+ *
+ * This function returns NULL if invalid ICMP header is found. On success,
+ * it returns the ICMP header.
+ */
+struct icmphdr *nfq_icmp_get_hdr(struct pkt_buff *pktb)
+{
+	if (pktb->transport_header == NULL)
+		return NULL;
+
+	/* No room for the ICMP header. */
+	if (pktb->tail - pktb->transport_header < sizeof(struct icmphdr))
+		return NULL;
+
+	return (struct icmphdr *)pktb->transport_header;
+}
+EXPORT_SYMBOL(nfq_icmp_get_hdr);
+
+/**
+ * @}
+ */
-- 
2.21.1 (Apple Git-122.3)




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH libnetfilter_queue] src: add pkt_buff function for ICMP
  2021-01-13  9:37 [PATCH libnetfilter_queue] src: add pkt_buff function for ICMP Etan Kissling
@ 2021-01-19 15:05 ` Etan Kissling
  2021-02-09 16:32 ` Pablo Neira Ayuso
  1 sibling, 0 replies; 3+ messages in thread
From: Etan Kissling @ 2021-01-19 15:05 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Pablo Neira Ayuso

Add support for processing ICMP packets using pkt_buff, similar to
existing library support for TCP and UDP.

Signed-off-by: Etan Kissling <etan_kissling@apple.com>
---
 include/libnetfilter_queue/Makefile.am        |  1 +
 .../libnetfilter_queue_icmp.h                 |  8 ++++
 src/Makefile.am                               |  1 +
 src/extra/icmp.c                              | 48 +++++++++++++++++++
 4 files changed, 58 insertions(+)
 create mode 100644 include/libnetfilter_queue/libnetfilter_queue_icmp.h
 create mode 100644 src/extra/icmp.c

diff --git a/include/libnetfilter_queue/Makefile.am b/include/libnetfilter_queue/Makefile.am
index 902fbf9..e436bab 100644
--- a/include/libnetfilter_queue/Makefile.am
+++ b/include/libnetfilter_queue/Makefile.am
@@ -1,5 +1,6 @@
 pkginclude_HEADERS = libnetfilter_queue.h	\
 		     linux_nfnetlink_queue.h	\
+		     libnetfilter_queue_icmp.h	\
 		     libnetfilter_queue_ipv4.h	\
 		     libnetfilter_queue_ipv6.h	\
 		     libnetfilter_queue_tcp.h	\
diff --git a/include/libnetfilter_queue/libnetfilter_queue_icmp.h b/include/libnetfilter_queue/libnetfilter_queue_icmp.h
new file mode 100644
index 0000000..9a8bd52
--- /dev/null
+++ b/include/libnetfilter_queue/libnetfilter_queue_icmp.h
@@ -0,0 +1,8 @@
+#ifndef _LIBNFQUEUE_ICMP_H_
+#define _LIBNFQUEUE_ICMP_H_
+
+struct pkt_buff;
+
+struct icmphdr *nfq_icmp_get_hdr(struct pkt_buff *pktb);
+
+#endif
diff --git a/src/Makefile.am b/src/Makefile.am
index 8cede12..079853e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -31,6 +31,7 @@ libnetfilter_queue_la_LDFLAGS = -Wc,-nostartfiles \
 libnetfilter_queue_la_SOURCES = libnetfilter_queue.c	\
 				nlmsg.c			\
 				extra/checksum.c	\
+				extra/icmp.c		\
 				extra/ipv6.c		\
 				extra/tcp.c		\
 				extra/ipv4.c		\
diff --git a/src/extra/icmp.c b/src/extra/icmp.c
new file mode 100644
index 0000000..a97979b
--- /dev/null
+++ b/src/extra/icmp.c
@@ -0,0 +1,48 @@
+/*
+ * (C) 2012 by Pablo Neira Ayuso <pablo@netfilter.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This code has been sponsored by Vyatta Inc. <http://www.vyatta.com>
+ */
+
+#include <stdio.h>
+#define _GNU_SOURCE
+#include <netinet/ip_icmp.h>
+
+#include <libnetfilter_queue/libnetfilter_queue_icmp.h>
+
+#include "internal.h"
+
+/**
+ * \defgroup icmp ICMP helper functions
+ * @{
+ */
+
+/**
+ * nfq_icmp_get_hdr - get the ICMP header.
+ * \param pktb: pointer to user-space network packet buffer
+ * \returns validated pointer to the ICMP header or NULL if the ICMP header was
+ * not set or if a minimal length check fails.
+ * \note You have to call nfq_ip_set_transport_header() or
+ * nfq_ip6_set_transport_header() first to set the ICMP header.
+ */
+EXPORT_SYMBOL
+struct icmphdr *nfq_icmp_get_hdr(struct pkt_buff *pktb)
+{
+	if (pktb->transport_header == NULL)
+		return NULL;
+
+	/* No room for the ICMP header. */
+	if (pktb_tail(pktb) - pktb->transport_header < sizeof(struct icmphdr))
+		return NULL;
+
+	return (struct icmphdr *)pktb->transport_header;
+}
+
+/**
+ * @}
+ */
-- 
2.21.1 (Apple Git-122.3)




^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH libnetfilter_queue] src: add pkt_buff function for ICMP
  2021-01-13  9:37 [PATCH libnetfilter_queue] src: add pkt_buff function for ICMP Etan Kissling
  2021-01-19 15:05 ` Etan Kissling
@ 2021-02-09 16:32 ` Pablo Neira Ayuso
  1 sibling, 0 replies; 3+ messages in thread
From: Pablo Neira Ayuso @ 2021-02-09 16:32 UTC (permalink / raw)
  To: Etan Kissling; +Cc: netfilter-devel, laforge

On Wed, Jan 13, 2021 at 10:37:30AM +0100, Etan Kissling wrote:
> Add support for processing ICMP packets using pkt_buff, similar to
> existing library support for TCP and UDP.

Applied, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-02-09 16:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-13  9:37 [PATCH libnetfilter_queue] src: add pkt_buff function for ICMP Etan Kissling
2021-01-19 15:05 ` Etan Kissling
2021-02-09 16:32 ` Pablo Neira Ayuso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).