Router: introducing routing on client address.
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
#include <nxt_cert.h>
|
||||
#include <nxt_router.h>
|
||||
#include <nxt_http.h>
|
||||
#include <nxt_sockaddr.h>
|
||||
#include <nxt_http_route_addr.h>
|
||||
|
||||
|
||||
typedef enum {
|
||||
@@ -82,6 +84,10 @@ static nxt_int_t nxt_conf_vldt_match_patterns_set_member(
|
||||
nxt_conf_validation_t *vldt, nxt_str_t *name, nxt_conf_value_t *value);
|
||||
static nxt_int_t nxt_conf_vldt_match_scheme_pattern(nxt_conf_validation_t *vldt,
|
||||
nxt_conf_value_t *value, void *data);
|
||||
static nxt_int_t nxt_conf_vldt_match_addrs(nxt_conf_validation_t *vldt,
|
||||
nxt_conf_value_t *value, void *data);
|
||||
static nxt_int_t nxt_conf_vldt_match_addr(nxt_conf_validation_t *vldt,
|
||||
nxt_conf_value_t *value);
|
||||
static nxt_int_t nxt_conf_vldt_app_name(nxt_conf_validation_t *vldt,
|
||||
nxt_conf_value_t *value, void *data);
|
||||
static nxt_int_t nxt_conf_vldt_app(nxt_conf_validation_t *vldt,
|
||||
@@ -283,6 +289,11 @@ static nxt_conf_vldt_object_t nxt_conf_vldt_match_members[] = {
|
||||
&nxt_conf_vldt_match_patterns,
|
||||
NULL },
|
||||
|
||||
{ nxt_string("source"),
|
||||
NXT_CONF_VLDT_STRING | NXT_CONF_VLDT_ARRAY,
|
||||
&nxt_conf_vldt_match_addrs,
|
||||
NULL },
|
||||
|
||||
{ nxt_string("uri"),
|
||||
NXT_CONF_VLDT_STRING | NXT_CONF_VLDT_ARRAY,
|
||||
&nxt_conf_vldt_match_patterns,
|
||||
@@ -1154,6 +1165,63 @@ nxt_conf_vldt_match_pattern(nxt_conf_validation_t *vldt,
|
||||
}
|
||||
|
||||
|
||||
static nxt_int_t
|
||||
nxt_conf_vldt_match_addrs(nxt_conf_validation_t *vldt,
|
||||
nxt_conf_value_t *value, void *data)
|
||||
{
|
||||
if (nxt_conf_type(value) == NXT_CONF_ARRAY) {
|
||||
return nxt_conf_vldt_array_iterator(vldt, value,
|
||||
&nxt_conf_vldt_match_addr);
|
||||
}
|
||||
|
||||
return nxt_conf_vldt_match_addr(vldt, value);
|
||||
}
|
||||
|
||||
|
||||
static nxt_int_t
|
||||
nxt_conf_vldt_match_addr(nxt_conf_validation_t *vldt,
|
||||
nxt_conf_value_t *value)
|
||||
{
|
||||
nxt_http_route_addr_pattern_t pattern;
|
||||
|
||||
switch (nxt_http_route_addr_pattern_parse(vldt->pool, &pattern, value)) {
|
||||
|
||||
case NXT_OK:
|
||||
return NXT_OK;
|
||||
|
||||
case NXT_ADDR_PATTERN_PORT_ERROR:
|
||||
return nxt_conf_vldt_error(vldt, "The \"address\" port an invalid "
|
||||
"port.");
|
||||
|
||||
case NXT_ADDR_PATTERN_CV_TYPE_ERROR:
|
||||
return nxt_conf_vldt_error(vldt, "The \"match\" pattern for "
|
||||
"\"address\" must be a string.");
|
||||
|
||||
case NXT_ADDR_PATTERN_LENGTH_ERROR:
|
||||
return nxt_conf_vldt_error(vldt, "The \"address\" is too short.");
|
||||
|
||||
case NXT_ADDR_PATTERN_FORMAT_ERROR:
|
||||
return nxt_conf_vldt_error(vldt, "The \"address\" format is invalid.");
|
||||
|
||||
case NXT_ADDR_PATTERN_RANGE_OVERLAP_ERROR:
|
||||
return nxt_conf_vldt_error(vldt, "The \"address\" range is "
|
||||
"overlapping.");
|
||||
|
||||
case NXT_ADDR_PATTERN_CIDR_ERROR:
|
||||
return nxt_conf_vldt_error(vldt, "The \"address\" has an invalid CIDR "
|
||||
"prefix.");
|
||||
|
||||
case NXT_ADDR_PATTERN_NO_IPv6_ERROR:
|
||||
return nxt_conf_vldt_error(vldt, "The \"address\" does not support "
|
||||
"IPv6 with your configuration.");
|
||||
|
||||
default:
|
||||
return nxt_conf_vldt_error(vldt, "The \"address\" has an unknown "
|
||||
"format.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static nxt_int_t
|
||||
nxt_conf_vldt_match_scheme_pattern(nxt_conf_validation_t *vldt,
|
||||
nxt_conf_value_t *value, void *data)
|
||||
|
||||
Reference in New Issue
Block a user