📄 ax_mast.c
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/snmptalk/ax_mast.c,v 1.3 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. ****************************************************************************//* * $Log: ax_mast.c,v $ * Revision 1.3 2003/01/15 14:04:54 josh * directory structure shifting * * Revision 1.2 2001/11/08 16:47:22 tneale * Updated for newset file layout * * Revision 1.1.1.1 2001/11/05 17:49:11 tneale * Tornado shuffle * * Revision 1.12 2001/01/19 22:24:43 paul * Update copyright. * * Revision 1.11 2000/03/17 00:14:32 meister * Update copyright message * * Revision 1.10 1999/05/27 16:19:16 josh * Added code for envoy_ax_translate_context() userexit. * * Revision 1.9 1998/07/06 01:02:33 sar * Casts to make compilers happy * * Revision 1.8 1998/06/23 20:56:43 sar * Moved parse.h to snark/h/parse.h * * Revision 1.7 1998/06/03 21:50:33 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 1.6 1998/02/25 15:21:57 sra * Finish moving types.h, bug.h, and bugdef.h to common/h/. * * Revision 1.5 1998/02/25 04:57:53 sra * Update copyrights. * * Revision 1.4 1998/02/25 01:37:20 sra * Fix up CVS/RCS keywords. * *//* [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/attache/slowtime.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/snmp/engine/agentx.h>#include <wrn/wm/attache/snmpvars.h>#include "md.h"#include "snmpint.h"typedef struct ax_foo_s { bits16_t ref_count; ENVOY_AX_CHUNK_T chunk; } ax_foo_t;void agentx_admin(ptr_t cookie, ptr_t ax_pkt){return;}void agentx_add(ptr_t cookie){((ax_foo_t *)(tcp_get_cookie((struct tcb *)cookie)))->ref_count++;}void agentx_free(ptr_t cookie, int foobar){((ax_foo_t *)(tcp_get_cookie((struct tcb *)cookie)))->ref_count--;}int agentx_send(ptr_t cookie, ptr_t ax_pkt, ptr_t vblist, ALENGTH_T need){packet *pkt;EBUFFER_T ebuff;EBufferInitialize(&ebuff);pkt = tcp_alloc(need);if (pkt == 0) return(1);EBufferSetup(BFL_IS_STATIC, &ebuff, pkt->pkt_data, pkt->pkt_datalen);if (envoy_ax_pkt_encode(ax_pkt, vblist, &ebuff, need)) { tcp_free(pkt); return(1); } (void) tcp_write((struct tcb *)cookie, pkt);return(0);}void agentx_open(struct tcb *con){ax_foo_t *myfoo;myfoo = (ax_foo_t *)SNMP_memory_alloc(sizeof(ax_foo_t));if (myfoo == 0) { tcp_abort(con); return; }myfoo->ref_count = 0;envoy_ax_chunk_init(&myfoo->chunk);tcp_set_cookie(con, (void *)myfoo);return;}bits16_t agentx_rcv(struct tcb *con, packet *pkt){ax_foo_t *myfoo;myfoo = (ax_foo_t *)tcp_get_cookie(con);if (envoy_ax_chunk_handler(pkt->pkt_data, pkt->pkt_datalen, envoy_ax_ma_handler, &myfoo->chunk, 0, agentx_admin, agentx_send, agentx_free, agentx_add, con)) tcp_abort(con);tcp_free(pkt);return(1000);}void agentx_remote_close(struct tcb *con){tcp_close(con);return;}void agentx_closed(struct tcb *con, int why){ax_foo_t *myfoo;envoy_ax_ma_cleanup_sessions(con, 0);myfoo = (ax_foo_t *)tcp_get_cookie(con);if (myfoo) { envoy_ax_chunk_clean(&myfoo->chunk); SNMP_memory_free(myfoo); }return;}void agentx_init(){struct tcb *con;con = tcp_create();if (con) { tcp_set_local_port(con, ENVOY_AX_MASTER_PORT); tcp_set_open_upcall(con, agentx_open); tcp_set_receive_upcall(con, agentx_rcv); tcp_set_receive_window(con, 1000); tcp_set_remote_close_upcall(con, agentx_remote_close); tcp_set_closed_upcall(con, agentx_closed); tcp_start(con, TCP_PASSIVE); }return;}sbits32_t envoy_ax_transport_type(ptr_t cookie){return(ENVOY_AX_TRANSPORT_TYPE_TCP);} int envoy_ax_transport_string(ptr_t cookie, ALENGTH_T *need, bits8_t **buf, int *dyn_buf){ipaddr_t ip;*buf = SNMP_memory_alloc(MAX_IPADDR_STRING_LEN + 1);if (*buf == 0) return(0);ip = tcp_get_remote_ipaddr((struct tcb *)cookie);(void) ipaddr_to_string(&ip, (char *)(*buf), MAX_IPADDR_STRING_LEN + 1);*need = STRLEN((char *)(*buf));*dyn_buf = 1;return(1);}void envoy_ax_translate_context(SNMP_PKT_T *pktp, ENVOY_AX_PKT_T *query_pkt){int comm_len;int i;bits8_t *comm;comm_len = EBufferUsed(SNMP_pkt_get_SNMP_community(pktp));if (SNMP_pkt_get_SNMP_version(pktp) == SNMP_VERSION_3) { EBufferPreLoad(BFL_IS_STATIC, ax_pkt_get_context(query_pkt), EBufferStart(SNMP_pkt_get_SNMP_community(pktp)), EBufferUsed(SNMP_pkt_get_SNMP_community(pktp))); }else { for (i = 0, comm = EBufferStart(SNMP_pkt_get_SNMP_community(pktp)); i < (comm_len - 1); i++, comm++) { if (*comm == '@') { EBufferPreLoad(BFL_IS_STATIC, ax_pkt_get_context(query_pkt), comm + 1, comm_len - (i+1)); break; } } }}bits32_t envoy_get_sysuptime(){return centiseconds_since_attache_boot();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -