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 1679
 				goto end;/* we do not cache obvious stuff */
1678 1680
 		}
1679 1681
 	}
1682
+#endif /* USE_IPV6 */
1680 1683
 #ifdef DNS_WATCHDOG_SUPPORT
1681 1684
 	if (atomic_get(dns_servers_up)==0)
1682 1685
 		goto end; /* the servers are down, needless to perform the query */
... ...
@@ -2055,7 +2058,7 @@ no_more_rrs:
2055 2058
  * returns a pointer to the internal hostent structure on success or
2056 2059
  *          0 on error
2057 2060
  */
2058
-struct hostent* dns_entry2he(struct dns_hash_entry* e)
2061
+inline static struct hostent* dns_entry2he(struct dns_hash_entry* e)
2059 2062
 {
2060 2063
 	static struct hostent he;
2061 2064
 	static char hostname[256];
... ...
@@ -2074,9 +2077,16 @@ struct hostent* dns_entry2he(struct dns_hash_entry* e)
2074 2077
 			len=4;
2075 2078
 			break;
2076 2079
 		case T_AAAA:
2080
+#ifdef USE_IPV6
2077 2081
 			af=AF_INET6;
2078 2082
 			len=16;
2079 2083
 			break;
2084
+#else /* USE_IPV6 */
2085
+			LOG(L_ERR, "ERROR: dns_entry2he: IPv6 dns cache entry, but "
2086
+						"IPv6 support disabled at compile time"
2087
+						" (recompile with -DUSE_IPV6)\n");
2088
+			return 0;
2089
+#endif /* USE_IPV6 */
2080 2090
 		default:
2081 2091
 			LOG(L_CRIT, "BUG: dns_entry2he: wrong entry type %d for %.*s\n",
2082 2092
 					e->type, e->name_len, e->name);
... ...
@@ -2120,7 +2130,7 @@ struct hostent* dns_entry2he(struct dns_hash_entry* e)
2120 2130
  * to a statical internal hostent structure
2121 2131
  * returns 0 on success, <0 on error (see the error codes)
2122 2132
  */
2123
-struct hostent* dns_a_get_he(str* name)
2133
+inline static struct hostent* dns_a_get_he(str* name)
2124 2134
 {
2125 2135
 	struct dns_hash_entry* e;
2126 2136
 	struct ip_addr* ip;
... ...
@@ -2139,12 +2149,12 @@ struct hostent* dns_a_get_he(str* name)
2139 2149
 }
2140 2150
 
2141 2151
 
2142
-
2152
+#ifdef USE_IPV6
2143 2153
 /* gethostbyname compatibility: performs an aaaa_lookup and returns a pointer
2144 2154
  * to a statical internal hostent structure
2145 2155
  * returns 0 on success, <0 on error (see the error codes)
2146 2156
  */
2147
-struct hostent* dns_aaaa_get_he(str* name)
2157
+inline static struct hostent* dns_aaaa_get_he(str* name)
2148 2158
 {
2149 2159
 	struct dns_hash_entry* e;
2150 2160
 	struct ip_addr* ip;
... ...
@@ -2161,6 +2171,7 @@ struct hostent* dns_aaaa_get_he(str* name)
2161 2171
 	dns_hash_put(e);
2162 2172
 	return he;
2163 2173
 }
2174
+#endif
2164 2175
 
2165 2176
 
2166 2177
 
... ...
@@ -2175,10 +2186,16 @@ inline static int dns_rr2ip(int type, struct dns_rr* rr, struct ip_addr* ip)
2175 2186
 			return 0;
2176 2187
 			break;
2177 2188
 		case T_AAAA:
2189
+#ifdef USE_IPV6
2178 2190
 			ip->af=AF_INET6;
2179 2191
 			ip->len=16;
2180 2192
 			memcpy(ip->u.addr, ((struct aaaa_rdata*)rr->rdata)->ip6, 16);
2181 2193
 			return 0;
2194
+#else /* USE_IPV6 */
2195
+			LOG(L_ERR, "ERROR: dns_rr2ip: IPv6 dns rr, but IPv6 support"
2196
+					   "disabled at compile time (recompile with "
2197
+					   "-DUSE_IPV6)\n" );
2198
+#endif /*USE_IPV6 */
2182 2199
 			break;
2183 2200
 	}
2184 2201
 	return -1;
... ...
@@ -2196,9 +2213,9 @@ inline static int dns_rr2ip(int type, struct dns_rr* rr, struct ip_addr* ip)
2196 2213
  */
2197 2214
 struct hostent* dns_get_he(str* name, int flags)
2198 2215
 {
2216
+#ifdef USE_IPV6
2199 2217
 	struct hostent* he;
2200 2218
 
2201
-
2202 2219
 	if ((flags&(DNS_IPV6_FIRST|DNS_IPV6_ONLY))){
2203 2220
 		he=dns_aaaa_get_he(name);
2204 2221
 		if (he) return he;
... ...
@@ -2212,6 +2229,9 @@ struct hostent* dns_get_he(str* name, int flags)
2212 2229
 		he=dns_aaaa_get_he(name);
2213 2230
 	}
2214 2231
 	return he;
2232
+#else /* USE_IPV6 */
2233
+	return dns_a_get_he(name);
2234
+#endif /* USE_IPV6 */
2215 2235
 }
2216 2236
 
2217 2237
 
... ...
@@ -2589,8 +2609,10 @@ struct hostent* dns_sip_resolvehost(str* name, unsigned short* port,
2589 2609
  *  ...
2590 2610
  *  dns_hash_put(dns_entry); -- finished with the entry
2591 2611
  */
2592
-int dns_a_resolve(struct dns_hash_entry** e, unsigned char* rr_no,
2593
-					str* name, struct ip_addr* ip)
2612
+inline static int dns_a_resolve( struct dns_hash_entry** e,
2613
+								 unsigned char* rr_no,
2614
+								 str* name,
2615
+								 struct ip_addr* ip)
2594 2616
 {
2595 2617
 	struct dns_rr* rr;
2596 2618
 	int ret;
... ...
@@ -2630,14 +2652,16 @@ error:
2630 2652
 }
2631 2653
 
2632 2654
 
2633
-
2655
+#ifdef USE_IPV6
2634 2656
 /* lookup, fills the dns_entry pointer and the ip addr.
2635 2657
  *  (with the first good ip). if *e ==0 does the a lookup, and changes it
2636 2658
  *   to the result, if not it uses the current value and tries to use
2637 2659
  * Same as dns_a_resolve but for aaaa records (see above).
2638 2660
  */
2639
-int dns_aaaa_resolve(struct dns_hash_entry** e, unsigned char* rr_no,
2640
-						str* name, struct ip_addr* ip)
2661
+inline static int dns_aaaa_resolve( struct dns_hash_entry** e,
2662
+									unsigned char* rr_no,
2663
+									str* name,
2664
+									struct ip_addr* ip)
2641 2665
 {
2642 2666
 	struct dns_rr* rr;
2643 2667
 	int ret;
... ...
@@ -2673,6 +2697,7 @@ int dns_aaaa_resolve(struct dns_hash_entry** e, unsigned char* rr_no,
2673 2697
 error:
2674 2698
 	return ret;
2675 2699
 }
2700
+#endif /* USE_IPV6 */
2676 2701
 
2677 2702
 
2678 2703
 
... ...
@@ -2685,13 +2710,17 @@ error:
2685 2710
  *  see dns_a_resolve() for the rest of the params., examples a.s.o
2686 2711
  *  WARNING: don't forget dns_hash_put(*e) when e is not needed anymore
2687 2712
  */
2688
-int dns_ip_resolve(struct dns_hash_entry** e, unsigned char* rr_no,
2689
-					str* name, struct ip_addr* ip, int flags)
2713
+inline static int dns_ip_resolve(	struct dns_hash_entry** e,
2714
+									unsigned char* rr_no,
2715
+									str* name,
2716
+									struct ip_addr* ip,
2717
+									int flags)
2690 2718
 {
2691 2719
 	int ret;
2692 2720
 
2693 2721
 	ret=-E_DNS_NO_IP;
2694 2722
 	if (*e==0){ /* first call */
2723
+#ifdef USE_IPV6
2695 2724
 		if ((flags&(DNS_IPV6_FIRST|DNS_IPV6_ONLY))){
2696 2725
 			ret=dns_aaaa_resolve(e, rr_no, name, ip);
2697 2726
 			if (ret>=0) return ret;
... ...
@@ -2704,9 +2733,13 @@ int dns_ip_resolve(struct dns_hash_entry** e, unsigned char* rr_no,
2704 2733
 		}else if (!(flags&(DNS_IPV6_ONLY|DNS_IPV4_ONLY))){
2705 2734
 			ret=dns_aaaa_resolve(e, rr_no, name, ip);
2706 2735
 		}
2736
+#else /* USE_IPV6 */
2737
+		ret=dns_a_resolve(e, rr_no, name, ip);
2738
+#endif /* USE_IPV6 */
2707 2739
 	}else if ((*e)->type==T_A){
2708 2740
 		/* continue A resolving */
2709 2741
 		ret=dns_a_resolve(e, rr_no, name, ip);
2742
+#ifdef USE_IPV6
2710 2743
 		if (ret>=0) return ret;
2711 2744
 		if (!(flags&(DNS_IPV6_ONLY|DNS_IPV6_FIRST|DNS_IPV4_ONLY))){
2712 2745
 			/* not found, try with AAAA */
... ...
@@ -2715,7 +2748,9 @@ int dns_ip_resolve(struct dns_hash_entry** e, unsigned char* rr_no,
2715 2748
 			*rr_no=0;
2716 2749
 			ret=dns_aaaa_resolve(e, rr_no, name, ip);
2717 2750
 		}
2751
+#endif /* USE_IPV6 */
2718 2752
 	}else if ((*e)->type==T_AAAA){
2753
+#ifdef USE_IPV6
2719 2754
 		/* continue AAAA resolving */
2720 2755
 		ret=dns_aaaa_resolve(e, rr_no, name, ip);
2721 2756
 		if (ret>=0) return ret;
... ...
@@ -2726,6 +2761,10 @@ int dns_ip_resolve(struct dns_hash_entry** e, unsigned char* rr_no,
2726 2761
 			*rr_no=0;
2727 2762
 			ret=dns_a_resolve(e, rr_no, name, ip);
2728 2763
 		}
2764
+#else /* USE_IPV6 */
2765
+		/* ipv6 disabled, try with A */
2766
+		ret=dns_a_resolve(e, rr_no, name, ip);
2767
+#endif /* USE_IPV6 */
2729 2768
 	}else{
2730 2769
 		LOG(L_CRIT, "BUG: dns_ip_resolve: invalid record type %d\n",
2731 2770
 					(*e)->type);
... ...
@@ -2747,7 +2786,7 @@ int dns_ip_resolve(struct dns_hash_entry** e, unsigned char* rr_no,
2747 2786
  *    record in the priority order and for records with the same priority
2748 2787
  *     the record with the higher weight (from the remaining ones)
2749 2788
  */
2750
-int dns_srv_resolve_nxt(struct dns_hash_entry** e,
2789
+inline static int dns_srv_resolve_nxt(struct dns_hash_entry** e,
2751 2790
 #ifdef DNS_SRV_LB
2752 2791
 						srv_flags_t* tried,
2753 2792
 #endif
... ...
@@ -2803,7 +2842,7 @@ error:
2803 2842
  *  WARNING: don't forget to init h prior to calling this function the first
2804 2843
  *   time and dns_srv_handle_put(h), even if error is returned
2805 2844
  */
2806
-int dns_srv_resolve_ip(struct dns_srv_handle* h,
2845
+inline static int dns_srv_resolve_ip(struct dns_srv_handle* h,
2807 2846
 					str* name, struct ip_addr* ip, unsigned short* port,
2808 2847
 					int flags)
2809 2848
 {
... ...
@@ -2860,7 +2899,7 @@ error:
2860 2899
  *            0 on success and it fills *ip, *port, dns_sip_resolve_h
2861 2900
  * WARNING: when finished, dns_sip_resolve_put(h) must be called!
2862 2901
  */
2863
-int dns_srv_sip_resolve(struct dns_srv_handle* h,  str* name,
2902
+inline static int dns_srv_sip_resolve(struct dns_srv_handle* h,  str* name,
2864 2903
 						struct ip_addr* ip, unsigned short* port, char* proto,
2865 2904
 						int flags)
2866 2905
 {
... ...
@@ -3014,7 +3053,7 @@ int dns_srv_sip_resolve(struct dns_srv_handle* h,  str* name,
3014 3053
  *            0 on success and it fills *ip, *port, dns_sip_resolve_h
3015 3054
  * WARNING: when finished, dns_sip_resolve_put(h) must be called!
3016 3055
  */
3017
-int dns_naptr_sip_resolve(struct dns_srv_handle* h,  str* name,
3056
+inline static int dns_naptr_sip_resolve(struct dns_srv_handle* h,  str* name,
3018 3057
 						struct ip_addr* ip, unsigned short* port, char* proto,
3019 3058
 						int flags)
3020 3059
 {
... ...
@@ -3119,7 +3158,7 @@ int dns_sip_resolve(struct dns_srv_handle* h,  str* name,
3119 3158
 /* performs an a lookup and fills ip with the first good ip address
3120 3159
  * returns 0 on success, <0 on error (see the error codes)
3121 3160
  */
3122
-int dns_a_get_ip(str* name, struct ip_addr* ip)
3161
+inline static int dns_a_get_ip(str* name, struct ip_addr* ip)
3123 3162
 {
3124 3163
 	struct dns_hash_entry* e;
3125 3164
 	int ret;
... ...
@@ -3133,8 +3172,8 @@ int dns_a_get_ip(str* name, struct ip_addr* ip)
3133 3172
 }
3134 3173
 
3135 3174
 
3136
-
3137
-int dns_aaaa_get_ip(str* name, struct ip_addr* ip)
3175
+#ifdef USE_IPV6
3176
+inline static int dns_aaaa_get_ip(str* name, struct ip_addr* ip)
3138 3177
 {
3139 3178
 	struct dns_hash_entry* e;
3140 3179
 	int ret;
... ...
@@ -3146,6 +3185,7 @@ int dns_aaaa_get_ip(str* name, struct ip_addr* ip)
3146 3185
 	if (e) dns_hash_put(e);
3147 3186
 	return ret;
3148 3187
 }
3188
+#endif /* USE_IPV6 */
3149 3189
 
3150 3190
 
3151 3191
 
... ...
@@ -3707,12 +3747,17 @@ static void dns_cache_add_record(rpc_t* rpc, void* ctx, unsigned short type)
3707 3747
 			}
3708 3748
 			break;
3709 3749
 		case T_AAAA:
3750
+#ifdef USE_IPV6
3710 3751
 			ip_addr = str2ip6(&ip);
3711 3752
 			if (!ip_addr) {
3712 3753
 				rpc->fault(ctx, 400, "Malformed ip address");
3713 3754
 				goto error;
3714 3755
 			}
3715 3756
 			break;
3757
+#else /* USE_IPV6 */
3758
+			rpc->fault(ctx, 400, "IPv6 support disabled ");
3759
+			return;
3760
+#endif /* USE_IPV6 */
3716 3761
 		/* case T_SRV: nothing to do */
3717 3762
 		}
3718 3763
 	}