{
    "props": {
        "id": {
            "default": null,
            "oneOf": [
                {
                    "type": "null"
                },
                {
                    "type": "integer",
                    "minimum": 0
                }
            ]
        },
        "weight": {
            "description": "Weight of the upstream server in load balancing, more weight means more traffic, 0 means the server is disabled",
            "type": "integer",
            "minimum": 0,
            "maximum": 100
        },
        "name": {
            "description": "Mnemonic name, for easier identification",
            "type": "string",
            "maxLength": 255,
            "default": ""
        },
        "proto": {
            "description": "Protocol number as per IANA assignments,\nsee  https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml",
            "type": "integer",
            "minimum": 1,
            "maximum": 254
        },
        "port": {
            "type": "integer",
            "minimum": 1,
            "maximum": 65535
        },
        "wsUpstreamItemIp": {
            "description": "WebSocket upstream item with IP address",
            "type": "object",
            "required": [
                "type",
                "ip",
                "weight",
                "port"
            ],
            "additionalProperties": false,
            "properties": {
                "type": {
                    "type": "string",
                    "enum": [
                        "primary",
                        "backup"
                    ]
                },
                "ip": {
                    "type": "string",
                    "format": "ipv4"
                },
                "dns_record": {
                    "type": "null"
                },
                "weight": {
                    "$ref": "#/props/weight"
                },
                "name": {
                    "$ref": "#/props/name"
                },
                "port": {
                    "$ref": "#/props/port"
                }
            }
        },
        "wsUpstreamItemDns": {
            "description": "WebSocket upstream item with DNS record",
            "type": "object",
            "required": [
                "type",
                "dns_record",
                "weight",
                "port"
            ],
            "additionalProperties": false,
            "properties": {
                "type": {
                    "type": "string",
                    "enum": [
                        "primary",
                        "backup"
                    ]
                },
                "ip": {
                    "type": "null"
                },
                "dns_record": {
                    "type": "string",
                    "minLength": 4
                },
                "weight": {
                    "$ref": "#/props/weight"
                },
                "name": {
                    "$ref": "#/props/name"
                },
                "port": {
                    "$ref": "#/props/port"
                }
            }
        },
        "httpUpstreamItemIp": {
            "description": "HTTP upstream item with IP address",
            "type": "object",
            "required": [
                "type",
                "ip",
                "weight",
                "port"
            ],
            "additionalProperties": false,
            "properties": {
                "type": {
                    "type": "string",
                    "enum": [
                        "primary",
                        "backup"
                    ]
                },
                "ip": {
                    "type": "string",
                    "format": "ipv4"
                },
                "dns_record": {
                    "type": "null"
                },
                "weight": {
                    "$ref": "#/props/weight"
                },
                "name": {
                    "$ref": "#/props/name"
                },
                "port": {
                    "$ref": "#/props/port"
                }
            }
        },
        "httpUpstreamItemDns": {
            "description": "HTTP upstream item with DNS record",
            "type": "object",
            "required": [
                "type",
                "dns_record",
                "weight",
                "port"
            ],
            "additionalProperties": false,
            "properties": {
                "type": {
                    "type": "string",
                    "enum": [
                        "primary",
                        "backup"
                    ]
                },
                "ip": {
                    "type": "null"
                },
                "dns_record": {
                    "type": "string",
                    "minLength": 4
                },
                "weight": {
                    "$ref": "#/props/weight"
                },
                "name": {
                    "$ref": "#/props/name"
                },
                "port": {
                    "$ref": "#/props/port"
                }
            }
        },
        "tcpProxyUpstreamItem": {
            "type": "object",
            "required": [
                "type",
                "ip",
                "weight",
                "port"
            ],
            "additionalProperties": false,
            "properties": {
                "type": {
                    "type": "string",
                    "enum": [
                        "primary",
                        "backup"
                    ]
                },
                "ip": {
                    "type": "string",
                    "format": "ipv4"
                },
                "weight": {
                    "$ref": "#/props/weight"
                },
                "name": {
                    "$ref": "#/props/name"
                },
                "port": {
                    "$ref": "#/props/port"
                }
            }
        },
        "upstreamSni": {
            "description": "SNI name to use in upstream SSL handshake",
            "type": "string",
            "maxLength": 255,
            "allOf": [
                {
                    "pattern": "^[0-9a-zA-z._-]*$"
                },
                {
                    "not": {
                        "pattern": "(?:^[_.-]|[_.-]$)"
                    }
                },
                {
                    "not": {
                        "pattern": "(?:[_-]\\.|\\.[_-])"
                    }
                },
                {
                    "not": {
                        "pattern": "\\.\\."
                    }
                },
                {
                    "not": {
                        "pattern": "[^.]{64,}\\."
                    }
                },
                {
                    "not": {
                        "pattern": "\\.[^.]{64,}"
                    }
                }
            ]
        }
    },
    "services": {
        "http": {
            "type": "object",
            "required": [
                "type",
                "port",
                "upstream"
            ],
            "additionalProperties": false,
            "properties": {
                "id": {
                    "$ref": "#/props/id"
                },
                "type": {
                    "type": "string",
                    "enum": [
                        "http"
                    ]
                },
                "defaultDrop": {
                    "description": "If true, only whitelisted IPs can access the service",
                    "type": "boolean",
                    "default": false
                },
                "port": {
                    "$ref": "#/props/port"
                },
                "ssl": {
                    "description": "If true, TLS is enabled for this service",
                    "type": "boolean",
                    "default": false
                },
                "http2": {
                    "description": "If true, HTTP/2 is enabled for this service",
                    "type": "boolean",
                    "default": false
                },
                "upstream": {
                    "type": "object",
                    "required": [
                        "balancer",
                        "weights",
                        "backups",
                        "upstreams"
                    ],
                    "additionalProperties": false,
                    "properties": {
                        "balancer": {
                            "type": "string",
                            "enum": [
                                "roundrobin",
                                "iphash"
                            ]
                        },
                        "weights": {
                            "type": "boolean"
                        },
                        "backups": {
                            "type": "boolean"
                        },
                        "ssl": {
                            "description": "If true, TLS-connection to upstream is enabled for this service",
                            "type": "boolean",
                            "default": false
                        },
                        "upstreams": {
                            "type": "array",
                            "items": {
                                "oneOf": [
                                    {
                                        "$ref": "#/props/httpUpstreamItemIp"
                                    },
                                    {
                                        "$ref": "#/props/httpUpstreamItemDns"
                                    }
                                ]
                            }
                        },
                        "sniName": {
                            "description": "Name to use for SNI in upstream SSL handshake,\nignored if upstream.ssl is false",
                            "oneOf": [
                                {
                                    "type": "null"
                                },
                                {
                                    "$ref": "#/props/upstreamSni"
                                }
                            ],
                            "default": null
                        },
                        "sniNameOverride": {
                            "description": "Forces the use of sniName as the HOST header in upstream request,\nignored if upstream.ssl is false or sniName is null",
                            "type": "boolean",
                            "default": false
                        }
                    }
                }
            }
        },
        "natUdp": {
            "type": "object",
            "required": [
                "type",
                "port",
                "proto",
                "upstream"
            ],
            "properties": {
                "id": {
                    "$ref": "#/props/id"
                },
                "type": {
                    "type": "string",
                    "enum": [
                        "nat"
                    ]
                },
                "port": {
                    "$ref": "#/props/port"
                },
                "proto": {
                    "type": "string",
                    "enum": [
                        "udp"
                    ]
                },
                "defaultDrop": {
                    "description": "If true, only whitelisted IPs can access the service",
                    "type": "boolean",
                    "default": false
                },
                "dropAmp": {
                    "description": "If true, amplified packets are dropped",
                    "type": "boolean",
                    "default": false
                },
                "rateLimit": {
                    "description": "Maximum packet rate per second per IP address (bps)",
                    "type": "integer",
                    "minimum": 8000,
                    "maximum": 1000000000000,
                    "multipleOf": 8000,
                    "default": 8000000
                },
                "upstream": {
                    "type": "object",
                    "required": [
                        "ip",
                        "port"
                    ],
                    "additionalProperties": false,
                    "properties": {
                        "ip": {
                            "type": "string",
                            "format": "ipv4"
                        },
                        "port": {
                            "$ref": "#/props/port"
                        }
                    }
                }
            }
        },
        "natTcp": {
            "type": "object",
            "required": [
                "type",
                "port",
                "proto",
                "upstream"
            ],
            "additionalProperties": false,
            "properties": {
                "id": {
                    "$ref": "#/props/id"
                },
                "type": {
                    "type": "string",
                    "enum": [
                        "nat"
                    ]
                },
                "port": {
                    "$ref": "#/props/port"
                },
                "proto": {
                    "type": "string",
                    "enum": [
                        "tcp"
                    ]
                },
                "defaultDrop": {
                    "description": "If true, only whitelisted IPs can access the service",
                    "type": "boolean",
                    "default": false
                },
                "upstream": {
                    "type": "object",
                    "required": [
                        "ip",
                        "port"
                    ],
                    "additionalProperties": false,
                    "properties": {
                        "ip": {
                            "type": "string",
                            "format": "ipv4"
                        },
                        "port": {
                            "$ref": "#/props/port"
                        }
                    }
                }
            }
        },
        "natAllTcp": {
            "type": "object",
            "required": [
                "type",
                "proto",
                "upstream"
            ],
            "additionalProperties": false,
            "properties": {
                "id": {
                    "$ref": "#/props/id"
                },
                "type": {
                    "type": "string",
                    "enum": [
                        "nat-all"
                    ]
                },
                "proto": {
                    "type": "string",
                    "enum": [
                        "tcp"
                    ]
                },
                "defaultDrop": {
                    "description": "If true, only whitelisted IPs can access the service",
                    "type": "boolean",
                    "default": false
                },
                "upstream": {
                    "type": "string",
                    "format": "ipv4"
                },
                "rateLimit": {
                    "description": "Maximum packet rate per second per IP address (bps)",
                    "type": "integer",
                    "minimum": 8000,
                    "maximum": 1000000000000,
                    "multipleOf": 8000,
                    "default": null
                }
            }
        },
        "natAllUdp": {
            "type": "object",
            "required": [
                "type",
                "proto",
                "upstream"
            ],
            "additionalProperties": false,
            "properties": {
                "id": {
                    "$ref": "#/props/id"
                },
                "type": {
                    "type": "string",
                    "enum": [
                        "nat-all"
                    ]
                },
                "proto": {
                    "type": "string",
                    "enum": [
                        "udp"
                    ]
                },
                "defaultDrop": {
                    "description": "If true, only whitelisted IPs can access the service",
                    "type": "boolean",
                    "default": false
                },
                "dropAmp": {
                    "description": "If true, amplified packets are dropped",
                    "type": "boolean",
                    "default": false
                },
                "rateLimit": {
                    "description": "Maximum packet rate per second per IP address (bps)",
                    "type": "integer",
                    "minimum": 8000,
                    "maximum": 1000000000000,
                    "multipleOf": 8000,
                    "default": 8000000
                },
                "upstream": {
                    "type": "string",
                    "format": "ipv4"
                }
            }
        },
        "tcpProxy": {
            "type": "object",
            "required": [
                "type",
                "port",
                "upstream"
            ],
            "additionalProperties": false,
            "properties": {
                "id": {
                    "$ref": "#/props/id"
                },
                "type": {
                    "type": "string",
                    "enum": [
                        "tcpproxy"
                    ]
                },
                "port": {
                    "$ref": "#/props/port"
                },
                "defaultDrop": {
                    "description": "If true, only whitelisted IPs can access the service",
                    "type": "boolean",
                    "default": false
                },
                "proxyProtocol": {
                    "type": "number",
                    "enum": [
                        0,
                        1,
                        2
                    ],
                    "default": 2
                },
                "upstream": {
                    "type": "object",
                    "required": [
                        "upstreams"
                    ],
                    "additionalProperties": false,
                    "properties": {
                        "upstreams": {
                            "type": "array",
                            "items": {
                                "$ref": "#/props/tcpProxyUpstreamItem"
                            }
                        }
                    }
                }
            }
        },
        "websocket": {
            "type": "object",
            "required": [
                "type",
                "port",
                "upstream"
            ],
            "additionalProperties": false,
            "properties": {
                "id": {
                    "$ref": "#/props/id"
                },
                "type": {
                    "type": "string",
                    "enum": [
                        "websocket"
                    ]
                },
                "port": {
                    "$ref": "#/props/port"
                },
                "defaultDrop": {
                    "description": "If true, only whitelisted IPs can access the service",
                    "type": "boolean",
                    "default": false
                },
                "ssl": {
                    "description": "If true, TLS is enabled for this service",
                    "type": "boolean",
                    "default": false
                },
                "upstream": {
                    "type": "object",
                    "required": [
                        "ssl",
                        "upstreams"
                    ],
                    "additionalProperties": false,
                    "properties": {
                        "ssl": {
                            "description": "If true, TLS is enabled for this service",
                            "type": "boolean",
                            "default": false
                        },
                        "upstreams": {
                            "type": "array",
                            "items": {
                                "oneOf": [
                                    {
                                        "$ref": "#/props/wsUpstreamItemIp"
                                    },
                                    {
                                        "$ref": "#/props/wsUpstreamItemDns"
                                    }
                                ]
                            }
                        }
                    }
                }
            }
        }
    },
    "type": "array",
    "minItems": 0,
    "maxItems": 150,
    "items": {
        "oneOf": [
            {
                "$ref": "#/services/tcpProxy"
            },
            {
                "$ref": "#/services/natUdp"
            },
            {
                "$ref": "#/services/natTcp"
            },
            {
                "$ref": "#/services/natAllUdp"
            },
            {
                "$ref": "#/services/natAllTcp"
            },
            {
                "$ref": "#/services/websocket"
            },
            {
                "$ref": "#/services/http"
            }
        ]
    }
}
