浏览代码

- checkself ipv6 and case insensitiveness fixes

Andrei Pelinescu-Onciul 22 年之前
父节点
当前提交
1f5206fd4c
共有 4 个文件被更改,包括 42 次插入23 次删除
  1. 1 1
      Makefile.defs
  2. 1 0
      TODO
  3. 38 21
      forward.c
  4. 2 1
      name_alias.h

+ 1 - 1
Makefile.defs

@@ -40,7 +40,7 @@ export makefile_defs
 VERSION = 0
 PATCHLEVEL = 8
 SUBLEVEL =   12
-EXTRAVERSION = dev-t13
+EXTRAVERSION = dev-t14
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")

+ 1 - 0
TODO

@@ -18,6 +18,7 @@ release:
 - backport: acc mem. leak fixes
 - backport: dns mem. leak fixes (resolve.[ch])
 - backport: id_builder receive_msg mem. leak (receive.c)
+- backport: check_self ipv6/case fixes (forward.c)
 - change tcp timeouts to 2 or 3 min?
 x check via ipv6 fixes and backport to stable
 x fix kill(0, SIGTERM) on startup error (will kill also the launching shell

+ 38 - 21
forward.c

@@ -41,6 +41,7 @@
  *               local replies  & "normal" replies (andrei)
  *  2003-04-12  update_sock_struct_form via uses also FL_FORCE_RPORT for
  *               local replies (andrei)
+ *  2003-08-21  check_self properly handles ipv6 addresses & refs   (andrei)
  */
 
 
@@ -220,21 +221,38 @@ struct socket_info* get_send_socket(union sockaddr_union* to, int proto)
 /* checks if the host:port is one of the address we listen on;
  * if port==0, the  port number is ignored
  * returns 1 if true, 0 if false, -1 on error
-*/
+ * WARNING: uses str2ip6 so it will overwrite any previous
+ *  unsaved result of this function (static buffer)
+ */
 int check_self(str* host, unsigned short port)
 {
 	int r;
+	char* hname;
+	int h_len;
+#ifdef USE_IPV6
+	struct ip_addr* ip6;
+#endif
 	
+	h_len=host->len;
+	hname=host->s;
+#ifdef USE_IPV6
+	if ((h_len>2)&&((*hname)=='[')&&(hname[h_len-1]==']')){
+		/* ipv6 reference, skip [] */
+		hname++;
+		h_len-=2;
+	}
+#endif
 	for (r=0; r<sock_no; r++){
 		DBG("check_self - checking if host==us: %d==%d && "
 				" [%.*s] == [%.*s]\n", 
-					host->len,
+					h_len,
 					sock_info[r].name.len,
-					host->len, host->s,
+					h_len, hname,
 					sock_info[r].name.len, sock_info[r].name.s
 			);
 		if (port) {
-			DBG("check_self - checking if port %d matches port %d\n", sock_info[r].port_no, port);
+			DBG("check_self - checking if port %d matches port %d\n", 
+					sock_info[r].port_no, port);
 #ifdef USE_TLS
 			if  ((sock_info[r].port_no!=port) && (tls_info[r].port_no!=port)) {
 #else
@@ -243,32 +261,31 @@ int check_self(str* host, unsigned short port)
 				continue;
 			}
 		}
-		if ( (host->len==sock_info[r].name.len) && 
-#ifdef USE_IPV6
-			(strncasecmp(host->s, sock_info[r].name.s,
-				     sock_info[r].name.len)==0) /*slower*/
-#else
-			(memcmp(host->s, sock_info[r].name.s, 
-				sock_info[r].name.len)==0)
-#endif
-			)
+		if ( (h_len==sock_info[r].name.len) && 
+			(strncasecmp(hname, sock_info[r].name.s,
+				     sock_info[r].name.len)==0) /*slower*/)
+			/* comp. must be case insensitive, host names
+			 * can be written in mixed case, it will also match
+			 * ipv6 addresses */
 			break;
 	/* check if host == ip address */
-		if ( 	(!sock_info[r].is_ip) &&
-				(host->len==sock_info[r].address_str.len) && 
 #ifdef USE_IPV6
-			(strncasecmp(host->s, sock_info[r].address_str.s,
-								 sock_info[r].address_str.len)==0) /*slower*/
-#else
-			(memcmp(host->s, sock_info[r].address_str.s, 
-								sock_info[r].address_str.len)==0)
+		/* ipv6 case is uglier, host can be [3ffe::1] */
+		ip6=str2ip6(host);
+		if ((ip6) && ip_addr_cmp(ip6, &sock_info[r].address))
+			break; /* match */
 #endif
+		/* ipv4 */
+		if ( 	(!sock_info[r].is_ip) &&
+				(h_len==sock_info[r].address_str.len) && 
+			(memcmp(hname, sock_info[r].address_str.s, 
+								sock_info[r].address_str.len)==0)
 			)
 			break;
 	}
 	if (r==sock_no){
 		/* try to look into the aliases*/
-		if (grep_aliases(host->s, host->len, port)==0){
+		if (grep_aliases(hname, h_len, port)==0){
 			DBG("check_self: host != me\n");
 			return 0;
 		}

+ 2 - 1
name_alias.h

@@ -57,7 +57,8 @@ static inline int grep_aliases(char* name, int len, unsigned short port)
 	
 	for(a=aliases;a;a=a->next)
 #ifdef USE_TLS
-		if ((a->alias.len==len) && ((a->port==0) || (port==0) || (port==tls_port_no) ||
+		if ((a->alias.len==len) && ((a->port==0) || (port==0) || 
+					(port==tls_port_no) ||
 #else
 		if ((a->alias.len==len) && ((a->port==0) || (port==0) || 
 #endif