nftables: bump to latest git / all patches upstreamed

Signed-off-by: Steven Barth <steven@midlink.org>

SVN-Revision: 43870
This commit is contained in:
Steven Barth 2015-01-08 11:31:36 +00:00
parent 15d8db1f8c
commit afff105706
6 changed files with 4 additions and 5030 deletions

View file

@ -1,4 +1,4 @@
# Copyright (C) 2014 OpenWrt.org
# Copyright (C) 2015 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
@ -7,14 +7,14 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=nftables
PKG_VERSION:=0.4
PKG_VERSION:=0.4+2015-01-08
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_URL:=git://git.netfilter.org/nftables
PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=v0.4
PKG_SOURCE_VERSION:=b3529cf43bba5c3c4cddefa7f5d0143d510fd3ec
PKG_MAINTAINER:=Steven Barth <steven@midlink.org>
PKG_LICENSE:=GPL-2.0
@ -24,7 +24,7 @@ include $(INCLUDE_DIR)/package.mk
CONFIGURE_ARGS += \
--disable-debug \
--without-libgmp \
--with-mini-gmp \
--without-cli \
define Package/nftables

View file

@ -1,55 +0,0 @@
From 20417d50a2f2c6d9ed1b22ca1195214d0c2c402d Mon Sep 17 00:00:00 2001
From: Steven Barth <cyrus@openwrt.org>
Date: Mon, 15 Dec 2014 13:58:55 +0100
Subject: [PATCH 1/5] parser: rename VERSION token to IPHDRVERSION
A token name of VERSION results in a macro being defined
with the same name. This prevents inclusion of config.h
in commonly used headers.
Signed-off-by: Steven Barth <cyrus@openwrt.org>
---
src/parser_bison.y | 6 +++---
src/scanner.l | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -237,7 +237,7 @@ static void location_update(struct locat
%token OPERATION "operation"
%token IP "ip"
-%token VERSION "version"
+%token IPHDRVERSION "version"
%token HDRLENGTH "hdrlength"
%token TOS "tos"
%token LENGTH "length"
@@ -1947,7 +1947,7 @@ ip_hdr_expr : IP ip_hdr_field
}
;
-ip_hdr_field : VERSION { $$ = IPHDR_VERSION; }
+ip_hdr_field : IPHDRVERSION { $$ = IPHDR_VERSION; }
| HDRLENGTH { $$ = IPHDR_HDRLENGTH; }
| TOS { $$ = IPHDR_TOS; }
| LENGTH { $$ = IPHDR_LENGTH; }
@@ -1994,7 +1994,7 @@ ip6_hdr_expr : IP6 ip6_hdr_field
}
;
-ip6_hdr_field : VERSION { $$ = IP6HDR_VERSION; }
+ip6_hdr_field : IPHDRVERSION { $$ = IP6HDR_VERSION; }
| PRIORITY { $$ = IP6HDR_PRIORITY; }
| FLOWLABEL { $$ = IP6HDR_FLOWLABEL; }
| LENGTH { $$ = IP6HDR_LENGTH; }
--- a/src/scanner.l
+++ b/src/scanner.l
@@ -349,7 +349,7 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr
"operation" { return OPERATION; }
"ip" { return IP; }
-"version" { return VERSION; }
+"version" { return IPHDRVERSION; }
"hdrlength" { return HDRLENGTH; }
"tos" { return TOS; }
"length" { return LENGTH; }

View file

@ -1,28 +0,0 @@
From 23e8958a5e539f682be4cbdf5196aa2014c7e295 Mon Sep 17 00:00:00 2001
From: Steven Barth <cyrus@openwrt.org>
Date: Mon, 15 Dec 2014 14:09:27 +0100
Subject: [PATCH 2/5] datatype: use mpz_set_str instead of gmp_sscanf
This simplifies the integer parsing logic and restricts it to
functions being part of the mini-gmp subset.
Signed-off-by: Steven Barth <cyrus@openwrt.org>
---
src/datatype.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -275,11 +275,9 @@ static struct error_record *integer_type
struct expr **res)
{
mpz_t v;
- int len;
mpz_init(v);
- if (gmp_sscanf(sym->identifier, "%Zu%n", v, &len) != 1 ||
- (int)strlen(sym->identifier) != len) {
+ if (mpz_set_str(v, sym->identifier, 0)) {
mpz_clear(v);
return error(&sym->location, "Could not parse %s",
sym->dtype->desc);

View file

@ -1,58 +0,0 @@
From ee23bda1e4a85243fa02dc712f0f323e366dbf8c Mon Sep 17 00:00:00 2001
From: Steven Barth <cyrus@openwrt.org>
Date: Mon, 15 Dec 2014 14:14:46 +0100
Subject: [PATCH 3/5] erec: use stdio vasprintf instead of gmp_vasprintf
Use stdio's vasprintf instead of gmp_vasprintf which is not part
of the mini-gmp function subset. Furthermore convert the only
gmp-specific user and allow the compiler to verify format-strings.
Signed-off-by: Steven Barth <cyrus@openwrt.org>
---
src/erec.c | 6 +++++-
src/evaluate.c | 8 ++++++--
2 files changed, 11 insertions(+), 3 deletions(-)
--- a/src/erec.c
+++ b/src/erec.c
@@ -44,6 +44,7 @@ static void erec_destroy(struct error_re
xfree(erec);
}
+__attribute__((format(printf, 3, 0)))
struct error_record *erec_vcreate(enum error_record_types type,
const struct location *loc,
const char *fmt, va_list ap)
@@ -55,10 +56,13 @@ struct error_record *erec_vcreate(enum e
erec->num_locations = 0;
erec_add_location(erec, loc);
- gmp_vasprintf(&erec->msg, fmt, ap);
+ if (vasprintf(&erec->msg, fmt, ap) < 0)
+ erec->msg = NULL;
+
return erec;
}
+__attribute__((format(printf, 3, 4)))
struct error_record *erec_create(enum error_record_types type,
const struct location *loc,
const char *fmt, ...)
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -232,9 +232,13 @@ static int expr_evaluate_value(struct ev
case TYPE_INTEGER:
mpz_init_bitmask(mask, ctx->ectx.len);
if (mpz_cmp((*expr)->value, mask) > 0) {
+ char *valstr = mpz_get_str(NULL, 10, (*expr)->value);
+ char *rangestr = mpz_get_str(NULL, 10, mask);
expr_error(ctx->msgs, *expr,
- "Value %Zu exceeds valid range 0-%Zu",
- (*expr)->value, mask);
+ "Value %s exceeds valid range 0-%s",
+ valstr, rangestr);
+ free(valstr);
+ free(rangestr);
mpz_clear(mask);
return -1;
}

View file

@ -1,186 +0,0 @@
From d73f1b630848fb7d90f51938e3c75a42ad947c26 Mon Sep 17 00:00:00 2001
From: Steven Barth <cyrus@openwrt.org>
Date: Mon, 15 Dec 2014 14:26:34 +0100
Subject: [PATCH 5/5] build: add --without-libgmp switch to disable use of
shared libgmp
This disables linking the >400 KB big libgmp and replace it with
the builtin mini-gmp which only increases size by ~30KB.
Signed-off-by: Steven Barth <cyrus@openwrt.org>
---
configure.ac | 17 +++++++++++++---
include/expression.h | 2 +-
include/gmputil.h | 10 +++++++++
include/utils.h | 4 ++--
src/Makefile.am | 4 ++++
src/gmputil.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++--
6 files changed, 86 insertions(+), 8 deletions(-)
--- a/configure.ac
+++ b/configure.ac
@@ -73,8 +73,18 @@ AM_CONDITIONAL([BUILD_PDF], [test "$DBLA
PKG_CHECK_MODULES([LIBMNL], [libmnl >= 1.0.3])
PKG_CHECK_MODULES([LIBNFTNL], [libnftnl >= 1.0.2])
-AC_CHECK_LIB([gmp], [__gmpz_init], ,
- AC_MSG_ERROR([No suitable version of libgmp found]))
+AC_ARG_WITH([libgmp], [AS_HELP_STRING([--without-libgmp],
+ [Disable libgmp support (use builtin mini-gmp)])], [],
+ [with_libgmp=yes])
+AS_IF([test "x$with_libgmp" != xno], [
+AC_CHECK_LIB([gmp],[__gmpz_init], , AC_MSG_ERROR([No suitable version of libgmp found]))
+])
+AM_CONDITIONAL([BUILD_MINIGMP], [test "x$with_libgmp" == xno])
+
+
+AS_IF([test "x$with_libgmp" != xyes -a "x$CONFIG_DEBUG" = xy], [
+AC_MSG_ERROR([--without-libgmp MUST be used with --disable-debug])
+])
AC_ARG_WITH([cli], [AS_HELP_STRING([--without-cli],
[disable interactive CLI (libreadline support)])],
@@ -130,4 +140,5 @@ AC_OUTPUT
echo "
nft configuration:
cli support: ${with_cli}
- enable debugging: ${with_debug}"
+ enable debugging: ${with_debug}
+ use shared libgmp: ${with_libgmp}"
--- a/include/expression.h
+++ b/include/expression.h
@@ -2,7 +2,7 @@
#define NFTABLES_EXPRESSION_H
#include <stdbool.h>
-#include <gmp.h>
+#include <gmputil.h>
#include <linux/netfilter/nf_tables.h>
#include <nftables.h>
--- a/include/gmputil.h
+++ b/include/gmputil.h
@@ -1,7 +1,17 @@
#ifndef NFTABLES_GMPUTIL_H
#define NFTABLES_GMPUTIL_H
+#include <config.h>
+
+#ifdef HAVE_LIBGMP
#include <gmp.h>
+#else
+#include <mini-gmp.h>
+/* mini-gmp doesn't come with gmp_printf, so we use our own minimal variant */
+extern int mpz_printf(const char *format, const mpz_t value);
+#define gmp_printf mpz_printf
+#endif
+
#include <asm/byteorder.h>
enum mpz_word_order {
--- a/include/utils.h
+++ b/include/utils.h
@@ -9,14 +9,14 @@
#include <unistd.h>
#include <assert.h>
#include <list.h>
-#include <gmp.h>
+#include <gmputil.h>
#define BITS_PER_BYTE 8
#ifdef DEBUG
#define pr_debug(fmt, arg...) gmp_printf(fmt, ##arg)
#else
-#define pr_debug(fmt, arg...) ({ if (false) gmp_printf(fmt, ##arg); 0; })
+#define pr_debug(fmt, arg...) ({ if (false) {}; 0; })
#endif
#define __fmtstring(x, y) __attribute__((format(printf, x, y)))
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -51,4 +51,8 @@ if BUILD_CLI
nft_SOURCES += cli.c
endif
+if BUILD_MINIGMP
+nft_SOURCES += mini-gmp.c
+endif
+
nft_LDADD = ${LIBMNL_LIBS} ${LIBNFTNL_LIBS}
--- a/src/gmputil.c
+++ b/src/gmputil.c
@@ -14,11 +14,9 @@
#include <stdio.h>
#include <unistd.h>
#include <string.h>
-#include <gmp.h>
#include <nftables.h>
#include <datatype.h>
-#include <gmputil.h>
#include <utils.h>
void mpz_bitmask(mpz_t rop, unsigned int width)
@@ -148,6 +146,61 @@ void mpz_switch_byteorder(mpz_t rop, uns
mpz_import_data(rop, data, BYTEORDER_HOST_ENDIAN, len);
}
+#ifndef HAVE_LIBGMP
+/* mini-gmp doesn't have a gmp_printf so we use our own minimal
+ * variant here which is able to format a single mpz_t */
+int mpz_printf(const char *f, const mpz_t value)
+{
+ int n = 0;
+ while (*f) {
+ if (*f != '%') {
+ if (fputc(*f, stdout) != *f)
+ return -1;
+
+ ++n;
+ } else {
+ unsigned long prec = 0;
+ int base;
+ size_t len;
+ char *str;
+ bool ok;
+
+ if (*++f == '.')
+ prec = strtoul(++f, (char**)&f, 10);
+
+ if (*f++ != 'Z')
+ return -1;
+
+ if (*f == 'u')
+ base = 10;
+ else if (*f == 'x')
+ base = 16;
+ else
+ return -1;
+
+ len = mpz_sizeinbase(value, base);
+ while (prec-- > len) {
+ if (fputc('0', stdout) != '0')
+ return -1;
+
+ ++n;
+ }
+
+ str = mpz_get_str(NULL, base, value);
+ ok = str && fwrite(str, 1, len, stdout) == len;
+ free(str);
+
+ if (!ok)
+ return -1;
+
+ n += len;
+ }
+ ++f;
+ }
+ return n;
+}
+#endif
+
static void *gmp_xrealloc(void *ptr, size_t old_size, size_t new_size)
{
return xrealloc(ptr, new_size);