/*----- Header files ------------------------------------------------------*/
+#include "config.h"
+
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
-#include <linux/netlink.h>
-#include <linux/rtnetlink.h>
-
#include <syslog.h>
#include <mLib/bits.h>
#include <mLib/conn.h>
#include <mLib/darray.h>
#include <mLib/dstr.h>
+#include <mLib/fdflags.h>
#include <mLib/fwatch.h>
#include <mLib/quis.h>
#include <mLib/report.h>
#include <mLib/sel.h>
#include <mLib/selbuf.h>
+/*----- System specifics --------------------------------------------------*/
+
+#define SYS_UNDEF 0
+#define SYS_LINUX 1
+
+#if SYS == SYS_LINUX
+# include <linux/netlink.h>
+# include <linux/rtnetlink.h>
+#else
+# error "Unsupported operating system: sorry. Patches welcome!"
+#endif
+
/*----- Data structures ---------------------------------------------------*/
#define ADDRLEN 64
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(_) \
};
struct query {
- int af;
+ const struct addrops *ao;
struct socket s[NDIR];
unsigned resp;
union {
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") \
};
struct policy {
- int af;
+ const struct addrops *ao;
struct sockpat sp[NDIR];
struct action act;
};
/*----- 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);
-int get_default_gw(int af, union addr *a);
void init_policy(struct policy *p);
void free_policy(struct policy *p);