Skip to content

Commit

Permalink
Allow a CIDR mask (/24) instead of subnetmask in config
Browse files Browse the repository at this point in the history
  • Loading branch information
Leseratte10 committed Jan 1, 2023
1 parent b4bdfff commit 3d11756
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
32 changes: 24 additions & 8 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,18 +403,34 @@ int HIDDENSYM make_netent(char *value, struct netent **ent)
free(*ent);
return (2);
}

// Check if there's a dot in the subnet string.
if (strstr(subnet, ".") != NULL) {
// There's a dot, so it's a netmask like 255.255.255.0
#ifdef HAVE_INET_ADDR
else if (((*ent)->localnet.s_addr = inet_addr(subnet)) == -1)
{
if (((*ent)->localnet.s_addr = inet_addr(subnet)) == -1)
{
#elif defined(HAVE_INET_ATON)
else if (!(inet_aton(subnet, &((*ent)->localnet))))
{
if (!(inet_aton(subnet, &((*ent)->localnet))))
{
#endif
/* Badly constructed subnet */
free(*ent);
return (3);
/* Badly constructed subnet */
free(*ent);
return (3);
}
}
else if (((*ent)->localip.s_addr & (*ent)->localnet.s_addr) != (*ent)->localip.s_addr)
else {
// No dot, probably a mask like /24
int mask_size = atoi(subnet);
if (mask_size < 0 || mask_size > 32) {
/* Bad mask */
free (*ent);
return (3);
}
(*ent)->localnet.s_addr = htonl((0xFFFFFFFFUL << (32-mask_size)) & 0xFFFFFFFFUL);
}

if (((*ent)->localip.s_addr & (*ent)->localnet.s_addr) != (*ent)->localip.s_addr)
{
/* Subnet and Ip != Ip */
free(*ent);
Expand Down
4 changes: 2 additions & 2 deletions tnat64.conf.complex.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# the man pages, tnat64(8) and tnat64.conf(8)

# Local networks
# For this example this machine can directly access 192.168.0.0/255.255.255.0
# For this example this machine can directly access 192.168.0.0/24
# (192.168.0.*) and 10.0.0.0/255.0.0.0 (10.*)

local = 192.168.0.0/255.255.255.0
local = 192.168.0.0/24
local = 10.0.0.0/255.0.0.0

# Paths
Expand Down

0 comments on commit 3d11756

Please sign in to comment.