]> granicus.if.org Git - ipset/commitdiff
Introduce new operation to get both setname and family
authorJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Wed, 4 Sep 2013 14:49:08 +0000 (16:49 +0200)
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Wed, 4 Sep 2013 14:49:08 +0000 (16:49 +0200)
ip[6]tables set match and SET target need to know the family of the set
in order to reject adding rules which refer to a set with a non-mathcing
family. Currently such rules are silently accepted and then ignored
instead of generating a clear error message to the user, which is not
helpful.

kernel/include/uapi/linux/netfilter/ipset/ip_set.h
kernel/net/netfilter/ipset/ip_set_core.c

index 8024cdf13b700560e9bd0c1f3df1bacbdd90b900..2b61ac44dcc1ee8831932588ae311828f323e0ed 100644 (file)
@@ -250,6 +250,14 @@ struct ip_set_req_get_set {
 #define IP_SET_OP_GET_BYINDEX  0x00000007      /* Get set name by index */
 /* Uses ip_set_req_get_set */
 
+#define IP_SET_OP_GET_FNAME    0x00000008      /* Get set index and family */
+struct ip_set_req_get_set_family {
+       unsigned int op;
+       unsigned int version;
+       unsigned int family;
+       union ip_set_name_index set;
+};
+
 #define IP_SET_OP_VERSION      0x00000100      /* Ask kernel version */
 struct ip_set_req_version {
        unsigned int op;
index 4c95bb8aecf4467caa04161a8ccf6b3a7f21762e..2532c924ef2830dac72d803d94935fe54aec7223 100644 (file)
@@ -1804,6 +1804,23 @@ ip_set_sockfn_get(struct sock *sk, int optval, void __user *user, int *len)
                unlock_nfnl();
                goto copy;
        }
+       case IP_SET_OP_GET_FNAME: {
+               struct ip_set_req_get_set_family *req_get = data;
+               ip_set_id_t id;
+
+               if (*len != sizeof(struct ip_set_req_get_set_family)) {
+                       ret = -EINVAL;
+                       goto done;
+               }
+               req_get->set.name[IPSET_MAXNAMELEN - 1] = '\0';
+               lock_nfnl();
+               find_set_and_id(req_get->set.name, &id);
+               req_get->set.index = id;
+               if (id != IPSET_INVALID_ID)
+                       req_get->family = nfnl_set(id)->family;
+               unlock_nfnl();
+               goto copy;
+       }
        case IP_SET_OP_GET_BYINDEX: {
                struct ip_set_req_get_set *req_get = data;
                struct ip_set *set;