PERFORCE change 82615 for review
Victor Cruceru
soc-victor at FreeBSD.org
Fri Aug 26 13:42:16 GMT 2005
http://perforce.freebsd.org/chv.cgi?CH=82615
Change 82615 by soc-victor at soc-victor_82.76.158.176 on 2005/08/26 13:41:51
Finished the SNMP implementation for RFC 4022 (TCP-MIB) by
adding SNMP SET support for the deprecated tcpConnTable.
Also removed the old implementation for the deprecated RFC1213-MIB
Affected files ...
.. //depot/projects/soc2005/bsnmp/contrib/bsnmp/snmp_mibII/mibII.c#4 edit
.. //depot/projects/soc2005/bsnmp/contrib/bsnmp/snmp_mibII/mibII_tcp.c#2 delete
.. //depot/projects/soc2005/bsnmp/contrib/bsnmp/snmp_mibII/mibII_tree.def#3 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp46/Makefile#5 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp46/tcp46_snmp.c#7 edit
Differences ...
==== //depot/projects/soc2005/bsnmp/contrib/bsnmp/snmp_mibII/mibII.c#4 (text+ko) ====
@@ -57,9 +57,7 @@
/* OR registrations */
static u_int ifmib_reg;
static u_int ipmib_reg;
-#if 0
-static u_int tcpmib_reg;
-#endif /*0*/
+
static u_int udpmib_reg;
static u_int ipForward_reg;
@@ -114,9 +112,6 @@
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_tcpMIB = OIDX_tcpMIB;
-#endif /*0*/
static const struct asn_oid oid_udpMIB = OIDX_udpMIB;
static const struct asn_oid oid_ipForward = OIDX_ipForward;
static const struct asn_oid oid_linkDown = OIDX_linkDown;
@@ -1445,10 +1440,7 @@
ipmib_reg = or_register(&oid_ipMIB,
"The MIB module for managing IP and ICMP implementations, but "
"excluding their management of IP routes.", module);
-#if 0
- tcpmib_reg = or_register(&oid_tcpMIB,
- "The MIB module for managing TCP implementations.", module);
-#endif /*0*/
+
udpmib_reg = or_register(&oid_udpMIB,
"The MIB module for managing UDP implementations.", module);
@@ -1510,9 +1502,7 @@
or_unregister(ipForward_reg);
or_unregister(udpmib_reg);
-#if 0
- or_unregister(tcpmib_reg);
-#endif /*0*/
+
or_unregister(ipmib_reg);
or_unregister(ifmib_reg);
==== //depot/projects/soc2005/bsnmp/contrib/bsnmp/snmp_mibII/mibII_tree.def#3 (text+ko) ====
@@ -148,30 +148,6 @@
(25 icmpOutAddrMasks COUNTER op_icmpstat GET)
(26 icmpOutAddrMaskReps COUNTER op_icmpstat GET)
)
-# (6 tcp
-# (1 tcpRtoAlgorithm INTEGER op_tcp GET)
-# (2 tcpRtoMin INTEGER32 op_tcp GET)
-# (3 tcpRtoMax INTEGER32 op_tcp GET)
-# (4 tcpMaxConn INTEGER32 op_tcp GET)
-# (5 tcpActiveOpens COUNTER op_tcp GET)
-# (6 tcpPassiveOpens COUNTER op_tcp GET)
-# (7 tcpAttemptFails COUNTER op_tcp GET)
-# (8 tcpEstabResets COUNTER op_tcp GET)
-# (9 tcpCurrEstab GAUGE op_tcp GET)
-# (10 tcpInSegs COUNTER op_tcp GET)
-# (11 tcpOutSegs COUNTER op_tcp GET)
-# (12 tcpRetransSegs COUNTER op_tcp GET)
-# (13 tcpConnTable
-# (1 tcpConnEntry : IPADDRESS INTEGER IPADDRESS INTEGER op_tcpconn
-# (1 tcpConnState INTEGER GET)
-# (2 tcpConnLocalAddress IPADDRESS GET)
-# (3 tcpConnLocalPort INTEGER GET)
-# (4 tcpConnRemAddress IPADDRESS GET)
-# (5 tcpConnRemPort INTEGER GET)
-# ))
-# (14 tcpInErrs COUNTER op_tcp GET)
-# (15 tcpOutRsts COUNTER op_tcp) # don't know
-# )
(7 udp
(1 udpInDatagrams COUNTER op_udp GET)
(2 udpNoPorts COUNTER op_udp GET)
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp46/Makefile#5 (text+ko) ====
@@ -40,6 +40,7 @@
XSYM= tcpMIB
DEFS= ${MOD}_tree.def
+
BMIBS= TCP-MIB.txt INET-ADDRESS-MIB.txt
.include <bsd.lib.mk>
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp46/tcp46_snmp.c#7 (text+ko) ====
@@ -65,6 +65,25 @@
*
* tcp
*/
+ /*
+ * The code for tcp delete operation was inspired by the code developed by
+ * Markus Friedl under the following copyright:
+ */
+ /*-
+ * Copyright (c) 2004 Markus Friedl <markus at openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
#include "asn1.h"
#include "snmp.h"
@@ -831,132 +850,204 @@
return (0);
}
+/*
+ * Delete a tcp connection identified by the conn parameter (snmp
+ * index encoded format). If the _deprecated parameter is 1, then
+ * the encoding is specified as in the index of the deprecated
+ * tcpConnTable (v4 only)
+ * Returns 0 for success, <0 if the deletion failed
+ */
static
-int drop_new_tcp_conn(struct asn_oid *conn){
+int drop_tcp_conn(struct asn_oid *conn, int _deprecated){
struct sockaddr_storage addrs[2];
int mib[] = { CTL_NET, PF_INET, IPPROTO_TCP, TCPCTL_DROP };
char local[64] = "", remote[64] = "";
- assert(conn != NULL);
+ assert(conn != NULL);
memset (&addrs[0], 0, sizeof(addrs));
- if (conn->subs[0] == IAT_ipv4) {
- struct sockaddr_in *sinl, *sinr;
+
+ if (_deprecated == 0 ){
+
+ if (conn->subs[0] == IAT_ipv4) {
+ struct sockaddr_in *sinl, *sinr;
- assert(conn->len == 12);
- if (conn->len != 12) {
- syslog(LOG_ERR, "%s: malformed SNMP index (wrong length) when deleting a connection",
- __func__);
- return -1;
- }
+ assert(conn->len == 12);
+ if (conn->len != 12) {
+ syslog(LOG_ERR,
+ "%s: malformed SNMP index (wrong length) when deleting a connection",
+ __func__);
+ return -1;
+ }
- if (conn->subs[6] != IAT_ipv4 ) {
- syslog(LOG_ERR, "%s: malformed SNMP index (remote not a v4) when deleting a connection",
- __func__);
- return -1;
- }
+ if (conn->subs[6] != IAT_ipv4 ) {
+ syslog(LOG_ERR,
+ "%s: malformed SNMP index (remote not a v4) when deleting a connection",
+ __func__);
+ return -1;
+ }
- memset(&addrs[1], 0, sizeof(addrs[1]));
- sinl = (struct sockaddr_in *)&addrs[1];
- sinl->sin_len = sizeof(struct sockaddr_in);
- sinl->sin_addr.s_addr = htonl(
- (conn->subs[1] << 24) |
- (conn->subs[2] << 16) |
- (conn->subs[3] << 8) |
- (conn->subs[4] << 0)
- );
- sinl->sin_port = htons(conn->subs[5]);
- addrs[1].ss_family = AF_INET;
+ memset(&addrs[1], 0, sizeof(addrs[1]));
+ sinl = (struct sockaddr_in *)&addrs[1];
+ sinl->sin_len = sizeof(struct sockaddr_in);
+ sinl->sin_addr.s_addr = htonl(
+ (conn->subs[1] << 24) |
+ (conn->subs[2] << 16) |
+ (conn->subs[3] << 8) |
+ (conn->subs[4] << 0)
+ );
+ sinl->sin_port = htons(conn->subs[5]);
+ addrs[1].ss_family = AF_INET;
- inet_ntop(AF_INET, &sinl->sin_addr, local, 64);
+ inet_ntop(AF_INET, &sinl->sin_addr, local, 64);
- memset(&addrs[0], 0, sizeof(addrs[0]));
- sinr = (struct sockaddr_in *)&addrs[0];
- sinr->sin_len = sizeof(struct sockaddr_in);
+ memset(&addrs[0], 0, sizeof(addrs[0]));
+ sinr = (struct sockaddr_in *)&addrs[0];
+ sinr->sin_len = sizeof(struct sockaddr_in);
- sinr->sin_addr.s_addr = htonl(
- (conn->subs[7] << 24) |
- (conn->subs[8] << 16) |
- (conn->subs[9] << 8) |
- (conn->subs[10] << 0)
- );
- sinr->sin_port = htons(conn->subs[11]);
- addrs[0].ss_family = AF_INET;
+ sinr->sin_addr.s_addr = htonl(
+ (conn->subs[7] << 24) |
+ (conn->subs[8] << 16) |
+ (conn->subs[9] << 8) |
+ (conn->subs[10] << 0)
+ );
+ sinr->sin_port = htons(conn->subs[11]);
+ addrs[0].ss_family = AF_INET;
- 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[5],
- remote,
- conn->subs[11]);
+ 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[5],
+ remote,
+ conn->subs[11]);
- } else if (conn->subs[0] == IAT_ipv6) {
- struct sockaddr_in6 *sin6l, *sin6r;
- int i = 0;
- assert(conn->len == 36);
- if (conn->len != 36) {
- syslog(LOG_ERR, "%s: malformed SNMP index (wrong length) when deleting a connection",
- __func__);
- return -1;
- }
+ } else if (conn->subs[0] == IAT_ipv6) {
+ struct sockaddr_in6 *sin6l, *sin6r;
+ int i = 0;
+ assert(conn->len == 36);
+ if (conn->len != 36) {
+ syslog(LOG_ERR,
+ "%s: malformed SNMP index (wrong length) when deleting a connection",
+ __func__);
+ return -1;
+ }
- if (conn->subs[18] != IAT_ipv6 ) {
- syslog(LOG_ERR, "%s: malformed SNMP index (remote not a v6) when deleting a connection",
- __func__);
- return -1;
- }
+ if (conn->subs[18] != IAT_ipv6 ) {
+ syslog(LOG_ERR,
+ "%s: malformed SNMP index (remote not a v6) when deleting a connection",
+ __func__);
+ return -1;
+ }
- memset(&addrs[1], 0, sizeof(addrs[1]));
- sin6l = (struct sockaddr_in6 *)&addrs[1];
+ memset(&addrs[1], 0, sizeof(addrs[1]));
+ sin6l = (struct sockaddr_in6 *)&addrs[1];
- for (i=0; i<16; i++) {
- sin6l->sin6_addr.s6_addr[i] = conn->subs[1+i];
- }
+ for (i=0; i<16; i++) {
+ sin6l->sin6_addr.s6_addr[i] = conn->subs[1+i];
+ }
- sin6l->sin6_port = htons(conn->subs[17]);
+ sin6l->sin6_port = htons(conn->subs[17]);
#ifdef SIN6_LEN
- sin6l->sin6_len = sizeof(struct sockaddr_in6);
+ 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);
+ addrs[1].ss_family = AF_INET6;
+ inet_ntop(AF_INET6, &sin6l->sin6_addr, local, 64);
- memset(&addrs[0], 0, sizeof(addrs[0]));
- sin6r = (struct sockaddr_in6 *)&addrs[0];
+ memset(&addrs[0], 0, sizeof(addrs[0]));
+ sin6r = (struct sockaddr_in6 *)&addrs[0];
- for (i=0; i<16; i++) {
- sin6r->sin6_addr.s6_addr[i] = conn->subs[19+i];
- }
+ for (i=0; i<16; i++) {
+ sin6r->sin6_addr.s6_addr[i] = conn->subs[19+i];
+ }
- sin6r->sin6_port = htons(conn->subs[35]);
+ sin6r->sin6_port = htons(conn->subs[35]);
#ifdef SIN6_LEN
- sin6r->sin6_len = sizeof(struct sockaddr_in6);
+ sin6r->sin6_len = sizeof(struct sockaddr_in6);
#endif /* SIN6_LEN */
- addrs[0].ss_family = AF_INET6;
+ addrs[0].ss_family = AF_INET6;
+
+ 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 ",
+ __func__,
+ local,
+ conn->subs[17],
+ remote,
+ conn->subs[35]);
+
- inet_ntop(AF_INET6, &sin6r->sin6_addr, remote, 64);
+ } else {
+ assert(0);
+ syslog(LOG_ERR, "%s: malformed SNMP index (not v4, not v6) when deleting a connection",
+ __func__);
+ return -1;
- syslog(LOG_INFO, "[%s] attempt to delete a tcp6 connection: local: %s:%d - remote: %s:%d \n ",
+ }
+ } else {
+ /*This the code for the old/ deprecated tcpConnTable*/
+ struct sockaddr_in *sinl, *sinr;
+
+ assert(conn->len == 10);
+ if (conn->len != 10) {
+ syslog(LOG_ERR,
+ "%s: malformed SNMP index (wrong length) when deleting a connection",
+ __func__);
+ return -1;
+ }
+
+
+
+
+ memset(&addrs[1], 0, sizeof(addrs[1]));
+ sinl = (struct sockaddr_in *)&addrs[1];
+ sinl->sin_len = sizeof(struct sockaddr_in);
+ sinl->sin_addr.s_addr = htonl(
+ (conn->subs[0] << 24) |
+ (conn->subs[1] << 16) |
+ (conn->subs[2] << 8) |
+ (conn->subs[3] << 0)
+ );
+ sinl->sin_port = htons(conn->subs[4]);
+ addrs[1].ss_family = AF_INET;
+
+ inet_ntop(AF_INET, &sinl->sin_addr, local, 64);
+
+
+
+ memset(&addrs[0], 0, sizeof(addrs[0]));
+ sinr = (struct sockaddr_in *)&addrs[0];
+ sinr->sin_len = sizeof(struct sockaddr_in);
+
+ sinr->sin_addr.s_addr = htonl(
+ (conn->subs[5] << 24) |
+ (conn->subs[6] << 16) |
+ (conn->subs[7] << 8) |
+ (conn->subs[8] << 0)
+ );
+ sinr->sin_port = htons(conn->subs[9]);
+ addrs[0].ss_family = AF_INET;
+
+ 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[17],
+ conn->subs[4],
remote,
- conn->subs[35]);
-
+ conn->subs[9]);
+
- } else {
- assert(0);
- syslog(LOG_ERR, "%s: malformed SNMP index (not v4, not v6) when deleting a connection",
- __func__);
- return -1;
-
}
+
if (sysctl(mib, sizeof (mib) / sizeof (int), NULL,
NULL, &addrs, sizeof(addrs)) == -1) {
syslog(LOG_ERR, "%s: failed to delete the specified tcp connection: %m", __func__);
@@ -1118,11 +1209,33 @@
return (SNMP_ERR_NOSUCHNAME);
break;
- case SNMP_OP_SET:
- return (SNMP_ERR_NOT_WRITEABLE);
+ case SNMP_OP_SET: {
+ if (value->var.subs[sub - 1] != LEAF_tcpConnState) {
+ return (SNMP_ERR_NOT_WRITEABLE);
+ }
+ if (value->v.integer != TCPS_deleteTCB) {
+ return (SNMP_ERR_WRONG_VALUE);
+ }
+
+ for (i = 0; i < tcp46_state_g.tcp4_total; i++)
+ if (index_compare(&value->var, sub,
+ &tcp46_state_g.tcp4oids[i].index) == 0)
+ break;
+
+ if (i == tcp46_state_g.tcp4_total)
+ return (SNMP_ERR_NOSUCHNAME);
+
+ if (drop_tcp_conn(&tcp46_state_g.tcp4oids[i].index, 1) != 0) {
+ return (SNMP_ERR_NOSUCHNAME);
+ }
+ return (SNMP_ERR_NOERROR);
+ }
+
case SNMP_OP_ROLLBACK:
- case SNMP_OP_COMMIT:
+ case SNMP_OP_COMMIT: {
+ return (SNMP_ERR_NOERROR);
+ }
default:
abort();
}
@@ -1252,7 +1365,7 @@
if (i == tcp46_state_g.all_tcp_total)
return (SNMP_ERR_NOSUCHNAME);
- if (drop_new_tcp_conn(&tcp46_state_g.all_tcpoids[i].index) != 0) {
+ if (drop_tcp_conn(&tcp46_state_g.all_tcpoids[i].index, 0) != 0) {
return (SNMP_ERR_NOSUCHNAME);
}
return (SNMP_ERR_NOERROR);
More information about the p4-projects
mailing list