X-Git-Url: https://git.distorted.org.uk/~mdw/yaid/blobdiff_plain/38b211f2a0e292153413e6edb543308f1443d0de..bf4d97617c92530ab67923aaba802333ee258352:/yaid.h diff --git a/yaid.h b/yaid.h index e0d13c1..85ad397 100644 --- a/yaid.h +++ b/yaid.h @@ -33,6 +33,8 @@ /*----- Header files ------------------------------------------------------*/ +#include "config.h" + #include #include #include @@ -52,21 +54,31 @@ #include #include -#include -#include - #include #include #include #include #include +#include #include #include #include #include #include +/*----- System specifics --------------------------------------------------*/ + +#define SYS_UNDEF 0 +#define SYS_LINUX 1 + +#if SYS == SYS_LINUX +# include +# include +#else +# error "Unsupported operating system: sorry. Patches welcome!" +#endif + /*----- Data structures ---------------------------------------------------*/ #define ADDRLEN 64 @@ -81,6 +93,50 @@ struct socket { unsigned port; }; +struct addrpat { + unsigned len; + union addr addr; +}; + +struct portpat { + unsigned lo, hi; +}; + +struct sockpat { + struct addrpat addr; + struct portpat port; +}; + +#define ADDRTYPES(_) \ + _(ipv4, IPV4, INET, "IPv4", 32) \ + _(ipv6, IPV6, INET6, "IPv6", 128) + +struct addrops { + int af; + const char *name; + unsigned len; + const union addr *any; + const struct addrops_sys *sys; + int (*addreq)(const union addr *, const union addr *); + int (*match_addrpat)(const struct addrpat *, const union addr *); + void (*socket_to_sockaddr)(const struct socket *s, void *, size_t *); + void (*sockaddr_to_addr)(const void *, union addr *); + int (*init_listen_socket)(int); +}; + +enum { +#define DEFADDR(ty, TY, af, name, len) ADDR_##TY, + ADDRTYPES(DEFADDR) +#undef DEFADDR + ADDR_LIMIT +}; + +extern const struct addrops addroptab[]; +#define OPS_SYS(ty, TY, af, name, len) \ + extern const struct addrops_sys addrops_sys_##ty; +ADDRTYPES(OPS_SYS) +#undef OPS_SYS + enum { L, R, NDIR }; #define RESPONSE(_) \ @@ -110,7 +166,7 @@ enum { }; struct query { - int af; + const struct addrops *ao; struct socket s[NDIR]; unsigned resp; union { @@ -131,20 +187,6 @@ enum { T_ERROR }; -struct addrpat { - unsigned len; - union addr addr; -}; - -struct portpat { - unsigned lo, hi; -}; - -struct sockpat { - struct addrpat addr; - struct portpat port; -}; - #define ACTIONS(_) \ _(USER, "user") \ _(TOKEN, "token") \ @@ -169,7 +211,7 @@ struct action { }; struct policy { - int af; + const struct addrops *ao; struct sockpat sp[NDIR]; struct action act; }; @@ -189,6 +231,10 @@ DA_DECL(policy_v, struct policy); /*----- Functions provided ------------------------------------------------*/ +int sockeq(const struct addrops *ao, + const struct socket *sa, const struct socket *sb); +void dputsock(dstr *d, const struct addrops *ao, const struct socket *s); + void logmsg(const struct query *q, int prio, const char *msg, ...); void identify(struct query *q);