1 2 #include <isc/util.h> 3 #include <ns/types.h> 4 #include <ns/client.h> 5 6 #include <blocklist.h> 7 8 #include <ns/pfilter.h> 9 10 static struct blocklist *blstate; 11 static int blenable; 12 13 void 14 pfilter_enable(void) { 15 blenable = 1; 16 } 17 18 #define TCP_CLIENT(c) (((c)->attributes & NS_CLIENTATTR_TCP) != 0) 19 20 void 21 pfilter_notify(isc_result_t res, ns_client_t *client, const char *msg) 22 { 23 int fd; 24 25 if (!blenable) 26 return; 27 28 if (blstate == NULL) 29 blstate = blocklist_open(); 30 31 if (blstate == NULL) 32 return; 33 34 if (!TCP_CLIENT(client) && !client->peeraddr_valid) 35 return; 36 37 if ((fd = isc_nmhandle_getfd(client->handle)) == -1) 38 return; 39 40 blocklist_sa_r(blstate, 41 res != ISC_R_SUCCESS, fd, 42 &client->peeraddr.type.sa, client->peeraddr.length, msg); 43 } 44