Skip to content
Permalink
Browse files

Attempt to give blacklistd enough socket info.

  • Loading branch information...
schmonz committed Jan 2, 2019
1 parent bb45507 commit b60e655bd06b7b2da8ccf55e07e8102cd125bbb7
Showing with 35 additions and 1 deletion.
  1. +35 −1 acceptutils_pfilter.c
@@ -3,9 +3,43 @@
#if HASBLACKLIST

#include <blacklist.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>

static int ip6(const struct sockaddr_storage *ss,char *ip,char *port) {
struct sockaddr_in6 *sock = (struct sockaddr_in6 *)ss;
sock->sin6_family = AF_INET6;
sock->sin6_port = htons(atoi(port));
return inet_pton(AF_INET6, ip, &sock->sin6_addr);
}

static int ip4(const struct sockaddr_storage *ss,char *ip,char *port) {
struct sockaddr_in *sock = (struct sockaddr_in *)ss;
sock->sin_family = AF_INET;
sock->sin_port = htons(atoi(port));
return inet_pton(AF_INET, ip, &sock->sin_addr);
}

static void socket_info(const struct sockaddr_storage *ss,socklen_t *slen) {
memset((void *)ss, 0, *slen);
char *proto = getenv("PROTO");
if (proto && 0 == strcmp(proto,"TCP6")) {
if (0 == ip6(ss,getenv("TCP6REMOTEIP"),getenv("TCP6LOCALPORT")))
(void)ip6(ss,getenv("TCPREMOTEIP"),getenv("TCPLOCALPORT"));
} else {
char *ip = getenv("TCPREMOTEIP");
char *port = getenv("TCPLOCALPORT");
if (0 == ip4(ss,ip,port))
(void)ip6(ss,ip,port);
}
}

void pfilter_notify(int what,const char *msg) {
blacklist(what, 0, msg);
const struct sockaddr_storage ss;
socklen_t slen = sizeof(ss);
socket_info(&ss,&slen);
blacklist_sa(what, 0, (void *)&ss, slen, msg);
}

#else

0 comments on commit b60e655

Please sign in to comment.
You can’t perform that action at this time.