| Conditions | 10 |
| Paths | 10 |
| Total Lines | 48 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 115 | private static function getForwardChain(Pools $p, $inetFamily) |
||
| 116 | { |
||
| 117 | $forwardChain = [ |
||
| 118 | '-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT', |
||
| 119 | ]; |
||
| 120 | |||
| 121 | foreach ($p as $pool) { |
||
| 122 | if (6 === $inetFamily && !$pool->getForward6()) { |
||
| 123 | // IPv6 forwarding was disabled |
||
| 124 | continue; |
||
| 125 | } |
||
| 126 | |||
| 127 | if (4 === $inetFamily) { |
||
| 128 | // get the IPv4 range |
||
| 129 | $srcNet = $pool->getRange()->getAddressPrefix(); |
||
| 130 | } else { |
||
| 131 | // get the IPv6 range |
||
| 132 | $srcNet = $pool->getRange6()->getAddressPrefix(); |
||
| 133 | } |
||
| 134 | $forwardChain[] = sprintf('-N vpn-%s', $pool->getId()); |
||
| 135 | |||
| 136 | $forwardChain[] = sprintf('-A FORWARD -i tun-%s+ -s %s -j vpn-%s', $pool->getId(), $srcNet, $pool->getId()); |
||
| 137 | |||
| 138 | // merge outgoing forwarding firewall rules to prevent certain |
||
| 139 | // traffic |
||
| 140 | $forwardChain = array_merge($forwardChain, self::getForwardFirewall($pool, $inetFamily)); |
||
| 141 | |||
| 142 | if ($pool->getClientToClient()) { |
||
| 143 | // allow client-to-client |
||
| 144 | $forwardChain[] = sprintf('-A vpn-%s -o tun-%s+ -d %s -j ACCEPT', $pool->getId(), $pool->getId(), $srcNet); |
||
| 145 | } |
||
| 146 | if ($pool->getDefaultGateway()) { |
||
| 147 | // allow traffic to all outgoing destinations |
||
| 148 | $forwardChain[] = sprintf('-A vpn-%s -o %s -j ACCEPT', $pool->getId(), $pool->getExtIf(), $srcNet); |
||
| 149 | } else { |
||
| 150 | // only allow certain traffic to the external interface |
||
| 151 | foreach ($pool->getRoutes() as $route) { |
||
| 152 | if ($inetFamily === $route->getFamily()) { |
||
| 153 | $forwardChain[] = sprintf('-A vpn-%s -o %s -d %s -j ACCEPT', $pool->getId(), $pool->getExtIf(), $route->getAddressPrefix()); |
||
| 154 | } |
||
| 155 | } |
||
| 156 | } |
||
| 157 | } |
||
| 158 | |||
| 159 | $forwardChain[] = sprintf('-A FORWARD -j REJECT --reject-with %s', 4 === $inetFamily ? 'icmp-host-prohibited' : 'icmp6-adm-prohibited'); |
||
| 160 | |||
| 161 | return $forwardChain; |
||
| 162 | } |
||
| 163 | |||
| 204 |