mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
186 files changed
+1173
-1206
No files matched your search
@@ -0,0 +1,138 @@
|
||||
#!/tmp/gns3/bin/sh
|
||||
|
||||
# script for udhcpc
|
||||
# Copyright (c) 2008 Natanael Copa <natanael.copa@gmail.com>
|
||||
|
||||
UDHCPC="/gns3/etc/udhcpc"
|
||||
UDHCPC_CONF="$UDHCPC/udhcpc.conf"
|
||||
|
||||
RESOLV_CONF="/etc/resolv.conf"
|
||||
[ -f $UDHCPC_CONF ] && . $UDHCPC_CONF
|
||||
|
||||
export broadcast
|
||||
export dns
|
||||
export domain
|
||||
export interface
|
||||
export ip
|
||||
export mask
|
||||
export metric
|
||||
export router
|
||||
export subnet
|
||||
|
||||
#export PATH=/usr/bin:/bin:/usr/sbin:/sbin
|
||||
|
||||
run_scripts() {
|
||||
local dir=$1
|
||||
if [ -d $dir ]; then
|
||||
for i in $dir/*; do
|
||||
[ -f $i ] && $i
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
deconfig() {
|
||||
ip addr flush dev $interface
|
||||
}
|
||||
|
||||
is_wifi() {
|
||||
test -e /sys/class/net/$interface/phy80211
|
||||
}
|
||||
|
||||
if_index() {
|
||||
if [ -e /sys/class/net/$interface/ifindex ]; then
|
||||
cat /sys/class/net/$interface/ifindex
|
||||
else
|
||||
ip link show dev $interface | head -n1 | cut -d: -f1
|
||||
fi
|
||||
}
|
||||
|
||||
calc_metric() {
|
||||
local base=
|
||||
if is_wifi; then
|
||||
base=300
|
||||
else
|
||||
base=200
|
||||
fi
|
||||
echo $(( $base + $(if_index) ))
|
||||
}
|
||||
|
||||
routes() {
|
||||
[ -z "$router" ] && return
|
||||
local gw= num=
|
||||
while ip route del default via dev $interface 2>/dev/null; do
|
||||
:
|
||||
done
|
||||
num=0
|
||||
for gw in $router; do
|
||||
ip route add 0.0.0.0/0 via $gw dev $interface \
|
||||
metric $(( $num + ${IF_METRIC:-$(calc_metric)} ))
|
||||
num=$(( $num + 1 ))
|
||||
done
|
||||
}
|
||||
|
||||
resolvconf() {
|
||||
local i
|
||||
[ -n "$IF_PEER_DNS" ] && [ "$IF_PEER_DNS" != "yes" ] && return
|
||||
if [ "$RESOLV_CONF" = "no" ] || [ "$RESOLV_CONF" = "NO" ] \
|
||||
|| [ -z "$RESOLV_CONF" ]; then
|
||||
return
|
||||
fi
|
||||
echo -n > "$RESOLV_CONF"
|
||||
[ -n "$domain" ] && echo "search $domain" >> "$RESOLV_CONF"
|
||||
for i in $dns; do
|
||||
echo "nameserver $i" >> "$RESOLV_CONF"
|
||||
done
|
||||
}
|
||||
|
||||
bound() {
|
||||
ip addr add $ip/$mask ${broadcast:+broadcast $broadcast} dev $interface
|
||||
ip link set dev $interface up
|
||||
routes
|
||||
resolvconf
|
||||
}
|
||||
|
||||
renew() {
|
||||
if ! ip addr show dev $interface | grep $ip/$mask; then
|
||||
ip addr flush dev $interface
|
||||
ip addr add $ip/$mask ${broadcast:+broadcast $broadcast} dev $interface
|
||||
fi
|
||||
|
||||
local i
|
||||
for i in $router; do
|
||||
if ! ip route show | grep ^default | grep $i; then
|
||||
routes
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if ! grep "^search $domain"; then
|
||||
resolvconf
|
||||
return
|
||||
fi
|
||||
for i in $dns; do
|
||||
if ! grep "^nameserver $i"; then
|
||||
resolvconf
|
||||
return
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
deconfig|renew|bound)
|
||||
run_scripts $UDHCPC/pre-$1
|
||||
$1
|
||||
run_scripts $UDHCPC/post-$1
|
||||
;;
|
||||
leasefail)
|
||||
echo "udhcpc failed to get a DHCP lease" >&2
|
||||
;;
|
||||
nak)
|
||||
echo "udhcpc received DHCP NAK" >&2
|
||||
;;
|
||||
*)
|
||||
echo "Error: this script should be called from udhcpc" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
exit 0
|
||||
|
||||
Executable
+58
@@ -0,0 +1,58 @@
|
||||
#!/gns3/bin/busybox sh
|
||||
#
|
||||
# Copyright (C) 2016 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#
|
||||
# This script is injected into the container and launch before
|
||||
# the start command of the container
|
||||
#
|
||||
OLD_PATH="$PATH"
|
||||
PATH=/gns3/bin:/tmp/gns3/bin
|
||||
|
||||
# bootstrap busybox commands
|
||||
if [ ! -d /tmp/gns3/bin ]; then
|
||||
busybox mkdir -p /tmp/gns3/bin
|
||||
/gns3/bin/busybox --install -s /tmp/gns3/bin
|
||||
fi
|
||||
|
||||
# Wait 2 seconds to settle the network interfaces
|
||||
sleep 2
|
||||
|
||||
# /etc/hosts
|
||||
[ -s /etc/hosts ] || cat > /etc/hosts << __EOF__
|
||||
127.0.1.1 $HOSTNAME
|
||||
127.0.0.1 localhost
|
||||
::1 localhost ip6-localhost ip6-loopback
|
||||
fe00::0 ip6-localnet
|
||||
ff00::0 ip6-mcastprefix
|
||||
ff02::1 ip6-allnodes
|
||||
ff02::2 ip6-allrouters
|
||||
__EOF__
|
||||
|
||||
# configure loopback interface
|
||||
ip link set dev lo up
|
||||
|
||||
# activate eth interfaces
|
||||
sed -n 's/^ *\(eth[0-9]*\):.*/\1/p' < /proc/net/dev | while read dev; do
|
||||
ip link set dev $dev up
|
||||
done
|
||||
|
||||
# configure network interfaces
|
||||
ifup -a -f
|
||||
|
||||
# continue normal docker startup
|
||||
PATH="$OLD_PATH"
|
||||
exec "$@"
|
||||
Reference in new issue
Block a user