3 * Common definitions for YAID
5 * (c) 2012 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Yet Another Ident Daemon (YAID).
12 * YAID is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * YAID is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with YAID; if not, write to the Free Software Foundation,
24 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 /*----- Header files ------------------------------------------------------*/
47 #include <sys/types.h>
53 #include <sys/socket.h>
54 #include <netinet/in.h>
55 #include <arpa/inet.h>
59 #include <mLib/bits.h>
60 #include <mLib/conn.h>
61 #include <mLib/darray.h>
62 #include <mLib/dstr.h>
63 #include <mLib/fdflags.h>
64 #include <mLib/fwatch.h>
65 #include <mLib/quis.h>
66 #include <mLib/report.h>
68 #include <mLib/selbuf.h>
70 /*----- System specifics --------------------------------------------------*/
76 # include <linux/netlink.h>
77 # include <linux/rtnetlink.h>
79 # error "Unsupported operating system: sorry. Patches welcome!"
82 /*----- Data structures ---------------------------------------------------*/
110 #define ADDRTYPES(_) \
118 const union addr *any;
119 const struct addrops_sys *sys;
120 int (*addreq)(const union addr *, const union addr *);
121 int (*match_addrpat)(const struct addrpat *, const union addr *);
122 void (*socket_to_sockaddr)(const struct socket *s, void *, size_t *);
123 void (*sockaddr_to_addr)(const void *, union addr *);
124 int (*init_listen_socket)(int);
128 #define DEFADDR(ty, TY) ADDR_##TY,
134 extern const struct addrops addroptab[];
135 #define OPS_SYS(ty, TY) \
136 extern const struct addrops_sys addrops_sys_##ty;
142 #define RESPONSE(_) \
143 _(ERROR, U(error, unsigned)) \
144 _(UID, U(uid, uid_t)) \
145 _(NAT, U(nat, struct socket))
148 _(INVPORT, "INVALID-PORT") \
149 _(NOUSER, "NO-USER") \
150 _(HIDDEN, "HIDDEN-USER") \
151 _(UNKNOWN, "UNKNOWN-ERROR")
152 extern const char *const errtok[];
155 #define DEFENUM(err, tok) E_##err,
162 #define DEFENUM(what, branch) R_##what,
169 const struct addrops *ao;
170 struct socket s[NDIR];
173 #define DEFBRANCH(WHAT, branch) branch
174 #define U(memb, ty) ty memb;
199 #define DEFENUM(tag, word) A_##tag,
214 const struct addrops *ao;
215 struct sockpat sp[NDIR];
218 #define POLICY_INIT(a) { 0, { { { 0 } } }, { a } }
222 const struct query *q;
230 DA_DECL(policy_v, struct policy);
232 /*----- Functions provided ------------------------------------------------*/
234 int sockeq(const struct addrops *ao,
235 const struct socket *sa, const struct socket *sb);
236 void dputsock(dstr *d, const struct addrops *ao, const struct socket *s);
238 void logmsg(const struct query *q, int prio, const char *msg, ...);
240 void identify(struct query *q);
242 void init_policy(struct policy *p);
243 void free_policy(struct policy *p);
244 void print_policy(const struct policy *p);
245 int match_policy(const struct policy *p, const struct query *q);
246 int parse_policy(FILE *fp, struct policy *p);
247 int open_policy_file(struct policy_file *pf, const char *name,
248 const char *what, const struct query *q);
249 int read_policy_file(struct policy_file *pf);
250 void close_policy_file(struct policy_file *pf);
251 int load_policy_file(const char *file, policy_v *pv);
253 /*----- That's all, folks -------------------------------------------------*/