Skip to content
This repository
Newer
Older
100644 49 lines (35 sloc) 1.209 kb
fcacae82 »
2010-04-08 add simple access features
1
2 #include <ngx_config.h>
3 #include <ngx_core.h>
4 #include <ngx_tcp.h>
5
6
7 ngx_int_t
9866e442 »
2010-09-07 fix code style
8 ngx_tcp_access_handler(ngx_tcp_session_t *s)
9 {
fcacae82 »
2010-04-08 add simple access features
10 ngx_uint_t i;
11 struct sockaddr_in *sin;
9866e442 »
2010-09-07 fix code style
12 ngx_tcp_access_rule_t *rule;
13 ngx_tcp_core_srv_conf_t *cscf;
fcacae82 »
2010-04-08 add simple access features
14
15 cscf = ngx_tcp_get_module_srv_conf(s, ngx_tcp_core_module);
16
17 if (cscf->rules == NULL) {
18 return NGX_DECLINED;
19 }
20
21 /* AF_INET only */
22
23 if (s->connection->sockaddr->sa_family != AF_INET) {
24 return NGX_DECLINED;
25 }
26
27 sin = (struct sockaddr_in *) s->connection->sockaddr;
28
29 rule = cscf->rules->elts;
30 for (i = 0; i < cscf->rules->nelts; i++) {
31
32 ngx_log_debug3(NGX_LOG_DEBUG_TCP, s->connection->log, 0,
33 "access: %08XD %08XD %08XD",
34 sin->sin_addr.s_addr, rule[i].mask, rule[i].addr);
35
36 if ((sin->sin_addr.s_addr & rule[i].mask) == rule[i].addr) {
37 if (rule[i].deny) {
38 ngx_log_error(NGX_LOG_NOTICE, s->connection->log, 0,
03bcb3cd »
2012-07-05 fix coding style
39 "access forbidden by rule");
fcacae82 »
2010-04-08 add simple access features
40
41 return NGX_ERROR;
42 }
43
44 return NGX_OK;
45 }
46 }
47
48 return NGX_DECLINED;
49 }
Something went wrong with that request. Please try again.