pool: Avoid conflict with start/end variables used in many commands
authorTobias Brunner <tobias@strongswan.org>
Tue, 28 Jan 2020 13:26:11 +0000 (14:26 +0100)
committerTobias Brunner <tobias@strongswan.org>
Tue, 28 Jan 2020 14:32:43 +0000 (15:32 +0100)
src/pool/pool.c

index ba1889d..86dd3f2 100644 (file)
@@ -40,7 +40,7 @@ database_t *db;
 /**
  * --start/--end addresses of various subcommands
  */
 /**
  * --start/--end addresses of various subcommands
  */
-host_t *start = NULL, *end = NULL;
+host_t *start_addr = NULL, *end_addr = NULL;
 
 /**
  * whether --add should --replace an existing pool
 
 /**
  * whether --add should --replace an existing pool
@@ -333,21 +333,21 @@ next_pool:
  */
 static void add(char *name, host_t *start, host_t *end, u_int timeout)
 {
  */
 static void add(char *name, host_t *start, host_t *end, u_int timeout)
 {
-       chunk_t start_addr, end_addr, cur_addr;
+       chunk_t start_chunk, end_chunk, cur_addr;
        u_int id, count;
 
        u_int id, count;
 
-       start_addr = start->get_address(start);
-       end_addr = end->get_address(end);
-       cur_addr = chunk_clonea(start_addr);
-       count = get_pool_size(start_addr, end_addr);
+       start_chunk = start->get_address(start);
+       end_chunk = end->get_address(end);
+       cur_addr = chunk_clonea(start_chunk);
+       count = get_pool_size(start_chunk, end_chunk);
 
 
-       if (start_addr.len != end_addr.len ||
-               memcmp(start_addr.ptr, end_addr.ptr, start_addr.len) > 0)
+       if (start_chunk.len != end_chunk.len ||
+               memcmp(start_chunk.ptr, end_chunk.ptr, start_chunk.len) > 0)
        {
                fprintf(stderr, "invalid start/end pair specified.\n");
                exit(EXIT_FAILURE);
        }
        {
                fprintf(stderr, "invalid start/end pair specified.\n");
                exit(EXIT_FAILURE);
        }
-       id = create_pool(name, start_addr, end_addr, timeout);
+       id = create_pool(name, start_chunk, end_chunk, timeout);
        printf("allocating %d addresses... ", count);
        fflush(stdout);
        db->transaction(db, FALSE);
        printf("allocating %d addresses... ", count);
        fflush(stdout);
        db->transaction(db, FALSE);
@@ -357,7 +357,7 @@ static void add(char *name, host_t *start, host_t *end, u_int timeout)
                        "INSERT INTO addresses (pool, address, identity, acquired, released) "
                        "VALUES (?, ?, ?, ?, ?)",
                        DB_UINT, id, DB_BLOB, cur_addr, DB_UINT, 0, DB_UINT, 0, DB_UINT, 1);
                        "INSERT INTO addresses (pool, address, identity, acquired, released) "
                        "VALUES (?, ?, ?, ?, ?)",
                        DB_UINT, id, DB_BLOB, cur_addr, DB_UINT, 0, DB_UINT, 0, DB_UINT, 1);
-               if (chunk_equals(cur_addr, end_addr))
+               if (chunk_equals(cur_addr, end_chunk))
                {
                        break;
                }
                {
                        break;
                }
@@ -944,8 +944,8 @@ static void batch(char *argv0, char *name)
 static void cleanup(void)
 {
        db->destroy(db);
 static void cleanup(void)
 {
        db->destroy(db);
-       DESTROY_IF(start);
-       DESTROY_IF(end);
+       DESTROY_IF(start_addr);
+       DESTROY_IF(end_addr);
 }
 
 static void do_args(int argc, char *argv[])
 }
 
 static void do_args(int argc, char *argv[])
@@ -1080,9 +1080,9 @@ static void do_args(int argc, char *argv[])
                                operation = OP_BATCH;
                                continue;
                        case 's':
                                operation = OP_BATCH;
                                continue;
                        case 's':
-                               DESTROY_IF(start);
-                               start = host_create_from_string(optarg, 0);
-                               if (start == NULL)
+                               DESTROY_IF(start_addr);
+                               start_addr = host_create_from_string(optarg, 0);
+                               if (!start_addr)
                                {
                                        fprintf(stderr, "invalid start address: '%s'.\n", optarg);
                                        usage();
                                {
                                        fprintf(stderr, "invalid start address: '%s'.\n", optarg);
                                        usage();
@@ -1090,9 +1090,9 @@ static void do_args(int argc, char *argv[])
                                }
                                continue;
                        case 'e':
                                }
                                continue;
                        case 'e':
-                               DESTROY_IF(end);
-                               end = host_create_from_string(optarg, 0);
-                               if (end == NULL)
+                               DESTROY_IF(end_addr);
+                               end_addr = host_create_from_string(optarg, 0);
+                               if (!end_addr)
                                {
                                        fprintf(stderr, "invalid end address: '%s'.\n", optarg);
                                        usage();
                                {
                                        fprintf(stderr, "invalid end address: '%s'.\n", optarg);
                                        usage();
@@ -1161,9 +1161,9 @@ static void do_args(int argc, char *argv[])
                        {
                                add_addresses(name, addresses, timeout);
                        }
                        {
                                add_addresses(name, addresses, timeout);
                        }
-                       else if (start != NULL && end != NULL)
+                       else if (start_addr && end_addr)
                        {
                        {
-                               add(name, start, end, timeout);
+                               add(name, start_addr, end_addr, timeout);
                        }
                        else
                        {
                        }
                        else
                        {
@@ -1203,13 +1203,13 @@ static void do_args(int argc, char *argv[])
                        show_attr();
                        break;
                case OP_RESIZE:
                        show_attr();
                        break;
                case OP_RESIZE:
-                       if (end == NULL)
+                       if (!end_addr)
                        {
                                fprintf(stderr, "missing arguments.\n");
                                usage();
                                exit(EXIT_FAILURE);
                        }
                        {
                                fprintf(stderr, "missing arguments.\n");
                                usage();
                                exit(EXIT_FAILURE);
                        }
-                       resize(name, end);
+                       resize(name, end_addr);
                        break;
                case OP_LEASES:
                        leases(filter, utc);
                        break;
                case OP_LEASES:
                        leases(filter, utc);