1#!/bin/sh /etc/rc.common 2#START=20 3 4setup_hostname() 5{ 6 local hostname="$($CONFIG get netbiosname)" 7 [ -z "$hostname" ] && hostname="$($CONFIG get Device_name)" 8 echo "$hostname" > /proc/sys/kernel/hostname 9} 10 11print_dhcpd_conf() 12{ 13 local n=1 14 local static_lease 15 local leases_file=/tmp/udhcpd.leases 16 17 [ ! -f $leases_file ] && touch $leases_file 18 19 cat <<EOF 20pidfile /var/run/udhcpd.pid 21start $($CONFIG get dhcp_start) 22end $($CONFIG get dhcp_end) 23interface br0 24remaining yes 25auto_time 5 26lease_file $leases_file 27option subnet $($CONFIG get lan_netmask) 28option router $($CONFIG get lan_ipaddr) 29option dns $($CONFIG get lan_ipaddr) 30option lease $($CONFIG get lan_lease) 31EOF 32 33 while : ; do 34 static_lease="$($CONFIG get reservation$n)" 35 [ "x$static_lease" = "x" ] && break || echo "static_lease $static_lease" 36 n=$(( $n + 1)) 37 done 38} 39 40start_dhcpd() 41{ 42 [ "$($CONFIG get lan_dhcp)" = "0" ] && return 43 print_dhcpd_conf > /tmp/udhcpd.conf 44 udhcpd /tmp/udhcpd.conf 45} 46 47restart_interface() 48{ 49 local wan6_type=`$CONFIG get ipv6_type` 50 local logo_test=`$CONFIG get endis_ipv6_logo_test` 51 local lan6_ip=`ifconfig $BR_IF |grep "inet6 addr" |grep -v "Link" |awk '{print $3}'` 52 53 ifconfig $LAN_IF up 54 ifconfig $BR_IF down 55 # Enable DAD, and randomly generate anoter link-local address if 56 # MAC-based duplicate link-local address has been found. 57 if [ "x$logo_test" = "x1" -a "x$wan6_type" = "xfixed" ]; then 58 echo 2 > /proc/sys/net/ipv6/conf/default/accept_dad 59 echo 2 > /proc/sys/net/ipv6/conf/${BR_IF}/accept_dad 60 echo 1 > /proc/sys/net/ipv6/neigh/${BR_IF}/not_send_neighbor_solicitation 61 echo 1 > /proc/sys/net/ipv6/neigh/${LAN_IF}/not_send_neighbor_solicitation 62 else 63 echo 3 > /proc/sys/net/ipv6/conf/default/accept_dad 64 echo 3 > /proc/sys/net/ipv6/conf/${BR_IF}/accept_dad 65 fi 66 67 [ ! -f /tmp/boot_status ] && sleep 2 68 ifconfig $BR_IF up 69 70 if [ "x$logo_test" = "x1" -a "x$wan6_type" = "xfixed" ]; then 71 echo "1" > /proc/sys/net/ipv6/neigh/${LAN_IF}/not_send_neighbor_solicitation 72 echo "1" > /proc/sys/net/ipv6/neigh/${BR_IF}/not_send_neighbor_solicitation 73 fi 74 75 # reset lan ipv6 adddress 76 [ "x$lan6_ip" != "x" ] && ip -6 addr add $lan6_ip dev $BR_IF 77} 78 79#At boot time, we wireless background here. 80#So we can make full use of the next sleep 10 for switch down. 81check_wlanboot() 82{ 83 [ "$changing_mode" != "1" ] && return 84 /etc/init.d/madwifi boot 85 /etc/init.d/wlan-common boot & 86} 87 88start_stage0() # $1: boot/start 89{ 90 local lan_ip=$($CONFIG get lan_ipaddr) 91 local lan_mask=$($CONFIG get lan_netmask) 92 93 setup_hostname 94 95 ifconfig $LAN_IF up 96 ifconfig $BR_IF ${lan_ip:-192.168.1.1} netmask ${lan_mask:-255.255.255.0} 97 restart_interface 98 99 /sbin/cmdroute start # Apply static route 100 /sbin/cmddlna ip_restart & 101 /sbin/ip_mac start # Apply lan static arp. 102 103 # Set Hairpin mode on br0:ethlan 104 brctl hairpin $BR_IF $LAN_IF on 105 106 start_dhcpd 107 check_wlanboot 108 109 # PHY link will be pulled low some seconds to force transition to reboot state 110 # and generating DHCP request and Discovery protocol and address refresh in the 111 # devices connected to the NETGEAR Local Area Network ports. 112 # 113 # After echo 9 into /proc/switch_phy, LAN physical signal will bring down 9 seconds, 114 # should wait for LAN physical signal bring up, and then execute subsequence actions 115 # as below. 116 echo -n 9 > /proc/switch_phy && sleep 10 117 118 /etc/init.d/net-scan $1 # daemon for getting attached devices 119 /etc/init.d/lltd $1 # Link Layer Topology Discovery Daemon 120 /etc/init.d/telnet $1 # telnet daemon for Router Debugging Mode ... 121} 122 123start() 124{ 125 [ "$1" = "mode" ] && changing_mode=1 126 start_stage0 start 127 /sbin/cmdupnp start # in booting, upnpd is started by net-wan 128 /usr/sbin/update_smb 129 130 # when the user changes "Device Name" in LAN Setup page, make sure the new name shows up on ReadyCLOUD. 131 if [ "$($CONFIG get readycloud_enable)" = "1" ]; then 132 local name=$($CONFIG get netbiosname) 133 [ "x$name" = "x" ] && name=$($CONFIG get Device_name) 134 /opt/rcagent/script/alish.sh $name 135 fi 136} 137 138stop() 139{ 140 # Bug 35743 [PnP-X]When change DUT IP from the GUI. The device icon change to gray and IP of the device don't change. 141 # Reason:stop miniupnpd to send bye-bye packets to inform client it would be down. 142 /sbin/cmdupnp stop 143 144 #/etc/init.d/samba stop 145 /usr/bin/killall smbd 2> /dev/null 146 /etc/init.d/telnet stop 147 /etc/init.d/lltd stop 148 /etc/init.d/net-scan stop 149 150 killall udhcpd 151 152 /sbin/cmdroute stop 153 #ifconfig $BR_IF down 154 ifconfig $LAN_IF down 155} 156 157restart() 158{ 159 stop 160 start 161} 162 163boot() 164{ 165 [ "$1" = "mode" ] && changing_mode=1 166 start_stage0 boot 167} 168