From: Stephane Ouellette <ouellettes@videotron.ca>
To: Harald Welte <laforge@netfilter.org>
Cc: Netfilter Mailing List <netfilter-devel@lists.netfilter.org>
Subject: [PATCH] libip6t_dst.c
Date: Thu, 04 Sep 2003 14:34:37 -0400 [thread overview]
Message-ID: <3F5785BD.9010202@videotron.ca> (raw)
[-- Attachment #1: Type: text/plain, Size: 434 bytes --]
Harald,
in a patch I've sent you recently, I introduced a typo.
The following patch fixes this and includes:
1- Fix preprocessor directive usage,
2- Redefine UNAME and LNAME macros such that their value is determined
at compile-time, not at run-time,
3- Modify all printf() calls that use LNAME and UNAME to take advantage
of the compile-time macro definitions,
4- More indentation fixes.
Please apply,
Stephane Ouellette.
[-- Attachment #2: libip6t_dst.c.patch --]
[-- Type: text/plain, Size: 7562 bytes --]
--- netfilter.orig/userspace/extensions/libip6t_dst.c Mon Aug 25 14:49:42 2003
+++ netfilter/userspace/extensions/libip6t_dst.c Mon Aug 25 16:15:43 2003
@@ -6,44 +6,37 @@
#include <getopt.h>
#include <errno.h>
#include <ip6tables.h>
-/*#include <linux/in6.h>*/
#include <linux/netfilter_ipv6/ip6t_opts.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
-
-#define DEBUG 0
-#define HOPBYHOP 0
-#define UNAME (HOPBYHOP ? "HBH" : "DST")
-#define LNAME (HOPBYHOP ? "hbh" : "dst")
+
+#ifdef HOPBYHOP
+#define UNAME "HBH"
+#define LNAME "hbh"
+#else
+#define UNAME "DST"
+#define LNAME "dst"
+#endif
/* Function which prints out usage message. */
static void
help(void)
{
printf(
-"%s v%s options:\n"
-" --%s-len [!] length total length of this header\n"
-" --%s-opts TYPE[:LEN][,TYPE[:LEN]...] \n"
+UNAME " v%s options:\n"
+" --" LNAME "-len [!] length total length of this header\n"
+" --" LNAME "-opts TYPE[:LEN][,TYPE[:LEN]...] \n"
" Options and its length (list, max: %d)\n",
-UNAME , IPTABLES_VERSION, LNAME, LNAME, IP6T_OPTS_OPTSNR);
+IPTABLES_VERSION, IP6T_OPTS_OPTSNR);
}
-#if HOPBYHOP
static struct option opts[] = {
- { .name = "hbh-len", .has_arg = 1, .flag = 0, .val = '1' },
- { .name = "hbh-opts", .has_arg = 1, .flag = 0, .val = '2' },
- { .name = "hbh-not-strict", .has_arg = 1, .flag = 0, .val = '3' },
+ { .name = LNAME "-len", .has_arg = 1, .flag = 0, .val = '1' },
+ { .name = LNAME "-opts", .has_arg = 1, .flag = 0, .val = '2' },
+ { .name = LNAME "-not-strict", .has_arg = 1, .flag = 0, .val = '3' },
{ .name = 0 }
};
-#else
-static struct option opts[] = {
- { .name = "dst-len", .has_arg = 1, .flag = 0, .val = '1' },
- { .name = "dst-opts", .has_arg = 1, .flag = 0, .val = '2' },
- { .name = "dst-not-strict", .has_arg = 1, .flag = 0, .val = '3' },
- { .name = 0 }
-};
-#endif
static u_int32_t
parse_opts_num(const char *idstr, const char *typestr)
@@ -55,16 +48,16 @@
if ( idstr == ep ) {
exit_error(PARAMETER_PROBLEM,
- "%s no valid digits in %s `%s'", UNAME, typestr, idstr);
+ UNAME " no valid digits in %s `%s'", typestr, idstr);
}
if ( id == ULONG_MAX && errno == ERANGE ) {
exit_error(PARAMETER_PROBLEM,
"%s `%s' specified too big: would overflow",
typestr, idstr);
- }
+ }
if ( *idstr != '\0' && *ep != '\0' ) {
exit_error(PARAMETER_PROBLEM,
- "%s error parsing %s `%s'", UNAME, typestr, idstr);
+ UNAME " error parsing %s `%s'", typestr, idstr);
}
return (u_int32_t) id;
}
@@ -76,39 +69,47 @@
unsigned int i;
buffer = strdup(optsstr);
- if (!buffer) exit_error(OTHER_PROBLEM, "strdup failed");
+ if (!buffer)
+ exit_error(OTHER_PROBLEM, "strdup failed");
- for (cp=buffer, i=0; cp && i<IP6T_OPTS_OPTSNR; cp=next,i++)
+ for (cp = buffer, i = 0; cp && i < IP6T_OPTS_OPTSNR; cp = next, i++)
{
- next=strchr(cp, ',');
- if (next) *next++='\0';
+ next = strchr(cp, ',');
+
+ if (next)
+ *next++='\0';
+
range = strchr(cp, ':');
+
if (range) {
if (i == IP6T_OPTS_OPTSNR-1)
exit_error(PARAMETER_PROBLEM,
"too many ports specified");
*range++ = '\0';
}
+
opts[i] = (u_int16_t)((parse_opts_num(cp,"opt") & 0x000000FF)<<8);
if (range) {
if (opts[i] == 0)
- exit_error(PARAMETER_PROBLEM, "PAD0 hasn't got length");
+ exit_error(PARAMETER_PROBLEM,
+ "PAD0 hasn't got length");
opts[i] |= (u_int16_t)(parse_opts_num(range,"length") &
0x000000FF);
- } else {
+ } else
opts[i] |= (0x00FF);
- }
-#if DEBUG
+#ifdef DEBUG
printf("opts str: %s %s\n", cp, range);
printf("opts opt: %04X\n", opts[i]);
#endif
}
- if (cp) exit_error(PARAMETER_PROBLEM, "too many addresses specified");
+
+ if (cp)
+ exit_error(PARAMETER_PROBLEM, "too many addresses specified");
free(buffer);
-#if DEBUG
+#ifdef DEBUG
printf("addr nr: %d\n", i);
#endif
@@ -141,7 +142,7 @@
case '1':
if (*flags & IP6T_OPTS_LEN)
exit_error(PARAMETER_PROBLEM,
- "Only one `--%s-len' allowed", LNAME);
+ "Only one `--" LNAME "-len' allowed");
check_inverse(optarg, &invert, &optind, 0);
optinfo->hdrlen = parse_opts_num(argv[optind-1], "length");
if (invert)
@@ -152,11 +153,11 @@
case '2':
if (*flags & IP6T_OPTS_OPTS)
exit_error(PARAMETER_PROBLEM,
- "Only one `--%s-opts' allowed", LNAME);
+ "Only one `--" LNAME "-opts' allowed");
check_inverse(optarg, &invert, &optind, 0);
if (invert)
exit_error(PARAMETER_PROBLEM,
- " '!' not allowed with `--%s-opts'", LNAME);
+ " '!' not allowed with `--" LNAME "-opts'");
optinfo->optsnr = parse_options(argv[optind-1], optinfo->opts);
optinfo->flags |= IP6T_OPTS_OPTS;
*flags |= IP6T_OPTS_OPTS;
@@ -164,10 +165,11 @@
case '3':
if (*flags & IP6T_OPTS_NSTRICT)
exit_error(PARAMETER_PROBLEM,
- "Only one `--%s-not-strict' allowed", LNAME);
+ "Only one `--" LNAME "-not-strict' allowed");
if ( !(*flags & IP6T_OPTS_OPTS) )
exit_error(PARAMETER_PROBLEM,
- "`--%s-opts ...' required before `--%s-not-strict'", LNAME, LNAME);
+ "`--" LNAME "-opts ...' required before `--"
+ LNAME "-not-strict'");
optinfo->flags |= IP6T_OPTS_NSTRICT;
*flags |= IP6T_OPTS_NSTRICT;
break;
@@ -189,12 +191,13 @@
{
unsigned int i;
- for(i=0; i<optsnr; i++){
- printf("%d", (optsp[i] & 0xFF00)>>8);
- if ((optsp[i] & 0x00FF) != 0x00FF){
+ for(i = 0; i < optsnr; i++) {
+ printf("%d", (optsp[i] & 0xFF00) >> 8);
+
+ if ((optsp[i] & 0x00FF) != 0x00FF)
printf(":%d", (optsp[i] & 0x00FF));
- }
- printf("%c", (i!=optsnr-1)?',':' ');
+
+ printf("%c", (i != optsnr - 1) ? ',' : ' ');
}
}
@@ -205,7 +208,7 @@
{
const struct ip6t_opts *optinfo = (struct ip6t_opts *)match->data;
- printf("%s ", LNAME);
+ printf(LNAME " ");
if (optinfo->flags & IP6T_OPTS_LEN)
printf("length:%s%u ",
optinfo->invflags & IP6T_OPTS_INV_LEN ? "!" : "",
@@ -230,34 +233,30 @@
const struct ip6t_opts *optinfo = (struct ip6t_opts *)match->data;
if (optinfo->flags & IP6T_OPTS_LEN) {
- printf("--%s-len %s%u ", LNAME,
+ printf("--" LNAME "-len %s%u ",
(optinfo->invflags & IP6T_OPTS_INV_LEN) ? "! " : "",
optinfo->hdrlen);
}
if (optinfo->flags & IP6T_OPTS_OPTS)
- printf("--%s-opts ", LNAME);
+ printf("--" LNAME "-opts ");
print_options(optinfo->optsnr, (u_int16_t *)optinfo->opts);
if (optinfo->flags & IP6T_OPTS_NSTRICT)
- printf("--%s-not-strict ", LNAME);
+ printf("--" LNAME "-not-strict ");
}
static
struct ip6tables_match optstruct = {
-#if HOPBYHOP
- .name = "hbh",
-#else
- .name = "dst",
-#endif
+ .name = LNAME,
.version = IPTABLES_VERSION,
.size = IP6T_ALIGN(sizeof(struct ip6t_opts)),
.userspacesize = IP6T_ALIGN(sizeof(struct ip6t_opts)),
.help = &help,
.init = &init,
.parse = &parse,
- .final = &final_check,
+ .final_check = &final_check,
.print = &print,
.save = &save,
.extra_opts = opts
next reply other threads:[~2003-09-04 18:34 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-04 18:34 Stephane Ouellette [this message]
2003-09-04 21:53 ` [PATCH] libip6t_dst.c Harald Welte
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=3F5785BD.9010202@videotron.ca \
--to=ouellettes@videotron.ca \
--cc=laforge@netfilter.org \
--cc=netfilter-devel@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.