]> git.ipfire.org Git - thirdparty/squid.git/blob - lib/snmplib/coexistance.c
Merged from trunk
[thirdparty/squid.git] / lib / snmplib / coexistance.c
1 /*
2 * RFC 1908: Coexistence between SNMPv1 and SNMPv2
3 */
4 /**********************************************************************
5 *
6 * Copyright 1997 by Carnegie Mellon University
7 *
8 * All Rights Reserved
9 *
10 * Permission to use, copy, modify, and distribute this software and its
11 * documentation for any purpose and without fee is hereby granted,
12 * provided that the above copyright notice appear in all copies and that
13 * both that copyright notice and this permission notice appear in
14 * supporting documentation, and that the name of CMU not be
15 * used in advertising or publicity pertaining to distribution of the
16 * software without specific, written prior permission.
17 *
18 * CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
19 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
20 * CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
21 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
23 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
24 * SOFTWARE.
25 *
26 * Author: Ryan Troll <ryan+@andrew.cmu.edu>
27 *
28 **********************************************************************/
29
30 #include "squid.h"
31
32 #include <stdio.h>
33
34 #if HAVE_UNISTD_H
35 #include <unistd.h>
36 #endif
37 #if HAVE_STDLIB_H
38 #include <stdlib.h>
39 #endif
40 #if HAVE_SYS_TYPES_H
41 #include <sys/types.h>
42 #endif
43 #if HAVE_CTYPE_H
44 #include <ctype.h>
45 #endif
46 #if HAVE_GNUMALLOC_H
47 #include <gnumalloc.h>
48 #elif HAVE_MALLOC_H
49 #include <malloc.h>
50 #endif
51 #if HAVE_MEMORY_H
52 #include <memory.h>
53 #endif
54 #if HAVE_STRING_H
55 #include <string.h>
56 #endif
57 #if HAVE_STRINGS_H
58 #include <strings.h>
59 #endif
60 #if HAVE_BSTRING_H
61 #include <bstring.h>
62 #endif
63 #if HAVE_SYS_SOCKET_H
64 #include <sys/socket.h>
65 #endif
66 #if HAVE_NETINET_IN_H
67 #include <netinet/in.h>
68 #endif
69 #if HAVE_ARPA_INET_H
70 #include <arpa/inet.h>
71 #endif
72 #if HAVE_SYS_TIME_H
73 #include <sys/time.h>
74 #endif
75 #if HAVE_NETDB_H
76 #include <netdb.h>
77 #endif
78
79 #include "asn1.h"
80 #include "snmp.h"
81 #include "snmp_api_error.h"
82 #include "snmp_error.h"
83 #include "snmp_pdu.h"
84 #include "snmp_vars.h"
85
86 #include "util.h"
87
88 /*
89 * RFC 1908: Coexistence between SNMPv1 and SNMPv2
90 *
91 * These convert:
92 *
93 * V1 PDUs from an ** AGENT ** to V2 PDUs for an ** MANAGER **
94 * V2 PDUs from an ** MANAGER ** to V1 PDUs for an ** AGENT **
95 *
96 * We will never convert V1 information from a manager into V2 PDUs. V1
97 * requests are always honored by V2 agents, and the responses will be
98 * valid V1 responses. (I think. XXXXX)
99 *
100 */
101 int
102 snmp_coexist_V2toV1(struct snmp_pdu *PDU)
103 {
104 /* Per 3.1.1:
105 */
106 switch (PDU->command) {
107
108 case SNMP_PDU_GET:
109 case SNMP_PDU_GETNEXT:
110 #if SNMP_PDU_SET
111 case SNMP_PDU_SET:
112 #endif
113 return (1);
114 break;
115
116 case SNMP_PDU_GETBULK:
117 PDU->non_repeaters = 0;
118 PDU->max_repetitions = 0;
119 PDU->command = SNMP_PDU_GETNEXT;
120 return (1);
121 break;
122
123 default:
124 snmplib_debug(2, "Unable to translate PDU %d to SNMPv1!\n", PDU->command);
125 snmp_set_api_error(SNMPERR_PDU_TRANSLATION);
126 return (0);
127 }
128 }