Skip to content

Commit

Permalink
Client mask
Browse files Browse the repository at this point in the history
- `client_subnet_index`: Fix setting v4/v6 mask, init function was called after and overwrote mask
  • Loading branch information
jelu committed Mar 15, 2024
1 parent 1212328 commit dedafdd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
11 changes: 9 additions & 2 deletions src/client_subnet_index.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ static hashfunc ipnet_hashfunc;
static hashkeycmp ipnet_cmpfunc;
static inX_addr v4mask;
static inX_addr v6mask;
static int v4set = 0, v6set = 0;

#define MAX_ARRAY_SZ 65536
static hashtbl* theHash = NULL;
Expand Down Expand Up @@ -113,18 +114,24 @@ void client_subnet_reset()

void client_subnet_init(void)
{
inXaddr_pton("255.255.255.0", &v4mask);
inXaddr_pton("ffff:ffff:ffff:ffff:ffff:ffff:0000:0000", &v6mask);
if (!v4set) {
inXaddr_pton("255.255.255.0", &v4mask);
}
if (!v6set) {
inXaddr_pton("ffff:ffff:ffff:ffff:ffff:ffff:0000:0000", &v6mask);
}
}

int client_subnet_v4_mask_set(const char* mask)
{
v4set = 1;
dsyslogf(LOG_INFO, "change v4 mask to %s", mask);
return inXaddr_pton(mask, &v4mask);
}

int client_subnet_v6_mask_set(const char* mask)
{
v6set = 1;
dsyslogf(LOG_INFO, "change v6 mask to %s", mask);
return inXaddr_pton(mask, &v6mask);
}
Expand Down
1 change: 1 addition & 0 deletions src/test/1458044657.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ dataset label_count dns All:null LabelCount:label_count any;
output_format XML;
output_format JSON;
tld_list ./1458044657.tld_list.dist;
client_v4_mask 255.255.255.255;
6 changes: 3 additions & 3 deletions src/test/1458044657.json_gold
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,13 @@
{
"Class": "ok",
"ClientSubnet": [
{ "val": "172.17.0.0", "count": 3 }
{ "val": "172.17.0.16", "count": 3 }
]
},
{
"Class": "non-auth-tld",
"ClientSubnet": [
{ "val": "172.17.0.0", "count": 1 }
{ "val": "172.17.0.16", "count": 1 }
]
}
]
Expand Down Expand Up @@ -449,7 +449,7 @@
{
"All": "ALL",
"ClientSubnet": [
{ "val": "172.17.0.0", "count": 4 }
{ "val": "172.17.0.16", "count": 4 }
]
}
]
Expand Down
6 changes: 3 additions & 3 deletions src/test/1458044657.xml_gold
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@
<dimension number="2" type="ClientSubnet"/>
<data>
<Class val="ok">
<ClientSubnet val="172.17.0.0" count="3"/>
<ClientSubnet val="172.17.0.16" count="3"/>
</Class>
<Class val="non-auth-tld">
<ClientSubnet val="172.17.0.0" count="1"/>
<ClientSubnet val="172.17.0.16" count="1"/>
</Class>
</data>
</array>
Expand Down Expand Up @@ -290,7 +290,7 @@
<dimension number="2" type="ClientSubnet"/>
<data>
<All val="ALL">
<ClientSubnet val="172.17.0.0" count="4"/>
<ClientSubnet val="172.17.0.16" count="4"/>
</All>
</data>
</array>
Expand Down

0 comments on commit dedafdd

Please sign in to comment.