summaryrefslogtreecommitdiffstats
path: root/src/extra
diff options
context:
space:
mode:
authorEtan Kissling <etan_kissling@apple.com>2021-01-19 16:05:39 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2021-02-09 17:31:31 +0100
commit662c8f44d53492d2e0ebd430dadef12d580ec330 (patch)
treebcaf73295210ad7c10c5ab57962ea3d482316846 /src/extra
parent0fcf33229820f1c89ae75bc54cb41c2acdd5d067 (diff)
src: add pkt_buff function for ICMP
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> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/extra')
-rw-r--r--src/extra/icmp.c48
1 files changed, 48 insertions, 0 deletions
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;
+}
+
+/**
+ * @}
+ */