summaryrefslogtreecommitdiffstats
path: root/ipset_ipporthash.c
diff options
context:
space:
mode:
author/C=EU/ST=EU/CN=Jozsef Kadlecsik/emailAddress=kadlec@blackhole.kfki.hu </C=EU/ST=EU/CN=Jozsef Kadlecsik/emailAddress=kadlec@blackhole.kfki.hu>2008-10-20 10:00:26 +0000
committer/C=EU/ST=EU/CN=Jozsef Kadlecsik/emailAddress=kadlec@blackhole.kfki.hu </C=EU/ST=EU/CN=Jozsef Kadlecsik/emailAddress=kadlec@blackhole.kfki.hu>2008-10-20 10:00:26 +0000
commita96e4fca10506462df4ee4035f0f86f09bd9dc34 (patch)
tree103bed0a7ae3608675f371d2ac91f3fa7f3a58cc /ipset_ipporthash.c
parentbc2ddd2d8da1252e78a1f25bd91c1e3cd8016ead (diff)
ipset 2.4 release
userspace changes: - Added KBUILD_OUTPUT support (Sven Wegener) - Fix memory leak in ipset_iptreemap (Sven Wegener) - Fix multiple compiler warnings (Sven Wegener) - ipportiphash, ipportnethash and setlist types added - binding marked as deprecated functionality - element separator token changed to ',' in anticipating IPv6 addresses, old separator tokens are still supported - unnecessary includes removed - ipset does not try to resolve IP addresses when listing the content of sets (default changed) - manpage updated - ChangeLog forked for kernel part kernel part changes: - ipportiphash, ipportnethash and setlist types added - set type modules reworked to avoid code duplication as much as possible, code unification macros - expand_macros Makefile target added to help debugging code unification macros - ip_set_addip_kernel and ip_set_delip_kernel changed from void to int, __ip_set_get_byname and __ip_set_put_byid added for the sake of setlist type - unnecessary includes removed - compatibility fix for kernels >= 2.6.27: semaphore.h was moved from asm/ to linux/ (James King) - ChangeLog forked for kernel part
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 = {