$schema: http://json-schema.org/draft-07/schema#
definitions:
  ip4Address:
    type: string
    pattern: ^([0-9]{1,3}\.){3}[0-9]{1,3}$
  ip6Address:
    type: string
    pattern: ^([0-9a-f]{0,4}:){2,7}[0-9a-f]{0,4}$
  ipAddress:
    oneOf:
    - $ref: "#/definitions/ip4Address"
    - $ref: "#/definitions/ip6Address"
  ip4AddressCidr:
    type: string
    pattern: ^([0-9]{1,3}\.){3}[0-9]{1,3}/[0-9]{1,2}$
  ip6AddressCidr:
    type: string
    pattern: ^([0-9a-f]{0,4}:){2,7}[0-9a-f]{0,4}/[0-9]{1,3}$
  ipAddressCidr:
    oneOf:
    - $ref: "#/definitions/ip4AddressCidr"
    - $ref: "#/definitions/ip6AddressCidr"
  firewall4Address:
    oneOf:
    - $ref: "#/definitions/ip4Address"
    - $ref: "#/definitions/ip4AddressCidr"
  firewall6Address:
    oneOf:
    - $ref: "#/definitions/ip6Address"
    - $ref: "#/definitions/ip6AddressCidr"
  firewallProto:
    oneOf:
    - type: string
    - type: integer
      minimum: 1
      maximum: 255
  firewallPort:
    type: integer
    minimum: 1
    maximum: 65534
  firewallPortOrRange:
    oneOf:
    - $ref: "#/definitions/firewallPort"
    - type: array
      items:
        $ref: "#/definitions/firewallPort"
      minItems: 2
      maxItems: 2
  firewallMatches:
    type: object
    patternProperties:
      ^(tcp|udp)$:
        type: object
        patternProperties:
          ^(srcport|!srcport|dstport|!dstport)$:
            $ref: "#/definitions/firewallPortOrRange"
        additionalProperties: False
      ^comment$:
        type: object
        properties:
          comment:
            type: string
        required:
        - comment
        additionalProperties: False
    additionalProperties: False
  firewallTarget:
    type: object
    patternProperties:
      ^(ACCEPT|REJECT|DROP)$:
        type: object
    minProperties: 1
    maxProperties: 1
    additionalProperties: False
type: object
properties:
  filter4:
    type: object
    properties:
      input:
        type: array
        items:
          type: object
          patternProperties:
            ^(src|!src|dst|!dst)$:
              $ref: "#/definitions/firewall4Address"
            ^(in|!in)$:
              type: string
            ^(proto|!proto)$:
              $ref: "#/definitions/firewallProto"
            ^matches$:
              $ref: "#/definitions/firewallMatches"
            ^target$:
              $ref: "#/definitions/firewallTarget"
          additionalProperties: False
    additionalProperties: False
  filter6:
    type: object
    properties:
      input:
        type: array
        items:
          type: object
          patternProperties:
            ^(src|!src|dst|!dst)$:
              $ref: "#/definitions/firewall6Address"
            ^(in|!in)$:
              type: string
            ^(proto|!proto)$:
              $ref: "#/definitions/firewallProto"
            ^matches$:
              $ref: "#/definitions/firewallMatches"
            ^target$:
              $ref: "#/definitions/firewallTarget"
          additionalProperties: False
    additionalProperties: False
additionalProperties: False
