Module Name: src
Committed By: christos
Date: Tue Jun 2 14:02:10 UTC 2015
Modified Files:
src/external/bsd/blacklist/bin: blacklistctl.c conf.c run.c state.c
support.c support.h
Log Message:
Add more debugging, simplify.
Use symbolic constants: -2=FEQUALS, -1=FSTAR
To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/external/bsd/blacklist/bin/blacklistctl.c
cvs rdiff -u -r1.20 -r1.21 src/external/bsd/blacklist/bin/conf.c
cvs rdiff -u -r1.12 -r1.13 src/external/bsd/blacklist/bin/run.c
cvs rdiff -u -r1.16 -r1.17 src/external/bsd/blacklist/bin/state.c
cvs rdiff -u -r1.6 -r1.7 src/external/bsd/blacklist/bin/support.c
cvs rdiff -u -r1.5 -r1.6 src/external/bsd/blacklist/bin/support.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/external/bsd/blacklist/bin/blacklistctl.c
diff -u src/external/bsd/blacklist/bin/blacklistctl.c:1.17 src/external/bsd/blacklist/bin/blacklistctl.c:1.18
--- src/external/bsd/blacklist/bin/blacklistctl.c:1.17 Mon Feb 2 17:01:55 2015
+++ src/external/bsd/blacklist/bin/blacklistctl.c Tue Jun 2 10:02:10 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: blacklistctl.c,v 1.17 2015/02/02 22:01:55 christos Exp $ */
+/* $NetBSD: blacklistctl.c,v 1.18 2015/06/02 14:02:10 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: blacklistctl.c,v 1.17 2015/02/02 22:01:55 christos Exp $");
+__RCSID("$NetBSD: blacklistctl.c,v 1.18 2015/06/02 14:02:10 christos Exp $");
#include <stdio.h>
#include <time.h>
@@ -85,7 +85,7 @@ main(int argc, char *argv[])
argc--;
argv++;
- while ((o = getopt(argc, argv, "abdrw")) != -1)
+ while ((o = getopt(argc, argv, "abD:drw")) != -1)
switch (o) {
case 'a':
all = 1;
@@ -93,6 +93,9 @@ main(int argc, char *argv[])
break;
case 'b':
blocked = 1;
+ case 'D':
+ dbname = optarg;
+ break;
break;
case 'd':
debug++;
Index: src/external/bsd/blacklist/bin/conf.c
diff -u src/external/bsd/blacklist/bin/conf.c:1.20 src/external/bsd/blacklist/bin/conf.c:1.21
--- src/external/bsd/blacklist/bin/conf.c:1.20 Sat May 30 18:39:14 2015
+++ src/external/bsd/blacklist/bin/conf.c Tue Jun 2 10:02:10 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: conf.c,v 1.20 2015/05/30 22:39:14 christos Exp $ */
+/* $NetBSD: conf.c,v 1.21 2015/06/02 14:02:10 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: conf.c,v 1.20 2015/05/30 22:39:14 christos Exp $");
+__RCSID("$NetBSD: conf.c,v 1.21 2015/06/02 14:02:10 christos Exp $");
#include <stdio.h>
#include <string.h>
@@ -56,6 +56,7 @@ __RCSID("$NetBSD: conf.c,v 1.20 2015/05/
#include "bl.h"
#include "internal.h"
+#include "support.h"
#include "conf.h"
@@ -71,6 +72,9 @@ struct sockaddr_if {
static int conf_is_interface(const char *);
+#define FSTAR -1
+#define FEQUAL -2
+
static void
advance(char **p)
{
@@ -91,13 +95,13 @@ getnum(const char *f, size_t l, bool loc
int *r = rp;
if (strcmp(p, "*") == 0) {
- *r = -1;
+ *r = FSTAR;
return 0;
}
if (strcmp(p, "=") == 0) {
if (local)
goto out;
- *r = -2;
+ *r = FEQUAL;
return 0;
}
@@ -134,13 +138,13 @@ getsecs(const char *f, size_t l, bool lo
tot = 0;
if (strcmp(p, "*") == 0) {
- c->c_duration = -1;
+ c->c_duration = FSTAR;
return 0;
}
if (strcmp(p, "=") == 0) {
if (local)
goto out;
- c->c_duration = -2;
+ c->c_duration = FEQUAL;
return 0;
}
again:
@@ -204,39 +208,22 @@ getport(const char *f, size_t l, bool lo
}
static int
-getmask(const char *f, size_t l, bool local __unused, const char **p, int def)
+getmask(const char *f, size_t l, bool local, const char **p, int *mask)
{
char *d;
- int e;
- intmax_t im;
const char *s = *p;
if ((d = strchr(s, ':')) != NULL) {
*d++ = '\0';
*p = d;
}
- if ((d = strchr(s, '/')) == NULL)
- return def;
-
- *d++ = '\0';
- if (strcmp(d, "=") == 0) {
- if (local)
- goto out;
- return -2;
+ if ((d = strchr(s, '/')) == NULL) {
+ *mask = FSTAR;
+ return 0;
}
- if (strcmp(d, "*") == 0)
- return def;
-
- im = strtoi(d, NULL, 0, 0, def, &e);
- if (e == 0)
- return (int)im;
- (*lfun)(LOG_ERR, "%s: %s, %zu: Bad mask [%s]", __func__, f, l, d);
- return -1;
-out:
- (*lfun)(LOG_ERR, "%s: %s, %zu: `=' name not allowed in local"
- " config", __func__, f, l);
- return -1;
+ *d++ = '\0';
+ return getnum(f, l, local, mask, "mask", d);
}
static int
@@ -247,8 +234,8 @@ gethostport(const char *f, size_t l, boo
const char *pstr;
if (strcmp(p, "*") == 0) {
- c->c_port = -1;
- c->c_lmask = -1;
+ c->c_port = FSTAR;
+ c->c_lmask = FSTAR;
return 0;
}
@@ -259,12 +246,9 @@ gethostport(const char *f, size_t l, boo
} else
pstr = p;
- if ((c->c_lmask = getmask(f, l, local, &pstr, 256)) == -1)
+ if (getmask(f, l, local, &pstr, &c->c_lmask) == -1)
goto out;
- if (c->c_lmask == 256)
- c->c_lmask = -1;
-
if (d) {
struct sockaddr_in6 *sin6 = (void *)&c->c_ss;
if (debug)
@@ -290,7 +274,7 @@ gethostport(const char *f, size_t l, boo
if (debug)
(*lfun)(LOG_DEBUG, "%s: interface %s",
__func__, p);
- if (c->c_lmask != -1)
+ if (c->c_lmask != FSTAR)
goto out1;
sif->sif_family = AF_MAX;
strlcpy(sif->sif_name, p,
@@ -311,12 +295,10 @@ gethostport(const char *f, size_t l, boo
}
}
- if (strcmp(pstr, "*") == 0)
- c->c_port = -1;
- else if (getport(f, l, local, &c->c_port, pstr) == -1)
+ if (getport(f, l, local, &c->c_port, pstr) == -1)
return -1;
- if (port && c->c_port != -1)
+ if (port && c->c_port != FSTAR && c->c_port != FEQUAL)
*port = htons((in_port_t)c->c_port);
return 0;
out:
@@ -373,10 +355,8 @@ static int
getname(const char *f, size_t l, bool local, struct conf *c,
const char *p)
{
- if ((c->c_rmask = getmask(f, l, local, &p, 256)) == -1)
+ if (getmask(f, l, local, &p, &c->c_rmask) == -1)
return -1;
- if (c->c_rmask == 256)
- c->c_rmask = local ? -1 : -2;
if (strcmp(p, "*") == 0) {
strlcpy(c->c_name, rulename, CONFNAMESZ);
@@ -475,12 +455,15 @@ conf_amask_eq(const void *v1, const void
const uint32_t *a1 = v1;
const uint32_t *a2 = v2;
uint32_t m;
+ int omask = mask;
len >>= 2;
switch (mask) {
- case -1:
- return memcmp(v1, v2, len) == 0;
- case -2:
+ case FSTAR:
+ if (memcmp(v1, v2, len) == 0)
+ return 1;
+ goto out;
+ case FEQUAL:
(*lfun)(LOG_CRIT, "%s: Internal error: bad mask %d", __func__,
mask);
@@ -499,9 +482,18 @@ conf_amask_eq(const void *v1, const void
} else
return 1;
if ((a1[i] & m) != (a2[i] & m))
- return 0;
+ goto out;
}
return 1;
+out:
+ if (debug > 1) {
+ char b1[256], b2[256];
+ hexdump(b1, sizeof(b1), "a1", v1, len);
+ hexdump(b2, sizeof(b2), "a1", v2, len);
+ (*lfun)(LOG_DEBUG, "%s: %s != %s [0x%x]", __func__,
+ b1, b2, omask);
+ }
+ return 0;
}
/*
@@ -514,9 +506,9 @@ conf_apply_mask(void *v, size_t len, int
uint32_t m;
switch (mask) {
- case -1:
+ case FSTAR:
return;
- case -2:
+ case FEQUAL:
(*lfun)(LOG_CRIT, "%s: Internal error: bad mask %d", __func__,
mask);
abort();
@@ -580,7 +572,7 @@ conf_addr_set(struct conf *c, const stru
*port = htons((in_port_t)c->c_port);
conf_apply_mask(addr, alen, c->c_lmask);
- if (c->c_lmask == -1)
+ if (c->c_lmask == FSTAR)
c->c_lmask = (int)(alen * 8);
if (debug) {
char buf[128];
@@ -690,7 +682,7 @@ conf_eq(const struct conf *c1, const str
return 0;
#define CMP(a, b, f) \
- if ((a)->f != (b)->f && (b)->f != -1 && (b)->f != -2) { \
+ if ((a)->f != (b)->f && (b)->f != FSTAR && (b)->f != FEQUAL) { \
if (debug > 1) \
(*lfun)(LOG_DEBUG, "%s: %s fail %d != %d", __func__, \
__STRING(f), (a)->f, (b)->f); \
@@ -708,9 +700,9 @@ static const char *
conf_num(char *b, size_t l, int n)
{
switch (n) {
- case -1:
+ case FSTAR:
return "*";
- case -2:
+ case FEQUAL:
return "=";
default:
snprintf(b, l, "%d", n);
@@ -739,7 +731,7 @@ fmtport(char *b, size_t l, int port)
{
char buf[128];
- if (port == -1)
+ if (port == FSTAR)
return;
if (b[0] == '\0' || strcmp(b, "*") == 0)
@@ -756,9 +748,9 @@ fmtmask(char *b, size_t l, int fam, int
char buf[128];
switch (mask) {
- case -1:
+ case FSTAR:
return "";
- case -2:
+ case FEQUAL:
if (strcmp(b, "=") == 0)
return "";
else {
@@ -829,8 +821,8 @@ conf_print(char *buf, size_t len, const
conf_namemask(hb, sizeof(hb), c), delim,
N(3, c->c_nfail), delim, N(4, c->c_duration));
else
- snprintf(buf, len, "%starget=%s, proto=%s, family=%s, "
- "uid=%s, name=%s, nfail=%s, duration=%s", pref,
+ snprintf(buf, len, "%starget:%s, proto:%s, family:%s, "
+ "uid:%s, name:%s, nfail:%s, duration:%s", pref,
ha, N(0, c->c_proto), N(1, c->c_family), N(2, c->c_uid),
conf_namemask(hb, sizeof(hb), c),
N(3, c->c_nfail), N(4, c->c_duration));
@@ -879,13 +871,13 @@ conf_merge(struct conf *c, const struct
if (sc->c_name[0])
memcpy(c->c_name, sc->c_name, CONFNAMESZ);
- if (sc->c_uid != -2)
+ if (sc->c_uid != FEQUAL)
c->c_uid = sc->c_uid;
- if (sc->c_rmask != -2)
+ if (sc->c_rmask != FEQUAL)
c->c_lmask = c->c_rmask = sc->c_rmask;
- if (sc->c_nfail != -2)
+ if (sc->c_nfail != FEQUAL)
c->c_nfail = sc->c_nfail;
- if (sc->c_duration != -2)
+ if (sc->c_duration != FEQUAL)
c->c_duration = sc->c_duration;
if (debug)
(*lfun)(LOG_DEBUG, "%s: %s", __func__,
@@ -1050,13 +1042,13 @@ conf_find(int fd, uid_t uid, const struc
}
cr->c_ss = lss;
- cr->c_lmask = -1;
+ cr->c_lmask = FSTAR;
cr->c_uid = (int)uid;
cr->c_family = lss.ss_family;
cr->c_name[0] = '\0';
- cr->c_rmask = -1;
- cr->c_nfail = -1;
- cr->c_duration = -1;
+ cr->c_rmask = FSTAR;
+ cr->c_nfail = FSTAR;
+ cr->c_duration = FSTAR;
if (debug)
(*lfun)(LOG_DEBUG, "%s", conf_print(buf, sizeof(buf),
Index: src/external/bsd/blacklist/bin/run.c
diff -u src/external/bsd/blacklist/bin/run.c:1.12 src/external/bsd/blacklist/bin/run.c:1.13
--- src/external/bsd/blacklist/bin/run.c:1.12 Tue Jan 27 14:40:37 2015
+++ src/external/bsd/blacklist/bin/run.c Tue Jun 2 10:02:10 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: run.c,v 1.12 2015/01/27 19:40:37 christos Exp $ */
+/* $NetBSD: run.c,v 1.13 2015/06/02 14:02:10 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: run.c,v 1.12 2015/01/27 19:40:37 christos Exp $");
+__RCSID("$NetBSD: run.c,v 1.13 2015/06/02 14:02:10 christos Exp $");
#include <stdio.h>
#ifdef HAVE_UTIL_H
@@ -116,6 +116,9 @@ run_change(const char *how, const struct
size_t off;
switch (c->c_proto) {
+ case -1:
+ prname = "";
+ break;
case IPPROTO_TCP:
prname = "tcp";
break;
@@ -127,7 +130,11 @@ run_change(const char *how, const struct
return -1;
}
- snprintf(poname, sizeof(poname), "%d", c->c_port);
+ if (c->c_port != -1)
+ snprintf(poname, sizeof(poname), "%d", c->c_port);
+ else
+ poname[0] = '\0';
+
snprintf(maskname, sizeof(maskname), "%d", c->c_lmask);
sockaddr_snprintf(adname, sizeof(adname), "%a", (const void *)&c->c_ss);
Index: src/external/bsd/blacklist/bin/state.c
diff -u src/external/bsd/blacklist/bin/state.c:1.16 src/external/bsd/blacklist/bin/state.c:1.17
--- src/external/bsd/blacklist/bin/state.c:1.16 Wed May 27 18:37:37 2015
+++ src/external/bsd/blacklist/bin/state.c Tue Jun 2 10:02:10 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: state.c,v 1.16 2015/05/27 22:37:37 christos Exp $ */
+/* $NetBSD: state.c,v 1.17 2015/06/02 14:02:10 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: state.c,v 1.16 2015/05/27 22:37:37 christos Exp $");
+__RCSID("$NetBSD: state.c,v 1.17 2015/06/02 14:02:10 christos Exp $");
#include <sys/types.h>
#include <sys/socket.h>
@@ -47,6 +47,7 @@ __RCSID("$NetBSD: state.c,v 1.16 2015/05
#include "bl.h"
#include "internal.h"
#include "conf.h"
+#include "support.h"
#include "state.h"
static HASHINFO openinfo = {
@@ -102,18 +103,7 @@ static void
dumpkey(const struct conf *k)
{
char buf[10240];
- size_t z;
- int r;
- const unsigned char *p = (const void *)k;
- const unsigned char *e = p + sizeof(*k);
- r = snprintf(buf, sizeof(buf), "%s: ", __func__);
- if (r == -1 || (z = (size_t)r) >= sizeof(buf))
- z = sizeof(buf);
- while (p < e) {
- r = snprintf(buf + z, sizeof(buf) - z, "%.2x", *p++);
- if (r == -1 || (z += (size_t)r) >= sizeof(buf))
- z = sizeof(buf);
- }
+ hexdump(buf, sizeof(buf), __func__, k, sizeof(*k));
(*lfun)(LOG_DEBUG, "%s", buf);
(*lfun)(LOG_DEBUG, "%s: %s", __func__,
conf_print(buf, sizeof(buf), "", "", k));
Index: src/external/bsd/blacklist/bin/support.c
diff -u src/external/bsd/blacklist/bin/support.c:1.6 src/external/bsd/blacklist/bin/support.c:1.7
--- src/external/bsd/blacklist/bin/support.c:1.6 Tue Jan 27 14:40:37 2015
+++ src/external/bsd/blacklist/bin/support.c Tue Jun 2 10:02:10 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: support.c,v 1.6 2015/01/27 19:40:37 christos Exp $ */
+/* $NetBSD: support.c,v 1.7 2015/06/02 14:02:10 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: support.c,v 1.6 2015/01/27 19:40:37 christos Exp $");
+__RCSID("$NetBSD: support.c,v 1.7 2015/06/02 14:02:10 christos Exp $");
#include <time.h>
#include <string.h>
@@ -131,3 +131,27 @@ fmtydhms(char *b, size_t l, time_t t)
APPEND(s)
return b;
}
+
+ssize_t
+hexdump(char *buf, size_t len, const char *str, const void *b, size_t l)
+{
+ size_t z, cz;
+ int r;
+ const unsigned char *p = b;
+ const unsigned char *e = p + l;
+
+ r = snprintf(buf, len, "%s: ", str);
+ if (r == -1)
+ return -1;
+ if ((cz = z = (size_t)r) >= len)
+ cz = len;
+
+ while (p < e) {
+ r = snprintf(buf + cz, len - cz, "%.2x", *p++);
+ if (r == -1)
+ return -1;
+ if ((cz = (z += (size_t)r)) >= len)
+ cz = len;
+ }
+ return (ssize_t)z;
+}
Index: src/external/bsd/blacklist/bin/support.h
diff -u src/external/bsd/blacklist/bin/support.h:1.5 src/external/bsd/blacklist/bin/support.h:1.6
--- src/external/bsd/blacklist/bin/support.h:1.5 Sun Jan 25 17:22:54 2015
+++ src/external/bsd/blacklist/bin/support.h Tue Jun 2 10:02:10 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: support.h,v 1.5 2015/01/25 22:22:54 christos Exp $ */
+/* $NetBSD: support.h,v 1.6 2015/06/02 14:02:10 christos Exp $ */
/*-
* Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -38,6 +38,7 @@ void vdlog(int, const char *, va_list)
__attribute__((__format__(__printf__, 2, 0)));
void dlog(int, const char *, ...)
__attribute__((__format__(__printf__, 2, 3)));
+ssize_t hexdump(char *, size_t, const char *, const void *, size_t);
__END_DECLS
#endif /* _SUPPORT_H */