{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "create_mangle_rule",
  "type": "object",
  "properties": {
    "chain": {
      "type": "string",
      "enum": ["prerouting", "input", "forward", "output", "postrouting"]
    },
    "action": {
      "type": "string",
      "enum": [
        "accept",
        "add-dst-to-address-list",
        "add-src-to-address-list",
        "change-dscp",
        "change-mss",
        "change-ttl",
        "clear-df",
        "drop",
        "fasttrack-connection",
        "jump",
        "log",
        "mark-connection",
        "mark-packet",
        "mark-routing",
        "passthrough",
        "return",
        "route",
        "set-priority",
        "sniff-pc",
        "sniff-tzsp"
      ]
    },
    "src_address": {
      "type": "string"
    },
    "dst_address": {
      "type": "string"
    },
    "src_port": {
      "type": "string"
    },
    "dst_port": {
      "type": "string"
    },
    "port": {
      "description": "Match if src OR dst port matches (with protocol)",
      "type": "string"
    },
    "protocol": {
      "type": "string"
    },
    "src_mac_address": {
      "description": "Source MAC, negatable e.g. \"!00:11:...\"",
      "type": "string"
    },
    "in_interface": {
      "description": "Negatable, e.g. \"!ether1\"",
      "type": "string"
    },
    "out_interface": {
      "type": "string"
    },
    "in_interface_list": {
      "description": "Interface list, negatable e.g. \"!WAN\"",
      "type": "string"
    },
    "out_interface_list": {
      "type": "string"
    },
    "src_address_list": {
      "description": "Match src in a named list; negate \"!name\"",
      "type": "string"
    },
    "dst_address_list": {
      "description": "Match dst in a named list; negate \"!name\" (e.g. \"!IR\" routes foreign traffic)",
      "type": "string"
    },
    "src_address_type": {
      "description": "e.g. \"local\", \"unicast\", \"!local\"",
      "type": "string"
    },
    "dst_address_type": {
      "type": "string"
    },
    "connection_mark": {
      "type": "string"
    },
    "packet_mark": {
      "type": "string"
    },
    "routing_mark": {
      "type": "string"
    },
    "connection_state": {
      "description": "e.g. \"new\", \"established,related\", \"!invalid\"",
      "type": "string"
    },
    "connection_nat_state": {
      "description": "\"srcnat\" / \"dstnat\" / \"!dstnat\"",
      "type": "string"
    },
    "connection_type": {
      "description": "Helper, e.g. \"sip\", \"ftp\"",
      "type": "string"
    },
    "connection_bytes": {
      "description": "e.g. \"1000000-0\" (>1 MB connections)",
      "type": "string"
    },
    "connection_limit": {
      "description": "e.g. \"100,32\"",
      "type": "string"
    },
    "connection_rate": {
      "description": "e.g. \"100k-1M\"",
      "type": "string"
    },
    "per_connection_classifier": {
      "description": "PCC for load balancing, e.g. \"both-addresses:2/0\"",
      "type": "string"
    },
    "tcp_flags": {
      "description": "RouterOS flag expression e.g. \"syn,!ack\"",
      "type": "string"
    },
    "dscp": {
      "description": "Match incoming DSCP (0-63)",
      "type": "string"
    },
    "priority": {
      "description": "Match packet/queue priority (0-63)",
      "type": "string"
    },
    "packet_size": {
      "description": "e.g. \"1500\" or \"0-500\"",
      "type": "string"
    },
    "ttl": {
      "description": "Match TTL, e.g. \"equal:64\", \"less-than:10\"",
      "type": "string"
    },
    "tcp_mss": {
      "description": "Match TCP MSS, e.g. \"1400-1500\" or \"!1460\"",
      "type": "string"
    },
    "fragment": {
      "description": "Match second and further fragments",
      "type": "boolean"
    },
    "icmp_options": {
      "description": "Match ICMP type:code, e.g. \"8:0\"",
      "type": "string"
    },
    "ipv4_options": {
      "description": "e.g. \"any\", \"loose-source-routing\", \"record-route\"",
      "type": "string"
    },
    "limit": {
      "description": "Rate limit matcher, e.g. \"50,5:packet\"",
      "type": "string"
    },
    "dst_limit": {
      "description": "Per-destination rate matcher, e.g. \"50,5,dst-address/1m\"",
      "type": "string"
    },
    "content": {
      "description": "Match packets containing this text",
      "type": "string"
    },
    "psd": {
      "description": "Port scan detection, e.g. \"21,3s,3,1\"",
      "type": "string"
    },
    "layer7_protocol": {
      "description": "Name of an /ip firewall layer7-protocol regex",
      "type": "string"
    },
    "ipsec_policy": {
      "description": "e.g. \"in,ipsec\" or \"out,none\"",
      "type": "string"
    },
    "nth": {
      "description": "e.g. \"2,1\" — every 2nd packet",
      "type": "string"
    },
    "random": {
      "description": "Match a random N% of packets (1-99)",
      "type": "string"
    },
    "time": {
      "description": "e.g. \"8h-16h,mon,tue,wed,thu,fri\"",
      "type": "string"
    },
    "hotspot": {
      "description": "e.g. \"auth\", \"!auth\", \"from-client\"",
      "type": "string"
    },
    "p2p": {
      "type": "string"
    },
    "new_connection_mark": {
      "type": "string"
    },
    "new_packet_mark": {
      "type": "string"
    },
    "new_routing_mark": {
      "type": "string"
    },
    "new_dscp": {
      "description": "0-63, for change-dscp",
      "type": "string"
    },
    "new_ttl": {
      "description": "e.g. \"decrement\", \"increment\", or \"set:64\"",
      "type": "string"
    },
    "new_mss": {
      "description": "e.g. \"1440\" or \"clamp-to-pmtu\", for change-mss",
      "type": "string"
    },
    "new_priority": {
      "description": "Priority for action=set-priority, e.g. \"4\", \"from-dscp\", \"from-ingress\"",
      "type": "string"
    },
    "routing_table": {
      "description": "Routing table for action=route",
      "type": "string"
    },
    "route_dst": {
      "description": "Gateway IP for action=route",
      "type": "string"
    },
    "jump_target": {
      "description": "Target chain name for action=jump",
      "type": "string"
    },
    "sniff_target": {
      "description": "Collector IP for action=sniff-tzsp/sniff-pc",
      "type": "string"
    },
    "sniff_target_port": {
      "description": "Collector UDP port for action=sniff-tzsp",
      "type": "string"
    },
    "address_list": {
      "description": "Target list name for add-src/dst-to-address-list",
      "type": "string"
    },
    "address_list_timeout": {
      "description": "Entry timeout for add-*-to-address-list e.g. \"1h\", \"none\"",
      "type": "string"
    },
    "passthrough": {
      "type": "boolean"
    },
    "comment": {
      "type": "string"
    },
    "disabled": {
      "default": false,
      "type": "boolean"
    },
    "log": {
      "default": false,
      "type": "boolean"
    },
    "log_prefix": {
      "type": "string"
    },
    "place_before": {
      "description": "Rule number or ID (*N) to insert before",
      "type": "string"
    }
  },
  "required": ["chain", "action", "disabled", "log"],
  "additionalProperties": false
}
