Klaus Demo nginx / f3959db
Merge of r4764: debug_connection with a domain name change. When "debug_connection" is configured with a domain name, only the first resolved address was used. Now all addresses will be used. Maxim Dounin 9 years ago
1 changed file(s) with 78 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
10611061 #if (NGX_DEBUG)
10621062 ngx_event_conf_t *ecf = conf;
10631063
1064 ngx_int_t rc;
1065 ngx_str_t *value;
1066 struct hostent *h;
1067 ngx_cidr_t *cidr;
1064 ngx_int_t rc;
1065 ngx_str_t *value;
1066 ngx_url_t u;
1067 ngx_cidr_t c, *cidr;
1068 ngx_uint_t i;
1069 struct sockaddr_in *sin;
1070 #if (NGX_HAVE_INET6)
1071 struct sockaddr_in6 *sin6;
1072 #endif
10681073
10691074 value = cf->args->elts;
10701075
1071 cidr = ngx_array_push(&ecf->debug_connection);
1076 #if (NGX_HAVE_UNIX_DOMAIN)
1077
1078 if (ngx_strcmp(value[1].data, "unix:") == 0) {
1079 cidr = ngx_array_push(&ecf->debug_connection);
1080 if (cidr == NULL) {
1081 return NGX_CONF_ERROR;
1082 }
1083
1084 cidr->family = AF_UNIX;
1085 return NGX_CONF_OK;
1086 }
1087
1088 #endif
1089
1090 rc = ngx_ptocidr(&value[1], &c);
1091
1092 if (rc != NGX_ERROR) {
1093 if (rc == NGX_DONE) {
1094 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
1095 "low address bits of %V are meaningless",
1096 &value[1]);
1097 }
1098
1099 cidr = ngx_array_push(&ecf->debug_connection);
1100 if (cidr == NULL) {
1101 return NGX_CONF_ERROR;
1102 }
1103
1104 *cidr = c;
1105
1106 return NGX_CONF_OK;
1107 }
1108
1109 ngx_memzero(&u, sizeof(ngx_url_t));
1110 u.host = value[1];
1111
1112 if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
1113 if (u.err) {
1114 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1115 "%s in debug_connection \"%V\"",
1116 u.err, &u.host);
1117 }
1118
1119 return NGX_CONF_ERROR;
1120 }
1121
1122 cidr = ngx_array_push_n(&ecf->debug_connection, u.naddrs);
10721123 if (cidr == NULL) {
10731124 return NGX_CONF_ERROR;
10741125 }
10751126
1076 #if (NGX_HAVE_UNIX_DOMAIN)
1077
1078 if (ngx_strcmp(value[1].data, "unix:") == 0) {
1079 cidr->family = AF_UNIX;
1080 return NGX_CONF_OK;
1081 }
1082
1083 #endif
1084
1085 rc = ngx_ptocidr(&value[1], cidr);
1086
1087 if (rc == NGX_DONE) {
1088 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
1089 "low address bits of %V are meaningless", &value[1]);
1090 return NGX_CONF_OK;
1091 }
1092
1093 if (rc == NGX_OK) {
1094 return NGX_CONF_OK;
1095 }
1096
1097 h = gethostbyname((char *) value[1].data);
1098
1099 if (h == NULL || h->h_addr_list[0] == NULL) {
1100 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1101 "host \"%s\" not found", value[1].data);
1102 return NGX_CONF_ERROR;
1103 }
1104
1105 cidr->family = AF_INET;
1106 cidr->u.in.mask = 0xffffffff;
1107 cidr->u.in.addr = *(in_addr_t *)(h->h_addr_list[0]);
1127 ngx_memzero(cidr, u.naddrs * sizeof(ngx_cidr_t));
1128
1129 for (i = 0; i < u.naddrs; i++) {
1130 cidr[i].family = u.addrs[i].sockaddr->sa_family;
1131
1132 switch (cidr[i].family) {
1133
1134 #if (NGX_HAVE_INET6)
1135 case AF_INET6:
1136 sin6 = (struct sockaddr_in6 *) u.addrs[i].sockaddr;
1137 cidr[i].u.in6.addr = sin6->sin6_addr;
1138 ngx_memset(cidr[i].u.in6.mask.s6_addr, 0xff, 16);
1139 break;
1140 #endif
1141
1142 default: /* AF_INET */
1143 sin = (struct sockaddr_in *) u.addrs[i].sockaddr;
1144 cidr[i].u.in.addr = sin->sin_addr.s_addr;
1145 cidr[i].u.in.mask = 0xffffffff;
1146 break;
1147 }
1148 }
11081149
11091150 #else
11101151