Commit 5b72642c authored by Michael Tremer's avatar Michael Tremer

address: Rename increment/decrement functions and modify address in place

Signed-off-by: default avatarMichael Tremer <michael.tremer@ipfire.org>
parent dd599427
......@@ -1463,7 +1463,8 @@ static int __loc_database_enumerator_next_bogon(
}
// Search where the gap could end
gap_end = address_decrement(loc_network_get_first_address(network));
gap_end = *loc_network_get_first_address(network);
loc_address_decrement(&gap_end);
// There is a gap
if (loc_address_cmp(gap_start, &gap_end) < 0) {
......@@ -1476,8 +1477,8 @@ static int __loc_database_enumerator_next_bogon(
}
// The gap now starts after this network
const struct in6_addr* network_end = loc_network_get_last_address(network);
(*gap_start) = address_increment(network_end);
(*gap_start) = *loc_network_get_last_address(network);
loc_address_increment(gap_start);
loc_network_unref(network);
......
......@@ -227,32 +227,24 @@ static inline int loc_address_sub(struct in6_addr* result,
}
}
static inline struct in6_addr address_increment(const struct in6_addr* address) {
struct in6_addr a = *address;
static inline void loc_address_increment(struct in6_addr* address) {
for (int octet = 15; octet >= 0; octet--) {
if (a.s6_addr[octet] < 255) {
a.s6_addr[octet]++;
if (address->s6_addr[octet] < 255) {
address->s6_addr[octet]++;
break;
} else {
a.s6_addr[octet] = 0;
address->s6_addr[octet] = 0;
}
}
return a;
}
static inline struct in6_addr address_decrement(const struct in6_addr* address) {
struct in6_addr a = *address;
static inline void loc_address_decrement(struct in6_addr* address) {
for (int octet = 15; octet >= 0; octet--) {
if (a.s6_addr[octet] > 0) {
a.s6_addr[octet]--;
if (address->s6_addr[octet] > 0) {
address->s6_addr[octet]--;
break;
}
}
return a;
}
static inline int loc_address_family_bit_length(const int family) {
......
......@@ -349,7 +349,7 @@ int loc_network_list_summarize(struct loc_ctx* ctx,
if (r)
return r;
num = address_increment(&num);
loc_address_increment(&num);
// How many bits do we need to represent this address?
int bits2 = loc_address_bit_length(&num) - 1;
......@@ -379,7 +379,7 @@ int loc_network_list_summarize(struct loc_ctx* ctx,
// The next network starts right after this one
start = *loc_network_get_last_address(network);
start = address_increment(&start);
loc_address_increment(&start);
}
return 0;
......
......@@ -434,7 +434,8 @@ LOC_EXPORT int loc_network_subnets(struct loc_network* network,
return r;
// The next subnet starts after the first one
struct in6_addr first_address = address_increment(&(*subnet1)->last_address);
struct in6_addr first_address = (*subnet1)->last_address;
loc_address_increment(&first_address);
// Create the second half of the network
r = loc_network_new(network->ctx, subnet2, &first_address, prefix);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment