mirror of
https://github.com/tnodir/fort
synced 2024-11-15 05:46:03 +00:00
Driver: fortconf: Prepare Rule structs
This commit is contained in:
parent
2ada1a9dc3
commit
b80c033ceb
@ -10,6 +10,8 @@
|
||||
static_assert(sizeof(ip6_addr_t) == 16, "ip6_addr_t size mismatch");
|
||||
|
||||
static_assert(sizeof(FORT_CONF_FLAGS) == sizeof(UINT32), "FORT_CONF_FLAGS size mismatch");
|
||||
static_assert(sizeof(FORT_CONF_RULE_EXPR) == sizeof(UINT16), "FORT_CONF_RULE_EXPR size mismatch");
|
||||
static_assert(sizeof(FORT_CONF_RULE) == sizeof(UINT16), "FORT_CONF_RULE size mismatch");
|
||||
static_assert(sizeof(FORT_TRAF) == sizeof(UINT64), "FORT_TRAF size mismatch");
|
||||
static_assert(sizeof(FORT_TIME) == sizeof(UINT16), "FORT_TIME size mismatch");
|
||||
static_assert(sizeof(FORT_PERIOD) == sizeof(UINT32), "FORT_PERIOD size mismatch");
|
||||
|
@ -8,7 +8,9 @@
|
||||
#define FORT_CONF_IP6_ARR_SIZE(n) ((n) * sizeof(ip6_addr_t))
|
||||
#define FORT_CONF_IP4_RANGE_SIZE(n) (FORT_CONF_IP4_ARR_SIZE(n) * 2)
|
||||
#define FORT_CONF_IP6_RANGE_SIZE(n) (FORT_CONF_IP6_ARR_SIZE(n) * 2)
|
||||
#define FORT_CONF_RULE_MAX 256
|
||||
#define FORT_CONF_RULE_MAX 1024
|
||||
#define FORT_CONF_RULE_SET_MAX 32
|
||||
#define FORT_CONF_RULE_DEPTH_MAX 8
|
||||
#define FORT_CONF_ZONE_MAX 32
|
||||
#define FORT_CONF_GROUP_MAX 16
|
||||
#define FORT_CONF_APPS_LEN_MAX (64 * 1024 * 1024)
|
||||
@ -68,6 +70,14 @@ typedef struct fort_service_info_list
|
||||
#define FORT_SERVICE_INFO_LIST_MIN_SIZE \
|
||||
(FORT_SERVICE_INFO_LIST_DATA_OFF + FORT_SERVICE_INFO_MAX_SIZE)
|
||||
|
||||
typedef struct fort_conf_port_list
|
||||
{
|
||||
UINT8 port_n;
|
||||
UINT8 pair_n;
|
||||
|
||||
UINT16 port[1];
|
||||
} FORT_CONF_PORT_LIST, *PFORT_CONF_PORT_LIST;
|
||||
|
||||
typedef struct fort_conf_addr4_list
|
||||
{
|
||||
UINT32 ip_n;
|
||||
@ -99,6 +109,55 @@ typedef struct fort_conf_addr_group
|
||||
char data[4];
|
||||
} FORT_CONF_ADDR_GROUP, *PFORT_CONF_ADDR_GROUP;
|
||||
|
||||
#define FORT_RULE_FLAG_ADDRESS 0x01
|
||||
#define FORT_RULE_FLAG_PORT 0x02
|
||||
#define FORT_RULE_FLAG_PROTO 0x04
|
||||
|
||||
typedef struct fort_conf_rule_expr
|
||||
{
|
||||
UINT8 expr_begin : 1;
|
||||
UINT8 expr_end : 1;
|
||||
UINT8 expr_or : 1;
|
||||
|
||||
UINT8 has_ip4_list : 1;
|
||||
UINT8 has_ip6_list : 1;
|
||||
|
||||
UINT8 flags;
|
||||
} FORT_CONF_RULE_EXPR, *PFORT_CONF_RULE_EXPR;
|
||||
|
||||
typedef struct fort_conf_rule
|
||||
{
|
||||
UINT8 enabled : 1;
|
||||
UINT8 blocked : 1;
|
||||
UINT8 exclusive : 1;
|
||||
|
||||
UINT8 has_accept_zones : 1;
|
||||
UINT8 has_reject_zones : 1;
|
||||
UINT8 has_expr : 1;
|
||||
|
||||
UINT8 set_count;
|
||||
} FORT_CONF_RULE, *PFORT_CONF_RULE;
|
||||
|
||||
typedef struct fort_conf_rules
|
||||
{
|
||||
UINT32 rule_off[FORT_CONF_RULE_MAX];
|
||||
|
||||
char data[4];
|
||||
} FORT_CONF_RULES, *PFORT_CONF_RULES;
|
||||
|
||||
typedef struct fort_conf_rule_flag
|
||||
{
|
||||
UINT16 rule_id;
|
||||
UCHAR enabled;
|
||||
} FORT_CONF_RULE_FLAG, *PFORT_CONF_RULE_FLAG;
|
||||
|
||||
#define FORT_CONF_RULE_SET_ALIGN sizeof(UINT16)
|
||||
#define FORT_CONF_RULE_SET_SIZE(set_count) FORT_ALIGN_SIZE((set_count), FORT_CONF_RULE_SET_ALIGN)
|
||||
#define FORT_CONF_RULE_SIZE(rule) \
|
||||
(sizeof(FORT_CONF_RULE) + FORT_ALIGN_SIZE((rule)->set_count, FORT_CONF_RULE_SET_ALIGN) \
|
||||
+ ((rule)->has_accept_zones ? sizeof(UINT32) : 0) \
|
||||
+ ((rule)->has_reject_zones ? sizeof(UINT32) : 0))
|
||||
|
||||
typedef struct fort_conf_zones
|
||||
{
|
||||
UINT32 mask;
|
||||
|
@ -324,8 +324,7 @@ int ConfRuleManager::getFreeRuleId(bool &ok)
|
||||
|
||||
const int maxRuleId = DbQuery(sqliteDb()).sql(sqlSelectMaxRuleId).execute().toInt();
|
||||
|
||||
constexpr int RuleMaxId = 9999;
|
||||
ok = (maxRuleId <= RuleMaxId);
|
||||
ok = (maxRuleId < ConfUtil::ruleMaxCount());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public:
|
||||
bool enabled : 1 = true;
|
||||
bool blocked : 1 = false;
|
||||
bool exclusive : 1 = false;
|
||||
bool ruleSetEdited : 1 = false;
|
||||
bool ruleSetEdited : 1 = false; // transient
|
||||
|
||||
RuleType ruleType = AppRule;
|
||||
|
||||
|
@ -152,7 +152,6 @@ void RulesWindow::setupUi()
|
||||
setupTreeRulesChanged();
|
||||
|
||||
// Actions on rule list model's changed/reset
|
||||
setupRuleListModelChanged();
|
||||
setupRuleListModelReset();
|
||||
|
||||
auto layout = new QVBoxLayout();
|
||||
@ -288,18 +287,6 @@ void RulesWindow::setupTreeRulesChanged()
|
||||
connect(m_ruleListView, &TreeView::currentIndexChanged, this, refreshTreeRulesChanged);
|
||||
}
|
||||
|
||||
void RulesWindow::setupRuleListModelChanged()
|
||||
{
|
||||
const auto refreshAddRule = [&] {
|
||||
m_actAddRule->setEnabled(ruleListModel()->rowCount() < ConfUtil::ruleMaxCount());
|
||||
};
|
||||
|
||||
refreshAddRule();
|
||||
|
||||
connect(ruleListModel(), &RuleListModel::modelReset, this, refreshAddRule);
|
||||
connect(ruleListModel(), &RuleListModel::rowsRemoved, this, refreshAddRule);
|
||||
}
|
||||
|
||||
void RulesWindow::setupRuleListModelReset()
|
||||
{
|
||||
expandTreeRules();
|
||||
|
@ -65,7 +65,6 @@ private:
|
||||
void setupTreeRulesHeader();
|
||||
void setupTreeRulesExpandingChanged();
|
||||
void setupTreeRulesChanged();
|
||||
void setupRuleListModelChanged();
|
||||
void setupRuleListModelReset();
|
||||
QLayout *setupButtons();
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <QLoggingCategory>
|
||||
|
||||
#include <conf/confrulemanager.h>
|
||||
#include <util/conf/confutil.h>
|
||||
#include <util/ioc/ioccontainer.h>
|
||||
|
||||
#include "rulelistmodel.h"
|
||||
@ -41,6 +42,11 @@ void RuleSetModel::initialize(const RuleRow &ruleRow, const QStringList &ruleSet
|
||||
|
||||
void RuleSetModel::addRule(const RuleRow &ruleRow)
|
||||
{
|
||||
if (m_ruleSet.size() >= ConfUtil::ruleSetMaxCount()) {
|
||||
qCDebug(LC) << "Rule Set is full";
|
||||
return;
|
||||
}
|
||||
|
||||
const int subRuleId = ruleRow.ruleId;
|
||||
|
||||
if (m_ruleSet.contains(subRuleId)) {
|
||||
|
@ -84,6 +84,16 @@ int ConfUtil::ruleMaxCount()
|
||||
return FORT_CONF_RULE_MAX;
|
||||
}
|
||||
|
||||
int ConfUtil::ruleSetMaxCount()
|
||||
{
|
||||
return FORT_CONF_RULE_SET_MAX;
|
||||
}
|
||||
|
||||
int ConfUtil::ruleDepthMaxCount()
|
||||
{
|
||||
return FORT_CONF_RULE_DEPTH_MAX;
|
||||
}
|
||||
|
||||
int ConfUtil::zoneMaxCount()
|
||||
{
|
||||
return FORT_CONF_ZONE_MAX;
|
||||
|
@ -33,6 +33,8 @@ public:
|
||||
QString errorMessage() const { return m_errorMessage; }
|
||||
|
||||
static int ruleMaxCount();
|
||||
static int ruleSetMaxCount();
|
||||
static int ruleDepthMaxCount();
|
||||
static int zoneMaxCount();
|
||||
|
||||
public slots:
|
||||
|
Loading…
Reference in New Issue
Block a user