wobblyhead hg > freebsd > botblockd
comparison src/botblockd.h @ 0:9f8d79c98fd2 0.4.0
initial public release
| author | Arkadiusz Juszczyk <ark@wobblyhead.net> |
|---|---|
| date | 2026-10-26 11:29 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:9f8d79c98fd2 |
|---|---|
| 1 /* | |
| 2 * Copyright (c) 2026 Arkadiusz Juszczyk <ark@wobblyhead.net> | |
| 3 * | |
| 4 * SPDX-License-Identifier: BSD-2-Clause | |
| 5 */ | |
| 6 | |
| 7 #ifndef BOTBLOCKD_H | |
| 8 #define BOTBLOCKD_H | |
| 9 | |
| 10 #include <sys/types.h> | |
| 11 #include <signal.h> | |
| 12 #include <stdbool.h> | |
| 13 #include <stdint.h> | |
| 14 #include <stdio.h> | |
| 15 #include <time.h> | |
| 16 | |
| 17 /* ---- compile-time paths and constants (PREFIX from the Makefile) ---- */ | |
| 18 | |
| 19 #define DEF_CONF PREFIX "/etc/botblockd/conf" | |
| 20 #define DEF_PIDFILE "/var/run/botblockd.pid" | |
| 21 #define PF_TABLE "botblock" | |
| 22 #define NSTATUS 1000 /* HTTP status codes are 0..999 */ | |
| 23 | |
| 24 /* ---- shared configuration ---- */ | |
| 25 | |
| 26 struct config { | |
| 27 int inspect_secs; | |
| 28 int inspect_count; | |
| 29 int min_errors; | |
| 30 int cooldown_secs; | |
| 31 int block_secs; | |
| 32 char input_log[512]; | |
| 33 char whitelist[512]; | |
| 34 bool status_is_err[NSTATUS]; /* true if the code counts as error */ | |
| 35 }; | |
| 36 | |
| 37 extern struct config cfg; | |
| 38 | |
| 39 /* ---- config.c ---- */ | |
| 40 | |
| 41 int parse_config(const char *path, struct config *out); | |
| 42 char *read_entry(FILE *fp, char **line, size_t *cap, int *lineno); | |
| 43 bool status_is_error(int code); | |
| 44 | |
| 45 /* ---- ip.c ---- */ | |
| 46 | |
| 47 int parse_ipv4(const char *s, uint32_t *out); | |
| 48 int parse_cidr(const char *s, uint32_t *net, uint32_t *mask); | |
| 49 const char *ip_str(uint32_t ip); | |
| 50 | |
| 51 /* ---- whitelist.c ---- */ | |
| 52 | |
| 53 int load_whitelist(const char *path); | |
| 54 bool is_whitelisted(uint32_t ip); | |
| 55 | |
| 56 /* ---- pf.c ---- */ | |
| 57 | |
| 58 int pf_block(uint32_t ip); | |
| 59 int pf_unblock(uint32_t ip); | |
| 60 int pf_show(bool quiet); | |
| 61 int pf_flush(void); | |
| 62 | |
| 63 /* ---- suspect.c ---- */ | |
| 64 | |
| 65 void process_request(uint32_t ip, int status); | |
| 66 void sweep(void); | |
| 67 | |
| 68 /* ---- logtail.c ---- */ | |
| 69 | |
| 70 int tail_open(void); | |
| 71 int tail_log(void); | |
| 72 | |
| 73 /* ---- main.c ---- */ | |
| 74 | |
| 75 extern volatile sig_atomic_t running; | |
| 76 extern volatile sig_atomic_t reload_pending; | |
| 77 void config_reload(void); | |
| 78 time_t monotime(void); | |
| 79 | |
| 80 #endif /* BOTBLOCKD_H */ |
