Browse code

- checkself ipv6 and case insensitiveness fixes

Andrei Pelinescu-Onciul authored on 21/08/2003 15:34:27
Showing 4 changed files
... ...
@@ -40,7 +40,7 @@ export makefile_defs
40 40
 VERSION = 0
41 41
 PATCHLEVEL = 8
42 42
 SUBLEVEL =   12
43
-EXTRAVERSION = dev-t13
43
+EXTRAVERSION = dev-t14
44 44
 
45 45
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
46 46
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
... ...
@@ -18,6 +18,7 @@ release:
18 18
 - backport: acc mem. leak fixes
19 19
 - backport: dns mem. leak fixes (resolve.[ch])
20 20
 - backport: id_builder receive_msg mem. leak (receive.c)
21
+- backport: check_self ipv6/case fixes (forward.c)
21 22
 - change tcp timeouts to 2 or 3 min?
22 23
 x check via ipv6 fixes and backport to stable
23 24
 x fix kill(0, SIGTERM) on startup error (will kill also the launching shell
... ...
@@ -41,6 +41,7 @@
41 41
  *               local replies  & "normal" replies (andrei)
42 42
  *  2003-04-12  update_sock_struct_form via uses also FL_FORCE_RPORT for
43 43
  *               local replies (andrei)
44
+ *  2003-08-21  check_self properly handles ipv6 addresses & refs   (andrei)
44 45
  */
45 46
 
46 47
 
... ...
@@ -220,21 +221,38 @@ struct socket_info* get_send_socket(union sockaddr_union* to, int proto)
220 220
 /* checks if the host:port is one of the address we listen on;
221 221
  * if port==0, the  port number is ignored
222 222
  * returns 1 if true, 0 if false, -1 on error
223
-*/
223
+ * WARNING: uses str2ip6 so it will overwrite any previous
224
+ *  unsaved result of this function (static buffer)
225
+ */
224 226
 int check_self(str* host, unsigned short port)
225 227
 {
226 228
 	int r;
229
+	char* hname;
230
+	int h_len;
231
+#ifdef USE_IPV6
232
+	struct ip_addr* ip6;
233
+#endif
227 234
 	
235
+	h_len=host->len;
236
+	hname=host->s;
237
+#ifdef USE_IPV6
238
+	if ((h_len>2)&&((*hname)=='[')&&(hname[h_len-1]==']')){
239
+		/* ipv6 reference, skip [] */
240
+		hname++;
241
+		h_len-=2;
242
+	}
243
+#endif
228 244
 	for (r=0; r<sock_no; r++){
229 245
 		DBG("check_self - checking if host==us: %d==%d && "
230 246
 				" [%.*s] == [%.*s]\n", 
231
-					host->len,
247
+					h_len,
232 248
 					sock_info[r].name.len,
233
-					host->len, host->s,
249
+					h_len, hname,
234 250
 					sock_info[r].name.len, sock_info[r].name.s
235 251
 			);
236 252
 		if (port) {
237
-			DBG("check_self - checking if port %d matches port %d\n", sock_info[r].port_no, port);
253
+			DBG("check_self - checking if port %d matches port %d\n", 
254
+					sock_info[r].port_no, port);
238 255
 #ifdef USE_TLS
239 256
 			if  ((sock_info[r].port_no!=port) && (tls_info[r].port_no!=port)) {
240 257
 #else
... ...
@@ -243,32 +261,31 @@ int check_self(str* host, unsigned short port)
243 243
 				continue;
244 244
 			}
245 245
 		}
246
-		if ( (host->len==sock_info[r].name.len) && 
247
-#ifdef USE_IPV6
248
-			(strncasecmp(host->s, sock_info[r].name.s,
249
-				     sock_info[r].name.len)==0) /*slower*/
250
-#else
251
-			(memcmp(host->s, sock_info[r].name.s, 
252
-				sock_info[r].name.len)==0)
253
-#endif
254
-			)
246
+		if ( (h_len==sock_info[r].name.len) && 
247
+			(strncasecmp(hname, sock_info[r].name.s,
248
+				     sock_info[r].name.len)==0) /*slower*/)
249
+			/* comp. must be case insensitive, host names
250
+			 * can be written in mixed case, it will also match
251
+			 * ipv6 addresses */
255 252
 			break;
256 253
 	/* check if host == ip address */
257
-		if ( 	(!sock_info[r].is_ip) &&
258
-				(host->len==sock_info[r].address_str.len) && 
259 254
 #ifdef USE_IPV6
260
-			(strncasecmp(host->s, sock_info[r].address_str.s,
261
-								 sock_info[r].address_str.len)==0) /*slower*/
262
-#else
263
-			(memcmp(host->s, sock_info[r].address_str.s, 
264
-								sock_info[r].address_str.len)==0)
255
+		/* ipv6 case is uglier, host can be [3ffe::1] */
256
+		ip6=str2ip6(host);
257
+		if ((ip6) && ip_addr_cmp(ip6, &sock_info[r].address))
258
+			break; /* match */
265 259
 #endif
260
+		/* ipv4 */
261
+		if ( 	(!sock_info[r].is_ip) &&
262
+				(h_len==sock_info[r].address_str.len) && 
263
+			(memcmp(hname, sock_info[r].address_str.s, 
264
+								sock_info[r].address_str.len)==0)
266 265
 			)
267 266
 			break;
268 267
 	}
269 268
 	if (r==sock_no){
270 269
 		/* try to look into the aliases*/
271
-		if (grep_aliases(host->s, host->len, port)==0){
270
+		if (grep_aliases(hname, h_len, port)==0){
272 271
 			DBG("check_self: host != me\n");
273 272
 			return 0;
274 273
 		}
... ...
@@ -57,7 +57,8 @@ static inline int grep_aliases(char* name, int len, unsigned short port)
57 57
 	
58 58
 	for(a=aliases;a;a=a->next)
59 59
 #ifdef USE_TLS
60
-		if ((a->alias.len==len) && ((a->port==0) || (port==0) || (port==tls_port_no) ||
60
+		if ((a->alias.len==len) && ((a->port==0) || (port==0) || 
61
+					(port==tls_port_no) ||
61 62
 #else
62 63
 		if ((a->alias.len==len) && ((a->port==0) || (port==0) || 
63 64
 #endif