Documentation is available at docsis_firewall.php
- <?php
- /**
- * DOCSIS Port Filter (Firewall)
- *
- * @author David Eder <david@eder.us>
- * @copyright 2004 David Eder
- * @package docsis_firewall
- * @version .3
- */
- /**
- */
- require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'docsis_config.php');
- if(!defined('SOL_ICMP')) define('SOL_ICMP', 1);
- if(!defined('SOL_TCP')) define('SOL_TCP', 6);
- if(!defined('SOL_UDP')) define('SOL_UDP', 17);
- if(!defined('SOL_ALL')) define('SOL_ALL', 256);
- if(!defined('DEFAULT_ACCEPT')) define('DEFAULT_ACCEPT', 2);
- if(!defined('DEFAULT_DROP')) define('DEFAULT_DROP', 1);
- if(!defined('INTERFACE_DEFAULT')) define('INTERFACE_DEFAULT', 0);
- if(!defined('DIRECTION_INBOUND')) define('DIRECTION_INBOUND', 1);
- if(!defined('DIRECTION_OUTBOUND')) define('DIRECTION_OUTBOUND', 2);
- if(!defined('DIRECTION_BOTH')) define('DIRECTION_BOTH', 3);
- if(!defined('BROADCAST_TRUE')) define('BROADCAST_TRUE', 1);
- if(!defined('BROADCAST_FALSE')) define('BROADCAST_FALSE', 2);
- /**
- * DOCSIS Port Filter (Firewall)
- *
- * @package docsis_firewall
- */
- class docsis_firewall
- {
- // see http://www.cisco.com/univercd/cc/td/doc/product/cable/cab_rout/cmtsfg/ufgcfile.htm#wp1025297
- var $filters = array();
- /**
- * Constructor
- */
- function docsis_firewall()
- {}
- /**
- * Add a filter to the firewall
- *
- * @param int $protocol either SOL_ICMP, SOL_TCP, SOL_UDP or SOL_ALL
- * @param int $control either DEFAULT_ACCEPT or DEFAULT_DROP
- * @param ipaddress $source_ip_address Source IP Address
- * @param ipaddress $source_mask Source Mask
- * @param int $source_port_low port to start filtering
- * @param int $source_port_high port to stop filtering
- * @param ipaddress $dest_ip_address Dest IP Address
- * @param ipaddress $dest_mask Destination Mask
- * @param int $dest_port_low Destination port low
- * @param int $dest_port_high Destination port high
- * @param int $interface_index Interface index defaults to INTERFACE_DEFAULT
- * @param int $direction Direction to match against valid values DIRECTION_INBOUND, DIRECTION_OUTBOUND or DIRECTION_BOTH default Value DIRECTION_BOTH
- * @param int $broadcast_only Only match multicast or broadcast traffic Valid Values BROADCAST_TRUE or BROADCAST_FALSE default is BROADCAST_FALSE
- */
- function add_filter($protocol=SOL_ALL, $control=DEFAULT_DROP,
- $source_ip_address='0.0.0.0', $source_mask='0.0.0.0', $source_port_low=0, $source_port_high=65535,
- $dest_ip_address='0.0.0.0', $dest_mask='0.0.0.0', $dest_port_low=0, $dest_port_high=65535,
- $interface_index=INTERFACE_DEFAULT, $direction=DIRECTION_BOTH, $broadcast_only=BROADCAST_FALSE)
- {
- $this->filters[] = array('protocol'=>$protocol, 'control'=>$control,
- 'source_ip_address'=>$source_ip_address, 'source_mask'=>$source_mask,
- 'source_port_low'=>$source_port_low, 'source_port_high'=>$source_port_high,
- 'dest_ip_address'=>$dest_ip_address, 'dest_mask'=>$dest_mask,
- 'dest_port_low'=>$dest_port_low, 'dest_port_high'=>$dest_port_high,
- 'interface_index'=>$interface_index, 'direction'=>$direction, 'broadcast_only'=>$broadcast_only);
- }
- /**
- * Write filter to bootfile
- *
- * @param docsis_config $bootfile to write to
- * @param int $default_action either DEFAULT_ACCEPT or DEFAULT_DROP
- */
- function write(&$bootfile, $default_action=DEFAULT_ACCEPT)
- {
- $number = 0;
- foreach($this->filters as $index=>$filter)
- {
- $number ++;
- // Create the filter and activate it
- $bootfile->add_snmp_object('.1.3.6.1.2.1.69.1.6.4.1.2.' . $number, new rfc1155_Integer(4));
- // Set Control Accept or Drop for this Rule
- $bootfile->add_snmp_object('.1.3.6.1.2.1.69.1.6.4.1.3.' . $number, new rfc1155_Integer($filter['control']));
- // Apply filter to all interfaces.
- $bootfile->add_snmp_object('.1.3.6.1.2.1.69.1.6.4.1.4.' . $number, new rfc1155_Integer($filter['interface_index']));
- // Apply filter to both inbound and outbound traffic.
- $bootfile->add_snmp_object('.1.3.6.1.2.1.69.1.6.4.1.5.' . $number, new rfc1155_Integer($filter['direction']));
- // Apply Filter to all traffic not just multi cast traffic.
- $bootfile->add_snmp_object('.1.3.6.1.2.1.69.1.6.4.1.6.' . $number, new rfc1155_Integer($filter['broadcast_only']));
- // Apply filter to traffic with this Source Address
- $bootfile->add_snmp_object('.1.3.6.1.2.1.69.1.6.4.1.7.' . $number, new rfc1155_IPAddress($filter['source_ip_address']));
- // Apply filter to traffice with this source mask
- $bootfile->add_snmp_object('.1.3.6.1.2.1.69.1.6.4.1.8.' . $number, new rfc1155_IPAddress($filter['source_mask']));
- // Apply filter to traffic with this Destination Address
- $bootfile->add_snmp_object('.1.3.6.1.2.1.69.1.6.4.1.9.' . $number, new rfc1155_IPAddress($filter['dest_ip_address']));
- // Apply filter to traffice with this Destination mask
- $bootfile->add_snmp_object('.1.3.6.1.2.1.69.1.6.4.1.10.' . $number, new rfc1155_IPAddress($filter['dest_mask']));
- // Match $this->protocol packets.
- $bootfile->add_snmp_object('.1.3.6.1.2.1.69.1.6.4.1.11.' . $number, new rfc1155_Integer($filter['protocol']));
- // Apply filter to traffic for port starting at source port_low.
- $bootfile->add_snmp_object('.1.3.6.1.2.1.69.1.6.4.1.12.' . $number, new rfc1155_Integer($filter['source_port_low']));
- // Apply filter to traffic for port ending at source port_high.
- $bootfile->add_snmp_object('.1.3.6.1.2.1.69.1.6.4.1.13.' . $number, new rfc1155_Integer($filter['source_port_high']));
- // Apply filter to traffic for port starting at dest port_low.
- $bootfile->add_snmp_object('.1.3.6.1.2.1.69.1.6.4.1.14.' . $number, new rfc1155_Integer($filter['dest_port_low']));
- // Apply filter to traffic for port ending at dest port_high.
- $bootfile->add_snmp_object('.1.3.6.1.2.1.69.1.6.4.1.15.' . $number, new rfc1155_Integer($filter['dest_port_high']));
- }
- // Sets Default Action when a packet does not match any rule
- // Important note setting this to DEFAULT_DROP will drop all
- // traffic reguardless of whether a rule is matched equivalent to Network Access = 0
- $bootfile->add_snmp_object('.1.3.6.1.2.1.69.1.6.3.0', new rfc1155_Integer($default_action));
- }
- }
- ?>
Documentation generated on Mon, 14 Nov 2005 18:00:15 -0700 by phpDocumentor 1.3.0RC3