require '_h2ph_pre.ph';

no warnings qw(redefine misc);

unless(defined(&_NETMPLS_MPLS_H_)) {
    eval 'sub _NETMPLS_MPLS_H_ () {1;}' unless defined(&_NETMPLS_MPLS_H_);
    require 'sys/param.ph';
    require 'sys/time.ph';
    require 'sys/proc.ph';
    require 'sys/queue.ph';
    require 'net/if.ph';
    require 'net/if_dl.ph';
    eval 'sub MPLS_LABEL_MAX () {((1<< 20) - 1);}' unless defined(&MPLS_LABEL_MAX);
    eval 'sub MPLS_HDRLEN () {$sizeof{\'struct shim_hdr\'};}' unless defined(&MPLS_HDRLEN);
    if(defined(&_KERNEL)) {
	eval 'sub __MADDR {
	    my($x) = @_;
    	    eval q((( &u_int32_t) &htonl(( &u_int32_t)($x))));
	}' unless defined(&__MADDR);
    } else {
	eval 'sub __MADDR {
	    my($x) = @_;
    	    eval q((( &u_int32_t)($x)));
	}' unless defined(&__MADDR);
    }
    eval 'sub MPLS_LABEL_MASK () { &__MADDR(0xfffff000);}' unless defined(&MPLS_LABEL_MASK);
    eval 'sub MPLS_LABEL_OFFSET () {12;}' unless defined(&MPLS_LABEL_OFFSET);
    eval 'sub MPLS_EXP_MASK () { &__MADDR(0xe00);}' unless defined(&MPLS_EXP_MASK);
    eval 'sub MPLS_EXP_OFFSET () {9;}' unless defined(&MPLS_EXP_OFFSET);
    eval 'sub MPLS_BOS_MASK () { &__MADDR(0x100);}' unless defined(&MPLS_BOS_MASK);
    eval 'sub MPLS_BOS_OFFSET () {8;}' unless defined(&MPLS_BOS_OFFSET);
    eval 'sub MPLS_TTL_MASK () { &__MADDR(0xff);}' unless defined(&MPLS_TTL_MASK);
    eval 'sub MPLS_BOS_ISSET {
        my($l) = @_;
	    eval q(((($l) &  &MPLS_BOS_MASK) ==  &MPLS_BOS_MASK));
    }' unless defined(&MPLS_BOS_ISSET);
    eval 'sub MPLS_LABEL_IPV4NULL () {0;}' unless defined(&MPLS_LABEL_IPV4NULL);
    eval 'sub MPLS_LABEL_RTALERT () {1;}' unless defined(&MPLS_LABEL_RTALERT);
    eval 'sub MPLS_LABEL_IPV6NULL () {2;}' unless defined(&MPLS_LABEL_IPV6NULL);
    eval 'sub MPLS_LABEL_IMPLNULL () {3;}' unless defined(&MPLS_LABEL_IMPLNULL);
    eval 'sub MPLS_LABEL_RESERVED_MAX () {15;}' unless defined(&MPLS_LABEL_RESERVED_MAX);
    eval 'sub MPLS_OP_LOCAL () {0x;}' unless defined(&MPLS_OP_LOCAL);
    eval 'sub MPLS_OP_POP () {0x1;}' unless defined(&MPLS_OP_POP);
    eval 'sub MPLS_OP_PUSH () {0x2;}' unless defined(&MPLS_OP_PUSH);
    eval 'sub MPLS_OP_SWAP () {0x4;}' unless defined(&MPLS_OP_SWAP);
    eval 'sub MPLS_INKERNEL_LOOP_MAX () {16;}' unless defined(&MPLS_INKERNEL_LOOP_MAX);
    eval 'sub satosmpls {
        my($sa) = @_;
	    eval q((($sa)));
    }' unless defined(&satosmpls);
    eval 'sub smplstosa {
        my($smpls) = @_;
	    eval q((($smpls)));
    }' unless defined(&smplstosa);
    eval 'sub MPLSCTL_ENABLE () {1;}' unless defined(&MPLSCTL_ENABLE);
    eval 'sub MPLSCTL_DEFTTL () {2;}' unless defined(&MPLSCTL_DEFTTL);
    eval 'sub MPLSCTL_IFQUEUE () {3;}' unless defined(&MPLSCTL_IFQUEUE);
    eval 'sub MPLSCTL_MAXINKLOOP () {4;}' unless defined(&MPLSCTL_MAXINKLOOP);
    eval 'sub MPLSCTL_MAPTTL_IP () {5;}' unless defined(&MPLSCTL_MAPTTL_IP);
    eval 'sub MPLSCTL_MAPTTL_IP6 () {6;}' unless defined(&MPLSCTL_MAPTTL_IP6);
    eval 'sub MPLSCTL_MAXID () {7;}' unless defined(&MPLSCTL_MAXID);
    eval 'sub MPLSCTL_NAMES () {{ { 0, 0}, { "enable",  &CTLTYPE_INT }, { "ttl",  &CTLTYPE_INT }, { "ifq",  &CTLTYPE_NODE }, { "maxloop_inkernel",  &CTLTYPE_INT }, { "mapttl_ip",  &CTLTYPE_INT }, { "mapttl_ip6",  &CTLTYPE_INT }, };}' unless defined(&MPLSCTL_NAMES);
    eval 'sub MPLSCTL_VARS () {{ 0,  &mpls_enable,  &mpls_defttl, 0,  &mpls_inkloop,  &mpls_mapttl_ip,  &mpls_mapttl_ip6, };}' unless defined(&MPLSCTL_VARS);
}
if(defined(&_KERNEL)) {
    eval 'sub MPE_HDRLEN () {$sizeof{\'struct shim_hdr\'};}' unless defined(&MPE_HDRLEN);
    eval 'sub MPE_MTU () {1500;}' unless defined(&MPE_MTU);
    eval 'sub MPE_MTU_MIN () {256;}' unless defined(&MPE_MTU_MIN);
    eval 'sub MPE_MTU_MAX () {8192;}' unless defined(&MPE_MTU_MAX);
}
1;
