mirror of
git://git.code.sf.net/p/xtables-addons/xtables-addons
synced 2025-09-20 11:34:57 +02:00
ipset: upgrade to ipset 2.4.3
This commit is contained in:
@@ -15,24 +15,14 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <asm/types.h>
|
||||
|
||||
#include "ip_set_ipporthash.h"
|
||||
#include "ip_set_jhash.h"
|
||||
#include <limits.h> /* UINT_MAX */
|
||||
#include <stdio.h> /* *printf */
|
||||
#include <string.h> /* mem*, str* */
|
||||
|
||||
#include "ipset.h"
|
||||
|
||||
#include "ip_set_ipporthash.h"
|
||||
|
||||
#define OPT_CREATE_HASHSIZE 0x01U
|
||||
#define OPT_CREATE_PROBES 0x02U
|
||||
#define OPT_CREATE_RESIZE 0x04U
|
||||
@@ -41,10 +31,10 @@
|
||||
#define OPT_CREATE_TO 0x20U
|
||||
|
||||
/* Initialize the create. */
|
||||
static void create_init(void *data)
|
||||
static void
|
||||
create_init(void *data)
|
||||
{
|
||||
struct ip_set_req_ipporthash_create *mydata =
|
||||
(struct ip_set_req_ipporthash_create *) data;
|
||||
struct ip_set_req_ipporthash_create *mydata = data;
|
||||
|
||||
DP("create INIT");
|
||||
|
||||
@@ -55,10 +45,10 @@ static void create_init(void *data)
|
||||
}
|
||||
|
||||
/* Function which parses command options; returns true if it ate an option */
|
||||
static int create_parse(int c, char *argv[], void *data, unsigned int *flags)
|
||||
static int
|
||||
create_parse(int c, char *argv[], void *data, unsigned *flags)
|
||||
{
|
||||
struct ip_set_req_ipporthash_create *mydata =
|
||||
(struct ip_set_req_ipporthash_create *) data;
|
||||
struct ip_set_req_ipporthash_create *mydata = data;
|
||||
ip_set_ip_t value;
|
||||
|
||||
DP("create_parse");
|
||||
@@ -146,10 +136,10 @@ static int create_parse(int c, char *argv[], void *data, unsigned int *flags)
|
||||
}
|
||||
|
||||
/* Final check; exit if not ok. */
|
||||
static void create_final(void *data, unsigned int flags)
|
||||
static void
|
||||
create_final(void *data, unsigned int flags)
|
||||
{
|
||||
struct ip_set_req_ipporthash_create *mydata =
|
||||
(struct ip_set_req_ipporthash_create *) data;
|
||||
struct ip_set_req_ipporthash_create *mydata = data;
|
||||
|
||||
#ifdef IPSET_DEBUG
|
||||
DP("hashsize %u probes %u resize %u",
|
||||
@@ -188,34 +178,38 @@ static void create_final(void *data, unsigned int flags)
|
||||
|
||||
/* Create commandline options */
|
||||
static const struct option create_opts[] = {
|
||||
{"hashsize", 1, 0, '1'},
|
||||
{"probes", 1, 0, '2'},
|
||||
{"resize", 1, 0, '3'},
|
||||
{"from", 1, 0, '4'},
|
||||
{"to", 1, 0, '5'},
|
||||
{"network", 1, 0, '6'},
|
||||
{.name = "hashsize", .has_arg = required_argument, .val = '1'},
|
||||
{.name = "probes", .has_arg = required_argument, .val = '2'},
|
||||
{.name = "resize", .has_arg = required_argument, .val = '3'},
|
||||
{.name = "from", .has_arg = required_argument, .val = '4'},
|
||||
{.name = "to", .has_arg = required_argument, .val = '5'},
|
||||
{.name = "network", .has_arg = required_argument, .val = '6'},
|
||||
{NULL},
|
||||
};
|
||||
|
||||
/* Add, del, test parser */
|
||||
static ip_set_ip_t adt_parser(unsigned int cmd, const char *arg, void *data)
|
||||
static ip_set_ip_t
|
||||
adt_parser(unsigned cmd, const char *optarg, void *data)
|
||||
{
|
||||
struct ip_set_req_ipporthash *mydata =
|
||||
(struct ip_set_req_ipporthash *) data;
|
||||
char *saved = ipset_strdup(arg);
|
||||
struct ip_set_req_ipporthash *mydata = data;
|
||||
char *saved = ipset_strdup(optarg);
|
||||
char *ptr, *tmp = saved;
|
||||
|
||||
DP("ipporthash: %p %p", arg, data);
|
||||
DP("ipporthash: %p %p", optarg, data);
|
||||
|
||||
ptr = strsep(&tmp, ":%");
|
||||
if (((ptr = strchr(tmp, ':')) || (ptr = strchr(tmp, '%'))) && ++warn_once == 1)
|
||||
fprintf(stderr, "Warning: please use ',' separator token between ip,port.\n"
|
||||
"Next release won't support old separator tokens.\n");
|
||||
|
||||
ptr = strsep(&tmp, ":%,");
|
||||
parse_ip(ptr, &mydata->ip);
|
||||
|
||||
if (tmp)
|
||||
parse_port(tmp, &mydata->port);
|
||||
else
|
||||
exit_error(PARAMETER_PROBLEM,
|
||||
"IP address and port must be specified: ip%%port");
|
||||
free(saved);
|
||||
"IP address and port must be specified: ip,port");
|
||||
ipset_free(saved);
|
||||
return 1;
|
||||
};
|
||||
|
||||
@@ -223,12 +217,11 @@ static ip_set_ip_t adt_parser(unsigned int cmd, const char *arg, void *data)
|
||||
* Print and save
|
||||
*/
|
||||
|
||||
static void initheader(struct set *set, const void *data)
|
||||
static void
|
||||
initheader(struct set *set, const void *data)
|
||||
{
|
||||
struct ip_set_req_ipporthash_create *header =
|
||||
(struct ip_set_req_ipporthash_create *) data;
|
||||
struct ip_set_ipporthash *map =
|
||||
(struct ip_set_ipporthash *) set->settype->header;
|
||||
const struct ip_set_req_ipporthash_create *header = data;
|
||||
struct ip_set_ipporthash *map = set->settype->header;
|
||||
|
||||
memset(map, 0, sizeof(struct ip_set_ipporthash));
|
||||
map->hashsize = header->hashsize;
|
||||
@@ -238,10 +231,10 @@ static void initheader(struct set *set, const void *data)
|
||||
map->last_ip = header->to;
|
||||
}
|
||||
|
||||
static void printheader(struct set *set, unsigned int options)
|
||||
static void
|
||||
printheader(struct set *set, unsigned options)
|
||||
{
|
||||
struct ip_set_ipporthash *mysetdata =
|
||||
(struct ip_set_ipporthash *) set->settype->header;
|
||||
struct ip_set_ipporthash *mysetdata = set->settype->header;
|
||||
|
||||
printf(" from: %s", ip_tostring(mysetdata->first_ip, options));
|
||||
printf(" to: %s", ip_tostring(mysetdata->last_ip, options));
|
||||
@@ -250,11 +243,10 @@ static void printheader(struct set *set, unsigned int options)
|
||||
printf(" resize: %u\n", mysetdata->resize);
|
||||
}
|
||||
|
||||
static void printips(struct set *set, void *data, size_t len,
|
||||
unsigned int options)
|
||||
static void
|
||||
printips(struct set *set, void *data, size_t len, unsigned options)
|
||||
{
|
||||
struct ip_set_ipporthash *mysetdata =
|
||||
(struct ip_set_ipporthash *) set->settype->header;
|
||||
struct ip_set_ipporthash *mysetdata = set->settype->header;
|
||||
size_t offset = 0;
|
||||
ip_set_ip_t *ipptr, ip;
|
||||
uint16_t port;
|
||||
@@ -264,7 +256,7 @@ static void printips(struct set *set, void *data, size_t len,
|
||||
if (*ipptr) {
|
||||
ip = (*ipptr>>16) + mysetdata->first_ip;
|
||||
port = (uint16_t) *ipptr;
|
||||
printf("%s:%s\n",
|
||||
printf("%s,%s\n",
|
||||
ip_tostring(ip, options),
|
||||
port_tostring(port, options));
|
||||
}
|
||||
@@ -272,10 +264,10 @@ static void printips(struct set *set, void *data, size_t len,
|
||||
}
|
||||
}
|
||||
|
||||
static void saveheader(struct set *set, unsigned int options)
|
||||
static void
|
||||
saveheader(struct set *set, unsigned options)
|
||||
{
|
||||
struct ip_set_ipporthash *mysetdata =
|
||||
(struct ip_set_ipporthash *) set->settype->header;
|
||||
struct ip_set_ipporthash *mysetdata = set->settype->header;
|
||||
|
||||
printf("-N %s %s --from %s",
|
||||
set->name, set->settype->typename,
|
||||
@@ -287,11 +279,10 @@ static void saveheader(struct set *set, unsigned int options)
|
||||
}
|
||||
|
||||
/* Print save for an IP */
|
||||
static void saveips(struct set *set, void *data, size_t len,
|
||||
unsigned int options)
|
||||
static void
|
||||
saveips(struct set *set, void *data, size_t len, unsigned options)
|
||||
{
|
||||
struct ip_set_ipporthash *mysetdata =
|
||||
(struct ip_set_ipporthash *) set->settype->header;
|
||||
struct ip_set_ipporthash *mysetdata = set->settype->header;
|
||||
size_t offset = 0;
|
||||
ip_set_ip_t *ipptr, ip;
|
||||
uint16_t port;
|
||||
@@ -301,7 +292,7 @@ static void saveips(struct set *set, void *data, size_t len,
|
||||
if (*ipptr) {
|
||||
ip = (*ipptr>>16) + mysetdata->first_ip;
|
||||
port = (uint16_t) *ipptr;
|
||||
printf("-A %s %s:%s\n", set->name,
|
||||
printf("-A %s %s,%s\n", set->name,
|
||||
ip_tostring(ip, options),
|
||||
port_tostring(port, options));
|
||||
}
|
||||
@@ -311,15 +302,15 @@ static void saveips(struct set *set, void *data, size_t len,
|
||||
|
||||
static char buffer[22];
|
||||
|
||||
static char * unpack_ipport_tostring(struct set *set, ip_set_ip_t bip, unsigned options)
|
||||
static char *
|
||||
unpack_ipport_tostring(struct set *set, ip_set_ip_t bip, unsigned options)
|
||||
{
|
||||
struct ip_set_ipporthash *mysetdata =
|
||||
(struct ip_set_ipporthash *) set->settype->header;
|
||||
struct ip_set_ipporthash *mysetdata = set->settype->header;
|
||||
ip_set_ip_t ip, port;
|
||||
|
||||
ip = (bip>>16) + mysetdata->first_ip;
|
||||
port = (uint16_t) bip;
|
||||
sprintf(buffer, "%s:%s",
|
||||
sprintf(buffer, "%s,%s",
|
||||
ip_tostring(ip, options), port_tostring(port, options));
|
||||
|
||||
return buffer;
|
||||
@@ -332,9 +323,9 @@ static void usage(void)
|
||||
" [--hashsize hashsize] [--probes probes ] [--resize resize]\n"
|
||||
"-N set ipporthash --network IP/mask\n"
|
||||
" [--hashsize hashsize] [--probes probes ] [--resize resize]\n"
|
||||
"-A set IP:port\n"
|
||||
"-D set IP:port\n"
|
||||
"-T set IP:port\n");
|
||||
"-A set IP,port\n"
|
||||
"-D set IP,port\n"
|
||||
"-T set IP,port\n");
|
||||
}
|
||||
|
||||
static struct settype settype_ipporthash = {
|
||||
|
Reference in New Issue
Block a user