Sophie

Sophie

distrib > Mandriva > 2011.0 > i586 > media > contrib-release-debug > by-pkgid > 95e1486a8650430c9f01849aff7a09a2 > files > 123

dcc-debug-1.3.122-2mdv2011.0.i586.rpm

/* Distributed Checksum Clearinghouse
 *
 * common server definitions
 *
 * Copyright (c) 2009 by Rhyolite Software, LLC
 *
 * This agreement is not applicable to any entity which sells anti-spam
 * solutions to others or provides an anti-spam solution as part of a
 * security solution sold to other entities, or to a private network
 * which employs the DCC or uses data provided by operation of the DCC
 * but does not provide corresponding data to other users.
 *
 * Permission to use, copy, modify, and distribute this software without
 * changes for any purpose with or without fee is hereby granted, provided
 * that the above copyright notice and this permission notice appear in all
 * copies and any distributed versions or copies are either unchanged
 * or not called anything similar to "DCC" or "Distributed Checksum
 * Clearinghouse".
 *
 * Parties not eligible to receive a license under this agreement can
 * obtain a commercial license to use DCC by contacting Rhyolite Software
 * at sales@rhyolite.com.
 *
 * A commercial license would be for Distributed Checksum and Reputation
 * Clearinghouse software.  That software includes additional features.  This
 * free license for Distributed ChecksumClearinghouse Software does not in any
 * way grant permision to use Distributed Checksum and Reputation Clearinghouse
 * software
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE, LLC DISCLAIMS ALL
 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE, LLC
 * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * Rhyolite Software DCC 1.3.122-1.94 $Revision$
 */

#ifndef SRVR_DEFS_H
#define SRVR_DEFS_H

#include "dcc_clnt.h"
#include "dcc_ids.h"
#include "dcc_heap_debug.h"
#include "db.h"

typedef int64_t   SCNTR;

typedef struct {
    struct timeval reset;
    SCNTR   nops;			/* DCC_OP_NOP packets */
    SCNTR   reports;			/* DCC_OP_REPORT or DCC_OP_REPORT_REP */
    SCNTR   report_retrans;		/* duplicate reports */
    SCNTR   report_reject;		/* reports ignored by -Q */
    SCNTR   report10;			/* reports of >10 targets */
    SCNTR   report100;			/* reports of >100 targets */
    SCNTR   report1000;			/* reports of >1000 targets */
    SCNTR   reportmany;			/* reports of spam */
    SCNTR   queries;			/* DCC_OP_QUERY */
    SCNTR   resp10;			/* responses of >10 targets */
    SCNTR   resp100;			/*   "       " >100 targets */
    SCNTR   resp1000;			/*   "       " >1000 targets */
    SCNTR   respmany;			/*   "       " spam */
    SCNTR   respwhite;			/* whitelisted responses */
    SCNTR   bad_op;			/* unknown, blacklisted, over active */
    SCNTR   bad_passwd;			/* requests with bad passwords */
    SCNTR   blist;			/* blacklisted requests */
    SCNTR   send_error;			/* error responses sent */
    SCNTR   admin;			/* DCC_OP_ADMN */
    SCNTR   rl;				/* responses rate-limited */
    SCNTR   anon_rl;			/* anonymous responses rate-limited */
    SCNTR   adds;			/* reports added */
    SCNTR   iflod_total;		/* total reports received */
    SCNTR   iflod_accepted;		/* timely and properly signed */
    SCNTR   iflod_stale;
    SCNTR   iflod_dup;
    SCNTR   iflod_wlist;		/* locally whitelisted */
    SCNTR   iflod_not_deleted;		/* delete commands ignored */
    SCNTR   norep;
    SCNTR   rep1;
    SCNTR   rep10;
    SCNTR   rep20;
    SCNTR   rep30;
    SCNTR   rep60;
    SCNTR   report_reps;		/* DCC_OP_REPORT_REP packets */
} DCCD_STATS;


typedef char FLOD_EMSG[DCC_FLOD_MAX_RESP];
typedef struct {
    int		trace_gen;		/* to get at least one trace message */
    u_char	complained;
    FLOD_EMSG	trace_msg;
    FLOD_EMSG	err_msg;
} LAST_ERROR;


/* memory mapped file of flooding information
 *  it is memory mapped so that dblist can report the state of flooding
 *  and so dbclean can see when flooding has stopped */

#define GREY_FLOD_NM	"grey_flod"
#define DCCD_FLOD_NM	"flod"
extern DCC_PATH flod_mmap_path, flod_path;

#ifndef DCCD_MAX_FLOODS
#define DCCD_MAX_FLOODS	32
#endif

typedef struct {
    /* timer and backoff for ordinary connect() */
    time_t	retry;
    int		retry_secs;
    /* timer for complaints about missing incoming connection */
    time_t	msg;
    int		msg_secs;
} CONN_TIMERS;
typedef u_int32_t FLOD_MMAP_FLAGS;
typedef struct {
    u_int	num;
    u_int	cur;
    DCC_SOCKU	su[DCC_MAX_HOSTADDRS];
    int		rem_h_errno;
    DCC_SOCKU	loc_v4;
    DCC_SOCKU	loc_v6;
    int		loc_h_errno;
} DNS;
typedef struct {
    char	rem_hostname[DCC_MAXDOMAINLEN];
    char	rem_portname[MAXPORTNAMELEN+1];
    char	loc_hostname[DCC_MAXDOMAINLEN];	/* bind to this */
    DNS		dns;			/* IP addresses */
    DB_PTR	confirm_pos;		/* confirmed sent to here */
    DCC_SRVR_ID	rem_id, in_passwd_id, out_passwd_id;
    CONN_TIMERS	otimers, itimers;
    time_t	reps_rejected;		/* when reputations last rejected */
    FLOD_MMAP_FLAGS flags;
#    define	 FLODMAP_FG_MARK	0x00000001
#    define	 FLODMAP_FG_IN_OFF	0x00000002
#    define	 FLODMAP_FG_OUT_OFF	0x00000004
#    define	 FLODMAP_FG_ROGUE	0x00000008  /* evil server */
#    define	 FLODMAP_FG_IN_CONN	0x00000010  /* input connected */
#    define	 FLODMAP_FG_OUT_CONN	0x00000020  /* output connected */
#    define	 FLODMAP_FG_IPv4	0x00000100  /* override IPv6 choice */
#    define	 FLODMAP_FG_IPv6	0x00000200  /* override IPv6 choice */
#    define	 FLODMAP_FG_PASSIVE	0x00000400  /* peer uses SOCKS */
#    define	 FLODMAP_FG_SOCKS	0x00000800
#    define	 FLODMAP_FG_NAT		0x00001000  /* SOCKS without library */
#    define	 FLODMAP_FG_NAT_AUTO	0x00002000  /* assumed NAT */
#     define	  FLODMAP_FG_ACT (FLODMAP_FG_SOCKS | FLODMAP_FG_NAT	\
				  | FLODMAP_FG_NAT_AUTO)
#    define	 FLODMAP_FG_OUT_SRVR	0x00004000  /* connected by peer */
#    define	 FLODMAP_FG_IN_SRVR	0x00008000  /* connected by peer */
#    define	 FLODMAP_FG_REWINDING	0x00010000  /* answering rewind */
#    define	 FLODMAP_FG_NEED_REWIND	0x00020000  /* database purged */
#    define	 FLODMAP_FG_FFWD_IN	0x00040000  /* want fastforward */
#    define	 FLODMAP_FG_USE_2PASSWD	0x00080000
#    define	 FLODMAP_FG_LEAF	0x00100000  /* path length restricted */
#    define	 FLODMAP_FG_MAPPED	0x00200000  /* server-IDs translated */
    u_char	iversion;		/* incoming flood protocol */
    struct {
	time_t	    cnts_cleared;
	time_t	    in_conn_changed;
	time_t	    out_conn_changed;
	u_int	    out_total_conn;	/* seconds connected */
	u_int	    in_total_conn;
	SCNTR	    out_reports;	/* total reports sent */
	SCNTR	    total;		/*		received */
	SCNTR	    accepted;
	SCNTR	    stale;		/* too old or in the future */
	SCNTR	    dup;		/* already received */
	SCNTR	    wlist;		/* whitelisted */
	SCNTR	    not_deleted;	/* delete commands ignored */
    } cnts;
    LAST_ERROR	    oflod_err;
    LAST_ERROR	    iflod_err;
} FLOD_MMAP;

typedef struct {
    char	magic[32];
#    define	 FLOD_MMAP_MAGIC	"DCC flod map version 20"
    char	pad[32-sizeof(DB_PTR)];
    DB_PTR	delay_pos;		/* delay flooding newer than this */
    DB_SN	sn;			/* ensure match with database */
    time_t	ids_mtime;		/* ids file mtime when we checked */
    FLOD_MMAP	mmaps[DCCD_MAX_FLOODS];
    DCCD_STATS	dccd_stats;
} FLOD_MMAPS;
extern FLOD_MMAPS *flod_mmaps;


#define _secs2ts(ts,secs) {						\
	u_int64_t ticks = ((u_int64_t)(secs)) << DCC_TS_SEC_SHIFT;	\
	(ts)->b[0] = ticks>>40; (ts)->b[1] = ticks>>32;			\
	(ts)->b[2] = ticks>>24; (ts)->b[3] = ticks>>16;			\
	(ts)->b[4] = ticks>>8; (ts)->b[5] = ticks; }
#ifdef HAVE_GCC_INLINE			/* no prototypes without inline */
static inline void
secs2ts(DCC_TS *ts, time_t secs) _secs2ts(ts, secs)
#else
#define secs2ts(ts, secs) _secs2ts(ts, secs)
#endif

#define _timeval2ts(ts, tv, delta_secs) {				\
	u_int64_t ticks = ((u_int64_t)(tv)->tv_sec			\
			   +(delta_secs)) << DCC_TS_SEC_SHIFT;		\
	ticks += (tv)->tv_usec >> DCC_TS_USEC_SHIFT;			\
	(ts)->b[0] = ticks>>40; (ts)->b[1] = ticks>>32;			\
	(ts)->b[2] = ticks>>24; (ts)->b[3] = ticks>>16;			\
	(ts)->b[4] = ticks>>8; (ts)->b[5] = ticks; }
#ifdef HAVE_GCC_INLINE			/* no prototypes without inline */
static inline void
timeval2ts(DCC_TS *ts, const struct timeval *tv, int delta_secs)
_timeval2ts(ts, tv, delta_secs)
#else
#define timeval2ts(ts, tv, delta_secs) _timeval2ts(ts, tv, delta_secs)
#endif

#define _ts2ticks(ts) ((((u_int64_t)(ts)->b[0])<<40)			\
		       + (((u_int64_t)(ts)->b[1])<<32)			\
		       + (((u_int64_t)(ts)->b[2])<<24)			\
		       + (((u_int64_t)(ts)->b[3])<<16)			\
		       + (((u_int64_t)(ts)->b[4])<<8)			\
		       + (ts)->b[5])

#define _ts2secs(ts) ((time_t)(_ts2ticks(ts) >> DCC_TS_SEC_SHIFT))
#ifdef HAVE_GCC_INLINE			/* no prototypes without inline */
static inline time_t
ts2secs(const DCC_TS *ts) {return _ts2secs(ts);}
#else
#define ts2secs(const DCC_TS *ts) _ts2secs(ts)
#endif

#define _ts2timeval(tv, ts) {						\
	u_int64_t ticks = _ts2ticks(ts);				\
	(tv)->tv_sec = ticks >> DCC_TS_SEC_SHIFT;			\
	(tv)->tv_usec = ((ticks &  DCC_TS_USEC_MASK) << DCC_TS_USEC_SHIFT); }
#ifdef HAVE_GCC_INLINE			/* no prototypes without inline */
static inline void
ts2timeval(struct timeval *tv, const DCC_TS *ts) _ts2timeval(tv, ts)
#else
#define ts2timeval(tv, ts) _ts2timeval(tv, ts)
#endif

#define _ts_newer_ts(ts1, ts2) (memcmp(ts1, ts2, sizeof(DCC_TS)) > 0)
#ifdef HAVE_GCC_INLINE			/* no prototypes without inline */
static inline int
ts_newer_ts(const DCC_TS *ts1, const DCC_TS *ts2)
{ return _ts_newer_ts(ts1, ts2); }
#else
#define ts_newer_ts(ts1, ts2) (memcmp(ts1, ts2, sizeof(DCC_TS)) > 0)
#endif

#define _ts_older_ts(ts1, ts2) (memcmp(ts1, ts2, sizeof(DCC_TS)) < 0)
#ifdef HAVE_GCC_INLINE			/* no prototypes without inline */
static inline int
ts_older_ts(const DCC_TS *ts1, const DCC_TS *ts2)
{ return _ts_older_ts(ts1, ts2); }
#else
#define ts_older_ts(ts1, ts2) _ts_older_ts(ts1, ts2)
#endif


#define DB_TYPE2STR(t) type2str_err(t,0,1,grey_on)

/* not thread safe */
extern DCC_PATH db_path_buf;
#define DB_NM2PATH_ERR(nm) dcc_fnm2abs_msg(db_path_buf, nm)


extern void flod_mmap_path_set(void);
extern u_char flod_mmap_sync(DCC_EMSG, u_char);
extern u_char flod_unmap(DCC_EMSG, const DCCD_STATS *);
extern u_char flod_mmap(DCC_EMSG, const DB_SN *, const DCCD_STATS *, u_char);
extern const char *flod_stats_printf(char *, int, int, int, int, int);
extern const char *socks_type_str(const FLOD_MMAP *);
extern const char *flodmap_fg(char *, int, const FLOD_MMAP *);
extern int flod_running(const char *);

extern int read_db(DCC_EMSG, void *, u_int, int, off_t, const char *);
extern u_char read_db_hdr(DCC_EMSG, DB_HDR *, int fd, const char *);
extern void read_rcd_invalidate(u_int);
extern int read_rcd(DCC_EMSG, DB_RCD *, int, off_t, const char *);

extern char *ts2str(char *, u_int, const DCC_TS *);
extern const char *ts2str_err(const DCC_TS *);

extern char *dcc_srvr_id2str(char *, u_int, DCC_SRVR_ID);

extern u_char istmpfs(int, const char *);


#endif /* SRVR_DEFS_H */