summaryrefslogtreecommitdiff
path: root/src/libs6/s6_accessrules_keycheck_ip4.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-01-15 20:14:44 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-01-15 20:14:44 +0000
commit87c5b2118efcee65eeda3f743d081ea9c2b866d9 (patch)
tree31ca07d6134adf44bc3d58f4fcf4ea8be9cb7dbb /src/libs6/s6_accessrules_keycheck_ip4.c
parentcd2500fcc704287c4994a3253b593593c867913e (diff)
downloads6-87c5b2118efcee65eeda3f743d081ea9c2b866d9.tar.xz
Move Unix domain utilities and access control utilites,
as well as the accessrules library, from s6-networking to here
Diffstat (limited to 'src/libs6/s6_accessrules_keycheck_ip4.c')
-rw-r--r--src/libs6/s6_accessrules_keycheck_ip4.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libs6/s6_accessrules_keycheck_ip4.c b/src/libs6/s6_accessrules_keycheck_ip4.c
new file mode 100644
index 0000000..66ace93
--- /dev/null
+++ b/src/libs6/s6_accessrules_keycheck_ip4.c
@@ -0,0 +1,24 @@
+/* ISC license. */
+
+#include <skalibs/uint32.h>
+#include <skalibs/uint.h>
+#include <skalibs/fmtscan.h>
+#include <s6/accessrules.h>
+
+s6_accessrules_result_t s6_accessrules_keycheck_ip4 (void const *key, void *data, s6_accessrules_params_t *params, s6_accessrules_backend_func_t_ref check1)
+{
+ char fmt[IP4_FMT + UINT_FMT + 6] = "ip4/" ;
+ uint32 ip ;
+ unsigned int i = 0 ;
+ uint32_unpack_big((char const *)key, &ip) ;
+ for (; i <= 32 ; i++)
+ {
+ register s6_accessrules_result_t r ;
+ register unsigned int len = 4 + ip4_fmtu32(fmt+4, (i == 32) ? 0 : ip & ~((1U << i) - 1)) ;
+ fmt[len++] = '_' ;
+ len += uint_fmt(fmt + len, 32 - i) ;
+ r = (*check1)(fmt, len, data, params) ;
+ if (r != S6_ACCESSRULES_NOTFOUND) return r ;
+ }
+ return S6_ACCESSRULES_NOTFOUND ;
+}