Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 894020 Details for
Bug 1069046
snmpd returns truncated value for Counter64 taken from smuxpeer
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
smux subagent
smux.c (text/plain), 8.47 KB, created by
Jan Safranek
on 2014-05-09 11:58:55 UTC
(
hide
)
Description:
smux subagent
Filename:
MIME Type:
Creator:
Jan Safranek
Created:
2014-05-09 11:58:55 UTC
Size:
8.47 KB
patch
obsolete
>/* Based on SMUX handler in GNU Quagga, http://www.nongnu.org/quagga/ > * > * This program is free software: you can redistribute it and/or modify > * it under the terms of the GNU General Public License as published by > * the Free Software Foundation, either version 3 of the License, or > * (at your option) any later version. > * > * This program is distributed in the hope that it will be useful, > * but WITHOUT ANY WARRANTY; without even the implied warranty of > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > * GNU General Public License for more details. > * > * You should have received a copy of the GNU General Public License > * along with this program. If not, see <http://www.gnu.org/licenses/>. > */ > >/* This is dummy implementation of SMUX protocol. It does: > * - send OPEN request > * - send 1 REGISTER request + process its response > * - process 1 GET request from snmpd and sends 1 response > * - exits > * > * Usage: > * 1. put into your snmpd.conf: > * smuxpeer 1.2.3.4 passwd > * 2. compile this program: > * gcc -o smux smux.c -l netsnmp > * 3. start snmpd: > * service snmpd restart > * (or snmpd -f -Lo -Dsmux for extra output) > * 4. start this program: > * ./smux localhost passwd > * 5. ask snmpd for 1.3.6.1.4.1.334.72.0 > * snmpget -v2c -c public localhost 1.3.6.1.4.1.334.72.0 > * 6. you should get the value: > * SNMPv2-SMI::enterprises.334.72.0 = Counter64: 20014547621496 > */ > >#include <net-snmp/net-snmp-config.h> >#include <net-snmp/net-snmp-includes.h> >#include <stdio.h> >#include <sys/types.h> >#include <sys/socket.h> >#include <netinet/in.h> >#include <netdb.h> > >#define BUFLEN 1024 > >#define SMUX_OPEN (ASN_APPLICATION | ASN_CONSTRUCTOR | 0) >#define SMUX_CLOSE (ASN_APPLICATION | ASN_PRIMITIVE | 1) >#define SMUX_RREQ (ASN_APPLICATION | ASN_CONSTRUCTOR | 2) >#define SMUX_RRSP (ASN_APPLICATION | ASN_PRIMITIVE | 3) >#define SMUX_SOUT (ASN_APPLICATION | ASN_PRIMITIVE | 4) > >#define SMUX_GET (ASN_CONTEXT | ASN_CONSTRUCTOR | 0) >#define SMUX_GETNEXT (ASN_CONTEXT | ASN_CONSTRUCTOR | 1) >#define SMUX_GETRSP (ASN_CONTEXT | ASN_CONSTRUCTOR | 2) >#define SMUX_SET (ASN_CONTEXT | ASN_CONSTRUCTOR | 3) >#define SMUX_TRAP (ASN_CONTEXT | ASN_CONSTRUCTOR | 4) > >oid smux_oid[] = {1,2,3,4}; >size_t smux_oid_len = 4; > >oid subtree_oid[] = {1,3,6,1,4,1,334,72,0}; >size_t subtree_oid_len = 9; > >/* > * Send SMUX_OPEN message. > */ >void send_open(int sock, char *smux_passwd) >{ > u_char buf[BUFLEN]; > u_char *ptr = buf; > size_t len = BUFLEN; > const char progname[] = "TESTSMUX"; > > /* SMUX Header. As placeholder. */ > ptr = asn_build_header (ptr, &len, (u_char) SMUX_OPEN, 0); > > /* SMUX Open. */ > long version = 0; > ptr = asn_build_int (ptr, &len, > (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), > &version, sizeof (version)); > > /* SMUX connection oid. */ > ptr = asn_build_objid (ptr, &len, > (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OBJECT_ID), > smux_oid, smux_oid_len); > > /* SMUX connection description. */ > ptr = asn_build_string (ptr, &len, > (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OCTET_STR), > (const u_char *) progname, strlen (progname)); > > /* SMUX connection password. */ > ptr = asn_build_string (ptr, &len, > (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OCTET_STR), > (u_char *)smux_passwd, strlen (smux_passwd)); > > /* Fill in real SMUX header. We exclude ASN header size (2). */ > len = BUFLEN; > asn_build_header (buf, &len, (u_char) SMUX_OPEN, (ptr - buf) - 2); > > size_t sent = send (sock, buf, (ptr - buf), 0); > printf("sent open: %d bytes\n", (int) sent); >} > > >/* > * Send SMUX_RREQ request and receive a response. > * It registers subtree_oid without the last component (.0) > */ >void send_register(int sock) >{ > u_char buf[BUFLEN]; > u_char *ptr = buf; > size_t len = BUFLEN; > > /* SMUX RReq Header. */ > ptr = asn_build_header (ptr, &len, (u_char) SMUX_RREQ, 0); > > /* Register MIB tree. */ > ptr = asn_build_objid (ptr, &len, > (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_OBJECT_ID), > subtree_oid, subtree_oid_len - 1); > > /* Priority. */ > long priority = -1; > ptr = asn_build_int (ptr, &len, > (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), > &priority, sizeof (priority)); > > /* Operation. */ > long operation = 2; /* Register R/W */ > ptr = asn_build_int (ptr, &len, > (u_char)(ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), > &operation, sizeof (operation)); > > len = BUFSIZ; > asn_build_header (buf, &len, (u_char) SMUX_RREQ, (ptr - buf) - 2); > size_t sent = send (sock, buf, (ptr - buf), 0); > printf("sent reg: %d bytes\n", (int)sent); > > // receive response > len = recv(sock, buf, BUFLEN, 0); > printf("Got registration resp., %d bytes\n", (int) len); > ptr = buf; > /* Parse SMUX message type and subsequent length. */ > u_char type; > ptr = asn_parse_header (ptr, &len, &type); > if (type != SMUX_RRSP) { > printf("Received wrong response, RRSP expected\n"); > exit(1); > } > > long err; > u_char val; > ptr = asn_parse_int(ptr, &len, &val, &err, sizeof (err)); > printf("Registration returned %ld\n", err); >} > >/* > * Receive one SNMP_GET request and send response. > * All other requests are not implemented! > */ >void process_req(int sock, u_char value_type, size_t value_len, u_char *value) >{ > u_char buf[BUFLEN]; > size_t len; > > // receive a request > len = recv(sock, buf, BUFLEN, 0); > > u_char *ptr = buf; > /* Parse SMUX message type and subsequent length. */ > u_char type; > ptr = asn_parse_header (ptr, &len, &type); > > if (type != SMUX_GET) { > printf("Got unknown message, GET expected\n"); > exit(1); > } > > long reqid, errstat = 0, errindex = 0; > /* We need only Request ID. */ > ptr = asn_parse_int (ptr, &len, &type, &reqid, sizeof (reqid)); > > > // build rsp > ptr = buf; > len = BUFLEN; > u_char *h1 = ptr; > ptr = asn_build_sequence (ptr, &len, (u_char) SMUX_GETRSP, 0); > u_char *h1e = ptr; > > ptr = asn_build_int (ptr, &len, > (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), > &reqid, sizeof (reqid)); > > ptr = asn_build_int (ptr, &len, > (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), > &errstat, sizeof (errstat)); > > ptr = asn_build_int (ptr, &len, > (u_char) (ASN_UNIVERSAL | ASN_PRIMITIVE | ASN_INTEGER), > &errindex, sizeof (errindex)); > > u_char *h2 = ptr; > /* Place holder h2 for one variable */ > ptr = asn_build_sequence (ptr, &len, > (u_char)(ASN_SEQUENCE | ASN_CONSTRUCTOR), 0); > u_char *h2e = ptr; > > /* > * Adding the value here !!! > */ > ptr = snmp_build_var_op (ptr, subtree_oid, &subtree_oid_len, > value_type, value_len, value, &len); > > /* Now variable size is known, fill in size */ > size_t length = BUFLEN; > asn_build_sequence(h2,&length,(u_char)(ASN_SEQUENCE|ASN_CONSTRUCTOR),ptr-h2e); > > /* Fill in size of whole sequence */ > asn_build_sequence(h1,&length,(u_char)SMUX_GETRSP,ptr-h1e); > > send (sock, buf, (ptr - buf), 0); >} > >void read_rsp(int sock, int len) >{ > char buf[BUFLEN]; > size_t count; > count = recv(sock, buf, len, 0); > printf("Read %d bytes\n", (int) count); >} > >int main(int argc, char **argv) >{ > int sock = socket(AF_INET, SOCK_STREAM, 0); > if (sock < 0) > { > perror("ERROR opening socket"); > exit(1); > } > struct hostent *server; > server = gethostbyname(argv[1]); > if (server == NULL) { > fprintf(stderr,"ERROR, no such host\n"); > exit(0); > } > > struct sockaddr_in serv_addr; > > bzero((char *) &serv_addr, sizeof(serv_addr)); > serv_addr.sin_family = AF_INET; > bcopy((char *)server->h_addr, > (char *)&serv_addr.sin_addr.s_addr, > server->h_length); > serv_addr.sin_port = htons(199); > > if (connect(sock,&serv_addr,sizeof(serv_addr)) < 0) > { > perror("ERROR connecting"); > exit(1); > } > > send_open(sock, argv[2]); > send_register(sock); > > // the value we want to send > // TODO: modify this if you want send different variable type or value > struct counter64 c64; > c64.low = 0x5678; > c64.high = 0x1234; > process_req(sock, ASN_COUNTER64, sizeof(c64), (u_char *)&c64); > > return 0; >} >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 1069046
: 894020