+
+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;
+}
+
+bool
+fw3_check_loopback_dev(const char *name)
+{
+ struct ifreq ifr;
+ int s;
+ bool rv = false;
+
+ s = socket(AF_LOCAL, SOCK_DGRAM, 0);
+
+ if (s < 0)
+ return false;
+
+ memset(&ifr, 0, sizeof(ifr));
+ snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", name);
+
+ if (ioctl(s, SIOCGIFFLAGS, &ifr) >= 0) {
+ if (ifr.ifr_flags & IFF_LOOPBACK)
+ rv = true;
+ }
+
+ close(s);
+
+ return rv;
+}
+
+bool
+fw3_check_loopback_addr(struct fw3_address *addr)
+{
+ if (addr->family == FW3_FAMILY_V4 &&
+ (ntohl(addr->address.v4.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET)
+ return true;
+
+ if (addr->family == FW3_FAMILY_V6 && !addr->range &&
+ fw3_netmask2bitlen(FW3_FAMILY_V6, &addr->mask.v6) == 128 &&
+ IN6_IS_ADDR_LOOPBACK(&addr->address.v6))
+ return true;
+
+ return false;
+}