1301169Slidl/*	$NetBSD: blacklist.c,v 1.5 2015/01/22 16:19:53 christos Exp $	*/
2301169Slidl
3301169Slidl/*-
4301169Slidl * Copyright (c) 2014 The NetBSD Foundation, Inc.
5301169Slidl * All rights reserved.
6301169Slidl *
7301169Slidl * This code is derived from software contributed to The NetBSD Foundation
8301169Slidl * by Christos Zoulas.
9301169Slidl *
10301169Slidl * Redistribution and use in source and binary forms, with or without
11301169Slidl * modification, are permitted provided that the following conditions
12301169Slidl * are met:
13301169Slidl * 1. Redistributions of source code must retain the above copyright
14301169Slidl *    notice, this list of conditions and the following disclaimer.
15301169Slidl * 2. Redistributions in binary form must reproduce the above copyright
16301169Slidl *    notice, this list of conditions and the following disclaimer in the
17301169Slidl *    documentation and/or other materials provided with the distribution.
18301169Slidl *
19301169Slidl * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20301169Slidl * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21301169Slidl * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22301169Slidl * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23301169Slidl * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24301169Slidl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25301169Slidl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26301169Slidl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27301169Slidl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28301169Slidl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29301169Slidl * POSSIBILITY OF SUCH DAMAGE.
30301169Slidl */
31301169Slidl#ifdef HAVE_CONFIG_H
32301169Slidl#include "config.h"
33301169Slidl#endif
34301169Slidl
35301169Slidl#include <sys/cdefs.h>
36301169Slidl__RCSID("$NetBSD: blacklist.c,v 1.5 2015/01/22 16:19:53 christos Exp $");
37301169Slidl
38301169Slidl#include <stdio.h>
39301169Slidl#include <bl.h>
40301169Slidl
41301169Slidl#include <stdarg.h>
42301169Slidl#include <errno.h>
43301169Slidl#include <string.h>
44301169Slidl#include <stdlib.h>
45301169Slidl#include <syslog.h>
46301169Slidl
47301169Slidlint
48301169Slidlblacklist_sa(int action, int rfd, const struct sockaddr *sa, socklen_t salen,
49301169Slidl    const char *msg)
50301169Slidl{
51301169Slidl	struct blacklist *bl;
52301169Slidl	int rv;
53301169Slidl	if ((bl = blacklist_open()) == NULL)
54301169Slidl		return -1;
55301169Slidl	rv = blacklist_sa_r(bl, action, rfd, sa, salen, msg);
56301169Slidl	blacklist_close(bl);
57301169Slidl	return rv;
58301169Slidl}
59301169Slidl
60301169Slidlint
61301169Slidlblacklist_sa_r(struct blacklist *bl, int action, int rfd,
62301169Slidl	const struct sockaddr *sa, socklen_t slen, const char *msg)
63301169Slidl{
64301169Slidl	return bl_send(bl, action ? BL_ADD : BL_DELETE, rfd, sa, slen, msg);
65301169Slidl}
66301169Slidl
67301169Slidlint
68301169Slidlblacklist(int action, int rfd, const char *msg)
69301169Slidl{
70301169Slidl	return blacklist_sa(action, rfd, NULL, 0, msg);
71301169Slidl}
72301169Slidl
73301169Slidlint
74301169Slidlblacklist_r(struct blacklist *bl, int action, int rfd, const char *msg)
75301169Slidl{
76301169Slidl	return blacklist_sa_r(bl, action, rfd, NULL, 0, msg);
77301169Slidl}
78301169Slidl
79301169Slidlstruct blacklist *
80301169Slidlblacklist_open(void) {
81301169Slidl	return bl_create(false, NULL, vsyslog);
82301169Slidl}
83301169Slidl
84301169Slidlvoid
85301169Slidlblacklist_close(struct blacklist *bl)
86301169Slidl{
87301169Slidl	bl_destroy(bl);
88301169Slidl}
89