CREATE TABLE IF NOT EXISTS fw_lock (
  name TEXT PRIMARY KEY,
  state INT
);

CREATE TABLE IF NOT EXISTS fw_chains (
  chain TEXT PRIMARY KEY,
  target INT,
  priority INT
);

CREATE TABLE IF NOT EXISTS fw_rules (
  key BIGINT PRIMARY KEY,
  chain TEXT NOT NULL,
  direction INT,
  s_ip_type INT,
  d_ip_type INT,
  s_port_type INT,
  d_port_type INT,
  protocol INT,
  family INT,
  s_ip1 TEXT NOT NULL,
  s_ip2 TEXT NOT NULL,
  d_ip1 TEXT NOT NULL,
  d_ip2 TEXT NOT NULL,
  s_port1 INT,
  s_port2 INT,
  d_port1 INT,
  d_port2 INT,
  ifname TEXT NOT NULL,
  target INT,
  log_level INT,
  log_prefix TEXT NOT NULL,
  nflog_group INT,
  nflog_prefix TEXT NOT NULL,
  nflog_range INT,
  nflog_threshold INT,
  identifier TEXT NOT NULL
);

CREATE INDEX IF NOT EXISTS rules_index ON fw_rules (chain, target);
