From 9285b403d9fa15b1fb4aff43af5bfcfc1b7649d9 Mon Sep 17 00:00:00 2001 From: roberto Date: Sun, 5 Sep 2010 12:47:21 +0200 Subject: [PATCH] SNMP test --- snmp.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ uwsgi.c | 1 + uwsgiconfig.py | 2 +- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/snmp.c b/snmp.c index bae8532a..a808ca42 100644 --- a/snmp.c +++ b/snmp.c @@ -55,6 +55,9 @@ void manage_snmp(int fd, uint8_t * buffer, int size, struct sockaddr_in *client_ return; ptr++; +#ifdef UWSGI_DEBUG + uwsgi_debug("SNMP packet size: %d\n", size); +#endif @@ -68,6 +71,9 @@ void manage_snmp(int fd, uint8_t * buffer, int size, struct sockaddr_in *client_ return; ptr += ptrdelta; +#ifdef UWSGI_DEBUG + uwsgi_debug("SNMP version: %d\n", version); +#endif @@ -90,11 +96,16 @@ void manage_snmp(int fd, uint8_t * buffer, int size, struct sockaddr_in *client_ if (memcmp(ptr, uwsgi.shared->snmp_community, community_len)) return; +#ifdef UWSGI_DEBUG + uwsgi_debug("SNMP community: %.*s\n", community_len, ptr); +#endif + ptr += community_len; // check for get request if (*ptr != SNMP_GET) return; + *ptr = SNMP_RES; ptr++; seq1 = ptr; @@ -110,20 +121,32 @@ void manage_snmp(int fd, uint8_t * buffer, int size, struct sockaddr_in *client_ if (*ptr != SNMP_INTEGER) return; ptr++; + +uwsgi_log("oops %p\n", ptr); ptrdelta = get_snmp_integer(ptr, &request_id); +uwsgi_log("oops %p\n", ptr); if (ptrdelta <= 0) return; +#ifdef UWSGI_DEBUG + uwsgi_debug("SNMP request id: %d %p\n", request_id, ptr); +#endif + // check here if (ptr + ptrdelta >= buffer + size) return; ptr += ptrdelta; +uwsgi_log("oops %d %p\n", ptrdelta, ptr); + // get error if (*ptr != SNMP_INTEGER) return; + +uwsgi_log("oops 2\n"); + ptr++; ptrdelta = get_snmp_integer(ptr, &snmp_int); if (ptrdelta <= 0) @@ -132,6 +155,10 @@ void manage_snmp(int fd, uint8_t * buffer, int size, struct sockaddr_in *client_ return; if (snmp_int != 0) return; + +#ifdef UWSGI_DEBUG + uwsgi_debug("SNMP int [0]: %d\n", snmp_int); +#endif ptr += ptrdelta; // get index @@ -148,6 +175,10 @@ void manage_snmp(int fd, uint8_t * buffer, int size, struct sockaddr_in *client_ return; ptr += ptrdelta; +#ifdef UWSGI_DEBUG + uwsgi_debug("SNMP int [1]: %d\n", snmp_int); +#endif + // check for sequence if (*ptr != SNMP_SEQUENCE) return; @@ -173,6 +204,10 @@ void manage_snmp(int fd, uint8_t * buffer, int size, struct sockaddr_in *client_ seq3 = ptr; ptr++; +#ifdef UWSGI_DEBUG + uwsgi_debug("SNMP ASN len: %d\n", asnlen); +#endif + // is it an OID ? if (*ptr != SNMP_OID) return; @@ -253,17 +288,28 @@ static int get_snmp_integer(uint8_t * ptr, uint64_t * val) { if (tlen > 4) return -1; +#ifdef UWSGI_DEBUG + uwsgi_debug("SNMP get integer TLEN %d\n", tlen); +#endif j = 0; #ifdef __BIG_ENDIAN__ for (i = 0; i < tlen; i++) { #else for (i = tlen - 1; i >= 0; i--) { +#ifdef UWSGI_DEBUG + uwsgi_debug("SNMP get integer iter %d %p\n", i, ptr); +#endif + #endif val[j] = ptr[1 + i]; j++; } +#ifdef UWSGI_DEBUG + uwsgi_debug("SNMP get integer iter %d %p\n", i, ptr); +#endif + return tlen + 1; } diff --git a/uwsgi.c b/uwsgi.c index e5197efe..cc4e78c9 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -1386,6 +1386,7 @@ int main(int argc, char *argv[], char *envp[]) { #ifdef UWSGI_SNMP else if (uwsgi.wsgi_req->buffer[0] == 0x30 && uwsgi.snmp) { manage_snmp(uwsgi_poll.fd, (uint8_t *) uwsgi.wsgi_req->buffer, rlen, &udp_client); + uwsgi_log("done\n"); } #endif else { diff --git a/uwsgiconfig.py b/uwsgiconfig.py index 81297477..e4a86a11 100644 --- a/uwsgiconfig.py +++ b/uwsgiconfig.py @@ -28,7 +28,7 @@ STACKLESS=False PLUGINS = [] USWALLOW=False UNBIT=False -DEBUG=False +DEBUG=True EMBED_PLUGINS=True UWSGI_BIN_NAME = 'uwsgi' UWSGI_PLUGIN_DIR = '.'