comparison src/http/ngx_http.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
17 static ngx_int_t ngx_http_init_phase_handlers(ngx_conf_t *cf, 17 static ngx_int_t ngx_http_init_phase_handlers(ngx_conf_t *cf,
18 ngx_http_core_main_conf_t *cmcf); 18 ngx_http_core_main_conf_t *cmcf);
19 19
20 static ngx_int_t ngx_http_add_addresses(ngx_conf_t *cf, 20 static ngx_int_t ngx_http_add_addresses(ngx_conf_t *cf,
21 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_port_t *port, 21 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_port_t *port,
22 ngx_http_listen_t *listen); 22 ngx_http_listen_opt_t *lsopt);
23 static ngx_int_t ngx_http_add_address(ngx_conf_t *cf, 23 static ngx_int_t ngx_http_add_address(ngx_conf_t *cf,
24 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_port_t *port, 24 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_port_t *port,
25 ngx_http_listen_t *listen); 25 ngx_http_listen_opt_t *lsopt);
26 static ngx_int_t ngx_http_add_server(ngx_conf_t *cf, 26 static ngx_int_t ngx_http_add_server(ngx_conf_t *cf,
27 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_addr_t *addr); 27 ngx_http_core_srv_conf_t *cscf, ngx_http_conf_addr_t *addr);
28 28
29 static char *ngx_http_merge_locations(ngx_conf_t *cf, 29 static char *ngx_http_merge_locations(ngx_conf_t *cf,
30 ngx_queue_t *locations, void **loc_conf, ngx_http_module_t *module, 30 ngx_queue_t *locations, void **loc_conf, ngx_http_module_t *module,
1093 } 1093 }
1094 1094
1095 1095
1096 ngx_int_t 1096 ngx_int_t
1097 ngx_http_add_listen(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, 1097 ngx_http_add_listen(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
1098 ngx_http_listen_t *listen) 1098 ngx_http_listen_opt_t *lsopt)
1099 { 1099 {
1100 in_port_t p; 1100 in_port_t p;
1101 ngx_uint_t i; 1101 ngx_uint_t i;
1102 struct sockaddr *sa; 1102 struct sockaddr *sa;
1103 struct sockaddr_in *sin; 1103 struct sockaddr_in *sin;
1115 if (cmcf->ports == NULL) { 1115 if (cmcf->ports == NULL) {
1116 return NGX_ERROR; 1116 return NGX_ERROR;
1117 } 1117 }
1118 } 1118 }
1119 1119
1120 sa = (struct sockaddr *) &listen->sockaddr; 1120 sa = (struct sockaddr *) &lsopt->sockaddr;
1121 1121
1122 switch (sa->sa_family) { 1122 switch (sa->sa_family) {
1123 1123
1124 #if (NGX_HAVE_INET6) 1124 #if (NGX_HAVE_INET6)
1125 case AF_INET6: 1125 case AF_INET6:
1141 continue; 1141 continue;
1142 } 1142 }
1143 1143
1144 /* a port is already in the port list */ 1144 /* a port is already in the port list */
1145 1145
1146 return ngx_http_add_addresses(cf, cscf, &port[i], listen); 1146 return ngx_http_add_addresses(cf, cscf, &port[i], lsopt);
1147 } 1147 }
1148 1148
1149 /* add a port to the port list */ 1149 /* add a port to the port list */
1150 1150
1151 port = ngx_array_push(cmcf->ports); 1151 port = ngx_array_push(cmcf->ports);
1155 1155
1156 port->family = sa->sa_family; 1156 port->family = sa->sa_family;
1157 port->port = p; 1157 port->port = p;
1158 port->addrs.elts = NULL; 1158 port->addrs.elts = NULL;
1159 1159
1160 return ngx_http_add_address(cf, cscf, port, listen); 1160 return ngx_http_add_address(cf, cscf, port, lsopt);
1161 } 1161 }
1162 1162
1163 1163
1164 static ngx_int_t 1164 static ngx_int_t
1165 ngx_http_add_addresses(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, 1165 ngx_http_add_addresses(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
1166 ngx_http_conf_port_t *port, ngx_http_listen_t *listen) 1166 ngx_http_conf_port_t *port, ngx_http_listen_opt_t *lsopt)
1167 { 1167 {
1168 u_char *p; 1168 u_char *p;
1169 size_t len, off; 1169 size_t len, off;
1170 ngx_uint_t i; 1170 ngx_uint_t i;
1171 struct sockaddr *sa; 1171 struct sockaddr *sa;
1174 /* 1174 /*
1175 * we can not compare whole sockaddr struct's as kernel 1175 * we can not compare whole sockaddr struct's as kernel
1176 * may fill some fields in inherited sockaddr struct's 1176 * may fill some fields in inherited sockaddr struct's
1177 */ 1177 */
1178 1178
1179 sa = (struct sockaddr *) &listen->sockaddr; 1179 sa = (struct sockaddr *) &lsopt->sockaddr;
1180 1180
1181 switch (sa->sa_family) { 1181 switch (sa->sa_family) {
1182 1182
1183 #if (NGX_HAVE_INET6) 1183 #if (NGX_HAVE_INET6)
1184 case AF_INET6: 1184 case AF_INET6:
1191 off = offsetof(struct sockaddr_in, sin_addr); 1191 off = offsetof(struct sockaddr_in, sin_addr);
1192 len = 4; 1192 len = 4;
1193 break; 1193 break;
1194 } 1194 }
1195 1195
1196 p = listen->sockaddr + off; 1196 p = lsopt->sockaddr + off;
1197 1197
1198 addr = port->addrs.elts; 1198 addr = port->addrs.elts;
1199 1199
1200 for (i = 0; i < port->addrs.nelts; i++) { 1200 for (i = 0; i < port->addrs.nelts; i++) {
1201 1201
1202 if (ngx_memcmp(p, (u_char *) addr[i].sockaddr + off, len) != 0) { 1202 if (ngx_memcmp(p, (u_char *) addr[i].opt.sockaddr + off, len) != 0) {
1203 continue; 1203 continue;
1204 } 1204 }
1205 1205
1206 /* the address is already in the address list */ 1206 /* the address is already in the address list */
1207 1207
1209 return NGX_ERROR; 1209 return NGX_ERROR;
1210 } 1210 }
1211 1211
1212 /* check the duplicate "default" server for this address:port */ 1212 /* check the duplicate "default" server for this address:port */
1213 1213
1214 if (listen->opt.default_server) { 1214 if (lsopt->default_server) {
1215 1215
1216 if (addr[i].opt.default_server) { 1216 if (addr[i].opt.default_server) {
1217 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 1217 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1218 "the duplicate default server"); 1218 "the duplicate default server");
1219 return NGX_ERROR; 1219 return NGX_ERROR;
1220 } 1220 }
1221 1221
1222 addr[i].opt = *lsopt;
1222 addr[i].core_srv_conf = cscf; 1223 addr[i].core_srv_conf = cscf;
1223 addr[i].opt = listen->opt;
1224 } 1224 }
1225 1225
1226 return NGX_OK; 1226 return NGX_OK;
1227 } 1227 }
1228 1228
1229 /* add the address to the addresses list that bound to this port */ 1229 /* add the address to the addresses list that bound to this port */
1230 1230
1231 return ngx_http_add_address(cf, cscf, port, listen); 1231 return ngx_http_add_address(cf, cscf, port, lsopt);
1232 } 1232 }
1233 1233
1234 1234
1235 /* 1235 /*
1236 * add the server address, the server names and the server core module 1236 * add the server address, the server names and the server core module
1237 * configurations to the port list 1237 * configurations to the port list
1238 */ 1238 */
1239 1239
1240 static ngx_int_t 1240 static ngx_int_t
1241 ngx_http_add_address(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf, 1241 ngx_http_add_address(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
1242 ngx_http_conf_port_t *port, ngx_http_listen_t *listen) 1242 ngx_http_conf_port_t *port, ngx_http_listen_opt_t *lsopt)
1243 { 1243 {
1244 ngx_http_conf_addr_t *addr; 1244 ngx_http_conf_addr_t *addr;
1245 1245
1246 if (port->addrs.elts == NULL) { 1246 if (port->addrs.elts == NULL) {
1247 if (ngx_array_init(&port->addrs, cf->temp_pool, 4, 1247 if (ngx_array_init(&port->addrs, cf->temp_pool, 4,
1255 addr = ngx_array_push(&port->addrs); 1255 addr = ngx_array_push(&port->addrs);
1256 if (addr == NULL) { 1256 if (addr == NULL) {
1257 return NGX_ERROR; 1257 return NGX_ERROR;
1258 } 1258 }
1259 1259
1260 ngx_memcpy(addr->sockaddr, listen->sockaddr, listen->socklen); 1260 addr->opt = *lsopt;
1261 addr->socklen = listen->socklen;
1262 addr->hash.buckets = NULL; 1261 addr->hash.buckets = NULL;
1263 addr->hash.size = 0; 1262 addr->hash.size = 0;
1264 addr->wc_head = NULL; 1263 addr->wc_head = NULL;
1265 addr->wc_tail = NULL; 1264 addr->wc_tail = NULL;
1266 #if (NGX_PCRE) 1265 #if (NGX_PCRE)
1267 addr->nregex = 0; 1266 addr->nregex = 0;
1268 addr->regex = NULL; 1267 addr->regex = NULL;
1269 #endif 1268 #endif
1270 addr->core_srv_conf = cscf; 1269 addr->core_srv_conf = cscf;
1271 addr->servers.elts = NULL; 1270 addr->servers.elts = NULL;
1272 addr->opt = listen->opt;
1273 1271
1274 return ngx_http_add_server(cf, cscf, addr); 1272 return ngx_http_add_server(cf, cscf, addr);
1275 } 1273 }
1276 1274
1277 1275
1627 { 1625 {
1628 ngx_listening_t *ls; 1626 ngx_listening_t *ls;
1629 ngx_http_core_loc_conf_t *clcf; 1627 ngx_http_core_loc_conf_t *clcf;
1630 ngx_http_core_srv_conf_t *cscf; 1628 ngx_http_core_srv_conf_t *cscf;
1631 1629
1632 ls = ngx_create_listening(cf, addr->sockaddr, addr->socklen); 1630 ls = ngx_create_listening(cf, addr->opt.sockaddr, addr->opt.socklen);
1633 if (ls == NULL) { 1631 if (ls == NULL) {
1634 return NULL; 1632 return NULL;
1635 } 1633 }
1636 1634
1637 ls->addr_ntop = 1; 1635 ls->addr_ntop = 1;
1696 1694
1697 addrs = hport->addrs; 1695 addrs = hport->addrs;
1698 1696
1699 for (i = 0; i < hport->naddrs; i++) { 1697 for (i = 0; i < hport->naddrs; i++) {
1700 1698
1701 sin = (struct sockaddr_in *) addr[i].sockaddr; 1699 sin = (struct sockaddr_in *) addr[i].opt.sockaddr;
1702 addrs[i].addr = sin->sin_addr.s_addr; 1700 addrs[i].addr = sin->sin_addr.s_addr;
1703 addrs[i].conf.core_srv_conf = addr[i].core_srv_conf; 1701 addrs[i].conf.core_srv_conf = addr[i].core_srv_conf;
1704 #if (NGX_HTTP_SSL) 1702 #if (NGX_HTTP_SSL)
1705 addrs[i].conf.ssl = addr[i].opt.ssl; 1703 addrs[i].conf.ssl = addr[i].opt.ssl;
1706 #endif 1704 #endif
1757 1755
1758 addrs6 = hport->addrs; 1756 addrs6 = hport->addrs;
1759 1757
1760 for (i = 0; i < hport->naddrs; i++) { 1758 for (i = 0; i < hport->naddrs; i++) {
1761 1759
1762 sin6 = (struct sockaddr_in6 *) addr[i].sockaddr; 1760 sin6 = (struct sockaddr_in6 *) addr[i].opt.sockaddr;
1763 addrs6[i].addr6 = sin6->sin6_addr; 1761 addrs6[i].addr6 = sin6->sin6_addr;
1764 addrs6[i].conf.core_srv_conf = addr[i].core_srv_conf; 1762 addrs6[i].conf.core_srv_conf = addr[i].core_srv_conf;
1765 #if (NGX_HTTP_SSL) 1763 #if (NGX_HTTP_SSL)
1766 addrs6[i].conf.ssl = addr[i].opt.ssl; 1764 addrs6[i].conf.ssl = addr[i].opt.ssl;
1767 #endif 1765 #endif