]> granicus.if.org Git - ipset/commitdiff
Correct the error codes: use ENOENT and EMSGSIZE
authorJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Wed, 26 Jan 2011 21:26:01 +0000 (22:26 +0100)
committerJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Wed, 26 Jan 2011 21:26:01 +0000 (22:26 +0100)
Use correct error codes (Patrick McHardy's review)

kernel/include/linux/netfilter/ipset/ip_set_ahash.h
kernel/ip_set_bitmap_ip.c
kernel/ip_set_bitmap_ipmac.c
kernel/ip_set_bitmap_port.c
kernel/ip_set_core.c
kernel/ip_set_list_set.c
src/errcode.c

index 8d4f2590916ff9e5a72106ba23c4720abd3570b7..ac98c2a7ecd5bcd9a2d2d8c01b1725b72ab5ce2f 100644 (file)
@@ -525,7 +525,7 @@ type_pf_head(struct ip_set *set, struct sk_buff *skb)
 
        return 0;
 nla_put_failure:
-       return -EFAULT;
+       return -EMSGSIZE;
 }
 
 /* Reply a LIST/SAVE request: dump the elements of the specified set */
@@ -545,7 +545,7 @@ type_pf_list(const struct ip_set *set,
 
        atd = ipset_nest_start(skb, IPSET_ATTR_ADT);
        if (!atd)
-               return -EFAULT;
+               return -EMSGSIZE;
        pr_debug("list hash set %s\n", set->name);
        for (; cb->args[2] < jhash_size(t->htable_bits); cb->args[2]++) {
                incomplete = skb_tail_pointer(skb);
@@ -559,7 +559,7 @@ type_pf_list(const struct ip_set *set,
                        if (!nested) {
                                if (cb->args[2] == first) {
                                        nla_nest_cancel(skb, atd);
-                                       return -EFAULT;
+                                       return -EMSGSIZE;
                                } else
                                        goto nla_put_failure;
                        }
@@ -581,6 +581,7 @@ nla_put_failure:
                pr_warning("Can't list set %s: one bucket does not fit into "
                           "a message. Please report it!\n", set->name);
                cb->args[2] = 0;
+               return -EMSGSIZE;
        }
        return 0;
 }
@@ -946,7 +947,7 @@ type_pf_tlist(const struct ip_set *set,
 
        atd = ipset_nest_start(skb, IPSET_ATTR_ADT);
        if (!atd)
-               return -EFAULT;
+               return -EMSGSIZE;
        for (; cb->args[2] < jhash_size(t->htable_bits); cb->args[2]++) {
                incomplete = skb_tail_pointer(skb);
                n = hbucket(t, cb->args[2]);
@@ -960,7 +961,7 @@ type_pf_tlist(const struct ip_set *set,
                        if (!nested) {
                                if (cb->args[2] == first) {
                                        nla_nest_cancel(skb, atd);
-                                       return -EFAULT;
+                                       return -EMSGSIZE;
                                } else
                                        goto nla_put_failure;
                        }
@@ -982,6 +983,7 @@ nla_put_failure:
                pr_warning("Can't list set %s: one bucket does not fit into "
                           "a message. Please report it!\n", set->name);
                cb->args[2] = 0;
+               return -EMSGSIZE;
        }
        return 0;
 }
index 4fbb3602f24cda66cf3d3739b297d7a2ff95a732..f97dee22738d1d4dab14a4330ff125a2fb27f573 100644 (file)
@@ -217,7 +217,7 @@ bitmap_ip_head(struct ip_set *set, struct sk_buff *skb)
 
        return 0;
 nla_put_failure:
-       return -EFAULT;
+       return -EMSGSIZE;
 }
 
 static int
@@ -230,7 +230,7 @@ bitmap_ip_list(const struct ip_set *set,
 
        atd = ipset_nest_start(skb, IPSET_ATTR_ADT);
        if (!atd)
-               return -EFAULT;
+               return -EMSGSIZE;
        for (; cb->args[2] < map->elements; cb->args[2]++) {
                id = cb->args[2];
                if (!bitmap_ip_test(map, id))
@@ -239,7 +239,7 @@ bitmap_ip_list(const struct ip_set *set,
                if (!nested) {
                        if (id == first) {
                                nla_nest_cancel(skb, atd);
-                               return -EFAULT;
+                               return -EMSGSIZE;
                        } else
                                goto nla_put_failure;
                }
@@ -255,6 +255,10 @@ bitmap_ip_list(const struct ip_set *set,
 nla_put_failure:
        nla_nest_cancel(skb, nested);
        ipset_nest_end(skb, atd);
+       if (unlikely(id == first)) {
+               cb->args[2] = 0;
+               return -EMSGSIZE;
+       }
        return 0;
 }
 
@@ -461,7 +465,7 @@ bitmap_ip_timeout_head(struct ip_set *set, struct sk_buff *skb)
 
        return 0;
 nla_put_failure:
-       return -EFAULT;
+       return -EMSGSIZE;
 }
 
 static int
@@ -475,7 +479,7 @@ bitmap_ip_timeout_list(const struct ip_set *set,
 
        adt = ipset_nest_start(skb, IPSET_ATTR_ADT);
        if (!adt)
-               return -EFAULT;
+               return -EMSGSIZE;
        for (; cb->args[2] < map->elements; cb->args[2]++) {
                id = cb->args[2];
                if (!bitmap_ip_timeout_test(map, id))
@@ -484,7 +488,7 @@ bitmap_ip_timeout_list(const struct ip_set *set,
                if (!nested) {
                        if (id == first) {
                                nla_nest_cancel(skb, adt);
-                               return -EFAULT;
+                               return -EMSGSIZE;
                        } else
                                goto nla_put_failure;
                }
@@ -504,6 +508,10 @@ bitmap_ip_timeout_list(const struct ip_set *set,
 nla_put_failure:
        nla_nest_cancel(skb, nested);
        ipset_nest_end(skb, adt);
+       if (unlikely(id == first)) {
+               cb->args[2] = 0;
+               return -EMSGSIZE;
+       }
        return 0;
 }
 
index 65cd1ea3aaf166dce448f3f2e8e0bf0a78075156..68fec19f7f2ee806027a2a3fe5e950e8105f8d7f 100644 (file)
@@ -175,7 +175,7 @@ bitmap_ipmac_list(const struct ip_set *set,
 
        atd = ipset_nest_start(skb, IPSET_ATTR_ADT);
        if (!atd)
-               return -EFAULT;
+               return -EMSGSIZE;
        for (; cb->args[2] <= last; cb->args[2]++) {
                id = cb->args[2];
                elem = bitmap_ipmac_elem(map, id);
@@ -185,7 +185,7 @@ bitmap_ipmac_list(const struct ip_set *set,
                if (!nested) {
                        if (id == first) {
                                nla_nest_cancel(skb, atd);
-                               return -EFAULT;
+                               return -EMSGSIZE;
                        } else
                                goto nla_put_failure;
                }
@@ -205,6 +205,10 @@ bitmap_ipmac_list(const struct ip_set *set,
 nla_put_failure:
        nla_nest_cancel(skb, nested);
        ipset_nest_end(skb, atd);
+       if (unlikely(id == first)) {
+               cb->args[2] = 0;
+               return -EMSGSIZE;
+       }
        return 0;
 }
 
@@ -298,7 +302,7 @@ bitmap_ipmac_tlist(const struct ip_set *set,
 
        atd = ipset_nest_start(skb, IPSET_ATTR_ADT);
        if (!atd)
-               return -EFAULT;
+               return -EMSGSIZE;
        for (; cb->args[2] <= last; cb->args[2]++) {
                id = cb->args[2];
                elem = bitmap_ipmac_elem(map, id);
@@ -308,7 +312,7 @@ bitmap_ipmac_tlist(const struct ip_set *set,
                if (!nested) {
                        if (id == first) {
                                nla_nest_cancel(skb, atd);
-                               return -EFAULT;
+                               return -EMSGSIZE;
                        } else
                                goto nla_put_failure;
                }
@@ -331,7 +335,7 @@ bitmap_ipmac_tlist(const struct ip_set *set,
 nla_put_failure:
        nla_nest_cancel(skb, nested);
        ipset_nest_end(skb, atd);
-       return 0;
+       return -EMSGSIZE;
 }
 
 static int
@@ -457,7 +461,7 @@ bitmap_ipmac_head(struct ip_set *set, struct sk_buff *skb)
 
        return 0;
 nla_put_failure:
-       return -EFAULT;
+       return -EMSGSIZE;
 }
 
 static bool
index fbd0aaf4a21a189cb976317c48591650a5fda0c5..3fb7c92380bda7e2eff3a35e126498d7833bd7dc 100644 (file)
@@ -197,7 +197,7 @@ bitmap_port_head(struct ip_set *set, struct sk_buff *skb)
 
        return 0;
 nla_put_failure:
-       return -EFAULT;
+       return -EMSGSIZE;
 }
 
 static int
@@ -211,7 +211,7 @@ bitmap_port_list(const struct ip_set *set,
 
        atd = ipset_nest_start(skb, IPSET_ATTR_ADT);
        if (!atd)
-               return -EFAULT;
+               return -EMSGSIZE;
        for (; cb->args[2] <= last; cb->args[2]++) {
                id = cb->args[2];
                if (!test_bit(id, map->members))
@@ -220,7 +220,7 @@ bitmap_port_list(const struct ip_set *set,
                if (!nested) {
                        if (id == first) {
                                nla_nest_cancel(skb, atd);
-                               return -EFAULT;
+                               return -EMSGSIZE;
                        } else
                                goto nla_put_failure;
                }
@@ -237,6 +237,10 @@ bitmap_port_list(const struct ip_set *set,
 nla_put_failure:
        nla_nest_cancel(skb, nested);
        ipset_nest_end(skb, atd);
+       if (unlikely(id == first)) {
+               cb->args[2] = 0;
+               return -EMSGSIZE;
+       }
        return 0;
 }
 
@@ -432,7 +436,7 @@ bitmap_port_timeout_head(struct ip_set *set, struct sk_buff *skb)
 
        return 0;
 nla_put_failure:
-       return -EFAULT;
+       return -EMSGSIZE;
 }
 
 static int
@@ -447,7 +451,7 @@ bitmap_port_timeout_list(const struct ip_set *set,
 
        adt = ipset_nest_start(skb, IPSET_ATTR_ADT);
        if (!adt)
-               return -EFAULT;
+               return -EMSGSIZE;
        for (; cb->args[2] <= last; cb->args[2]++) {
                id = cb->args[2];
                if (!bitmap_port_timeout_test(map, id))
@@ -456,7 +460,7 @@ bitmap_port_timeout_list(const struct ip_set *set,
                if (!nested) {
                        if (id == first) {
                                nla_nest_cancel(skb, adt);
-                               return -EFAULT;
+                               return -EMSGSIZE;
                        } else
                                goto nla_put_failure;
                }
@@ -476,6 +480,10 @@ bitmap_port_timeout_list(const struct ip_set *set,
 nla_put_failure:
        nla_nest_cancel(skb, nested);
        ipset_nest_end(skb, adt);
+       if (unlikely(id == first)) {
+               cb->args[2] = 0;
+               return -EMSGSIZE;
+       }
        return 0;
 }
 
index aa5d12f695bae1bdd8c062381c6801242378e9c4..023813b973a357af64d67f310d6aa8fc45ceeffe 100644 (file)
@@ -755,7 +755,7 @@ ip_set_destroy(struct sock *ctnl, struct sk_buff *skb,
        } else {
                i = find_set_id(nla_data(attr[IPSET_ATTR_SETNAME]));
                if (i == IPSET_INVALID_ID)
-                       return -EEXIST;
+                       return -ENOENT;
                else if (atomic_read(&ip_set_list[i]->ref))
                        return -IPSET_ERR_BUSY;
 
@@ -793,7 +793,7 @@ ip_set_flush(struct sock *ctnl, struct sk_buff *skb,
        } else {
                i = find_set_id(nla_data(attr[IPSET_ATTR_SETNAME]));
                if (i == IPSET_INVALID_ID)
-                       return -EEXIST;
+                       return -ENOENT;
 
                ip_set_flush_set(ip_set_list[i]);
        }
@@ -828,7 +828,7 @@ ip_set_rename(struct sock *ctnl, struct sk_buff *skb,
 
        set = find_set(nla_data(attr[IPSET_ATTR_SETNAME]));
        if (set == NULL)
-               return -EEXIST;
+               return -ENOENT;
        if (atomic_read(&set->ref) != 0)
                return -IPSET_ERR_REFERENCED;
 
@@ -869,7 +869,7 @@ ip_set_swap(struct sock *ctnl, struct sk_buff *skb,
 
        from_id = find_set_id(nla_data(attr[IPSET_ATTR_SETNAME]));
        if (from_id == IPSET_INVALID_ID)
-               return -EEXIST;
+               return -ENOENT;
 
        to_id = find_set_id(nla_data(attr[IPSET_ATTR_SETNAME2]));
        if (to_id == IPSET_INVALID_ID)
@@ -954,7 +954,7 @@ dump_init(struct netlink_callback *cb)
 
        index = find_set_id(nla_data(cda[IPSET_ATTR_SETNAME]));
        if (index == IPSET_INVALID_ID)
-               return -EEXIST;
+               return -ENOENT;
 
        cb->args[0] = DUMP_ONE;
        cb->args[1] = index;
@@ -990,7 +990,7 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb)
                set = ip_set_list[index];
                if (set == NULL) {
                        if (cb->args[0] == DUMP_ONE) {
-                               ret = -EEXIST;
+                               ret = -ENOENT;
                                goto out;
                        }
                        continue;
@@ -1012,7 +1012,7 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb)
                                cb->nlh->nlmsg_seq, flags,
                                IPSET_CMD_LIST);
                if (!nlh) {
-                       ret = -EFAULT;
+                       ret = -EMSGSIZE;
                        goto release_refcount;
                }
                NLA_PUT_U8(skb, IPSET_ATTR_PROTOCOL, IPSET_PROTOCOL);
@@ -1147,7 +1147,7 @@ ip_set_uadd(struct sock *ctnl, struct sk_buff *skb,
 
        set = find_set(nla_data(attr[IPSET_ATTR_SETNAME]));
        if (set == NULL)
-               return -EEXIST;
+               return -ENOENT;
 
        if (attr[IPSET_ATTR_DATA]) {
                ret = call_ad(skb, attr,
@@ -1191,7 +1191,7 @@ ip_set_udel(struct sock *ctnl, struct sk_buff *skb,
 
        set = find_set(nla_data(attr[IPSET_ATTR_SETNAME]));
        if (set == NULL)
-               return -EEXIST;
+               return -ENOENT;
 
        if (attr[IPSET_ATTR_DATA]) {
                ret = call_ad(skb, attr,
@@ -1228,7 +1228,7 @@ ip_set_utest(struct sock *ctnl, struct sk_buff *skb,
 
        set = find_set(nla_data(attr[IPSET_ATTR_SETNAME]));
        if (set == NULL)
-               return -EEXIST;
+               return -ENOENT;
 
        read_lock_bh(&set->lock);
        ret = set->variant->uadt(set,
@@ -1262,7 +1262,7 @@ ip_set_header(struct sock *ctnl, struct sk_buff *skb,
 
        index = find_set_id(nla_data(attr[IPSET_ATTR_SETNAME]));
        if (index == IPSET_INVALID_ID)
-               return -EEXIST;
+               return -ENOENT;
        set = ip_set_list[index];
 
        skb2 = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
@@ -1282,7 +1282,7 @@ ip_set_header(struct sock *ctnl, struct sk_buff *skb,
 
        ret = netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT);
        if (ret < 0)
-               return -EFAULT;
+               return ret;
 
        return 0;
 
@@ -1290,7 +1290,7 @@ nla_put_failure:
        nlmsg_cancel(skb2, nlh2);
 nlmsg_failure:
        kfree_skb(skb2);
-       return -EFAULT;
+       return -EMSGSIZE;
 }
 
 /* Get type data */
@@ -1342,7 +1342,7 @@ ip_set_type(struct sock *ctnl, struct sk_buff *skb,
        pr_debug("Send TYPE, nlmsg_len: %u\n", nlh2->nlmsg_len);
        ret = netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT);
        if (ret < 0)
-               return -EFAULT;
+               return ret;
 
        return 0;
 
@@ -1350,7 +1350,7 @@ nla_put_failure:
        nlmsg_cancel(skb2, nlh2);
 nlmsg_failure:
        kfree_skb(skb2);
-       return -EFAULT;
+       return -EMSGSIZE;
 }
 
 /* Get protocol version */
@@ -1385,7 +1385,7 @@ ip_set_protocol(struct sock *ctnl, struct sk_buff *skb,
 
        ret = netlink_unicast(ctnl, skb2, NETLINK_CB(skb).pid, MSG_DONTWAIT);
        if (ret < 0)
-               return -EFAULT;
+               return ret;
 
        return 0;
 
@@ -1393,7 +1393,7 @@ nla_put_failure:
        nlmsg_cancel(skb2, nlh2);
 nlmsg_failure:
        kfree_skb(skb2);
-       return -EFAULT;
+       return -EMSGSIZE;
 }
 
 static const struct nfnl_callback ip_set_netlink_subsys_cb[IPSET_MSG_MAX] = {
index 892a106d788afaf2c7c694d9ff91603be2d20b27..933d9ef54664912507da039529d6eab461a2b82a 100644 (file)
@@ -392,7 +392,7 @@ list_set_head(struct ip_set *set, struct sk_buff *skb)
 
        return 0;
 nla_put_failure:
-       return -EFAULT;
+       return -EMSGSIZE;
 }
 
 static int
@@ -406,7 +406,7 @@ list_set_list(const struct ip_set *set,
 
        atd = ipset_nest_start(skb, IPSET_ATTR_ADT);
        if (!atd)
-               return -EFAULT;
+               return -EMSGSIZE;
        for (; cb->args[2] < map->size; cb->args[2]++) {
                i = cb->args[2];
                e = list_set_elem(map, i);
@@ -418,7 +418,7 @@ list_set_list(const struct ip_set *set,
                if (!nested) {
                        if (i == first) {
                                nla_nest_cancel(skb, atd);
-                               return -EFAULT;
+                               return -EMSGSIZE;
                        } else
                                goto nla_put_failure;
                }
@@ -441,6 +441,10 @@ finish:
 nla_put_failure:
        nla_nest_cancel(skb, nested);
        ipset_nest_end(skb, atd);
+       if (unlikely(i == first)) {
+               cb->args[2] = 0;
+               return -EMSGSIZE;
+       }
        return 0;
 }
 
index 00686fadc7ef895b262d4025d0ca7121131ca8aa..36ce58a2b776d49a4f61739249989e1bb30526bd 100644 (file)
 /* Core kernel error codes */
 static const struct ipset_errcode_table core_errcode_table[] = {
        /* Generic error codes */
-       { EEXIST, 0,
+       { ENOENT, 0,
          "The set with the given name does not exist" },
+       { EMSGSIZE, 0,
+         "Kernel error received: message could not be created" },
        { IPSET_ERR_PROTOCOL,  0,
          "Kernel error received: ipset protocol error" },