Date: Tue, 30 Aug 2005 16:49:45 GMT From: Victor Cruceru <soc-victor@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 82853 for review Message-ID: <200508301649.j7UGnjUM095513@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=82853 Change 82853 by soc-victor@soc-victor_82.76.158.176 on 2005/08/30 16:49:28 Various fixes for TCP-MIB & UDP-MIB instrumentations Affected files ... .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp_udp46/tcp46_snmp.c#7 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp_udp46/tcp_udp46.h#6 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp_udp46/tcp_udp46_common.c#5 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp_udp46/udp46_snmp.c#7 edit Differences ... ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp_udp46/tcp46_snmp.c#7 (text+ko) ==== @@ -88,23 +88,15 @@ #include "tcp_udp46.h" #include "tcp_udp46_oid.h" #include "tcp_udp46_tree.h" -#include <stdio.h> #include <syslog.h> -#include <sys/socketvar.h> -#include <netinet/in_pcb.h> -#include <netinet/tcp.h> -#include <netinet/tcp_var.h> #include <netinet/tcp_timer.h> #include <netinet/tcp_fsm.h> -#include <netinet/in.h> -#include <sys/socket.h> #include <arpa/inet.h> #include <string.h> #include <stdlib.h> #include <assert.h> -#include <sys/types.h> #include <sys/sysctl.h> -#include <sys/file.h> + @@ -206,14 +198,14 @@ /*next is the encoding for the SNMP table index*/ all_oid->index.len = 12; - all_oid->index.subs[0] = IAT_ipv4; + all_oid->index.subs[0] = (uint32_t)IAT_ipv4; inaddr = ntohl(tp->xt_inp.inp_laddr.s_addr); all_oid->index.subs[1] = (inaddr >> 24) & 0xff; all_oid->index.subs[2] = (inaddr >> 16) & 0xff; all_oid->index.subs[3] = (inaddr >> 8) & 0xff; all_oid->index.subs[4] = (inaddr >> 0) & 0xff; all_oid->index.subs[5] = ntohs(tp->xt_inp.inp_lport); - all_oid->index.subs[6] = IAT_ipv4; + all_oid->index.subs[6] = (uint32_t)IAT_ipv4; inaddr = ntohl(tp->xt_inp.inp_faddr.s_addr); all_oid->index.subs[7] = (inaddr >> 24) & 0xff; all_oid->index.subs[8] = (inaddr >> 16) & 0xff; @@ -237,13 +229,13 @@ assert(tp != NULL); /*next is the encoding for the SNMP table index*/ all_oid->index.len = 36; - all_oid->index.subs[0] = IAT_ipv6; + all_oid->index.subs[0] = (uint32_t)IAT_ipv6; for (i=0; i<16; i++) { all_oid->index.subs[1+i] = tp->xt_inp.in6p_laddr.s6_addr[i]; all_oid->index.subs[19+i] = tp->xt_inp.in6p_faddr.s6_addr[i]; } all_oid->index.subs[17] = ntohs(tp->xt_inp.in6p_lport); - all_oid->index.subs[18] = IAT_ipv6; + all_oid->index.subs[18] = (uint32_t)IAT_ipv6; all_oid->index.subs[35] = ntohs(tp->xt_inp.in6p_fport); @@ -282,7 +274,7 @@ _oid != listener_oid && i < tcp_udp46_state_g.listen_tcpoids_len; i++, _oid++ ) { - if ( _oid->index.subs[0] == IAT_ipv6 ) { + if ( _oid->index.subs[0] == (uint32_t)IAT_ipv6 ) { if ( _oid->index.subs[17] == ntohs(tp->xt_inp.inp_lport) && listener_oid->so_pgid == _oid->so_pgid) { L4_DPRINTF((stderr, "V4: [%s] Got listener with port %d.\n ", @@ -294,7 +286,7 @@ sizeof(zero_ip6)) == 0) { /*got it*/ _oid->index.len = 3; - _oid->index.subs[0] = IAT_unknown; + _oid->index.subs[0] = (uint32_t)IAT_unknown; _oid->index.subs[1] = 0; /*zero/ empty octet sting*/ _oid->index.subs[2] = ntohs(tp->xt_inp.inp_lport); return 1; @@ -334,7 +326,7 @@ _oid != listener_oid && i < tcp_udp46_state_g.listen_tcpoids_len; i++, _oid++ ) { - if ( _oid->index.subs[0] == IAT_ipv4 ) { + if ( _oid->index.subs[0] == (uint32_t)IAT_ipv4 ) { if ( _oid->index.subs[5] == ntohs(tp->xt_inp.in6p_lport) && listener_oid->so_pgid == _oid->so_pgid ) { L4_DPRINTF((stderr, "[%s] Got listener with port %d.\n ", @@ -346,7 +338,7 @@ sizeof(zero_ip4)) == 0) { /*got it*/ _oid->index.len = 3; - _oid->index.subs[0] = IAT_unknown; + _oid->index.subs[0] = (uint32_t)IAT_unknown; _oid->index.subs[1] = 0; /*zero/ empty octet sting*/ _oid->index.subs[2] = ntohs(tp->xt_inp.in6p_lport); return 1; @@ -382,7 +374,7 @@ } /*next is the encoding for the SNMP table index*/ listener_oid->index.len = 6; - listener_oid->index.subs[0] = IAT_ipv4; + listener_oid->index.subs[0] = (uint32_t)IAT_ipv4; inaddr = ntohl(tp->xt_inp.inp_laddr.s_addr); listener_oid->index.subs[1] = (inaddr >> 24) & 0xff; listener_oid->index.subs[2] = (inaddr >> 16) & 0xff; @@ -421,7 +413,7 @@ /*next is the encoding for the SNMP table index*/ listener_oid->index.len = 18; - listener_oid->index.subs[0] = IAT_ipv6; + listener_oid->index.subs[0] = (uint32_t)IAT_ipv6; for (i=0; i<16; i++) { listener_oid->index.subs[1+i] = tp->xt_inp.in6p_laddr.s6_addr[i]; } @@ -725,7 +717,7 @@ if (_deprecated == 0 ){ - if (conn->subs[0] == IAT_ipv4) { + if (conn->subs[0] == (uint32_t)IAT_ipv4) { struct sockaddr_in *sinl, *sinr; assert(conn->len == 12); @@ -736,7 +728,7 @@ return -1; } - if (conn->subs[6] != IAT_ipv4 ) { + if (conn->subs[6] != (uint32_t)IAT_ipv4 ) { syslog(LOG_ERR, "%s: malformed SNMP index (remote not a v4) when deleting a connection", __func__); @@ -757,7 +749,7 @@ sinl->sin_port = htons(conn->subs[5]); addrs[1].ss_family = AF_INET; - inet_ntop(AF_INET, &sinl->sin_addr, local, 64); + (void)inet_ntop(AF_INET, &sinl->sin_addr, local, 64); @@ -774,7 +766,7 @@ sinr->sin_port = htons(conn->subs[11]); addrs[0].ss_family = AF_INET; - inet_ntop(AF_INET, &sinr->sin_addr, remote, 64); + (void)inet_ntop(AF_INET, &sinr->sin_addr, remote, 64); syslog(LOG_INFO, "[%s] attempt to delete a tcp4 connection : local: %s:%d - remote: %s:%d \n ", __func__, @@ -784,7 +776,7 @@ conn->subs[11]); - } else if (conn->subs[0] == IAT_ipv6) { + } else if (conn->subs[0] == (uint32_t)IAT_ipv6) { struct sockaddr_in6 *sin6l, *sin6r; int i = 0; assert(conn->len == 36); @@ -795,7 +787,7 @@ return -1; } - if (conn->subs[18] != IAT_ipv6 ) { + if (conn->subs[18] != (uint32_t)IAT_ipv6 ) { syslog(LOG_ERR, "%s: malformed SNMP index (remote not a v6) when deleting a connection", __func__); @@ -815,7 +807,7 @@ sin6l->sin6_len = sizeof(struct sockaddr_in6); #endif /* SIN6_LEN */ addrs[1].ss_family = AF_INET6; - inet_ntop(AF_INET6, &sin6l->sin6_addr, local, 64); + (void)inet_ntop(AF_INET6, &sin6l->sin6_addr, local, 64); memset(&addrs[0], 0, sizeof(addrs[0])); sin6r = (struct sockaddr_in6 *)&addrs[0]; @@ -830,7 +822,7 @@ #endif /* SIN6_LEN */ addrs[0].ss_family = AF_INET6; - inet_ntop(AF_INET6, &sin6r->sin6_addr, remote, 64); + (void)inet_ntop(AF_INET6, &sin6r->sin6_addr, remote, 64); syslog(LOG_INFO, "[%s] attempt to delete a tcp6 connection: local: %s:%d - remote: %s:%d \n ", @@ -875,7 +867,7 @@ sinl->sin_port = htons(conn->subs[4]); addrs[1].ss_family = AF_INET; - inet_ntop(AF_INET, &sinl->sin_addr, local, 64); + (void)inet_ntop(AF_INET, &sinl->sin_addr, local, 64); @@ -892,20 +884,20 @@ sinr->sin_port = htons(conn->subs[9]); addrs[0].ss_family = AF_INET; - inet_ntop(AF_INET, &sinr->sin_addr, remote, 64); + (void)inet_ntop(AF_INET, &sinr->sin_addr, remote, 64); syslog(LOG_INFO, - "[%s] attempt to delete a tcp4 connection : local: %s:%d - remote: %s:%d \n ", - __func__, - local, - conn->subs[4], - remote, - conn->subs[9]); + "[%s] attempt to delete a tcp4 connection : local: %s:%d - remote: %s:%d \n ", + __func__, + local, + conn->subs[4], + remote, + conn->subs[9]); } if (sysctl(mib, sizeof (mib) / sizeof (int), NULL, - NULL, &addrs, sizeof(addrs)) == -1) { + NULL, &addrs[0], sizeof(addrs)) == -1) { syslog(LOG_ERR, "%s: failed to delete the specified tcp connection: %m", __func__); return -1; } else { @@ -916,7 +908,7 @@ return 0; } - return 0; + /*Unreachable*/ } @@ -1069,7 +1061,7 @@ if (value->var.subs[sub - 1] != LEAF_tcpConnState) { return (SNMP_ERR_NOT_WRITEABLE); } - if (value->v.integer != TCPS_deleteTCB) { + if (value->v.integer != (int)TCPS_deleteTCB) { return (SNMP_ERR_WRONG_VALUE); } @@ -1095,6 +1087,8 @@ default: abort(); } + + assert(tcp_udp46_state_g.tcp4oids[i].index.len == 10); switch (value->var.subs[sub - 1]) { @@ -1102,37 +1096,37 @@ switch (tcp_udp46_state_g.tcp4oids[i].tp->xt_tp.t_state) { case TCPS_CLOSED: - value->v.integer = TCPS_closed; + value->v.integer = (int32_t)TCPS_closed; break; case TCPS_LISTEN: - value->v.integer = TCPS_listen; + value->v.integer = (int32_t)TCPS_listen; break; case TCPS_SYN_SENT: - value->v.integer = TCPS_synSent; + value->v.integer = (int32_t)TCPS_synSent; break; case TCPS_SYN_RECEIVED: - value->v.integer = TCPS_synReceived; + value->v.integer = (int32_t)TCPS_synReceived; break; case TCPS_ESTABLISHED: - value->v.integer = TCPS_established; + value->v.integer = (int32_t)TCPS_established; break; case TCPS_CLOSE_WAIT: - value->v.integer = TCPS_closeWait; + value->v.integer = (int32_t)TCPS_closeWait; break; case TCPS_FIN_WAIT_1: - value->v.integer = TCPS_finWait1; + value->v.integer = (int32_t)TCPS_finWait1; break; case TCPS_CLOSING: - value->v.integer = TCPS_closing; + value->v.integer = (int32_t)TCPS_closing; break; case TCPS_LAST_ACK: - value->v.integer = TCPS_lastAck; + value->v.integer = (int32_t)TCPS_lastAck; break; case TCPS_FIN_WAIT_2: - value->v.integer = TCPS_finWait2; + value->v.integer = (int32_t)TCPS_finWait2; break; case TCPS_TIME_WAIT: - value->v.integer = TCPS_timeWait; + value->v.integer = (int32_t)TCPS_timeWait; break; default: value->v.integer = 0; @@ -1140,7 +1134,6 @@ } break; - assert(tcp_udp46_state_g.tcp4oids[i].index.len == 10); case LEAF_tcpConnLocalAddress: value->v.ipaddress[0] = tcp_udp46_state_g.tcp4oids[i].index.subs[0]; @@ -1161,7 +1154,7 @@ break; case LEAF_tcpConnRemPort: - value->v.integer = tcp_udp46_state_g.tcp4oids[i].index.subs[9]; + value->v.uint32 = tcp_udp46_state_g.tcp4oids[i].index.subs[9]; break; } return (SNMP_ERR_NOERROR); @@ -1209,7 +1202,7 @@ if (value->var.subs[sub - 1] != LEAF_tcpConnectionState) { return (SNMP_ERR_NOT_WRITEABLE); } - if (value->v.integer != TCPS_deleteTCB) { + if (value->v.integer != (int32_t)TCPS_deleteTCB) { return (SNMP_ERR_WRONG_VALUE); } @@ -1246,38 +1239,38 @@ switch (tcp_udp46_state_g.all_tcpoids[i].tp->xt_tp.t_state) { case TCPS_CLOSED: - value->v.integer = TCPS_closed; + value->v.integer = (int32_t)TCPS_closed; break; case TCPS_LISTEN: - value->v.integer = TCPS_listen; + value->v.integer = (int32_t)TCPS_listen; assert(0); break; case TCPS_SYN_SENT: - value->v.integer = TCPS_synSent; + value->v.integer = (int32_t)TCPS_synSent; break; case TCPS_SYN_RECEIVED: - value->v.integer = TCPS_synReceived; + value->v.integer = (int32_t)TCPS_synReceived; break; case TCPS_ESTABLISHED: - value->v.integer = TCPS_established; + value->v.integer = (int32_t)TCPS_established; break; case TCPS_CLOSE_WAIT: - value->v.integer = TCPS_closeWait; + value->v.integer = (int32_t)TCPS_closeWait; break; case TCPS_FIN_WAIT_1: - value->v.integer = TCPS_finWait1; + value->v.integer = (int32_t)TCPS_finWait1; break; case TCPS_CLOSING: - value->v.integer = TCPS_closing; + value->v.integer = (int32_t)TCPS_closing; break; case TCPS_LAST_ACK: - value->v.integer = TCPS_lastAck; + value->v.integer = (int32_t)TCPS_lastAck; break; case TCPS_FIN_WAIT_2: - value->v.integer = TCPS_finWait2; + value->v.integer = (int32_t)TCPS_finWait2; break; case TCPS_TIME_WAIT: - value->v.integer = TCPS_timeWait; + value->v.integer = (int32_t)TCPS_timeWait; break; default: value->v.integer = 0; @@ -1289,7 +1282,6 @@ case LEAF_tcpConnectionProcess: /*this is from hrSWRunTable, where the index is pid + 1 */ - /*FIX ME: this doesn't work*/ value->v.integer = ( tcp_udp46_state_g.all_tcpoids[i].so_pgid == 0 ? 0 : tcp_udp46_state_g.all_tcpoids[i].so_pgid + 1 ); break; ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp_udp46/tcp_udp46.h#6 (text+ko) ==== @@ -34,14 +34,12 @@ #include "asn1.h" #include "snmp.h" #include "snmpmod.h" -#include <sys/time.h> /*for struct clockinfo*/ #include <sys/socketvar.h> #include <netinet/in_pcb.h> /*for struct xinpgen*/ #include <netinet/tcp.h> #include <netinet/tcp_var.h> /*for struct tcpstat*/ #include <sys/file.h> /*for struct xfile*/ #include <stdio.h> /*for fprintf*/ -#include <sys/types.h> /*for pid_t*/ #include <netinet/udp.h> #include <netinet/ip_var.h> #include <netinet/udp_var.h> ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp_udp46/tcp_udp46_common.c#5 (text+ko) ==== @@ -68,8 +68,11 @@ */ static int tcp_udp46_init(struct lmodule * mod, int argc __unused, char *argv[] __unused) { + + size_t len = 0; + tcp_udp46_module = mod; - int len = 0; + memset(&tcp_udp46_state_g, 0, sizeof(struct tcp_udp46_state)); len = sizeof(tcp_udp46_state_g.clock_info); ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp_udp46/udp46_snmp.c#7 (text+ko) ==== @@ -63,13 +63,11 @@ */ #include "tcp_udp46.h" -#include "tcp_udp46.h" #include "tcp_udp46_oid.h" #include "tcp_udp46_tree.h" #include <assert.h> #include <string.h> #include <stdlib.h> -#include <sys/types.h> #include <sys/sysctl.h> #include <syslog.h> @@ -164,7 +162,7 @@ if ( _oid->inp == NULL) { continue; } - if ( _oid->index.subs[0] == IAT_ipv4 + if ( _oid->index.subs[0] == (uint32_t)IAT_ipv4 && inp->xi_inp.inp_laddr.s_addr == _oid->inp->xi_inp.inp_laddr.s_addr && inp->xi_inp.inp_lport == _oid->inp->xi_inp.inp_lport && inp->xi_inp.inp_faddr.s_addr == _oid->inp->xi_inp.inp_faddr.s_addr @@ -179,7 +177,7 @@ /*check for an existent IPv6 endpoint bound to 0::0/128 */ if ( inp->xi_inp.inp_laddr.s_addr == INADDR_ANY && inp->xi_inp.inp_faddr.s_addr == INADDR_ANY ) { - if( _oid->index.subs[0] == IAT_ipv6 && + if( _oid->index.subs[0] == (uint32_t)IAT_ipv6 && _oid->inp->xi_inp.in6p_lport == inp->xi_inp.inp_lport && pid_owner == _oid->so_pgid) { if (memcmp(&zero_ip6[0], @@ -194,10 +192,10 @@ _oid->index.subs[21] : _oid->index.subs[36] ); _oid->index.len = 7; - _oid->index.subs[0] = IAT_unknown; + _oid->index.subs[0] = (uint32_t)IAT_unknown; _oid->index.subs[1] = 0; /*zero/ empty octet sting*/ _oid->index.subs[2] = ntohs(inp->xi_inp.inp_lport); - _oid->index.subs[3] = IAT_unknown; + _oid->index.subs[3] = (uint32_t)IAT_unknown; _oid->index.subs[4] = 0; /*zero/ empty octet sting*/ _oid->index.subs[5] = ntohs(_oid->inp->xi_inp.in6p_fport); /*copy instance number*/ @@ -210,7 +208,7 @@ } - all_oid->index.subs[0] = IAT_ipv4; + all_oid->index.subs[0] = (uint32_t)IAT_ipv4; inaddr = ntohl(inp->xi_inp.inp_laddr.s_addr); all_oid->index.subs[1] = (inaddr >> 24) & 0xff; all_oid->index.subs[2] = (inaddr >> 16) & 0xff; @@ -221,14 +219,14 @@ if(inp->xi_inp.inp_faddr.s_addr == INADDR_ANY && inp->xi_inp.inp_fport == 0 ){ all_oid->index.len = 10; - all_oid->index.subs[6] = IAT_unknown; + all_oid->index.subs[6] = (uint32_t)IAT_unknown; all_oid->index.subs[7] = 0; /*zero/ empty octet sting*/ all_oid->index.subs[8] = 0; all_oid->index.subs[9] = instance; } else { all_oid->index.len = 13; - all_oid->index.subs[6] = IAT_ipv4; + all_oid->index.subs[6] = (uint32_t)IAT_ipv4; inaddr = ntohl(inp->xi_inp.inp_faddr.s_addr); all_oid->index.subs[7] = (inaddr >> 24) & 0xff; all_oid->index.subs[8] = (inaddr >> 16) & 0xff; @@ -263,7 +261,7 @@ if ( _oid->inp == NULL) { continue; } - if ( _oid->index.subs[0] == IAT_ipv6 + if ( _oid->index.subs[0] == (uint32_t)IAT_ipv6 && IN6_ARE_ADDR_EQUAL(&inp->xi_inp.in6p_laddr, &_oid->inp->xi_inp.in6p_laddr) == 0 && inp->xi_inp.in6p_lport == _oid->inp->xi_inp.in6p_lport @@ -280,7 +278,7 @@ /*check for an existent IPv4 endpoint bound to 0.0.0.0 */ if ( IN6_IS_ADDR_UNSPECIFIED(&inp->xi_inp.in6p_laddr) && IN6_IS_ADDR_UNSPECIFIED(&inp->xi_inp.in6p_faddr)) { - if( _oid->index.subs[0] == IAT_ipv4 && + if( _oid->index.subs[0] == (uint32_t)IAT_ipv4 && _oid->inp->xi_inp.inp_lport == inp->xi_inp.in6p_lport && pid_owner == _oid->so_pgid) { if ( inp->xi_inp.inp_faddr.s_addr == INADDR_ANY && @@ -291,10 +289,10 @@ _oid->index.subs[9] : _oid->index.subs[12] ); _oid->index.len = 7; - _oid->index.subs[0] = IAT_unknown; + _oid->index.subs[0] = (uint32_t)IAT_unknown; _oid->index.subs[1] = 0; /*zero/ empty octet sting*/ _oid->index.subs[2] = ntohs(inp->xi_inp.inp_lport); - _oid->index.subs[3] = IAT_unknown; + _oid->index.subs[3] = (uint32_t)IAT_unknown; _oid->index.subs[4] = 0; /*zero/ empty octet sting*/ _oid->index.subs[5] = ntohs(_oid->inp->xi_inp.in6p_fport); /*copy instance number*/ @@ -312,12 +310,12 @@ inp->xi_inp.in6p_fport == 0 ) { all_oid->index.len = 22; - all_oid->index.subs[0] = IAT_ipv6; + all_oid->index.subs[0] = (uint32_t)IAT_ipv6; for (i=0; i<16; i++) { all_oid->index.subs[1+i] = inp->xi_inp.in6p_laddr.s6_addr[i]; } all_oid->index.subs[17] = ntohs(inp->xi_inp.in6p_lport); - all_oid->index.subs[18] = IAT_unknown; + all_oid->index.subs[18] = (uint32_t)IAT_unknown; all_oid->index.subs[19] = 0; all_oid->index.subs[20] = 0; all_oid->index.subs[21] = instance; @@ -325,13 +323,13 @@ } else { all_oid->index.len = 37; - all_oid->index.subs[0] = IAT_ipv6; + all_oid->index.subs[0] = (uint32_t)IAT_ipv6; for (i=0; i<16; i++) { all_oid->index.subs[1+i] = inp->xi_inp.in6p_laddr.s6_addr[i]; all_oid->index.subs[19+i] = inp->xi_inp.in6p_faddr.s6_addr[i]; } all_oid->index.subs[17] = ntohs(inp->xi_inp.in6p_lport); - all_oid->index.subs[18] = IAT_ipv6; + all_oid->index.subs[18] = (uint32_t)IAT_ipv6; all_oid->index.subs[35] = ntohs(inp->xi_inp.in6p_fport); all_oid->index.subs[36] = instance; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200508301649.j7UGnjUM095513>