1 /* $OpenBSD: sasyncd.h,v 1.14 2007/01/08 15:31:01 markus Exp $ */ 2 3 /* 4 * Copyright (c) 2005 H�kan Olsson. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 /* 29 * This code was written under funding by Multicom Security AB. 30 */ 31 32 33 #include <sys/queue.h> 34 35 enum RUNSTATE { INIT = 0, SLAVE, MASTER, FAIL }; 36 #define CARPSTATES { "INIT", "SLAVE", "MASTER", "FAIL" } 37 38 struct syncpeer; 39 struct timeval; 40 41 struct cfgstate { 42 enum RUNSTATE runstate; 43 enum RUNSTATE lockedstate; 44 int debug; 45 int verboselevel; 46 u_int32_t flags; 47 48 char *carp_ifname; 49 char *carp_ifgroup; 50 int carp_ifindex; 51 52 char *sharedkey; 53 int sharedkey_len; 54 55 int pfkey_socket; 56 57 int route_socket; 58 59 char *listen_on; 60 in_port_t listen_port; 61 sa_family_t listen_family; 62 63 int peercnt; 64 LIST_HEAD(, syncpeer) peerlist; 65 }; 66 67 /* flags */ 68 #define FM_STARTUP 0x0000 69 #define FM_NEVER 0x0001 70 #define FM_SYNC 0x0002 71 #define FM_MASK 0x0003 72 73 /* Do not sync SAs to/from our peers. */ 74 #define SKIP_LOCAL_SAS 0x0004 75 76 extern struct cfgstate cfgstate; 77 extern int carp_demoted; 78 79 #define SASYNCD_USER "_isakmpd" 80 #define SASYNCD_CFGFILE "/etc/sasyncd.conf" 81 82 #define CARP_DEFAULT_INTERVAL 10 83 #define SASYNCD_DEFAULT_PORT 500 84 85 /* 86 * sasyncd "protocol" definition 87 * 88 * Message format: 89 * u_int32_t type 90 * u_int32_t len 91 * raw data 92 */ 93 94 /* sasyncd protocol message types */ 95 #define MSG_SYNCCTL 0 96 #define MSG_PFKEYDATA 1 97 #define MSG_MAXTYPE 1 /* Increase when new types are added. */ 98 99 100 #define CARP_DEC -1 101 #define CARP_INC 1 102 103 #define CARP_DEMOTE_MAXTIME 60 104 105 /* conf.c */ 106 int conf_parse_file(char *); 107 108 /* carp.c */ 109 int carp_init(void); 110 void carp_check_state(void); 111 void carp_demote(int, int); 112 void carp_update_state(enum RUNSTATE); 113 void carp_set_rfd(fd_set *); 114 void carp_read_message(fd_set *); 115 const char* carp_state_name(enum RUNSTATE); 116 void isakmpd_setrun(void); 117 118 119 /* log.c */ 120 /* 121 * Log levels for log_msg(level, ...) roughly means: 122 * 0 = errors and other important messages 123 * 1 = state changes, ctl message errors and dis-/connecting peers 124 * 2 = configuration and initialization messages 125 * 3 = PF_KEY logging 126 * 4 = misc network 127 * 5 = crypto 128 * 6 = timers 129 */ 130 void log_init(char *); 131 void log_msg(int, const char *, ...); 132 void log_err(const char *, ...); 133 134 /* monitor.c */ 135 pid_t monitor_init(void); 136 void monitor_loop(void); 137 void monitor_carpdemote(void *); 138 void monitor_carpundemote(void *); 139 140 /* net.c */ 141 void dump_buf(int, u_int8_t *, u_int32_t, char *); 142 void net_ctl_update_state(void); 143 int net_init(void); 144 void net_handle_messages(fd_set *); 145 int net_queue(struct syncpeer *, u_int32_t, u_int8_t *, u_int32_t); 146 void net_send_messages(fd_set *); 147 int net_set_rfds(fd_set *); 148 int net_set_pending_wfds(fd_set *); 149 void net_shutdown(void); 150 151 /* pfkey.c */ 152 int pfkey_init(int); 153 int pfkey_queue_message(u_int8_t *, u_int32_t); 154 void pfkey_read_message(fd_set *); 155 void pfkey_send_message(fd_set *); 156 void pfkey_set_rfd(fd_set *); 157 void pfkey_set_pending_wfd(fd_set *); 158 int pfkey_set_promisc(void); 159 void pfkey_shutdown(void); 160 void pfkey_snapshot(void *); 161 162 /* timer.c */ 163 void timer_init(void); 164 void timer_next_event(struct timeval *); 165 void timer_run(void); 166 int timer_add(char *, u_int32_t, void (*)(void *), void *); 167 168 #if defined (GC_DEBUG) 169 /* Boehms GC */ 170 void *GC_debug_malloc(size_t, char *, int); 171 void *GC_debug_realloc(void *, size_t, char *, int); 172 void GC_debug_free(void *); 173 char *gc_strdup(const char *); 174 175 #define malloc(x) GC_debug_malloc ((x), __FILE__, __LINE__) 176 #define realloc(x,y) GC_debug_realloc ((x), (y), __FILE__, __LINE__) 177 #define free(x) GC_debug_free (x) 178 #define calloc(x,y) malloc((x) * (y)) 179 #define strdup(x) gc_strdup((x)) 180 181 #endif /* WITH_BOEHM_GC */ 182