Mercurial > hg > nginx-vendor-current
comparison src/http/modules/ngx_http_geo_module.c @ 454:a8424ffa495c NGINX_0_7_39
nginx 0.7.39
*) Bugfix: large response with SSI might hang, if gzipping was enabled;
the bug had appeared in 0.7.28.
Thanks to Artem Bokhan.
*) Bugfix: a segmentation fault might occur in worker process, if short
static variants are used in a "try_files" directive.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 02 Mar 2009 00:00:00 +0300 |
parents | 76a79816b771 |
children | 24b676623d4f |
comparison
equal
deleted
inserted
replaced
453:9ef0e36f3cd5 | 454:a8424ffa495c |
---|---|
776 ngx_str_t *value) | 776 ngx_str_t *value) |
777 { | 777 { |
778 ngx_int_t rc, del; | 778 ngx_int_t rc, del; |
779 ngx_str_t *net; | 779 ngx_str_t *net; |
780 ngx_uint_t i; | 780 ngx_uint_t i; |
781 ngx_inet_cidr_t cidrin; | 781 ngx_cidr_t cidr; |
782 ngx_http_variable_value_t *val, *old; | 782 ngx_http_variable_value_t *val, *old; |
783 | 783 |
784 if (ctx->tree == NULL) { | 784 if (ctx->tree == NULL) { |
785 ctx->tree = ngx_radix_tree_create(ctx->pool, -1); | 785 ctx->tree = ngx_radix_tree_create(ctx->pool, -1); |
786 if (ctx->tree == NULL) { | 786 if (ctx->tree == NULL) { |
787 return NGX_CONF_ERROR; | 787 return NGX_CONF_ERROR; |
788 } | 788 } |
789 } | 789 } |
790 | 790 |
791 if (ngx_strcmp(value[0].data, "default") == 0) { | 791 if (ngx_strcmp(value[0].data, "default") == 0) { |
792 cidrin.addr = 0; | 792 cidr.u.in.addr = 0; |
793 cidrin.mask = 0; | 793 cidr.u.in.mask = 0; |
794 net = &value[0]; | 794 net = &value[0]; |
795 | 795 |
796 } else { | 796 } else { |
797 if (ngx_strcmp(value[0].data, "delete") == 0) { | 797 if (ngx_strcmp(value[0].data, "delete") == 0) { |
798 net = &value[1]; | 798 net = &value[1]; |
802 net = &value[0]; | 802 net = &value[0]; |
803 del = 0; | 803 del = 0; |
804 } | 804 } |
805 | 805 |
806 if (ngx_strcmp(net->data, "255.255.255.255") == 0) { | 806 if (ngx_strcmp(net->data, "255.255.255.255") == 0) { |
807 cidrin.addr = 0xffffffff; | 807 cidr.u.in.addr = 0xffffffff; |
808 cidrin.mask = 0xffffffff; | 808 cidr.u.in.mask = 0xffffffff; |
809 | 809 |
810 } else { | 810 } else { |
811 rc = ngx_ptocidr(net, &cidrin); | 811 rc = ngx_ptocidr(net, &cidr); |
812 | 812 |
813 if (rc == NGX_ERROR) { | 813 if (rc == NGX_ERROR) { |
814 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 814 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
815 "invalid network \"%V\"", net); | 815 "invalid network \"%V\"", net); |
816 return NGX_CONF_ERROR; | 816 return NGX_CONF_ERROR; |
817 } | 817 } |
818 | 818 |
819 if (cidr.family != AF_INET) { | |
820 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
821 "\"geo\" supports IPv4 only"); | |
822 return NGX_CONF_ERROR; | |
823 } | |
824 | |
819 if (rc == NGX_DONE) { | 825 if (rc == NGX_DONE) { |
820 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | 826 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
821 "low address bits of %V are meaningless", | 827 "low address bits of %V are meaningless", |
822 net); | 828 net); |
823 } | 829 } |
824 | 830 |
825 cidrin.addr = ntohl(cidrin.addr); | 831 cidr.u.in.addr = ntohl(cidr.u.in.addr); |
826 cidrin.mask = ntohl(cidrin.mask); | 832 cidr.u.in.mask = ntohl(cidr.u.in.mask); |
827 } | 833 } |
828 | 834 |
829 if (del) { | 835 if (del) { |
830 if (ngx_radix32tree_delete(ctx->tree, cidrin.addr, cidrin.mask) | 836 if (ngx_radix32tree_delete(ctx->tree, cidr.u.in.addr, |
837 cidr.u.in.mask) | |
831 != NGX_OK) | 838 != NGX_OK) |
832 { | 839 { |
833 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | 840 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
834 "no network \"%V\" to delete", net); | 841 "no network \"%V\" to delete", net); |
835 } | 842 } |
843 if (val == NULL) { | 850 if (val == NULL) { |
844 return NGX_CONF_ERROR; | 851 return NGX_CONF_ERROR; |
845 } | 852 } |
846 | 853 |
847 for (i = 2; i; i--) { | 854 for (i = 2; i; i--) { |
848 rc = ngx_radix32tree_insert(ctx->tree, cidrin.addr, cidrin.mask, | 855 rc = ngx_radix32tree_insert(ctx->tree, cidr.u.in.addr, cidr.u.in.mask, |
849 (uintptr_t) val); | 856 (uintptr_t) val); |
850 if (rc == NGX_OK) { | 857 if (rc == NGX_OK) { |
851 return NGX_CONF_OK; | 858 return NGX_CONF_OK; |
852 } | 859 } |
853 | 860 |
856 } | 863 } |
857 | 864 |
858 /* rc == NGX_BUSY */ | 865 /* rc == NGX_BUSY */ |
859 | 866 |
860 old = (ngx_http_variable_value_t *) | 867 old = (ngx_http_variable_value_t *) |
861 ngx_radix32tree_find(ctx->tree, cidrin.addr & cidrin.mask); | 868 ngx_radix32tree_find(ctx->tree, cidr.u.in.addr & cidr.u.in.mask); |
862 | 869 |
863 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, | 870 ngx_conf_log_error(NGX_LOG_WARN, cf, 0, |
864 "duplicate network \"%V\", value: \"%v\", old value: \"%v\"", | 871 "duplicate network \"%V\", value: \"%v\", old value: \"%v\"", |
865 net, val, old); | 872 net, val, old); |
866 | 873 |
867 rc = ngx_radix32tree_delete(ctx->tree, cidrin.addr, cidrin.mask); | 874 rc = ngx_radix32tree_delete(ctx->tree, cidr.u.in.addr, cidr.u.in.mask); |
868 | 875 |
869 if (rc == NGX_ERROR) { | 876 if (rc == NGX_ERROR) { |
870 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid radix tree"); | 877 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid radix tree"); |
871 return NGX_CONF_ERROR; | 878 return NGX_CONF_ERROR; |
872 } | 879 } |