Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/blacklist/bin Add more debugging, simplify.
details: https://anonhg.NetBSD.org/src/rev/2c554fe3ac71
branches: trunk
changeset: 338639:2c554fe3ac71
user: christos <christos%NetBSD.org@localhost>
date: Tue Jun 02 14:02:10 2015 +0000
description:
Add more debugging, simplify.
Use symbolic constants: -2=FEQUALS, -1=FSTAR
diffstat:
external/bsd/blacklist/bin/blacklistctl.c | 9 +-
external/bsd/blacklist/bin/conf.c | 124 ++++++++++++++---------------
external/bsd/blacklist/bin/run.c | 13 ++-
external/bsd/blacklist/bin/state.c | 18 +---
external/bsd/blacklist/bin/support.c | 28 ++++++-
external/bsd/blacklist/bin/support.h | 3 +-
6 files changed, 106 insertions(+), 89 deletions(-)
diffs (truncated from 511 to 300 lines):
diff -r 2b875126e092 -r 2c554fe3ac71 external/bsd/blacklist/bin/blacklistctl.c
--- a/external/bsd/blacklist/bin/blacklistctl.c Tue Jun 02 13:26:36 2015 +0000
+++ b/external/bsd/blacklist/bin/blacklistctl.c Tue Jun 02 14:02:10 2015 +0000
@@ -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 @@
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 @@
break;
case 'b':
blocked = 1;
+ case 'D':
+ dbname = optarg;
+ break;
break;
case 'd':
debug++;
diff -r 2b875126e092 -r 2c554fe3ac71 external/bsd/blacklist/bin/conf.c
--- a/external/bsd/blacklist/bin/conf.c Tue Jun 02 13:26:36 2015 +0000
+++ b/external/bsd/blacklist/bin/conf.c Tue Jun 02 14:02:10 2015 +0000
@@ -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 @@
#include "bl.h"
#include "internal.h"
+#include "support.h"
#include "conf.h"
@@ -71,6 +72,9 @@
static int conf_is_interface(const char *);
+#define FSTAR -1
+#define FEQUAL -2
+
static void
advance(char **p)
{
@@ -91,13 +95,13 @@
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 @@
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 @@
}
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;
+ if ((d = strchr(s, '/')) == NULL) {
+ *mask = FSTAR;
+ return 0;
+ }
*d++ = '\0';
- if (strcmp(d, "=") == 0) {
- if (local)
- goto out;
- return -2;
- }
- 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;
+ return getnum(f, l, local, mask, "mask", d);
}
static int
@@ -247,8 +234,8 @@
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 @@
} 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 @@
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 @@
}
}
- 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 @@
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 @@
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 @@
} 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 @@
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 @@
*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 @@
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 @@
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 @@
{
char buf[128];
- if (port == -1)
+ if (port == FSTAR)
return;
Home |
Main Index |
Thread Index |
Old Index