incubator-nuttx/tools/simhostroute.sh

83 lines
2.6 KiB
Bash
Raw Normal View History

simulator network host route helper script and docs Squashed commit of the following: commit 685951b5385062035ac558df1112353c9441c910 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 16:33:00 2020 -0800 fixed typo in readme commit ad1d3289b48af0de3095e3f365429017e57278b3 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 16:07:48 2020 -0800 simulator host route helper script and docs Squashed commit of the following: commit cf5cddcf55a155303cb5abb1aa026f6dcaf369ca Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 15:50:40 2020 -0800 syslog on console to fix compile error commit def1bb73fcfbc8b115c55d9f4544b97d583807f2 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 15:46:13 2020 -0800 formatting as per PR feedback; removed ping commit b179fd8831b77fbbe85527a4ab3161e1f1ca1e43 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 15:45:49 2020 -0800 formatting as per PR feedback commit e3280bede9798d9a00b118e126c02ceab497e33a Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 13:56:50 2020 -0800 add simhostroute.sh description to readme commit 09a6b0ca3bacf005c2a79102141ae8cc3eb91849 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:38:40 2020 -0800 fixed error in simhostroute.sh usage docs commit d838582119d43ee2002ce3808051c82b23e98c58 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:28:35 2020 -0800 added tcpblaster defconfig and updated docs commit af3d2d6591f12d1127027fdd363858052094e624 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:21:29 2020 -0800 added info about capabilities and running as root commit 6359cfdfedefc818b169455401942d3d33a59f41 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:20:42 2020 -0800 updated network linux readme commit 47feb08aa74e4b1fc6c802567bc777d31e7c9a83 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:09:04 2020 -0800 initial addition
2020-02-25 08:34:35 +08:00
#!/bin/bash
#****************************************************************************
# tools/simhostroute.sh
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
#****************************************************************************
# Helper script to set up host route to NuttX simulator
# and set up IP Tables to allow it to access the
simulator network host route helper script and docs Squashed commit of the following: commit 685951b5385062035ac558df1112353c9441c910 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 16:33:00 2020 -0800 fixed typo in readme commit ad1d3289b48af0de3095e3f365429017e57278b3 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 16:07:48 2020 -0800 simulator host route helper script and docs Squashed commit of the following: commit cf5cddcf55a155303cb5abb1aa026f6dcaf369ca Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 15:50:40 2020 -0800 syslog on console to fix compile error commit def1bb73fcfbc8b115c55d9f4544b97d583807f2 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 15:46:13 2020 -0800 formatting as per PR feedback; removed ping commit b179fd8831b77fbbe85527a4ab3161e1f1ca1e43 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 15:45:49 2020 -0800 formatting as per PR feedback commit e3280bede9798d9a00b118e126c02ceab497e33a Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 13:56:50 2020 -0800 add simhostroute.sh description to readme commit 09a6b0ca3bacf005c2a79102141ae8cc3eb91849 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:38:40 2020 -0800 fixed error in simhostroute.sh usage docs commit d838582119d43ee2002ce3808051c82b23e98c58 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:28:35 2020 -0800 added tcpblaster defconfig and updated docs commit af3d2d6591f12d1127027fdd363858052094e624 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:21:29 2020 -0800 added info about capabilities and running as root commit 6359cfdfedefc818b169455401942d3d33a59f41 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:20:42 2020 -0800 updated network linux readme commit 47feb08aa74e4b1fc6c802567bc777d31e7c9a83 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:09:04 2020 -0800 initial addition
2020-02-25 08:34:35 +08:00
# internet.
#
# This script needs to be run as root.
#
# Note that on Linux you may also have to set kernel capabilities
# on the nuttx executable to allow NuttX to access the tap device:
#
# sudo setcap cap_net_admin+ep ./nuttx
if [ $# != 2 ]; then
echo "Usage: $0 <interface> <on|off>"
exit 1
fi
IF_HOST=$1
STATUS=$2
IF_BRIDGE=nuttx0
IP_NET="10.0.1.0/24"
IP_NETMASK="255.255.255.0"
IP_BROADCAST="10.0.0.255"
IP_HOST="10.0.1.1"
IP_NUTTX="10.0.1.2"
if [ "$STATUS" == "on" ]; then
ip link add $IF_BRIDGE type bridge
ifconfig $IF_BRIDGE $IP_HOST
ifconfig $IF_BRIDGE up
ifconfig -a
ip addr add $IP_HOST dev $IF_BRIDGE
simulator network host route helper script and docs Squashed commit of the following: commit 685951b5385062035ac558df1112353c9441c910 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 16:33:00 2020 -0800 fixed typo in readme commit ad1d3289b48af0de3095e3f365429017e57278b3 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 16:07:48 2020 -0800 simulator host route helper script and docs Squashed commit of the following: commit cf5cddcf55a155303cb5abb1aa026f6dcaf369ca Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 15:50:40 2020 -0800 syslog on console to fix compile error commit def1bb73fcfbc8b115c55d9f4544b97d583807f2 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 15:46:13 2020 -0800 formatting as per PR feedback; removed ping commit b179fd8831b77fbbe85527a4ab3161e1f1ca1e43 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 15:45:49 2020 -0800 formatting as per PR feedback commit e3280bede9798d9a00b118e126c02ceab497e33a Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 13:56:50 2020 -0800 add simhostroute.sh description to readme commit 09a6b0ca3bacf005c2a79102141ae8cc3eb91849 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:38:40 2020 -0800 fixed error in simhostroute.sh usage docs commit d838582119d43ee2002ce3808051c82b23e98c58 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:28:35 2020 -0800 added tcpblaster defconfig and updated docs commit af3d2d6591f12d1127027fdd363858052094e624 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:21:29 2020 -0800 added info about capabilities and running as root commit 6359cfdfedefc818b169455401942d3d33a59f41 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:20:42 2020 -0800 updated network linux readme commit 47feb08aa74e4b1fc6c802567bc777d31e7c9a83 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:09:04 2020 -0800 initial addition
2020-02-25 08:34:35 +08:00
ifconfig $IF_BRIDGE netmask $IP_NETMASK
ip route delete $IP_NET
ip route add $IP_NET dev $IF_BRIDGE src $IP_HOST
ip route add $IP_NUTTX/32 dev $IF_BRIDGE src $IP_HOST
# nat to allow NuttX to access the internet
iptables -t nat -A POSTROUTING -o $IF_HOST -j MASQUERADE
iptables -A FORWARD -i $IF_HOST -o $IF_BRIDGE -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i $IF_BRIDGE -o $IF_HOST -j ACCEPT
# enable forward to make sure nat works
sysctl -w net.ipv4.ip_forward=1
simulator network host route helper script and docs Squashed commit of the following: commit 685951b5385062035ac558df1112353c9441c910 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 16:33:00 2020 -0800 fixed typo in readme commit ad1d3289b48af0de3095e3f365429017e57278b3 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 16:07:48 2020 -0800 simulator host route helper script and docs Squashed commit of the following: commit cf5cddcf55a155303cb5abb1aa026f6dcaf369ca Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 15:50:40 2020 -0800 syslog on console to fix compile error commit def1bb73fcfbc8b115c55d9f4544b97d583807f2 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 15:46:13 2020 -0800 formatting as per PR feedback; removed ping commit b179fd8831b77fbbe85527a4ab3161e1f1ca1e43 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 15:45:49 2020 -0800 formatting as per PR feedback commit e3280bede9798d9a00b118e126c02ceab497e33a Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 13:56:50 2020 -0800 add simhostroute.sh description to readme commit 09a6b0ca3bacf005c2a79102141ae8cc3eb91849 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:38:40 2020 -0800 fixed error in simhostroute.sh usage docs commit d838582119d43ee2002ce3808051c82b23e98c58 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:28:35 2020 -0800 added tcpblaster defconfig and updated docs commit af3d2d6591f12d1127027fdd363858052094e624 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:21:29 2020 -0800 added info about capabilities and running as root commit 6359cfdfedefc818b169455401942d3d33a59f41 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:20:42 2020 -0800 updated network linux readme commit 47feb08aa74e4b1fc6c802567bc777d31e7c9a83 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:09:04 2020 -0800 initial addition
2020-02-25 08:34:35 +08:00
ip route show
else
ip route delete $IP_NET
ip route delete $IP_NUTTX/32
# delete nat rules to clean up
iptables -t nat -D POSTROUTING -o $IF_HOST -j MASQUERADE
simulator network host route helper script and docs Squashed commit of the following: commit 685951b5385062035ac558df1112353c9441c910 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 16:33:00 2020 -0800 fixed typo in readme commit ad1d3289b48af0de3095e3f365429017e57278b3 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 16:07:48 2020 -0800 simulator host route helper script and docs Squashed commit of the following: commit cf5cddcf55a155303cb5abb1aa026f6dcaf369ca Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 15:50:40 2020 -0800 syslog on console to fix compile error commit def1bb73fcfbc8b115c55d9f4544b97d583807f2 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 15:46:13 2020 -0800 formatting as per PR feedback; removed ping commit b179fd8831b77fbbe85527a4ab3161e1f1ca1e43 Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 15:45:49 2020 -0800 formatting as per PR feedback commit e3280bede9798d9a00b118e126c02ceab497e33a Author: Adam Feuer <adam@starcat.io> Date: Mon Feb 24 13:56:50 2020 -0800 add simhostroute.sh description to readme commit 09a6b0ca3bacf005c2a79102141ae8cc3eb91849 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:38:40 2020 -0800 fixed error in simhostroute.sh usage docs commit d838582119d43ee2002ce3808051c82b23e98c58 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:28:35 2020 -0800 added tcpblaster defconfig and updated docs commit af3d2d6591f12d1127027fdd363858052094e624 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:21:29 2020 -0800 added info about capabilities and running as root commit 6359cfdfedefc818b169455401942d3d33a59f41 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:20:42 2020 -0800 updated network linux readme commit 47feb08aa74e4b1fc6c802567bc777d31e7c9a83 Author: Adam Feuer <adam@starcat.io> Date: Sun Feb 23 17:09:04 2020 -0800 initial addition
2020-02-25 08:34:35 +08:00
iptables -D FORWARD -i $IF_HOST -o $IF_BRIDGE -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -D FORWARD -i $IF_BRIDGE -o $IF_HOST -j ACCEPT
ip link delete $IF_BRIDGE type bridge
ip route show
fi