summaryrefslogtreecommitdiffhomepage
path: root/libs/luci-lib-ip
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2015-01-26 10:47:39 +0100
committerJo-Philipp Wich <jow@openwrt.org>2015-01-26 10:47:39 +0100
commit8c8c69fa5d69113617fd9a897b843f22d44c76a6 (patch)
tree82d91660b72b0f27b42cc442c5e3342c45333a2f /libs/luci-lib-ip
parent0d32e69f163e80442c7a483c445484ee250986e8 (diff)
luci-lib-ip: accept 2nd netmask argument in new(), IPv4() and IPv6()
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'libs/luci-lib-ip')
-rw-r--r--libs/luci-lib-ip/src/ip.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/libs/luci-lib-ip/src/ip.c b/libs/luci-lib-ip/src/ip.c
index 760506a9e..8c9155b1a 100644
--- a/libs/luci-lib-ip/src/ip.c
+++ b/libs/luci-lib-ip/src/ip.c
@@ -81,14 +81,14 @@ struct dump_state {
};
-static int _cidr_new(lua_State *L, int index, int family);
+static int _cidr_new(lua_State *L, int index, int family, bool mask);
static cidr_t *L_checkcidr (lua_State *L, int index, cidr_t *p)
{
if (lua_type(L, index) == LUA_TUSERDATA)
return luaL_checkudata(L, index, LUCI_IP_CIDR);
- if (_cidr_new(L, index, p ? p->family : 0))
+ if (_cidr_new(L, index, p ? p->family : 0, false))
return lua_touserdata(L, -1);
luaL_error(L, "Invalid operand");
@@ -284,7 +284,7 @@ static int L_checkbits(lua_State *L, int index, cidr_t *p)
return bits;
}
-static int _cidr_new(lua_State *L, int index, int family)
+static int _cidr_new(lua_State *L, int index, int family, bool mask)
{
uint32_t n;
const char *addr;
@@ -321,6 +321,9 @@ static int _cidr_new(lua_State *L, int index, int family)
if (family && cidr.family != family)
return 0;
+
+ if (mask)
+ cidr.bits = L_checkbits(L, index + 1, &cidr);
}
if (!(cidrp = lua_newuserdata(L, sizeof(*cidrp))))
@@ -334,17 +337,17 @@ static int _cidr_new(lua_State *L, int index, int family)
static int cidr_new(lua_State *L)
{
- return _cidr_new(L, 1, 0);
+ return _cidr_new(L, 1, 0, true);
}
static int cidr_ipv4(lua_State *L)
{
- return _cidr_new(L, 1, AF_INET);
+ return _cidr_new(L, 1, AF_INET, true);
}
static int cidr_ipv6(lua_State *L)
{
- return _cidr_new(L, 1, AF_INET6);
+ return _cidr_new(L, 1, AF_INET6, true);
}
static int cidr_is4(lua_State *L)