Skip to content

Commit fb21ae2

Browse files
Merge branch 'openresty:master' into SSL_set_status_check
2 parents 581d966 + 8df9125 commit fb21ae2

29 files changed

+181
-91
lines changed

src/api/ngx_stream_lua_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/* Public API for other Nginx modules */
3030

3131

32-
#define ngx_stream_lua_version 16
32+
#define ngx_stream_lua_version 16
3333

3434

3535
typedef struct {

src/ngx_stream_lua_api.c

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
#endif
1818
#include "ddebug.h"
1919

20+
#if (NGX_LINUX)
21+
#include <linux/netfilter_ipv4.h>
22+
#if (NGX_HAVE_INET6)
23+
#include <linux/netfilter_ipv6.h>
24+
#include <linux/netfilter_ipv6/ip6_tables.h>
25+
#endif
26+
#endif
2027

2128
#include "ngx_stream_lua_common.h"
2229
#include "api/ngx_stream_lua_api.h"
@@ -35,8 +42,6 @@ ngx_stream_lua_get_global_state(ngx_conf_t *cf)
3542
}
3643

3744

38-
39-
4045
static ngx_int_t ngx_stream_lua_shared_memory_init(ngx_shm_zone_t *shm_zone,
4146
void *data);
4247

@@ -218,4 +223,84 @@ ngx_stream_lua_shared_memory_init(ngx_shm_zone_t *shm_zone, void *data)
218223
return NGX_OK;
219224
}
220225

226+
227+
#if (NGX_LINUX)
228+
int
229+
ngx_stream_lua_ffi_req_dst_addr(ngx_stream_lua_request_t *r, char *buf,
230+
int *buf_size, u_char *errbuf, size_t *errbuf_size)
231+
{
232+
int fd;
233+
int opt_name;
234+
int family;
235+
socklen_t addr_sz;
236+
socklen_t len = sizeof(family);
237+
238+
struct sockaddr_storage addr;
239+
240+
addr_sz = sizeof(addr);
241+
/* Check if connection exists */
242+
if (r->session->connection == NULL) {
243+
*errbuf_size = ngx_snprintf(errbuf, *errbuf_size, "no connection")
244+
- errbuf;
245+
return NGX_ERROR;
246+
}
247+
248+
fd = r->session->connection->fd;
249+
250+
/* Validate file descriptor */
251+
if (fd < 0) {
252+
*errbuf_size = ngx_snprintf(errbuf, *errbuf_size, "invalid fd")
253+
- errbuf;
254+
return NGX_ERROR;
255+
}
256+
257+
/* Get socket family using getsockopt */
258+
if (getsockopt(fd, SOL_SOCKET, SO_DOMAIN, &family, &len) != 0) {
259+
*errbuf_size = ngx_snprintf(errbuf, *errbuf_size,
260+
"failed to get socket family") - errbuf;
261+
return NGX_ERROR;
262+
}
263+
264+
memset(&addr, 0, addr_sz);
265+
266+
/* Get original destination address based on socket family */
267+
if (family == AF_INET) {
268+
/* IPv4 */
269+
opt_name = SO_ORIGINAL_DST;
270+
if (getsockopt(fd, SOL_IP, opt_name, &addr, &addr_sz) != 0) {
271+
*errbuf_size
272+
= ngx_snprintf(errbuf, *errbuf_size,
273+
"failed to get IPv4 origin addr") - errbuf;
274+
return NGX_ERROR;
275+
}
276+
277+
#if (NGX_HAVE_INET6)
278+
279+
} else if (family == AF_INET6) {
280+
/* IPv6 */
281+
opt_name = IP6T_SO_ORIGINAL_DST;
282+
if (getsockopt(fd, SOL_IPV6, opt_name, &addr, &addr_sz) != 0) {
283+
*errbuf_size
284+
= ngx_snprintf(errbuf, *errbuf_size,
285+
"failed to get IPv6 origin addr") - errbuf;
286+
return NGX_ERROR;
287+
}
288+
#endif
289+
290+
} else {
291+
/* Unsupported address family */
292+
*errbuf_size
293+
= ngx_snprintf(errbuf, *errbuf_size,
294+
"unsupported address family: %d", family) - errbuf;
295+
return NGX_ERROR;
296+
}
297+
298+
/* Convert socket address to string representation */
299+
*buf_size = ngx_sock_ntop((struct sockaddr *)&addr, addr_sz,
300+
(u_char *) buf, *buf_size, 1);
301+
302+
return NGX_OK;
303+
}
304+
#endif
305+
221306
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */

src/ngx_stream_lua_args.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,4 @@ ngx_stream_lua_parse_args(lua_State *L, u_char *buf, u_char *last, int max)
156156
}
157157

158158

159-
160-
161159
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */

src/ngx_stream_lua_common.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,6 @@ struct ngx_stream_lua_main_conf_s {
246246
};
247247

248248

249-
250-
251249
struct ngx_stream_lua_srv_conf_s {
252250
#if (NGX_STREAM_SSL)
253251
ngx_ssl_t *ssl; /* shared by SSL cosockets */
@@ -330,6 +328,7 @@ struct ngx_stream_lua_srv_conf_s {
330328

331329
};
332330

331+
333332
typedef ngx_stream_lua_srv_conf_t ngx_stream_lua_loc_conf_t;
334333

335334

@@ -360,8 +359,6 @@ struct ngx_stream_lua_posted_thread_s {
360359
};
361360

362361

363-
364-
365362
struct ngx_stream_lua_co_ctx_s {
366363
void *data; /* user state for cosockets */
367364

@@ -527,12 +524,9 @@ typedef struct ngx_stream_lua_ctx_s {
527524
} ngx_stream_lua_ctx_t;
528525

529526

530-
531-
532527
extern ngx_module_t ngx_stream_lua_module;
533528

534529

535-
536530
#endif /* _NGX_STREAM_LUA_COMMON_H_INCLUDED_ */
537531

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

src/ngx_stream_lua_consts.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,4 @@ ngx_stream_lua_inject_core_consts(lua_State *L)
4747
}
4848

4949

50-
5150
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */

src/ngx_stream_lua_contentby.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,6 @@ ngx_stream_lua_content_handler(ngx_stream_session_t *s)
208208
}
209209

210210

211-
212-
213211
ngx_int_t
214212
ngx_stream_lua_content_handler_file(ngx_stream_lua_request_t *r)
215213
{

src/ngx_stream_lua_control.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ ngx_stream_lua_inject_control_api(ngx_log_t *log, lua_State *L)
4040
}
4141

4242

43-
44-
4543
static int
4644
ngx_stream_lua_on_abort(lua_State *L)
4745
{

src/ngx_stream_lua_ctx.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ ngx_stream_lua_ngx_set_ctx_helper(lua_State *L, ngx_stream_lua_request_t *r,
5555
lua_pop(L, 1);
5656

5757
pool = r->pool;
58-
if (ngx_stream_lua_ngx_ctx_add_cleanup(r, pool, ctx->ctx_ref) != NGX_OK) {
58+
if (ngx_stream_lua_ngx_ctx_add_cleanup(r, pool, ctx->ctx_ref) != NGX_OK)
59+
{
5960
return luaL_error(L, "no memory");
6061
}
6162

@@ -160,8 +161,8 @@ ngx_stream_lua_ffi_set_ctx_ref(ngx_stream_lua_request_t *r, int ref)
160161

161162

162163
static ngx_int_t
163-
ngx_stream_lua_ngx_ctx_add_cleanup(ngx_stream_lua_request_t *r, ngx_pool_t *pool,
164-
int ref)
164+
ngx_stream_lua_ngx_ctx_add_cleanup(ngx_stream_lua_request_t *r,
165+
ngx_pool_t *pool, int ref)
165166
{
166167
lua_State *L;
167168
ngx_pool_cleanup_t *cln;

src/ngx_stream_lua_directive.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,6 @@ ngx_stream_lua_package_path(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
234234
}
235235

236236

237-
238-
239-
240-
241-
242-
243237
char *
244238
ngx_stream_lua_preread_by_lua_block(ngx_conf_t *cf, ngx_command_t *cmd,
245239
void *conf)
@@ -354,6 +348,7 @@ ngx_stream_lua_preread_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
354348
return NGX_CONF_OK;
355349
}
356350

351+
357352
char *
358353
ngx_stream_lua_content_by_lua_block(ngx_conf_t *cf, ngx_command_t *cmd,
359354
void *conf)
@@ -597,8 +592,6 @@ ngx_stream_lua_log_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
597592
}
598593

599594

600-
601-
602595
char *
603596
ngx_stream_lua_init_by_lua_block(ngx_conf_t *cf, ngx_command_t *cmd,
604597
void *conf)
@@ -727,8 +720,6 @@ ngx_stream_lua_init_worker_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
727720
}
728721

729722

730-
731-
732723
static u_char *
733724
ngx_stream_lua_gen_chunk_name(ngx_conf_t *cf, const char *tag, size_t tag_len,
734725
size_t *chunkname_len)
@@ -870,13 +861,15 @@ ngx_stream_lua_conf_lua_block_parse(ngx_conf_t *cf, ngx_command_t *cmd)
870861
if (dst == NULL) {
871862
return NGX_CONF_ERROR;
872863
}
864+
873865
dst->len = len;
874866
dst->len--; /* skip the trailing '}' block terminator */
875867

876868
p = ngx_palloc(cf->pool, len);
877869
if (p == NULL) {
878870
return NGX_CONF_ERROR;
879871
}
872+
880873
dst->data = p;
881874

882875
for (i = 0; i < cf->args->nelts; i++) {

src/ngx_stream_lua_initworkerby.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ ngx_stream_lua_init_worker(ngx_cycle_t *cycle)
158158
if (part->next == NULL) {
159159
break;
160160
}
161+
161162
part = part->next;
162163
ofile = part->elts;
163164
i = 0;

0 commit comments

Comments
 (0)