socsvn commit: r271800 - in soc2014/shonali/head/contrib/bsnmp: snmp_target snmpd
shonali at FreeBSD.org
shonali at FreeBSD.org
Sun Aug 3 17:34:47 UTC 2014
Author: shonali
Date: Sun Aug 3 17:34:45 2014
New Revision: 271800
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271800
Log:
Made changes to struct target_address in snmpmod.h & correspondingly modified target_snmp.c & trap.c
Modified:
soc2014/shonali/head/contrib/bsnmp/snmp_target/target_snmp.c
soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h
soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c
Modified: soc2014/shonali/head/contrib/bsnmp/snmp_target/target_snmp.c
==============================================================================
--- soc2014/shonali/head/contrib/bsnmp/snmp_target/target_snmp.c Sun Aug 3 16:45:07 2014 (r271799)
+++ soc2014/shonali/head/contrib/bsnmp/snmp_target/target_snmp.c Sun Aug 3 17:34:45 2014 (r271800)
@@ -163,15 +163,27 @@
case LEAF_snmpTargetAddrTDomain:
return (SNMP_ERR_INCONS_VALUE);
case LEAF_snmpTargetAddrTAddress:
- if (val->v.octetstring.len != SNMP_UDP_ADDR_SIZ)
+ if (val->v.octetstring.len != SNMP_UDP_ADDR_SIZ && val->v.octetstring.len != SNMP_UDP_ADDRv6_SIZ)
return (SNMP_ERR_INCONS_VALUE);
- ctx->scratch->ptr1 = malloc(SNMP_UDP_ADDR_SIZ);
- if (ctx->scratch->ptr1 == NULL)
- return (SNMP_ERR_GENERR);
- memcpy(ctx->scratch->ptr1, addrs->address,
- SNMP_UDP_ADDR_SIZ);
- memcpy(addrs->address, val->v.octetstring.octets,
- SNMP_UDP_ADDR_SIZ);
+ if (val->v.octetstring.len == SNMP_UDP_ADDR_SIZ){
+ ctx->scratch->ptr1 = malloc(SNMP_UDP_ADDR_SIZ);
+ if (ctx->scratch->ptr1 == NULL)
+ return (SNMP_ERR_GENERR);
+ memcpy(ctx->scratch->ptr1, addrs->address.address,
+ SNMP_UDP_ADDR_SIZ);
+ memcpy(addrs->address.address, val->v.octetstring.octets,
+ SNMP_UDP_ADDR_SIZ);
+ }
+
+ else if (val->v.octetstring.len == SNMP_UDP_ADDRv6_SIZ){
+ ctx->scratch->ptr1 = malloc(SNMP_UDP_ADDRv6_SIZ);
+ if (ctx->scratch->ptr1 == NULL)
+ return (SNMP_ERR_GENERR);
+ memcpy(ctx->scratch->ptr1, addrs->address.address6,
+ SNMP_UDP_ADDRv6_SIZ);
+ memcpy(addrs->address.address6, val->v.octetstring.octets,
+ SNMP_UDP_ADDRv6_SIZ);
+ }
break;
case LEAF_snmpTargetAddrTagList:
@@ -221,7 +233,7 @@
val->v.integer != RowStatus_destroy)
return (SNMP_ERR_INCONS_VALUE);
if (val->v.integer == RowStatus_active &&
- (addrs->address[0] == 0 ||
+ ((addrs->address.address[0] == 0 && addrs->address.address6[0] == 0) ||
strlen(addrs->taglist) == 0 ||
strlen(addrs->paramname) == 0))
return (SNMP_ERR_INCONS_VALUE);
@@ -268,10 +280,17 @@
return (SNMP_ERR_GENERR);
switch (val->var.subs[sub - 1]) {
- case LEAF_snmpTargetAddrTAddress:
- memcpy(addrs->address, ctx->scratch->ptr1,
+ case LEAF_snmpTargetAddrTAddress:
+ if (val->var.len == SNMP_UDP_ADDR_SIZ) {
+ memcpy(addrs->address.address, ctx->scratch->ptr1,
SNMP_UDP_ADDR_SIZ);
free(ctx->scratch->ptr1);
+ }
+ else if (val->var.len == SNMP_UDP_ADDRv6_SIZ) {
+ memcpy(addrs->address.address6, ctx->scratch->ptr1,
+ SNMP_UDP_ADDRv6_SIZ);
+ free(ctx->scratch->ptr1);
+ }
break;
case LEAF_snmpTargetAddrTagList:
@@ -310,7 +329,10 @@
case LEAF_snmpTargetAddrTDomain:
return (oid_get(val, &oid_udp_domain));
case LEAF_snmpTargetAddrTAddress:
- return (string_get(val, addrs->address, SNMP_UDP_ADDR_SIZ));
+ if (val->var.len == SNMP_UDP_ADDR_SIZ)
+ return (string_get(val, addrs->address.address, SNMP_UDP_ADDR_SIZ));
+ if (val->var.len == SNMP_UDP_ADDRv6_SIZ)
+ return (string_get(val, addrs->address.address6, SNMP_UDP_ADDRv6_SIZ));
case LEAF_snmpTargetAddrTimeout:
val->v.integer = addrs->timeout;
break;
Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h
==============================================================================
--- soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h Sun Aug 3 16:45:07 2014 (r271799)
+++ soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h Sun Aug 3 17:34:45 2014 (r271800)
@@ -473,11 +473,19 @@
#define SNMP_UDP_ADDR_SIZ 6
#define SNMP_UDP_ADDRv6_SIZ 18
#define SNMP_TAG_SIZ (255 + 1)
+
+enum target_domain {
+ TransportAddressIPv4 = 0,
+ TransportAddressIPv6 = 1,
+};
struct target_address {
char name[SNMP_ADM_STR32_SIZ];
- uint8_t address[SNMP_UDP_ADDR_SIZ];
- uint8_t address6[SNMP_UDP_ADDRv6_SIZ];
+ enum target_domain domain;
+ union address {
+ uint8_t address[SNMP_UDP_ADDR_SIZ];
+ uint8_t address6[SNMP_UDP_ADDRv6_SIZ];
+ }address;
int32_t timeout;
int32_t retry;
char taglist[SNMP_TAG_SIZ];
Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c
==============================================================================
--- soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Sun Aug 3 16:45:07 2014 (r271799)
+++ soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Sun Aug 3 17:34:45 2014 (r271800)
@@ -770,19 +770,12 @@
target_activate_address(struct target_address *addrs)
{
/* XXX - IPv4/IPv6 - Check if there is a better way of determining address type */
- int len;
- if(addrs->address == NULL && addrs->address6 != NULL)
- len = 18;
- else if (addrs->address != NULL && addrs->address6 == NULL)
- len = 6;
- else
- syslog(LOG_ERR, "Target address %s does not exist", addrs->name);
struct sockaddr_in sa;
struct sockaddr_in6 sa6;
- switch (len) {
+ switch (addrs->domain) {
- case 6:
+ case TransportAddressIPv4 :
if ((addrs->socket = socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
syslog(LOG_ERR, "socket(UDP): %m");
return (SNMP_ERR_RES_UNAVAIL);
@@ -793,11 +786,11 @@
sa.sin_len = sizeof(sa);
sa.sin_family = AF_INET;
- sa.sin_addr.s_addr = htonl((addrs->address[0] << 24) |
- (addrs->address[1] << 16) | (addrs->address[2] << 8) |
- (addrs->address[3] << 0));
- sa.sin_port = htons(addrs->address[4]) << 8 |
- htons(addrs->address[5]) << 0;
+ sa.sin_addr.s_addr = htonl((addrs->address.address[0] << 24) |
+ (addrs->address.address[1] << 16) | (addrs->address.address[2] << 8) |
+ (addrs->address.address[3] << 0));
+ sa.sin_port = htons(addrs->address.address[4]) << 8 |
+ htons(addrs->address.address[5]) << 0;
if (connect(addrs->socket, (struct sockaddr *)&sa, sa.sin_len) == -1) {
syslog(LOG_ERR, "connect(%s,%u): %m",
@@ -807,7 +800,7 @@
}
- case 18:
+ case TransportAddressIPv6 :
if ((addrs->socket = socket(PF_INET6, SOCK_DGRAM, 0)) == -1) {
syslog(LOG_ERR, "socket(UDP): %m");
return (SNMP_ERR_RES_UNAVAIL);
@@ -818,13 +811,13 @@
sa6.sin6_len = sizeof(sa6);
sa6.sin6_family = AF_INET6;
/* Host to network byte order not reqd - check */
- *(sa6.sin6_addr.s6_addr) = (addrs->address6[0] << 120) | (addrs->address6[1] << 112) | (addrs->address6[2] << 104) |
- (addrs->address6[3] << 96) | (addrs->address6[4] << 88) |
- (addrs->address6[5] << 80) | (addrs->address6[6] << 72) | (addrs->address6[7] << 64) | (addrs->address6[8] << 56) |
- (addrs->address6[9] << 48) | (addrs->address6[10] << 40) | (addrs->address6[11] << 32) | (addrs->address6[12] << 24) |
- (addrs->address6[13] << 16) | (addrs->address6[14] << 8) | addrs->address6[15];
- sa6.sin6_port = htons(addrs->address6[16]) << 8 |
- htons(addrs->address6[17]) << 0;
+ *(sa6.sin6_addr.s6_addr) = (addrs->address.address6[0] << 120) | (addrs->address.address6[1] << 112) | (addrs->address.address6[2] << 104) |
+ (addrs->address.address6[3] << 96) | (addrs->address.address6[4] << 88) |
+ (addrs->address.address6[5] << 80) | (addrs->address.address6[6] << 72) | (addrs->address.address6[7] << 64) | (addrs->address.address6[8] << 56) |
+ (addrs->address.address6[9] << 48) | (addrs->address.address6[10] << 40) | (addrs->address.address6[11] << 32) | (addrs->address.address6[12] << 24) |
+ (addrs->address.address6[13] << 16) | (addrs->address.address6[14] << 8) | addrs->address.address6[15];
+ sa6.sin6_port = htons(addrs->address.address6[16]) << 8 |
+ htons(addrs->address.address6[17]) << 0;
char dst[INET6_ADDRSTRLEN];
inet_ntop(AF_INET6,&(sa6.sin6_addr), dst, INET6_ADDRSTRLEN);
if (connect(addrs->socket, (struct sockaddr *)&sa6, sa6.sin6_len) == -1) {
More information about the svn-soc-all
mailing list