Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: support lua balancer set proxy bind dynamic #350

Closed
wants to merge 5 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions src/ngx_stream_lua_balancer.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,4 +752,70 @@ ngx_stream_lua_ffi_balancer_get_last_failure(ngx_stream_lua_request_t *r,
}


int
ngx_stream_lua_ffi_balancer_set_proxy_bind(ngx_stream_lua_request_t *r,
const u_char *addr, size_t addr_len, char **err)
{
ngx_int_t rc;
ngx_str_t addr_str;
ngx_addr_t *addr_val;
ngx_stream_lua_ctx_t *ctx;
ngx_stream_upstream_t *u;

if (r == NULL) {
*err = "no request found";
return NGX_ERROR;
}

u = r->session->upstream;
if (u == NULL) {
*err = "no upstream found";
return NGX_ERROR;
}

ctx = ngx_stream_lua_get_module_ctx(r, ngx_stream_lua_module);
if (ctx == NULL) {
*err = "no ctx found";
return NGX_ERROR;
}

if ((ctx->context & NGX_STREAM_LUA_CONTEXT_BALANCER) == 0) {
*err = "API disabled in the current context";
return NGX_ERROR;
}

addr_val = ngx_pcalloc(r->pool, sizeof(ngx_addr_t));
if (addr_val == NULL) {
*err = "no memory for addr_val";
return NGX_ERROR;
}

addr_str.len = addr_len;
addr_str.data = ngx_palloc(r->pool, addr_len);
if (addr_str.data == NULL) {
*err = "no memory for addr_str";
return NGX_ERROR;
}

ngx_memcpy(addr_str.data, addr, addr_len);

rc = ngx_parse_addr_port(r->pool, addr_val, addr_str.data, addr_str.len);
if (rc == NGX_ERROR) {
*err = "parse addr port failed";
return NGX_ERROR;
}

if (rc != NGX_OK) {
*err = "invalid addr";
return NGX_ERROR;
}

addr_val->name = addr_str;

u->peer.local = addr_val;

return NGX_OK;
}


/* vi:set ft=c ts=4 sw=4 et fdm=marker: */
Loading