80ddfa2
From 10b72726428476e5efe582d34aa409b53d8b1434 Mon Sep 17 00:00:00 2001
80ddfa2
From: Duncan Roe <duncan_roe@optusnet.com.au>
80ddfa2
Date: Tue, 15 May 2018 08:26:43 +1000
80ddfa2
Subject: [PATCH] ebtables: Fix build errors and warnings
80ddfa2
80ddfa2
Since commit b1cdae87f25021eb835872d86d6e7206bd421c3f, make fails thusly:
80ddfa2
80ddfa2
> libebtc.c: In function 'ebt_reinit_extensions':
80ddfa2
> libebtc.c:275:11: error: 'union <anonymous>' has no member named 'revision'
80ddfa2
>     m->m->u.revision = m->revision;
80ddfa2
>            ^
80ddfa2
> libebtc.c: In function 'ebt_check_rule_exists':
80ddfa2
> libebtc.c:555:21: error: 'union <anonymous>' has no member named 'revision'
80ddfa2
>            m_l2->m->u.revision != m->m->u.revision)) {
80ddfa2
>                      ^
80ddfa2
> libebtc.c:555:41: error: 'union <anonymous>' has no member named 'revision'
80ddfa2
>            m_l2->m->u.revision != m->m->u.revision)) {
80ddfa2
>                                          ^
80ddfa2
> libebtc.c: In function 'ebt_register_match':
80ddfa2
> libebtc.c:1215:9: error: 'union <anonymous>' has no member named 'revision'
80ddfa2
>   m->m->u.revision = m->revision;
80ddfa2
>          ^
80ddfa2
The cause of this failure is that the commit updated include/ebtables.h but
80ddfa2
libebtc.c uses include/linux/netfilter_bridge/ebtables.h via
80ddfa2
include/ebtables_u.h (gcc -E -C verifies this).
80ddfa2
80ddfa2
The 2 versions of ebtables.h looked to me to be otherwise close enough, so
80ddfa2
amended ebtables_u.h to use the newer one.
80ddfa2
80ddfa2
Makefile insists on being warning-free, so cleared up warnings. Apart from
80ddfa2
unused variables, there was also the issue that the diagnostic macro
80ddfa2
ebt_print_error2 *returns* (i.e. makes its caller return) and returns -1. This
80ddfa2
is unsuitable for use in functions which do not return a value, so introduced
80ddfa2
ebt_print_error3 to do this.
80ddfa2
80ddfa2
Signed-off-by: Duncan Roe <duncan_roe@optusnet.com.au>
80ddfa2
Signed-off-by: Florian Westphal <fw@strlen.de>
80ddfa2
Signed-off-by: Phil Sutter <psutter@redhat.com>
80ddfa2
---
80ddfa2
 extensions/ebt_string.c | 25 +++++++++++--------------
80ddfa2
 include/ebtables_u.h    |  4 +++-
80ddfa2
 2 files changed, 14 insertions(+), 15 deletions(-)
80ddfa2
80ddfa2
diff --git a/extensions/ebt_string.c b/extensions/ebt_string.c
80ddfa2
index 793f5df312f10..9550c41096a86 100644
80ddfa2
--- a/extensions/ebt_string.c
80ddfa2
+++ b/extensions/ebt_string.c
80ddfa2
@@ -71,7 +71,7 @@ static void parse_string(const char *s, struct xt_string_info *info)
80ddfa2
 		info->patlen = strnlen(s, XT_STRING_MAX_PATTERN_SIZE);
80ddfa2
 		return;
80ddfa2
 	}
80ddfa2
-	ebt_print_error2("STRING too long \"%s\"", s);
80ddfa2
+	ebt_print_error3("STRING too long \"%s\"", s);
80ddfa2
 }
80ddfa2
 
80ddfa2
 static void parse_hex_string(const char *s, struct xt_string_info *info)
80ddfa2
@@ -83,14 +83,14 @@ static void parse_hex_string(const char *s, struct xt_string_info *info)
80ddfa2
 	slen = strlen(s);
80ddfa2
 
80ddfa2
 	if (slen == 0) {
80ddfa2
-		ebt_print_error2("STRING must contain at least one char");
80ddfa2
+		ebt_print_error3("STRING must contain at least one char");
80ddfa2
 	}
80ddfa2
 
80ddfa2
 	while (i < slen) {
80ddfa2
 		if (s[i] == '\\' && !hex_f) {
80ddfa2
 			literal_f = 1;
80ddfa2
 		} else if (s[i] == '\\') {
80ddfa2
-			ebt_print_error2("Cannot include literals in hex data");
80ddfa2
+			ebt_print_error3("Cannot include literals in hex data");
80ddfa2
 		} else if (s[i] == '|') {
80ddfa2
 			if (hex_f)
80ddfa2
 				hex_f = 0;
80ddfa2
@@ -108,28 +108,28 @@ static void parse_hex_string(const char *s, struct xt_string_info *info)
80ddfa2
 
80ddfa2
 		if (literal_f) {
80ddfa2
 			if (i+1 >= slen) {
80ddfa2
-				ebt_print_error2("Bad literal placement at end of string");
80ddfa2
+				ebt_print_error3("Bad literal placement at end of string");
80ddfa2
 			}
80ddfa2
 			info->pattern[sindex] = s[i+1];
80ddfa2
 			i += 2;  /* skip over literal char */
80ddfa2
 			literal_f = 0;
80ddfa2
 		} else if (hex_f) {
80ddfa2
 			if (i+1 >= slen) {
80ddfa2
-				ebt_print_error2("Odd number of hex digits");
80ddfa2
+				ebt_print_error3("Odd number of hex digits");
80ddfa2
 			}
80ddfa2
 			if (i+2 >= slen) {
80ddfa2
 				/* must end with a "|" */
80ddfa2
-				ebt_print_error2("Invalid hex block");
80ddfa2
+				ebt_print_error3("Invalid hex block");
80ddfa2
 			}
80ddfa2
 			if (! isxdigit(s[i])) /* check for valid hex char */
80ddfa2
-				ebt_print_error2("Invalid hex char '%c'", s[i]);
80ddfa2
+				ebt_print_error3("Invalid hex char '%c'", s[i]);
80ddfa2
 			if (! isxdigit(s[i+1])) /* check for valid hex char */
80ddfa2
-				ebt_print_error2("Invalid hex char '%c'", s[i+1]);
80ddfa2
+				ebt_print_error3("Invalid hex char '%c'", s[i+1]);
80ddfa2
 			hextmp[0] = s[i];
80ddfa2
 			hextmp[1] = s[i+1];
80ddfa2
 			hextmp[2] = '\0';
80ddfa2
 			if (! sscanf(hextmp, "%x", &schar))
80ddfa2
-				ebt_print_error2("Invalid hex char `%c'", s[i]);
80ddfa2
+				ebt_print_error3("Invalid hex char `%c'", s[i]);
80ddfa2
 			info->pattern[sindex] = (char) schar;
80ddfa2
 			if (s[i+2] == ' ')
80ddfa2
 				i += 3;  /* spaces included in the hex block */
80ddfa2
@@ -140,7 +140,7 @@ static void parse_hex_string(const char *s, struct xt_string_info *info)
80ddfa2
 			i++;
80ddfa2
 		}
80ddfa2
 		if (sindex > XT_STRING_MAX_PATTERN_SIZE)
80ddfa2
-			ebt_print_error2("STRING too long \"%s\"", s);
80ddfa2
+			ebt_print_error3("STRING too long \"%s\"", s);
80ddfa2
 		sindex++;
80ddfa2
 	}
80ddfa2
 	info->patlen = sindex;
80ddfa2
@@ -150,9 +150,6 @@ static int parse(int c, char **argv, int argc, const struct ebt_u_entry *entry,
80ddfa2
 		 unsigned int *flags, struct ebt_entry_match **match)
80ddfa2
 {
80ddfa2
 	struct xt_string_info *info = (struct xt_string_info *)(*match)->data;
80ddfa2
-	int i;
80ddfa2
-	int input_string_length = 0;
80ddfa2
-	char buf[3] = { 0 };
80ddfa2
 
80ddfa2
 	switch (c) {
80ddfa2
 	case STRING_FROM:
80ddfa2
@@ -206,7 +203,7 @@ static void final_check(const struct ebt_u_entry *entry,
80ddfa2
 	struct xt_string_info *info = (struct xt_string_info *)match->data;
80ddfa2
 
80ddfa2
 	if (info->to_offset < info->from_offset) {
80ddfa2
-		ebt_print_error2("'to' offset should not be less than 'from' "
80ddfa2
+		ebt_print_error3("'to' offset should not be less than 'from' "
80ddfa2
 				 "offset");
80ddfa2
 	}
80ddfa2
 }
80ddfa2
diff --git a/include/ebtables_u.h b/include/ebtables_u.h
80ddfa2
index 4824a145964ef..7adc5a2f33329 100644
80ddfa2
--- a/include/ebtables_u.h
80ddfa2
+++ b/include/ebtables_u.h
80ddfa2
@@ -25,7 +25,7 @@
80ddfa2
 #define EBTABLES_U_H
80ddfa2
 #include <netinet/in.h>
80ddfa2
 #include <netinet/ether.h>
80ddfa2
-#include <linux/netfilter_bridge/ebtables.h>
80ddfa2
+#include <ebtables.h>
80ddfa2
 #include <linux/netfilter/x_tables.h>
80ddfa2
 
80ddfa2
 #ifndef IPPROTO_SCTP
80ddfa2
@@ -338,6 +338,8 @@ _ch;})
80ddfa2
 #define ebt_print_error(format,args...) __ebt_print_error(format, ##args);
80ddfa2
 #define ebt_print_error2(format, args...) do {__ebt_print_error(format, ##args); \
80ddfa2
    return -1;} while (0)
80ddfa2
+#define ebt_print_error3(format, args...) do {__ebt_print_error(format, ##args); \
80ddfa2
+   return;} while (0)
80ddfa2
 #define ebt_check_option2(flags,mask)	\
80ddfa2
 ({ebt_check_option(flags,mask);		\
80ddfa2
  if (ebt_errormsg[0] != '\0')		\
80ddfa2
-- 
80ddfa2
2.21.0
80ddfa2