| 2046 | |
| 2047 | |
| 2048 | int get_next_su(struct proxy_l *p, union sockaddr_union* su, int add_to_bl) |
| 2049 | { |
| 2050 | struct hostent *he; |
| 2051 | struct bl_rule *list; |
| 2052 | struct net ip_net; |
| 2053 | int n; |
| 2054 | |
| 2055 | if (failover_bl && add_to_bl) { |
| 2056 | memset( &ip_net, 0xff , sizeof(struct net)); |
| 2057 | hostent2ip_addr( &ip_net.ip, &p->host, p->addr_idx); |
| 2058 | ip_net.mask.af = ip_net.ip.af; |
| 2059 | ip_net.mask.len = ip_net.ip.len; |
| 2060 | list = 0; |
| 2061 | n = add_rule_to_list( &list, &list, &ip_net, 0, p->port, p->proto, 0); |
| 2062 | if (n!=0) { |
| 2063 | LM_ERR("failed to build bl rule\n"); |
| 2064 | } else { |
| 2065 | add_list_to_head( failover_bl, list, list, 0, DNS_BL_EXPIRE); |
| 2066 | } |
| 2067 | } |
| 2068 | |
| 2069 | /* any more available IPs in he ? */ |
| 2070 | if ( p->host.h_addr_list[++p->addr_idx] ) { |
| 2071 | /* yes -> return the IP*/ |
| 2072 | hostent2su( su, &p->host, p->addr_idx, (p->port)?p->port:SIP_PORT); |
| 2073 | return 0; |
| 2074 | } |
| 2075 | |
| 2076 | /* get a new he from DNS */ |
| 2077 | he = get_next_he( &p->dn, &p->proto, &p->port); |
| 2078 | if (he==NULL) |
| 2079 | return -1; |
| 2080 | |
| 2081 | /* replace the current he */ |
| 2082 | if (p->flags&PROXY_SHM_FLAG) { |
| 2083 | free_shm_hostent( &p->host ); |
| 2084 | n = hostent_shm_cpy(&(p->host), he); |
| 2085 | } else { |
| 2086 | free_hostent( &p->host ); |
| 2087 | n = hostent_cpy(&(p->host), he); |
| 2088 | } |
| 2089 | if (n!=0) { |
| 2090 | free_dns_res( p ); |
| 2091 | return -1; |
| 2092 | } |
| 2093 | |
| 2094 | hostent2su( su, &p->host, 0, (p->port)?p->port:SIP_PORT); |
| 2095 | p->addr_idx = 0; |
| 2096 | return 0; |
| 2097 | } |
| 2098 | |
| 2099 | |
| 2100 |
no test coverage detected