iptables: ip6table version support and libip6t_multiport.fix
PATCH 1/1 iptables: ip6table version support and libip6t_multiport.fix
details: http://bugs.debian.org/329775
The [email protected] address reaches all interested Debian parties.
Rémi Denis-Courmont has submitted a patch to that adds version support to ip6tables and updates libip6t_multiport to v1. (Rémi also posted to the list but something appears to have gone wrong.)
It Works for Me.
extensions/libip6t_multiport.c +199 -1
@@ -20,6 +20,23 @@" --dports ...\n" " match destination port(s)\n" " --ports port[,port,port]\n" +" match both source and destination port(s)\n" +" NOTE: this kernel does not support port ranges in multiport.\n" , +IPTABLES_VERSION); +} + +static void +help_v1 (void ) +{ +printf ( +"multiport v%s options:\n" +" --source-ports [!] port[,port:port,port...]\n" +" --sports ...\n" +" match source port(s)\n" +" --destination-ports [!] port[,port:port,port...]\n" +" --dports ...\n" +" match destination port(s)\n" +" --ports [!] port[,port:port,port]\n" " match both source and destination port(s)\n" ,IPTABLES_VERSION ); }
@@ -49,7 +66,7 @@ {unsigned int portnum; -if ((string_to_number (port,0 ,65535 , &portnum)) !=-1 || +if (string_to_number (port,0 ,65535 , &portnum) !=-1 || (portnum =service_to_port (port, proto)) !=-1 )return (u_int16_t )portnum;
@@ -77,6 +94,46 @@return i; } +static void +parse_multi_ports_v1 (const char *portstring, +struct xt_multiport_v1 *multiinfo, +const char *proto) +{ +char *buffer, *cp, *next, *range; +unsigned int i; +u_int16_t m; + + buffer =strdup (portstring); +if (!buffer)exit_error (OTHER_PROBLEM ,"strdup failed" ); + +for (i=0 ; i<XT_MULTI_PORTS ; i++) + multiinfo->pflags[i] =0 ; + +for (cp=buffer, i=0 ; cp && i<XT_MULTI_PORTS ; cp=next, i++) { + next=strchr (cp,',' ); +if (next) *next++='\0' ; + range =strchr (cp,':' ); +if (range) { +if (i ==XT_MULTI_PORTS -1 ) +exit_error (PARAMETER_PROBLEM , +"too many ports specified" ); + *range++ ='\0' ; + } + multiinfo->ports[i] =parse_port (cp, proto); +if (range) { + multiinfo->pflags[i] =1 ; + multiinfo->ports[++i] =parse_port (range, proto); +if (multiinfo->ports[i-1 ] >= multiinfo->ports[i]) +exit_error (PARAMETER_PROBLEM , +"invalid portrange specified" ); + m <<=1 ; + } + } + multiinfo->count = i; +if (cp)exit_error (PARAMETER_PROBLEM ,"too many ports specified" ); +free (buffer); +} +/* Initialize the match. */ static void init (struct ip6t_entry_match *m,unsigned int *nfcache)
@@ -150,6 +207,52 @@return 1 ; } +static int +parse_v1 (int c,char **argv,int invert,unsigned int *flags, +const struct ip6t_entry *entry, +unsigned int *nfcache, +struct ip6t_entry_match **match) +{ +const char *proto; +struct xt_multiport_v1 *multiinfo + = (struct xt_multiport_v1 *)(*match)->data; + +switch (c) { +case '1' : +check_inverse (argv[optind-1 ], &invert, &optind,0 ); + proto =check_proto (entry); +parse_multi_ports_v1 (argv[optind-1 ], multiinfo, proto); + multiinfo->flags =IP6T_MULTIPORT_SOURCE ; +break ; + +case '2' : +check_inverse (argv[optind-1 ], &invert, &optind,0 ); + proto =check_proto (entry); +parse_multi_ports_v1 (argv[optind-1 ], multiinfo, proto); + multiinfo->flags =IP6T_MULTIPORT_DESTINATION ; +break ; + +case '3' : +check_inverse (argv[optind-1 ], &invert, &optind,0 ); + proto =check_proto (entry); +parse_multi_ports_v1 (argv[optind-1 ], multiinfo, proto); + multiinfo->flags =IP6T_MULTIPORT_EITHER ; +break ; + +default : +return 0 ; + } + +if (invert) + multiinfo->invert =1 ; + +if (*flags) +exit_error (PARAMETER_PROBLEM , +"multiport can only have one option" ); + *flags =1 ; +return 1 ; +} +/* Final check; must specify something. */ static void final_check (unsigned int flags)
@@ -218,6 +321,49 @@printf (" " ); } +static void +print_v1 (const struct ip6t_ip6 *ip, +const struct ip6t_entry_match *match, +int numeric) +{ +const struct xt_multiport_v1 *multiinfo + = (const struct xt_multiport_v1 *)match->data; +unsigned int i; + +printf ("multiport " ); + +switch (multiinfo->flags) { +case IP6T_MULTIPORT_SOURCE : +printf ("sports " ); +break ; + +case IP6T_MULTIPORT_DESTINATION : +printf ("dports " ); +break ; + +case IP6T_MULTIPORT_EITHER : +printf ("ports " ); +break ; + +default : +printf ("ERROR " ); +break ; + } + +if (multiinfo->invert) +printf ("! " ); + +for (i=0 ; i < multiinfo->count; i++) { +printf ("%s" , i ?"," :"" ); +print_port (multiinfo->ports[i], ip->proto, numeric); +if (multiinfo->pflags[i]) { +printf (":" ); +print_port (multiinfo->ports[++i], ip->proto, numeric); + } + } +printf (" " ); +} +/* Saves the union ip6t_matchinfo in parsable form to stdout. */ static void save (const struct ip6t_ip6 *ip,const struct ip6t_entry_match *match) {
@@ -246,6 +392,41 @@printf (" " ); } +static void save_v1 (const struct ip6t_ip6 *ip, +const struct ip6t_entry_match *match) +{ +const struct xt_multiport_v1 *multiinfo + = (const struct xt_multiport_v1 *)match->data; +unsigned int i; + +switch (multiinfo->flags) { +case IP6T_MULTIPORT_SOURCE : +printf ("--sports " ); +break ; + +case IP6T_MULTIPORT_DESTINATION : +printf ("--dports " ); +break ; + +case IP6T_MULTIPORT_EITHER : +printf ("--ports " ); +break ; + } + +if (multiinfo->invert) +printf ("! " ); + +for (i=0 ; i < multiinfo->count; i++) { +printf ("%s" , i ?"," :"" ); +print_port (multiinfo->ports[i], ip->proto,1 ); +if (multiinfo->pflags[i]) { +printf (":" ); +print_port (multiinfo->ports[++i], ip->proto,1 ); + } + } +printf (" " ); +} +static struct ip6tables_match multiport = { .name ="multiport" , .version =IPTABLES_VERSION ,
@@ -260,8 +441,25 @@ .extra_opts = opts, }; +static struct ip6tables_match multiport_v1 = { + .next =NULL , + .name ="multiport" , + .revision =1 , + .version =IPTABLES_VERSION , + .size =IP6T_ALIGN (sizeof (struct xt_multiport_v1 )), + .userspacesize =IP6T_ALIGN (sizeof (struct xt_multiport_v1 )), + .help = &help_v1, + .init = &init, + .parse = &parse_v1, + .final_check = &final_check, + .print = &print_v1, + .save = &save_v1, + .extra_opts = opts +}; +void _init (void ) {register_match6 (&multiport); +register_match6 (&multiport_v1); }
include/ip6tables.h +3 -0
@@ -22,6 +22,9 @@ip6t_chainlabel name; +/* Revision of match (0 by default). */ +u_int8_t revision; +const char *version;/* Size of match data. */
ip6tables.c +81 -3
127 lines not on this page · raw message
Quoted 10 lines · Laurence J. Lane
details: http://bugs.debian.org/329775
The [email protected] address reaches all interested Debian parties.
Rémi Denis-Courmont has submitted a patch to that adds version support to ip6tables and updates
libip6t_multiportto v1. (Rémi also posted to the list but something appears to have gone wrong.)It Works for Me.
I guess the list software ate the attachment.
diff -Nru iptables-1.3.5.orig/extensions/libip6t_multiport.c iptables-1.3.5/extensions/libip6t_multiport.c
--- iptables-1.3.5.orig/extensions/libip6t_multiport.c 2005-02-19
21:19:17.000000000 +0200
+++ iptables-1.3.5/extensions/libip6t_multiport.c 2006-08-27
13:03:36.000000000 +0300
@@ -20,6 +20,23 @@
" --dports ...\n"
" match destination port(s)\n"
" --ports port[,port,port]\n"
+" match both source and destination port(s)\n"
+" NOTE: this kernel does not support port ranges in multiport.\n", +IPTABLES_VERSION);
+}
+
+static void
+help_v1(void)
+{
+ printf(
+"multiport v%s options:\n"
+" --source-ports [!] port[,port:port,port...]\n"
+" --sports ...\n"
+" match source port(s)\n"
+" --destination-ports [!] port[,port:port,port...]\n" +" --dports ...\n"
+" match destination port(s)\n"
+" --ports [!] port[,port:port,port]\n"
" match both source and destination port(s)\n",IPTABLES_VERSION);
}
@@ -49,7 +66,7 @@
{
unsigned int portnum;- if ((string_to_number(port, 0, 65535, &portnum)) != -1 ||
+ if (string_to_number(port, 0, 65535, &portnum) != -1 ||
(portnum = service_to_port(port, proto)) != -1) return (u_int16_t)portnum;
@@ -77,6 +94,46 @@
return i; }
+static void
+parse_multi_ports_v1(const char *portstring,
+ struct xt_multiport_v1 *multiinfo,
+ const char *proto)
+{
+ char *buffer, *cp, *next, *range;
+ unsigned int i;
+ u_int16_t m;
+
+ buffer = strdup(portstring);
+ if (!buffer) exit_error(OTHER_PROBLEM, "strdup failed");
+
+ for (i=0; i<XT_MULTI_PORTS; i++)
+ multiinfo->pflags[i] = 0;
+
+ for (cp=buffer, i=0; cp && i<XT_MULTI_PORTS; cp=next, i++) {
+ next=strchr(cp, ',');
+ if (next) *next++='\0';
+ range = strchr(cp, ':');
+ if (range) {
+ if (i == XT_MULTI_PORTS-1)
+ exit_error(PARAMETER_PROBLEM,
+ "too many ports specified");
+ *range++ = '\0';
+ }
+ multiinfo->ports[i] = parse_port(cp, proto);
+ if (range) {
+ multiinfo->pflags[i] = 1;
+ multiinfo->ports[++i] = parse_port(range, proto);
+ if (multiinfo->ports[i-1] >= multiinfo->ports[i])
+ exit_error(PARAMETER_PROBLEM,
+ "invalid portrange specified");
+ m <<= 1;
+ }
+ }
+ multiinfo->count = i;
+ if (cp) exit_error(PARAMETER_PROBLEM, "too many ports specified");
+ free(buffer);
+}
+
/* Initialize the match. */
static voidinit(struct ip6t_entry_match *m, unsigned int *nfcache) @@ -150,6 +207,52 @@
return 1; }
+static int
+parse_v1(int c, char **argv, int invert, unsigned int *flags,
+ const struct ip6t_entry *entry,
+ unsigned int *nfcache,
+ struct ip6t_entry_match **match)
+{
+ const char *proto;
+ struct xt_multiport_v1 *multiinfo
+ = (struct xt_multiport_v1 *)(*match)->data;
+
+ switch (c) {
+ case '1':
+ check_inverse(argv[optind-1], &invert, &optind, 0);
+ proto = check_proto(entry);
+ parse_multi_ports_v1(argv[optind-1], multiinfo, proto);
+ multiinfo->flags = IP6T_MULTIPORT_SOURCE;
+ break;
+
+ case '2':
+ check_inverse(argv[optind-1], &invert, &optind, 0);
+ proto = check_proto(entry);
+ parse_multi_ports_v1(argv[optind-1], multiinfo, proto);
+ multiinfo->flags = IP6T_MULTIPORT_DESTINATION;
+ break;
+
+ case '3':
+ check_inverse(argv[optind-1], &invert, &optind, 0);
+ proto = check_proto(entry);
+ parse_multi_ports_v1(argv[optind-1], multiinfo, proto);
+ multiinfo->flags = IP6T_MULTIPORT_EITHER;
+ break;
+
+ default:
+ return 0;
+ }
+
+ if (invert)
+ multiinfo->invert = 1;
+
+ if (*flags)
+ exit_error(PARAMETER_PROBLEM,
+ "multiport can only have one option");
+ *flags = 1;
+ return 1;
+}
+
/* Final check; must specify something. */
static voidfinal_check(unsigned int flags)
@@ -218,6 +321,49 @@
printf(" ");
}+static void
+print_v1(const struct ip6t_ip6 *ip,
+ const struct ip6t_entry_match *match,
+ int numeric)
+{
+ const struct xt_multiport_v1 *multiinfo
+ = (const struct xt_multiport_v1 *)match->data;
+ unsigned int i;
+
+ printf("multiport ");
+
+ switch (multiinfo->flags) {
+ case IP6T_MULTIPORT_SOURCE:
+ printf("sports ");
+ break;
+
+ case IP6T_MULTIPORT_DESTINATION:
+ printf("dports ");
+ break;
+
+ case IP6T_MULTIPORT_EITHER:
+ printf("ports ");
+ break;
+
+ default:
+ printf("ERROR ");
+ break;
+ }
+
+ if (multiinfo->invert)
+ printf("! ");
+
+ for (i=0; i < multiinfo->count; i++) {
+ printf("%s", i ? "," : "");
+ print_port(multiinfo->ports[i], ip->proto, numeric);
+ if (multiinfo->pflags[i]) {
+ printf(":");
+ print_port(multiinfo->ports[++i], ip->proto, numeric);
+ }
+ }
+ printf(" ");
+}
+
/* Saves the union ip6t_matchinfo in parsable form to stdout. */ static void save(const struct ip6t_ip6 *ip, const struct ip6t_entry_match *match)
{
@@ -246,6 +392,41 @@
printf(" ");
}+static void save_v1(const struct ip6t_ip6 *ip,
+ const struct ip6t_entry_match *match)
+{
+ const struct xt_multiport_v1 *multiinfo
+ = (const struct xt_multiport_v1 *)match->data;
+ unsigned int i;
+
+ switch (multiinfo->flags) {
+ case IP6T_MULTIPORT_SOURCE:
+ printf("--sports ");
+ break;
+
+ case IP6T_MULTIPORT_DESTINATION:
+ printf("--dports ");
+ break;
+
+ case IP6T_MULTIPORT_EITHER:
+ printf("--ports ");
+ break;
+ }
+
+ if (multiinfo->invert)
+ printf("! ");
+
+ for (i=0; i < multiinfo->count; i++) {
+ printf("%s", i ? "," : "");
+ print_port(multiinfo->ports[i], ip->proto, 1);
+ if (multiinfo->pflags[i]) {
+ printf(":");
+ print_port(multiinfo->ports[++i], ip->proto, 1);
+ }
+ }
+ printf(" ");
+}
+
static struct ip6tables_match multiport = {
.name = "multiport",
.version = IPTABLES_VERSION,
@@ -260,8 +441,25 @@
.extra_opts = opts,
};+static struct ip6tables_match multiport_v1 = {
+ .next = NULL,
+ .name = "multiport",
+ .revision = 1,
+ .version = IPTABLES_VERSION,
+ .size = IP6T_ALIGN(sizeof(struct xt_multiport_v1)),
+ .userspacesize = IP6T_ALIGN(sizeof(struct xt_multiport_v1)),
+ .help = &help_v1,
+ .init = &init,
+ .parse = &parse_v1,
+ .final_check = &final_check,
+ .print = &print_v1,
+ .save = &save_v1,
+ .extra_opts = opts
+};
+
void_init(void)
{
register_match6(&multiport);+ register_match6(&multiport_v1);
}
diff -Nru iptables-1.3.5.orig/include/ip6tables.hiptables-1.3.5/include/ip6tables.h
include/ip6tables.h +0 -0
@@ -22,6 +22,9 @@
ip6t_chainlabel name;
+ /* Revision of match (0 by default). */
+ u_int8_t revision;
+
const char *version; /* Size of match data. */
ip6tables.c +0 -0
@@ -193,6 +193,8 @@
const char *program_name;
char *lib_dir;
+int kernel_version;
+
/* Keeping track of external matches and targets: linked lists. */ struct ip6tables_match *ip6tables_matches = NULL;
struct ip6tables_target *ip6tables_targets = NULL;
@@ -1047,10 +1049,51 @@
return merge; }
+static int compatible_revision(const char *name, u_int8_t revision, int opt) +{
+ struct ip6t_get_revision rev;
+ socklen_t s = sizeof(rev);
+ int max_rev, sockfd;
+
+ sockfd = socket(AF_INET6, SOCK_RAW, IPPROTO_RAW);
+ if (sockfd < 0) {
+ fprintf(stderr, "Could not open socket to kernel: %s\n",
+ strerror(errno));
+ exit(1);
+ }
+
+ strcpy(rev.name, name);
+ rev.revision = revision;
+
+ max_rev = getsockopt(sockfd, IPPROTO_IPV6, opt, &rev, &s);
+ if (max_rev < 0) {
+ /* Definitely don't support this? */
+ if (errno == EPROTONOSUPPORT) {
+ close(sockfd);
+ return 0;
+ } else if (errno == ENOPROTOOPT) {
+ close(sockfd);
+ /* Assume only revision 0 support (old kernel) */
+ return (revision == 0);
+ } else {
+ fprintf(stderr, "getsockopt failed strangely: %s\n",
+ strerror(errno));
+ exit(1);
+ }
+ }
+ close(sockfd);
+ return 1;
+}
+
+static int compatible_match_revision(const char *name, u_int8_t revision) +{
+ return compatible_revision(name, revision, IP6T_SO_GET_REVISION_MATCH);
+}
+
voidregister_match6(struct ip6tables_match *me)
{
- struct ip6tables_match **i;
+ struct ip6tables_match **i, *old;
if (strcmp(me->version, program_version) != 0) {
fprintf(stderr, "%s: match `%s' v%s (I'm v%s).\n",
@@ -1058,12 +1101,36 @@
exit(1);
}- if (find_match(me->name, DURING_LOAD, NULL)) {
- fprintf(stderr, "%s: match `%s' already registered.\n",
+ /* Revision field stole a char from name. */
+ if (strlen(me->name) >= IP6T_FUNCTION_MAXNAMELEN-1) {
+ fprintf(stderr, "%s: target `%s' has invalid name\n",
program_name, me->name); exit(1); }
+ old = find_match(me->name, DURING_LOAD, NULL);
+ if (old) {
+ if (old->revision == me->revision) {
+ fprintf(stderr,
+ "%s: match `%s' already registered.\n",
+ program_name, me->name);
+ exit(1);
+ }
+
+ /* Now we have two (or more) options, check compatibility. */
+ if (compatible_match_revision(old->name, old->revision)
+ && old->revision > me->revision)
+ return;
+
+ /* Replace if compatible. */
+ if (!compatible_match_revision(me->name, me->revision))
+ return;
+
+ /* Delete old one. */
+ for (i = &ip6tables_matches; *i!=old; i = &(*i)->next);
+ *i = old->next;
+ }
+
if (me->size != IP6T_ALIGN(me->size)) {
fprintf(stderr, "%s: match `%s' has invalid size %u.\n",
program_name, me->name, (unsigned int)me->size);
@@ -1700,6 +1767,14 @@
*matches = NULL;
}+static void set_revision(char *name, u_int8_t revision)
+{
+ /* Old kernel sources don't have ".revision" field,
+ but we stole a byte from name. */
+ name[IP6T_FUNCTION_MAXNAMELEN - 2] = '\0';
+ name[IP6T_FUNCTION_MAXNAMELEN - 1] = revision;
+}
+
int do_command6(int argc, char *argv[], char **table, ip6tc_handle_t *handle)
{
struct ip6t_entry fw, *e = NULL;
@@ -1978,6 +2053,7 @@
m->m = fw_calloc(1, size);
m->m->u.match_size = size;
strcpy(m->m->u.user.name, m->name);
+ set_revision(m->m->u.user.name, m->revision);
if (m->init != NULL)
m->init(m->m, &fw.nfcache);
opts = merge_options(opts, m->extra_opts, &m->option_offset);
@@ -2120,6 +2196,8 @@
m->m = fw_calloc(1, size);
m->m->u.match_size = size;
strcpy(m->m->u.user.name, m->name);
+ set_revision(m->m->u.user.name,
+ m->revision);
if (m->init != NULL)
m->init(m->m, &fw.nfcache);Hello,
From: "Laurence J. Lane" <[email protected]>
Date: Sun, 1 Oct 2006 21:37:54 -0400
Quoted 7 lines · Laurence J. Lane
Quoted 6 lines
details: http://bugs.debian.org/329775
The [email protected] address reaches all interested Debian parties.
Quoted 7 lines
Quoted 5 lines
Rémi Denis-Courmont has submitted a patch to that adds version support to ip6tables and updates
libip6t_multiportto v1. (Rémi also posted to the list but something appears to have gone wrong.)It Works for Me.
I guess the list software ate the attachment.
Great! I'll read deeply that.
Quoted 6 lines
(quoted diff) +6
-0+static void +parse_multi_ports_v1(const char *portstring, + struct xt_multiport_v1 *multiinfo, + const char *proto) +{ + char *buffer, *cp, *next, *range;
Review
Quoted 10 lines
(quoted diff) +10
-0+ unsigned int i; + u_int16_t m; + + buffer = strdup(portstring); + if (!buffer) exit_error(OTHER_PROBLEM, "strdup failed"); + + for (i=0; i<XT_MULTI_PORTS; i++) + multiinfo->pflags[i] = 0; + + for (cp=buffer, i=0; cp && i<XT_MULTI_PORTS; cp=next, i++) {
Please use IP6T_MULTI_PORTS so that we can compile with linux 2.4.
Regards,
-- Yasuyuki Kozakai
Le lundi 2 octobre 2006 07:46, Yasuyuki KOZAKAI a écrit :
(...)
Quoted 1 line
Please use
IP6T_MULTI_PORTSso that we can compile with linux 2.4.
There you go (also resynched with latest SVN), but won't it fail with xt_multiport_v1 anyway (there is no ip6t_multiport_v1 in *any* kernel version to date, AFAIK)?
ip6tables.h +3 -0
@@ -33,6 +33,9 @@ip6t_chainlabel name; +/* Revision of match (0 by default). */ +u_int8_t revision; +const char *version;/* Size of match data. */
libip6t_multiport.c +146 -0
169 lines not on this page · raw message
ip6t_entry_match *match)
{
@@ -238,6 +384,41 @@
printf(" ");
}
+static void save_v1(const struct ip6t_ip6 *ip,
+ const struct ip6t_entry_match *match)
+{
+ const struct xt_multiport_v1 *multiinfo
+ = (const struct xt_multiport_v1 *)match->data;
+ unsigned int i;
+
+ switch (multiinfo->flags) {
+ case IP6T_MULTIPORT_SOURCE:
+ printf("--sports ");
+ break;
+
+ case IP6T_MULTIPORT_DESTINATION:
+ printf("--dports ");
+ break;
+
+ case IP6T_MULTIPORT_EITHER:
+ printf("--ports ");
+ break;
+ }
+
+ if (multiinfo->invert)
+ printf("! ");
+
+ for (i=0; i < multiinfo->count; i++) {
+ printf("%s", i ? "," : "");
+ print_port(multiinfo->ports[i], ip->proto, 1);
+ if (multiinfo->pflags[i]) {
+ printf(":");
+ print_port(multiinfo->ports[++i], ip->proto, 1);
+ }
+ }
+ printf(" ");
+}
+
static struct ip6tables_match multiport = {
.name = "multiport",
.version = IPTABLES_VERSION,
@@ -252,8 +433,25 @@
.extra_opts = opts,
};
+static struct ip6tables_match multiport_v1 = {
+ .next = NULL,
+ .name = "multiport",
+ .revision = 1,
+ .version = IPTABLES_VERSION,
+ .size = IP6T_ALIGN(sizeof(struct xt_multiport_v1)),
+ .userspacesize = IP6T_ALIGN(sizeof(struct xt_multiport_v1)),
+ .help = &help_v1,
+ .init = &init,
+ .parse = &parse_v1,
+ .final_check = &final_check,
+ .print = &print_v1,
+ .save = &save_v1,
+ .extra_opts = opts
+};
+
void
_init(void)
{
register_match6(&multiport);
+ register_match6(&multiport_v1);
}
ip6tables.c +3 -0
@@ -193,6 +193,8 @@const char *program_name;char *lib_dir; +int kernel_version; +/* Keeping track of external matches and targets: linked lists. */ struct ip6tables_match *ip6tables_matches =NULL ;struct ip6tables_target *ip6tables_targets =NULL ;
@@ -1102,10 +1104,51 @@return merge; } +static int compatible_revision(const char *name, u_int8_t revision, int
opt)
+{
+ struct ip6t_get_revision rev;
+ socklen_t s = sizeof(rev);
+ int max_rev, sockfd;
+
+ sockfd = socket(AF_INET6, SOCK_RAW, IPPROTO_RAW);
+ if (sockfd < 0) {
+ fprintf(stderr, "Could not open socket to kernel: %s\n",
+ strerror(errno));
+ exit(1);
+ }
+
+ strcpy(rev.name, name);
+ rev.revision = revision;
+
+ max_rev = getsockopt(sockfd, IPPROTO_IPV6, opt, &rev, &s);
+ if (max_rev < 0) {
+ /* Definitely don't support this? */
+ if (errno == EPROTONOSUPPORT) {
+ close(sockfd);
+ return 0;
+ } else if (errno == ENOPROTOOPT) {
+ close(sockfd);
+ /* Assume only revision 0 support (old kernel) */
+ return (revision == 0);
+ } else {
+ fprintf(stderr, "getsockopt failed strangely: %s\n",
+ strerror(errno));
+ exit(1);
+ }
+ }
+ close(sockfd);
+ return 1;
+}
+
+static int compatible_match_revision(const char *name, u_int8_t revision)
+{
+ return compatible_revision(name, revision,IP6T_SO_GET_REVISION_MATCH);
+}
+
void
register_match6(struct ip6tables_match *me)
{
- struct ip6tables_match **i;
+ struct ip6tables_match **i, *old;
if (strcmp(me->version, program_version) != 0) {
fprintf(stderr, "%s: match `%s' v%s (I'm v%s).\n",
@@ -1113,12 +1156,36 @@
exit(1);
}
- if (find_match(me->name, DURING_LOAD, NULL)) {
- fprintf(stderr, "%s: match `%s' already registered.\n",
+ /* Revision field stole a char from name. */
+ if (strlen(me->name) >= IP6T_FUNCTION_MAXNAMELEN-1) {
+ fprintf(stderr, "%s: target `%s' has invalid name\n",
program_name, me->name);
exit(1);
}
+ old = find_match(me->name, DURING_LOAD, NULL);
+ if (old) {
+ if (old->revision == me->revision) {
+ fprintf(stderr,
+ "%s: match `%s' already registered.\n",
+ program_name, me->name);
+ exit(1);
+ }
+
+ /* Now we have two (or more) options, check compatibility. */
+ if (compatible_match_revision(old->name, old->revision)
+ && old->revision > me->revision)
+ return;
+
+ /* Replace if compatible. */
+ if (!compatible_match_revision(me->name, me->revision))
+ return;
+
+ /* Delete old one. */
+ for (i = &ip6tables_matches; *i!=old; i = &(*i)->next);
+ *i = old->next;
+ }
+
if (me->size != IP6T_ALIGN(me->size)) {
fprintf(stderr, "%s: match `%s' has invalid size %u.\n",
program_name, me->name, (unsigned int)me->size);
@@ -1761,6 +1828,14 @@
*matches = NULL;
}
+static void set_revision(char *name, u_int8_t revision)
+{
+ /* Old kernel sources don't have ".revision" field,
+ but we stole a byte from name. */
+ name[IP6T_FUNCTION_MAXNAMELEN - 2] = '\0';
+ name[IP6T_FUNCTION_MAXNAMELEN - 1] = revision;
+}
+
int do_command6(int argc, char *argv[], char **table, ip6tc_handle_t
*handle)
{
struct ip6t_entry fw, *e = NULL;
@@ -2041,6 +2116,7 @@
m->m = fw_calloc(1, size); m->m->u.match_size = size; strcpy(m->m->u.user.name, m->name);
+ set_revision(m->m->u.user.name, m->revision);
if (m->init != NULL)
m->init(m->m, &fw.nfcache);
if (m != m->next)
@@ -2185,6 +2261,8 @@
m->m = fw_calloc(1, size); m->m->u.match_size = size; strcpy(m->m->u.user.name, m->name);
+ set_revision(m->m->u.user.name,
+ m->revision);
if (m->init != NULL)
m->init(m->m, &fw.nfcache);
Signature · 2 lines
Rémi Denis-Courmont http://www.remlab.net/
From: Rémi Denis-Courmont <[email protected]>
Date: Mon, 2 Oct 2006 17:47:42 +0300
Quoted 7 lines · Yasuyuki KOZAKAI
(...)
Quoted 1 line
Please use
IP6T_MULTI_PORTSso that we can compile with linux 2.4.There you go (also resynched with latest SVN), but won't it fail with
xt_multiport_v1anyway (there is noip6t_multiport_v1in *any* kernel version to date, AFAIK)?
But they have multiport v0 features. The revision was introduced to keep compatibility with such features in old kernel and make possible to add new features to new kernel.
IPv4 multiport match (and policy match, too) would help you. It has the line
#include ../../include/netfilter_ipv4/ipt_multiport.h
and definitions for old kernel are included in the header.
-- Yasuyuki Kozakai
A message that is not in the archive (sent off-list or not yet received): [email protected]
Le mardi 3 octobre 2006 17:30, vous avez écrit :
Quoted 6 lines
IPv4 multiport match (and policy match, too) would help you. It has the line
#include ../../include/netfilter_ipv4/ipt_multiport.hand definitions for old kernel are included in the header.
Ok. This time there is no trace of (xt|XT)_ at all:
diff -Nru iptables-1.3.5.orig/extensions/libip6t_multiport.c iptables-1.3.5/extensions/libip6t_multiport.c
--- iptables-1.3.5.orig/extensions/libip6t_multiport.c 2005-02-19
21:19:17.000000000 +0200
+++ iptables-1.3.5/extensions/libip6t_multiport.c 2006-08-27
13:03:36.000000000 +0300
@@ -20,6 +20,23 @@
" --dports ...\n"
" match destination port(s)\n"
" --ports port[,port,port]\n"
+" match both source and destination port(s)\n"
+" NOTE: this kernel does not support port ranges in multiport.\n", +IPTABLES_VERSION);
+}
+
+static void
+help_v1(void)
+{
+ printf(
+"multiport v%s options:\n"
+" --source-ports [!] port[,port:port,port...]\n"
+" --sports ...\n"
+" match source port(s)\n"
+" --destination-ports [!] port[,port:port,port...]\n" +" --dports ...\n"
+" match destination port(s)\n"
+" --ports [!] port[,port:port,port]\n"
" match both source and destination port(s)\n",
IPTABLES_VERSION);
}
@@ -49,7 +66,7 @@
{
unsigned int portnum;
- if ((string_to_number(port, 0, 65535, &portnum)) != -1 ||
+ if (string_to_number(port, 0, 65535, &portnum) != -1 ||
(portnum = service_to_port(port, proto)) != -1)
return (u_int16_t)portnum;
@@ -77,6 +94,46 @@
return i;
}
+static void
+parse_multi_ports_v1(const char *portstring,
+ struct xt_multiport_v1 *multiinfo,
+ const char *proto)
+{
+ char *buffer, *cp, *next, *range;
+ unsigned int i;
+ u_int16_t m;
+
+ buffer = strdup(portstring);
+ if (!buffer) exit_error(OTHER_PROBLEM, "strdup failed");
+
+ for (i=0; i<XT_MULTI_PORTS; i++)
+ multiinfo->pflags[i] = 0;
+
+ for (cp=buffer, i=0; cp && i<XT_MULTI_PORTS; cp=next, i++) {
+ next=strchr(cp, ',');
+ if (next) *next++='\0';
+ range = strchr(cp, ':');
+ if (range) {
+ if (i == XT_MULTI_PORTS-1)
+ exit_error(PARAMETER_PROBLEM,
+ "too many ports specified");
+ *range++ = '\0';
+ }
+ multiinfo->ports[i] = parse_port(cp, proto);
+ if (range) {
+ multiinfo->pflags[i] = 1;
+ multiinfo->ports[++i] = parse_port(range, proto);
+ if (multiinfo->ports[i-1] >= multiinfo->ports[i])
+ exit_error(PARAMETER_PROBLEM,
+ "invalid portrange specified");
+ m <<= 1;
+ }
+ }
+ multiinfo->count = i;
+ if (cp) exit_error(PARAMETER_PROBLEM, "too many ports specified");
+ free(buffer);
+}
+
/* Initialize the match. */
static void
init(struct ip6t_entry_match *m, unsigned int *nfcache)
@@ -150,6 +207,52 @@
return 1;
}
+static int
+parse_v1(int c, char **argv, int invert, unsigned int *flags,
+ const struct ip6t_entry *entry,
+ unsigned int *nfcache,
+ struct ip6t_entry_match **match)
+{
+ const char *proto;
+ struct xt_multiport_v1 *multiinfo
+ = (struct xt_multiport_v1 *)(*match)->data;
+
+ switch (c) {
+ case '1':
+ check_inverse(argv[optind-1], &invert, &optind, 0);
+ proto = check_proto(entry);
+ parse_multi_ports_v1(argv[optind-1], multiinfo, proto);
+ multiinfo->flags = IP6T_MULTIPORT_SOURCE;
+ break;
+
+ case '2':
+ check_inverse(argv[optind-1], &invert, &optind, 0);
+ proto = check_proto(entry);
+ parse_multi_ports_v1(argv[optind-1], multiinfo, proto);
+ multiinfo->flags = IP6T_MULTIPORT_DESTINATION;
+ break;
+
+ case '3':
+ check_inverse(argv[optind-1], &invert, &optind, 0);
+ proto = check_proto(entry);
+ parse_multi_ports_v1(argv[optind-1], multiinfo, proto);
+ multiinfo->flags = IP6T_MULTIPORT_EITHER;
+ break;
+
+ default:
+ return 0;
+ }
+
+ if (invert)
+ multiinfo->invert = 1;
+
+ if (*flags)
+ exit_error(PARAMETER_PROBLEM,
+ "multiport can only have one option");
+ *flags = 1;
+ return 1;
+}
+
/* Final check; must specify something. */
static void
final_check(unsigned int flags)
@@ -218,6 +321,49 @@
printf(" ");
}
+static void
+print_v1(const struct ip6t_ip6 *ip,
+ const struct ip6t_entry_match *match,
+ int numeric)
+{
+ const struct xt_multiport_v1 *multiinfo
+ = (const struct xt_multiport_v1 *)match->data;
+ unsigned int i;
+
+ printf("multiport ");
+
+ switch (multiinfo->flags) {
+ case IP6T_MULTIPORT_SOURCE:
+ printf("sports ");
+ break;
+
+ case IP6T_MULTIPORT_DESTINATION:
+ printf("dports ");
+ break;
+
+ case IP6T_MULTIPORT_EITHER:
+ printf("ports ");
+ break;
+
+ default:
+ printf("ERROR ");
+ break;
+ }
+
+ if (multiinfo->invert)
+ printf("! ");
+
+ for (i=0; i < multiinfo->count; i++) {
+ printf("%s", i ? "," : "");
+ print_port(multiinfo->ports[i], ip->proto, numeric);
+ if (multiinfo->pflags[i]) {
+ printf(":");
+ print_port(multiinfo->ports[++i], ip->proto, numeric);
+ }
+ }
+ printf(" ");
+}
+
/* Saves the union ip6t_matchinfo in parsable form to stdout. */ static void save(const struct ip6t_ip6 *ip, const structip6t_entry_match *match)
{
@@ -246,6 +392,41 @@
printf(" ");
}
+static void save_v1(const struct ip6t_ip6 *ip,
+ const struct ip6t_entry_match *match)
+{
+ const struct xt_multiport_v1 *multiinfo
+ = (const struct xt_multiport_v1 *)match->data;
+ unsigned int i;
+
+ switch (multiinfo->flags) {
+ case IP6T_MULTIPORT_SOURCE:
+ printf("--sports ");
+ break;
+
+ case IP6T_MULTIPORT_DESTINATION:
+ printf("--dports ");
+ break;
+
+ case IP6T_MULTIPORT_EITHER:
+ printf("--ports ");
+ break;
+ }
+
+ if (multiinfo->invert)
+ printf("! ");
+
+ for (i=0; i < multiinfo->count; i++) {
+ printf("%s", i ? "," : "");
+ print_port(multiinfo->ports[i], ip->proto, 1);
+ if (multiinfo->pflags[i]) {
+ printf(":");
+ print_port(multiinfo->ports[++i], ip->proto, 1);
+ }
+ }
+ printf(" ");
+}
+
static struct ip6tables_match multiport = {
.name = "multiport",
.version = IPTABLES_VERSION,
@@ -260,8 +441,25 @@
.extra_opts = opts,
};
+static struct ip6tables_match multiport_v1 = {
+ .next = NULL,
+ .name = "multiport",
+ .revision = 1,
+ .version = IPTABLES_VERSION,
+ .size = IP6T_ALIGN(sizeof(struct xt_multiport_v1)),
+ .userspacesize = IP6T_ALIGN(sizeof(struct xt_multiport_v1)),
+ .help = &help_v1,
+ .init = &init,
+ .parse = &parse_v1,
+ .final_check = &final_check,
+ .print = &print_v1,
+ .save = &save_v1,
+ .extra_opts = opts
+};
+
void
_init(void)
{
register_match6(&multiport);
+ register_match6(&multiport_v1);
}
diff -Nru iptables-1.3.5.orig/include/ip6tables.hiptables-1.3.5/include/ip6tables.h
--- iptables-1.3.5.orig/include/ip6tables.h 2006-01-30
10:43:09.000000000 +0200
+++ iptables-1.3.5/include/ip6tables.h 2006-08-27 13:02:55.000000000
+0300
@@ -22,6 +22,9 @@
ip6t_chainlabel name;
+ /* Revision of match (0 by default). */
+ u_int8_t revision;
+
const char *version;
/* Size of match data. */
ip6tables.c +3 -0
@@ -193,6 +193,8 @@const char *program_name;char *lib_dir; +int kernel_version; +/* Keeping track of external matches and targets: linked lists. */ struct ip6tables_match *ip6tables_matches =NULL ;struct ip6tables_target *ip6tables_targets =NULL ;
@@ -1047,10 +1049,51 @@return merge; } +static int compatible_revision(const char *name, u_int8_t revision, int
opt)
+{
+ struct ip6t_get_revision rev;
+ socklen_t s = sizeof(rev);
+ int max_rev, sockfd;
+
+ sockfd = socket(AF_INET6, SOCK_RAW, IPPROTO_RAW);
+ if (sockfd < 0) {
+ fprintf(stderr, "Could not open socket to kernel: %s\n",
+ strerror(errno));
+ exit(1);
+ }
+
+ strcpy(rev.name, name);
+ rev.revision = revision;
+
+ max_rev = getsockopt(sockfd, IPPROTO_IPV6, opt, &rev, &s);
+ if (max_rev < 0) {
+ /* Definitely don't support this? */
+ if (errno == EPROTONOSUPPORT) {
+ close(sockfd);
+ return 0;
+ } else if (errno == ENOPROTOOPT) {
+ close(sockfd);
+ /* Assume only revision 0 support (old kernel) */
+ return (revision == 0);
+ } else {
+ fprintf(stderr, "getsockopt failed strangely: %s\n",
+ strerror(errno));
+ exit(1);
+ }
+ }
+ close(sockfd);
+ return 1;
+}
+
+static int compatible_match_revision(const char *name, u_int8_t revision)
+{
+ return compatible_revision(name, revision,IP6T_SO_GET_REVISION_MATCH);
+}
+
void
register_match6(struct ip6tables_match *me)
{
- struct ip6tables_match **i;
+ struct ip6tables_match **i, *old;
if (strcmp(me->version, program_version) != 0) {
fprintf(stderr, "%s: match `%s' v%s (I'm v%s).\n",
@@ -1058,12 +1101,36 @@
exit(1);
}
- if (find_match(me->name, DURING_LOAD, NULL)) {
- fprintf(stderr, "%s: match `%s' already registered.\n",
+ /* Revision field stole a char from name. */
+ if (strlen(me->name) >= IP6T_FUNCTION_MAXNAMELEN-1) {
+ fprintf(stderr, "%s: target `%s' has invalid name\n",
program_name, me->name);
exit(1);
}
+ old = find_match(me->name, DURING_LOAD, NULL);
+ if (old) {
+ if (old->revision == me->revision) {
+ fprintf(stderr,
+ "%s: match `%s' already registered.\n",
+ program_name, me->name);
+ exit(1);
+ }
+
+ /* Now we have two (or more) options, check compatibility. */
+ if (compatible_match_revision(old->name, old->revision)
+ && old->revision > me->revision)
+ return;
+
+ /* Replace if compatible. */
+ if (!compatible_match_revision(me->name, me->revision))
+ return;
+
+ /* Delete old one. */
+ for (i = &ip6tables_matches; *i!=old; i = &(*i)->next);
+ *i = old->next;
+ }
+
if (me->size != IP6T_ALIGN(me->size)) {
fprintf(stderr, "%s: match `%s' has invalid size %u.\n",
program_name, me->name, (unsigned int)me->size);
@@ -1700,6 +1767,14 @@
*matches = NULL;
}
+static void set_revision(char *name, u_int8_t revision)
+{
+ /* Old kernel sources don't have ".revision" field,
+ but we stole a byte from name. */
+ name[IP6T_FUNCTION_MAXNAMELEN - 2] = '\0';
+ name[IP6T_FUNCTION_MAXNAMELEN - 1] = revision;
+}
+
int do_command6(int argc, char *argv[], char **table, ip6tc_handle_t
*handle)
{
struct ip6t_entry fw, *e = NULL;
@@ -1978,6 +2053,7 @@
m->m = fw_calloc(1, size);
m->m->u.match_size = size; strcpy(m->m->u.user.name, m->name);
+ set_revision(m->m->u.user.name, m->revision);
if (m->init != NULL)
m->init(m->m, &fw.nfcache);
opts = merge_options(opts, m->extra_opts, &m->option_offset);
@@ -2120,6 +2196,8 @@
m->m = fw_calloc(1, size); m->m->u.match_size = size; strcpy(m->m->u.user.name, m->name);
+ set_revision(m->m->u.user.name,
+ m->revision);
if (m->init != NULL)
m->init(m->m, &fw.nfcache);
Signature · 2 lines
Rémi Denis-Courmont http://www.remlab.net/
Hello, sorry for late replying.
From: Rémi Denis-Courmont <[email protected]>
Date: Tue, 3 Oct 2006 22:58:28 +0300
Quoted 9 lines
Le mardi 3 octobre 2006 17:30, vous avez écrit :
Quoted 6 lines
IPv4 multiport match (and policy match, too) would help you. It has the line
#include ../../include/netfilter_ipv4/ipt_multiport.hand definitions for old kernel are included in the header.
Ok. This time there is no trace of (xt|XT)_ at all:
??? Did you send intended patch ? It includes XT_MULTI_PORTS as folows.
Quoted 10 lines
diff -Nru
iptables-1.3.5.orig/extensions/libip6t_multiport.ciptables-1.3.5/extensions/libip6t_multiport.c
---iptables-1.3.5.orig/extensions/libip6t_multiport.c2005-02-19
21:19:17.000000000 +0200
+++iptables-1.3.5/extensions/libip6t_multiport.c2006-08-27
13:03:36.000000000 +0300(quoted diff) +0
-0@@ -20,6 +20,23 @@ " --dports ...\n" " match destination port(s)\n" " --ports port[,port,port]\n"
snip
Review
Quoted 3 lines
(quoted diff) +3
-0+ for (i=0; i<XT_MULTI_PORTS; i++) + multiinfo->pflags[i] = 0; +
And I noticed that your mailer breaks the patch. For example,
Review line 393
Quoted 10 lines
(quoted diff) +3
-0+ printf(" "); +} + /* Saves the union ip6t_matchinfo in parsable form to stdout. */ static void save(const struct ip6t_ip6 *ip, const struct
ip6t_entry_match*match)
{(quoted diff) +0
-0@@ -246,6 +392,41 @@ printf(" "); }
ip6t_entry_match *match) is moved to next line. That should be after "const struct ".
Regards,
-- Yasuyuki Kozakai
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 2 lines · Yasuyuki KOZAKAI
??? Did you send intended patch ? It includes
XT_MULTI_PORTSas folows.
Hmm, probably resent the old one accidentally then.
Sending the correct patch as attachment to avoid further breakages.
Signature · 2 lines
Rémi Denis-Courmont http://www.remlab.net/
include/linux/netfilter_ipv6/ip6t_multiport.h +30 -0
@@ -0,0 +1,30 @@ +#ifndef _IP6T_MULTIPORT_H +#define _IP6T_MULTIPORT_H + +enum ip6t_multiport_flags +{ +IP6T_MULTIPORT_SOURCE , +IP6T_MULTIPORT_DESTINATION , +IP6T_MULTIPORT_EITHER +}; + +#define IP6T_MULTI_PORTS 15 + +/* Must fit inside union xt_matchinfo: 16 bytes */ +struct ip6t_multiport +{ +u_int8_t flags;/* Type of comparison */ +u_int8_t count;/* Number of ports */ +u_int16_t ports[IP6T_MULTI_PORTS ];/* Ports */ +}; + +struct ip6t_multiport_v1 +{ +u_int8_t flags;/* Type of comparison */ +u_int8_t count;/* Number of ports */ +u_int16_t ports[IP6T_MULTI_PORTS ];/* Ports */ +u_int8_t pflags[IP6T_MULTI_PORTS ];/* Port flags */ +u_int8_t invert;/* Invert flag */ +}; + +#endif /*_IP6T_MULTIPORT_H*/
Modification de propriétés sur iptables/include/linux/netfilter_ipv6/ip6t_multiport.h
___________________________________________________________________
Nom : svn:eol-style
+ native
include/ip6tables.h +3 -0
@@ -33,6 +33,9 @@ip6t_chainlabel name; +/* Revision of match (0 by default). */ +u_int8_t revision; +const char *version;/* Size of match data. */
extensions/libip6t_multiport.c +200 -1
245 lines not on this page · raw message
ip6tables.c +81 -3
127 lines not on this page · raw message
Hello,
Quoted 7 lines · Yasuyuki KOZAKAI
Quoted 2 lines
??? Did you send intended patch ? It includes
XT_MULTI_PORTSas folows.Hmm, probably resent the old one accidentally then.
Sending the correct patch as attachment to avoid further breakages.
Thanks,
OK, I've update your patch (please see below comments in detail), and also tested with kernel 2.4.33.3 and 2.6 linus tree and ip6tables build with headers in each of them.
If no objection, I'll commit the attached patch next week.
I appreciate if you tries to build with 2.4 kernel for such changes from next time.
From: Rémi Denis-Courmont <[email protected]>
Date: Thu, 12 Oct 2006 17:29:35 +0300
include/ip6tables.h line 39
Quoted 12 lines
Index:
iptables/include/ip6tables.h
===================================================================include/ip6tables.h +3
-0@@ -33,6 +33,9 @@ip6t_chainlabel name; +/* Revision of match (0 by default). */ +u_int8_t revision; +const char *version;
The declaration for ip6t_get_revision is missing. That doesn't exist in 2.4 kernel.
ip6tables.c line 196
Quoted 9 lines
Index:
iptables/ip6tables.c
===================================================================ip6tables.c +1
-0@@ -193,6 +193,8 @@const char *program_name;char *lib_dir; +int kernel_version;
This isn't used anywhere.
Regards,
extensions/libip6t_multiport.c +200 -1
@@ -5,7 +5,8 @@#include <stdlib.h> #include <getopt.h> #include <ip6tables.h> -#include <linux/netfilter_ipv6/ip6t_multiport.h> +/* To ensure that iptables compiles with an old kernel */ +#include "../include/linux/netfilter_ipv6/ip6t_multiport.h" /* Function which prints out usage message. */ static void
@@ -20,6 +21,23 @@ help(void)" --dports ...\n" " match destination port(s)\n" " --ports port[,port,port]\n" +" match both source and destination port(s)\n" +" NOTE: this kernel does not support port ranges in multiport.\n" , +IPTABLES_VERSION); +} + +static void +help_v1 (void ) +{ +printf ( +"multiport v%s options:\n" +" --source-ports [!] port[,port:port,port...]\n" +" --sports ...\n" +" match source port(s)\n" +" --destination-ports [!] port[,port:port,port...]\n" +" --dports ...\n" +" match destination port(s)\n" +" --ports [!] port[,port:port,port]\n" " match both source and destination port(s)\n" ,IPTABLES_VERSION ); }
@@ -70,6 +88,46 @@ parse_multi_ports(const char *portstringreturn i; } +static void +parse_multi_ports_v1 (const char *portstring, +struct ip6t_multiport_v1 *multiinfo, +const char *proto) +{ +char *buffer, *cp, *next, *range; +unsigned int i; +u_int16_t m; + + buffer =strdup (portstring); +if (!buffer)exit_error (OTHER_PROBLEM ,"strdup failed" ); + +for (i=0 ; i<IP6T_MULTI_PORTS ; i++) + multiinfo->pflags[i] =0 ; + +for (cp=buffer, i=0 ; cp && i<IP6T_MULTI_PORTS ; cp=next, i++) { + next=strchr (cp,',' ); +if (next) *next++='\0' ; + range =strchr (cp,':' ); +if (range) { +if (i ==IP6T_MULTI_PORTS -1 ) +exit_error (PARAMETER_PROBLEM , +"too many ports specified" ); + *range++ ='\0' ; + } + multiinfo->ports[i] =parse_port (cp, proto); +if (range) { + multiinfo->pflags[i] =1 ; + multiinfo->ports[++i] =parse_port (range, proto); +if (multiinfo->ports[i-1 ] >= multiinfo->ports[i]) +exit_error (PARAMETER_PROBLEM , +"invalid portrange specified" ); + m <<=1 ; + } + } + multiinfo->count = i; +if (cp)exit_error (PARAMETER_PROBLEM ,"too many ports specified" ); +free (buffer); +} +/* Initialize the match. */ static void init (struct ip6t_entry_match *m,unsigned int *nfcache)
@@ -143,6 +201,52 @@ parse(int c, char **argv, int invert, unreturn 1 ; } +static int +parse_v1 (int c,char **argv,int invert,unsigned int *flags, +const struct ip6t_entry *entry, +unsigned int *nfcache, +struct ip6t_entry_match **match) +{ +const char *proto; +struct ip6t_multiport_v1 *multiinfo + = (struct ip6t_multiport_v1 *)(*match)->data; + +switch (c) { +case '1' : +check_inverse (argv[optind-1 ], &invert, &optind,0 ); + proto =check_proto (entry); +parse_multi_ports_v1 (argv[optind-1 ], multiinfo, proto); + multiinfo->flags =IP6T_MULTIPORT_SOURCE ; +break ; + +case '2' : +check_inverse (argv[optind-1 ], &invert, &optind,0 ); + proto =check_proto (entry); +parse_multi_ports_v1 (argv[optind-1 ], multiinfo, proto); + multiinfo->flags =IP6T_MULTIPORT_DESTINATION ; +break ; + +case '3' : +check_inverse (argv[optind-1 ], &invert, &optind,0 ); + proto =check_proto (entry); +parse_multi_ports_v1 (argv[optind-1 ], multiinfo, proto); + multiinfo->flags =IP6T_MULTIPORT_EITHER ; +break ; + +default : +return 0 ; + } + +if (invert) + multiinfo->invert =1 ; + +if (*flags) +exit_error (PARAMETER_PROBLEM , +"multiport can only have one option" ); + *flags =1 ; +return 1 ; +} +/* Final check; must specify something. */ static void final_check (unsigned int flags)
@@ -210,6 +314,49 @@ print(const struct ip6t_ip6 *ip,printf (" " ); } +static void +print_v1 (const struct ip6t_ip6 *ip, +const struct ip6t_entry_match *match, +int numeric) +{ +const struct ip6t_multiport_v1 *multiinfo + = (const struct ip6t_multiport_v1 *)match->data; +unsigned int i; + +printf ("multiport " ); + +switch (multiinfo->flags) { +case IP6T_MULTIPORT_SOURCE : +printf ("sports " ); +break ; + +case IP6T_MULTIPORT_DESTINATION : +printf ("dports " ); +break ; + +case IP6T_MULTIPORT_EITHER : +printf ("ports " ); +break ; + +default : +printf ("ERROR " ); +break ; + } + +if (multiinfo->invert) +printf ("! " ); + +for (i=0 ; i < multiinfo->count; i++) { +printf ("%s" , i ?"," :"" ); +print_port (multiinfo->ports[i], ip->proto, numeric); +if (multiinfo->pflags[i]) { +printf (":" ); +print_port (multiinfo->ports[++i], ip->proto, numeric); + } + } +printf (" " ); +} +/* Saves the union ip6t_matchinfo in parsable form to stdout. */ static void save (const struct ip6t_ip6 *ip,const struct ip6t_entry_match *match) {
@@ -238,6 +385,41 @@ static void save(const struct ip6t_ip6 *printf (" " ); } +static void save_v1 (const struct ip6t_ip6 *ip, +const struct ip6t_entry_match *match) +{ +const struct ip6t_multiport_v1 *multiinfo + = (const struct ip6t_multiport_v1 *)match->data; +unsigned int i; + +switch (multiinfo->flags) { +case IP6T_MULTIPORT_SOURCE : +printf ("--sports " ); +break ; + +case IP6T_MULTIPORT_DESTINATION : +printf ("--dports " ); +break ; + +case IP6T_MULTIPORT_EITHER : +printf ("--ports " ); +break ; + } + +if (multiinfo->invert) +printf ("! " ); + +for (i=0 ; i < multiinfo->count; i++) { +printf ("%s" , i ?"," :"" ); +print_port (multiinfo->ports[i], ip->proto,1 ); +if (multiinfo->pflags[i]) { +printf (":" ); +print_port (multiinfo->ports[++i], ip->proto,1 ); + } + } +printf (" " ); +} +static struct ip6tables_match multiport = { .name ="multiport" , .version =IPTABLES_VERSION ,
@@ -252,8 +434,25 @@ static struct ip6tables_match multiport .extra_opts = opts, }; +static struct ip6tables_match multiport_v1 = { + .next =NULL , + .name ="multiport" , + .revision =1 , + .version =IPTABLES_VERSION , + .size =IP6T_ALIGN (sizeof (struct ip6t_multiport_v1 )), + .userspacesize =IP6T_ALIGN (sizeof (struct ip6t_multiport_v1 )), + .help = &help_v1, + .init = &init, + .parse = &parse_v1, + .final_check = &final_check, + .print = &print_v1, + .save = &save_v1, + .extra_opts = opts +}; +void _init (void ) {register_match6 (&multiport); +register_match6 (&multiport_v1); }
include/ip6tables.h +15 -0
@@ -15,6 +15,18 @@#define IPPROTO_DCCP 33#endif +#ifndef IP6T_SO_GET_REVISION_MATCH /* Old kernel source. */ +#define IP6T_SO_GET_REVISION_MATCH (IP6T_BASE_CTL + 2) +#define IP6T_SO_GET_REVISION_TARGET (IP6T_BASE_CTL + 3) + +struct ip6t_get_revision +{ +char name[IP6T_FUNCTION_MAXNAMELEN -1 ]; + +u_int8_t revision; +}; +#endif /* IP6T_SO_GET_REVISION_MATCH Old kernel source */ +struct ip6tables_rule_match {struct ip6tables_rule_match *next;
@@ -33,6 +45,9 @@ struct ip6tables_matchip6t_chainlabel name; +/* Revision of match (0 by default). */ +u_int8_t revision; +const char *version;/* Size of match data. */
include/linux/netfilter_ipv6/ip6t_multiport.h new file +30 -0
@@ -0,0 +1,30 @@ +#ifndef _IP6T_MULTIPORT_H +#define _IP6T_MULTIPORT_H + +enum ip6t_multiport_flags +{ +IP6T_MULTIPORT_SOURCE , +IP6T_MULTIPORT_DESTINATION , +IP6T_MULTIPORT_EITHER +}; + +#define IP6T_MULTI_PORTS 15 + +/* Must fit inside union xt_matchinfo: 16 bytes */ +struct ip6t_multiport +{ +u_int8_t flags;/* Type of comparison */ +u_int8_t count;/* Number of ports */ +u_int16_t ports[IP6T_MULTI_PORTS ];/* Ports */ +}; + +struct ip6t_multiport_v1 +{ +u_int8_t flags;/* Type of comparison */ +u_int8_t count;/* Number of ports */ +u_int16_t ports[IP6T_MULTI_PORTS ];/* Ports */ +u_int8_t pflags[IP6T_MULTI_PORTS ];/* Port flags */ +u_int8_t invert;/* Invert flag */ +}; + +#endif /*_IP6T_MULTIPORT_H*/
ip6tables.c +79 -3
119 lines not on this page · raw message
Hi, Patrick,
I've found the following your mail and would I be better to commit this until next version of iptables ?
From: Patrick McHardy <[email protected]>
Date: Mon, 09 Oct 2006 18:02:14 +0200
Quoted 7 lines
We should consider moving away from using the kernel headers directly. Breaking compilation of old iptables versions is not too bad IMO, old binaries will still work and someone compiling old iptables with a new kernel can just as well just compile a new version.
Unfortunately 1.3.6 won't compile with 2.6.19, so we might have to put out a new version soon.
From: Yasuyuki KOZAKAI <[email protected]>
Date: Fri, 13 Oct 2006 09:50:44 +0900 (JST)
Quoted 56 lines
Hello,
Quoted 7 lines · Yasuyuki KOZAKAI
Quoted 2 lines
??? Did you send intended patch ? It includes
XT_MULTI_PORTSas folows.Hmm, probably resent the old one accidentally then.
Sending the correct patch as attachment to avoid further breakages.
Thanks,
OK, I've update your patch (please see below comments in detail), and also tested with kernel 2.4.33.3 and 2.6 linus tree and ip6tables build with headers in each of them.
If no objection, I'll commit the attached patch next week.
I appreciate if you tries to build with 2.4 kernel for such changes from next time.
From: Rémi Denis-Courmont <[email protected]>
Date: Thu, 12 Oct 2006 17:29:35 +0300include/ip6tables.h line 39
Quoted 12 lines
Index:
iptables/include/ip6tables.h
===================================================================include/ip6tables.h +3
-0@@ -33,6 +33,9 @@ip6t_chainlabel name; +/* Revision of match (0 by default). */ +u_int8_t revision; +const char *version;The declaration for
ip6t_get_revisionis missing. That doesn't exist in 2.4 kernel.ip6tables.c line 196
Quoted 9 lines
Index:
iptables/ip6tables.c
===================================================================ip6tables.c +1
-0@@ -193,6 +193,8 @@const char *program_name;char *lib_dir; +int kernel_version;This isn't used anywhere.
Regards,
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 4 lines · Yasuyuki KOZAKAI
Hi, Patrick,
I've found the following your mail and would I be better to commit this until next version of iptables ?
The patch looks fine, I guess we can add it since we still have a few weeks until we should release a new version.
From: Patrick McHardy <[email protected]>
Date: Fri, 20 Oct 2006 12:06:49 +0200
Quoted 8 lines
Quoted 4 lines · Yasuyuki KOZAKAI
Hi, Patrick,
I've found the following your mail and would I be better to commit this until next version of iptables ?
The patch looks fine, I guess we can add it since we still have a few weeks until we should release a new version.
OK, I've commited it. Thanks.
-- Yasuyuki Kozakai