浏览代码

- if ipv6 support is disabled (-DUSE_IPV6 not defined), don't even try to use
AF_INET6 (might not be defined if the underlying OS doesn't support ipv6), or
str2ip6

Andrei Pelinescu-Onciul 17 年之前
父节点
当前提交
145d6ad0f9
共有 5 个文件被更改,包括 43 次插入3 次删除
  1. 9 1
      cfg.y
  2. 24 1
      dst_blacklist.c
  3. 4 0
      ip_addr.c
  4. 2 1
      resolve.h
  5. 4 0
      socket_info.c

+ 9 - 1
cfg.y

@@ -1215,10 +1215,10 @@ ipv6addr:
 		if ($$==0) {
 			LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
 		} else {
+		#ifdef USE_IPV6
 			memset($$, 0, sizeof(struct ip_addr));
 			$$->af=AF_INET6;
 			$$->len=16;
-		#ifdef USE_IPV6
 			if (inet_pton(AF_INET6, $1, $$->u.addr)<=0) {
 				yyerror("bad ipv6 address");
 			}
@@ -1481,8 +1481,10 @@ exp_elem:
 		s_tmp.s=$3;
 		s_tmp.len=strlen($3);
 		ip_tmp=str2ip(&s_tmp);
+	#ifdef USE_IPV6
 		if (ip_tmp==0)
 			ip_tmp=str2ip6(&s_tmp);
+	#endif
 		if (ip_tmp) {
 			$$=mk_elem($2, SRCIP_O, 0, NET_ST, mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
 		} else {
@@ -1499,8 +1501,10 @@ exp_elem:
 		s_tmp.s=$3;
 		s_tmp.len=strlen($3);
 		ip_tmp=str2ip(&s_tmp);
+	#ifdef USE_IPV6
 		if (ip_tmp==0)
 			ip_tmp=str2ip6(&s_tmp);
+	#endif /* USE_IPV6 */
 		if (ip_tmp) {
 			$$=mk_elem($2, DSTIP_O, 0, NET_ST, mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
 		} else {
@@ -1520,8 +1524,10 @@ exp_elem:
 		s_tmp.s=$3;
 		s_tmp.len=strlen($3);
 		ip_tmp=str2ip(&s_tmp);
+	#ifdef USE_IPV6
 		if (ip_tmp==0)
 			ip_tmp=str2ip6(&s_tmp);
+	#endif /* USE_IPV6 */
 		if (ip_tmp) {
 			$$=mk_elem($2, SNDIP_O, 0, NET_ST, mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
 		} else {
@@ -1551,8 +1557,10 @@ exp_elem:
 		s_tmp.s=$3;
 		s_tmp.len=strlen($3);
 		ip_tmp=str2ip(&s_tmp);
+	#ifdef USE_IPV6
 		if (ip_tmp==0)
 			ip_tmp=str2ip6(&s_tmp);
+	#endif /* USE_IPV6 */
 		if (ip_tmp) {
 			$$=mk_elem($2, TOIP_O, 0, NET_ST, mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
 		} else {

+ 24 - 1
dst_blacklist.c

@@ -307,10 +307,13 @@ static ticks_t blst_timer(ticks_t ticks, struct timer_ln* tl, void* data);
 inline static void dst_blst_entry2ip(struct ip_addr* ip,
 										struct dst_blst_entry* e)
 {
+#ifdef USE_IPV6
 	if (e->flags & BLST_IS_IPV6){
 		ip->af=AF_INET6;
 		ip->len=16;
-	}else{
+	}else
+#endif /* USE_IPV6 */
+	{
 		ip->af=AF_INET;
 		ip->len=4;
 	}
@@ -528,7 +531,12 @@ inline static struct dst_blst_entry* _dst_blacklist_lst_find(
 	unsigned char type;
 
 	head=&dst_blst_hash[hash].first;
+#ifdef USE_IPV6
 	type=(ip->af==AF_INET6)*BLST_IS_IPV6;
+#else  /* USE_IPV6 */
+	if (unlikely(ip->af!=AF_INET)) return 0;
+	type=0;
+#endif /* USE_IPV6 */
 	for (crt=head, tmp=&(*head)->next; *crt; crt=tmp, tmp=&(*crt)->next){
 		e=*crt;
 		prefetch_loc_r((*crt)->next, 1);
@@ -569,7 +577,12 @@ inline static int _dst_blacklist_del(
 	unsigned char type;
 	
 	head=&dst_blst_hash[hash].first;
+#ifdef USE_IPV6
 	type=(ip->af==AF_INET6)*BLST_IS_IPV6;
+#else  /* USE_IPV6 */
+	if (unlikely(ip->af!=AF_INET)) return 0;
+	type=0;
+#endif /* USE_IPV6 */
 	for (crt=head, tmp=&(*head)->next; *crt; crt=tmp, tmp=&(*crt)->next){
 		e=*crt;
 		prefetch_loc_r((*crt)->next, 1);
@@ -1093,14 +1106,24 @@ void dst_blst_add(rpc_t* rpc, void* ctx)
 	}
 
 	if (err_flags & BLST_IS_IPV6) {
+#ifdef USE_IPV6
 		/* IPv6 address is specified */
 		ip_addr = str2ip6(&ip);
+#else  /* USE_IPV6 */
+		rpc->fault(ctx, 400, "IPv6 support disabled");
+		return;
+#endif /* USE_IPV6 */
 	} else {
 		/* try IPv4 first, than IPv6 */
 		ip_addr = str2ip(&ip);
 		if (!ip_addr) {
+#ifdef USE_IPV6
 			ip_addr = str2ip6(&ip);
 			err_flags |= BLST_IS_IPV6;
+#else  /* USE_IPV6 */
+			rpc->fault(ctx, 400, "Malformed or IPv6 ip address");
+			return;
+#endif /* USE_IPV6 */
 		}
 	}
 	if (!ip_addr) {

+ 4 - 0
ip_addr.c

@@ -115,6 +115,7 @@ void print_ip(char* p, struct ip_addr* ip, char *s)
 								(s)?s:""
 								);
 			break;
+#ifdef USE_IPV6
 		case AF_INET6:
 			DBG("%s%x:%x:%x:%x:%x:%x:%x:%x%s", (p)?p:"",
 											htons(ip->u.addr16[0]),
@@ -128,6 +129,7 @@ void print_ip(char* p, struct ip_addr* ip, char *s)
 											(s)?s:""
 				);
 			break;
+#endif /* USE_IPV6 */
 		default:
 			DBG("print_ip: warning unknown address family %d\n", ip->af);
 	}
@@ -144,6 +146,7 @@ void stdout_print_ip(struct ip_addr* ip)
 								ip->u.addr[2],
 								ip->u.addr[3]);
 			break;
+#ifdef USE_IPV6
 		case AF_INET6:
 			printf("%x:%x:%x:%x:%x:%x:%x:%x",	htons(ip->u.addr16[0]),
 											htons(ip->u.addr16[1]),
@@ -155,6 +158,7 @@ void stdout_print_ip(struct ip_addr* ip)
 											htons(ip->u.addr16[7])
 				);
 			break;
+#endif /* USE_IPV6 */
 		default:
 			DBG("print_ip: warning unknown address family %d\n", ip->af);
 	}

+ 2 - 1
resolve.h

@@ -220,7 +220,7 @@ error_dots:
 }
 
 
-
+#ifdef USE_IPV6
 /* returns an ip_addr struct.; on error returns 0
  * the ip_addr struct is static, so subsequent calls will destroy its content*/
 static inline struct ip_addr* str2ip6(str* st)
@@ -323,6 +323,7 @@ error_char:
 			st->s);*/
 	return 0;
 }
+#endif /* USE_IPV6 */
 
 
 

+ 4 - 0
socket_info.c

@@ -494,8 +494,12 @@ int add_interfaces(char* if_name, int family, unsigned short port,
 				#else
 					( (ifr.ifr_addr.sa_family==AF_INET)?
 						sizeof(struct sockaddr_in):
+					#ifdef USE_IPV6
 						((ifr.ifr_addr.sa_family==AF_INET6)?
 						sizeof(struct sockaddr_in6):sizeof(struct sockaddr)) )
+					#else /* USE_IPV6 */
+						sizeof(struct sockaddr) )
+					#endif /* USE_IPV6 */
 				#endif
 				)
 			#endif