summaryrefslogtreecommitdiffhomepage
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/contrib/hotplug.d-20-aliases24
-rw-r--r--core/src/ffluci/http.lua6
-rw-r--r--core/src/ffluci/sys.lua31
3 files changed, 49 insertions, 12 deletions
diff --git a/core/contrib/hotplug.d-20-aliases b/core/contrib/hotplug.d-20-aliases
new file mode 100644
index 0000000000..b9986e3aaa
--- /dev/null
+++ b/core/contrib/hotplug.d-20-aliases
@@ -0,0 +1,24 @@
+add_aliases() {
+ local config="$1"
+
+ config_get base "$INTERFACE" ifname
+ config_get iface "$config" ifname
+ config_get ipaddr "$config" ipaddr
+ config_get auto "$config" auto
+
+ [ "${iface%%:*}" == "$base" -a "$iface" != "$base" ] && {
+ case "$auto" in
+ 1|on|enabled) setup_interface "$iface" "$config";;
+ *) return 1;;
+ esac
+ }
+}
+
+
+case "$ACTION" in
+ ifup)
+ include /lib/network
+ scan_interfaces
+ config_foreach "add_aliases" interface
+ ;;
+esac
diff --git a/core/src/ffluci/http.lua b/core/src/ffluci/http.lua
index 06e1c43bda..44d1a925c4 100644
--- a/core/src/ffluci/http.lua
+++ b/core/src/ffluci/http.lua
@@ -59,6 +59,12 @@ function request_redirect(category, module, action, ...)
end
+-- Returns the User's IP
+function remote_addr()
+ return ENV.REMOTE_ADDR
+end
+
+
-- Returns the script name
function script_name()
return ENV.SCRIPT_NAME
diff --git a/core/src/ffluci/sys.lua b/core/src/ffluci/sys.lua
index 44855f8ef3..77d45cfb7a 100644
--- a/core/src/ffluci/sys.lua
+++ b/core/src/ffluci/sys.lua
@@ -115,18 +115,14 @@ group = {}
group.getgroup = posix.getgroup
net = {}
+-- Returns the ARP-Table
+function net.arptable()
+ return _parse_delimited_table(io.lines("/proc/net/arp"), "%s%s+")
+end
+
-- Returns whether an IP-Adress belongs to a certain net
-function net.belongs(ip, net)
- local netparts = ffluci.util.split(net, "/")
-
- if #netparts ~= 2 then
- return nil
- end
-
- local binadr = net.ip4bin(ip)
- local binnet = net.ip4bin(netparts[1])
-
- return (binadr:sub(1, netparts[2]) == binnet:sub(1, netparts[2]))
+function net.belongs(ip, net, prefix)
+ return (net.ip4bin(ip):sub(1, prefix) == net.ip4bin(net):sub(1, prefix))
end
-- Returns all available network interfaces
@@ -138,6 +134,17 @@ function net.devices()
return devices
end
+-- Returns the prefix to a given netmask
+function net.mask4prefix(mask)
+ local bin = net.ip4bin(mask)
+
+ if not bin then
+ return nil
+ end
+
+ return #ffluci.util.split(bin, "1")-1
+end
+
-- Returns the kernel routing table
function net.routes()
return _parse_delimited_table(io.lines("/proc/net/route"))
@@ -267,7 +274,7 @@ end
-- Internal functions
function _parse_delimited_table(iter, delimiter)
- delimiter = delimiter or "\t+"
+ delimiter = delimiter or "%s+"
local data = {}
local trim = ffluci.util.trim