NAME
WebService::OPNsense::Firewall::Filter - Firewall filter rule controller
VERSION
version 0.003
SYNOPSIS
use WebService::OPNsense::Constants qw( $ACTION_PASS $PROTO_TCP $OPN_ENABLED );
my $filter = $opn->firewall_filter;
# Search for rules
my $rules = $filter->search_rule(
current => 1,
rowCount => 50,
);
# Add a new rule
my $result = $filter->add_rule({
rule => {
action => $ACTION_PASS,
description => 'Allow HTTP',
destination_port => '80',
enabled => $OPN_ENABLED,
protocol => $PROTO_TCP,
source_net => 'any',
},
});
DESCRIPTION
Manages firewall filter rules.
CONSTANTS
The following constants are available from WebService::OPNsense::Constants.
Actions
Use when setting the action field in a rule.
Address families
Use when setting the address_family field.
Directions
Use when setting the direction field.
Gateway
Use when setting the gateway field.
Interface names
Use when setting the interface field.
$INTERFACE_WAN$INTERFACE_LAN$INTERFACE_DMZ$INTERFACE_GUEST$INTERFACE_LOOPBACK$INTERFACE_OPT1through$INTERFACE_OPT9
Protocols
Use when setting the protocol field.
$PROTO_ANY$PROTO_ESP$PROTO_GRE$PROTO_ICMP$PROTO_OSPF$PROTO_PIM$PROTO_SCTP$PROTO_TCP$PROTO_TCP_UDP$PROTO_UDP$PROTO_VRRP
Rule sequence positions
Use when setting the sequence field.
SNAT modes
Use when setting the snat_mode field.
State types
Use when setting the state_type field.
TCP flags
Use when setting the tcp_flags_* fields.
$TCP_FLAG_ACK$TCP_FLAG_CWR$TCP_FLAG_ECE$TCP_FLAG_FIN$TCP_FLAG_PSH$TCP_FLAG_RST$TCP_FLAG_SYN$TCP_FLAG_URG
METHODS
search_rule
my $results = $filter->search_rule(%params);
Searches for firewall rules. Returns the raw API response hashref.
get_rule
my $rule = $filter->get_rule($uuid);
Returns a single rule by UUID.
add_rule
my $result = $filter->add_rule($rule_data);
Creates firewall rule. $rule_data should be a hashref matching the OPNsense API format (e.g. { rule => { ... } }).
set_rule
my $result = $filter->set_rule($uuid, $rule_data);
Updates rule.
del_rule
my $result = $filter->del_rule($uuid);
Deletes a rule by UUID.
toggle_rule
my $result = $filter->toggle_rule($uuid, $enabled);
Enables or disables a rule.
apply
my $result = $filter->apply;
my $result = $filter->apply($rollback_revision);
Applies pending changes. Optionally specify a rollback revision.
savepoint
my $result = $filter->savepoint;
Creates a configuration savepoint for rollback.
cancel_rollback
my $result = $filter->cancel_rollback($revision);
Cancels a pending rollback.
move_rule_before
my $result = $filter->move_rule_before($selected_uuid, $target_uuid);
Moves a rule before another rule in the rule order.
toggle_rule_log
my $result = $filter->toggle_rule_log($uuid, $log);
Toggles the log flag for a rule. $log should be 0 or 1.
download_rules
my $rules = $filter->download_rules;
Downloads all firewall rules.
upload_rules
my $result = $filter->upload_rules($rules_data);
Uploads firewall rules from a data structure.
get_interface_list
my $interfaces = $filter->get_interface_list;
Returns a list of available network interfaces.
list_categories
my $categories = $filter->list_categories;
Returns a list of available rule categories.
list_network_select_options
my $options = $filter->list_network_select_options;
Returns selectable network options for rule creation.
list_port_select_options
my $options = $filter->list_port_select_options;
Returns selectable port options for rule creation.
revert
my $result = $filter->revert( $revision );
Reverts to a previous configuration revision.
get
my $config = $filter->get;
Returns the full firewall configuration.
set_settings
my $result = $filter->set_settings( $settings );
Updates the firewall configuration.
client
my $http_client = $ctrl->client;
Returns the underlying HTTP client object used for API requests.
SEE ALSO
WebService::OPNsense::Firewall::Role::NAT
AUTHOR
Dean Hamstead <dean@fragfest.com.au>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2026 by Dean Hamstead.
This is free software, licensed under:
The MIT (X11) License