xref: /openbsd/libexec/spamd/sync.h (revision d72b910d)
1 /*	$OpenBSD: sync.h,v 1.3 2008/05/22 19:54:11 deraadt Exp $	*/
2 
3 /*
4  * Copyright (c) 2006, 2007 Reyk Floeter <reyk@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _SPAMD_SYNC
20 #define _SPAMD_SYNC
21 
22 /*
23  * spamd(8) synchronisation protocol.
24  *
25  * This protocol has been designed for realtime synchronisation between
26  * multiple machines running spamd(8), ie. in front of a MX and a backup MX.
27  * It is a simple Type-Length-Value based protocol, it allows easy
28  * extension with future subtypes and bulk transfers by sending multiple
29  * entries at once. The unencrypted messages will be authenticated using
30  * HMAC-SHA1.
31  *
32  * the spamd(8) synchronisation protocol is not intended to be used as
33  * a public SPAM sender database or distribution between vendors.
34  */
35 
36 #define SPAM_SYNC_VERSION	2
37 #define SPAM_SYNC_MCASTADDR	"224.0.1.240"	/* XXX choose valid address */
38 #define SPAM_SYNC_MCASTTTL	IP_DEFAULT_MULTICAST_TTL
39 #define SPAM_SYNC_HMAC_LEN	20	/* SHA1 */
40 #define SPAM_SYNC_MAXSIZE	1408
41 #define SPAM_SYNC_KEY		"/etc/mail/spamd.key"
42 
43 #define SPAM_ALIGNBYTES      (15)
44 #define SPAM_ALIGN(p)        (((u_int)(p) + SPAM_ALIGNBYTES) &~ SPAM_ALIGNBYTES)
45 
46 struct spam_synchdr {
47 	u_int8_t	sh_version;
48 	u_int8_t	sh_af;
49 	u_int16_t	sh_length;
50 	u_int32_t	sh_counter;
51 	u_int8_t	sh_hmac[SPAM_SYNC_HMAC_LEN];
52 	u_int8_t	sh_pad[4];
53 } __packed;
54 
55 struct spam_synctlv_hdr {
56 	u_int16_t	st_type;
57 	u_int16_t	st_length;
58 } __packed;
59 
60 struct spam_synctlv_grey {
61 	u_int16_t	sg_type;
62 	u_int16_t	sg_length;
63 	u_int32_t	sg_timestamp;
64 	u_int32_t	sg_ip;
65 	u_int16_t	sg_from_length;
66 	u_int16_t	sg_to_length;
67 	u_int16_t	sg_helo_length;
68 	/* strings go here, then packet code re-aligns packet */
69 } __packed;
70 
71 struct spam_synctlv_addr {
72 	u_int16_t	sd_type;
73 	u_int16_t	sd_length;
74 	u_int32_t	sd_timestamp;
75 	u_int32_t	sd_expire;
76 	u_int32_t	sd_ip;
77 } __packed;
78 
79 #define SPAM_SYNC_END		0x0000
80 #define SPAM_SYNC_GREY		0x0001
81 #define SPAM_SYNC_WHITE		0x0002
82 #define SPAM_SYNC_TRAPPED	0x0003
83 
84 extern int	 sync_init(const char *, const char *, u_short);
85 extern int	 sync_addhost(const char *, u_short);
86 extern void	 sync_recv(void);
87 extern void	 sync_update(time_t, char *, char *, char *, char *);
88 extern void	 sync_white(time_t, time_t, char *);
89 extern void	 sync_trapped(time_t, time_t, char *);
90 
91 #endif /* _SPAMD_SYNC */
92