xref: /minix/external/bsd/bind/dist/bin/named/pfilter.c (revision 00b67f09)
1 #include <config.h>
2 
3 #include <isc/platform.h>
4 #include <isc/util.h>
5 #include <named/types.h>
6 #include <named/client.h>
7 
8 #include <blacklist.h>
9 
10 #include "pfilter.h"
11 
12 static struct blacklist *blstate;
13 
14 void
pfilter_open(void)15 pfilter_open(void)
16 {
17 	if (blstate == NULL)
18 		blstate = blacklist_open();
19 }
20 
21 #define TCP_CLIENT(c)  (((c)->attributes & NS_CLIENTATTR_TCP) != 0)
22 
23 void
pfilter_notify(isc_result_t res,ns_client_t * client,const char * msg)24 pfilter_notify(isc_result_t res, ns_client_t *client, const char *msg)
25 {
26 	isc_socket_t *socket;
27 
28 	pfilter_open();
29 
30 	if (TCP_CLIENT(client))
31 		socket = client->tcpsocket;
32 	else {
33 		socket = client->udpsocket;
34 		if (!client->peeraddr_valid)
35 			return;
36 	}
37 
38 	if (socket == NULL)
39 		return;
40 
41 	if (blstate == NULL)
42 		return;
43 
44 	blacklist_sa_r(blstate,
45 	    res != ISC_R_SUCCESS, isc_socket_getfd(socket),
46 	    &client->peeraddr.type.sa, client->peeraddr.length, msg);
47 }
48