zones: add interface/subnet bound LOG rules
[project/firewall3.git] / utils.c
diff --git a/utils.c b/utils.c
index 875a141..4f892a7 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -893,3 +893,43 @@ fw3_flush_conntrack(void *state)
 
        freeifaddrs(ifaddr);
 }
+
+bool fw3_attr_parse_name_type(struct blob_attr *entry, const char **name, const char **type)
+{
+       struct blob_attr *opt;
+       unsigned orem;
+
+       if (!type || !name)
+               return false;
+
+       *type = NULL;
+
+       blobmsg_for_each_attr(opt, entry, orem)
+               if (!strcmp(blobmsg_name(opt), "type"))
+                       *type = blobmsg_get_string(opt);
+               else if (!strcmp(blobmsg_name(opt), "name"))
+                       *name = blobmsg_get_string(opt);
+
+       return *type != NULL ? true : false;
+}
+
+const char *
+fw3_protoname(void *proto)
+{
+       static char buf[sizeof("4294967295")];
+       struct fw3_protocol *p = proto;
+       struct protoent *pe;
+
+       if (!p)
+               return "?";
+
+       pe = getprotobynumber(p->protocol);
+
+       if (!pe)
+       {
+               snprintf(buf, sizeof(buf), "%u", p->protocol);
+               return buf;
+       }
+
+       return pe->p_name;
+}