2 ******************************************************************************
4 * File: fwknopd_common.h
6 * Author: Damien Stuart
8 * Purpose: Header file for fwknopd source files.
10 * Copyright 2010 Damien Stuart (dstuart@dstuart.org)
12 * License (GNU Public License):
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
29 ******************************************************************************
31 #ifndef FWKNOPD_COMMON_H
32 #define FWKNOPD_COMMON_H
37 #include <netinet/in.h>
48 /* My Name and Version
50 #define MY_NAME "fwknopd"
51 #define MY_DESC "Single Packet Authorization server"
53 /* Get our program version from VERSION (defined in config.h).
55 #define MY_VERSION VERSION
57 /* Some program defaults.
60 /* Our default config directory is based on SYSCONFDIR as set by the
63 #define DEF_CONF_DIR SYSCONFDIR"/"PACKAGE_NAME
66 #define DEF_CONFIG_FILE DEF_CONF_DIR"/"MY_NAME".conf"
67 #define DEF_ACCESS_FILE DEF_CONF_DIR"/access.conf"
70 /* Our default run directory is based on LOCALSTATEDIR as set by the
71 * configure script. This is where we put the PID and digest cache files.
73 #define DEF_RUN_DIR SYSRUNDIR"/run/"PACKAGE_NAME
78 #define DEF_PID_FILENAME MY_NAME".pid"
80 #define DEF_DIGEST_CACHE_FILENAME "digest.cache"
82 #define DEF_DIGEST_CACHE_DB_FILENAME "digest_db.cache"
85 #define DEF_INTERFACE "eth0"
86 #define DEF_ENABLE_PCAP_PROMISC "N"
87 #define DEF_PCAP_FILTER "udp port 62201"
88 #define DEF_PCAP_DISPATCH_COUNT "0"
89 #define DEF_PCAP_LOOP_SLEEP "100000" /* a tenth of a second (in microseconds) */
90 #define DEF_ENABLE_SPA_PACKET_AGING "Y"
91 #define DEF_MAX_SPA_PACKET_AGE "120"
92 #define DEF_ENABLE_DIGEST_PERSISTENCE "Y"
93 #define DEF_MAX_SNIFF_BYTES "1500"
94 #define DEF_GPG_HOME_DIR "/root/.gnupg"
95 #define DEF_ENABLE_SPA_OVER_HTTP "N"
96 #define DEF_ENABLE_TCP_SERVER "N"
97 #define DEF_TCPSERV_PORT "62201"
98 #define DEF_SYSLOG_IDENTITY MY_NAME
99 #define DEF_SYSLOG_FACILITY "LOG_DAEMON"
101 #define DEF_FW_ACCESS_TIMEOUT 30
103 /* Iptables-specific defines
105 #if FIREWALL_IPTABLES
107 #define DEF_FLUSH_IPT_AT_INIT "Y"
108 #define DEF_FLUSH_IPT_AT_EXIT "Y"
109 #define DEF_ENABLE_IPT_FORWARDING "N"
110 #define DEF_ENABLE_IPT_LOCAL_NAT "Y"
111 #define DEF_ENABLE_IPT_SNAT "N"
112 #define DEF_ENABLE_IPT_OUTPUT "N"
113 #define DEF_IPT_INPUT_ACCESS "ACCEPT, filter, INPUT, 1, FWKNOP_INPUT, 1"
114 #define DEF_IPT_OUTPUT_ACCESS "ACCEPT, filter, OUTPUT, 1, FWKNOP_OUTPUT, 1"
115 #define DEF_IPT_FORWARD_ACCESS "ACCEPT, filter, FORWARD, 1, FWKNOP_FORWARD, 1"
116 #define DEF_IPT_DNAT_ACCESS "DNAT, nat, PREROUTING, 1, FWKNOP_PREROUTING, 1"
117 #define DEF_IPT_SNAT_ACCESS "SNAT, nat, POSTROUTING, 1, FWKNOP_POSTROUTING, 1"
118 #define DEF_IPT_MASQUERADE_ACCESS "MASQUERADE, nat, POSTROUTING, 1, FWKNOP_POSTROUTING, 1"
120 /* Ipfw-specific defines
124 #define DEF_FLUSH_IPFW_AT_INIT "Y"
125 #define DEF_FLUSH_IPFW_AT_EXIT "Y"
126 #define DEF_IPFW_START_RULE_NUM "10000"
127 #define DEF_IPFW_MAX_RULES "1000"
128 #define DEF_IPFW_ACTIVE_SET_NUM "1"
129 #define DEF_IPFW_EXPIRE_SET_NUM "2"
130 #define DEF_IPFW_EXPIRE_PURGE_INTERVAL "30"
131 #define DEF_IPFW_ADD_CHECK_STATE "N"
135 #define DEF_PF_ANCHOR_NAME "fwknop"
136 #define DEF_PF_EXPIRE_INTERVAL "30"
140 /* --DSS Place-holder */
142 #endif /* FIREWALL Type */
144 /* fwknopd-specific limits
146 #define MAX_PCAP_FILTER_LEN 1024
147 #define MAX_IFNAME_LEN 128
148 #define MAX_SPA_PACKET_LEN 1500 /* --DSS check this? */
149 #define MAX_HOSTNAME_LEN 64
151 /* The minimum possible valid SPA data size.
153 #define MIN_SPA_DATA_SIZE 140
155 /* Configuration file parameter tags.
156 * This will correspond to entries in the configuration parameters
159 * Note: It is important to maintain an equivalence between this enum and the
160 * config_map[] array in server/cmd_opts.h
163 CONF_CONFIG_FILE = 0,
164 CONF_OVERRIDE_CONFIG,
165 //CONF_FIREWALL_TYPE,
167 CONF_ENABLE_PCAP_PROMISC,
169 CONF_PCAP_DISPATCH_COUNT,
170 CONF_PCAP_LOOP_SLEEP,
171 CONF_MAX_SNIFF_BYTES,
172 CONF_ENABLE_SPA_PACKET_AGING,
173 CONF_MAX_SPA_PACKET_AGE,
174 CONF_ENABLE_DIGEST_PERSISTENCE,
175 CONF_CMD_EXEC_TIMEOUT,
177 CONF_ENABLE_SPA_OVER_HTTP,
178 CONF_ENABLE_TCP_SERVER,
181 CONF_SYSLOG_IDENTITY,
182 CONF_SYSLOG_FACILITY,
183 //CONF_IPT_EXEC_TRIES,
184 //CONF_ENABLE_EXTERNAL_CMDS,
185 //CONF_EXTERNAL_CMD_OPEN,
186 //CONF_EXTERNAL_CMD_CLOSE,
187 //CONF_EXTERNAL_CMD_ALARM,
188 //CONF_ENABLE_EXT_CMD_PREFIX,
189 //CONF_EXT_CMD_PREFIX,
190 #if FIREWALL_IPTABLES
191 CONF_ENABLE_IPT_FORWARDING,
192 CONF_ENABLE_IPT_LOCAL_NAT,
193 CONF_ENABLE_IPT_SNAT,
194 CONF_SNAT_TRANSLATE_IP,
195 CONF_ENABLE_IPT_OUTPUT,
196 CONF_FLUSH_IPT_AT_INIT,
197 CONF_FLUSH_IPT_AT_EXIT,
198 CONF_IPT_INPUT_ACCESS,
199 CONF_IPT_OUTPUT_ACCESS,
200 CONF_IPT_FORWARD_ACCESS,
201 CONF_IPT_DNAT_ACCESS,
202 CONF_IPT_SNAT_ACCESS,
203 CONF_IPT_MASQUERADE_ACCESS,
205 CONF_FLUSH_IPFW_AT_INIT,
206 CONF_FLUSH_IPFW_AT_EXIT,
207 CONF_IPFW_START_RULE_NUM,
209 CONF_IPFW_ACTIVE_SET_NUM,
210 CONF_IPFW_EXPIRE_SET_NUM,
211 CONF_IPFW_EXPIRE_PURGE_INTERVAL,
212 CONF_IPFW_ADD_CHECK_STATE,
215 CONF_PF_EXPIRE_INTERVAL,
217 /* --DSS Place-holder */
218 #endif /* FIREWALL type */
220 CONF_FWKNOP_CONF_DIR,
222 CONF_FWKNOP_PID_FILE,
231 NUMBER_OF_CONFIG_ENTRIES /* Marks the end and number of entries */
234 /* A simple linked list of uints for the access stanza items that allow
235 * multiple comma-separated entries.
237 typedef struct acc_int_list
241 struct acc_int_list *next;
244 /* A simple linked list of proto and ports for the access stanza items that
245 * allow multiple comma-separated entries.
247 typedef struct acc_port_list
251 struct acc_port_list *next;
254 /* A simple linked list of strings for the access stanza items that
255 * allow multiple comma-separated entries.
257 typedef struct acc_string_list
260 struct acc_string_list *next;
263 /* Access stanza list struct.
265 typedef struct acc_stanza
268 acc_int_list_t *source_list;
270 acc_port_list_t *oport_list;
271 char *restrict_ports;
272 acc_port_list_t *rport_list;
274 int fw_access_timeout;
275 unsigned char enable_cmd_exec;
278 char *require_username;
279 unsigned char require_source_address;
281 char *gpg_decrypt_id;
282 char *gpg_decrypt_pw;
283 unsigned char gpg_require_sig;
284 unsigned char gpg_ignore_sig_error;
286 acc_string_list_t *gpg_remote_id_list;
287 time_t access_expire_time;
289 unsigned char force_nat;
291 char *force_nat_proto;
292 unsigned int force_nat_port;
293 struct acc_stanza *next;
297 /* Firewall-related data and types. */
299 #if FIREWALL_IPTABLES
300 /* --DSS XXX: These are arbitrary. We should determine appropriate values.
302 #define MAX_TABLE_NAME_LEN 64
303 #define MAX_CHAIN_NAME_LEN 64
304 #define MAX_TARGET_NAME_LEN 64
306 /* Fwknop custom chain types
314 IPT_MASQUERADE_ACCESS,
315 NUM_FWKNOP_ACCESS_TYPES /* Leave this entry last */
318 /* Structure to define an fwknop firewall chain configuration.
322 char target[MAX_TARGET_NAME_LEN];
324 char table[MAX_TABLE_NAME_LEN];
325 char from_chain[MAX_CHAIN_NAME_LEN];
327 char to_chain[MAX_CHAIN_NAME_LEN];
333 /* Based on the fw_chain fields (not counting type)
335 #define FW_NUM_CHAIN_FIELDS 6
338 struct fw_chain chain[NUM_FWKNOP_ACCESS_TYPES];
339 char fw_command[MAX_PATH_LEN];
345 unsigned short start_rule_num;
346 unsigned short max_rules;
347 unsigned short active_rules;
348 unsigned short total_rules;
349 unsigned short active_set_num;
350 unsigned short expire_set_num;
351 unsigned short purge_interval;
352 unsigned char *rule_map;
355 char fw_command[MAX_PATH_LEN];
360 #define MAX_PF_ANCHOR_LEN 64
363 unsigned short active_rules;
365 char anchor[MAX_PF_ANCHOR_LEN];
366 char fw_command[MAX_PATH_LEN];
371 /* --DSS Place-holder */
373 #endif /* FIREWALL type */
375 /* SPA Packet info struct.
377 typedef struct spa_pkt_info
379 unsigned int packet_data_len;
380 unsigned int packet_proto;
381 unsigned int packet_src_ip;
382 unsigned int packet_dst_ip;
383 unsigned short packet_src_port;
384 unsigned short packet_dst_port;
385 unsigned char packet_data[MAX_SPA_PACKET_LEN+1];
388 /* Struct for (processed and verified) SPA data used by the server.
390 typedef struct spa_data
397 char spa_message_src_ip[MAX_IPV4_STR_LEN];
398 char pkt_source_ip[MAX_IPV4_STR_LEN];
399 char spa_message_remain[1024]; /* --DSS FIXME: arbitrary bounds */
402 unsigned int client_timeout;
403 unsigned int fw_access_timeout;
407 /* fwknopd server configuration parameters and values
409 typedef struct fko_srv_options
411 /* The command-line options or flags that invoke an immediate response
414 unsigned char dump_config; /* Dump current configuration flag */
415 unsigned char foreground; /* Run in foreground flag */
416 unsigned char kill; /* flag to initiate kill of fwknopd */
417 unsigned char rotate_digest_cache;/* flag to force rotation of digest */
418 unsigned char restart; /* Restart fwknopd flag */
419 unsigned char status; /* Get fwknopd status flag */
420 unsigned char fw_list; /* List current firewall rules */
421 unsigned char fw_list_all; /* List all current firewall rules */
422 unsigned char fw_flush; /* Flush current firewall rules */
423 unsigned char test; /* Test mode flag */
424 unsigned char verbose; /* Verbose mode flag */
426 int data_link_offset;
431 struct digest_cache_list *digest_cache; /* In-memory digest cache list */
434 spa_pkt_info_t spa_pkt; /* The current SPA packet */
436 /* Counter set from the command line to exit after the specified
437 * number of SPA packets are processed.
439 unsigned int packet_ctr_limit;
440 unsigned int packet_ctr; /* counts packets with >0 payload bytes */
442 /* This array holds all of the config file entry values as strings
443 * indexed by their tag name.
445 char *config[NUMBER_OF_CONFIG_ENTRIES];
447 acc_stanza_t *acc_stanzas; /* List of access stanzas */
449 /* Firewall config info.
451 struct fw_config *fw_config;
455 extern fko_srv_options_t options;
457 /* For cleaning up memory before exiting
460 #define NO_FW_CLEANUP 0
461 void clean_exit(fko_srv_options_t *opts, unsigned int fw_cleanup_flag, unsigned int exit_status);
463 #endif /* FWKNOPD_COMMON_H */