svn commit: samba r18993 - in branches/SAMBA_3_0/source/lib/socket_wrapper: .

metze at samba.org metze at samba.org
Fri Sep 29 09:48:46 GMT 2006


Author: metze
Date: 2006-09-29 09:48:46 +0000 (Fri, 29 Sep 2006)
New Revision: 18993

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=18993

Log:
merge from samba4:

prepare SOCKET_WRAPPER_PCAP_FILE support

metze
Modified:
   branches/SAMBA_3_0/source/lib/socket_wrapper/socket_wrapper.c


Changeset:
Modified: branches/SAMBA_3_0/source/lib/socket_wrapper/socket_wrapper.c
===================================================================
--- branches/SAMBA_3_0/source/lib/socket_wrapper/socket_wrapper.c	2006-09-29 09:31:20 UTC (rev 18992)
+++ branches/SAMBA_3_0/source/lib/socket_wrapper/socket_wrapper.c	2006-09-29 09:48:46 UTC (rev 18993)
@@ -109,6 +109,7 @@
 	int protocol;
 	int bound;
 	int bcast;
+	int is_server;
 
 	char *path;
 	char *tmp_path;
@@ -137,14 +138,10 @@
 	return s;
 }
 
-static const char *socket_wrapper_dump_dir(void)
+static const char *socket_wrapper_pcap_file(void)
 {
-	const char *s = getenv("SOCKET_WRAPPER_DUMP_DIR");
+	const char *s = getenv("SOCKET_WRAPPER_PCAP_FILE");
 
-	if (!socket_wrapper_dir()) {
-		return NULL;
-	}
-
 	if (s == NULL) {
 		return NULL;
 	}
@@ -435,23 +432,40 @@
 }
 
 enum swrap_packet_type {
-	SWRAP_CONNECT,
-	SWRAP_ACCEPT,
+	SWRAP_CONNECT_SEND,
+	SWRAP_CONNECT_UNREACH,
+	SWRAP_CONNECT_RECV,
+	SWRAP_CONNECT_ACK,
+	SWRAP_ACCEPT_SEND,
+	SWRAP_ACCEPT_RECV,
+	SWRAP_ACCEPT_ACK,
 	SWRAP_RECVFROM,
 	SWRAP_SENDTO,
+	SWRAP_SENDTO_UNREACH,
+	SWRAP_PENDING_RST,
 	SWRAP_RECV,
+	SWRAP_RECV_RST,
 	SWRAP_SEND,
-	SWRAP_CLOSE
+	SWRAP_SEND_RST,
+	SWRAP_CLOSE_SEND,
+	SWRAP_CLOSE_RECV,
+	SWRAP_CLOSE_ACK
 };
 
 static void swrap_dump_packet(struct socket_info *si, const struct sockaddr *addr,
 			      enum swrap_packet_type type,
-			      const void *buf, size_t len, ssize_t ret)
+			      const void *buf, size_t len)
 {
-	if (!socket_wrapper_dump_dir()) {
+	const char *file_name;
+
+	file_name = socket_wrapper_pcap_file();
+	if (!file_name) {
 		return;
 	}
 
+	if (si->family != AF_INET) {
+		return;
+	}
 }
 
 _PUBLIC_ int swrap_socket(int family, int type, int protocol)
@@ -548,6 +562,7 @@
 	child_si->type = parent_si->type;
 	child_si->protocol = parent_si->protocol;
 	child_si->bound = 1;
+	child_si->is_server = 1;
 
 	ret = real_getsockname(fd, (struct sockaddr *)&un_my_addr, &un_my_addrlen);
 	if (ret == -1) {
@@ -572,7 +587,9 @@
 
 	DLIST_ADD(sockets, child_si);
 
-	swrap_dump_packet(child_si, addr, SWRAP_ACCEPT, NULL, 0, 0);
+	swrap_dump_packet(child_si, addr, SWRAP_ACCEPT_SEND, NULL, 0);
+	swrap_dump_packet(child_si, addr, SWRAP_ACCEPT_RECV, NULL, 0);
+	swrap_dump_packet(child_si, addr, SWRAP_ACCEPT_ACK, NULL, 0);
 
 	return fd;
 }
@@ -668,6 +685,8 @@
 	ret = sockaddr_convert_to_un(si, (const struct sockaddr *)serv_addr, addrlen, &un_addr, 0, NULL);
 	if (ret == -1) return -1;
 
+	swrap_dump_packet(si, serv_addr, SWRAP_CONNECT_SEND, NULL, 0);
+
 	ret = real_connect(s, (struct sockaddr *)&un_addr, 
 			   sizeof(struct sockaddr_un));
 
@@ -679,10 +698,13 @@
 	if (ret == 0) {
 		si->peername_len = addrlen;
 		si->peername = sockaddr_dup(serv_addr, addrlen);
+
+		swrap_dump_packet(si, serv_addr, SWRAP_CONNECT_RECV, NULL, 0);
+		swrap_dump_packet(si, serv_addr, SWRAP_CONNECT_ACK, NULL, 0);
+	} else {
+		swrap_dump_packet(si, serv_addr, SWRAP_CONNECT_UNREACH, NULL, 0);
 	}
 
-	swrap_dump_packet(si, serv_addr, SWRAP_CONNECT, NULL, 0, ret);
-
 	return ret;
 }
 
@@ -736,7 +758,7 @@
 		return real_getpeername(s, name, addrlen);
 	}
 
-	if (!si->peername) 
+	if (!si->peername)
 	{
 		errno = ENOTCONN;
 		return -1;
@@ -821,7 +843,7 @@
 		return -1;
 	}
 
-	swrap_dump_packet(si, from, SWRAP_RECVFROM, buf, len, ret);
+	swrap_dump_packet(si, from, SWRAP_RECVFROM, buf, ret);
 
 	return ret;
 }
@@ -863,7 +885,7 @@
 			real_sendto(s, buf, len, flags, (struct sockaddr *)&un_addr, sizeof(un_addr));
 		}
 
-		swrap_dump_packet(si, to, SWRAP_SENDTO, buf, len, len);
+		swrap_dump_packet(si, to, SWRAP_SENDTO, buf, len);
 
 		return len;
 	}
@@ -875,7 +897,12 @@
 		errno = EHOSTUNREACH;
 	}
 
-	swrap_dump_packet(si, to, SWRAP_SENDTO, buf, len, ret);
+	if (ret == -1) {
+		swrap_dump_packet(si, to, SWRAP_SENDTO, buf, len);
+		swrap_dump_packet(si, to, SWRAP_SENDTO_UNREACH, buf, len);
+	} else {
+		swrap_dump_packet(si, to, SWRAP_SENDTO, buf, ret);
+	}
 
 	return ret;
 }
@@ -883,7 +910,8 @@
 _PUBLIC_ int swrap_ioctl(int s, int r, void *p)
 {
 	int ret;
-	struct socket_info *si = find_socket_info(s);	
+	struct socket_info *si = find_socket_info(s);
+	int value;
 
 	if (!si) {
 		return real_ioctl(s, r, p);
@@ -891,6 +919,17 @@
 
 	ret = real_ioctl(s, r, p);
 
+	switch (r) {
+	case FIONREAD:
+		value = *((int *)p);
+		if (ret == -1 && errno != EAGAIN && errno != ENOBUFS) {
+			swrap_dump_packet(si, NULL, SWRAP_PENDING_RST, NULL, 0);
+		} else if (value == 0) { /* END OF FILE */
+			swrap_dump_packet(si, NULL, SWRAP_PENDING_RST, NULL, 0);
+		}
+		break;
+	}
+
 	return ret;
 }
 
@@ -904,11 +943,14 @@
 	}
 
 	ret = real_recv(s, buf, len, flags);
-	if (ret == -1) 
-		return ret;
+	if (ret == -1 && errno != EAGAIN && errno != ENOBUFS) {
+		swrap_dump_packet(si, NULL, SWRAP_RECV_RST, NULL, 0);
+	} else if (ret == 0) { /* END OF FILE */
+		swrap_dump_packet(si, NULL, SWRAP_RECV_RST, NULL, 0);
+	} else {
+		swrap_dump_packet(si, NULL, SWRAP_RECV, buf, ret);
+	}
 
-	swrap_dump_packet(si, NULL, SWRAP_RECV, buf, len, ret);
-
 	return ret;
 }
 
@@ -923,10 +965,13 @@
 	}
 
 	ret = real_send(s, buf, len, flags);
-	if (ret == -1) 
-		return ret;
 
-	swrap_dump_packet(si, NULL, SWRAP_SEND, buf, len, ret);
+	if (ret == -1) {
+		swrap_dump_packet(si, NULL, SWRAP_SEND, buf, len);
+		swrap_dump_packet(si, NULL, SWRAP_SEND_RST, NULL, 0);
+	} else {
+		swrap_dump_packet(si, NULL, SWRAP_SEND, buf, ret);
+	}
 
 	return ret;
 }
@@ -942,11 +987,20 @@
 
 	DLIST_REMOVE(sockets, si);
 
+	if (si->myname && si->peername) {
+		swrap_dump_packet(si, NULL, SWRAP_CLOSE_SEND, NULL, 0);
+	}
+
 	ret = real_close(fd);
 
-	free(si->path);
-	free(si->myname);
-	free(si->peername);
+	if (si->myname && si->peername) {
+		swrap_dump_packet(si, NULL, SWRAP_CLOSE_RECV, NULL, 0);
+		swrap_dump_packet(si, NULL, SWRAP_CLOSE_ACK, NULL, 0);
+	}
+
+	if (si->path) free(si->path);
+	if (si->myname) free(si->myname);
+	if (si->peername) free(si->peername);
 	if (si->tmp_path) {
 		unlink(si->tmp_path);
 		free(si->tmp_path);



More information about the samba-cvs mailing list