Unrecognized option AF_INET

How to customize and extend your OpenVPN installation.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Post Reply
superdimitri
OpenVpn Newbie
Posts: 4
Joined: Tue Oct 24, 2017 10:13 pm

Unrecognized option AF_INET

Post by superdimitri » Tue Oct 24, 2017 10:40 pm

Hi, new user here! I hope maybe someone with more knowledge with OpenVPN can help me!

Platform: Tomato v1.28.0000 -2017.2-kille72- K26ARM USB AIO-64K.
Netgear R7000 router.

I am trying to call an script by using cmd --ipchange in my config.

My config:

Code: Select all

# Automatically generated configuration
daemon
client
dev tun11
proto udp
remote nl.myvpnserver 1198
resolv-retry 30
nobind
persist-key
persist-tun
comp-lzo adaptive
ncp-ciphers AES-128-GCM:AES-256-GCM:AES-128-CBC:AES-256-CBC
cipher AES-128-CBC
redirect-gateway def1
verb 3
script-security 2
up updown.sh
down updown.sh
ca ca.crt
status-version 2
status status

# Custom Configuration
syslog [progname]
persist-key
persist-tun
tls-client
auth-user-pass /tmp/password.txt
comp-lzo
verb 3
reneg-sec 0
ipchange "/etc/openvpn/test.sh"
script-security 3
My test.sh script:

Code: Select all

#!/opt/bin/bash
#
# Enable port forwarding when using Private Internet Access
#
# Usage:
#  ./port_forwarding.sh
set -x
exec 2>/etc/openvpn/mylog

TRANSUSER=myusername
TRANSPASS=mypass
TRANSHOST=my host ip

/bin/echo waiting 20s for vpn to connect and trasmission to start
sleep 20

error( )
{
  /bin/echo "$@" 1>&2
  exit 1
}

error_and_usage( )
{
  /bin/echo "$@" 1>&2
  usage_and_exit 1
}

usage( )
{
  /bin/echo "Usage: `dirname $0`/$PROGRAM"
}

usage_and_exit( )
{
  usage
  exit $1
}

version( )
{
  /bin/echo "$PROGRAM version $VERSION"
}


port_forward_assignment( )
{
  client_id_file="/etc/openvpn/pia_client_id"
  if [ ! -f "$client_id_file" ]; then
    if hash /opt/bin/shasum 2>/dev/null; then
      /usr/bin/head -n 100 /dev/urandom | /opt/bin/shasum -a 256 | tr -d " -" > "$client_id_file"
    elif hash /opt/bin/sha256sum 2>/dev/null; then
      /usr/bin/head -n 100 /dev/urandom | /opt/bin/sha256sum | tr -d " -" > "$client_id_file"
    else
      /bin/echo "Please install shasum or sha256sum, and make sure it is visible in your \$PATH"
      exit 1
    fi
  fi
  client_id=`/bin/cat "$client_id_file"`
  json=`/opt/bin/curl "piaurl>/dev/null`
  if [ "$json" == "" ]; then
    json='Port forwarding is already activated on this connection, has expired, or you are not connected to a PIA region that supports port forwarding'
  fi

  /bin/echo server returned message: $json

#trim VPN forwarded port from JSON
PORT=$(echo $json | /usr/bin/awk 'BEGIN{r=1;FS="[{}\":]+"} /port/{r=0; print $3} END{exit r}')
/bin/echo if succesful port is:$PORT  

#change transmission port on the fly

/opt/bin/transmission-remote $TRANSHOST --auth $TRANSUSER:$TRANSPASS -p "$PORT"
/bin/echo your transmission details: $TRANSHOST $TRANSUSER $TRANSPASS
}

/bin/echo remember to reconnect to VPN before running this script. Run no longer than 2 minutes after connection or this will fail!

EXITCODE=0
PROGRAM=`basename $0`
VERSION=2.1

while /usr/bin/test $# -gt 0
do
  case $1 in
  --usage | --help | -h )
    usage_and_exit 0
    ;;
  --version | -v )
    version
    exit 0
    ;;
  *)
    error_and_usage "Unrecognized option: $1"
    ;;
  esac
  shift
done

port_forward_assignment

exit 0
My output from log my debug log:

Code: Select all

+ TRANSUSER=myuser
+ TRANSPASS=mypass
+ TRANSHOST=myhost
+ /bin/echo waiting 20s for vpn to connect and trasmission to start
+ sleep 20
+ /bin/echo remember to reconnect to VPN before running this script. Run no longer than 2 minutes after connection or this will 'fail!'
+ EXITCODE=0
++ basename /etc/openvpn/test.sh
+ PROGRAM=test.sh
+ VERSION=2.1
+ /usr/bin/test 1 -gt 0
+ case $1 in
+ error_and_usage 'Unrecognized option: [AF_INET]46.166.138.167 1198'
+ /bin/echo 'Unrecognized option: [AF_INET]46.166.138.167 1198'
Unrecognized option: [AF_INET]46.166.138.167 1198
+ usage_and_exit 1
+ usage
++ dirname /etc/openvpn/test.sh
+ /bin/echo 'Usage: /etc/openvpn/test.sh'
+ exit 1
My output from openvpn log:

Code: Select all

R7000 daemon.warn openvpn[12538]: WARNING: Failed running command (--ipchange): external program exited with error status: 1
My goal is to set this script to request and receive a port number from private internet access' port forward API JSON. I then forward the returned port number to transmission client.

My script works fine with ./test.sh and bash -x test.sh from SSH console, just not when running vpn.

Seems like the error is related to the IP and port of the VPN server I am connecting too, however I cannot find which part of this relates to my script? Does anyone know?

Code: Select all

Unrecognized option: [AF_INET]46.166.138.167 1198
I am a newbie to linux, this will be my first shell script and is mostly just a collection of other scripts and help I have found elsewhere online, thank you for any help you can give!

I have read the man and FAQ on the website and I'm running out of ideas!

TinCanTech
OpenVPN Protagonist
Posts: 11137
Joined: Fri Jun 03, 2016 1:17 pm

Re: Unrecognized option AF_INET

Post by TinCanTech » Thu Oct 26, 2017 10:47 am

superdimitri wrote:
Tue Oct 24, 2017 10:40 pm

My output from log my debug log:

Code: Select all

+ error_and_usage 'Unrecognized option: [AF_INET]46.166.138.167 1198'
+ /bin/echo 'Unrecognized option: [AF_INET]46.166.138.167 1198'
Unrecognized option: [AF_INET]46.166.138.167 1198
+ usage_and_exit 1
+ usage
++ dirname /etc/openvpn/test.sh
+ /bin/echo 'Usage: /etc/openvpn/test.sh'
+ exit 1
My output from openvpn log:

Code: Select all

R7000 daemon.warn openvpn[12538]: WARNING: Failed running command (--ipchange): external program exited with error status: 1
From your script log you can see that the script exited with "exit 1" which openvpn interprets as the script failed and then openvpn logs that for you.

By the look of your script error:

Code: Select all

Unrecognized option: [AF_INET]46.166.138.167 1198
I would say that you are not extracting the port number correctly.

superdimitri
OpenVpn Newbie
Posts: 4
Joined: Tue Oct 24, 2017 10:13 pm

Re: Unrecognized option AF_INET

Post by superdimitri » Thu Oct 26, 2017 4:31 pm

Thanks for your reply!
TinCanTech wrote:
Thu Oct 26, 2017 10:47 am
I would say that you are not extracting the port number correctly.
But the odd thing is the script works fine if I run it from terminal:

test.sh outputs:

Code: Select all

root@R7000:/tmp/etc/openvpn# test.sh
+ exec
waiting 20s for vpn to connect and trasmission to start
remember to reconnect to VPN before running this script. Run no longer than 2 minutes after connection or this will fail!
server returned message: {"port":44257}
if successful port is:44257
xxx.xxx.x.xxx:1198/transmission/rpc/ responded: "success"
your transmission details: myhost myuser mypass
bash -x test.sh outputs:

Code: Select all

root@R7000:/tmp/etc/openvpn# bash -x test.sh
+ set -x
+ exec
waiting 20s for vpn to connect and trasmission to start
remember to reconnect to VPN before running this script. Run no longer than 2 minutes after connection or this will fail!
server returned message: {"port":44257}
if successful port is:44257
xxx.xxx.x.xxx:1198/transmission/rpc/ responded: "success"
your transmission details: myhost myuser mypass
And

Code: Select all

Unrecognized option: [AF_INET]xx.xxx.xxx.xxx 1198
is the server address and port set in my client..not the forwarded port from my VPN and nothing to do with the returned JSON.

So I'm confused!

TinCanTech
OpenVPN Protagonist
Posts: 11137
Joined: Fri Jun 03, 2016 1:17 pm

Re: Unrecognized option AF_INET

Post by TinCanTech » Fri Oct 27, 2017 12:03 pm

All I can tell you is that openvpn is running the script and script returns error 1.

If you want me to debug your script you can contact me on tincanteksup <at> gmail

superdimitri
OpenVpn Newbie
Posts: 4
Joined: Tue Oct 24, 2017 10:13 pm

Re: Unrecognized option AF_INET

Post by superdimitri » Tue Oct 31, 2017 2:44 am

I sent you an email

TinCanTech
OpenVPN Protagonist
Posts: 11137
Joined: Fri Jun 03, 2016 1:17 pm

Re: Unrecognized option AF_INET

Post by TinCanTech » Tue Oct 31, 2017 11:26 am

The reason that json is empty is because curl fails.

The reason that curl fails is because; as a security measure (therefore by design), OpenVPN will not allow any packets to traverse the tunnel while any script which was started by the openvpn binary is still executing.

You will need to find another method to invoke your script.

Post Reply