1
0
This repository has been archived on 2025-01-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Anderson Luiz Alves 0464e230c1 stock 103961
2017-07-30 16:48:04 -03:00

84 lines
2.3 KiB
Bash
Executable File

#!/bin/sh
# /etc/bewan/scripts/ip-up
# common script for DHCP client et PPP client on the WAN side
# Environment variables:
# WANID: WAN interface index
# IFNAME: network interface
# IPADDR: IP address
# SMASK: subnet mask
# ROUTERS: gateways
# SERVERS: DNS servers
# DOMAIN: Domain name
# IPREMOTE: peer IP address (PPP)
# DHCPSRV: DHCP server (DHCP)
# DHCP43: Option DHCP 43 if exists
# DHCP101: Option DHCP 101 if exists
# DHCP121: Option DHCP 121 if exists
WANID=${WANID:-0}
base_log "$SCRIPTD/ip-up $WANID started" debug
# Used by TR069 to get the URL of ACS
DHCP43="${DHCP43:-}"
# Used by update-routes to create classless static routes
DHCP121=${DHCP121:-}
# Timezone code for STB
DHCP101=${DHCP101:-}
IFDIR=$WAND/$WANID/ip
if [ -d "$IFDIR" ]; then
echo $IPADDR >$IFDIR/ipaddr
[ "$SMASK" != '' ] && echo $SMASK >$IFDIR/ipmask
[ "$IPREMOTE" != '' ] && echo $IPREMOTE >$IFDIR/ipremote
[ "$ROUTERS" != '' ] && echo $ROUTERS >$IFDIR/routers
[ "$SERVERS" != '' ] && echo $SERVERS >$IFDIR/servers
[ "$DHCPSRV" != '' ] && echo $DHCPSRV >$IFDIR/dhcpsrv
[ "$DOMAIN" != '' ] && echo $DOMAIN >$IFDIR/domain
cp -f /proc/uptime $IFDIR/uptime
# Record environment variables with leading and ending quotes
env | sed "s/=/='/g" | sed "s/$/'/g" >$IFDIR/ip-up-env
fi
base_call_scripts 'update-routes update-nat update-dns'
# compute args: $WANID $DEFRTE $INET
# Default route flag
DEFROUTE=`cat $WAND/defroute 2>/dev/null`
DEFRTE=0
if [ "$DEFROUTE" = "$WANID" ] || [ -d "$ROUTED/wan$WANID/default" ]; then
DEFRTE=1
fi
# Internet connection flag
INTERNET=`cat $WAND/internet 2>/dev/null`
INET=0
for ix in `strip $INTERNET`; do
[ "$ix" = "$WANID" ] && INET=1
done
# call scripts found in /etc/bewan/ip-up.d directory
# $1: $WANID, index of WAN interface
# $2: $DEFRTE, true if WAN interface is a default route
# $3: $INET, true if WAN interface is an Internet connection
trap base_reboot_on_exit EXIT
for script in `find /etc/bewan/ip-up.d -follow -type f | sort`; do
base_log "$script $WANID" debug
. $script $WANID $DEFRTE $INET
done
trap '' EXIT
[ ! -f $RCRUNNING ] && base_call_initd 'inittab'
# Flush conntrack
if [ -f "/proc/net/ip_conntrack_flush" ]; then
echo 1 > /proc/net/ip_conntrack_flush
fi
base_log "$SCRIPTD/ip-up $WANID exited" debug