changeset 775:7b1ce5baf938

Imported from trunk into 2.0 branch: * include/mibgroup/mibII/itf_helpers.h: * src/mibgroup/mibII/helpers.c: (New) Functions for finding the interface structure for Free and open BSD. * src/mibgroup/mibII/interfaces.c: Use the helper functions and other changes needed for the FreeBSD stack. * src/mibgroup/mibII/ip.c: Ditto * src/mibgroup/mibII/udp.c: Ditto * src/mibgroup/mibII/tcp.c: Ditto * src/mibgroup/mibII/dot3.c: Ditto * cdl/snmpagent.cdl: Removed the requirement for the OpenBSD stack. * doc/snmp.sgml: Removed the documented requirement for the OpenBSD stack.
author asl
date Tue, 25 Mar 2003 16:56:41 +0000
parents bd672be526a4
children 1c7cb34bec1b
files packages/net/snmp/agent/current/ChangeLog packages/net/snmp/agent/current/cdl/snmpagent.cdl packages/net/snmp/agent/current/doc/snmp.sgml packages/net/snmp/agent/current/src/mibgroup/mibII/dot3.c packages/net/snmp/agent/current/src/mibgroup/mibII/interfaces.c packages/net/snmp/agent/current/src/mibgroup/mibII/ip.c packages/net/snmp/agent/current/src/mibgroup/mibII/tcp.c packages/net/snmp/agent/current/src/mibgroup/mibII/udp.c packages/net/snmp/agent/current/src/snmptask.c
diffstat 9 files changed, 157 insertions(+), 132 deletions(-) [+]
line wrap: on
line diff
--- a/packages/net/snmp/agent/current/ChangeLog
+++ b/packages/net/snmp/agent/current/ChangeLog
@@ -1,3 +1,19 @@
+2003-03-25  Andrew Lunn  <andrew.lunn@ascom.ch>
+
+	Imported from trunk into 2.0 branch:
+        * include/mibgroup/mibII/itf_helpers.h:
+	* src/mibgroup/mibII/helpers.c: (New) Functions for finding the
+	interface structure for Free and open BSD.
+	* src/mibgroup/mibII/interfaces.c: Use the helper functions and
+	other changes needed for the FreeBSD stack.
+	* src/mibgroup/mibII/ip.c: Ditto
+	* src/mibgroup/mibII/udp.c: Ditto
+	* src/mibgroup/mibII/tcp.c: Ditto
+	* src/mibgroup/mibII/dot3.c: Ditto
+	* cdl/snmpagent.cdl: Removed the requirement for the OpenBSD stack.
+	* doc/snmp.sgml: Removed the documented requirement for the OpenBSD
+	stack.
+	
 2003-02-24  Jonathan Larmour  <jifl@eCosCentric.com>
 
 	* cdl/snmpagent.cdl: Add doc link.
--- a/packages/net/snmp/agent/current/cdl/snmpagent.cdl
+++ b/packages/net/snmp/agent/current/cdl/snmpagent.cdl
@@ -41,7 +41,7 @@
 ######DESCRIPTIONBEGIN####
 #
 # Author(s):      hmt
-# Original data:  hmt
+# Original data:  hmt, Andrew Lunn
 # Contributors:   gthomas
 # Date:           2000-05-30
 #
@@ -63,8 +63,6 @@ cdl_package CYGPKG_SNMPAGENT {
     requires      { 0 != CYGINT_ISO_ERRNO }
     requires      { 0 != CYGINT_ISO_ERRNO_CODES }
     requires      CYGPKG_NET
-# For now we only work with the OpenBSD stack, not FreeBSD
-    requires      CYGPKG_NET_OPENBSD_STACK
     requires      CYGPKG_SNMPLIB
     description   "SNMP agent based on the UCD-SNMP project."
 
@@ -78,6 +76,7 @@ cdl_package CYGPKG_SNMPAGENT {
 		snmp_vars.c			\
 		snmpd.c				\
                 snmptask.c			\
+		mibgroup/mibII/helpers.c        \
 		mibgroup/mibII/system_mib.c	\
 		mibgroup/mibII/sysORTable.c	\
 		mibgroup/mibII/snmp_mib.c	\
--- a/packages/net/snmp/agent/current/doc/snmp.sgml
+++ b/packages/net/snmp/agent/current/doc/snmp.sgml
@@ -244,23 +244,10 @@ again.
 <SECT1 id="net-snmp-configuring-ecos">
 <TITLE>Configuring eCos</TITLE>
 <PARA>
-To use the SNMP agent, the SNMP library and agent packages must
-be included in your configuration. In addition, at this point, the SNMP
-stack only works with the OpenBSD-based TCP/IP stack, not the FreeBSD-based
-stack. The "old_net" template can be used as a starting point for using
-the OpenBSD-based TCP/IP stack, for example:
-<SCREEN>
-$ <USERINPUT>ecosconfig new mytarget old_net</USERINPUT>
-</SCREEN>
-or you can add the various required packages to an existing configuration with:
-<SCREEN>
-$ <USERINPUT>ecosconfig add net openbsd_net eth_drivers</USERINPUT>
-</SCREEN>
-</PARA>
-<PARA>
-To incorporate the stack into your configuration select the SNMP library
-and SNMP agent packages in the eCos Configuration Tool, or at the command
-line type:
+To use the SNMP agent, the SNMP library and agent packages must be
+included in your configuration. To incorporate the stack into your
+configuration select the SNMP library and SNMP agent packages in the
+eCos Configuration Tool, or at the command line type:
 <SCREEN>
 $ <USERINPUT>ecosconfig add snmplib snmpagent</USERINPUT>
 </SCREEN>
--- a/packages/net/snmp/agent/current/src/mibgroup/mibII/dot3.c
+++ b/packages/net/snmp/agent/current/src/mibgroup/mibII/dot3.c
@@ -101,8 +101,13 @@ CONNECTION WITH THE USE OR PERFORMANCE O
 #include "mibincl.h"
 #include "mibgroup/util_funcs.h"
 #include "mibgroup/mibII/dot3.h"
+#include "mibgroup/mibII/ifr_helper.h"
 
 #include <net/if_types.h>
+#include <net/if.h>
+#ifdef CYGPKG_NET_FREEBSD_STACK
+#include <net/if_var.h>
+#endif
 
 // Get info about the device
 #include <pkgconf/system.h>
@@ -226,19 +231,15 @@ var_dot3StatsTable(struct variable *vp,
     int supports_dot3 = 0, i;
     struct ether_drv_stats x;
     
-    for (ifp = ifnet.tqh_first; ifp != 0; ifp = ifp->if_list.tqe_next)
-        interface_count++;
-        
+    interface_count = cyg_snmp_num_interfaces();
+
     if ( header_simple_table( vp,name,length,exact,var_len,write_method,
                               interface_count)
          == MATCH_FAILED )
         return NULL;
 
-    for ( interface_count = name[ (*length)-1 ], ifp = ifnet.tqh_first;
-          interface_count > 1 && ifp != 0;
-          interface_count-- )
-        ifp = ifp->if_list.tqe_next;
-    
+    ifp = cyg_snmp_get_if(name[ (*length)-1 ]);
+
     if ( ! ifp )
         return NULL;
 
--- a/packages/net/snmp/agent/current/src/mibgroup/mibII/interfaces.c
+++ b/packages/net/snmp/agent/current/src/mibgroup/mibII/interfaces.c
@@ -54,7 +54,7 @@
 //#####DESCRIPTIONBEGIN####
 //
 // Author(s):    hmt
-// Contributors: hmt
+// Contributors: hmt, Andrew Lunn
 // Date:         2000-05-30
 // Purpose:      Port of UCD-SNMP distribution to eCos.
 // Description:  
@@ -92,6 +92,22 @@ CONNECTION WITH THE USE OR PERFORMANCE O
 /* This file was generated by mib2c and is intended for use as a mib module
    for the ucd-snmp snmpd agent. */
 
+#include <pkgconf/system.h>
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <net/if.h>
+#ifdef CYGPKG_NET_FREEBSD_STACK
+#include <net/if_var.h>
+#endif
+#include <netinet/in.h>
+#include <netinet/if_ether.h>
+#include <net/if_arp.h>
+// These two to acquire all the statistics.
+
+#include <cyg/io/eth/eth_drv_stats.h>
+#include <sys/sockio.h>
 
 /* This should always be included first before anything else */
 #include <config.h>
@@ -101,17 +117,9 @@ CONNECTION WITH THE USE OR PERFORMANCE O
 #include "mibincl.h"
 #include "mibgroup/util_funcs.h"
 #include "mibgroup/mibII/interfaces.h"
-
+#include "mibgroup/mibII/ifr_helper.h"
 #include <net/if_types.h>
 
-// Get info about the device
-#include <pkgconf/system.h>
-
-// These two two acquire all the statistics.
-#include <cyg/io/eth/eth_drv.h>
-#include <cyg/io/eth/eth_drv_stats.h>
-#include <sys/sockio.h>
-
 /* 
  * interfaces_variables_oid:
  *   this is the top level oid that we want to register under.  This
@@ -121,10 +129,6 @@ CONNECTION WITH THE USE OR PERFORMANCE O
 oid interfaces_variables_oid[] = { 1,3,6,1,2,1,2 };
 
 
-extern struct ifnet_head ifnet;
-
-
-
 /* 
  * variable4 interfaces_variables:
  *   this variable defines function callbacks and type return information 
@@ -201,7 +205,6 @@ void init_interfaces(void) {
   /* place any other initialization junk you need here */
 }
 
-
 /*
  * var_interfaces():
  *   This function is called every time the agent gets a request for
@@ -224,34 +227,24 @@ var_interfaces(struct variable *vp,
 {
     
 
-    /* variables we may use later */
-    static long long_ret;
-//    static unsigned char string[SPRINT_MAX_LEN];
-//    static oid objid[MAX_OID_LEN];
-//    static struct counter64 c64;
-
-
-    if ( MATCH_FAILED ==
-         header_generic(vp,name,length,exact,var_len,write_method) )
-        return NULL;
-
-    /* 
-     * this is where we do the value assignments for the mib results.
-     */
-    switch(vp->magic) {
-    case IFNUMBER: {
-        register struct ifnet *ifp;
-        long_ret = 0;
-        for (ifp = ifnet.tqh_first; ifp != 0; ifp = ifp->if_list.tqe_next)
-            long_ret++;
-        
-        return (unsigned char *) &long_ret;
-    }   
-
-    default:
-        ERROR_MSG("");
-    }
+  static long long_ret;
+  
+  if ( MATCH_FAILED ==
+       header_generic(vp,name,length,exact,var_len,write_method) )
     return NULL;
+  
+  /* 
+   * this is where we do the value assignments for the mib results.
+   */
+  switch(vp->magic) {
+  case IFNUMBER: {
+    long_ret = cyg_snmp_num_interfaces();
+    return (unsigned char *) &long_ret;
+  }
+  default:
+    ERROR_MSG("");
+  }
+  return NULL;
 }
 
 
@@ -274,13 +267,10 @@ var_ifTable(struct variable *vp,
     static long long_ret;
     static unsigned char string[SPRINT_MAX_LEN];
     static oid objid[MAX_OID_LEN];
-//  static struct counter64 c64;
-    
-    register struct ifnet *ifp;
-    int interface_count = 0;
-    
-    for (ifp = ifnet.tqh_first; ifp != 0; ifp = ifp->if_list.tqe_next)
-        interface_count++;
+    struct ifnet *ifp;
+    int if_num;
+
+    int interface_count = cyg_snmp_num_interfaces();
         
     /* 
      * This assumes that the table is a 'simple' table.
@@ -297,13 +287,11 @@ var_ifTable(struct variable *vp,
          == MATCH_FAILED )
         return NULL;
     
-    for ( interface_count = name[ (*length)-1 ], ifp = ifnet.tqh_first;
-          interface_count > 1 && ifp != 0;
-          interface_count-- )
-        ifp = ifp->if_list.tqe_next;
-
-    if ( ! ifp )
-        return NULL;
+    if_num = name[ (*length)-1 ];
+    
+    ifp = cyg_snmp_get_if(if_num);
+    if (!ifp)
+      return NULL;
 
 // This is to assist customers with their own special interfaces; if they
 // define IFT_CUSTOMER_SPECIAL to whatever their own device is, then its
--- a/packages/net/snmp/agent/current/src/mibgroup/mibII/ip.c
+++ b/packages/net/snmp/agent/current/src/mibgroup/mibII/ip.c
@@ -54,7 +54,7 @@
 //#####DESCRIPTIONBEGIN####
 //
 // Author(s):    hmt
-// Contributors: hmt
+// Contributors: hmt, Andrew Lunn
 // Date:         2000-05-30
 // Purpose:      Port of UCD-SNMP distribution to eCos.
 // Description:  
@@ -92,25 +92,31 @@ CONNECTION WITH THE USE OR PERFORMANCE O
 /* This file was generated by mib2c and is intended for use as a mib module
    for the ucd-snmp snmpd agent. */
 
+#include <sys/param.h>
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/time.h>
+#include <net/if.h>
+#ifdef CYGPKG_NET_FREEBSD_STACK
+#include <net/if_var.h>
+#endif
+#include <netinet/in.h>
+#include <netinet/if_ether.h>
+#include <net/if_arp.h>
+#include <netinet/in_var.h>
+#include <netinet/ip_var.h>
 
 /* This should always be included first before anything else */
 #include <config.h>
 
-
 /* minimal include directives */
 #include "mibincl.h"
 #include "mibgroup/util_funcs.h"
 #include "mibgroup/mibII/ip.h"
 
-#define _KERNEL 1
-
-#include <netinet/in_var.h>
-#include <netinet/ip_var.h>
+#include <cyg/io/eth/eth_drv.h>
 
 extern struct in_ifaddrhead in_ifaddr;
-extern struct ifnet_head ifnet;
-
-#include <cyg/io/eth/eth_drv.h>
 
 /* 
  * ip_variables_oid:
@@ -122,7 +128,6 @@ extern struct ifnet_head ifnet;
 
 oid ip_variables_oid[] = { 1,3,6,1,2,1,4 };
 
-
 /* 
  * variable4 ip_variables:
  *   this variable defines function callbacks and type return information 
@@ -294,7 +299,9 @@ var_ip(struct variable *vp,
             + ipstat.ips_badlen
             + ipstat.ips_badoptions
             + ipstat.ips_badvers
+#ifdef CYGPKG_NET_OPENBSD_STACK
             + ipstat.ips_badfrags
+#endif
             + ipstat.ips_toolong
             ;
         return (unsigned char *) &long_ret;
@@ -319,7 +326,9 @@ var_ip(struct variable *vp,
             + ipstat.ips_badlen
             + ipstat.ips_badoptions
             + ipstat.ips_badvers
+#ifdef CYGPKG_NET_OPENBSD_STACK
             + ipstat.ips_badfrags
+#endif
             + ipstat.ips_toolong
                 ) -
             ipstat.ips_cantforward;
@@ -417,7 +426,16 @@ var_ipAddrTable(struct variable *vp,
     /* fill in object part of name for current (less sizeof instance part) */
     memcpy( (char *)current,(char *)vp->name, (int)vp->namelen * sizeof(oid));
 
-    for (ia = in_ifaddr.tqh_first; ia; ia = ia->ia_list.tqe_next) {
+    for (
+#ifdef CYGPKG_NET_OPENBSD_STACK
+	 ia = in_ifaddr.tqh_first; ia; 
+	 ia = ia->ia_list.tqe_next
+#endif
+#ifdef CYGPKG_NET_FREEBSD_STACK
+	 ia = in_ifaddrhead.tqh_first; ia; 
+	 ia = ia->ia_link.tqe_next
+#endif
+	 ) {
 	cp = (u_char *)&(ia->ia_addr.sin_addr.s_addr);
 
 	op = current + 10;
@@ -544,7 +562,16 @@ var_ipNetToMediaTable(struct variable *v
     /* fill in object part of name for current (less sizeof instance part) */
     memcpy((char *)current, (char *)vp->name, (int)vp->namelen * sizeof(oid));
 
-    for (ia = in_ifaddr.tqh_first; ia; ia = ia->ia_list.tqe_next) {
+    for (
+#ifdef CYGPKG_NET_OPENBSD_STACK
+	 ia = in_ifaddr.tqh_first; ia; 
+	 ia = ia->ia_list.tqe_next
+#endif
+#ifdef CYGPKG_NET_FREEBSD_STACK	 
+	   ia = in_ifaddrhead.tqh_first; ia; 
+	 ia = ia->ia_link.tqe_next
+#endif
+	 ) {
         // interface number
         current[10] = ia->ia_ifa.ifa_ifp->if_index;
         // IP address
--- a/packages/net/snmp/agent/current/src/mibgroup/mibII/tcp.c
+++ b/packages/net/snmp/agent/current/src/mibgroup/mibII/tcp.c
@@ -54,7 +54,7 @@
 //#####DESCRIPTIONBEGIN####
 //
 // Author(s):    hmt
-// Contributors: hmt
+// Contributors: hmt, Andrew Lunn
 // Date:         2000-05-30
 // Purpose:      Port of UCD-SNMP distribution to eCos.
 // Description:  
@@ -92,7 +92,7 @@ CONNECTION WITH THE USE OR PERFORMANCE O
 /* This file was generated by mib2c and is intended for use as a mib module
    for the ucd-snmp snmpd agent. */
 
-
+#include <pkgconf/system.h>
 /* This should always be included first before anything else */
 #include <config.h>
 
@@ -264,9 +264,18 @@ var_tcp(struct variable *vp,
     case TCPCURRESTAB: {
         struct inpcb *inp;
         long_ret = 0;
-        for (inp = tcbtable.inpt_queue.cqh_first;
+        for (
+#ifdef CYGPKG_NET_OPENBSD_STACK
+	     inp = tcbtable.inpt_queue.cqh_first;
              inp != (struct inpcb *)&tcbtable.inpt_queue;
-             inp = inp->inp_queue.cqe_next) {
+             inp = inp->inp_queue.cqe_next
+#endif
+#ifdef CYGPKG_NET_FREEBSD_STACK
+	     inp = tcb.lh_first;
+             inp;
+             inp = inp->inp_list.le_next
+#endif
+	     ) {
             struct tcpcb *tp = intotcpcb( inp );
             if ( tp && (TCPS_ESTABLISHED == tp->t_state ||
                         TCPS_CLOSE_WAIT  == tp->t_state) )
@@ -349,9 +358,18 @@ var_tcpConnTable(struct variable *vp,
     /* fill in object part of name for current (less sizeof instance part) */
     memcpy((char *)newname, (char *)vp->name, (int)vp->namelen * sizeof(oid));
 
-    for (inp = tcbtable.inpt_queue.cqh_first;
-         inp != (struct inpcb *)&tcbtable.inpt_queue;
-         inp = inp->inp_queue.cqe_next) {
+    for (
+#ifdef CYGPKG_NET_OPENBSD_STACK
+	     inp = tcbtable.inpt_queue.cqh_first;
+             inp != (struct inpcb *)&tcbtable.inpt_queue;
+             inp = inp->inp_queue.cqe_next
+#endif
+#ifdef CYGPKG_NET_FREEBSD_STACK
+	     inp = tcb.lh_first;
+             inp;
+             inp = inp->inp_list.le_next
+#endif
+	 ) {
 
         cp = (u_char *)&inp->inp_laddr.s_addr;
         op = newname + 10;
--- a/packages/net/snmp/agent/current/src/mibgroup/mibII/udp.c
+++ b/packages/net/snmp/agent/current/src/mibgroup/mibII/udp.c
@@ -54,7 +54,7 @@
 //#####DESCRIPTIONBEGIN####
 //
 // Author(s):    hmt
-// Contributors: hmt
+// Contributors: hmt, Andrew Lunn
 // Date:         2000-05-30
 // Purpose:      Port of UCD-SNMP distribution to eCos.
 // Description:  
@@ -92,30 +92,24 @@ CONNECTION WITH THE USE OR PERFORMANCE O
 /* This file was generated by mib2c and is intended for use as a mib module
    for the ucd-snmp snmpd agent. */
 
+#include <pkgconf/system.h>
 
 /* This should always be included first before anything else */
 #include <config.h>
 
-
 /* minimal include directives */
 #include "mibincl.h"
 #include "mibgroup/util_funcs.h"
 #include "mibgroup/mibII/udp.h"
 
-
+#include <sys/protosw.h>
 
 #define _KERNEL
-
-#include <net/if.h>
-#include <net/route.h>
-
 #include <netinet/in.h>
 #include <netinet/in_systm.h>
-#include <netinet/in_var.h>
 #include <netinet/ip.h>
 #include <netinet/in_pcb.h>
 #include <netinet/ip_var.h>
-#include <netinet/ip_icmp.h>
 #include <netinet/udp.h>
 #include <netinet/udp_var.h>
 
@@ -257,9 +251,18 @@ var_udpTable(struct variable *vp,
     /* fill in object part of name for current (less sizeof instance part) */
     memcpy((char *)newname, (char *)vp->name, (int)vp->namelen * sizeof(oid));
 
-    for (inp = udbtable.inpt_queue.cqh_first;
+    for (
+#ifdef CYGPKG_NET_OPENBSD_STACK
+	 inp = udbtable.inpt_queue.cqh_first;
          inp != (struct inpcb *)&udbtable.inpt_queue;
-         inp = inp->inp_queue.cqe_next) {
+         inp = inp->inp_queue.cqe_next
+#endif
+#ifdef CYGPKG_NET_FREEBSD_STACK
+	 inp = udb.lh_first;
+         inp;
+         inp = inp->inp_list.le_next
+#endif
+	 ) {
         cp = (u_char *)&inp->inp_laddr.s_addr;
         op = newname + 10;
         *op++ = *cp++;
--- a/packages/net/snmp/agent/current/src/snmptask.c
+++ b/packages/net/snmp/agent/current/src/snmptask.c
@@ -152,25 +152,11 @@ CONNECTION WITH THE USE OR PERFORMANCE O
 //
 //==========================================================================
 
-
-// Support routines, etc., used by network code
-
-#include <sys/param.h>
-#include <sys/malloc.h>
-#include <sys/mbuf.h>
-#include <sys/kernel.h>
-#include <sys/domain.h>
-#include <sys/protosw.h>
-#include <net/netisr.h>
-
-#include <machine/cpu.h>
-
-#include <cyg/infra/diag.h>
-#include <cyg/hal/hal_intr.h>
+#include <cyg/hal/hal_arch.h>
 #include <cyg/kernel/kapi.h>
 
-
-
+#include <pkgconf/system.h>
+#include CYGDAT_NET_STACK_CFG
 
 #define STACK_SIZE CYGNUM_HAL_STACK_SIZE_TYPICAL + 102400
 static char netsnmp_stack[STACK_SIZE];
@@ -188,7 +174,7 @@ void (*snmpd_reinit_function)( void ) = 
 externC void snmpd( void (*initfunc)( void ) );
 
 static void
-snmpdloop( void )
+snmpdloop( cyg_addrword_t data )
 {
     while ( 1 )
         snmpd(snmpd_reinit_function);