From: Kentaro Matsuyama <matsuy...@thinktube.com>

Some PPP connections don't use a dedicated IP, instead an IP address of another
local interface is "reused" on the PPP interface.

Some Internet providers require this, since their PPPoE server pushes the
network address when routing multiple IPs, and some customers want to use it to
save IP addresses.

Reference: http://www.sustworks.com/site/ipr_guide/unnumbered.html

I have added an UCI option 'unnumbered' 'INTF' which means "reuse the IP
address of INTF" (e.g. unnumbered LAN will put the IP of the LAN interface on
the ppp interface as well), and the following script in /etc/ppp/ip-up.d/.

It works, but it is not integrated with netifd, e.g. netifd does not know about
the IP address we assigned.

Signed-off-by: Bruno Randolf <b...@einfach.org>
---
 package/ppp/Makefile               |  2 ++
 package/ppp/files/ip_unnumbered.sh | 45 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)
 create mode 100755 package/ppp/files/ip_unnumbered.sh

diff --git a/package/ppp/Makefile b/package/ppp/Makefile
index b6fbded..9617087 100644
--- a/package/ppp/Makefile
+++ b/package/ppp/Makefile
@@ -206,6 +206,8 @@ define Package/ppp-mod-pppoe/install
        $(INSTALL_DIR) $(1)/usr/lib/pppd/$(PKG_VERSION)
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/lib/pppd/$(PKG_VERSION)/rp-pppoe.so \
                $(1)/usr/lib/pppd/$(PKG_VERSION)/
+       $(INSTALL_DIR) $(1)/etc/ppp/ip-up.d
+       $(INSTALL_BIN) ./files/ip_unnumbered.sh $(1)/etc/ppp/ip-up.d
 endef
 
 define Package/ppp-mod-radius/install
diff --git a/package/ppp/files/ip_unnumbered.sh 
b/package/ppp/files/ip_unnumbered.sh
new file mode 100755
index 0000000..38919ad
--- /dev/null
+++ b/package/ppp/files/ip_unnumbered.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+
+#pppoe-WAN eth0 0 192.168.71.5 10.0.0.1 WAN
+P_LOCAL=$4
+P_REMOTE=$5
+P_IFACE=$1
+P_NET=$6
+
+hook_unnumbered() {
+       local cfg="$1"
+       local proto ifname unnumbered
+
+       config_get proto "$cfg" proto
+       [ "$proto" = "pppoe" ] || return 0
+
+       config_get ifname "$cfg" ifname
+       [ "x$P_IFACE" = "x$ifname" ] || return 0
+
+       config_get unnumbered "$cfg" unnumbered
+       [ -n "$unnumbered" ] || return 0
+
+       # Get ipaddr and netmask from unnumbered interface.
+       # And that interface must be static one.
+       local proto ipaddr netmask
+       config_get proto "$unnumbered" proto
+       config_get ipaddr "$unnumbered" ipaddr
+       config_get netmask "$unnumbered" netmask
+       [ -n "$ipaddr" -a -n "$netmask" -a "x$proto" = "xstatic" ] || return 0
+
+       eval "$(ipcalc.sh $ipaddr $netmask)"
+
+       # Validate netowrk address
+       if [ "x$P_LOCAL" = "x$NETWORK" ]; then
+               /sbin/ifconfig ${P_IFACE} "$ipaddr" pointopoint ${P_REMOTE}
+               /sbin/route add default gw ${P_REMOTE}
+       fi
+}
+
+. /etc/functions.sh
+include /lib/network
+scan_interfaces
+config_load network
+
+hook_unnumbered $P_NET
+
-- 
1.8.1.2
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to