summaryrefslogtreecommitdiffstats
path: root/ipset_ipporthash.c
diff options
context:
space:
mode:
Diffstat (limited to 'ipset_ipporthash.c')
-rw-r--r--ipset_ipporthash.c63
1 files changed, 24 insertions, 39 deletions
diff --git a/ipset_ipporthash.c b/ipset_ipporthash.c
index c090744..1b92979 100644
--- a/ipset_ipporthash.c
+++ b/ipset_ipporthash.c
@@ -15,21 +15,12 @@
* 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 <linux/netfilter_ipv4/ip_set_ipporthash.h>
-#include <linux/netfilter_ipv4/ip_set_jhash.h>
#include "ipset.h"
@@ -44,8 +35,7 @@
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");
@@ -59,8 +49,7 @@ create_init(void *data)
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");
@@ -151,8 +140,7 @@ create_parse(int c, char *argv[], void *data, unsigned *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",
@@ -204,21 +192,25 @@ static const struct option create_opts[] = {
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;
+ struct ip_set_req_ipporthash *mydata = data;
char *saved = ipset_strdup(optarg);
char *ptr, *tmp = saved;
DP("ipporthash: %p %p", optarg, data);
- ptr = strsep(&tmp, ":%");
+ if ((ptr = strchr(tmp, ':')) || (ptr = strchr(tmp, '%')))
+ fprintf(stderr, "Warning: please replace old separator character '%s.1' with ','.\n"
+ "Next release won't support it.\n",
+ ptr);
+
+ 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");
+ "IP address and port must be specified: ip,port");
free(saved);
return 1;
};
@@ -230,10 +222,8 @@ adt_parser(unsigned cmd, const char *optarg, 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;
@@ -246,8 +236,7 @@ initheader(struct set *set, const void *data)
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));
@@ -259,8 +248,7 @@ printheader(struct set *set, unsigned 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;
@@ -270,7 +258,7 @@ printips(struct set *set, void *data, size_t len, unsigned options)
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));
}
@@ -281,8 +269,7 @@ printips(struct set *set, void *data, size_t len, unsigned 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,
@@ -297,8 +284,7 @@ saveheader(struct set *set, unsigned 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;
@@ -308,7 +294,7 @@ saveips(struct set *set, void *data, size_t len, unsigned options)
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));
}
@@ -321,13 +307,12 @@ static char buffer[22];
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;
@@ -340,9 +325,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 = {