📄 attache.c
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/snmptalk/attache.c,v 1.5 2003/01/15 14:04:54 josh Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved. Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//**************************************************************************** * Copyright 1991-1997 Epilogue Technology Corporation. * Copyright 1998 Integrated Systems, Inc. * All rights reserved. ****************************************************************************//* Attache specific glue routines for snmptalk. *//* * $Log: attache.c,v $ * Revision 1.5 2003/01/15 14:04:54 josh * directory structure shifting * * Revision 1.4 2002/05/23 18:51:13 josh * code modifications to support the entity MIB * * Revision 1.3 2002/03/11 19:17:07 josh * snmptalk's destination address is now stored and passed around * as an ipaddr_t. This required changes to a lot of internal function * calls that used to expect an inaddr_t to be passed around. Also, * snmptalk is now capable of using IPv6 sockets * * Revision 1.2 2001/11/08 16:47:21 tneale * Updated for newset file layout * * Revision 1.1.1.1 2001/11/05 17:49:11 tneale * Tornado shuffle * * Revision 7.16.4.1 2001/08/24 15:00:50 josh * add a proxy send routine for SNMPv3 proxies * * Revision 7.16 2001/01/19 22:24:42 paul * Update copyright. * * Revision 7.15 2000/03/17 00:14:32 meister * Update copyright message * * Revision 7.14 1998/09/18 19:55:55 meister * timer call renaming tm_ --> etc_tm_ * * Revision 7.13 1998/06/23 20:56:42 sar * Moved parse.h to snark/h/parse.h * * Revision 7.12 1998/06/07 02:51:39 sar * Move the validate routines to snark library, leaving * a proxy_send_rtn and envoy_now stubs that either do the * right thing or point to the right routine. * * Revision 7.11 1998/06/03 21:50:34 sar * Moved nvutils and nvviews to snark/lib so we can have one copy shared * amongst the demos * Moved the common string functions from stdf to common/lib and created * a series of macros for this code to use * Moved strdup to snark/lib and renamed it to etc_strdup to avoid * needing one from the system libraries * * Revision 7.10 1998/02/25 15:21:57 sra * Finish moving types.h, bug.h, and bugdef.h to common/h/. * * Revision 7.9 1998/02/25 04:57:53 sra * Update copyrights. * * Revision 7.8 1997/10/30 04:17:59 sar * Split attache.c into attache.c for utilities and att_opr.c for * the snmp send and receive functions. * * Revision 7.7 1997/10/16 23:46:57 sar * changed the sys contact string * * Revision 7.6 1997/10/16 02:23:41 sar * cast the return from a call to snmp_memory_alloc() to keep compilers happier * * Revision 7.5 1997/03/20 06:53:44 sra * DFARS-safe copyright text. Zap! * * Revision 7.4 1997/02/25 10:58:16 sra * Update copyright notice, dust under the bed. * * Revision 7.3 1997/02/19 08:10:29 sra * More fun merging snmptalk into snark, general snark cleanup. * * Revision 7.2 1997/01/08 23:26:53 sar * Updated include files to use envoy/h as appropriate after * move from envoy/utils to snark/snmptalk * * Revision 7.1 1997/01/08 01:56:37 sar * use snark based routines. sty driver for in/output and read_init * for init files, cleaned up dns stuff some. * * Revision 7.0 1996/03/18 20:19:20 sar * Updated rev to 7.0 and copyright to 96 * * Revision 6.4 1996/02/27 21:31:57 sar * changed int i to unsigned int i and add a void in a declaration * to keep compilers happy. * * Revision 6.3 1996/02/24 18:11:40 sra * Fix pcatt.h lossage. Get rid of ATT_DNS conditionals. * * Revision 6.2 1996/01/10 16:41:40 sar * Added packet dump code * * Revision 6.1 1995/11/01 00:56:58 sar * removed no_pp stuff and casts of 0 * * Revision 6.0 1995/05/31 21:49:59 sra * Release 6.0. * * Revision 5.4 1995/03/24 16:28:36 sar * Implemented envoy_call_timer as a call to the attache timer routines. * * Revision 5.3 1995/03/17 21:13:34 dab * changed reference to interface_routes_owner to be static_routes_owner * instead. * * Revision 5.2 1994/09/30 19:41:55 dab * Removed old type definitions. * * Revision 5.1 1994/07/24 15:41:03 dab * Added ability to set UDP port used by manager and the set command can * now specify enumerated integer values by symbolic name. * * Revision 5.0 1994/05/16 15:57:40 sar * Updated revision to 5.0 and copyright to include 1994 * * Revision 4.0 1993/06/24 17:14:56 sar * Updated rev to 4.0 and copyright to 93 * * Revision 3.12 1993/06/13 02:48:16 sar * moved inclusion of stdf.h to be after asn1.h so that NO_PP will be defined * if desired. * * Revision 3.11 1993/05/26 14:24:39 dab * Rearrange configuration so IP addresses have to be there for a * packet driver interface to be created but the address can be 0. * * Revision 3.10 1993/05/19 20:38:22 sar * was trying to set an OIDC (unsigned) to -1, now set it to 0xFFFF. * * Revision 3.9 1993/05/17 20:36:13 sar * Added <install.h> and "stdf.h" to include string routines that zortech * didn't have. * Changed from an inadder to a dns_server to make borland happy. * * Revision 3.8 1993/03/04 21:53:06 sra * Add call to SNMPTALK_DEMO_INIT() in md_start_up(), so that I can put * in random demo code via the port configuration definitions. * * Revision 3.7 1993/03/02 18:20:49 dab * Use new header file read_ini.h to get those declarations. * * Revision 3.6 1993/02/23 19:00:17 dab * New configuration scheme uses <> includes instead of "" * * Revision 3.5 1993/02/05 18:47:56 dab * Changed "system.h" to <snmptalk.h> * * Revision 3.4 1993/01/19 19:17:23 dab * Attach loopback interface before adding routes in case any route * wants to reference it. * * Added code to use the new (not really so new) dns library. * * Revision 3.5 1992/12/17 20:48:18 dab * Changes to use the attache dns library. * * Revision 3.4 1992/12/15 20:52:57 dab * Attache loopback interface before adding routes in case routes * want to reference it. Also, with change to the order that interfaces * are put on interface list this means the loopback interface comes * first. * * Revision 3.3 1992/09/29 13:33:37 dab * Changed to attach interfaces even if they don't have an IP address * configured. * * Added handling of route-gw and route-net commands in the configuration * file to put in static routes. * * Revision 3.2 92/09/18 16:45:40 dab * Use new packet driver and new IP routing table. * * Revision 3.1 92/06/16 16:05:37 dab * Added batch mode * * Revision 3.0 92/04/03 19:53:14 dab * Release 3.0 * * Revision 1.10 92/02/27 16:49:30 dab * Fixed memory leak where the command line was being strdup'd but * never free'd. * * Revision 1.9 92/02/11 10:55:56 dab * Casts to make Microsoft C happier. * * Revision 1.8 92/02/04 15:02:41 dab * Wrote new_atoinet which doesn't use sscanf and which returns 0 if * it has a problem parsing the IP address. * * Revision 1.7 91/11/07 09:32:16 dab * Removed snmp responder community strings to snmpint.c * * Revision 1.6 91/11/06 13:54:37 dab * Added function prototypes for internal functions and other fixups so * pickier compilers would be happy. * * Revision 1.5 91/11/05 09:53:37 dab * Added attache specific snmp variables. * *//* [clearcase]modification history-------------------01a,19apr05,job update copyright notices*/#include <wrn/wm/common/install.h>#include <snmptalk.h>#include <stdio.h>#include <wrn/wm/attache/config.h>#include <wrn/wm/common/types.h>#include <wrn/wm/attache/mib.h>#include <wrn/wm/attache/timer.h>#include <wrn/wm/attache/packet.h>#include <wrn/wm/attache/net.h>#include <wrn/wm/attache/route.h>#include <wrn/wm/attache/ip.h>#include <wrn/wm/attache/arp.h>#include <wrn/wm/attache/udp.h>#include <wrn/wm/attache/dns.h>#include <wrn/wm/attache/glue.h>#include <wrn/wm/attache/tcp.h>#include <wrn/wm/demo/tasks.h>#include <wrn/wm/demo/snarklib.h>#include <wrn/wm/demo/snmpconf.h>#include <wrn/wm/snmp/engine/asn1.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/attache/snmpvars.h>#include "md.h"#include "snmpint.h"#include <wrn/wm/demo/snmpfunc.h>/* * Interface to Attache's DNS code. *//* DNS configuration */extern struct dns_config domain_config;/* Gratuitous declarations for a certain lame compiler. */static void dns_answer (struct dns_query *query, char *dname, int n, ipaddr_t addrs[], void *cookie);static void dns_error_response (struct dns_query *query, enum dns_error error, void *cookie);/* state that we pass through the dns cookies to keep track of what we're * asking. */struct dns_state { void (*answer_rtn) __((struct sty *, char *, ipaddr_t *)); struct sty *sty; char name[1];};/* If the dns gives us an answer we come here, cookie is struct dns_state */static void dns_answer(struct dns_query *query, char *dname, int n, ipaddr_t addrs[], void *cookie){ struct dns_state *ds = cookie; (*ds->answer_rtn)(ds->sty, dname, n == 0 ? 0L : &(addrs[0])); SNMP_memory_free(ds);}/* If the dns fails we come here and call the answer upcall, stashed in cookie, * with 0. */static void dns_error_response(struct dns_query *query, enum dns_error error, void *cookie){ struct dns_state *ds = cookie; (*ds->answer_rtn)(ds->sty, ds->name, 0L); SNMP_memory_free(ds);}/* Convert a hostname string to an IP address. */void md_hostname_to_addr(struct sty *sty, char *name, void (*answer)(struct sty *sty, char *name, ipaddr_t *iaddr)){ struct dns_state *ds; ds = (struct dns_state *)SNMP_memory_alloc(sizeof(struct dns_state) + STRLEN(name)); if (ds == 0) { (*answer)(sty, name, 0); return; } STRCPY(ds->name, name); ds->answer_rtn = answer; ds->sty = sty; dns_name_to_ipaddr(name, dns_answer, dns_error_response, &domain_config, 0, ds);}/* * Hook Envoy's timer system into Attache's timer system. * Unfortunately, ANSI C doesn't promise that we can store a function * pointer in a (void *), so we have to be a little tricker than that. */static void envoy_glue_handler(struct timer *tm, void *cookie){ (**((void (**)(void)) cookie))();}void envoy_call_timer(bits32_t when, void (*what)(void)){ static struct timer tm; static void (*what_)(void); if (!tm.handler) { etc_tm_init(&tm); tm.handler = envoy_glue_handler; tm.cookie = &what_; } what_ = what; etc_tm_set(&tm, when);}/* Glue routine to connect up to the attache now routine in snark/lib. We use this mechanism instead of envoy.h so we can compile most of the code without knowing what we are running on the top of */bits32_t envoy_now(void){return(glue_now());}#if !(INSTALL_ENVOY_AGENTX_MASTER)bits32_t envoy_get_sysuptime(){return centiseconds_since_attache_boot();}#endif/* * snmp agent variables. */char snmp_auth_traps = 0;/* WARNING: The following strings should be in NVT form, i.e. any embedded * newlines whould be carriage-return followed by linefeed (newline) * * You should set these to the default values you would like them set to * for your device. */static char var_sysDescr_data[MAX_SYSDESCR] = "Epilogue Technology SNMPTALK";struct string_wlen var_sysDescr = { MAX_SYSDESCR, 28, var_sysDescr_data };static char var_sysContact_data[MAX_SYSCONTACT] = "sales@epilogue.com";struct string_wlen var_sysContact = { MAX_SYSCONTACT, 18, var_sysContact_data };static char var_sysLocation_data[MAX_SYSLOCATION] = "sysLocation not set";struct string_wlen var_sysLocation = { MAX_SYSLOCATION, 19, var_sysLocation_data };static char var_sysName_data[MAX_SYSNAME] = "sysName not set";struct string_wlen var_sysName = { MAX_SYSNAME, 15, var_sysName_data };long var_sysServices = 4;#if (INSTALL_ENVOY_SNMP_PROXY)/****************************************************************************NAME: proxy_send_rtnPURPOSE: glue routine to connect up to the real send rtn in snark/libPARAMETERS: EBUFFER_T * The buffer to send ptr_t Information as to where to send the buffer.RETURNS: sbits32_t A reasonable timeout period for this transport ****************************************************************************/sbits32_t proxy_send_rtn(EBUFFER_T *ebuf, ptr_t cookie){return(attache_proxy_send_rtn(ebuf, cookie));}#endif /* #if (INSTALL_ENVOY_SNMP_PROXY) */#if (INSTALL_ENVOY_SNMP_V3_PROXY)/****************************************************************************NAME: envoy_snmp_send_proxyPURPOSE: send an SNMP packet to a proxy targetPARAMETERS: SNMPADDR_T * The address to send to SNMPADDR_T * The address to send from PTR_T The packet structure to be encoded and sent ALENGTH_T The expected size of the encoded buffer PTR_T A cookieRETURNS: nothing ****************************************************************************/void envoy_snmp_send_proxy(SNMPADDR_T *for_addr, SNMPADDR_T *loc_addr, PTR_T pktp, ALENGTH_T need){struct udp_conn udpc;EBUFFER_T ebuff;packet *p;bits32_t for_ip, loc_ip;EBufferInitialize(&ebuff);p = udp_alloc(need, 0);if (!p) return;MEMSET(&udpc, 0, sizeof(struct udp_conn));MEMCPY(&for_ip, for_addr->snmp_data, 4);MEMCPY(&loc_ip, loc_addr->snmp_data, 4);ip_conn_set_dst(udp_conn_get_ip_conn(&udpc), for_ip);ip_conn_set_src(udp_conn_get_ip_conn(&udpc), loc_ip);EBufferSetup(BFL_IS_STATIC, &ebuff, p->pkt_data, p->pkt_datalen);if (SNMP_Process_Finish((SNMP_PKT_T *) pktp, &ebuff, need) == 0) { /* build a control block to send a response back where the * request came from */ udp_conn_set_dst(&udpc, for_addr->snmp_port); udp_conn_set_src(&udpc, SNMP_REQUEST_PORT); udp_send_conn(p, &udpc); EBufferClean(&ebuff); }}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -