summaryrefslogtreecommitdiff
path: root/iprule.c
diff options
context:
space:
mode:
authorMatthew Hagan <mnhagan88@gmail.com>2022-01-16 00:21:17 +0000
committerHans Dedecker <dedeckeh@gmail.com>2022-01-22 21:24:16 +0100
commited7187684685430ee6de49e551775badbee39761 (patch)
tree70161fb2b0d0969a8f7cf10d49478ff3c439b737 /iprule.c
parent3043206e94da412eb19dd72ea68edcaca545d84c (diff)
downloadnetifd-ed7187684685430ee6de49e551775badbee39761.tar.gz
iprule: add support for uidrange
Allow for per-user routing policies via the uidrange iprule option. Option allows for a single UID or range of UIDs. Signed-off-by: Matthew Hagan <mnhagan88@gmail.com> Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'iprule.c')
-rw-r--r--iprule.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/iprule.c b/iprule.c
index b9e16a5..0956073 100644
--- a/iprule.c
+++ b/iprule.c
@@ -44,6 +44,7 @@ enum {
RULE_ACTION,
RULE_GOTO,
RULE_SUP_PREFIXLEN,
+ RULE_UIDRANGE,
RULE_DISABLED,
__RULE_MAX
};
@@ -59,6 +60,7 @@ static const struct blobmsg_policy rule_attr[__RULE_MAX] = {
[RULE_FWMARK] = { .name = "mark", .type = BLOBMSG_TYPE_STRING },
[RULE_LOOKUP] = { .name = "lookup", .type = BLOBMSG_TYPE_STRING },
[RULE_SUP_PREFIXLEN] = { .name = "suppress_prefixlength", .type = BLOBMSG_TYPE_INT32 },
+ [RULE_UIDRANGE] = { .name = "uidrange", .type = BLOBMSG_TYPE_STRING },
[RULE_ACTION] = { .name = "action", .type = BLOBMSG_TYPE_STRING },
[RULE_GOTO] = { .name = "goto", .type = BLOBMSG_TYPE_INT32 },
[RULE_DISABLED] = { .name = "disabled", .type = BLOBMSG_TYPE_BOOL },
@@ -282,6 +284,18 @@ iprule_add(struct blob_attr *attr, bool v6)
rule->flags |= IPRULE_SUP_PREFIXLEN;
}
+ if ((cur = tb[RULE_UIDRANGE]) != NULL) {
+ int ret = sscanf(blobmsg_get_string(cur), "%u-%u", &rule->uidrange_start, &rule->uidrange_end);
+
+ if (ret == 1)
+ rule->uidrange_end = rule->uidrange_start;
+ else if (ret != 2) {
+ DPRINTF("Failed to parse UID range: %s\n", (char *) blobmsg_data(cur));
+ goto error;
+ }
+ rule->flags |= IPRULE_UIDRANGE;
+ }
+
if ((cur = tb[RULE_ACTION]) != NULL) {
if (!system_resolve_iprule_action(blobmsg_data(cur), &rule->action)) {
DPRINTF("Failed to parse rule action: %s\n", (char *) blobmsg_data(cur));