// $Id: NetVar.cc,v 1.82 2003/08/31 00:38:11 vern Exp $
//
// Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
//      The Regents of the University of California.  All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that: (1) source code distributions
// retain the above copyright notice and this paragraph in its entirety, (2)
// distributions including binary code include the above copyright notice and
// this paragraph in its entirety in the documentation or other materials
// provided with the distribution, and (3) all advertising materials mentioning
// features or use of this software display the following acknowledgement:
// ``This product includes software developed by the University of California,
// Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
// the University nor the names of its contributors may be used to endorse
// or promote products derived from this software without specific prior
// written permission.
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.

#include "config.h"

#include "Var.h"
#include "NetVar.h"

RecordType* conn_id;
RecordType* endpoint;
RecordType* endpoint_stats;
RecordType* connection_type;
RecordType* icmp_conn;
RecordType* icmp_context;
RecordType* SYN_packet;
RecordType* signature_state;

RecordType* net_stats;

int watchdog_interval;
double heartbeat_interval;

int max_timer_expires;

int ignore_checksums;
int partial_connection_ok;
int tcp_SYN_ack_ok;
int tcp_match_undelivered;

double frag_timeout;

double tcp_SYN_timeout;
double tcp_session_timer;
double tcp_connection_linger;
double tcp_attempt_delay;
double tcp_close_delay;
double tcp_reset_delay;
double tcp_partial_close_delay;

double non_analyzed_lifetime;
double default_inactivity_timeout;

int tcp_storm_thresh;
double tcp_storm_interarrival_thresh;

TableVal* tcp_reassembler_ports_orig;
TableVal* tcp_reassembler_ports_resp;

double dns_session_timeout;
double ntp_session_timeout;
double rpc_timeout;

ListVal* skip_authentication;
ListVal* direct_login_prompts;
ListVal* login_prompts;
ListVal* login_non_failure_msgs;
ListVal* login_failure_msgs;
ListVal* login_success_msgs;
ListVal* login_timeouts;

int mime_segment_length;
int mime_segment_overlap_length;
RecordType* mime_header_rec;
TableType* mime_header_list;

int http_entity_data_delivery_size;
RecordType* http_stats_rec;
RecordType* http_message_stat;

int pm_request;
RecordType* pm_mapping;
TableType* pm_mappings;
RecordType* pm_port_request;
RecordType* pm_callit_request;

RecordType* ntp_msg;

TableVal* samba_cmds;

RecordType* dns_msg;
RecordType* dns_answer;
RecordType* dns_soa;
TableVal* dns_skip_auth;
TableVal* dns_skip_addl;

double stp_delta;
double stp_idle_min;

double interconn_min_interarrival;
double interconn_max_interarrival;
int interconn_max_keystroke_pkt_size;
int interconn_default_pkt_size;
double interconn_stat_period;
double interconn_stat_backoff;
RecordType* interconn_endp_stats;

double backdoor_stat_period;
double backdoor_stat_backoff;

RecordType* backdoor_endp_stats;

RecordType* software;
RecordType* software_version;

double table_expire_interval;

RecordType* packet_type;

double packet_sort_window;

double connection_status_update_interval;

StringVal* state_file;

int orig_addr_anonymization, resp_addr_anonymization;

#include "const.bif.netvar_def"
#include "event.bif.netvar_def"

void init_net_var()
	{
#include "const.bif.netvar_init"
#include "event.bif.netvar_init"

	conn_id = internal_type("conn_id")->AsRecordType();
	endpoint = internal_type("endpoint")->AsRecordType();
	endpoint_stats = internal_type("endpoint_stats")->AsRecordType();
	connection_type = internal_type("connection")->AsRecordType();
	icmp_conn = internal_type("icmp_conn")->AsRecordType();
	icmp_context = internal_type("icmp_context")->AsRecordType();
	signature_state = internal_type("signature_state")->AsRecordType();
	SYN_packet = internal_type("SYN_packet")->AsRecordType();

	ignore_checksums = opt_internal_int("ignore_checksums");
	partial_connection_ok = opt_internal_int("partial_connection_ok");
	tcp_SYN_ack_ok = opt_internal_int("tcp_SYN_ack_ok");
	tcp_match_undelivered = opt_internal_int("tcp_match_undelivered");

	frag_timeout = opt_internal_double("frag_timeout");

	tcp_SYN_timeout = opt_internal_double("tcp_SYN_timeout");
	tcp_session_timer = opt_internal_double("tcp_session_timer");
	tcp_connection_linger = opt_internal_double("tcp_connection_linger");
	tcp_attempt_delay = opt_internal_double("tcp_attempt_delay");
	tcp_close_delay = opt_internal_double("tcp_close_delay");
	tcp_reset_delay = opt_internal_double("tcp_reset_delay");
	tcp_partial_close_delay = opt_internal_double("tcp_partial_close_delay");

	non_analyzed_lifetime = opt_internal_double("non_analyzed_lifetime");
	default_inactivity_timeout = opt_internal_double("inactivity_timeout");

	tcp_storm_thresh = opt_internal_int("tcp_storm_thresh");
	tcp_storm_interarrival_thresh =
		opt_internal_double("tcp_storm_interarrival_thresh");

	tcp_reassembler_ports_orig =
		internal_val("tcp_reassembler_ports_orig")->AsTableVal();
	tcp_reassembler_ports_resp =
		internal_val("tcp_reassembler_ports_resp")->AsTableVal();

	dns_session_timeout = opt_internal_double("dns_session_timeout");
	ntp_session_timeout = opt_internal_double("ntp_session_timeout");
	rpc_timeout = opt_internal_double("rpc_timeout");

	net_stats = internal_type("net_stats")->AsRecordType();

	watchdog_interval = int(opt_internal_double("watchdog_interval"));
	heartbeat_interval = opt_internal_double("heartbeat_interval");

	max_timer_expires = opt_internal_int("max_timer_expires");

	skip_authentication = internal_list_val("skip_authentication");
	direct_login_prompts = internal_list_val("direct_login_prompts");
	login_prompts = internal_list_val("login_prompts");
	login_non_failure_msgs = internal_list_val("login_non_failure_msgs");
	login_failure_msgs = internal_list_val("login_failure_msgs");
	login_success_msgs = internal_list_val("login_success_msgs");
	login_timeouts = internal_list_val("login_timeouts");

	mime_segment_length = opt_internal_int("mime_segment_length");
	mime_segment_overlap_length = opt_internal_int("mime_segment_overlap_length");
	mime_header_rec = internal_type("mime_header_rec")->AsRecordType();
	mime_header_list = internal_type("mime_header_list")->AsTableType();

	http_entity_data_delivery_size = opt_internal_int("http_entity_data_delivery_size");
	http_stats_rec = internal_type("http_stats_rec")->AsRecordType();
	http_message_stat = internal_type("http_message_stat")->AsRecordType();

	pm_request = pm_request_null || pm_request_set ||
		pm_request_unset || pm_request_getport ||
		pm_request_dump || pm_request_callit ||
		pm_attempt_null || pm_attempt_set ||
		pm_attempt_unset || pm_attempt_getport ||
		pm_attempt_dump || pm_attempt_callit ||
		pm_bad_port;

	pm_mapping = internal_type("pm_mapping")->AsRecordType();
	pm_mappings = internal_type("pm_mappings")->AsTableType();
	pm_port_request = internal_type("pm_port_request")->AsRecordType();
	pm_callit_request = internal_type("pm_callit_request")->AsRecordType();

	ntp_msg = internal_type("ntp_msg")->AsRecordType();

	samba_cmds = internal_val("samba_cmds")->AsTableVal();

	dns_msg = internal_type("dns_msg")->AsRecordType();
	dns_answer = internal_type("dns_answer")->AsRecordType();
	dns_soa = internal_type("dns_soa")->AsRecordType();

	dns_skip_auth = internal_val("dns_skip_auth")->AsTableVal();
	dns_skip_addl = internal_val("dns_skip_addl")->AsTableVal();

	stp_delta = opt_internal_double("stp_delta");
	stp_idle_min = opt_internal_double("stp_idle_min");

	interconn_min_interarrival = opt_internal_double("interconn_min_interarrival");
	interconn_max_interarrival = opt_internal_double("interconn_max_interarrival");
	interconn_max_keystroke_pkt_size = opt_internal_int("interconn_max_keystroke_pkt_size");
	interconn_default_pkt_size = opt_internal_int("interconn_default_pkt_size");
	interconn_stat_period = opt_internal_double("interconn_stat_period");
	interconn_stat_backoff = opt_internal_double("interconn_stat_backoff");
	interconn_endp_stats = internal_type("interconn_endp_stats")->AsRecordType();

	backdoor_stat_period = opt_internal_double("backdoor_stat_period");
	backdoor_stat_backoff = opt_internal_double("backdoor_stat_backoff");
	backdoor_endp_stats = internal_type("backdoor_endp_stats")->AsRecordType();

	software = internal_type("software")->AsRecordType();
	software_version = internal_type("software_version")->AsRecordType();;

	table_expire_interval = opt_internal_double("table_expire_interval");

	packet_type = internal_type("packet")->AsRecordType();

	packet_sort_window = opt_internal_double("packet_sort_window");

	orig_addr_anonymization = opt_internal_int("orig_addr_anonymization");
	resp_addr_anonymization = opt_internal_int("resp_addr_anonymization");

	connection_status_update_interval = opt_internal_double("connection_status_update_interval");

	state_file = internal_val("state_file")->AsStringVal();
	}
