2 # (c) 2010 Gregor Riepl <onitake@gmail.com>
4 # Tethering utility for Maemo
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
28 echo $(date): $@ >> /tmp/mtetherd-script.log
33 echo $(date): $@ >> /tmp/mtetherd-script.log
37 if [ "${INTERFACE}" = "" -o "${WAN}" = "" -o "${ADDRESS}" = "" -o "${NETMASK}" = "" -o "${DHCP_START}" = "" -o "${DHCP_END}" = "" ]; then
38 die "Usage: $0 <interface> <wan interface> <address> <netmask> <dhcp range start> <dhcp range end>"
41 log "Setting up routing for: $INTERFACE $WAN $ADDRESS $NETMASK $DHCP_START $DHCP_END"
43 echo "${INTERFACE}" | grep -E -q '^[a-zA-Z]+[0-9]+$' || die "Invalid interface name"
44 echo "${WAN}" | grep -E -q '^[a-zA-Z]+[0-9]+$' || die "Invalid WANÂ interface name"
45 echo "${ADDRESS}" | grep -E -q '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' || die "Invalid address"
46 echo "${NETMASK}" | grep -E -q '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' || die "Invalid netmask"
47 echo "${DHCP_START}" | grep -E -q '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' || die "Invalid DHCP start address"
48 echo "${DHCP_END}" | grep -E -q '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' || die "Invalid DHCP end address"
50 RUNFILE="/var/run/mtetherd.${INTERFACE}.pid"
51 log "PID file = ${RUNFILE}"
53 log "/sbin/ifconfig ${INTERFACE} ${ADDRESS} netmask ${NETMASK}"
54 msg=$(/sbin/ifconfig ${INTERFACE} ${ADDRESS} netmask ${NETMASK} 2>&1)
56 log "/sbin/modprobe ipt_MASQUERADE"
57 msg=$(/sbin/modprobe ipt_MASQUERADE 2>&1)
59 log "/usr/sbin/iptables -t nat -A POSTROUTING -o ${WAN} -j MASQUERADE"
60 msg=$(/usr/sbin/iptables -t nat -A POSTROUTING -o ${WAN} -j MASQUERADE 2>&1)
62 #-a, --listen-address=ipaddr Specify local address(es) to listen on.
63 #-d, --no-daemon Do NOT fork into the background: run in debug mode.
64 #-D, --domain-needed Do NOT forward queries with no domain part.
65 #-f, --filterwin2k Don't forward spurious DNS requests from Windows hosts.
66 #-F, --dhcp-range=ipaddr,ipaddr,time Enable DHCP in the range given with lease duration.
67 #-g, --group=groupname Change to this group after startup (defaults to dip).
68 #-h, --no-hosts Do NOT load /etc/hosts file.
69 #-i, --interface=interface Specify interface(s) to listen on.
70 #-I, --except-interface=int Specify interface(s) NOT to listen on.
71 #-k, --keep-in-foreground Do NOT fork into the background, do NOT run in debug mode.
72 #-K, --dhcp-authoritative Assume we are the only DHCP server on the local network.
73 #-l, --dhcp-leasefile=path Specify where to store DHCP leases (defaults to /var/lib/misc/dnsmasq.leases).
74 #-n, --no-poll Do NOT poll /etc/resolv.conf file, reload only on SIGHUP.
75 #-N, --no-negcache Do NOT cache failed search results.
76 #-o, --strict-order Use nameservers strictly in the order given in /etc/resolv.conf.
77 #-p, --port=number Specify port to listen for DNS requests on (defaults to 53).
78 #-q, --log-queries Log DNS queries.
79 #-Q, --query-port=number Force the originating port for upstream DNS queries.
80 #-R, --no-resolv Do NOT read resolv.conf.
81 #-s, --domain=<domain> Specify the domain to be assigned in DHCP leases.
82 #-u, --user=username Change to this user after startup. (defaults to nobody).
83 #-x, --pid-file=path Specify path of PID file (defaults to /var/run/dnsmasq.pid).
84 #-X, --dhcp-lease-max=number Specify maximum number of DHCP leases (defaults to 150).
85 #-z, --bind-interfaces Bind only to interfaces in use.
86 #-Z, --read-ethers Read DHCP static host information from /etc/ethers.
87 #-1, --enable-dbus Enable the DBus interface for setting upstream servers, etc.
88 #-2, --no-dhcp-interface=interface Do not provide DHCP on this interface, only provide DNS.
89 #-9, --leasefile-ro Do not use leasefile.
90 # --log-dhcp Extra logging for DHCP.
91 # --min-port=<port> Specify lowest port available for DNS query transmission.
92 log "/sbin/start-stop-daemon -S -p \"${RUNFILE}\" -b -x /usr/sbin/dnsmasq -- -x \"${RUNFILE}\" -k -I lo -i ${INTERFACE} -a ${ADDRESS} -z -F ${DHCP_START},${DHCP_END},3600"
93 msg=$(/sbin/start-stop-daemon -S -p "${RUNFILE}" -b -x /usr/sbin/dnsmasq -- -x "${RUNFILE}" -k -I lo -i ${INTERFACE} -a ${ADDRESS} -z -F ${DHCP_START},${DHCP_END},3600 2>&1)
95 log "echo 1 > /proc/sys/net/ipv4/conf/${INTERFACE}/forwarding"
96 echo 1 > /proc/sys/net/ipv4/conf/${INTERFACE}/forwarding
97 log "echo 1 > /proc/sys/net/ipv4/conf/${WAN}/forwarding"
98 echo 1 > /proc/sys/net/ipv4/conf/${WAN}/forwarding
100 log "Finished setting up routing for $INTERFACE"