Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 27 Aug 2005 19:55:28 GMT
From:      Victor Cruceru <soc-victor@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 82680 for review
Message-ID:  <200508271955.j7RJtStG079107@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=82680

Change 82680 by soc-victor@soc-victor_82.76.158.176 on 2005/08/27 19:54:28

	
	Added support for TCP-MIB::tcpConnectionProcess and  TCP-MIB::tcpListenerProcess
	(based on "kern.file" sysctl ). Now we are fully compliant with the RFC 4022.

Affected files ...

.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp46/tcp46_snmp.c#8 edit

Differences ...

==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp46/tcp46_snmp.c#8 (text+ko) ====

@@ -107,6 +107,7 @@
 #include <assert.h>
 #include <sys/types.h>
 #include <sys/sysctl.h>
+#include <sys/file.h>
 
 /*forward declaration*/
 static int
@@ -206,6 +207,10 @@
 
 	struct tcp_index *listen_tcpoids;	/*snmp vector for the unified v4 and v6 listners tcp table; malloc'd*/
 	size_t		listen_tcpoids_len;	/*the allocated len of the above vector */
+	
+	struct xfile 	*xfiles;
+	size_t 		xfiles_len;
+	u_int		xfiles_total;
 
 				
 };
@@ -272,6 +277,11 @@
 		tcp46_state_g.xinpgen_len = 0;
 	}
 
+	if (tcp46_state_g.xfiles != NULL && tcp46_state_g.xfiles_len > 0 ) {
+		free(tcp46_state_g.xfiles);
+		tcp46_state_g.xfiles = NULL;
+		tcp46_state_g.xfiles_len = 0;
+	}
 		
 	if (tcp46_registration_id > 0) {
 		or_unregister(tcp46_registration_id);
@@ -355,6 +365,26 @@
 	tcp46_loading_v
 };
 
+
+static
+pid_t 
+get_socket_pid(struct xtcpcb *tp) {
+	struct xfile *xf = NULL;
+	u_int n = 0;
+	assert(tp != NULL);
+	
+	for (xf =  tcp46_state_g.xfiles, n = 0; n < tcp46_state_g.xfiles_total; ++n, ++xf) {
+		if (xf->xf_data == NULL) {
+			continue;
+		}	
+		if (xf->xf_data == (void *)tp->xt_socket.xso_so) {
+			return (xf->xf_pid);
+		}	
+	}
+	return ((pid_t)0);		
+}
+
+
 /*
  * Add an entry into the list associated with the old/ deprecated
  * tcpConnTable
@@ -409,8 +439,8 @@
 	all_oid->index.subs[10] = (inaddr >>  0) & 0xff;
 	all_oid->index.subs[11] = ntohs(tp->xt_inp.inp_fport);
 	
-	/*FIX ME: this doesn't work*/
-	all_oid->so_pgid = tp->xt_socket.so_pgid;
+
+	all_oid->so_pgid = get_socket_pid(tp);
 
 }
 
@@ -434,8 +464,8 @@
 	all_oid->index.subs[18] = IAT_ipv6;
 	all_oid->index.subs[35] = ntohs(tp->xt_inp.in6p_fport);
 	
-	/*FIX ME: this doesn't work*/
-	all_oid->so_pgid = tp->xt_socket.so_pgid;
+
+	all_oid->so_pgid = get_socket_pid(tp);
 
 }
 
@@ -471,7 +501,8 @@
 		i++, _oid++ )
 	{
 		if ( _oid->index.subs[0] == IAT_ipv6 ) {
-			if ( _oid->index.subs[17] == ntohs(tp->xt_inp.inp_lport) ){
+			if ( _oid->index.subs[17] == ntohs(tp->xt_inp.inp_lport) && 
+				listener_oid->so_pgid == _oid->so_pgid) {
 				TCP46_DPRINTF((stderr, "V4: [%s] Got listener with port %d.\n ", 
 					__func__,
 					_oid->index.subs[5])); 		
@@ -522,7 +553,8 @@
 		i++, _oid++ )
 	{
 		if ( _oid->index.subs[0] == IAT_ipv4 ) {
-			if ( _oid->index.subs[5] == ntohs(tp->xt_inp.in6p_lport) ) {
+			if ( _oid->index.subs[5] == ntohs(tp->xt_inp.in6p_lport) && 
+			     listener_oid->so_pgid == _oid->so_pgid ) {
 				TCP46_DPRINTF((stderr, "[%s] Got listener with port %d.\n ", 
 					__func__,
 					_oid->index.subs[5])); 		
@@ -560,6 +592,9 @@
 	in_addr_t inaddr;
 	assert(listener_oid != NULL);
 	assert(tp != NULL);
+	
+	listener_oid->so_pgid = get_socket_pid(tp);
+	
 	if ( check_duplicate6_listner( listener_oid, tp ) == 1 ) {
 		return 1;
 	}
@@ -572,8 +607,8 @@
 	listener_oid->index.subs[3] = (inaddr >>  8) & 0xff;
 	listener_oid->index.subs[4] = (inaddr >>  0) & 0xff;
 	listener_oid->index.subs[5] = ntohs(tp->xt_inp.inp_lport);
-	/*FIX ME: this doesn't work*/
-	listener_oid->so_pgid = tp->xt_socket.so_pgid;
+	
+	
 	return 0;
 
 }
@@ -595,6 +630,9 @@
 	int i = 0;
 	assert(listener_oid != NULL);
 	assert(tp != NULL);
+	
+	listener_oid->so_pgid = get_socket_pid(tp);
+	
 	if ( check_duplicate4_listner( listener_oid, tp ) == 1 ) {
 		return 1;
 	}
@@ -607,13 +645,45 @@
 	}
 	listener_oid->index.subs[17] = ntohs(tp->xt_inp.in6p_lport);
 	
-	/*FIX ME: this doesn't work*/
-	listener_oid->so_pgid = tp->xt_socket.so_pgid;
+	
+	
 	return 0;
 
 }
 
 static int
+fetch_xfiles(void) {
+	size_t xfilesize = 0;
+	struct xfile *ptr = NULL;
+	
+	tcp46_state_g.xfiles_total = 0;
+	
+	/* Get the xfiles */
+	if (sysctlbyname("kern.file", NULL, &xfilesize, NULL, 0)) {
+		syslog(LOG_ERR, "sysctlbyname(kern.file) failed: %m");
+		return (-1);
+	}	
+	if (xfilesize > tcp46_state_g.xfiles_len) {
+		if ((ptr = realloc(tcp46_state_g.xfiles, xfilesize)) == NULL) {
+			syslog(LOG_ERR, "%zu: %m", xfilesize);
+			return (-1);
+		}
+		tcp46_state_g.xfiles = ptr;
+		tcp46_state_g.xfiles_len = xfilesize;
+	}
+
+
+	if (sysctlbyname("kern.file", tcp46_state_g.xfiles, &xfilesize, NULL, 0) < 0) {
+		syslog(LOG_ERR, "sysctlbyname(kern.file) failed: %m");
+		return (-1);
+	}
+	tcp46_state_g.xfiles_total = xfilesize / sizeof(struct xfile);
+	return 0;
+}
+
+
+
+static int
 fetch_tcp(void)
 {
 	size_t len;
@@ -657,6 +727,10 @@
 	tcp46_state_g.all_tcp_total = 0;
 	tcp46_state_g.listen_tcp_total = 0;
 	
+	if (fetch_xfiles() != 0) {
+		TCP46_DPRINTF((stderr, "[%s] Failed to fetch the xfiles\n ", __func__ ));
+	}
+	
 	/*First count the endpoints*/
 	for (ptr = (struct xinpgen *)(void *)((char *)tcp46_state_g.xinpgen + tcp46_state_g.xinpgen->xig_len);
 	     ptr->xig_len > sizeof(struct xinpgen);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200508271955.j7RJtStG079107>