Skip to content

Commit

Permalink
Merge pull request #8 from proditis/master
Browse files Browse the repository at this point in the history
style(9) and work towards supporting OpenBSD ports system
  • Loading branch information
proditis committed Jun 29, 2015
2 parents 809dd0c + 71ba658 commit 5c347c8
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 65 deletions.
48 changes: 8 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,40 +1,8 @@
# Build the diverters dont write this with eclipse :P
# SAMPLE needs work
#

BINDIR = /usr/local/sbin

all: bofh-divert dnsbl-divert

install: install-bofh install-dnsbl

uninstall: uninstall-bofh uninstall-dnsbl

clean:
rm -rf stdpf.o daemon.o dnsbl-divert bofh-divert

bofh-divert: bofh-divert.c daemon.o stdpf.o
gcc -o bofh-divert bofh-divert.c daemon.o stdpf.o

dnsbl-divert: dnsbl-divert.c daemon.o stdpf.o
gcc -o dnsbl-divert dnsbl-divert.c daemon.o stdpf.o

daemon.o: daemon.c
gcc -c daemon.c

stdpf.o: stdpf.c
gcc -c stdpf.c

install-bofh:
install -Ss -o root -g wheel -m 750 bofh-divert $(BINDIR)/bofh-divert
install -o root -g wheel -m 750 rc.bofh /etc/rc.d/bofh_divert

install-dnsbl:
install -Ss -o root -g wheel -m 750 dnsbl-divert $(BINDIR)/dnsbl-divert
install -o root -g wheel -m 750 rc.dnsbl /etc/rc.d/dnsbl_divert

uninstall-bofh:
rm $(BINDIR)/bofh-divert /etc/rc.d/rc.bofh

uninstall-dnsbl:
rm $(BINDIR)/dnsbl-divert /etc/rc.d/rc.dnsbl
# taken from pfstatd
SUBDIR= bofh
SUBDIR+= dnsbl
#SUBDIR+= heartbleed
CFLAGS+= -Wall
CFLAGS+= -I${.CURDIR}

.include <bsd.prog.mk>
9 changes: 9 additions & 0 deletions bofh/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# taken from pfstatd
PROG= bofh-divert
SRCS= bofh-divert.c daemon.c stdpf.c
MAN=
.PATH: ${.CURDIR}/..
CFLAGS+= -Wall
CFLAGS+= -I${.CURDIR}/..

.include <bsd.prog.mk>
3 changes: 2 additions & 1 deletion bofh-divert.c → bofh/bofh-divert.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
#define DAEMON_NAME "bofh-divert"

void usage() {
fprintf(stderr,"usage: %s -p pnum -t tname\n",DAEMON_NAME);
extern char *__progname;
fprintf(stderr,"usage: %s -p pnum -t tname\n",__progname);
fprintf(stderr,"\tpnum divert port number to bind (1-65535)\n");
fprintf(stderr,"\ttname table to add collected host IPs (up to %d chars)\n",PF_TABLE_NAME_SIZE);
exit(EXIT_FAILURE);
Expand Down
12 changes: 6 additions & 6 deletions daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
* http://www.4pmp.com/2009/12/a-simple-daemon-in-c/
* with a few adjustments to better fit our needs.
*/
#include <sys/types.h>
#include <sys/stat.h>

#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <fcntl.h>
#include <signal.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>


#include "daemon.h"

Expand Down
4 changes: 2 additions & 2 deletions daemon.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef DAEMON_H
#define DAEMON_H 1
void daemonShutdown();
void signal_handler(int sig);
void daemonize(char *rundir, char *pidfile);
void signal_handler(int);
void daemonize(char *, char *);
#endif
9 changes: 9 additions & 0 deletions dnsbl/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# taken from pfstatd
PROG= dnsbl-divert
SRCS= dnsbl-divert.c daemon.c stdpf.c
MAN=
.PATH: ${.CURDIR}/..
CFLAGS+= -Wall
CFLAGS+= -I${.CURDIR}/..

.include <bsd.prog.mk>
23 changes: 14 additions & 9 deletions dnsbl-divert.c → dnsbl/dnsbl-divert.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,28 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <net/pfvar.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/in_systm.h>
#include <netinet/ip_var.h>
#include <netinet/tcpip.h>
#include <net/if.h>
#include <net/pfvar.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>

#include <ctype.h> // for isdigit
#include <err.h>
#include <fcntl.h>
#include <netdb.h>
#include <resolv.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <syslog.h>
#include <unistd.h> // for getopt
#include <ctype.h> // for isdigit
#include <err.h>
#include <resolv.h>
#include <netdb.h>

#include "stdpf.h"
#include "daemon.h"

Expand Down Expand Up @@ -86,7 +88,8 @@ static char *revip_str(char *ip) {
}

void usage() {
printf("usage: %s -p pnum -t tbl -c tch [dns]\n",DAEMON_NAME);
extern char *__progname;
printf("usage: %s -p pnum -t tbl -c tch [dns]\n",__progname);
printf("\tpnum divert port number to bind (1-65535)\n");
printf("\ttbl table to populate with DNSBLed hosts (up to %d chars)\n",PF_TABLE_NAME_SIZE);
printf("\ttch table to cache already-looked-up hosts (up to %d chars)\n",PF_TABLE_NAME_SIZE);
Expand All @@ -108,9 +111,11 @@ int main(int argc, char *argv[]) {
char pidPath[64];
char syslogLine[256];

extern char *__progname;
extern char *optarg;
extern int optind;
int ch, cherr=0, pflag=0, tflag=0, cflag=0;

while ((ch = getopt(argc, argv, "p:t:c:")) != -1) {
switch (ch) {
case 'p':
Expand Down Expand Up @@ -155,7 +160,7 @@ int main(int argc, char *argv[]) {

/* Logging */
setlogmask(LOG_UPTO(LOG_INFO));
openlog(DAEMON_NAME, LOG_CONS | LOG_PERROR, LOG_USER);
openlog(__progname, LOG_CONS | LOG_PERROR, LOG_USER);

syslog(LOG_INFO, "Daemon starting up");

Expand Down
9 changes: 9 additions & 0 deletions heartbleed/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# taken from pfstatd
PROG= heartbleed-divert
SRCS= heartbleed-divert.c
#MAN= pfstatd.8
.PATH: ${.CURDIR}/..
CFLAGS+= -Wall
CFLAGS+= -I${.CURDIR}/..

.include <bsd.prog.mk>
3 changes: 2 additions & 1 deletion heartbleed-divert.c → heartbleed/heartbleed-divert.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@
#include <netinet/tcp.h>
#include <netinet/tcpip.h>
#include <arpa/inet.h>

#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <err.h>

#define DIVERT_PORT 700
#define DAEMON_NAME "heartbleed-divert"
Expand Down
11 changes: 6 additions & 5 deletions stdpf.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <net/pfvar.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/in_systm.h>
#include <netinet/ip_var.h>
#include <net/if.h>
#include <net/pfvar.h>
#include <arpa/inet.h>
#include <stdlib.h>

#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <err.h>
#include <unistd.h>


#include "stdpf.h"
Expand Down
2 changes: 1 addition & 1 deletion stdpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
if (mask < 8) b[0] &= (0xFF << ( 8 - mask)); \
}

void add(char *tname, struct in_addr *ip, uint8_t mask);
void add(char *, struct in_addr *, uint8_t);
void ets_pf_open();
void ets_pf_close();
#endif

0 comments on commit 5c347c8

Please sign in to comment.