3 Commits
v6 ... v7

Author SHA1 Message Date
Auke Kok a2a6d8e9ac v7. 2018-01-10 10:29:53 -08:00
Auke Kok c5569176d2 Allow whitelist patterns.
This allows for some simple form of netmask type patterning
which will work for /8, /16 and /24 subnets to be whitelisted
for ipv4, and for any multiple of /32 subnets for ipv6.
2018-01-08 16:06:26 -08:00
Auke Kok bf81c259b0 Add 'nocreate' option to bypass all rule/set creation.
This may help in situations where external tools are used to maintain
iptables or ipset setups and we should not disturb them by creating
rules.
2018-01-05 12:57:45 -08:00
4 changed files with 75 additions and 15 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.64])
AC_INIT([tallow], [6], [auke-jan.h.kok@intel.com])
AC_INIT([tallow], [7], [auke-jan.h.kok@intel.com])
AM_INIT_AUTOMAKE([])
AC_CONFIG_FILES([Makefile])
+29 -9
View File
@@ -40,7 +40,13 @@ struct tallow_struct {
static struct tallow_struct *head;
static struct tallow_struct *whitelist;
struct whitelist_struct {
char *ip;
size_t len;
struct whitelist_struct *next;
};
static struct whitelist_struct *whitelist;
#define FILTER_STRING "SYSLOG_IDENTIFIER=sshd"
struct pattern_struct {
@@ -68,6 +74,7 @@ static struct pattern_struct patterns[PATTERN_COUNT] = {
static char ipt_path[PATH_MAX];
static int expires = 3600;
static int has_ipv6 = 0;
static bool nocreate = false;
static sd_journal *j;
static int ext(char *fmt, ...)
@@ -105,6 +112,9 @@ static void setup(void)
return;
done = true;
if (nocreate)
return;
/* init ipset and iptables */
/* delete iptables ref to set before the ipset! */
ext_ignore("%s/iptables -t filter -D INPUT -m set --match-set tallow src -j DROP 2> /dev/null", ipt_path);
@@ -166,21 +176,24 @@ static void block(struct tallow_struct *s, int instant_block)
static void whitelist_add(char *ip)
{
struct tallow_struct *w = whitelist;
struct tallow_struct *n;
struct whitelist_struct *w = whitelist;
struct whitelist_struct *n;
while (w && w->next)
w = w->next;
n = calloc(1, sizeof(struct tallow_struct));
n = calloc(1, sizeof(struct whitelist_struct));
if (!n) {
fprintf(stderr, "Out of memory.\n");
exit(EXIT_FAILURE);
}
n->ip = strdup(ip);
n->next = NULL;
n->blocked = false;
size_t l = strlen(ip);
if ((ip[l-1] == '.') || (ip[l-1] == ':'))
n->len = l;
else
n->len = -1;
if (!whitelist)
whitelist = n;
@@ -192,7 +205,7 @@ static void find(const char *ip, float weight, int instant_block)
{
struct tallow_struct *s = head;
struct tallow_struct *n;
struct tallow_struct *w = whitelist;
struct whitelist_struct *w = whitelist;
if (!ip)
return;
@@ -207,8 +220,13 @@ static void find(const char *ip, float weight, int instant_block)
/* whitelist */
while (w) {
if (!strcmp(w->ip, ip))
return;
if (w->len > 0) {
if (!strncmp(w->ip, ip, w->len))
return;
} else {
if (!strcmp(w->ip, ip))
return;
}
w = w->next;
}
@@ -384,6 +402,8 @@ int main(void)
whitelist_add(val);
if (!strcmp(key, "ipv6"))
has_ipv6 = atoi(val);
if (!strcmp(key, "nocreate"))
nocreate = (atoi(val) == 1);
}
fclose(f);
}
+18 -1
View File
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "TALLOW" "5" "December 2017" "" ""
.TH "TALLOW" "5" "January 2018" "" ""
.
.SH "NAME"
\fBtallow\fR
@@ -30,6 +30,23 @@ This file is read on startup by the tallow(1) daemon, and can be used to provide
.P
\fBipv6\fR=\fB<0|1>\fR Enable of disable ipv6 (ip6tables) support\. Ipv6 is disabled automatically on systems that do not appear to have ipv6 support and enabled when ipv6 is present\. Use this option to explicitly disable ipv6 support if your system does not have ipv6 or is missing ip6tables\. Even with ipv6 disabled, tallow will track and log ipv6 addresses\.
.
.P
\fBnocreate\fR=\fB<0|1>\fR Disable the creation of iptables rules and ipset sets\. By default, tallow will create new iptables(1) and ip6tables(1) rules when needed automatically\. If set to \fB1\fR, \fBtallow(1)\fR will not create any new iptables rules or ipset sets to work\. You should create them manually before tallow starts up and remove them afterwards\. To create them manually, you can use the following commands:
.
.IP "" 4
.
.nf
iptables \-t filter \-I INPUT \-m set \-\-match\-set tallow src \-j DROP
ipset create tallow hash:ip family inet timeout 3600
ip6tables \-t filter \-I INPUT \-m set \-\-match\-set tallow6 src \-j DROP
ipset create tallow6 hash:ip family inet6 timeout 3600
.
.fi
.
.IP "" 0
.
.SH "SEE ALSO"
tallow(1)
.
+27 -4
View File
@@ -30,10 +30,17 @@ longer than this period. If IP addresses are seen, but not
blocked within this period, they are also removed from the
watch list. Defaults to 3600s.
`whitelist`=`<ipv4 address>`
Specify an IP address that should never be blocked. Multiple IP
addresses can be included by repeating the `whitelist`
option several times. By default, only 127.0.0.1 is whitelisted.
`whitelist`=`<ip address|pattern>`
Specify an IP address or `pattern` that should never be
blocked. Multiple IP addresses can be included by repeating the
`whitelist` option several times. By default, only 127.0.0.1 is
whitelisted.
If the last character of the listed ip adress is a `.` or a `:`, then
the matching is only performed on the leftmost characters of an IP
address against the whitelist entry. For instance, if you whitelist
`10.` then all IP addresses in the `10/8` subnet mask will match this
whitelist entry and never be blocked.
`ipv6`=`<0|1>`
Enable of disable ipv6 (ip6tables) support. Ipv6 is disabled
@@ -43,6 +50,22 @@ disable ipv6 support if your system does not have ipv6 or is
missing ip6tables. Even with ipv6 disabled, tallow will track
and log ipv6 addresses.
`nocreate`=`<0|1>`
Disable the creation of iptables rules and ipset sets. By default,
tallow will create new iptables(1) and ip6tables(1) rules when needed
automatically. If set to `1`, `tallow(1)` will not create any new
iptables rules or ipset sets to work. You should create them manually
before tallow starts up and remove them afterwards. To create them
manually, you can use the following commands:
```
iptables -t filter -I INPUT -m set --match-set tallow src -j DROP
ipset create tallow hash:ip family inet timeout 3600
ip6tables -t filter -I INPUT -m set --match-set tallow6 src -j DROP
ipset create tallow6 hash:ip family inet6 timeout 3600
```
## SEE ALSO
tallow(1)