Browse code

- better support for no ipv6 (-DUSE_IPV6 not defined) - more functions changed to static

Andrei Pelinescu-Onciul authored on 30/04/2008 19:52:25
Showing 1 changed files
... ...
@@ -496,7 +496,7 @@ int init_dns_cache_stats(int iproc_num)
496 496
 /* must be called with the DNS_LOCK hold
497 497
  * remove and entry from the hash, dec. its refcnt and if not referenced
498 498
  * anymore deletes it */
499
-void _dns_hash_remove(struct dns_hash_entry* e)
499
+inline static void _dns_hash_remove(struct dns_hash_entry* e)
500 500
 {
501 501
 	clist_rm(e, next, prev);
502 502
 #ifdef DNS_CACHE_DEBUG
... ...
@@ -1669,7 +1669,9 @@ inline static struct dns_hash_entry* dns_cache_do_request(str* name, int type)
1669 1669
 					atomic_set(&e->refcnt, 1);/* because we ret. a ref. to it*/
1670 1670
 				goto end; /* we do not cache obvious stuff */
1671 1671
 		}
1672
-	}else if (type==T_AAAA){
1672
+	}
1673
+#ifdef USE_IPV6
1674
+	else if (type==T_AAAA){
1673 1675
 		if ((ip=str2ip6(name))!=0){
1674 1676
 				e=dns_cache_mk_ip_entry(name, ip);
1675 1677
 				if (e)
... ...
@@ -1677,6 +1679,7 @@ inline static struct dns_hash_entry* dns_cache_do_request(str* name, int type)
1677 1677
 				goto end;/* we do not cache obvious stuff */
1678 1678
 		}
1679 1679
 	}
1680
+#endif /* USE_IPV6 */
1680 1681
 #ifdef DNS_WATCHDOG_SUPPORT
1681 1682
 	if (atomic_get(dns_servers_up)==0)
1682 1683
 		goto end; /* the servers are down, needless to perform the query */
... ...
@@ -2055,7 +2058,7 @@ no_more_rrs:
2055 2055
  * returns a pointer to the internal hostent structure on success or
2056 2056
  *          0 on error
2057 2057
  */
2058
-struct hostent* dns_entry2he(struct dns_hash_entry* e)
2058
+inline static struct hostent* dns_entry2he(struct dns_hash_entry* e)
2059 2059
 {
2060 2060
 	static struct hostent he;
2061 2061
 	static char hostname[256];
... ...
@@ -2074,9 +2077,16 @@ struct hostent* dns_entry2he(struct dns_hash_entry* e)
2074 2074
 			len=4;
2075 2075
 			break;
2076 2076
 		case T_AAAA:
2077
+#ifdef USE_IPV6
2077 2078
 			af=AF_INET6;
2078 2079
 			len=16;
2079 2080
 			break;
2081
+#else /* USE_IPV6 */
2082
+			LOG(L_ERR, "ERROR: dns_entry2he: IPv6 dns cache entry, but "
2083
+						"IPv6 support disabled at compile time"
2084
+						" (recompile with -DUSE_IPV6)\n");
2085
+			return 0;
2086
+#endif /* USE_IPV6 */
2080 2087
 		default:
2081 2088
 			LOG(L_CRIT, "BUG: dns_entry2he: wrong entry type %d for %.*s\n",
2082 2089
 					e->type, e->name_len, e->name);
... ...
@@ -2120,7 +2130,7 @@ struct hostent* dns_entry2he(struct dns_hash_entry* e)
2120 2120
  * to a statical internal hostent structure
2121 2121
  * returns 0 on success, <0 on error (see the error codes)
2122 2122
  */
2123
-struct hostent* dns_a_get_he(str* name)
2123
+inline static struct hostent* dns_a_get_he(str* name)
2124 2124
 {
2125 2125
 	struct dns_hash_entry* e;
2126 2126
 	struct ip_addr* ip;
... ...
@@ -2139,12 +2149,12 @@ struct hostent* dns_a_get_he(str* name)
2139 2139
 }
2140 2140
 
2141 2141
 
2142
-
2142
+#ifdef USE_IPV6
2143 2143
 /* gethostbyname compatibility: performs an aaaa_lookup and returns a pointer
2144 2144
  * to a statical internal hostent structure
2145 2145
  * returns 0 on success, <0 on error (see the error codes)
2146 2146
  */
2147
-struct hostent* dns_aaaa_get_he(str* name)
2147
+inline static struct hostent* dns_aaaa_get_he(str* name)
2148 2148
 {
2149 2149
 	struct dns_hash_entry* e;
2150 2150
 	struct ip_addr* ip;
... ...
@@ -2161,6 +2171,7 @@ struct hostent* dns_aaaa_get_he(str* name)
2161 2161
 	dns_hash_put(e);
2162 2162
 	return he;
2163 2163
 }
2164
+#endif
2164 2165
 
2165 2166
 
2166 2167
 
... ...
@@ -2175,10 +2186,16 @@ inline static int dns_rr2ip(int type, struct dns_rr* rr, struct ip_addr* ip)
2175 2175
 			return 0;
2176 2176
 			break;
2177 2177
 		case T_AAAA:
2178
+#ifdef USE_IPV6
2178 2179
 			ip->af=AF_INET6;
2179 2180
 			ip->len=16;
2180 2181
 			memcpy(ip->u.addr, ((struct aaaa_rdata*)rr->rdata)->ip6, 16);
2181 2182
 			return 0;
2183
+#else /* USE_IPV6 */
2184
+			LOG(L_ERR, "ERROR: dns_rr2ip: IPv6 dns rr, but IPv6 support"
2185
+					   "disabled at compile time (recompile with "
2186
+					   "-DUSE_IPV6)\n" );
2187
+#endif /*USE_IPV6 */
2182 2188
 			break;
2183 2189
 	}
2184 2190
 	return -1;
... ...
@@ -2196,9 +2213,9 @@ inline static int dns_rr2ip(int type, struct dns_rr* rr, struct ip_addr* ip)
2196 2196
  */
2197 2197
 struct hostent* dns_get_he(str* name, int flags)
2198 2198
 {
2199
+#ifdef USE_IPV6
2199 2200
 	struct hostent* he;
2200 2201
 
2201
-
2202 2202
 	if ((flags&(DNS_IPV6_FIRST|DNS_IPV6_ONLY))){
2203 2203
 		he=dns_aaaa_get_he(name);
2204 2204
 		if (he) return he;
... ...
@@ -2212,6 +2229,9 @@ struct hostent* dns_get_he(str* name, int flags)
2212 2212
 		he=dns_aaaa_get_he(name);
2213 2213
 	}
2214 2214
 	return he;
2215
+#else /* USE_IPV6 */
2216
+	return dns_a_get_he(name);
2217
+#endif /* USE_IPV6 */
2215 2218
 }
2216 2219
 
2217 2220
 
... ...
@@ -2589,8 +2609,10 @@ struct hostent* dns_sip_resolvehost(str* name, unsigned short* port,
2589 2589
  *  ...
2590 2590
  *  dns_hash_put(dns_entry); -- finished with the entry
2591 2591
  */
2592
-int dns_a_resolve(struct dns_hash_entry** e, unsigned char* rr_no,
2593
-					str* name, struct ip_addr* ip)
2592
+inline static int dns_a_resolve( struct dns_hash_entry** e,
2593
+								 unsigned char* rr_no,
2594
+								 str* name,
2595
+								 struct ip_addr* ip)
2594 2596
 {
2595 2597
 	struct dns_rr* rr;
2596 2598
 	int ret;
... ...
@@ -2630,14 +2652,16 @@ error:
2630 2630
 }
2631 2631
 
2632 2632
 
2633
-
2633
+#ifdef USE_IPV6
2634 2634
 /* lookup, fills the dns_entry pointer and the ip addr.
2635 2635
  *  (with the first good ip). if *e ==0 does the a lookup, and changes it
2636 2636
  *   to the result, if not it uses the current value and tries to use
2637 2637
  * Same as dns_a_resolve but for aaaa records (see above).
2638 2638
  */
2639
-int dns_aaaa_resolve(struct dns_hash_entry** e, unsigned char* rr_no,
2640
-						str* name, struct ip_addr* ip)
2639
+inline static int dns_aaaa_resolve( struct dns_hash_entry** e,
2640
+									unsigned char* rr_no,
2641
+									str* name,
2642
+									struct ip_addr* ip)
2641 2643
 {
2642 2644
 	struct dns_rr* rr;
2643 2645
 	int ret;
... ...
@@ -2673,6 +2697,7 @@ int dns_aaaa_resolve(struct dns_hash_entry** e, unsigned char* rr_no,
2673 2673
 error:
2674 2674
 	return ret;
2675 2675
 }
2676
+#endif /* USE_IPV6 */
2676 2677
 
2677 2678
 
2678 2679
 
... ...
@@ -2685,13 +2710,17 @@ error:
2685 2685
  *  see dns_a_resolve() for the rest of the params., examples a.s.o
2686 2686
  *  WARNING: don't forget dns_hash_put(*e) when e is not needed anymore
2687 2687
  */
2688
-int dns_ip_resolve(struct dns_hash_entry** e, unsigned char* rr_no,
2689
-					str* name, struct ip_addr* ip, int flags)
2688
+inline static int dns_ip_resolve(	struct dns_hash_entry** e,
2689
+									unsigned char* rr_no,
2690
+									str* name,
2691
+									struct ip_addr* ip,
2692
+									int flags)
2690 2693
 {
2691 2694
 	int ret;
2692 2695
 
2693 2696
 	ret=-E_DNS_NO_IP;
2694 2697
 	if (*e==0){ /* first call */
2698
+#ifdef USE_IPV6
2695 2699
 		if ((flags&(DNS_IPV6_FIRST|DNS_IPV6_ONLY))){
2696 2700
 			ret=dns_aaaa_resolve(e, rr_no, name, ip);
2697 2701
 			if (ret>=0) return ret;
... ...
@@ -2704,9 +2733,13 @@ int dns_ip_resolve(struct dns_hash_entry** e, unsigned char* rr_no,
2704 2704
 		}else if (!(flags&(DNS_IPV6_ONLY|DNS_IPV4_ONLY))){
2705 2705
 			ret=dns_aaaa_resolve(e, rr_no, name, ip);
2706 2706
 		}
2707
+#else /* USE_IPV6 */
2708
+		ret=dns_a_resolve(e, rr_no, name, ip);
2709
+#endif /* USE_IPV6 */
2707 2710
 	}else if ((*e)->type==T_A){
2708 2711
 		/* continue A resolving */
2709 2712
 		ret=dns_a_resolve(e, rr_no, name, ip);
2713
+#ifdef USE_IPV6
2710 2714
 		if (ret>=0) return ret;
2711 2715
 		if (!(flags&(DNS_IPV6_ONLY|DNS_IPV6_FIRST|DNS_IPV4_ONLY))){
2712 2716
 			/* not found, try with AAAA */
... ...
@@ -2715,7 +2748,9 @@ int dns_ip_resolve(struct dns_hash_entry** e, unsigned char* rr_no,
2715 2715
 			*rr_no=0;
2716 2716
 			ret=dns_aaaa_resolve(e, rr_no, name, ip);
2717 2717
 		}
2718
+#endif /* USE_IPV6 */
2718 2719
 	}else if ((*e)->type==T_AAAA){
2720
+#ifdef USE_IPV6
2719 2721
 		/* continue AAAA resolving */
2720 2722
 		ret=dns_aaaa_resolve(e, rr_no, name, ip);
2721 2723
 		if (ret>=0) return ret;
... ...
@@ -2726,6 +2761,10 @@ int dns_ip_resolve(struct dns_hash_entry** e, unsigned char* rr_no,
2726 2726
 			*rr_no=0;
2727 2727
 			ret=dns_a_resolve(e, rr_no, name, ip);
2728 2728
 		}
2729
+#else /* USE_IPV6 */
2730
+		/* ipv6 disabled, try with A */
2731
+		ret=dns_a_resolve(e, rr_no, name, ip);
2732
+#endif /* USE_IPV6 */
2729 2733
 	}else{
2730 2734
 		LOG(L_CRIT, "BUG: dns_ip_resolve: invalid record type %d\n",
2731 2735
 					(*e)->type);
... ...
@@ -2747,7 +2786,7 @@ int dns_ip_resolve(struct dns_hash_entry** e, unsigned char* rr_no,
2747 2747
  *    record in the priority order and for records with the same priority
2748 2748
  *     the record with the higher weight (from the remaining ones)
2749 2749
  */
2750
-int dns_srv_resolve_nxt(struct dns_hash_entry** e,
2750
+inline static int dns_srv_resolve_nxt(struct dns_hash_entry** e,
2751 2751
 #ifdef DNS_SRV_LB
2752 2752
 						srv_flags_t* tried,
2753 2753
 #endif
... ...
@@ -2803,7 +2842,7 @@ error:
2803 2803
  *  WARNING: don't forget to init h prior to calling this function the first
2804 2804
  *   time and dns_srv_handle_put(h), even if error is returned
2805 2805
  */
2806
-int dns_srv_resolve_ip(struct dns_srv_handle* h,
2806
+inline static int dns_srv_resolve_ip(struct dns_srv_handle* h,
2807 2807
 					str* name, struct ip_addr* ip, unsigned short* port,
2808 2808
 					int flags)
2809 2809
 {
... ...
@@ -2860,7 +2899,7 @@ error:
2860 2860
  *            0 on success and it fills *ip, *port, dns_sip_resolve_h
2861 2861
  * WARNING: when finished, dns_sip_resolve_put(h) must be called!
2862 2862
  */
2863
-int dns_srv_sip_resolve(struct dns_srv_handle* h,  str* name,
2863
+inline static int dns_srv_sip_resolve(struct dns_srv_handle* h,  str* name,
2864 2864
 						struct ip_addr* ip, unsigned short* port, char* proto,
2865 2865
 						int flags)
2866 2866
 {
... ...
@@ -3014,7 +3053,7 @@ int dns_srv_sip_resolve(struct dns_srv_handle* h,  str* name,
3014 3014
  *            0 on success and it fills *ip, *port, dns_sip_resolve_h
3015 3015
  * WARNING: when finished, dns_sip_resolve_put(h) must be called!
3016 3016
  */
3017
-int dns_naptr_sip_resolve(struct dns_srv_handle* h,  str* name,
3017
+inline static int dns_naptr_sip_resolve(struct dns_srv_handle* h,  str* name,
3018 3018
 						struct ip_addr* ip, unsigned short* port, char* proto,
3019 3019
 						int flags)
3020 3020
 {
... ...
@@ -3119,7 +3158,7 @@ int dns_sip_resolve(struct dns_srv_handle* h,  str* name,
3119 3119
 /* performs an a lookup and fills ip with the first good ip address
3120 3120
  * returns 0 on success, <0 on error (see the error codes)
3121 3121
  */
3122
-int dns_a_get_ip(str* name, struct ip_addr* ip)
3122
+inline static int dns_a_get_ip(str* name, struct ip_addr* ip)
3123 3123
 {
3124 3124
 	struct dns_hash_entry* e;
3125 3125
 	int ret;
... ...
@@ -3133,8 +3172,8 @@ int dns_a_get_ip(str* name, struct ip_addr* ip)
3133 3133
 }
3134 3134
 
3135 3135
 
3136
-
3137
-int dns_aaaa_get_ip(str* name, struct ip_addr* ip)
3136
+#ifdef USE_IPV6
3137
+inline static int dns_aaaa_get_ip(str* name, struct ip_addr* ip)
3138 3138
 {
3139 3139
 	struct dns_hash_entry* e;
3140 3140
 	int ret;
... ...
@@ -3146,6 +3185,7 @@ int dns_aaaa_get_ip(str* name, struct ip_addr* ip)
3146 3146
 	if (e) dns_hash_put(e);
3147 3147
 	return ret;
3148 3148
 }
3149
+#endif /* USE_IPV6 */
3149 3150
 
3150 3151
 
3151 3152
 
... ...
@@ -3707,12 +3747,17 @@ static void dns_cache_add_record(rpc_t* rpc, void* ctx, unsigned short type)
3707 3707
 			}
3708 3708
 			break;
3709 3709
 		case T_AAAA:
3710
+#ifdef USE_IPV6
3710 3711
 			ip_addr = str2ip6(&ip);
3711 3712
 			if (!ip_addr) {
3712 3713
 				rpc->fault(ctx, 400, "Malformed ip address");
3713 3714
 				goto error;
3714 3715
 			}
3715 3716
 			break;
3717
+#else /* USE_IPV6 */
3718
+			rpc->fault(ctx, 400, "IPv6 support disabled ");
3719
+			return;
3720
+#endif /* USE_IPV6 */
3716 3721
 		/* case T_SRV: nothing to do */
3717 3722
 		}
3718 3723
 	}