Date: Sun, 28 Aug 2005 17:17:49 GMT From: Victor Cruceru <soc-victor@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 82719 for review Message-ID: <200508281717.j7SHHn5k027246@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=82719 Change 82719 by soc-victor@soc-victor_82.76.158.176 on 2005/08/28 17:17:29 Finished the preparations for implementing RFC 4113 (combined v4 & v6 UDP-MIB): - deactivated the old code for RFC 2013 (v4 only UDP-MIB, obsoleted by RFC 4113) - added the boilerplate code for the new UDP-MIB. Affected files ... .. //depot/projects/soc2005/bsnmp/contrib/bsnmp/snmp_mibII/mibII.c#5 edit .. //depot/projects/soc2005/bsnmp/contrib/bsnmp/snmp_mibII/mibII_tree.def#4 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_mibII/Makefile#3 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp_udp46/Makefile#3 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp_udp46/tcp46_snmp.c#3 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp_udp46/tcp_udp46.h#1 add .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp_udp46/tcp_udp46_common.c#1 add .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp_udp46/tcp_udp46_tree.def#2 edit .. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp_udp46/udp46_snmp.c#1 add Differences ... ==== //depot/projects/soc2005/bsnmp/contrib/bsnmp/snmp_mibII/mibII.c#5 (text+ko) ==== @@ -58,7 +58,10 @@ static u_int ifmib_reg; static u_int ipmib_reg; +#if 0 static u_int udpmib_reg; +#endif /*0*/ + static u_int ipForward_reg; /*****************************/ @@ -112,7 +115,9 @@ static const struct asn_oid oid_ifMIB = OIDX_ifMIB; static const struct asn_oid oid_ipMIB = OIDX_ipMIB; +#if 0 static const struct asn_oid oid_udpMIB = OIDX_udpMIB; +#endif /*0*/ static const struct asn_oid oid_ipForward = OIDX_ipForward; static const struct asn_oid oid_linkDown = OIDX_linkDown; static const struct asn_oid oid_linkUp = OIDX_linkUp; @@ -1441,9 +1446,10 @@ "The MIB module for managing IP and ICMP implementations, but " "excluding their management of IP routes.", module); - +#if 0 udpmib_reg = or_register(&oid_udpMIB, "The MIB module for managing UDP implementations.", module); +#endif /*0*/ ipForward_reg = or_register(&oid_ipForward, "The MIB module for the display of CIDR multipath IP Routes.", @@ -1501,8 +1507,9 @@ /* XXX free memory */ or_unregister(ipForward_reg); +#if 0 or_unregister(udpmib_reg); - +#endif or_unregister(ipmib_reg); or_unregister(ifmib_reg); ==== //depot/projects/soc2005/bsnmp/contrib/bsnmp/snmp_mibII/mibII_tree.def#4 (text+ko) ==== @@ -148,17 +148,17 @@ (25 icmpOutAddrMasks COUNTER op_icmpstat GET) (26 icmpOutAddrMaskReps COUNTER op_icmpstat GET) ) - (7 udp - (1 udpInDatagrams COUNTER op_udp GET) - (2 udpNoPorts COUNTER op_udp GET) - (3 udpInErrors COUNTER op_udp GET) - (4 udpOutDatagrams COUNTER op_udp GET) - (5 udpTable - (1 udpEntry : IPADDRESS INTEGER op_udptable - (1 udpLocalAddress IPADDRESS GET) - (2 udpLocalPort INTEGER GET) - )) - ) +# (7 udp +# (1 udpInDatagrams COUNTER op_udp GET) +# (2 udpNoPorts COUNTER op_udp GET) +# (3 udpInErrors COUNTER op_udp GET) +# (4 udpOutDatagrams COUNTER op_udp GET) +# (5 udpTable +# (1 udpEntry : IPADDRESS INTEGER op_udptable +# (1 udpLocalAddress IPADDRESS GET) +# (2 udpLocalPort INTEGER GET) +# )) +# ) (31 ifMIB (1 ifMIBObjects (1 ifXTable @@ -201,10 +201,8 @@ ) (48 ipMIB ) - (49 tcpMIB - ) - (50 udpMIB - ) +# (50 udpMIB +# ) )) (6 snmpV2 (3 snmpModules ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_mibII/Makefile#3 (text+ko) ==== @@ -8,8 +8,8 @@ MOD= mibII SRCS= mibII.c mibII_ifmib.c mibII_ip.c mibII_interfaces.c \ mibII_ipaddr.c mibII_ifstack.c mibII_rcvaddr.c \ - mibII_nettomedia.c mibII_udp.c mibII_route.c -XSYM= ipAddrTable ifTable ifRcvAddressEntry ifMIB ipMIB udpMIB \ + mibII_nettomedia.c mibII_route.c +XSYM= ipAddrTable ifTable ifRcvAddressEntry ifMIB ipMIB \ ipForward ifIndex linkDown linkUp MAN= snmp_mibII.3 ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp_udp46/Makefile#3 (text+ko) ==== @@ -30,17 +30,19 @@ MOD= tcp_udp46 -SRCS= tcp46_snmp.c +SRCS= tcp_udp46_common.c \ + tcp46_snmp.c \ + udp46_snmp.c WARNS?= 6 #Not having NDEBUG defined will enable assertions and a lot of output on stderr CFLAGS+= -DNDEBUG -XSYM= tcpMIB +XSYM= tcpMIB udpMIB DEFS= ${MOD}_tree.def -BMIBS= TCP-MIB.txt INET-ADDRESS-MIB.txt +BMIBS= TCP-MIB.txt UDP-MIB.txt INET-ADDRESS-MIB.txt .include <bsd.lib.mk> ==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp_udp46/tcp46_snmp.c#3 (text+ko) ==== @@ -85,9 +85,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "asn1.h" -#include "snmp.h" -#include "snmpmod.h" +#include "tcp_udp46.h" #include "tcp_udp46_oid.h" #include "tcp_udp46_tree.h" #include <stdio.h> @@ -101,7 +99,6 @@ #include <netinet/in.h> #include <sys/socket.h> #include <arpa/inet.h> - #include <string.h> #include <stdlib.h> #include <assert.h> @@ -109,34 +106,10 @@ #include <sys/sysctl.h> #include <sys/file.h> -/*forward declaration*/ -static int -fetch_tcp(void); -/*a debug macro*/ -#ifndef NDEBUG -#define TCP46_DPRINTF(ARGS) do { \ - fprintf(stderr, "TCP46_DEBUG: "); \ - fprintf ARGS; \ - } while (0) -#else -#define TCP46_DPRINTF(ARGS) -#endif /*NDEBUG*/ - -/*internal id got after we'll register this module with the agent */ -static -u_int tcp46_registration_id = 0; - -/* this our tcp46 module */ -static -struct lmodule *tcp46_module; - -static -const struct asn_oid oid_tcp46 = OIDX_tcpMIB; /*see the generated file tcp46_oid.h*/ - enum TCP_ConnState { TCPS_closed = 1, TCPS_listen = 2, @@ -162,11 +135,6 @@ }; -struct tcp_index { - struct asn_oid index; - struct xtcpcb *tp; - pid_t so_pgid; -}; static int tcp_compare(const void *p1, const void *p2) @@ -188,192 +156,14 @@ } -struct tcp46_state { - struct clockinfo clock_info; - uint64_t tcp_tick; /*agent tick when this struct was last updated*/ - struct tcpstat tcpstat; /*holder for tcp stats*/ - struct xinpgen *xinpgen; /*holder for data get via sysctl; malloc'd*/ - size_t xinpgen_len; /*the allocated len of the above vector */ - u_int tcp_estab_count; /*value for the scalar named tcpCurrEstab*/ - u_int tcp4_total; /*the number of tcp4 entries*/ - u_int all_tcp_total; /*the number of tcp4 and tcp6 entries (without listeners)*/ - u_int listen_tcp_total; /*the number of tcp4 and tcp6 entries in listen state*/ - - struct tcp_index *tcp4oids; /*snmp vector for the tcp4 table; malloc'd*/ - size_t tcp4oids_len; /*the allocated len of the above vector */ - - struct tcp_index *all_tcpoids; /*snmp vector for the unified v4 and v6 tcp table; malloc'd*/ - size_t all_tcpoids_len; /*the allocated len of the above vector */ - - 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; - - -}; - -/* - * Global variable used to hold all the data - * related to this SNMP module - */ static -struct tcp46_state tcp46_state_g; - - - -/* - * TCP mib module initialization hook. - * Returns 0 on success, < 0 on error - */ -static -int tcp46_init(struct lmodule * mod, int argc __unused, char *argv[] __unused) { - tcp46_module = mod; - int len = 0; - memset(&tcp46_state_g, 0, sizeof(struct tcp46_state)); - - len = sizeof(tcp46_state_g.clock_info); - if (sysctlbyname("kern.clockrate", &tcp46_state_g.clock_info, &len, NULL, 0) == -1) { - syslog(LOG_ERR, "kern.clockrate: %m"); - return (-1); - } - if (len != sizeof(tcp46_state_g.clock_info)) { - syslog(LOG_ERR, "kern.clockrate: wrong size"); - return (-1); - } - TCP46_DPRINTF((stderr, "[%s] done.\n", __func__)); - return (0); -} - -/* - * TCP mib module finalization hook. - * Returns 0 on success, < 0 on error - */ -static -int tcp46_fini(void) { - if (tcp46_state_g.tcp4oids != NULL && tcp46_state_g.tcp4oids_len > 0) { - free(tcp46_state_g.tcp4oids); - tcp46_state_g.tcp4oids = NULL; - tcp46_state_g.tcp4oids_len = 0; - } - - if (tcp46_state_g.all_tcpoids != NULL && tcp46_state_g.all_tcpoids_len > 0) { - free(tcp46_state_g.all_tcpoids); - tcp46_state_g.all_tcpoids = NULL; - tcp46_state_g.all_tcpoids_len = 0; - } - - if (tcp46_state_g.listen_tcpoids != NULL && tcp46_state_g.listen_tcpoids_len > 0) { - free(tcp46_state_g.listen_tcpoids); - tcp46_state_g.listen_tcpoids = NULL; - tcp46_state_g.listen_tcpoids_len = 0; - } - - if (tcp46_state_g.xinpgen != NULL && tcp46_state_g.xinpgen_len > 0) { - free(tcp46_state_g.xinpgen); - tcp46_state_g.xinpgen = NULL; - 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); - } - - - TCP46_DPRINTF((stderr, "[%s] done.\n", __func__)); - return (0); - -} - -/* - * TCP mib module dump function - * returns nothing - */ -static -void tcp46_dump_v(void) { - /*nothing iteresting here for the time being*/ - TCP46_DPRINTF((stderr, "[%s] done.\n ", __func__)); -} - -/* - * TCP mib module reconfiguration function - * returns nothing -*/ -static -void tcp46_config_v(void) { - /*nothing iteresting here for the time being*/ - TCP46_DPRINTF((stderr, "[%s] done.\n ", __func__)); -} - - - -static -void tcp46_loading_v(const struct lmodule *mod __unused, int loaded) -{ - /*nothing iteresting here for the time being*/ - if ( loaded == 1 ) { - goto LABEL_RETURN; - } -LABEL_RETURN:; - TCP46_DPRINTF((stderr,"[%s] done.\n ", __func__)); - -} - -/* - * TCP mib module start operation - * returns nothing - */ -static -void tcp46_start_v(void) { - tcp46_registration_id = or_register(&oid_tcp46, - "The MIB module for TCP (rfc 4022).", - tcp46_module); - if (tcp46_registration_id == 0) { - syslog(LOG_ERR, "Failed to register the tcp46 module." ); - return; - } - if (fetch_tcp() == -1) { - syslog(LOG_ERR, "Failed to fetch the TCP data in tcp46 module." ); - } - - TCP46_DPRINTF((stderr, "[%s] done.\n ", __func__)); -} - -/* - * This identifies the TCP mib module - * inside the agent - */ -const struct snmp_module config = { - "This module implements the TCP_MIB (rfc 4022)", - tcp46_init, - tcp46_fini, - NULL, /*idle function, do not use it*/ - tcp46_dump_v, - tcp46_config_v, - tcp46_start_v, - NULL, /* proxy a PDU */ - tcp_udp46_ctree, /* see the generated tcp46_tree.h */ - tcp_udp46_CTREE_SIZE, /* see the generated tcp46_tree.h */ - 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) { + for (xf = tcp_udp46_state_g.xfiles, n = 0; n < tcp_udp46_state_g.xfiles_total; ++n, ++xf) { if (xf->xf_data == NULL) { continue; } @@ -482,7 +272,7 @@ static uint32_t zero_ip6[] ={ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - if (tcp46_state_g.listen_tcpoids_len == 0) { + if (tcp_udp46_state_g.listen_tcpoids_len == 0) { /*empty list, no duplicates*/ return 0; } @@ -496,8 +286,8 @@ ntohs(tp->xt_inp.inp_lport))); - for (_oid = tcp46_state_g.listen_tcpoids; - _oid != listener_oid && i < tcp46_state_g.listen_tcpoids_len; + for (_oid = tcp_udp46_state_g.listen_tcpoids; + _oid != listener_oid && i < tcp_udp46_state_g.listen_tcpoids_len; i++, _oid++ ) { if ( _oid->index.subs[0] == IAT_ipv6 ) { @@ -535,7 +325,7 @@ static uint32_t zero_ip4[] = { 0, 0, 0, 0 }; - if (tcp46_state_g.listen_tcpoids_len == 0) { + if (tcp_udp46_state_g.listen_tcpoids_len == 0) { /*empty list, no duplicates*/ return 0; } @@ -548,8 +338,8 @@ __func__, ntohs(tp->xt_inp.in6p_lport))); - for (_oid = tcp46_state_g.listen_tcpoids; - _oid != listener_oid && i < tcp46_state_g.listen_tcpoids_len; + for (_oid = tcp_udp46_state_g.listen_tcpoids; + _oid != listener_oid && i < tcp_udp46_state_g.listen_tcpoids_len; i++, _oid++ ) { if ( _oid->index.subs[0] == IAT_ipv4 ) { @@ -651,39 +441,39 @@ } -static int +int fetch_xfiles(void) { size_t xfilesize = 0; struct xfile *ptr = NULL; - tcp46_state_g.xfiles_total = 0; + tcp_udp46_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) { + if (xfilesize > tcp_udp46_state_g.xfiles_len) { + if ((ptr = realloc(tcp_udp46_state_g.xfiles, xfilesize)) == NULL) { syslog(LOG_ERR, "%zu: %m", xfilesize); return (-1); } - tcp46_state_g.xfiles = ptr; - tcp46_state_g.xfiles_len = xfilesize; + tcp_udp46_state_g.xfiles = ptr; + tcp_udp46_state_g.xfiles_len = xfilesize; } - if (sysctlbyname("kern.file", tcp46_state_g.xfiles, &xfilesize, NULL, 0) < 0) { + if (sysctlbyname("kern.file", tcp_udp46_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); + tcp_udp46_state_g.xfiles_total = xfilesize / sizeof(struct xfile); return 0; } -static int +int fetch_tcp(void) { size_t len; @@ -692,12 +482,12 @@ struct tcp_index *oid = NULL, *all_oid = NULL, *listen_oid = NULL; - len = sizeof(tcp46_state_g.tcpstat); - if (sysctlbyname("net.inet.tcp.stats", &tcp46_state_g.tcpstat, &len, NULL, 0) == -1) { + len = sizeof(tcp_udp46_state_g.tcpstat); + if (sysctlbyname("net.inet.tcp.stats", &tcp_udp46_state_g.tcpstat, &len, NULL, 0) == -1) { syslog(LOG_ERR, "sysctlbyname(net.inet.tcp.stats) failed: %m"); return (-1); } - if (len != sizeof(tcp46_state_g.tcpstat)) { + if (len != sizeof(tcp_udp46_state_g.tcpstat)) { syslog(LOG_ERR, "sysctlbyname(net.inet.tcp.stats) error: wrong size"); return (-1); } @@ -707,32 +497,32 @@ syslog(LOG_ERR, "sysctlbyname(net.inet.tcp.pcblist) failed: %m"); return (-1); } - if (len > tcp46_state_g.xinpgen_len) { - if ((ptr = realloc(tcp46_state_g.xinpgen, len)) == NULL) { + if (len > tcp_udp46_state_g.xinpgen_len) { + if ((ptr = realloc(tcp_udp46_state_g.xinpgen, len)) == NULL) { syslog(LOG_ERR, "%zu: %m", len); return (-1); } - tcp46_state_g.xinpgen = ptr; - tcp46_state_g.xinpgen_len = len; + tcp_udp46_state_g.xinpgen = ptr; + tcp_udp46_state_g.xinpgen_len = len; } - if (sysctlbyname("net.inet.tcp.pcblist", tcp46_state_g.xinpgen, &len, NULL, 0) == -1) { + if (sysctlbyname("net.inet.tcp.pcblist", tcp_udp46_state_g.xinpgen, &len, NULL, 0) == -1) { syslog(LOG_ERR, "sysctlbyname(net.inet.tcp.pcblist) failed: %m"); return (-1); } - tcp46_state_g.tcp_tick = get_ticks(); + tcp_udp46_state_g.tcp_tick = get_ticks(); - tcp46_state_g.tcp_estab_count = 0; - tcp46_state_g.tcp4_total = 0; - tcp46_state_g.all_tcp_total = 0; - tcp46_state_g.listen_tcp_total = 0; + tcp_udp46_state_g.tcp_estab_count = 0; + tcp_udp46_state_g.tcp4_total = 0; + tcp_udp46_state_g.all_tcp_total = 0; + tcp_udp46_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); + for (ptr = (struct xinpgen *)(void *)((char *)tcp_udp46_state_g.xinpgen + tcp_udp46_state_g.xinpgen->xig_len); ptr->xig_len > sizeof(struct xinpgen); ptr = (struct xinpgen *)(void *)((char *)ptr + ptr->xig_len)) { tp = (struct xtcpcb *)ptr; @@ -749,7 +539,7 @@ } /* Ignore PCBs which were freed during copyout. */ - if (tp->xt_inp.inp_gencnt > tcp46_state_g.xinpgen->xig_gen ) { + if (tp->xt_inp.inp_gencnt > tcp_udp46_state_g.xinpgen->xig_gen ) { TCP46_DPRINTF((stderr, "[%s] One tcp4 conn. ignored (freed during copyout)\n ", __func__ )); @@ -759,84 +549,84 @@ if ( (tp->xt_inp.inp_vflag & INP_IPV4) == INP_IPV4) { - tcp46_state_g.tcp4_total++; + tcp_udp46_state_g.tcp4_total++; } if ((tp->xt_inp.inp_vflag & (INP_IPV6 | INP_IPV6PROTO | INP_IPV4)) != 0 ) { /*for connection in listen state we have a separate table*/ if ( tp->xt_tp.t_state != TCPS_LISTEN ) { - tcp46_state_g.all_tcp_total++; + tcp_udp46_state_g.all_tcp_total++; } else { - tcp46_state_g.listen_tcp_total++; + tcp_udp46_state_g.listen_tcp_total++; } } if (tp->xt_tp.t_state == TCPS_ESTABLISHED || tp->xt_tp.t_state == TCPS_CLOSE_WAIT) { - tcp46_state_g.tcp_estab_count++; + tcp_udp46_state_g.tcp_estab_count++; } } TCP46_DPRINTF((stderr, "[%s] Got %d tcp4 connections, %d tcp{4,6} connections, %d tcp{4,6} listeners.\n ", __func__, - tcp46_state_g.tcp4_total, - tcp46_state_g.all_tcp_total, - tcp46_state_g.listen_tcp_total)); + tcp_udp46_state_g.tcp4_total, + tcp_udp46_state_g.all_tcp_total, + tcp_udp46_state_g.listen_tcp_total)); /*Then reallocate the SNMP holder for v4 if needed*/ - if (tcp46_state_g.tcp4oids_len < tcp46_state_g.tcp4_total) { - oid = realloc(tcp46_state_g.tcp4oids, - tcp46_state_g.tcp4_total * sizeof(tcp46_state_g.tcp4oids[0])); + if (tcp_udp46_state_g.tcp4oids_len < tcp_udp46_state_g.tcp4_total) { + oid = realloc(tcp_udp46_state_g.tcp4oids, + tcp_udp46_state_g.tcp4_total * sizeof(tcp_udp46_state_g.tcp4oids[0])); if (oid == NULL) { - free(tcp46_state_g.tcp4oids); - tcp46_state_g.tcp4oids_len = 0; + free(tcp_udp46_state_g.tcp4oids); + tcp_udp46_state_g.tcp4oids_len = 0; return (0); } - tcp46_state_g.tcp4oids = oid; - tcp46_state_g.tcp4oids_len = tcp46_state_g.tcp4_total; + tcp_udp46_state_g.tcp4oids = oid; + tcp_udp46_state_g.tcp4oids_len = tcp_udp46_state_g.tcp4_total; } /*Then reallocate the SNMP holder for v4 & v6 if needed*/ - if (tcp46_state_g.all_tcpoids_len < tcp46_state_g.all_tcp_total) { - all_oid = realloc(tcp46_state_g.all_tcpoids, - tcp46_state_g.all_tcp_total * sizeof(tcp46_state_g.all_tcpoids[0])); + if (tcp_udp46_state_g.all_tcpoids_len < tcp_udp46_state_g.all_tcp_total) { + all_oid = realloc(tcp_udp46_state_g.all_tcpoids, + tcp_udp46_state_g.all_tcp_total * sizeof(tcp_udp46_state_g.all_tcpoids[0])); if (all_oid == NULL) { - free(tcp46_state_g.all_tcpoids); - tcp46_state_g.all_tcpoids_len = 0; + free(tcp_udp46_state_g.all_tcpoids); + tcp_udp46_state_g.all_tcpoids_len = 0; return (0); } - tcp46_state_g.all_tcpoids = all_oid; - tcp46_state_g.all_tcpoids_len = tcp46_state_g.all_tcp_total; + tcp_udp46_state_g.all_tcpoids = all_oid; + tcp_udp46_state_g.all_tcpoids_len = tcp_udp46_state_g.all_tcp_total; } /*Then reallocate the SNMP holder for v4 & v6 listeners if needed*/ - if (tcp46_state_g.listen_tcpoids_len < tcp46_state_g.listen_tcp_total) { - listen_oid = realloc(tcp46_state_g.listen_tcpoids, - tcp46_state_g.listen_tcp_total * sizeof(tcp46_state_g.listen_tcpoids[0])); + if (tcp_udp46_state_g.listen_tcpoids_len < tcp_udp46_state_g.listen_tcp_total) { + listen_oid = realloc(tcp_udp46_state_g.listen_tcpoids, + tcp_udp46_state_g.listen_tcp_total * sizeof(tcp_udp46_state_g.listen_tcpoids[0])); if (listen_oid == NULL) { - free(tcp46_state_g.listen_tcpoids); - tcp46_state_g.listen_tcpoids_len = 0; + free(tcp_udp46_state_g.listen_tcpoids); + tcp_udp46_state_g.listen_tcpoids_len = 0; return (0); } - tcp46_state_g.listen_tcpoids = listen_oid; - tcp46_state_g.listen_tcpoids_len = tcp46_state_g.listen_tcp_total; + tcp_udp46_state_g.listen_tcpoids = listen_oid; + tcp_udp46_state_g.listen_tcpoids_len = tcp_udp46_state_g.listen_tcp_total; } /*Finally fill in the SNMP indexes*/ - memset(tcp46_state_g.tcp4oids, 0, - tcp46_state_g.tcp4_total * sizeof(tcp46_state_g.tcp4oids[0]) ); + memset(tcp_udp46_state_g.tcp4oids, 0, + tcp_udp46_state_g.tcp4_total * sizeof(tcp_udp46_state_g.tcp4oids[0]) ); - memset(tcp46_state_g.all_tcpoids, 0, - tcp46_state_g.all_tcp_total * sizeof(tcp46_state_g.all_tcpoids[0]) ); + memset(tcp_udp46_state_g.all_tcpoids, 0, + tcp_udp46_state_g.all_tcp_total * sizeof(tcp_udp46_state_g.all_tcpoids[0]) ); - memset(tcp46_state_g.listen_tcpoids, 0, - tcp46_state_g.listen_tcp_total * sizeof(tcp46_state_g.listen_tcpoids[0]) ); + memset(tcp_udp46_state_g.listen_tcpoids, 0, + tcp_udp46_state_g.listen_tcp_total * sizeof(tcp_udp46_state_g.listen_tcpoids[0]) ); - oid = tcp46_state_g.tcp4oids; - all_oid = tcp46_state_g.all_tcpoids; - listen_oid = tcp46_state_g.listen_tcpoids; + oid = tcp_udp46_state_g.tcp4oids; + all_oid = tcp_udp46_state_g.all_tcpoids; + listen_oid = tcp_udp46_state_g.listen_tcpoids; - for (ptr = (struct xinpgen *)(void *)((char *)tcp46_state_g.xinpgen + tcp46_state_g.xinpgen->xig_len); + for (ptr = (struct xinpgen *)(void *)((char *)tcp_udp46_state_g.xinpgen + tcp_udp46_state_g.xinpgen->xig_len); ptr->xig_len > sizeof(struct xinpgen); ptr = (struct xinpgen *)(void *)((char *)ptr + ptr->xig_len)) { tp = (struct xtcpcb *)ptr; @@ -847,7 +637,7 @@ } /* Ignore PCBs which were freed during copyout. */ - if (tp->xt_inp.inp_gencnt > tcp46_state_g.xinpgen->xig_gen ) { + if (tp->xt_inp.inp_gencnt > tcp_udp46_state_g.xinpgen->xig_gen ) { continue; } if ( (tp->xt_inp.inp_vflag & INP_IPV4) == INP_IPV4) { @@ -870,8 +660,8 @@ listen_oid++; } else { /*this was a duplicate one*/ - assert(tcp46_state_g.listen_tcp_total > 1); - tcp46_state_g.listen_tcp_total--; + assert(tcp_udp46_state_g.listen_tcp_total > 1); + tcp_udp46_state_g.listen_tcp_total--; } } @@ -890,8 +680,8 @@ listen_oid++; } else { /*this was a duplicate one*/ - assert(tcp46_state_g.listen_tcp_total > 1); - tcp46_state_g.listen_tcp_total--; + assert(tcp_udp46_state_g.listen_tcp_total > 1); + tcp_udp46_state_g.listen_tcp_total--; } } @@ -901,23 +691,23 @@ TCP46_DPRINTF((stderr, "[%s] Got %d tcp{4,6} DISTINCT listeners.\n ", __func__, - tcp46_state_g.listen_tcp_total)); + tcp_udp46_state_g.listen_tcp_total)); /*Keep the lists sorted ins SNMP index ordering*/ - qsort( tcp46_state_g.tcp4oids, - tcp46_state_g.tcp4_total, - sizeof(tcp46_state_g.tcp4oids[0]), + qsort( tcp_udp46_state_g.tcp4oids, + tcp_udp46_state_g.tcp4_total, + sizeof(tcp_udp46_state_g.tcp4oids[0]), tcp_compare); - qsort( tcp46_state_g.all_tcpoids, - tcp46_state_g.all_tcp_total, - sizeof(tcp46_state_g.all_tcpoids[0]), + qsort( tcp_udp46_state_g.all_tcpoids, + tcp_udp46_state_g.all_tcp_total, + sizeof(tcp_udp46_state_g.all_tcpoids[0]), tcp_compare); - qsort( tcp46_state_g.listen_tcpoids, - tcp46_state_g.listen_tcp_total, - sizeof(tcp46_state_g.listen_tcpoids[0]), + qsort( tcp_udp46_state_g.listen_tcpoids, + tcp_udp46_state_g.listen_tcp_total, + sizeof(tcp_udp46_state_g.listen_tcpoids[0]), tcp_compare); @@ -1166,7 +956,7 @@ } } - if (tcp46_state_g.tcp_tick < this_tick) + if (tcp_udp46_state_g.tcp_tick < this_tick) if (fetch_tcp() == -1) return (SNMP_ERR_GENERR); @@ -1176,7 +966,7 @@ value->v.integer = 4; /* Van Jacobson */ break; -#define hz (tcp46_state_g.clock_info.hz) +#define hz (tcp_udp46_state_g.clock_info.hz) case LEAF_tcpRtoMin: value->v.integer = 1000 * TCPTV_MIN / hz; @@ -1191,42 +981,42 @@ break; case LEAF_tcpActiveOpens: - value->v.uint32 = tcp46_state_g.tcpstat.tcps_connattempt; + value->v.uint32 = tcp_udp46_state_g.tcpstat.tcps_connattempt; break; case LEAF_tcpPassiveOpens: - value->v.uint32 = tcp46_state_g.tcpstat.tcps_accepts; + value->v.uint32 = tcp_udp46_state_g.tcpstat.tcps_accepts; break; case LEAF_tcpAttemptFails: - value->v.uint32 = tcp46_state_g.tcpstat.tcps_conndrops; + value->v.uint32 = tcp_udp46_state_g.tcpstat.tcps_conndrops; break; case LEAF_tcpEstabResets: - value->v.uint32 = tcp46_state_g.tcpstat.tcps_drops; + value->v.uint32 = tcp_udp46_state_g.tcpstat.tcps_drops; break; case LEAF_tcpCurrEstab: - value->v.uint32 = tcp46_state_g.tcp_estab_count; + value->v.uint32 = tcp_udp46_state_g.tcp_estab_count; break; case LEAF_tcpInSegs: - value->v.uint32 = tcp46_state_g.tcpstat.tcps_rcvtotal; + value->v.uint32 = tcp_udp46_state_g.tcpstat.tcps_rcvtotal; break; case LEAF_tcpOutSegs: - value->v.uint32 = tcp46_state_g.tcpstat.tcps_sndtotal - - tcp46_state_g.tcpstat.tcps_sndrexmitpack; + value->v.uint32 = tcp_udp46_state_g.tcpstat.tcps_sndtotal - + tcp_udp46_state_g.tcpstat.tcps_sndrexmitpack; break; case LEAF_tcpRetransSegs: - value->v.uint32 = tcp46_state_g.tcpstat.tcps_sndrexmitpack; + value->v.uint32 = tcp_udp46_state_g.tcpstat.tcps_sndrexmitpack; break; case LEAF_tcpInErrs: - value->v.uint32 = tcp46_state_g.tcpstat.tcps_rcvbadsum + - tcp46_state_g.tcpstat.tcps_rcvbadoff + - tcp46_state_g.tcpstat.tcps_rcvshort; + value->v.uint32 = tcp_udp46_state_g.tcpstat.tcps_rcvbadsum + + tcp_udp46_state_g.tcpstat.tcps_rcvbadoff + + tcp_udp46_state_g.tcpstat.tcps_rcvshort; break; case LEAF_tcpOutRsts: @@ -1234,12 +1024,12 @@ break; case LEAF_tcpHCInSegs: - value->v.counter64 = tcp46_state_g.tcpstat.tcps_rcvtotal; + value->v.counter64 = tcp_udp46_state_g.tcpstat.tcps_rcvtotal; break; case LEAF_tcpHCOutSegs: - value->v.counter64 = tcp46_state_g.tcpstat.tcps_sndtotal - - tcp46_state_g.tcpstat.tcps_sndrexmitpack; + value->v.counter64 = tcp_udp46_state_g.tcpstat.tcps_sndtotal - + tcp_udp46_state_g.tcpstat.tcps_sndrexmitpack; break; default : @@ -1260,26 +1050,26 @@ { u_int i; - if (tcp46_state_g.tcp_tick < this_tick) + if (tcp_udp46_state_g.tcp_tick < this_tick) if (fetch_tcp() == -1) return (SNMP_ERR_GENERR); switch (op) { case SNMP_OP_GETNEXT: - for (i = 0; i < tcp46_state_g.tcp4_total; i++) - if (index_compare(&value->var, sub, &tcp46_state_g.tcp4oids[i].index) < 0) + for (i = 0; i < tcp_udp46_state_g.tcp4_total; i++) + if (index_compare(&value->var, sub, &tcp_udp46_state_g.tcp4oids[i].index) < 0) break; - if (i == tcp46_state_g.tcp4_total) + if (i == tcp_udp46_state_g.tcp4_total) return (SNMP_ERR_NOSUCHNAME); - index_append(&value->var, sub, &tcp46_state_g.tcp4oids[i].index); + index_append(&value->var, sub, &tcp_udp46_state_g.tcp4oids[i].index); break; case SNMP_OP_GET: - for (i = 0; i < tcp46_state_g.tcp4_total; i++) - if (index_compare(&value->var, sub, &tcp46_state_g.tcp4oids[i].index) == 0) + for (i = 0; i < tcp_udp46_state_g.tcp4_total; i++) + if (index_compare(&value->var, sub, &tcp_udp46_state_g.tcp4oids[i].index) == 0) break; - if (i == tcp46_state_g.tcp4_total) + if (i == tcp_udp46_state_g.tcp4_total) return (SNMP_ERR_NOSUCHNAME); break; @@ -1291,15 +1081,15 @@ return (SNMP_ERR_WRONG_VALUE); } - for (i = 0; i < tcp46_state_g.tcp4_total; i++) + for (i = 0; i < tcp_udp46_state_g.tcp4_total; i++) if (index_compare(&value->var, sub, - &tcp46_state_g.tcp4oids[i].index) == 0) + &tcp_udp46_state_g.tcp4oids[i].index) == 0) break; - if (i == tcp46_state_g.tcp4_total) + if (i == tcp_udp46_state_g.tcp4_total) return (SNMP_ERR_NOSUCHNAME); - if (drop_tcp_conn(&tcp46_state_g.tcp4oids[i].index, 1) != 0) { + if (drop_tcp_conn(&tcp_udp46_state_g.tcp4oids[i].index, 1) != 0) { return (SNMP_ERR_NOSUCHNAME); } return (SNMP_ERR_NOERROR); @@ -1317,7 +1107,7 @@ switch (value->var.subs[sub - 1]) { case LEAF_tcpConnState: - switch (tcp46_state_g.tcp4oids[i].tp->xt_tp.t_state) { + switch (tcp_udp46_state_g.tcp4oids[i].tp->xt_tp.t_state) { case TCPS_CLOSED: value->v.integer = TCPS_closed; @@ -1358,28 +1148,28 @@ } break; - assert(tcp46_state_g.tcp4oids[i].index.len == 10); + assert(tcp_udp46_state_g.tcp4oids[i].index.len == 10); case LEAF_tcpConnLocalAddress: - value->v.ipaddress[0] = tcp46_state_g.tcp4oids[i].index.subs[0]; - value->v.ipaddress[1] = tcp46_state_g.tcp4oids[i].index.subs[1]; - value->v.ipaddress[2] = tcp46_state_g.tcp4oids[i].index.subs[2]; - value->v.ipaddress[3] = tcp46_state_g.tcp4oids[i].index.subs[3]; + value->v.ipaddress[0] = tcp_udp46_state_g.tcp4oids[i].index.subs[0]; + value->v.ipaddress[1] = tcp_udp46_state_g.tcp4oids[i].index.subs[1]; + value->v.ipaddress[2] = tcp_udp46_state_g.tcp4oids[i].index.subs[2]; + value->v.ipaddress[3] = tcp_udp46_state_g.tcp4oids[i].index.subs[3]; break; case LEAF_tcpConnLocalPort: - value->v.integer = tcp46_state_g.tcp4oids[i].index.subs[4]; + value->v.integer = tcp_udp46_state_g.tcp4oids[i].index.subs[4]; break; case LEAF_tcpConnRemAddress: - value->v.ipaddress[0] = tcp46_state_g.tcp4oids[i].index.subs[5]; - value->v.ipaddress[1] = tcp46_state_g.tcp4oids[i].index.subs[6]; - value->v.ipaddress[2] = tcp46_state_g.tcp4oids[i].index.subs[7]; - value->v.ipaddress[3] = tcp46_state_g.tcp4oids[i].index.subs[8]; + value->v.ipaddress[0] = tcp_udp46_state_g.tcp4oids[i].index.subs[5]; + value->v.ipaddress[1] = tcp_udp46_state_g.tcp4oids[i].index.subs[6]; + value->v.ipaddress[2] = tcp_udp46_state_g.tcp4oids[i].index.subs[7]; + value->v.ipaddress[3] = tcp_udp46_state_g.tcp4oids[i].index.subs[8]; break; case LEAF_tcpConnRemPort: - value->v.integer = tcp46_state_g.tcp4oids[i].index.subs[9]; + value->v.integer = tcp_udp46_state_g.tcp4oids[i].index.subs[9]; break; } return (SNMP_ERR_NOERROR); @@ -1395,31 +1185,31 @@ { u_int i; - if (tcp46_state_g.tcp_tick < this_tick) + if (tcp_udp46_state_g.tcp_tick < this_tick) if (fetch_tcp() == -1) return (SNMP_ERR_GENERR); switch (op) { case SNMP_OP_GETNEXT: - for (i = 0; i < tcp46_state_g.all_tcp_total; i++) + for (i = 0; i < tcp_udp46_state_g.all_tcp_total; i++) if (index_compare(&value->var, sub, - &tcp46_state_g.all_tcpoids[i].index) < 0) + &tcp_udp46_state_g.all_tcpoids[i].index) < 0) break; - if (i == tcp46_state_g.all_tcp_total) + if (i == tcp_udp46_state_g.all_tcp_total) return (SNMP_ERR_NOSUCHNAME); index_append(&value->var, sub, - &tcp46_state_g.all_tcpoids[i].index); + &tcp_udp46_state_g.all_tcpoids[i].index); break; case SNMP_OP_GET: - for (i = 0; i < tcp46_state_g.all_tcp_total; i++) + for (i = 0; i < tcp_udp46_state_g.all_tcp_total; i++) if (index_compare(&value->var, sub, - &tcp46_state_g.all_tcpoids[i].index) == 0) + &tcp_udp46_state_g.all_tcpoids[i].index) == 0) break; - if (i == tcp46_state_g.all_tcp_total) + if (i == tcp_udp46_state_g.all_tcp_total) return (SNMP_ERR_NOSUCHNAME); break; @@ -1431,15 +1221,15 @@ return (SNMP_ERR_WRONG_VALUE); } - for (i = 0; i < tcp46_state_g.all_tcp_total; i++) + for (i = 0; i < tcp_udp46_state_g.all_tcp_total; i++) >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200508281717.j7SHHn5k027246>