Mercurial > hg > nginx
comparison src/core/ngx_cycle.c @ 5473:d39ef821d03e
Core: externalized ngx_cmp_sockaddr().
It's also extended with the "cmp_port" argument to indicate
whether ports should be compared as well, or only addresses.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Fri, 06 Dec 2013 14:30:27 +0400 |
parents | d8ee8ef5dcde |
children | b2b5b1b74129 |
comparison
equal
deleted
inserted
replaced
5472:ab493c60d9ff | 5473:d39ef821d03e |
---|---|
9 #include <ngx_core.h> | 9 #include <ngx_core.h> |
10 #include <ngx_event.h> | 10 #include <ngx_event.h> |
11 | 11 |
12 | 12 |
13 static void ngx_destroy_cycle_pools(ngx_conf_t *conf); | 13 static void ngx_destroy_cycle_pools(ngx_conf_t *conf); |
14 static ngx_int_t ngx_cmp_sockaddr(struct sockaddr *sa1, struct sockaddr *sa2); | |
15 static ngx_int_t ngx_init_zone_pool(ngx_cycle_t *cycle, | 14 static ngx_int_t ngx_init_zone_pool(ngx_cycle_t *cycle, |
16 ngx_shm_zone_t *shm_zone); | 15 ngx_shm_zone_t *shm_zone); |
17 static ngx_int_t ngx_test_lockfile(u_char *file, ngx_log_t *log); | 16 static ngx_int_t ngx_test_lockfile(u_char *file, ngx_log_t *log); |
18 static void ngx_clean_old_cycles(ngx_event_t *ev); | 17 static void ngx_clean_old_cycles(ngx_event_t *ev); |
19 | 18 |
492 for (i = 0; i < old_cycle->listening.nelts; i++) { | 491 for (i = 0; i < old_cycle->listening.nelts; i++) { |
493 if (ls[i].ignore) { | 492 if (ls[i].ignore) { |
494 continue; | 493 continue; |
495 } | 494 } |
496 | 495 |
497 if (ngx_cmp_sockaddr(nls[n].sockaddr, ls[i].sockaddr) == NGX_OK) | 496 if (ngx_cmp_sockaddr(nls[n].sockaddr, nls[n].socklen, |
497 ls[i].sockaddr, ls[n].socklen, 1) | |
498 == NGX_OK) | |
498 { | 499 { |
499 nls[n].fd = ls[i].fd; | 500 nls[n].fd = ls[i].fd; |
500 nls[n].previous = &ls[i]; | 501 nls[n].previous = &ls[i]; |
501 ls[i].remain = 1; | 502 ls[i].remain = 1; |
502 | 503 |
847 ngx_destroy_pool(conf->pool); | 848 ngx_destroy_pool(conf->pool); |
848 } | 849 } |
849 | 850 |
850 | 851 |
851 static ngx_int_t | 852 static ngx_int_t |
852 ngx_cmp_sockaddr(struct sockaddr *sa1, struct sockaddr *sa2) | |
853 { | |
854 struct sockaddr_in *sin1, *sin2; | |
855 #if (NGX_HAVE_INET6) | |
856 struct sockaddr_in6 *sin61, *sin62; | |
857 #endif | |
858 #if (NGX_HAVE_UNIX_DOMAIN) | |
859 struct sockaddr_un *saun1, *saun2; | |
860 #endif | |
861 | |
862 if (sa1->sa_family != sa2->sa_family) { | |
863 return NGX_DECLINED; | |
864 } | |
865 | |
866 switch (sa1->sa_family) { | |
867 | |
868 #if (NGX_HAVE_INET6) | |
869 case AF_INET6: | |
870 sin61 = (struct sockaddr_in6 *) sa1; | |
871 sin62 = (struct sockaddr_in6 *) sa2; | |
872 | |
873 if (sin61->sin6_port != sin62->sin6_port) { | |
874 return NGX_DECLINED; | |
875 } | |
876 | |
877 if (ngx_memcmp(&sin61->sin6_addr, &sin62->sin6_addr, 16) != 0) { | |
878 return NGX_DECLINED; | |
879 } | |
880 | |
881 break; | |
882 #endif | |
883 | |
884 #if (NGX_HAVE_UNIX_DOMAIN) | |
885 case AF_UNIX: | |
886 saun1 = (struct sockaddr_un *) sa1; | |
887 saun2 = (struct sockaddr_un *) sa2; | |
888 | |
889 if (ngx_memcmp(&saun1->sun_path, &saun2->sun_path, | |
890 sizeof(saun1->sun_path)) | |
891 != 0) | |
892 { | |
893 return NGX_DECLINED; | |
894 } | |
895 | |
896 break; | |
897 #endif | |
898 | |
899 default: /* AF_INET */ | |
900 | |
901 sin1 = (struct sockaddr_in *) sa1; | |
902 sin2 = (struct sockaddr_in *) sa2; | |
903 | |
904 if (sin1->sin_port != sin2->sin_port) { | |
905 return NGX_DECLINED; | |
906 } | |
907 | |
908 if (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr) { | |
909 return NGX_DECLINED; | |
910 } | |
911 | |
912 break; | |
913 } | |
914 | |
915 return NGX_OK; | |
916 } | |
917 | |
918 | |
919 static ngx_int_t | |
920 ngx_init_zone_pool(ngx_cycle_t *cycle, ngx_shm_zone_t *zn) | 853 ngx_init_zone_pool(ngx_cycle_t *cycle, ngx_shm_zone_t *zn) |
921 { | 854 { |
922 u_char *file; | 855 u_char *file; |
923 ngx_slab_pool_t *sp; | 856 ngx_slab_pool_t *sp; |
924 | 857 |