Two options are defined for dhcp protocol:
- use_dns: boolean, default to true.
- use_default_route: boolean, default to true.

If protocol is pptp call to udhcpc is kept blocking for the moment.

Documentation is included in the patch.

Signed-off-by: Frédéric Moulins <[EMAIL PROTECTED]>

---

Is it too late for 8.09 ?

diff --git a/docs/network-scripts.tex b/docs/network-scripts.tex
--- a/docs/network-scripts.tex
+++ b/docs/network-scripts.tex
@@ -52,3 +52,21 @@
 \texttt{scan\_\textit{protocolname}} is optional and only necessary if your 
protocol
 uses a custom device, e.g. a tunnel or a PPP device.
 
+For DHCP based protocols (eg. PPTP, L2TP) you can implement the following shell
+functions triggered upon DHCP event to control routes and DNS behaviour :
+
+\begin{Verbatim}
+dhcp_add_routes_<protocolname>() {
+    local action="$1" # deconfig, bound or renew
+    # add routes or not
+    [ "bound" = "$1" ] && dhcp_add_routes
+}
+
+dhcp_add_dns_<protocolname>() {
+    local action="$1" # deconfig, bound or renew
+    # add dns or not
+}
+\end{Verbatim}
+
+Adding routes or DNS within these functions can be done using
+\texttt{dhcp\_add\_routes} or \texttt{dhcp\_add\_dns} respectively.
diff --git a/docs/network.tex b/docs/network.tex
--- a/docs/network.tex
+++ b/docs/network.tex
@@ -33,8 +33,18 @@
 \texttt{netmask} are mandatory, while \texttt{gateway} and \texttt{dns} are 
optional.
 You can specify more than one DNS server, separated with spaces.
 
-DHCP currently only accepts \texttt{ipaddr} (IP address to request from the 
server)
-and \texttt{hostname} (client hostname identify as) - both are optional.
+DHCP currently accepts these options:
+\begin{itemize}
+    \item{ipaddr} \\
+        IP address to request from the server
+    \item{hostname} \\
+        client hostname identify as
+    \item{use\_default\_route} \\
+        Use obtained default route Default: true.
+    \item{use\_dns} \\
+        Use obtained dns IP. Default: true.
+\end{itemize}
+All are optional.
 
 PPP based protocols (\texttt{pppoe}, \texttt{pptp}, ...) accept these options:
 \begin{itemize}
diff --git a/package/base-files/files/lib/network/config.sh 
b/package/base-files/files/lib/network/config.sh
--- a/package/base-files/files/lib/network/config.sh
+++ b/package/base-files/files/lib/network/config.sh
@@ -258,7 +258,7 @@
                                        $DEBUG ifconfig "$iface" "$ipaddr" 
${netmask:+netmask "$netmask"}
 
                                # don't stay running in background if dhcp is 
not the main proto on the interface (e.g. when using pptp)
-                               [ ."$proto1" != ."$proto" ] && dhcpopts="-n -q"
+                               [ ."$proto1" != ."$proto" -a ."pptp" = 
."$proto" ] && dhcpopts="-n -q"
                                $DEBUG eval udhcpc -t 0 -i "$iface" 
${ipaddr:+-r $ipaddr} ${hostname:+-H $hostname} ${clientid:+-c $clientid} -b -p 
"$pidfile" ${dhcpopts:- -R &}
                                lock -u "/var/lock/dhcp-$iface"
                        fi
diff --git a/package/base-files/files/usr/share/udhcpc/default.script 
b/package/base-files/files/usr/share/udhcpc/default.script
--- a/package/base-files/files/usr/share/udhcpc/default.script
+++ b/package/base-files/files/usr/share/udhcpc/default.script
@@ -1,28 +1,44 @@
 #!/bin/sh
 [ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
 . /etc/functions.sh
-include /lib/network
 
 RESOLV_CONF="/tmp/resolv.conf.auto"
 
 hotplug_event() {
-       scan_interfaces
-       for ifc in $interfaces; do
-               config_get ifname $ifc ifname
-               [ "$ifname" = "$interface" ] || continue
-
-               config_get proto $ifc proto
-               [ "$proto" = "dhcp" ] || continue
-               [ ifup = "$1" ] && {
-                       uci_set_state network "$ifc" ipaddr "$ip"
-                       uci_set_state network "$ifc" netmask 
"${subnet:-255.255.255.0}"
+       [ ifup = "$1" ] && {
+               uci_set_state network "$ifc" ipaddr "$ip"
+               uci_set_state network "$ifc" netmask "${subnet:-255.255.255.0}"
+               [ $use_dns -eq 1 ] && {
                        uci_set_state network "$ifc" dnsdomain "$domain"
                        uci_set_state network "$ifc" dns "$dns"
-                       uci_set_state network "$ifc" gateway "$router"
                }
-               env -i ACTION="$1" INTERFACE="$ifc" DEVICE="$ifname" PROTO=dhcp 
/sbin/hotplug-call iface
-       done
+               [ $use_default_route -eq 1 ] && uci_set_state network "$ifc" 
gateway "$router"
+       }
+       env -i ACTION="$1" INTERFACE="$ifc" DEVICE="$device" PROTO=$proto 
/sbin/hotplug-call iface
 }
+
+dhcp_add_routes() {
+               for i in $router ; do
+                       echo "adding router $i"
+                       route add default gw $i dev $interface
+                       valid="$valid|$i"
+               done
+
+               echo "deleting old routes"
+               $(route -n | awk '/^0.0.0.0\W{9}('$valid')\W/ {next} /^0.0.0.0/ 
{print "route del -net "$1" gw "$2";"}')
+}
+
+dhcp_add_dns() {
+               echo -n > "${RESOLV_CONF}.tmp"
+               ${domain:+echo search $domain} >> "${RESOLV_CONF}.tmp"
+               for i in $dns ; do
+                       echo "adding dns $i"
+                       echo "nameserver $i" >> "${RESOLV_CONF}.tmp"
+               done
+               mv "${RESOLV_CONF}.tmp" "$RESOLV_CONF"
+}
+
+include /lib/network
 
 case "$1" in
        deconfig)
@@ -30,40 +46,48 @@
                hotplug_event ifdown
        ;;
        renew|bound)
-               ifconfig $interface $ip \
-               netmask ${subnet:-255.255.255.0} \
-               broadcast ${broadcast:-+}
+               scan_interfaces
+               for ifc in $interfaces; do
+                       config_get device $ifc device
+                       [ "$device" = "$interface" ] || continue
+                       
+                       ifconfig $interface $ip \
+                       netmask ${subnet:-255.255.255.0} \
+                       broadcast ${broadcast:-+}
 
-               [ -n "$router" ] && {
-                       for i in $router ; do
-                               echo "adding router $i"
-                               route add default gw $i dev $interface
-                               valid="$valid|$i"
-
-                       done
-
-                       echo "deleting old routes"
-                       $(route -n | awk '/^0.0.0.0\W{9}('$valid')\W/ {next} 
/^0.0.0.0/ {print "route del -net "$1" gw "$2";"}')
-               }
-               
-               [ -n "$dns" ] && {
-                       echo -n > "${RESOLV_CONF}.tmp"
-                       ${domain:+echo search $domain} >> "${RESOLV_CONF}.tmp"
-                       for i in $dns ; do
-                               echo "adding dns $i"
-                               echo "nameserver $i" >> "${RESOLV_CONF}.tmp"
-                       done
-                       mv "${RESOLV_CONF}.tmp" "$RESOLV_CONF"
-               }
-               
-               if [ "$1" = "renew" ]; then
-                       hotplug_event update
-               else
-                       hotplug_event ifup
-               fi
-               
-               # user rules
-               [ -f /etc/udhcpc.user ] && . /etc/udhcpc.user
+                       config_get proto $ifc proto
+                       [ -n "$router" ] && {
+                               if [ "dhcp" != "$proto" ]; then
+                                       ( eval "type dhcp_add_routes_$proto" ) 
>/dev/null 2>/dev/null \
+                                               && eval "dhcp_add_routes_$proto 
'$1'"
+                               else
+                                       config_get_bool use_default_route 
"$ifc" use_default_route 1
+                                       [ $use_default_route -eq 1 ] && {
+                                               dhcp_add_routes
+                                       }
+                               fi
+                       }
+                       [ -n "$dns" ] && {
+                               if [ "dhcp" != "$proto" ]; then
+                                       ( eval "type dhcp_add_dns_$proto" ) 
>/dev/null 2>/dev/null \
+                                               && eval "dhcp_add_dns_$proto 
'$1'"
+                               else
+                                       config_get_bool use_dns "$ifc" use_dns 1
+                                       [ $use_dns -eq 1 ] && {
+                                               dhcp_add_dns
+                                       }
+                               fi
+                       }
+                       [ "$proto" = "dhcp" ] && {
+                               if [ "$1" = "renew" ]; then
+                                       hotplug_event update
+                               else
+                                       hotplug_event ifup
+                               fi
+                       }
+                       # user rules
+                       [ -f /etc/udhcpc.user ] && . /etc/udhcpc.user
+               done
        ;;
 esac
 
_______________________________________________
openwrt-devel mailing list
[email protected]
http://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to