Skip to content

Commit

Permalink
MVC/Firewall/Util - add CIDRToMask()
Browse files Browse the repository at this point in the history
  • Loading branch information
AdSchellevis committed May 10, 2023
1 parent 271525f commit d633cd9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/opnsense/mvc/app/library/OPNsense/Firewall/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,16 @@ public static function calcRuleHash($rule)
return md5(json_encode($rule));
}

/**
* convert ipv4 cidr to netmask e.g. 24 --> 255.255.255.0
* @param int $bits ipv4 bits
* @return string netmask
*/
public static function CIDRToMask($bits)
{
return long2ip(0xFFFFFFFF << (32 - $bits));
}

/**
* Find the smallest possible subnet mask for given IP range
* @param array ips (start, end)
Expand Down

0 comments on commit d633cd9

Please sign in to comment.