summaryrefslogtreecommitdiffstats
path: root/openwrt/package/base-files/default/usr
diff options
context:
space:
mode:
Diffstat (limited to 'openwrt/package/base-files/default/usr')
-rw-r--r--openwrt/package/base-files/default/usr/lib/common.awk66
-rw-r--r--openwrt/package/base-files/default/usr/lib/parse-config.awk40
-rwxr-xr-xopenwrt/package/base-files/default/usr/share/udhcpc/default.script37
3 files changed, 123 insertions, 20 deletions
diff --git a/openwrt/package/base-files/default/usr/lib/common.awk b/openwrt/package/base-files/default/usr/lib/common.awk
new file mode 100644
index 000000000..63a8cf23d
--- /dev/null
+++ b/openwrt/package/base-files/default/usr/lib/common.awk
@@ -0,0 +1,66 @@
+function portstr(type, str) {
+ gsub(/-/, ":", str)
+ if (insmod_mport != 1) {
+ print "insmod ipt_multiport >&- 2>&-"
+ insmod_mport = 1
+ }
+ if (type == "src") return " -m multiport --sports " str
+ else return " -m multiport --dports " str
+}
+
+function str2ipt(str) {
+ str2data(str)
+ _cmd = ""
+ if (_l["src"] != "") _cmd = _cmd " -s " _l["src"]
+ if (_l["dest"] != "") _cmd = _cmd " -d " _l["dest"]
+ if (_l["proto"] != "") {
+ _cmd = _cmd " -p " _l["proto"]
+ }
+ # scripts need to check for proto="" and emit two rules in that case
+ if ((_l["proto"] == "") || (_l["proto"] == "tcp") || (_l["proto"] == "udp")) {
+ if (_l["sport"] != "") _cmd = _cmd portstr("src", _l["sport"])
+ if (_l["dport"] != "") _cmd = _cmd portstr("dest", _l["dport"])
+ }
+ if (_l["layer7"] != "") {
+ if (insmod_l7 != 1) {
+ print "insmod ipt_layer7 >&- 2>&-"
+ insmod_l7 = 1
+ }
+ _cmd = _cmd " -m layer7 --l7proto " _l["layer7"]
+ }
+ return _cmd
+}
+
+function str2data(str) {
+ delete _l
+ _n = split(str, _o, "[\t ]")
+ for (_i = 1; _i <= _n; _i++) {
+ _n2 = split(_o[_i], _c, "=")
+ if (_n2 == 2) _l[_c[1]] = _c[2]
+ }
+}
+
+function bitcount(c) {
+ c=and(rshift(c, 1),0x55555555)+and(c,0x55555555)
+ c=and(rshift(c, 2),0x33333333)+and(c,0x33333333)
+ c=and(rshift(c, 4),0x0f0f0f0f)+and(c,0x0f0f0f0f)
+ c=and(rshift(c, 8),0x00ff00ff)+and(c,0x00ff00ff)
+ c=and(rshift(c,16),0x0000ffff)+and(c,0x0000ffff)
+ return c
+}
+
+function validate_netmask(nm) {
+ return and(-nm,compl(nm))
+}
+
+function ip2int(ip) {
+ for (ret=0,n=split(ip,a,"\."),x=1;x<=n;x++) ret=or(lshift(ret,8),a[x])
+ return ret
+}
+
+function int2ip(ip,ret,x) {
+ ret=and(ip,255)
+ ip=rshift(ip,8)
+ for(;x<3;ret=and(ip,255)"."ret,ip=rshift(ip,8),x++);
+ return ret
+}
diff --git a/openwrt/package/base-files/default/usr/lib/parse-config.awk b/openwrt/package/base-files/default/usr/lib/parse-config.awk
new file mode 100644
index 000000000..bde5c0072
--- /dev/null
+++ b/openwrt/package/base-files/default/usr/lib/parse-config.awk
@@ -0,0 +1,40 @@
+{
+ line=$0
+ gsub(/^[ \t]*/, "")
+ gsub(/[ \t]*$/, "")
+}
+
+$1 == "@define" {
+ v[$2] = $3
+}
+
+$1 == "@ifdef" {
+ if_open = 1
+ if (v[$2] != "") noprint = 0
+ else noprint = 1
+}
+
+$1 == "@ifndef" {
+ if_open = 1
+ if (v[$2] != "") noprint = 1
+ else noprint = 0
+}
+
+$1 == "@else" {
+ if (noprint == 1) noprint = 0
+ else noprint = 1
+}
+
+($1 !~ /^@/) && (noprint != 1) {
+ n=split(line "@@", a, /@@/)
+ for (i=1; i<=n; i++) {
+ if ((i % 2) == 1) printf a[i]
+ else printf v[a[i]]
+ }
+ print ""
+}
+
+$1 == "@endif" {
+ if_open = 0
+ noprint = 0
+}
diff --git a/openwrt/package/base-files/default/usr/share/udhcpc/default.script b/openwrt/package/base-files/default/usr/share/udhcpc/default.script
index 42d3eaf0c..4604648e6 100755
--- a/openwrt/package/base-files/default/usr/share/udhcpc/default.script
+++ b/openwrt/package/base-files/default/usr/share/udhcpc/default.script
@@ -1,18 +1,17 @@
#!/bin/sh
[ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
+. /etc/config/network
RESOLV_CONF="/tmp/resolv.conf"
hotplug_event() {
- nvram show 2>&- | grep _proto=dhcp | {
- while :; do
- read FOO
- [ -z "$FOO" ] && break
- FOO="${FOO%%_*}"
- [ "$(nvram get ${FOO}_ifname)" = "${interface}" ] || continue
- env -i ACTION="$1" INTERFACE="${FOO}" PROTO=dhcp /sbin/hotplug iface
- done
- }
+ for ifname in lan wan wifi ${ifnames}; do
+ eval "proto=\"\${${ifname}_proto}\""
+ eval "if=\"\${${ifname}_ifname}\""
+ [ "$proto" = "dhcp" ] || continue
+ [ "$if" = "$interface" ] || continue
+ env -i ACTION="$1" INTERFACE="$ifname" PROTO=dhcp /sbin/hotplug iface
+ done
}
case "$1" in
@@ -26,22 +25,20 @@ case "$1" in
broadcast ${broadcast:-+}
if [ -n "$router" ] ; then
-
- if [ "$router" != "$(route -n | grep '^0.0.0.0' | grep $interface | awk '{ print $2 }')" ] ; then
- while route del default gw 0.0.0.0 dev $interface 2>&- ; do
- echo "removing old default route"
- done
- for i in $router ; do
- route add default gw $i dev $interface
- done
- fi
+ echo "deleting routers"
+ while route del default gw 0.0.0.0 dev $interface >&- 2>&- ; do :; done
+
+ for i in $router ; do
+ echo "adding router $i"
+ route add default gw $i dev $interface
+ done
fi
echo -n > $RESOLV_CONF
${domain:+echo search $domain} >> $RESOLV_CONF
for i in $dns ; do
- echo adding dns $i
- echo nameserver $i >> $RESOLV_CONF
+ echo "adding dns $i"
+ echo "nameserver $i" >> $RESOLV_CONF
done
hotplug_event ifup