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 1501
 		s_tmp.s=$3;
1500 1502
 		s_tmp.len=strlen($3);
1501 1503
 		ip_tmp=str2ip(&s_tmp);
1504
+	#ifdef USE_IPV6
1502 1505
 		if (ip_tmp==0)
1503 1506
 			ip_tmp=str2ip6(&s_tmp);
1507
+	#endif /* USE_IPV6 */
1504 1508
 		if (ip_tmp) {
1505 1509
 			$$=mk_elem($2, DSTIP_O, 0, NET_ST, mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
1506 1510
 		} else {
... ...
@@ -1520,8 +1524,10 @@ exp_elem:
1520 1524
 		s_tmp.s=$3;
1521 1525
 		s_tmp.len=strlen($3);
1522 1526
 		ip_tmp=str2ip(&s_tmp);
1527
+	#ifdef USE_IPV6
1523 1528
 		if (ip_tmp==0)
1524 1529
 			ip_tmp=str2ip6(&s_tmp);
1530
+	#endif /* USE_IPV6 */
1525 1531
 		if (ip_tmp) {
1526 1532
 			$$=mk_elem($2, SNDIP_O, 0, NET_ST, mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
1527 1533
 		} else {
... ...
@@ -1551,8 +1557,10 @@ exp_elem:
1551 1557
 		s_tmp.s=$3;
1552 1558
 		s_tmp.len=strlen($3);
1553 1559
 		ip_tmp=str2ip(&s_tmp);
1560
+	#ifdef USE_IPV6
1554 1561
 		if (ip_tmp==0)
1555 1562
 			ip_tmp=str2ip6(&s_tmp);
1563
+	#endif /* USE_IPV6 */
1556 1564
 		if (ip_tmp) {
1557 1565
 			$$=mk_elem($2, TOIP_O, 0, NET_ST, mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
1558 1566
 		} 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 531
 	unsigned char type;
529 532
 
530 533
 	head=&dst_blst_hash[hash].first;
534
+#ifdef USE_IPV6
531 535
 	type=(ip->af==AF_INET6)*BLST_IS_IPV6;
536
+#else  /* USE_IPV6 */
537
+	if (unlikely(ip->af!=AF_INET)) return 0;
538
+	type=0;
539
+#endif /* USE_IPV6 */
532 540
 	for (crt=head, tmp=&(*head)->next; *crt; crt=tmp, tmp=&(*crt)->next){
533 541
 		e=*crt;
534 542
 		prefetch_loc_r((*crt)->next, 1);
... ...
@@ -569,7 +577,12 @@ inline static int _dst_blacklist_del(
569 577
 	unsigned char type;
570 578
 	
571 579
 	head=&dst_blst_hash[hash].first;
580
+#ifdef USE_IPV6
572 581
 	type=(ip->af==AF_INET6)*BLST_IS_IPV6;
582
+#else  /* USE_IPV6 */
583
+	if (unlikely(ip->af!=AF_INET)) return 0;
584
+	type=0;
585
+#endif /* USE_IPV6 */
573 586
 	for (crt=head, tmp=&(*head)->next; *crt; crt=tmp, tmp=&(*crt)->next){
574 587
 		e=*crt;
575 588
 		prefetch_loc_r((*crt)->next, 1);
... ...
@@ -1093,14 +1106,24 @@ void dst_blst_add(rpc_t* rpc, void* ctx)
1093 1106
 	}
1094 1107
 
1095 1108
 	if (err_flags & BLST_IS_IPV6) {
1109
+#ifdef USE_IPV6
1096 1110
 		/* IPv6 address is specified */
1097 1111
 		ip_addr = str2ip6(&ip);
1112
+#else  /* USE_IPV6 */
1113
+		rpc->fault(ctx, 400, "IPv6 support disabled");
1114
+		return;
1115
+#endif /* USE_IPV6 */
1098 1116
 	} else {
1099 1117
 		/* try IPv4 first, than IPv6 */
1100 1118
 		ip_addr = str2ip(&ip);
1101 1119
 		if (!ip_addr) {
1120
+#ifdef USE_IPV6
1102 1121
 			ip_addr = str2ip6(&ip);
1103 1122
 			err_flags |= BLST_IS_IPV6;
1123
+#else  /* USE_IPV6 */
1124
+			rpc->fault(ctx, 400, "Malformed or IPv6 ip address");
1125
+			return;
1126
+#endif /* USE_IPV6 */
1104 1127
 		}
1105 1128
 	}
1106 1129
 	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 129
 											(s)?s:""
129 130
 				);
130 131
 			break;
132
+#endif /* USE_IPV6 */
131 133
 		default:
132 134
 			DBG("print_ip: warning unknown address family %d\n", ip->af);
133 135
 	}
... ...
@@ -144,6 +146,7 @@ void stdout_print_ip(struct ip_addr* ip)
144 146
 								ip->u.addr[2],
145 147
 								ip->u.addr[3]);
146 148
 			break;
149
+#ifdef USE_IPV6
147 150
 		case AF_INET6:
148 151
 			printf("%x:%x:%x:%x:%x:%x:%x:%x",	htons(ip->u.addr16[0]),
149 152
 											htons(ip->u.addr16[1]),
... ...
@@ -155,6 +158,7 @@ void stdout_print_ip(struct ip_addr* ip)
155 158
 											htons(ip->u.addr16[7])
156 159
 				);
157 160
 			break;
161
+#endif /* USE_IPV6 */
158 162
 		default:
159 163
 			DBG("print_ip: warning unknown address family %d\n", ip->af);
160 164
 	}
... ...
@@ -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