Browse code

- 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 authored on 30/04/2008 19:50:04
Showing 5 changed files
... ...
@@ -1215,10 +1215,10 @@ ipv6addr:
1215 1215
 		if ($$==0) {
1216 1216
 			LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
1217 1217
 		} else {
1218
+		#ifdef USE_IPV6
1218 1219
 			memset($$, 0, sizeof(struct ip_addr));
1219 1220
 			$$->af=AF_INET6;
1220 1221
 			$$->len=16;
1221
-		#ifdef USE_IPV6
1222 1222
 			if (inet_pton(AF_INET6, $1, $$->u.addr)<=0) {
1223 1223
 				yyerror("bad ipv6 address");
1224 1224
 			}
... ...
@@ -1481,8 +1481,10 @@ exp_elem:
1481 1481
 		s_tmp.s=$3;
1482 1482
 		s_tmp.len=strlen($3);
1483 1483
 		ip_tmp=str2ip(&s_tmp);
1484
+	#ifdef USE_IPV6
1484 1485
 		if (ip_tmp==0)
1485 1486
 			ip_tmp=str2ip6(&s_tmp);
1487
+	#endif
1486 1488
 		if (ip_tmp) {
1487 1489
 			$$=mk_elem($2, SRCIP_O, 0, NET_ST, mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
1488 1490
 		} else {
... ...
@@ -1499,8 +1501,10 @@ exp_elem:
1499 1499
 		s_tmp.s=$3;
1500 1500
 		s_tmp.len=strlen($3);
1501 1501
 		ip_tmp=str2ip(&s_tmp);
1502
+	#ifdef USE_IPV6
1502 1503
 		if (ip_tmp==0)
1503 1504
 			ip_tmp=str2ip6(&s_tmp);
1505
+	#endif /* USE_IPV6 */
1504 1506
 		if (ip_tmp) {
1505 1507
 			$$=mk_elem($2, DSTIP_O, 0, NET_ST, mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
1506 1508
 		} else {
... ...
@@ -1520,8 +1524,10 @@ exp_elem:
1520 1520
 		s_tmp.s=$3;
1521 1521
 		s_tmp.len=strlen($3);
1522 1522
 		ip_tmp=str2ip(&s_tmp);
1523
+	#ifdef USE_IPV6
1523 1524
 		if (ip_tmp==0)
1524 1525
 			ip_tmp=str2ip6(&s_tmp);
1526
+	#endif /* USE_IPV6 */
1525 1527
 		if (ip_tmp) {
1526 1528
 			$$=mk_elem($2, SNDIP_O, 0, NET_ST, mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
1527 1529
 		} else {
... ...
@@ -1551,8 +1557,10 @@ exp_elem:
1551 1551
 		s_tmp.s=$3;
1552 1552
 		s_tmp.len=strlen($3);
1553 1553
 		ip_tmp=str2ip(&s_tmp);
1554
+	#ifdef USE_IPV6
1554 1555
 		if (ip_tmp==0)
1555 1556
 			ip_tmp=str2ip6(&s_tmp);
1557
+	#endif /* USE_IPV6 */
1556 1558
 		if (ip_tmp) {
1557 1559
 			$$=mk_elem($2, TOIP_O, 0, NET_ST, mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
1558 1560
 		} else {
... ...
@@ -307,10 +307,13 @@ static ticks_t blst_timer(ticks_t ticks, struct timer_ln* tl, void* data);
307 307
 inline static void dst_blst_entry2ip(struct ip_addr* ip,
308 308
 										struct dst_blst_entry* e)
309 309
 {
310
+#ifdef USE_IPV6
310 311
 	if (e->flags & BLST_IS_IPV6){
311 312
 		ip->af=AF_INET6;
312 313
 		ip->len=16;
313
-	}else{
314
+	}else
315
+#endif /* USE_IPV6 */
316
+	{
314 317
 		ip->af=AF_INET;
315 318
 		ip->len=4;
316 319
 	}
... ...
@@ -528,7 +531,12 @@ inline static struct dst_blst_entry* _dst_blacklist_lst_find(
528 528
 	unsigned char type;
529 529
 
530 530
 	head=&dst_blst_hash[hash].first;
531
+#ifdef USE_IPV6
531 532
 	type=(ip->af==AF_INET6)*BLST_IS_IPV6;
533
+#else  /* USE_IPV6 */
534
+	if (unlikely(ip->af!=AF_INET)) return 0;
535
+	type=0;
536
+#endif /* USE_IPV6 */
532 537
 	for (crt=head, tmp=&(*head)->next; *crt; crt=tmp, tmp=&(*crt)->next){
533 538
 		e=*crt;
534 539
 		prefetch_loc_r((*crt)->next, 1);
... ...
@@ -569,7 +577,12 @@ inline static int _dst_blacklist_del(
569 569
 	unsigned char type;
570 570
 	
571 571
 	head=&dst_blst_hash[hash].first;
572
+#ifdef USE_IPV6
572 573
 	type=(ip->af==AF_INET6)*BLST_IS_IPV6;
574
+#else  /* USE_IPV6 */
575
+	if (unlikely(ip->af!=AF_INET)) return 0;
576
+	type=0;
577
+#endif /* USE_IPV6 */
573 578
 	for (crt=head, tmp=&(*head)->next; *crt; crt=tmp, tmp=&(*crt)->next){
574 579
 		e=*crt;
575 580
 		prefetch_loc_r((*crt)->next, 1);
... ...
@@ -1093,14 +1106,24 @@ void dst_blst_add(rpc_t* rpc, void* ctx)
1093 1093
 	}
1094 1094
 
1095 1095
 	if (err_flags & BLST_IS_IPV6) {
1096
+#ifdef USE_IPV6
1096 1097
 		/* IPv6 address is specified */
1097 1098
 		ip_addr = str2ip6(&ip);
1099
+#else  /* USE_IPV6 */
1100
+		rpc->fault(ctx, 400, "IPv6 support disabled");
1101
+		return;
1102
+#endif /* USE_IPV6 */
1098 1103
 	} else {
1099 1104
 		/* try IPv4 first, than IPv6 */
1100 1105
 		ip_addr = str2ip(&ip);
1101 1106
 		if (!ip_addr) {
1107
+#ifdef USE_IPV6
1102 1108
 			ip_addr = str2ip6(&ip);
1103 1109
 			err_flags |= BLST_IS_IPV6;
1110
+#else  /* USE_IPV6 */
1111
+			rpc->fault(ctx, 400, "Malformed or IPv6 ip address");
1112
+			return;
1113
+#endif /* USE_IPV6 */
1104 1114
 		}
1105 1115
 	}
1106 1116
 	if (!ip_addr) {
... ...
@@ -115,6 +115,7 @@ void print_ip(char* p, struct ip_addr* ip, char *s)
115 115
 								(s)?s:""
116 116
 								);
117 117
 			break;
118
+#ifdef USE_IPV6
118 119
 		case AF_INET6:
119 120
 			DBG("%s%x:%x:%x:%x:%x:%x:%x:%x%s", (p)?p:"",
120 121
 											htons(ip->u.addr16[0]),
... ...
@@ -128,6 +129,7 @@ void print_ip(char* p, struct ip_addr* ip, char *s)
128 128
 											(s)?s:""
129 129
 				);
130 130
 			break;
131
+#endif /* USE_IPV6 */
131 132
 		default:
132 133
 			DBG("print_ip: warning unknown address family %d\n", ip->af);
133 134
 	}
... ...
@@ -144,6 +146,7 @@ void stdout_print_ip(struct ip_addr* ip)
144 144
 								ip->u.addr[2],
145 145
 								ip->u.addr[3]);
146 146
 			break;
147
+#ifdef USE_IPV6
147 148
 		case AF_INET6:
148 149
 			printf("%x:%x:%x:%x:%x:%x:%x:%x",	htons(ip->u.addr16[0]),
149 150
 											htons(ip->u.addr16[1]),
... ...
@@ -155,6 +158,7 @@ void stdout_print_ip(struct ip_addr* ip)
155 155
 											htons(ip->u.addr16[7])
156 156
 				);
157 157
 			break;
158
+#endif /* USE_IPV6 */
158 159
 		default:
159 160
 			DBG("print_ip: warning unknown address family %d\n", ip->af);
160 161
 	}
... ...
@@ -220,7 +220,7 @@ error_dots:
220 220
 }
221 221
 
222 222
 
223
-
223
+#ifdef USE_IPV6
224 224
 /* returns an ip_addr struct.; on error returns 0
225 225
  * the ip_addr struct is static, so subsequent calls will destroy its content*/
226 226
 static inline struct ip_addr* str2ip6(str* st)
... ...
@@ -323,6 +323,7 @@ error_char:
323 323
 			st->s);*/
324 324
 	return 0;
325 325
 }
326
+#endif /* USE_IPV6 */
326 327
 
327 328
 
328 329
 
... ...
@@ -494,8 +494,12 @@ int add_interfaces(char* if_name, int family, unsigned short port,
494 494
 				#else
495 495
 					( (ifr.ifr_addr.sa_family==AF_INET)?
496 496
 						sizeof(struct sockaddr_in):
497
+					#ifdef USE_IPV6
497 498
 						((ifr.ifr_addr.sa_family==AF_INET6)?
498 499
 						sizeof(struct sockaddr_in6):sizeof(struct sockaddr)) )
500
+					#else /* USE_IPV6 */
501
+						sizeof(struct sockaddr) )
502
+					#endif /* USE_IPV6 */
499 503
 				#endif
500 504
 				)
501 505
 			#endif