Skip to content

Commit

Permalink
build: initial import
Browse files Browse the repository at this point in the history
Signed-off-by: Alon Bar-Lev <[email protected]>
  • Loading branch information
alonbl committed Nov 15, 2015
1 parent 65648da commit 3a877fa
Show file tree
Hide file tree
Showing 8 changed files with 587 additions and 92 deletions.
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.deps
.libs

*.o
*.in
*~

Makefile
aclocal.m4
autom4te.cache
compile
config.guess
config.h
config.log
config.status
config.sub
configure
depcomp
install-sh
libtool
ltmain.sh
missing
stamp-h1

iprange
iprange.spec
28 changes: 28 additions & 0 deletions COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FireHOL Copyright

Copyright (C) 2003-2015 Costa Tsaousis <[email protected]>
Copyright (C) 2012-2015 Phil Whineray <[email protected]>

Original iprange.c Copyright:

Copyright (C) 2003 Gabriel L. Somlo

comment by Costa Tsaousis:
An excellent work by Gabriel Somlo for loading and merging CIDRs.
I have built all the features this tool provides on top of the
original work of Gabriel.

License

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
34 changes: 34 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
iprange (1.0.0)

2015-11-12 Costa Tsaousis ([email protected])
- added logic to retry temporary DNS failures
2015-11-11 Costa Tsaousis ([email protected])
- added --diff to find the differences between ipsets
2015-11-05 Costa Tsaousis ([email protected])
- added threaded DNS resolution of hostnames
2015-11-05 Costa Tsaousis ([email protected])
- better error handling when parsing input files
- optimized printing using internal ip2str() implementation
- added DNS resolution of hostnames
2015-06-06 Costa Tsaousis ([email protected])
- added support for loading multiple sets
- added support for merging multiple files
- added support for comparing ipsets (all-to-all, one-to-all)
- added support for parsing IP ranges from the input file
(much like -s did for a single range)
- added support for parsing netmasks
- added support for min prefix generated
- added support for generated only specific prefixes
- added support for reducing the prefixes for iptables ipsets
- the output is now always optimized (reduced / merged)
- removed option -s (convert a single IP range to CIDR)
- added support for finding the common IPs in multiple files
- added timings
- added verbose output
2015-05-31 Costa Tsaousis ([email protected])
- added -C option to report count of unique IPs
- some optimizations to speed it up by 10% - 20%
2004-10-16 Paul Townsend (alpha alpha beta at purdue dot edu)
- more general input/output formatting
2003 Gabriel L. Somlo, the original author of iprange.c core
- found at http://www.cs.colostate.edu/~somlo/iprange.c
22 changes: 22 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Copyright (C) 2015 Alon Bar-Lev <[email protected]>
#
AUTOMAKE_OPTIONS=foreign dist-bzip2 1.10
ACLOCAL_AMFLAGS = -I m4

MAINTAINERCLEANFILES= \
config.log config.status \
$(srcdir)/Makefile.in \
$(srcdir)/config.h.in $(srcdir)/config.h.in~ $(srcdir)/configure \
$(srcdir)/install-sh $(srcdir)/ltmain.sh $(srcdir)/missing \
$(srcdir)/compile $(srcdir)/depcomp $(srcdir)/aclocal.m4 \
$(srcdir)/config.guess $(srcdir)/config.sub \
$(srcdir)/m4/ltsugar.m4 $(srcdir)/m4/libtool.m4 \
$(srcdir)/m4/ltversion.m4 $(srcdir)/m4/lt~obsolete.m4 \
$(srcdir)/m4/ltoptions.m4 \
$(srcdir)/pkcs11-helper.spec $(srcdir)/config-w32-vc.h

sbin_PROGRAMS = iprange
dist_noinst_DATA = iprange.spec

iprange_SOURCES = iprange.c
72 changes: 72 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#
# Copyright (C) 2015 Alon Bar-Lev <[email protected]>
#
AC_PREREQ(2.60)

define([VERSION_MAJOR], [1])
define([VERSION_MINOR], [0])
define([VERSION_FIX], [0])
define([VERSION_NUMBER], VERSION_MAJOR[.]VERSION_MINOR[.]VERSION_FIX)
define([VERSION_SUFFIX], [_master])

AC_INIT([iprange], VERSION_NUMBER[]VERSION_SUFFIX)
PACKAGE_RPM_VERSION="VERSION_NUMBER"
PACKAGE_RPM_RELEASE="0.0.$(echo VERSION_SUFFIX | sed 's/^_//')"
AC_SUBST([PACKAGE_RPM_VERSION])
AC_SUBST([PACKAGE_RPM_RELEASE])

AC_CONFIG_AUX_DIR([.])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([iprange.c])
AM_INIT_AUTOMAKE
AC_CANONICAL_HOST
AC_PROG_CC
AC_PROG_INSTALL
AC_ARG_ENABLE(
[pedantic],
[AS_HELP_STRING([--enable-pedantic], [enable pedantic compiler warnings])],
,
[enable_pedantic="no"]
)
AC_ARG_WITH(
[compare-with-common],
[AS_HELP_STRING([--without-compare-with-common], [if set, use MODE_COMMON to compare files this is 20 times faster than MODE COMBINE])],
,
[with_compare_with_common="yes"]
)
AC_ARG_WITH(
[system-ip2str],
[AS_HELP_STRING([--with-system-ip2str], [if set, use slower inet_ntoa])],
,
[with_system_ip2str="no"]
)

ACX_PTHREAD(, [AC_MSG_ERROR([Cannot initialize pthread environment])])
LIBS="${PTHREAD_LIBS} ${LIBS}"
CFLAGS="${CFLAGS} ${PTHREAD_CFLAGS}"
CC="${PTHREAD_CC}"

AC_TYPE_UINT32_T
AC_C_INLINE

test "${with_compare_with_common}" = "yes" && AC_DEFINE([COMPARE_WITH_COMMON], [1], [compare settings])
test "${with_system_ip2str}" = "yes" && AC_DEFINE([SYSTEM_IP2STR], [1], [ip2str settings])

if test "${GCC}" = "yes"; then
AC_DEFINE_UNQUOTED([likely(x)], [__builtin_expect(!!(x), 1)], [gcc branch optimization])
AC_DEFINE_UNQUOTED([unlikely(x)], [__builtin_expect(!!(x), 0)], [gcc branch optimization])
else
AC_DEFINE_UNQUOTED([likely(x)], [(x)], [gcc branch optimization])
AC_DEFINE_UNQUOTED([unlikely(x)], [(x)], [gcc branch optimization])
fi

if test "${enable_pedantic}" = "yes"; then
enable_strict="yes"
CFLAGS="${CFLAGS} -pedantic -Wall -Wextra -Wpointer-arith -Wsign-compare -Wno-unused-parameter -Wno-unused-function"
fi
AC_CONFIG_FILES([
Makefile
iprange.spec
])
AC_OUTPUT
102 changes: 10 additions & 92 deletions iprange.c
Original file line number Diff line number Diff line change
@@ -1,80 +1,16 @@
/* iprange
*
* FireHOL - A firewall for humans...
*
* FireHOL Copyright
*
* Copyright (C) 2003-2015 Costa Tsaousis <[email protected]>
* Copyright (C) 2012-2015 Phil Whineray <[email protected]>
*
* Original iprange.c Copyright:
*
* Copyright (C) 2003 Gabriel L. Somlo
*
* comment by Costa Tsaousis:
* An excellent work by Gabriel Somlo for loading and merging CIDRs.
* I have built all the features this tool provides on top of the
* original work of Gabriel.
*
* License
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* See the file COPYING for details.
*
* To compile:
* gcc -o iprange iprange.c -O2 -Wall -lpthread
*
* CHANGELOG:
* 2003 Gabriel L. Somlo, the original author of iprange.c core
* - found at http://www.cs.colostate.edu/~somlo/iprange.c
* 2004-10-16 Paul Townsend (alpha alpha beta at purdue dot edu)
* - more general input/output formatting
* 2015-05-31 Costa Tsaousis ([email protected])
* - added -C option to report count of unique IPs
* - some optimizations to speed it up by 10% - 20%
* 2015-06-06 Costa Tsaousis ([email protected])
* - added support for loading multiple sets
* - added support for merging multiple files
* - added support for comparing ipsets (all-to-all, one-to-all)
* - added support for parsing IP ranges from the input file
* (much like -s did for a single range)
* - added support for parsing netmasks
* - added support for min prefix generated
* - added support for generated only specific prefixes
* - added support for reducing the prefixes for iptables ipsets
* - the output is now always optimized (reduced / merged)
* - removed option -s (convert a single IP range to CIDR)
* - added support for finding the common IPs in multiple files
* - added timings
* - added verbose output
* 2015-11-05 Costa Tsaousis ([email protected])
* - better error handling when parsing input files
* - optimized printing using internal ip2str() implementation
* - added DNS resolution of hostnames
* 2015-11-05 Costa Tsaousis ([email protected])
* - added threaded DNS resolution of hostnames
* 2015-11-11 Costa Tsaousis ([email protected])
* - added --diff to find the differences between ipsets
* 2015-11-12 Costa Tsaousis ([email protected])
* - added logic to retry temporary DNS failures
*
/*
* Copyright (C) 2003-2015 Costa Tsaousis <[email protected]>
* Copyright (C) 2012-2015 Phil Whineray <[email protected]>
* Copyright (C) 2003 Gabriel L. Somlo
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#if defined(HAVE_INTTYPES_H)
#include <inttypes.h>
#elif defined(HAVE_STDINT_H)
#include <stdint.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -92,20 +28,6 @@
// normally the elements are IP, IP/MASK, HOSTNAME
#define MAX_INPUT_ELEMENT 255

#ifdef __GNUC__
// gcc branch optimization
// #warning "Using GCC branch optimizations"
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#else
#define likely(x) (x)
#define unlikely(x) (x)
#endif

// if set, use MODE_COMMON to compare files
// this is 20 times faster than MODE COMBINE
#define COMPARE_WITH_COMMON 1

#define BINARY_HEADER_V10 "iprange binary format v1.0\n"
uint32_t endianess = 0x1A2B3C4D;

Expand Down Expand Up @@ -2102,11 +2024,7 @@ void usage(const char *me) {
fprintf(stderr, "\n"
"iprange\n"
"manage IP ranges\n"
#ifdef VERSION
"version: " VERSION " ($Id: 8de62265ac795ec920e0c30e94763cb6ac2571cb $)\n"
#else
"version: $Id: 8de62265ac795ec920e0c30e94763cb6ac2571cb $\n"
#endif
"version: " VERSION "\n"
"\n"
"Original, Copyright (C) 2003 Gabriel L. Somlo\n"
"Adapted, Copyright (C) 2004 Paul Townsend\n"
Expand Down
32 changes: 32 additions & 0 deletions iprange.spec.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Summary: Manage ip ranges
Name: @PACKAGE_NAME@
Version: @PACKAGE_RPM_VERSION@
Release: @PACKAGE_RPM_RELEASE@%{?release_suffix}%{?dist}
License: GPLv2+
URL: http://firehol.org
Source: %{name}-@[email protected]

BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

%description
Manage ip ranges.

%prep
%setup -q -n %{name}-@PACKAGE_VERSION@

%build
%configure \
--docdir="%{_docdir}/%{name}-%{version}" \
%{?conf}
make %{?_smp_mflags}

%install
rm -rf "%{buildroot}"
make %{?_smp_mflags} install DESTDIR="%{buildroot}"

%files
%{_sbindir}/iprange

%changelog
* Sun Nov 15 2015 Alon Bar-Lev <[email protected]> - 1.0.0-1
- Initial add.
Loading

0 comments on commit 3a877fa

Please sign in to comment.