require '_h2ph_pre.ph';

no warnings qw(redefine misc);

unless(defined(&_NET_IF_IPSEC_H_)) {
    eval 'sub _NET_IF_IPSEC_H_ () {1;}' unless defined(&_NET_IF_IPSEC_H_);
    require 'sys/queue.ph';
    if(defined(&_KERNEL)) {
	require 'sys/pserialize.ph';
	require 'sys/psref.ph';
    }
    if(defined(&_KERNEL_OPT)) {
	require './net/opt_inet.ph';
    }
    require 'netinet/in.ph';
    require 'netipsec/ipsec.ph';
    if(defined(&_KERNEL)) {
	unless(defined(&MAX_IPSEC_NEST)) {
	    eval 'sub MAX_IPSEC_NEST () {1;}' unless defined(&MAX_IPSEC_NEST);
	}
	eval 'sub IFF_NAT_T () { &IFF_LINK0;}' unless defined(&IFF_NAT_T);
	eval 'sub IFF_ECN () { &IFF_LINK1;}' unless defined(&IFF_ECN);
	eval 'sub IFF_FWD_IPV6 () { &IFF_LINK2;}' unless defined(&IFF_FWD_IPV6);
	eval 'sub IPSEC_MTU () {(1280);}' unless defined(&IPSEC_MTU);
	eval 'sub IPSEC_MTU_MIN () {(1280);}' unless defined(&IPSEC_MTU_MIN);
	eval 'sub IPSEC_MTU_MAX () {(8192);}' unless defined(&IPSEC_MTU_MAX);
	eval 'sub IV_SP_IN {
	    my($x) = @_;
    	    eval q((($x)-> $iv_sp[ &IPSEC_DIR_INBOUND]));
	}' unless defined(&IV_SP_IN);
	eval 'sub IV_SP_IN6 {
	    my($x) = @_;
    	    eval q((($x)-> $iv_sp6[ &IPSEC_DIR_INBOUND]));
	}' unless defined(&IV_SP_IN6);
	eval 'sub IV_SP_OUT {
	    my($x) = @_;
    	    eval q((($x)-> $iv_sp[ &IPSEC_DIR_OUTBOUND]));
	}' unless defined(&IV_SP_OUT);
	eval 'sub IV_SP_OUT6 {
	    my($x) = @_;
    	    eval q((($x)-> $iv_sp6[ &IPSEC_DIR_OUTBOUND]));
	}' unless defined(&IV_SP_OUT6);
	eval 'sub if_ipsec_variant_is_configured {
	    my($var) = @_;
    	    eval q({ ( ($var->{iv_psrc}) !=  &NULL  &&  ($var->{iv_pdst}) !=  &NULL); });
	}' unless defined(&if_ipsec_variant_is_configured);
	eval 'sub if_ipsec_variant_is_unconfigured {
	    my($var) = @_;
    	    eval q({ ( ($var->{iv_psrc}) ==  &NULL ||  ($var->{iv_pdst}) ==  &NULL); });
	}' unless defined(&if_ipsec_variant_is_unconfigured);
	eval 'sub if_ipsec_copy_variant {
	    my($dst,$src) = @_;
    	    eval q({  ($dst->{iv_softc}) =  ($src->{iv_softc});  ($dst->{iv_psrc}) =  ($src->{iv_psrc});  ($dst->{iv_pdst}) =  ($src->{iv_pdst});  ($dst->{iv_encap_cookie4}) =  ($src->{iv_encap_cookie4});  ($dst->{iv_encap_cookie6}) =  ($src->{iv_encap_cookie6});  ($dst->{iv_output}) =  ($src->{iv_output});  ($dst->{iv_sport}) =  ($src->{iv_sport});  ($dst->{iv_dport}) =  ($src->{iv_dport}); });
	}' unless defined(&if_ipsec_copy_variant);
	eval 'sub if_ipsec_clear_config {
	    my($var) = @_;
    	    eval q({  ($var->{iv_psrc}) =  &NULL;  ($var->{iv_pdst}) =  &NULL;  ($var->{iv_encap_cookie4}) =  &NULL;  ($var->{iv_encap_cookie6}) =  &NULL;  ($var->{iv_output}) =  &NULL;  ($var->{iv_sport}) = 0;  ($var->{iv_dport}) = 0; });
	}' unless defined(&if_ipsec_clear_config);
	eval 'sub if_ipsec_putref_variant {
	    my($var,$psref) = @_;
    	    eval q({  &KASSERT($var !=  &NULL);  &psref_release($psref,  ($var->{iv_psref}),  &iv_psref_class); });
	}' unless defined(&if_ipsec_putref_variant);
	eval 'sub if_ipsec_heldref_variant {
	    my($var) = @_;
    	    eval q({  &psref_held( ($var->{iv_psref}),  &iv_psref_class); });
	}' unless defined(&if_ipsec_heldref_variant);
    }
}
1;
