#!/usr/bin/pfsh

#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright 2016 OmniTI Computer Consulting, Inc. All rights reserved.
#

#
# in.iked used to be a hard link to "isaexec", but thanks to its closed-source
# and recent discoveries about amplification attacks, we need to instead
# put a wrapper around the actual executables and LD_PRELOAD an interposer to
# __xnet_sendmsg to rate-limit messages.
#

# First determine the right in.iked binary.
EXECDIR=`/usr/bin/dirname $0`
ISA=`/usr/bin/isainfo -k`

if [ $ISA = "i386" ]; then
    ISADIR="i86"
else
    # Should work for "amd64", "sparc", and "sparcv9".
    ISADIR=$ISA
fi

# Then set up LD_PRELOAD to interpose on __xnet_sendmsg().
if [ -e $LD_PRELOAD ]; then
    LD_PRELOAD=libRLike.so
else
    LD_PRELOAD="libRLike.so $LD_PRELOAD"
fi

export LD_PRELOAD

# echo "LD_PRELOAD is " $LD_PRELOAD
# echo "Would execute $EXECDIR/$ISADIR/in.iked"
exec $EXECDIR/$ISADIR/in.iked
