]> git.ipfire.org Git - thirdparty/xtables-addons.git/commitdiff
extensions: split assignments and if-exprs
authorJan Engelhardt <jengelh@inai.de>
Sun, 25 Oct 2020 14:41:24 +0000 (15:41 +0100)
committerJan Engelhardt <jengelh@inai.de>
Sun, 25 Oct 2020 14:41:24 +0000 (15:41 +0100)
extensions/ACCOUNT/libxt_ACCOUNT_cl.c
extensions/ACCOUNT/xt_ACCOUNT.c
extensions/libxt_geoip.c
extensions/pknock/libxt_pknock.c
extensions/pknock/pknlusr.c
extensions/pknock/xt_pknock.c
extensions/xt_CHAOS.c
extensions/xt_lscan.c

index fb5280684ec9c68ec0e65b9058dafb46f778510b..901b773aaf52f5f1e45c61c29ed7756c324ad75f 100644 (file)
@@ -34,7 +34,8 @@ int ipt_ACCOUNT_init(struct ipt_ACCOUNT_context *ctx)
 
        // 4096 bytes default buffer should save us from reallocations
        // as it fits 200 concurrent active clients
-       if ((ctx->data = malloc(IPT_ACCOUNT_MIN_BUFSIZE)) == NULL) {
+       ctx->data = malloc(IPT_ACCOUNT_MIN_BUFSIZE);
+       if (ctx->data == NULL) {
                close(ctx->sockfd);
                ctx->sockfd = -1;
                ctx->error_str = "Out of memory for data buffer";
index 18e0b8a0a1b7242642cef466c649533a1ed5f8b2..7f4da85690c0b3c24610e29cdf56eeed5e36773e 100644 (file)
@@ -627,7 +627,8 @@ static int ipt_acc_handle_prepare_read(struct ipt_acc_table *ipt_acc_tables,
        dest->itemcount = ipt_acc_tables[table_nr].itemcount;
 
        /* allocate "root" table */
-       if ((dest->data = ipt_acc_zalloc_page()) == NULL) {
+       dest->data = ipt_acc_zalloc_page();
+       if (dest->data == NULL) {
                printk("ACCOUNT: out of memory for root table "
                        "in ipt_acc_handle_prepare_read()\n");
                return -1;
@@ -725,7 +726,8 @@ static int ipt_acc_handle_prepare_read_flush(struct ipt_acc_table *ipt_acc_table
        }
 
        /* Try to allocate memory */
-       if (!(new_data_page = ipt_acc_zalloc_page())) {
+       new_data_page = ipt_acc_zalloc_page();
+       if (new_data_page == NULL) {
                printk("ACCOUNT: ipt_acc_handle_prepare_read_flush(): "
                        "Out of memory!\n");
                return -1;
@@ -979,7 +981,8 @@ static int ipt_acc_get_ctl(struct sock *sk, int cmd, void *user, int *len)
 
                /* Allocate a userspace handle */
                down(&ian->ipt_acc_userspace_mutex);
-               if ((handle.handle_nr = ipt_acc_handle_find_slot(ian->ipt_acc_handles)) == -1) {
+               handle.handle_nr = ipt_acc_handle_find_slot(ian->ipt_acc_handles);
+               if (handle.handle_nr == -1) {
                        ipt_acc_data_free(dest.data, dest.depth);
                        up(&ian->ipt_acc_userspace_mutex);
                        return -EINVAL;
index 5b8697dc6161b0b9b182b523e8c583f46248dd8a..b91cd5dbd3ca03c1428527664f65b234f13fd46f 100644 (file)
@@ -75,7 +75,6 @@ geoip_get_subnets(const char *code, uint32_t *count, uint8_t nfproto)
        void *subnets;
        struct stat sb;
        char buf[256];
-       int fd;
 #if __BYTE_ORDER == __LITTLE_ENDIAN
        unsigned int n;
 #endif
@@ -86,7 +85,8 @@ geoip_get_subnets(const char *code, uint32_t *count, uint8_t nfproto)
        else
                snprintf(buf, sizeof(buf), GEOIP_DB_DIR "/%s.iv4", code);
 
-       if ((fd = open(buf, O_RDONLY)) < 0) {
+       int fd = open(buf, O_RDONLY);
+       if (fd < 0) {
                fprintf(stderr, "Could not open %s: %s\n", buf, strerror(errno));
                xtables_error(OTHER_PROBLEM, "Could not read geoip database");
        }
@@ -203,7 +203,8 @@ static unsigned int parse_geoip_cc(const char *ccstr, uint16_t *cc,
                next = strchr(cp, ',');
                if (next) *next++ = '\0';
 
-               if ((cctmp = check_geoip_cc(cp, cc, count)) != 0) {
+               cctmp = check_geoip_cc(cp, cc, count);
+               if (cctmp != 0) {
                        if ((mem[count++].user =
                            (unsigned long)geoip_load_cc(cp, cctmp, nfproto)) == 0)
                                xtables_error(OTHER_PROBLEM,
index 1cd829333a1d6c1166350a47910c8c576311c548..5a9aab8168de52b26b571e6a1785dd618330d756 100644 (file)
@@ -91,12 +91,11 @@ proto_to_name(uint8_t proto)
 static const char *
 check_proto(uint16_t pnum, uint8_t invflags)
 {
-       char *proto;
-
        if (invflags & XT_INV_PROTO)
                xtables_error(PARAMETER_PROBLEM, PKNOCK "only works with TCP and UDP.");
 
-       if ((proto = proto_to_name(pnum)) != NULL)
+       const char *proto = proto_to_name(pnum);
+       if (proto != NULL)
                return proto;
        else if (pnum == 0)
                xtables_error(PARAMETER_PROBLEM, PKNOCK "needs `-p tcp' or `-p udp'");
index 77deb2a751db551a8f1abafb120c64815fbc5cda..33c0f0568a70f125c52e6463ba458a77aaccb990 100644 (file)
@@ -30,8 +30,8 @@ int main(int argc, char **argv)
        struct xt_pknock_nl_msg *pknock_msg;
 
        if (argc > 2) {
-               char *prog;
-               if (!(prog = strdup(argv[0]))) {
+               char *prog = strdup(argv[0]);
+               if (prog == NULL) {
                        perror("strdup()");
                } else {
                        fprintf(stderr, "%s [ group-id ]\n", basename(prog));
index e3d6a90a5a0d88b83b0904ac73901d9d22b3ee8e..c71b337df31d791e26d6c7a61ed43b275bbb9043 100644 (file)
@@ -972,7 +972,8 @@ static bool pknock_mt(const struct sk_buff *skb,
 
        /* Sets, updates, removes or checks the peer matching status. */
        if (info->option & XT_PKNOCK_KNOCKPORT) {
-               if ((ret = is_allowed(peer))) {
+               ret = is_allowed(peer);
+               if (ret != 0) {
                        if (info->option & XT_PKNOCK_CLOSESECRET &&
                            (iph->protocol == IPPROTO_UDP ||
                            iph->protocol == IPPROTO_UDPLITE))
index eec36d49f2a7ca61bd0a34c275061c81bcdb5efb..69d2082794e2fd923f8e7030e3af5a9d57c668e9 100644 (file)
@@ -171,7 +171,8 @@ static int __init chaos_tg_init(void)
                printk(KERN_WARNING PFX "Warning: Could not find or load "
                       "\"DELUDE\" target\n");
 
-       if ((ret = xt_register_target(&chaos_tg_reg)) != 0) {
+       ret = xt_register_target(&chaos_tg_reg);
+       if (ret != 0) {
                printk(KERN_WARNING PFX "xt_register_target returned "
                       "error %d\n", ret);
                goto out3;
index 060fe44a4405167ffd6fcfa708594df7726602ce..6fd6533d7e372719d24e089633f1e5689551d1db 100644 (file)
@@ -184,7 +184,8 @@ lscan_mt(const struct sk_buff *skb, struct xt_action_param *par)
                return false;
 
        /* Check for invalid packets: -m conntrack --ctstate INVALID */
-       if ((ctdata = nf_ct_get(skb, &ctstate)) == NULL) {
+       ctdata = nf_ct_get(skb, &ctstate);
+       if (ctdata == NULL) {
                if (info->match_stealth)
                        return lscan_mt_stealth(tcph);
                /*