comparison src/http/ngx_http_core_module.c @ 3220:cdcd9e29c589

*) move sockaddr to the listen options *) rename ngx_http_listen_t to ngx_http_listen_opt_t
author Igor Sysoev <igor@sysoev.ru>
date Wed, 21 Oct 2009 16:47:44 +0000
parents 81b8416054b0
children c8de5a8b6d17
comparison
equal deleted inserted replaced
3219:81b8416054b0 3220:cdcd9e29c589
2830 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) 2830 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
2831 { 2831 {
2832 ngx_http_core_srv_conf_t *prev = parent; 2832 ngx_http_core_srv_conf_t *prev = parent;
2833 ngx_http_core_srv_conf_t *conf = child; 2833 ngx_http_core_srv_conf_t *conf = child;
2834 2834
2835 ngx_http_listen_t ls;
2836 struct sockaddr_in *sin; 2835 struct sockaddr_in *sin;
2836 ngx_http_listen_opt_t lsopt;
2837 ngx_http_server_name_t *sn; 2837 ngx_http_server_name_t *sn;
2838 2838
2839 /* TODO: it does not merge, it inits only */ 2839 /* TODO: it does not merge, it inits only */
2840 2840
2841 if (!conf->listen) { 2841 if (!conf->listen) {
2842 ngx_memzero(&ls, sizeof(ngx_http_listen_t)); 2842 ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t));
2843 2843
2844 sin = (struct sockaddr_in *) &ls.sockaddr; 2844 sin = (struct sockaddr_in *) &lsopt.sockaddr;
2845 2845
2846 sin->sin_family = AF_INET; 2846 sin->sin_family = AF_INET;
2847 #if (NGX_WIN32) 2847 #if (NGX_WIN32)
2848 sin->sin_port = htons(80); 2848 sin->sin_port = htons(80);
2849 #else 2849 #else
2850 sin->sin_port = htons((getuid() == 0) ? 80 : 8000); 2850 sin->sin_port = htons((getuid() == 0) ? 80 : 8000);
2851 #endif 2851 #endif
2852 sin->sin_addr.s_addr = INADDR_ANY; 2852 sin->sin_addr.s_addr = INADDR_ANY;
2853 2853
2854 ls.socklen = sizeof(struct sockaddr_in); 2854 lsopt.socklen = sizeof(struct sockaddr_in);
2855 2855
2856 ls.opt.backlog = NGX_LISTEN_BACKLOG; 2856 lsopt.backlog = NGX_LISTEN_BACKLOG;
2857 ls.opt.rcvbuf = -1; 2857 lsopt.rcvbuf = -1;
2858 ls.opt.sndbuf = -1; 2858 lsopt.sndbuf = -1;
2859 ls.opt.wildcard = 1; 2859 lsopt.wildcard = 1;
2860 2860
2861 (void) ngx_sock_ntop((struct sockaddr *) &ls.sockaddr, ls.opt.addr, 2861 (void) ngx_sock_ntop((struct sockaddr *) &lsopt.sockaddr, lsopt.addr,
2862 NGX_SOCKADDR_STRLEN, 1); 2862 NGX_SOCKADDR_STRLEN, 1);
2863 2863
2864 if (ngx_http_add_listen(cf, conf, &ls) == NGX_OK) { 2864 if (ngx_http_add_listen(cf, conf, &lsopt) == NGX_OK) {
2865 return NGX_CONF_OK; 2865 return NGX_CONF_OK;
2866 } 2866 }
2867 } 2867 }
2868 2868
2869 if (conf->server_name.data == NULL) { 2869 if (conf->server_name.data == NULL) {
3264 static char * 3264 static char *
3265 ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 3265 ngx_http_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3266 { 3266 {
3267 ngx_http_core_srv_conf_t *cscf = conf; 3267 ngx_http_core_srv_conf_t *cscf = conf;
3268 3268
3269 ngx_str_t *value, size; 3269 ngx_str_t *value, size;
3270 ngx_url_t u; 3270 ngx_url_t u;
3271 ngx_uint_t n; 3271 ngx_uint_t n;
3272 ngx_http_listen_t ls; 3272 ngx_http_listen_opt_t lsopt;
3273 3273
3274 cscf->listen = 1; 3274 cscf->listen = 1;
3275 3275
3276 value = cf->args->elts; 3276 value = cf->args->elts;
3277 3277
3289 } 3289 }
3290 3290
3291 return NGX_CONF_ERROR; 3291 return NGX_CONF_ERROR;
3292 } 3292 }
3293 3293
3294 ngx_memzero(&ls, sizeof(ngx_http_listen_t)); 3294 ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t));
3295 3295
3296 ngx_memcpy(ls.sockaddr, u.sockaddr, u.socklen); 3296 ngx_memcpy(lsopt.sockaddr, u.sockaddr, u.socklen);
3297 3297
3298 ls.socklen = u.socklen; 3298 lsopt.socklen = u.socklen;
3299 ls.opt.backlog = NGX_LISTEN_BACKLOG; 3299 lsopt.backlog = NGX_LISTEN_BACKLOG;
3300 ls.opt.rcvbuf = -1; 3300 lsopt.rcvbuf = -1;
3301 ls.opt.sndbuf = -1; 3301 lsopt.sndbuf = -1;
3302 ls.opt.wildcard = u.wildcard; 3302 lsopt.wildcard = u.wildcard;
3303 3303
3304 (void) ngx_sock_ntop((struct sockaddr *) &ls.sockaddr, ls.opt.addr, 3304 (void) ngx_sock_ntop((struct sockaddr *) &lsopt.sockaddr, lsopt.addr,
3305 NGX_SOCKADDR_STRLEN, 1); 3305 NGX_SOCKADDR_STRLEN, 1);
3306 3306
3307 if (cf->args->nelts > 2 && ngx_strcmp(value[2].data, "default") == 0) { 3307 if (cf->args->nelts > 2 && ngx_strcmp(value[2].data, "default") == 0) {
3308 ls.opt.default_server = 1; 3308 lsopt.default_server = 1;
3309 n = 3; 3309 n = 3;
3310 3310
3311 } else { 3311 } else {
3312 n = 2; 3312 n = 2;
3313 } 3313 }
3314 3314
3315 for ( /* void */ ; n < cf->args->nelts; n++) { 3315 for ( /* void */ ; n < cf->args->nelts; n++) {
3316 3316
3317 if (ls.opt.default_server == 0) { 3317 if (lsopt.default_server == 0) {
3318 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 3318 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3319 "\"%V\" parameter can be specified for " 3319 "\"%V\" parameter can be specified for "
3320 "the default \"listen\" directive only", 3320 "the default \"listen\" directive only",
3321 &value[n]); 3321 &value[n]);
3322 return NGX_CONF_ERROR; 3322 return NGX_CONF_ERROR;
3323 } 3323 }
3324 3324
3325 if (ngx_strcmp(value[n].data, "bind") == 0) { 3325 if (ngx_strcmp(value[n].data, "bind") == 0) {
3326 ls.opt.bind = 1; 3326 lsopt.bind = 1;
3327 continue; 3327 continue;
3328 } 3328 }
3329 3329
3330 if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) { 3330 if (ngx_strncmp(value[n].data, "backlog=", 8) == 0) {
3331 ls.opt.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8); 3331 lsopt.backlog = ngx_atoi(value[n].data + 8, value[n].len - 8);
3332 ls.opt.bind = 1; 3332 lsopt.bind = 1;
3333 3333
3334 if (ls.opt.backlog == NGX_ERROR || ls.opt.backlog == 0) { 3334 if (lsopt.backlog == NGX_ERROR || lsopt.backlog == 0) {
3335 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 3335 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3336 "invalid backlog \"%V\"", &value[n]); 3336 "invalid backlog \"%V\"", &value[n]);
3337 return NGX_CONF_ERROR; 3337 return NGX_CONF_ERROR;
3338 } 3338 }
3339 3339
3342 3342
3343 if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) { 3343 if (ngx_strncmp(value[n].data, "rcvbuf=", 7) == 0) {
3344 size.len = value[n].len - 7; 3344 size.len = value[n].len - 7;
3345 size.data = value[n].data + 7; 3345 size.data = value[n].data + 7;
3346 3346
3347 ls.opt.rcvbuf = ngx_parse_size(&size); 3347 lsopt.rcvbuf = ngx_parse_size(&size);
3348 ls.opt.bind = 1; 3348 lsopt.bind = 1;
3349 3349
3350 if (ls.opt.rcvbuf == NGX_ERROR) { 3350 if (lsopt.rcvbuf == NGX_ERROR) {
3351 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 3351 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3352 "invalid rcvbuf \"%V\"", &value[n]); 3352 "invalid rcvbuf \"%V\"", &value[n]);
3353 return NGX_CONF_ERROR; 3353 return NGX_CONF_ERROR;
3354 } 3354 }
3355 3355
3358 3358
3359 if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) { 3359 if (ngx_strncmp(value[n].data, "sndbuf=", 7) == 0) {
3360 size.len = value[n].len - 7; 3360 size.len = value[n].len - 7;
3361 size.data = value[n].data + 7; 3361 size.data = value[n].data + 7;
3362 3362
3363 ls.opt.sndbuf = ngx_parse_size(&size); 3363 lsopt.sndbuf = ngx_parse_size(&size);
3364 ls.opt.bind = 1; 3364 lsopt.bind = 1;
3365 3365
3366 if (ls.opt.sndbuf == NGX_ERROR) { 3366 if (lsopt.sndbuf == NGX_ERROR) {
3367 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 3367 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3368 "invalid sndbuf \"%V\"", &value[n]); 3368 "invalid sndbuf \"%V\"", &value[n]);
3369 return NGX_CONF_ERROR; 3369 return NGX_CONF_ERROR;
3370 } 3370 }
3371 3371
3372 continue; 3372 continue;
3373 } 3373 }
3374 3374
3375 if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) { 3375 if (ngx_strncmp(value[n].data, "accept_filter=", 14) == 0) {
3376 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER) 3376 #if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)
3377 ls.opt.accept_filter = (char *) &value[n].data[14]; 3377 lsopt.accept_filter = (char *) &value[n].data[14];
3378 ls.opt.bind = 1; 3378 lsopt.bind = 1;
3379 #else 3379 #else
3380 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 3380 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3381 "accept filters \"%V\" are not supported " 3381 "accept filters \"%V\" are not supported "
3382 "on this platform, ignored", 3382 "on this platform, ignored",
3383 &value[n]); 3383 &value[n]);
3385 continue; 3385 continue;
3386 } 3386 }
3387 3387
3388 if (ngx_strcmp(value[n].data, "deferred") == 0) { 3388 if (ngx_strcmp(value[n].data, "deferred") == 0) {
3389 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT) 3389 #if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)
3390 ls.opt.deferred_accept = 1; 3390 lsopt.deferred_accept = 1;
3391 ls.opt.bind = 1; 3391 lsopt.bind = 1;
3392 #else 3392 #else
3393 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 3393 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3394 "the deferred accept is not supported " 3394 "the deferred accept is not supported "
3395 "on this platform, ignored"); 3395 "on this platform, ignored");
3396 #endif 3396 #endif
3399 3399
3400 if (ngx_strncmp(value[n].data, "ipv6only=o", 10) == 0) { 3400 if (ngx_strncmp(value[n].data, "ipv6only=o", 10) == 0) {
3401 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) 3401 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
3402 struct sockaddr *sa; 3402 struct sockaddr *sa;
3403 3403
3404 sa = (struct sockaddr *) ls.sockaddr; 3404 sa = (struct sockaddr *) lsopt.sockaddr;
3405 3405
3406 if (sa->sa_family == AF_INET6) { 3406 if (sa->sa_family == AF_INET6) {
3407 3407
3408 if (ngx_strcmp(&value[n].data[10], "n") == 0) { 3408 if (ngx_strcmp(&value[n].data[10], "n") == 0) {
3409 ls.opt.ipv6only = 1; 3409 lsopt.ipv6only = 1;
3410 3410
3411 } else if (ngx_strcmp(&value[n].data[10], "ff") == 0) { 3411 } else if (ngx_strcmp(&value[n].data[10], "ff") == 0) {
3412 ls.opt.ipv6only = 2; 3412 lsopt.ipv6only = 2;
3413 3413
3414 } else { 3414 } else {
3415 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 3415 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3416 "invalid ipv6only flags \"%s\"", 3416 "invalid ipv6only flags \"%s\"",
3417 &value[n].data[9]); 3417 &value[n].data[9]);
3418 return NGX_CONF_ERROR; 3418 return NGX_CONF_ERROR;
3419 } 3419 }
3420 3420
3421 ls.opt.bind = 1; 3421 lsopt.bind = 1;
3422 3422
3423 } else { 3423 } else {
3424 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 3424 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3425 "ipv6only is not supported " 3425 "ipv6only is not supported "
3426 "on addr \"%s\", ignored", ls.opt.addr); 3426 "on addr \"%s\", ignored", lsopt.addr);
3427 } 3427 }
3428 3428
3429 continue; 3429 continue;
3430 #else 3430 #else
3431 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 3431 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3435 #endif 3435 #endif
3436 } 3436 }
3437 3437
3438 if (ngx_strcmp(value[n].data, "ssl") == 0) { 3438 if (ngx_strcmp(value[n].data, "ssl") == 0) {
3439 #if (NGX_HTTP_SSL) 3439 #if (NGX_HTTP_SSL)
3440 ls.opt.ssl = 1; 3440 lsopt.ssl = 1;
3441 continue; 3441 continue;
3442 #else 3442 #else
3443 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 3443 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3444 "the \"ssl\" parameter requires " 3444 "the \"ssl\" parameter requires "
3445 "ngx_http_ssl_module"); 3445 "ngx_http_ssl_module");
3450 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 3450 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
3451 "the invalid \"%V\" parameter", &value[n]); 3451 "the invalid \"%V\" parameter", &value[n]);
3452 return NGX_CONF_ERROR; 3452 return NGX_CONF_ERROR;
3453 } 3453 }
3454 3454
3455 if (ngx_http_add_listen(cf, cscf, &ls) == NGX_OK) { 3455 if (ngx_http_add_listen(cf, cscf, &lsopt) == NGX_OK) {
3456 return NGX_CONF_OK; 3456 return NGX_CONF_OK;
3457 } 3457 }
3458 3458
3459 return NGX_CONF_ERROR; 3459 return NGX_CONF_ERROR;
3460 } 3460 }