From: Sebastien Tricaud <sebastien.tricaud@wengo.com>
Cc: netfilter-devel@lists.netfilter.org,
Patrick McHardy <kaber@trash.net>,
Pablo Neira Ayuso <pablo@netfilter.org>
Subject: Re: Change Packet Payload
Date: Fri, 16 Feb 2007 14:11:19 +0100 [thread overview]
Message-ID: <45D5AD77.3080709@wengo.com> (raw)
In-Reply-To: <45D47214.8000508@wengo.com>
[-- Attachment #1: Type: text/plain, Size: 105 bytes --]
Hi folks,
this is patch adds the checksum computation feature in netfilter_queue.
Thanks,
Sebastien.
[-- Attachment #2: nfq-compute_cksum.2.patch --]
[-- Type: text/x-patch, Size: 5324 bytes --]
Index: include/libnetfilter_queue/Makefile.am
===================================================================
--- include/libnetfilter_queue/Makefile.am (revision 6757)
+++ include/libnetfilter_queue/Makefile.am (working copy)
@@ -1,3 +1,3 @@
-pkginclude_HEADERS = libnetfilter_queue.h libipq.h linux_nfnetlink_queue.h
+pkginclude_HEADERS = libnetfilter_queue.h libipq.h linux_nfnetlink_queue.h protocol_any_helper.h
Index: include/libnetfilter_queue/libnetfilter_queue.h
===================================================================
--- include/libnetfilter_queue/libnetfilter_queue.h (revision 6757)
+++ include/libnetfilter_queue/libnetfilter_queue.h (working copy)
@@ -14,9 +14,8 @@
#define __LIBCTNETLINK_H
#include <libnfnetlink/libnfnetlink.h>
-// #include <libnfnetlink/liunx_nfnetlink.h>
-
#include <libnetfilter_queue/linux_nfnetlink_queue.h>
+#include <libnetfilter_queue/protocol_any_helper.h>
struct nfq_handle;
struct nfq_q_handle;
@@ -79,8 +78,7 @@
extern u_int32_t nfq_get_physindev(struct nfq_data *nfad);
extern u_int32_t nfq_get_outdev(struct nfq_data *nfad);
extern u_int32_t nfq_get_physoutdev(struct nfq_data *nfad);
-
-extern int nfq_get_indev_name(struct nlif_handle *nlif_handle,
+extern int nfq_get_indev_name(struct nlif_handle *nlif_handle,
struct nfq_data *nfad, char *name);
extern int nfq_get_physindev_name(struct nlif_handle *nlif_handle,
struct nfq_data *nfad, char *name);
Index: include/libnetfilter_queue/protocol_any_helper.h
===================================================================
--- include/libnetfilter_queue/protocol_any_helper.h (revision 0)
+++ include/libnetfilter_queue/protocol_any_helper.h (revision 0)
@@ -0,0 +1,17 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+extern unsigned short nfq_compute_cksum(unsigned short *addr, int count);
+
Index: configure.in
===================================================================
--- configure.in (revision 6757)
+++ configure.in (working copy)
@@ -23,7 +23,7 @@
PKG_CHECK_MODULES(LIBNFNETLINK, libnfnetlink >= $LIBNFNETLINK_REQUIRED,,
AC_MSG_ERROR(Cannot find libnfnetlink >= $LIBNFNETLINK_REQUIRED))
-CFLAGS="$CFLAGS $LIBNFNETLINK_CFLAGS"
+CFLAGS="$CFLAGS $LIBNFNETLINK_CFLAGS -Wpadded"
LIBNFQUEUE_LIBS="$LIBNFNETLINK_LIBS"
AC_SUBST(LIBNFQUEUE_LIBS)
Index: src/protocol_any_helper.c
===================================================================
--- src/protocol_any_helper.c (revision 0)
+++ src/protocol_any_helper.c (revision 0)
@@ -0,0 +1,53 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <libnetfilter_queue/protocol_any_helper.h>
+
+/**
+ * nfq_compute_cksum - returns the checksum computed
+ * @addr: Address of stored data pointer
+ * @count: packet lenght (header+payload)
+ *
+ * Helper function to compute packet checkum.
+ */
+/* Copyright (C) The Internet Society 1988. This version of this code
+ * is part of RFC 1071; see the RFC itself for full legal notices.
+ *
+ * The original code has been slightly changed
+ */
+unsigned short nfq_compute_cksum(unsigned short *addr, int count)
+{
+
+ /* Compute Internet Checksum for "count" bytes
+ * beginning at location "addr".
+ */
+ unsigned short sum = 0;
+
+ while( count > 1 ) {
+ /* This is the inner loop */
+ sum += (unsigned short *) addr++;
+ count -= 2;
+ }
+
+ /* Add left-over byte, if any */
+ if( count > 0 )
+ sum += * (unsigned char *) addr;
+
+ /* Fold 32-bit sum to 16 bits */
+ while (sum>>16)
+ sum = (sum & 0xffff) + (sum >> 16);
+
+ return ~sum;
+}
Index: src/Makefile.am
===================================================================
--- src/Makefile.am (revision 6757)
+++ src/Makefile.am (working copy)
@@ -10,7 +10,7 @@
libnetfilter_queue_la_LDFLAGS = -Wc,-nostartfiles -lnfnetlink \
-version-info $(LIBVERSION)
-libnetfilter_queue_la_SOURCES = libnetfilter_queue.c
+libnetfilter_queue_la_SOURCES = libnetfilter_queue.c protocol_any_helper.c
libnetfilter_queue_libipq_la_LDFLAGS = -Wc,-nostartfiles \
-version-info 1:0:0
prev parent reply other threads:[~2007-02-16 13:11 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-09 9:10 Change Packet Payload Luis Campo Giralte
2007-02-09 9:31 ` Eric Leblond
2007-02-09 9:48 ` Henrik Nordstrom
2007-02-13 22:10 ` Pablo Neira Ayuso
2007-02-14 9:39 ` Sebastien Tricaud
2007-02-14 9:47 ` Sebastien Tricaud
2007-02-14 9:52 ` Patrick McHardy
2007-02-14 9:55 ` Sebastien Tricaud
2007-02-14 10:05 ` Sebastien Tricaud
2007-02-14 10:09 ` Patrick McHardy
2007-02-15 0:36 ` Pablo Neira Ayuso
2007-02-15 14:45 ` Sebastien Tricaud
2007-02-16 13:11 ` Sebastien Tricaud [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=45D5AD77.3080709@wengo.com \
--to=sebastien.tricaud@wengo.com \
--cc=kaber@trash.net \
--cc=netfilter-devel@lists.netfilter.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).