···1515/* The protocol version */1616#define IPSET_PROTOCOL 617171818-/* The maximum permissible comment length we will accept over netlink */1919-#define IPSET_MAX_COMMENT_SIZE 2552020-2118/* The max length of strings including NUL: set and type identifiers */2219#define IPSET_MAXNAMELEN 322020+2121+/* The maximum permissible comment length we will accept over netlink */2222+#define IPSET_MAX_COMMENT_SIZE 25523232424/* Message types and commands */2525enum ipset_cmd {
+6-5
net/netfilter/ipset/ip_set_bitmap_gen.h
···4141 struct mtype *map = set->data;42424343 init_timer(&map->gc);4444- map->gc.data = (unsigned long) set;4444+ map->gc.data = (unsigned long)set;4545 map->gc.function = gc;4646 map->gc.expires = jiffies + IPSET_GC_PERIOD(set->timeout) * HZ;4747 add_timer(&map->gc);···223223 if (!test_bit(id, map->members) ||224224 (SET_WITH_TIMEOUT(set) &&225225#ifdef IP_SET_BITMAP_STORED_TIMEOUT226226- mtype_is_filled((const struct mtype_elem *) x) &&226226+ mtype_is_filled((const struct mtype_elem *)x) &&227227#endif228228 ip_set_timeout_expired(ext_timeout(x, set))))229229 continue;···240240 if (mtype_do_list(skb, map, id, set->dsize))241241 goto nla_put_failure;242242 if (ip_set_put_extensions(skb, set, x,243243- mtype_is_filled((const struct mtype_elem *) x)))243243+ mtype_is_filled((const struct mtype_elem *)x)))244244 goto nla_put_failure;245245 ipset_nest_end(skb, nested);246246 }···266266static void267267mtype_gc(unsigned long ul_set)268268{269269- struct ip_set *set = (struct ip_set *) ul_set;269269+ struct ip_set *set = (struct ip_set *)ul_set;270270 struct mtype *map = set->data;271271 void *x;272272 u32 id;273273274274 /* We run parallel with other readers (test element)275275- * but adding/deleting new entries is locked out */275275+ * but adding/deleting new entries is locked out276276+ */276277 spin_lock_bh(&set->lock);277278 for (id = 0; id < map->elements; id++)278279 if (mtype_gc_test(id, map, set->dsize)) {
···9090 return 0;9191 elem = get_elem(map->extensions, e->id, dsize);9292 if (elem->filled == MAC_FILLED)9393- return e->ether == NULL ||9393+ return !e->ether ||9494 ether_addr_equal(e->ether, elem->ether);9595 /* Trigger kernel to fill out the ethernet address */9696 return -EAGAIN;···131131 /* If MAC is unset yet, we store plain timeout value132132 * because the timer is not activated yet133133 * and we can reuse it later when MAC is filled out,134134- * possibly by the kernel */134134+ * possibly by the kernel135135+ */135136 if (e->ether)136137 ip_set_timeout_set(timeout, t);137138 else···156155 /* memcpy isn't atomic */157156 clear_bit(e->id, map->members);158157 smp_mb__after_atomic();159159- memcpy(elem->ether, e->ether, ETH_ALEN);158158+ ether_addr_copy(elem->ether, e->ether);160159 }161160 return IPSET_ADD_FAILED;162161 } else if (!e->ether)···165164 /* Fill the MAC address and trigger the timer activation */166165 clear_bit(e->id, map->members);167166 smp_mb__after_atomic();168168- memcpy(elem->ether, e->ether, ETH_ALEN);167167+ ether_addr_copy(elem->ether, e->ether);169168 elem->filled = MAC_FILLED;170169 return IPSET_ADD_START_STORED_TIMEOUT;171170 } else if (e->ether) {172171 /* We can store MAC too */173173- memcpy(elem->ether, e->ether, ETH_ALEN);172172+ ether_addr_copy(elem->ether, e->ether);174173 elem->filled = MAC_FILLED;175174 return 0;176176- } else {177177- elem->filled = MAC_UNSET;178178- /* MAC is not stored yet, don't start timer */179179- return IPSET_ADD_STORE_PLAIN_TIMEOUT;180175 }176176+ elem->filled = MAC_UNSET;177177+ /* MAC is not stored yet, don't start timer */178178+ return IPSET_ADD_STORE_PLAIN_TIMEOUT;181179}182180183181static inline int···352352 if (cidr >= HOST_MASK)353353 return -IPSET_ERR_INVALID_CIDR;354354 ip_set_mask_from_to(first_ip, last_ip, cidr);355355- } else355355+ } else {356356 return -IPSET_ERR_PROTOCOL;357357+ }357358358359 elements = (u64)last_ip - first_ip + 1;359360
···3535 bool is_deleted; /* deleted by ip_set_net_exit */3636 bool is_destroyed; /* all sets are destroyed */3737};3838+3839static int ip_set_net_id __read_mostly;39404041static inline struct ip_set_net *ip_set_pernet(struct net *net)···6160#define ip_set(inst, id) \6261 ip_set_dereference((inst)->ip_set_list)[id]63626464-/*6565- * The set types are implemented in modules and registered set types6363+/* The set types are implemented in modules and registered set types6664 * can be found in ip_set_type_list. Adding/deleting types is6765 * serialized by ip_set_type_mutex.6866 */···131131 goto unlock;132132 }133133 /* Make sure the type is already loaded134134- * but we don't support the revision */134134+ * but we don't support the revision135135+ */135136 list_for_each_entry_rcu(type, &ip_set_type_list, list)136137 if (STRNCMP(type->name, name)) {137138 err = -IPSET_ERR_FIND_TYPE;···291290int292291ip_set_get_ipaddr4(struct nlattr *nla, __be32 *ipaddr)293292{294294- struct nlattr *tb[IPSET_ATTR_IPADDR_MAX+1];293293+ struct nlattr *tb[IPSET_ATTR_IPADDR_MAX + 1];295294296295 if (unlikely(!flag_nested(nla)))297296 return -IPSET_ERR_PROTOCOL;···308307int309308ip_set_get_ipaddr6(struct nlattr *nla, union nf_inet_addr *ipaddr)310309{311311- struct nlattr *tb[IPSET_ATTR_IPADDR_MAX+1];310310+ struct nlattr *tb[IPSET_ATTR_IPADDR_MAX + 1];312311313312 if (unlikely(!flag_nested(nla)))314313 return -IPSET_ERR_PROTOCOL;···319318 return -IPSET_ERR_PROTOCOL;320319321320 memcpy(ipaddr, nla_data(tb[IPSET_ATTR_IPADDR_IPV6]),322322- sizeof(struct in6_addr));321321+ sizeof(struct in6_addr));323322 return 0;324323}325324EXPORT_SYMBOL_GPL(ip_set_get_ipaddr6);···468467}469468EXPORT_SYMBOL_GPL(ip_set_put_extensions);470469471471-/*472472- * Creating/destroying/renaming/swapping affect the existence and470470+/* Creating/destroying/renaming/swapping affect the existence and473471 * the properties of a set. All of these can be executed from userspace474472 * only and serialized by the nfnl mutex indirectly from nfnetlink.475473 *···495495 write_unlock_bh(&ip_set_ref_lock);496496}497497498498-/*499499- * Add, del and test set entries from kernel.498498+/* Add, del and test set entries from kernel.500499 *501500 * The set behind the index must exist and must be referenced502501 * so it can't be destroyed (or changed) under our foot.···523524 dev_net(par->in ? par->in : par->out), index);524525 int ret = 0;525526526526- BUG_ON(set == NULL);527527+ BUG_ON(!set);527528 pr_debug("set %s, index %u\n", set->name, index);528529529530 if (opt->dim < set->type->dimension ||···562563 dev_net(par->in ? par->in : par->out), index);563564 int ret;564565565565- BUG_ON(set == NULL);566566+ BUG_ON(!set);566567 pr_debug("set %s, index %u\n", set->name, index);567568568569 if (opt->dim < set->type->dimension ||···585586 dev_net(par->in ? par->in : par->out), index);586587 int ret = 0;587588588588- BUG_ON(set == NULL);589589+ BUG_ON(!set);589590 pr_debug("set %s, index %u\n", set->name, index);590591591592 if (opt->dim < set->type->dimension ||···600601}601602EXPORT_SYMBOL_GPL(ip_set_del);602603603603-/*604604- * Find set by name, reference it once. The reference makes sure the604604+/* Find set by name, reference it once. The reference makes sure the605605 * thing pointed to, does not go away under our feet.606606 *607607 */···614616 rcu_read_lock();615617 for (i = 0; i < inst->ip_set_max; i++) {616618 s = rcu_dereference(inst->ip_set_list)[i];617617- if (s != NULL && STRNCMP(s->name, name)) {619619+ if (s && STRNCMP(s->name, name)) {618620 __ip_set_get(s);619621 index = i;620622 *set = s;···627629}628630EXPORT_SYMBOL_GPL(ip_set_get_byname);629631630630-/*631631- * If the given set pointer points to a valid set, decrement632632+/* If the given set pointer points to a valid set, decrement632633 * reference count by 1. The caller shall not assume the index633634 * to be valid, after calling this function.634635 *···640643641644 rcu_read_lock();642645 set = rcu_dereference(inst->ip_set_list)[index];643643- if (set != NULL)646646+ if (set)644647 __ip_set_put(set);645648 rcu_read_unlock();646649}···654657}655658EXPORT_SYMBOL_GPL(ip_set_put_byindex);656659657657-/*658658- * Get the name of a set behind a set index.660660+/* Get the name of a set behind a set index.659661 * We assume the set is referenced, so it does exist and660662 * can't be destroyed. The set cannot be renamed due to661663 * the referencing either.···665669{666670 const struct ip_set *set = ip_set_rcu_get(net, index);667671668668- BUG_ON(set == NULL);672672+ BUG_ON(!set);669673 BUG_ON(set->ref == 0);670674671675 /* Referenced, so it's safe */···673677}674678EXPORT_SYMBOL_GPL(ip_set_name_byindex);675679676676-/*677677- * Routines to call by external subsystems, which do not680680+/* Routines to call by external subsystems, which do not678681 * call nfnl_lock for us.679682 */680683681681-/*682682- * Find set by index, reference it once. The reference makes sure the684684+/* Find set by index, reference it once. The reference makes sure the683685 * thing pointed to, does not go away under our feet.684686 *685687 * The nfnl mutex is used in the function.···703709}704710EXPORT_SYMBOL_GPL(ip_set_nfnl_get_byindex);705711706706-/*707707- * If the given set pointer points to a valid set, decrement712712+/* If the given set pointer points to a valid set, decrement708713 * reference count by 1. The caller shall not assume the index709714 * to be valid, after calling this function.710715 *···718725 nfnl_lock(NFNL_SUBSYS_IPSET);719726 if (!inst->is_deleted) { /* already deleted from ip_set_net_exit() */720727 set = ip_set(inst, index);721721- if (set != NULL)728728+ if (set)722729 __ip_set_put(set);723730 }724731 nfnl_unlock(NFNL_SUBSYS_IPSET);725732}726733EXPORT_SYMBOL_GPL(ip_set_nfnl_put);727734728728-/*729729- * Communication protocol with userspace over netlink.735735+/* Communication protocol with userspace over netlink.730736 *731737 * The commands are serialized by the nfnl mutex.732738 */···752760753761 nlh = nlmsg_put(skb, portid, seq, cmd | (NFNL_SUBSYS_IPSET << 8),754762 sizeof(*nfmsg), flags);755755- if (nlh == NULL)763763+ if (!nlh)756764 return NULL;757765758766 nfmsg = nlmsg_data(nlh);···785793 *id = IPSET_INVALID_ID;786794 for (i = 0; i < inst->ip_set_max; i++) {787795 set = ip_set(inst, i);788788- if (set != NULL && STRNCMP(set->name, name)) {796796+ if (set && STRNCMP(set->name, name)) {789797 *id = i;790798 break;791799 }···811819 *index = IPSET_INVALID_ID;812820 for (i = 0; i < inst->ip_set_max; i++) {813821 s = ip_set(inst, i);814814- if (s == NULL) {822822+ if (!s) {815823 if (*index == IPSET_INVALID_ID)816824 *index = i;817825 } else if (STRNCMP(name, s->name)) {···843851 struct ip_set_net *inst = ip_set_pernet(net);844852 struct ip_set *set, *clash = NULL;845853 ip_set_id_t index = IPSET_INVALID_ID;846846- struct nlattr *tb[IPSET_ATTR_CREATE_MAX+1] = {};854854+ struct nlattr *tb[IPSET_ATTR_CREATE_MAX + 1] = {};847855 const char *name, *typename;848856 u8 family, revision;849857 u32 flags = flag_exist(nlh);850858 int ret = 0;851859852860 if (unlikely(protocol_failed(attr) ||853853- attr[IPSET_ATTR_SETNAME] == NULL ||854854- attr[IPSET_ATTR_TYPENAME] == NULL ||855855- attr[IPSET_ATTR_REVISION] == NULL ||856856- attr[IPSET_ATTR_FAMILY] == NULL ||857857- (attr[IPSET_ATTR_DATA] != NULL &&861861+ !attr[IPSET_ATTR_SETNAME] ||862862+ !attr[IPSET_ATTR_TYPENAME] ||863863+ !attr[IPSET_ATTR_REVISION] ||864864+ !attr[IPSET_ATTR_FAMILY] ||865865+ (attr[IPSET_ATTR_DATA] &&858866 !flag_nested(attr[IPSET_ATTR_DATA]))))859867 return -IPSET_ERR_PROTOCOL;860868···865873 pr_debug("setname: %s, typename: %s, family: %s, revision: %u\n",866874 name, typename, family_name(family), revision);867875868868- /*869869- * First, and without any locks, allocate and initialize876876+ /* First, and without any locks, allocate and initialize870877 * a normal base set structure.871878 */872872- set = kzalloc(sizeof(struct ip_set), GFP_KERNEL);879879+ set = kzalloc(sizeof(*set), GFP_KERNEL);873880 if (!set)874881 return -ENOMEM;875882 spin_lock_init(&set->lock);···876885 set->family = family;877886 set->revision = revision;878887879879- /*880880- * Next, check that we know the type, and take888888+ /* Next, check that we know the type, and take881889 * a reference on the type, to make sure it stays available882890 * while constructing our new set.883891 *884892 * After referencing the type, we try to create the type885893 * specific part of the set without holding any locks.886894 */887887- ret = find_set_type_get(typename, family, revision, &(set->type));895895+ ret = find_set_type_get(typename, family, revision, &set->type);888896 if (ret)889897 goto out;890898891891- /*892892- * Without holding any locks, create private part.893893- */899899+ /* Without holding any locks, create private part. */894900 if (attr[IPSET_ATTR_DATA] &&895901 nla_parse_nested(tb, IPSET_ATTR_CREATE_MAX, attr[IPSET_ATTR_DATA],896902 set->type->create_policy)) {···901913902914 /* BTW, ret==0 here. */903915904904- /*905905- * Here, we have a valid, constructed set and we are protected916916+ /* Here, we have a valid, constructed set and we are protected906917 * by the nfnl mutex. Find the first free index in ip_set_list907918 * and check clashing.908919 */···924937 /* Wraparound */925938 goto cleanup;926939927927- list = kzalloc(sizeof(struct ip_set *) * i, GFP_KERNEL);940940+ list = kcalloc(i, sizeof(struct ip_set *), GFP_KERNEL);928941 if (!list)929942 goto cleanup;930943 /* nfnl mutex is held, both lists are valid */···938951 inst->ip_set_max = i;939952 kfree(tmp);940953 ret = 0;941941- } else if (ret)954954+ } else if (ret) {942955 goto cleanup;956956+ }943957944944- /*945945- * Finally! Add our shiny new set to the list, and be done.946946- */958958+ /* Finally! Add our shiny new set to the list, and be done. */947959 pr_debug("create: '%s' created with index %u!\n", set->name, index);948960 ip_set(inst, index) = set;949961···10041018 if (!attr[IPSET_ATTR_SETNAME]) {10051019 for (i = 0; i < inst->ip_set_max; i++) {10061020 s = ip_set(inst, i);10071007- if (s != NULL && s->ref) {10211021+ if (s && s->ref) {10081022 ret = -IPSET_ERR_BUSY;10091023 goto out;10101024 }···10231037 } else {10241038 s = find_set_and_id(inst, nla_data(attr[IPSET_ATTR_SETNAME]),10251039 &i);10261026- if (s == NULL) {10401040+ if (!s) {10271041 ret = -ENOENT;10281042 goto out;10291043 } else if (s->ref) {···10681082 if (!attr[IPSET_ATTR_SETNAME]) {10691083 for (i = 0; i < inst->ip_set_max; i++) {10701084 s = ip_set(inst, i);10711071- if (s != NULL)10851085+ if (s)10721086 ip_set_flush_set(s);10731087 }10741088 } else {10751089 s = find_set(inst, nla_data(attr[IPSET_ATTR_SETNAME]));10761076- if (s == NULL)10901090+ if (!s)10771091 return -ENOENT;1078109210791093 ip_set_flush_set(s);···11051119 int ret = 0;1106112011071121 if (unlikely(protocol_failed(attr) ||11081108- attr[IPSET_ATTR_SETNAME] == NULL ||11091109- attr[IPSET_ATTR_SETNAME2] == NULL))11221122+ !attr[IPSET_ATTR_SETNAME] ||11231123+ !attr[IPSET_ATTR_SETNAME2]))11101124 return -IPSET_ERR_PROTOCOL;1111112511121126 set = find_set(inst, nla_data(attr[IPSET_ATTR_SETNAME]));11131113- if (set == NULL)11271127+ if (!set)11141128 return -ENOENT;1115112911161130 read_lock_bh(&ip_set_ref_lock);···11221136 name2 = nla_data(attr[IPSET_ATTR_SETNAME2]);11231137 for (i = 0; i < inst->ip_set_max; i++) {11241138 s = ip_set(inst, i);11251125- if (s != NULL && STRNCMP(s->name, name2)) {11391139+ if (s && STRNCMP(s->name, name2)) {11261140 ret = -IPSET_ERR_EXIST_SETNAME2;11271141 goto out;11281142 }···11541168 char from_name[IPSET_MAXNAMELEN];1155116911561170 if (unlikely(protocol_failed(attr) ||11571157- attr[IPSET_ATTR_SETNAME] == NULL ||11581158- attr[IPSET_ATTR_SETNAME2] == NULL))11711171+ !attr[IPSET_ATTR_SETNAME] ||11721172+ !attr[IPSET_ATTR_SETNAME2]))11591173 return -IPSET_ERR_PROTOCOL;1160117411611175 from = find_set_and_id(inst, nla_data(attr[IPSET_ATTR_SETNAME]),11621176 &from_id);11631163- if (from == NULL)11771177+ if (!from)11641178 return -ENOENT;1165117911661180 to = find_set_and_id(inst, nla_data(attr[IPSET_ATTR_SETNAME2]),11671181 &to_id);11681168- if (to == NULL)11821182+ if (!to)11691183 return -IPSET_ERR_EXIST_SETNAME2;1170118411711185 /* Features must not change.11721172- * Not an artificial restriction anymore, as we must prevent11731173- * possible loops created by swapping in setlist type of sets. */11861186+ * Not an artifical restriction anymore, as we must prevent11871187+ * possible loops created by swapping in setlist type of sets.11881188+ */11741189 if (!(from->type->features == to->type->features &&11751190 from->family == to->family))11761191 return -IPSET_ERR_TYPE_MISMATCH;···12331246{12341247 struct nlmsghdr *nlh = nlmsg_hdr(cb->skb);12351248 int min_len = nlmsg_total_size(sizeof(struct nfgenmsg));12361236- struct nlattr *cda[IPSET_ATTR_CMD_MAX+1];12491249+ struct nlattr *cda[IPSET_ATTR_CMD_MAX + 1];12371250 struct nlattr *attr = (void *)nlh + min_len;12381251 u32 dump_type;12391252 ip_set_id_t index;···1247126012481261 set = find_set_and_id(inst, nla_data(cda[IPSET_ATTR_SETNAME]),12491262 &index);12501250- if (set == NULL)12631263+ if (!set)12511264 return -ENOENT;1252126512531266 dump_type = DUMP_ONE;12541267 cb->args[IPSET_CB_INDEX] = index;12551255- } else12681268+ } else {12561269 dump_type = DUMP_ALL;12701270+ }1257127112581272 if (cda[IPSET_ATTR_FLAGS]) {12591273 u32 f = ip_set_get_h32(cda[IPSET_ATTR_FLAGS]);12741274+12601275 dump_type |= (f << 16);12611276 }12621277 cb->args[IPSET_CB_NET] = (unsigned long)inst;···12841295 if (ret < 0) {12851296 nlh = nlmsg_hdr(cb->skb);12861297 /* We have to create and send the error message12871287- * manually :-( */12981298+ * manually :-(12991299+ */12881300 if (nlh->nlmsg_flags & NLM_F_ACK)12891301 netlink_ack(cb->skb, nlh, ret);12901302 return ret;···13031313 pr_debug("dump type, flag: %u %u index: %ld\n",13041314 dump_type, dump_flags, cb->args[IPSET_CB_INDEX]);13051315 for (; cb->args[IPSET_CB_INDEX] < max; cb->args[IPSET_CB_INDEX]++) {13061306- index = (ip_set_id_t) cb->args[IPSET_CB_INDEX];13161316+ index = (ip_set_id_t)cb->args[IPSET_CB_INDEX];13071317 write_lock_bh(&ip_set_ref_lock);13081318 set = ip_set(inst, index);13091319 is_destroyed = inst->is_destroyed;···14701480 size_t payload = min(SIZE_MAX,14711481 sizeof(*errmsg) + nlmsg_len(nlh));14721482 int min_len = nlmsg_total_size(sizeof(struct nfgenmsg));14731473- struct nlattr *cda[IPSET_ATTR_CMD_MAX+1];14831483+ struct nlattr *cda[IPSET_ATTR_CMD_MAX + 1];14741484 struct nlattr *cmdattr;14751485 u32 *errline;1476148614771487 skb2 = nlmsg_new(payload, GFP_KERNEL);14781478- if (skb2 == NULL)14881488+ if (!skb2)14791489 return -ENOMEM;14801490 rep = __nlmsg_put(skb2, NETLINK_CB(skb).portid,14811491 nlh->nlmsg_seq, NLMSG_ERROR, payload, 0);···1492150214931503 *errline = lineno;1494150414951495- netlink_unicast(ctnl, skb2, NETLINK_CB(skb).portid, MSG_DONTWAIT);15051505+ netlink_unicast(ctnl, skb2, NETLINK_CB(skb).portid,15061506+ MSG_DONTWAIT);14961507 /* Signal netlink not to send its ACK/errmsg. */14971508 return -EINTR;14981509 }···15081517{15091518 struct ip_set_net *inst = ip_set_pernet(sock_net(ctnl));15101519 struct ip_set *set;15111511- struct nlattr *tb[IPSET_ATTR_ADT_MAX+1] = {};15201520+ struct nlattr *tb[IPSET_ATTR_ADT_MAX + 1] = {};15121521 const struct nlattr *nla;15131522 u32 flags = flag_exist(nlh);15141523 bool use_lineno;15151524 int ret = 0;1516152515171526 if (unlikely(protocol_failed(attr) ||15181518- attr[IPSET_ATTR_SETNAME] == NULL ||15271527+ !attr[IPSET_ATTR_SETNAME] ||15191528 !((attr[IPSET_ATTR_DATA] != NULL) ^15201529 (attr[IPSET_ATTR_ADT] != NULL)) ||15211521- (attr[IPSET_ATTR_DATA] != NULL &&15301530+ (attr[IPSET_ATTR_DATA] &&15221531 !flag_nested(attr[IPSET_ATTR_DATA])) ||15231523- (attr[IPSET_ATTR_ADT] != NULL &&15321532+ (attr[IPSET_ATTR_ADT] &&15241533 (!flag_nested(attr[IPSET_ATTR_ADT]) ||15251525- attr[IPSET_ATTR_LINENO] == NULL))))15341534+ !attr[IPSET_ATTR_LINENO]))))15261535 return -IPSET_ERR_PROTOCOL;1527153615281537 set = find_set(inst, nla_data(attr[IPSET_ATTR_SETNAME]));15291529- if (set == NULL)15381538+ if (!set)15301539 return -ENOENT;1531154015321541 use_lineno = !!attr[IPSET_ATTR_LINENO];···15631572{15641573 struct ip_set_net *inst = ip_set_pernet(sock_net(ctnl));15651574 struct ip_set *set;15661566- struct nlattr *tb[IPSET_ATTR_ADT_MAX+1] = {};15751575+ struct nlattr *tb[IPSET_ATTR_ADT_MAX + 1] = {};15671576 const struct nlattr *nla;15681577 u32 flags = flag_exist(nlh);15691578 bool use_lineno;15701579 int ret = 0;1571158015721581 if (unlikely(protocol_failed(attr) ||15731573- attr[IPSET_ATTR_SETNAME] == NULL ||15821582+ !attr[IPSET_ATTR_SETNAME] ||15741583 !((attr[IPSET_ATTR_DATA] != NULL) ^15751584 (attr[IPSET_ATTR_ADT] != NULL)) ||15761576- (attr[IPSET_ATTR_DATA] != NULL &&15851585+ (attr[IPSET_ATTR_DATA] &&15771586 !flag_nested(attr[IPSET_ATTR_DATA])) ||15781578- (attr[IPSET_ATTR_ADT] != NULL &&15871587+ (attr[IPSET_ATTR_ADT] &&15791588 (!flag_nested(attr[IPSET_ATTR_ADT]) ||15801580- attr[IPSET_ATTR_LINENO] == NULL))))15891589+ !attr[IPSET_ATTR_LINENO]))))15811590 return -IPSET_ERR_PROTOCOL;1582159115831592 set = find_set(inst, nla_data(attr[IPSET_ATTR_SETNAME]));15841584- if (set == NULL)15931593+ if (!set)15851594 return -ENOENT;1586159515871596 use_lineno = !!attr[IPSET_ATTR_LINENO];···16181627{16191628 struct ip_set_net *inst = ip_set_pernet(sock_net(ctnl));16201629 struct ip_set *set;16211621- struct nlattr *tb[IPSET_ATTR_ADT_MAX+1] = {};16301630+ struct nlattr *tb[IPSET_ATTR_ADT_MAX + 1] = {};16221631 int ret = 0;1623163216241633 if (unlikely(protocol_failed(attr) ||16251625- attr[IPSET_ATTR_SETNAME] == NULL ||16261626- attr[IPSET_ATTR_DATA] == NULL ||16341634+ !attr[IPSET_ATTR_SETNAME] ||16351635+ !attr[IPSET_ATTR_DATA] ||16271636 !flag_nested(attr[IPSET_ATTR_DATA])))16281637 return -IPSET_ERR_PROTOCOL;1629163816301639 set = find_set(inst, nla_data(attr[IPSET_ATTR_SETNAME]));16311631- if (set == NULL)16401640+ if (!set)16321641 return -ENOENT;1633164216341643 if (nla_parse_nested(tb, IPSET_ATTR_ADT_MAX, attr[IPSET_ATTR_DATA],···16591668 int ret = 0;1660166916611670 if (unlikely(protocol_failed(attr) ||16621662- attr[IPSET_ATTR_SETNAME] == NULL))16711671+ !attr[IPSET_ATTR_SETNAME]))16631672 return -IPSET_ERR_PROTOCOL;1664167316651674 set = find_set(inst, nla_data(attr[IPSET_ATTR_SETNAME]));16661666- if (set == NULL)16751675+ if (!set)16671676 return -ENOENT;1668167716691678 skb2 = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);16701670- if (skb2 == NULL)16791679+ if (!skb2)16711680 return -ENOMEM;1672168116731682 nlh2 = start_msg(skb2, NETLINK_CB(skb).portid, nlh->nlmsg_seq, 0,···17161725 int ret = 0;1717172617181727 if (unlikely(protocol_failed(attr) ||17191719- attr[IPSET_ATTR_TYPENAME] == NULL ||17201720- attr[IPSET_ATTR_FAMILY] == NULL))17281728+ !attr[IPSET_ATTR_TYPENAME] ||17291729+ !attr[IPSET_ATTR_FAMILY]))17211730 return -IPSET_ERR_PROTOCOL;1722173117231732 family = nla_get_u8(attr[IPSET_ATTR_FAMILY]);···17271736 return ret;1728173717291738 skb2 = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);17301730- if (skb2 == NULL)17391739+ if (!skb2)17311740 return -ENOMEM;1732174117331742 nlh2 = start_msg(skb2, NETLINK_CB(skb).portid, nlh->nlmsg_seq, 0,···17721781 struct nlmsghdr *nlh2;17731782 int ret = 0;1774178317751775- if (unlikely(attr[IPSET_ATTR_PROTOCOL] == NULL))17841784+ if (unlikely(!attr[IPSET_ATTR_PROTOCOL]))17761785 return -IPSET_ERR_PROTOCOL;1777178617781787 skb2 = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);17791779- if (skb2 == NULL)17881788+ if (!skb2)17801789 return -ENOMEM;1781179017821791 nlh2 = start_msg(skb2, NETLINK_CB(skb).portid, nlh->nlmsg_seq, 0,···19041913 ret = -EFAULT;19051914 goto done;19061915 }19071907- op = (unsigned int *) data;19161916+ op = (unsigned int *)data;1908191719091918 if (*op < IP_SET_OP_VERSION) {19101919 /* Check the version at the beginning of operations */···20162025 if (inst->ip_set_max >= IPSET_INVALID_ID)20172026 inst->ip_set_max = IPSET_INVALID_ID - 1;2018202720192019- list = kzalloc(sizeof(struct ip_set *) * inst->ip_set_max, GFP_KERNEL);20282028+ list = kcalloc(inst->ip_set_max, sizeof(struct ip_set *), GFP_KERNEL);20202029 if (!list)20212030 return -ENOMEM;20222031 inst->is_deleted = false;···20522061 .size = sizeof(struct ip_set_net)20532062};2054206320552055-20562064static int __init20572065ip_set_init(void)20582066{20592067 int ret = nfnetlink_subsys_register(&ip_set_netlink_subsys);20682068+20602069 if (ret != 0) {20612070 pr_err("ip_set: cannot register with nfnetlink.\n");20622071 return ret;
+7-6
net/netfilter/ipset/ip_set_getport.c
···3030 const struct tcphdr *th;31313232 th = skb_header_pointer(skb, protooff, sizeof(_tcph), &_tcph);3333- if (th == NULL)3333+ if (!th)3434 /* No choice either */3535 return false;3636···4242 const sctp_sctphdr_t *sh;43434444 sh = skb_header_pointer(skb, protooff, sizeof(_sh), &_sh);4545- if (sh == NULL)4545+ if (!sh)4646 /* No choice either */4747 return false;4848···5555 const struct udphdr *uh;56565757 uh = skb_header_pointer(skb, protooff, sizeof(_udph), &_udph);5858- if (uh == NULL)5858+ if (!uh)5959 /* No choice either */6060 return false;6161···6767 const struct icmphdr *ic;68686969 ic = skb_header_pointer(skb, protooff, sizeof(_ich), &_ich);7070- if (ic == NULL)7070+ if (!ic)7171 return false;72727373 *port = (__force __be16)htons((ic->type << 8) | ic->code);···7878 const struct icmp6hdr *ic;79798080 ic = skb_header_pointer(skb, protooff, sizeof(_ich), &_ich);8181- if (ic == NULL)8181+ if (!ic)8282 return false;83838484 *port = (__force __be16)···116116 return false;117117 default:118118 /* Other protocols doesn't have ports,119119- so we can match fragments */119119+ * so we can match fragments.120120+ */120121 *proto = protocol;121122 return true;122123 }
+31-24
net/netfilter/ipset/ip_set_hash_gen.h
···3535/* Number of elements to store in an initial array block */3636#define AHASH_INIT_SIZE 43737/* Max number of elements to store in an array block */3838-#define AHASH_MAX_SIZE (3*AHASH_INIT_SIZE)3838+#define AHASH_MAX_SIZE (3 * AHASH_INIT_SIZE)3939/* Max muber of elements in the array block when tuned */4040#define AHASH_MAX_TUNED 644141···5757 */5858 return n > curr && n <= AHASH_MAX_TUNED ? n : curr;5959}6060+6061#define TUNE_AHASH_MAX(h, multi) \6162 ((h)->ahash_max = tune_ahash_max((h)->ahash_max, multi))6263#else···257256#endif258257259258#define HKEY(data, initval, htable_bits) \260260-(jhash2((u32 *)(data), HKEY_DATALEN/sizeof(u32), initval) \259259+(jhash2((u32 *)(data), HKEY_DATALEN / sizeof(u32), initval) \261260 & jhash_mask(htable_bits))262261263262#ifndef htype···300299301300 /* Add in increasing prefix order, so larger cidr first */302301 for (i = 0, j = -1; i < nets_length && h->nets[i].cidr[n]; i++) {303303- if (j != -1)302302+ if (j != -1) {304303 continue;305305- else if (h->nets[i].cidr[n] < cidr)304304+ } else if (h->nets[i].cidr[n] < cidr) {306305 j = i;307307- else if (h->nets[i].cidr[n] == cidr) {306306+ } else if (h->nets[i].cidr[n] == cidr) {308307 h->nets[cidr - 1].nets[n]++;309308 return;310309 }···323322 u8 i, j, net_end = nets_length - 1;324323325324 for (i = 0; i < nets_length; i++) {326326- if (h->nets[i].cidr[n] != cidr)327327- continue;325325+ if (h->nets[i].cidr[n] != cidr)326326+ continue;328327 h->nets[cidr - 1].nets[n]--;329328 if (h->nets[cidr - 1].nets[n] > 0)330330- return;329329+ return;331330 for (j = i; j < net_end && h->nets[j].cidr[n]; j++)332332- h->nets[j].cidr[n] = h->nets[j + 1].cidr[n];331331+ h->nets[j].cidr[n] = h->nets[j + 1].cidr[n];333332 h->nets[j].cidr[n] = 0;334334- return;333333+ return;335334 }336335}337336#endif···427426 if (SET_WITH_TIMEOUT(set))428427 del_timer_sync(&h->gc);429428430430- mtype_ahash_destroy(set, __ipset_dereference_protected(h->table, 1),431431- true);429429+ mtype_ahash_destroy(set,430430+ __ipset_dereference_protected(h->table, 1), true);432431 kfree(h);433432434433 set->data = NULL;···440439 struct htype *h = set->data;441440442441 init_timer(&h->gc);443443- h->gc.data = (unsigned long) set;442442+ h->gc.data = (unsigned long)set;444443 h->gc.function = gc;445444 h->gc.expires = jiffies + IPSET_GC_PERIOD(set->timeout) * HZ;446445 add_timer(&h->gc);···531530static void532531mtype_gc(unsigned long ul_set)533532{534534- struct ip_set *set = (struct ip_set *) ul_set;533533+ struct ip_set *set = (struct ip_set *)ul_set;535534 struct htype *h = set->data;536535537536 pr_debug("called\n");···545544546545/* Resize a hash: create a new hash table with doubling the hashsize547546 * and inserting the elements to it. Repeat until we succeed or548548- * fail due to memory pressures. */547547+ * fail due to memory pressures.548548+ */549549static int550550mtype_resize(struct ip_set *set, bool retried)551551{···689687}690688691689/* Add an element to a hash and update the internal counters when succeeded,692692- * otherwise report the proper error code. */690690+ * otherwise report the proper error code.691691+ */693692static int694693mtype_add(struct ip_set *set, void *value, const struct ip_set_ext *ext,695694 struct ip_set_ext *mext, u32 flags)···929926930927#ifdef IP_SET_HASH_WITH_NETS931928/* Special test function which takes into account the different network932932- * sizes added to the set */929929+ * sizes added to the set930930+ */933931static int934932mtype_test_cidrs(struct ip_set *set, struct mtype_elem *d,935933 const struct ip_set_ext *ext,···10081004 t = rcu_dereference_bh(h->table);10091005#ifdef IP_SET_HASH_WITH_NETS10101006 /* If we test an IP address and not a network address,10111011- * try all possible network sizes */10071007+ * try all possible network sizes10081008+ */10121009 for (i = 0; i < IPSET_NET_COUNT; i++)10131010 if (DCIDR_GET(d->cidr, i) != SET_HOST_MASK(set->family))10141011 break;···11531148 nla_nest_cancel(skb, atd);11541149 ret = -EMSGSIZE;11551150 goto out;11561156- } else11571157- goto nla_put_failure;11511151+ }11521152+ goto nla_put_failure;11581153 }11591154 if (mtype_data_list(skb, e))11601155 goto nla_put_failure;···11761171 set->name);11771172 cb->args[IPSET_CB_ARG0] = 0;11781173 ret = -EMSGSIZE;11791179- } else11741174+ } else {11801175 ipset_nest_end(skb, atd);11761176+ }11811177out:11821178 rcu_read_unlock();11831179 return ret;···1186118011871181static int11881182IPSET_TOKEN(MTYPE, _kadt)(struct ip_set *set, const struct sk_buff *skb,11891189- const struct xt_action_param *par,11901190- enum ipset_adt adt, struct ip_set_adt_opt *opt);11831183+ const struct xt_action_param *par,11841184+ enum ipset_adt adt, struct ip_set_adt_opt *opt);1191118511921186static int11931187IPSET_TOKEN(MTYPE, _uadt)(struct ip_set *set, struct nlattr *tb[],11941194- enum ipset_adt adt, u32 *lineno, u32 flags, bool retried);11881188+ enum ipset_adt adt, u32 *lineno, u32 flags,11891189+ bool retried);1195119011961191static const struct ip_set_type_variant mtype_variant = {11971192 .kadt = mtype_kadt,
···11#include <linux/export.h>22#include <linux/netfilter/ipset/pfxlen.h>3344-/*55- * Prefixlen maps for fast conversions, by Jan Engelhardt.66- */44+/* Prefixlen maps for fast conversions, by Jan Engelhardt. */7586#define E(a, b, c, d) \97 {.ip6 = { \···911 htonl(c), htonl(d), \1012 } }11131212-/*1313- * This table works for both IPv4 and IPv6;1414+/* This table works for both IPv4 and IPv6;1415 * just use prefixlen_netmask_map[prefixlength].ip.1516 */1617const union nf_inet_addr ip_set_netmask_map[] = {···146149EXPORT_SYMBOL_GPL(ip_set_netmask_map);147150148151#undef E149149-#define E(a, b, c, d) \150150- {.ip6 = { (__force __be32) a, (__force __be32) b, \151151- (__force __be32) c, (__force __be32) d, \152152+#define E(a, b, c, d) \153153+ {.ip6 = { (__force __be32)a, (__force __be32)b, \154154+ (__force __be32)c, (__force __be32)d, \152155 } }153156154154-/*155155- * This table works for both IPv4 and IPv6;157157+/* This table works for both IPv4 and IPv6;156158 * just use prefixlen_hostmask_map[prefixlength].ip.157159 */158160const union nf_inet_addr ip_set_hostmask_map[] = {
+24-20
net/netfilter/xt_set.c
···99 */10101111/* Kernel module which implements the set match and SET target1212- * for netfilter/iptables. */1212+ * for netfilter/iptables.1313+ */13141415#include <linux/module.h>1516#include <linux/skbuff.h>···5453set_match_v0(const struct sk_buff *skb, struct xt_action_param *par)5554{5655 const struct xt_set_info_match_v0 *info = par->matchinfo;5656+5757 ADT_OPT(opt, par->family, info->match_set.u.compat.dim,5858 info->match_set.u.compat.flags, 0, UINT_MAX);5959···7169 info->u.compat.dim = IPSET_DIM_ZERO;7270 if (info->u.flags[0] & IPSET_MATCH_INV)7371 info->u.compat.flags |= IPSET_INV_MATCH;7474- for (i = 0; i < IPSET_DIM_MAX-1 && info->u.flags[i]; i++) {7272+ for (i = 0; i < IPSET_DIM_MAX - 1 && info->u.flags[i]; i++) {7573 info->u.compat.dim++;7674 if (info->u.flags[i] & IPSET_SRC)7777- info->u.compat.flags |= (1<<info->u.compat.dim);7575+ info->u.compat.flags |= (1 << info->u.compat.dim);7876 }7977}8078···9189 info->match_set.index);9290 return -ENOENT;9391 }9494- if (info->match_set.u.flags[IPSET_DIM_MAX-1] != 0) {9292+ if (info->match_set.u.flags[IPSET_DIM_MAX - 1] != 0) {9593 pr_warn("Protocol error: set match dimension is over the limit!\n");9694 ip_set_nfnl_put(par->net, info->match_set.index);9795 return -ERANGE;···117115set_match_v1(const struct sk_buff *skb, struct xt_action_param *par)118116{119117 const struct xt_set_info_match_v1 *info = par->matchinfo;118118+120119 ADT_OPT(opt, par->family, info->match_set.dim,121120 info->match_set.flags, 0, UINT_MAX);122121···182179set_match_v3(const struct sk_buff *skb, struct xt_action_param *par)183180{184181 const struct xt_set_info_match_v3 *info = par->matchinfo;182182+ int ret;183183+185184 ADT_OPT(opt, par->family, info->match_set.dim,186185 info->match_set.flags, info->flags, UINT_MAX);187187- int ret;188186189187 if (info->packets.op != IPSET_COUNTER_NONE ||190188 info->bytes.op != IPSET_COUNTER_NONE)···229225set_match_v4(const struct sk_buff *skb, struct xt_action_param *par)230226{231227 const struct xt_set_info_match_v4 *info = par->matchinfo;228228+ int ret;229229+232230 ADT_OPT(opt, par->family, info->match_set.dim,233231 info->match_set.flags, info->flags, UINT_MAX);234234- int ret;235232236233 if (info->packets.op != IPSET_COUNTER_NONE ||237234 info->bytes.op != IPSET_COUNTER_NONE)···258253set_target_v0(struct sk_buff *skb, const struct xt_action_param *par)259254{260255 const struct xt_set_info_target_v0 *info = par->targinfo;256256+261257 ADT_OPT(add_opt, par->family, info->add_set.u.compat.dim,262258 info->add_set.u.compat.flags, 0, UINT_MAX);263259 ADT_OPT(del_opt, par->family, info->del_set.u.compat.dim,···297291 return -ENOENT;298292 }299293 }300300- if (info->add_set.u.flags[IPSET_DIM_MAX-1] != 0 ||301301- info->del_set.u.flags[IPSET_DIM_MAX-1] != 0) {294294+ if (info->add_set.u.flags[IPSET_DIM_MAX - 1] != 0 ||295295+ info->del_set.u.flags[IPSET_DIM_MAX - 1] != 0) {302296 pr_warn("Protocol error: SET target dimension is over the limit!\n");303297 if (info->add_set.index != IPSET_INVALID_ID)304298 ip_set_nfnl_put(par->net, info->add_set.index);···331325set_target_v1(struct sk_buff *skb, const struct xt_action_param *par)332326{333327 const struct xt_set_info_target_v1 *info = par->targinfo;328328+334329 ADT_OPT(add_opt, par->family, info->add_set.dim,335330 info->add_set.flags, 0, UINT_MAX);336331 ADT_OPT(del_opt, par->family, info->del_set.dim,···400393set_target_v2(struct sk_buff *skb, const struct xt_action_param *par)401394{402395 const struct xt_set_info_target_v2 *info = par->targinfo;396396+403397 ADT_OPT(add_opt, par->family, info->add_set.dim,404398 info->add_set.flags, info->flags, info->timeout);405399 ADT_OPT(del_opt, par->family, info->del_set.dim,···408400409401 /* Normalize to fit into jiffies */410402 if (add_opt.ext.timeout != IPSET_NO_TIMEOUT &&411411- add_opt.ext.timeout > UINT_MAX/MSEC_PER_SEC)412412- add_opt.ext.timeout = UINT_MAX/MSEC_PER_SEC;403403+ add_opt.ext.timeout > UINT_MAX / MSEC_PER_SEC)404404+ add_opt.ext.timeout = UINT_MAX / MSEC_PER_SEC;413405 if (info->add_set.index != IPSET_INVALID_ID)414406 ip_set_add(info->add_set.index, skb, par, &add_opt);415407 if (info->del_set.index != IPSET_INVALID_ID)···427419set_target_v3(struct sk_buff *skb, const struct xt_action_param *par)428420{429421 const struct xt_set_info_target_v3 *info = par->targinfo;422422+ int ret;423423+430424 ADT_OPT(add_opt, par->family, info->add_set.dim,431425 info->add_set.flags, info->flags, info->timeout);432426 ADT_OPT(del_opt, par->family, info->del_set.dim,···436426 ADT_OPT(map_opt, par->family, info->map_set.dim,437427 info->map_set.flags, 0, UINT_MAX);438428439439- int ret;440440-441429 /* Normalize to fit into jiffies */442430 if (add_opt.ext.timeout != IPSET_NO_TIMEOUT &&443443- add_opt.ext.timeout > UINT_MAX/MSEC_PER_SEC)444444- add_opt.ext.timeout = UINT_MAX/MSEC_PER_SEC;431431+ add_opt.ext.timeout > UINT_MAX / MSEC_PER_SEC)432432+ add_opt.ext.timeout = UINT_MAX / MSEC_PER_SEC;445433 if (info->add_set.index != IPSET_INVALID_ID)446434 ip_set_add(info->add_set.index, skb, par, &add_opt);447435 if (info->del_set.index != IPSET_INVALID_ID)···464456 }465457 return XT_CONTINUE;466458}467467-468459469460static int470461set_target_v3_checkentry(const struct xt_tgchk_param *par)···504497 !(par->hook_mask & (1 << NF_INET_FORWARD |505498 1 << NF_INET_LOCAL_OUT |506499 1 << NF_INET_POST_ROUTING))) {507507- pr_warn("mapping of prio or/and queue is allowed only"508508- "from OUTPUT/FORWARD/POSTROUTING chains\n");500500+ pr_warn("mapping of prio or/and queue is allowed only from OUTPUT/FORWARD/POSTROUTING chains\n");509501 return -EINVAL;510502 }511503 index = ip_set_nfnl_get_byindex(par->net,···525519 if (info->add_set.dim > IPSET_DIM_MAX ||526520 info->del_set.dim > IPSET_DIM_MAX ||527521 info->map_set.dim > IPSET_DIM_MAX) {528528- pr_warn("Protocol error: SET target dimension "529529- "is over the limit!\n");522522+ pr_warn("Protocol error: SET target dimension is over the limit!\n");530523 if (info->add_set.index != IPSET_INVALID_ID)531524 ip_set_nfnl_put(par->net, info->add_set.index);532525 if (info->del_set.index != IPSET_INVALID_ID)···550545 if (info->map_set.index != IPSET_INVALID_ID)551546 ip_set_nfnl_put(par->net, info->map_set.index);552547}553553-554548555549static struct xt_match set_matches[] __read_mostly = {556550 {