Merge branch 'master' of ssh://git.sv.gnu.org:/srv/git/lwip

This commit is contained in:
Dirk Ziegelmeier 2016-01-04 21:27:39 +01:00
commit e336f877c2
8 changed files with 48 additions and 305 deletions

View File

@ -1222,7 +1222,7 @@ lwip_netconn_do_connect(struct api_msg_msg *msg)
}
/**
* Connect a pcb contained inside a netconn
* Disconnect a pcb contained inside a netconn
* Only used for UDP netconns.
* Called from netconn_disconnect.
*

View File

@ -53,7 +53,7 @@ extern "C" {
#define SNMP_ASN1_CLASS_MASK 0xC0
#define SNMP_ASN1_CONTENTTYPE_MASK 0x20
#define SNMP_ASN1_DATATYPE_MASK 0x1F
#define SNMP_ASN1_DATATYPE_EXTENDED 0x1F // DataType indicating that datatype is encoded in following bytes
#define SNMP_ASN1_DATATYPE_EXTENDED 0x1F /* DataType indicating that datatype is encoded in following bytes */
/* context specific (SNMP) tags (from SNMP spec. RFC1157) */
#define SNMP_ASN1_CONTEXT_PDU_GET_REQ 0

View File

@ -40,6 +40,8 @@
#include "lwip/apps/snmp.h"
#include "lwip/apps/snmp_core.h"
#include "snmp_core_priv.h"
#include <string.h>
#if (LWIP_SNMP && (SNMP_TRAP_DESTINATIONS<=0))
#error "If you want to use SNMP, you have to define SNMP_TRAP_DESTINATIONS>=1 in your lwipopts.h"
@ -210,13 +212,13 @@ snmp_ip6_to_oid(const ip6_addr_t *ip, u32_t *oid)
u8_t
snmp_ip_port_to_oid(const ip_addr_t *ip, u16_t port, u32_t *oid)
{
u8_t index;
u8_t idx;
index = snmp_ip_to_oid(ip, oid);
oid[index] = port;
index++;
idx = snmp_ip_to_oid(ip, oid);
oid[idx] = port;
idx++;
return index;
return idx;
}
/**
@ -310,25 +312,25 @@ snmp_oid_to_ip(const u32_t *oid, u8_t oid_len, ip_addr_t *ip)
u8_t
snmp_oid_to_ip_port(const u32_t *oid, u8_t oid_len, ip_addr_t *ip, u16_t *port)
{
u8_t index = 0;
u8_t idx = 0;
/* InetAddressType + InetAddress */
index += snmp_oid_to_ip(&oid[index], oid_len-index, ip);
if(index == 0) {
idx += snmp_oid_to_ip(&oid[idx], oid_len-idx, ip);
if(idx == 0) {
return 0;
}
/* InetPortNumber */
if(oid_len < (index+1)) {
if(oid_len < (idx+1)) {
return 0;
}
if(oid[index] > 0xffff) {
if(oid[idx] > 0xffff) {
return 0;
}
*port = (u16_t)oid[index];
index++;
*port = (u16_t)oid[idx];
idx++;
return index;
return idx;
}
#endif /* LWIP_IPV4 || LWIP_IPV6 */

View File

@ -2073,21 +2073,21 @@ tcp_ConnectionTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8
ip_addr_t local_ip, remote_ip;
u16_t local_port, remote_port;
struct tcp_pcb *pcb;
u8_t index = 0;
u8_t idx = 0;
u8_t i;
struct tcp_pcb ** const tcp_pcb_nonlisten_lists[] = {&tcp_bound_pcbs, &tcp_active_pcbs, &tcp_tw_pcbs};
LWIP_UNUSED_ARG(value_len);
/* tcpConnectionLocalAddressType + tcpConnectionLocalAddress + tcpConnectionLocalPort */
index += snmp_oid_to_ip_port(&row_oid[index], row_oid_len-index, &local_ip, &local_port);
if(index == 0) {
idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len-idx, &local_ip, &local_port);
if(idx == 0) {
return SNMP_ERR_NOSUCHINSTANCE;
}
/* tcpConnectionRemAddressType + tcpConnectionRemAddress + tcpConnectionRemPort */
index += snmp_oid_to_ip_port(&row_oid[index], row_oid_len-index, &remote_ip, &remote_port);
if(index == 0) {
idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len-idx, &remote_ip, &remote_port);
if(idx == 0) {
return SNMP_ERR_NOSUCHINSTANCE;
}
@ -2132,17 +2132,17 @@ tcp_ConnectionTable_get_next_cell_instance_and_value(const u32_t* column, struct
pcb = *tcp_pcb_nonlisten_lists[i];
while (pcb != NULL) {
u8_t index = 0;
u8_t idx = 0;
u32_t test_oid[LWIP_ARRAYSIZE(result_temp)];
/* tcpConnectionLocalAddressType + tcpConnectionLocalAddress + tcpConnectionLocalPort */
index += snmp_ip_port_to_oid(&pcb->local_ip, pcb->local_port, &test_oid[index]);
idx += snmp_ip_port_to_oid(&pcb->local_ip, pcb->local_port, &test_oid[idx]);
/* tcpConnectionRemAddressType + tcpConnectionRemAddress + tcpConnectionRemPort */
index += snmp_ip_port_to_oid(&pcb->remote_ip, pcb->remote_port, &test_oid[index]);
idx += snmp_ip_port_to_oid(&pcb->remote_ip, pcb->remote_port, &test_oid[idx]);
/* check generated OID: is it a candidate for the next one? */
snmp_next_oid_check(&state, test_oid, index, pcb);
snmp_next_oid_check(&state, test_oid, idx, pcb);
pcb = pcb->next;
}
@ -2182,13 +2182,13 @@ tcp_ListenerTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t
ip_addr_t local_ip;
u16_t local_port;
struct tcp_pcb_listen *pcb;
u8_t index = 0;
u8_t idx = 0;
LWIP_UNUSED_ARG(value_len);
/* tcpListenerLocalAddressType + tcpListenerLocalAddress + tcpListenerLocalPort */
index += snmp_oid_to_ip_port(&row_oid[index], row_oid_len-index, &local_ip, &local_port);
if(index == 0) {
idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len-idx, &local_ip, &local_port);
if(idx == 0) {
return SNMP_ERR_NOSUCHINSTANCE;
}
@ -2223,14 +2223,14 @@ tcp_ListenerTable_get_next_cell_instance_and_value(const u32_t* column, struct s
/* iterate over all possible OIDs to find the next one */
pcb = tcp_listen_pcbs.listen_pcbs;
while (pcb != NULL) {
u8_t index = 0;
u8_t idx = 0;
u32_t test_oid[LWIP_ARRAYSIZE(result_temp)];
/* tcpListenerLocalAddressType + tcpListenerLocalAddress + tcpListenerLocalPort */
index += snmp_ip_port_to_oid(&pcb->local_ip, pcb->local_port, &test_oid[index]);
idx += snmp_ip_port_to_oid(&pcb->local_ip, pcb->local_port, &test_oid[idx]);
/* check generated OID: is it a candidate for the next one? */
snmp_next_oid_check(&state, test_oid, index, NULL);
snmp_next_oid_check(&state, test_oid, idx, NULL);
pcb = pcb->next;
}
@ -2307,27 +2307,27 @@ udp_endpointTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t
ip_addr_t local_ip, remote_ip;
u16_t local_port, remote_port;
struct udp_pcb *pcb;
int index = 0;
u8_t idx = 0;
LWIP_UNUSED_ARG(value_len);
/* udpEndpointLocalAddressType + udpEndpointLocalAddress + udpEndpointLocalPort */
index += snmp_oid_to_ip_port(&row_oid[index], row_oid_len-index, &local_ip, &local_port);
if(index == 0) {
idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len-idx, &local_ip, &local_port);
if(idx == 0) {
return SNMP_ERR_NOSUCHINSTANCE;
}
/* udpEndpointRemoteAddressType + udpEndpointRemoteAddress + udpEndpointRemotePort */
index += snmp_oid_to_ip_port(&row_oid[index], row_oid_len-index, &remote_ip, &remote_port);
if(index == 0) {
idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len-idx, &remote_ip, &remote_port);
if(idx == 0) {
return SNMP_ERR_NOSUCHINSTANCE;
}
/* udpEndpointInstance */
if(row_oid_len < (index+1)) {
if(row_oid_len < (idx+1)) {
return SNMP_ERR_NOSUCHINSTANCE;
}
if(row_oid[index] != 0) {
if(row_oid[idx] != 0) {
return SNMP_ERR_NOSUCHINSTANCE;
}
@ -2368,19 +2368,19 @@ udp_endpointTable_get_next_cell_instance_and_value(const u32_t* column, struct s
pcb = udp_pcbs;
while (pcb != NULL) {
u32_t test_oid[LWIP_ARRAYSIZE(result_temp)];
u8_t index = 0;
u8_t idx = 0;
/* udpEndpointLocalAddressType + udpEndpointLocalAddress + udpEndpointLocalPort */
index += snmp_ip_port_to_oid(&pcb->local_ip, pcb->local_port, &test_oid[index]);
idx += snmp_ip_port_to_oid(&pcb->local_ip, pcb->local_port, &test_oid[idx]);
/* udpEndpointRemoteAddressType + udpEndpointRemoteAddress + udpEndpointRemotePort */
index += snmp_ip_port_to_oid(&pcb->remote_ip, pcb->remote_port, &test_oid[index]);
idx += snmp_ip_port_to_oid(&pcb->remote_ip, pcb->remote_port, &test_oid[idx]);
test_oid[index] = 0; /* udpEndpointInstance */
index++;
test_oid[idx] = 0; /* udpEndpointInstance */
idx++;
/* check generated OID: is it a candidate for the next one? */
snmp_next_oid_check(&state, test_oid, index, NULL);
snmp_next_oid_check(&state, test_oid, idx, NULL);
pcb = pcb->next;
}

View File

@ -36,6 +36,7 @@
#include "snmp_pbuf_stream.h"
#include "lwip/def.h"
#include <string.h>
err_t
snmp_pbuf_stream_init(struct snmp_pbuf_stream* pbuf_stream, struct pbuf* p, u16_t offset, u16_t length)

View File

@ -36,6 +36,7 @@
#include "lwip/apps/snmp_core.h"
#include "lwip/apps/snmp_table.h"
#include <string.h>
snmp_err_t snmp_table_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance)
{

View File

@ -35,6 +35,7 @@
#include "lwip/apps/snmp_core.h"
#include "lwip/mem.h"
#include "lwip/sys.h"
#include <string.h>
struct threadsync_data
{

View File

@ -118,68 +118,6 @@ snmp_send_trap(const struct snmp_obj_id *device_enterprise_oid, s32_t generic_tr
LWIP_UNUSED_ARG(generic_trap);
LWIP_UNUSED_ARG(specific_trap);
return ERR_OK;
#if 0
//struct snmp_trap_dst *td;
//struct netif *dst_if;
//const ip_addr_t* dst_ip;
//struct pbuf *p;
//u16_t i,tot_len;
//err_t err = ERR_OK;
//for (i = 0, td = &trap_dst[0]; i < SNMP_TRAP_DESTINATIONS; i++, td++) {
// if ((td->enable != 0) && !ip_addr_isany(&td->dip)) {
// /* network order trap destination */
// ip_addr_copy(trap_msg.dip, td->dip);
// /* lookup current source address for this dst */
// ip_route_get_local_ip(IP_IS_V6(trap_msg.lip), trap_msg.lip,
// &td->dip, dst_if, dst_ip);
// if ((dst_if != NULL) && (dst_ip != NULL)) {
// trap_msg.sip_raw_len = (IP_IS_V6_VAL(*dst_ip) ? 16 : 4);
// MEMCPY(trap_msg.sip_raw, dst_ip, trap_msg.sip_raw_len);
// if (device_enterprise_oid == NULL) {
// trap_msg.enterprise = snmp_get_device_enterprise_oid();
// } else {
// trap_msg.enterprise = device_enterprise_oid;
// }
// trap_msg.gen_trap = generic_trap;
// if (generic_trap == SNMP_GENTRAP_ENTERPRISE_SPECIFIC) {
// trap_msg.spc_trap = specific_trap;
// } else {
// trap_msg.spc_trap = 0;
// }
// MIB2_COPY_SYSUPTIME_TO(&trap_msg.ts);
// /* pass 0, calculate length fields */
// tot_len = snmp_varbind_list_sum(&trap_msg.outvb);
// tot_len = snmp_trap_header_sum(&trap_msg, tot_len);
// /* allocate pbuf(s) */
// p = pbuf_alloc(PBUF_TRANSPORT, tot_len, PBUF_RAM);
// if (p != NULL) {
// u16_t ofs;
// /* pass 1, encode packet ino the pbuf(s) */
// ofs = snmp_trap_header_enc(&trap_msg, p);
// snmp_varbind_list_enc(&trap_msg.outvb, p, ofs);
// snmp_stats.outtraps++;
// snmp_stats.outpkts++;
// /** send to the TRAP destination */
// snmp_sendto(trap_msg.handle, p, &trap_msg.dip, SNMP_TRAP_PORT);
// } else {
// err = ERR_MEM;
// }
// } else {
// /* routing error */
// err = ERR_RTE;
// }
// }
//}
//return err;
#endif
}
err_t
@ -208,204 +146,4 @@ snmp_authfail_trap(void)
}
}
#if 0
//extern struct snmp_msg_trap trap_msg;
//struct snmp_msg_trap
//{
// /* Communication handle */
// void *handle;
// /* local IP address */
// ip_addr_t *lip;
// /* destination IP address */
// ip_addr_t dip;
//
// /* source enterprise ID (sysObjectID) */
// const struct snmp_obj_id *enterprise;
// /* source IP address, raw network order format */
// u8_t sip_raw[4];
// /* source IP address length */
// u8_t sip_raw_len;
// /* generic trap code */
// u32_t gen_trap;
// /* specific trap code */
// u32_t spc_trap;
// /* timestamp */
// u32_t ts;
// ///* list of variable bindings to output */
// //struct snmp_varbind_root outvb;
// ///* output trap lengths used in ASN encoding */
// //struct snmp_trap_header_lengths thl;
//};
/** output response message header length fields */
//struct snmp_trap_header_lengths
//{
// /* encoding timestamp length length */
// u8_t tslenlen;
// /* encoding specific-trap length length */
// u8_t strplenlen;
// /* encoding generic-trap length length */
// u8_t gtrplenlen;
// /* encoding agent-addr length length */
// u8_t aaddrlenlen;
// /* encoding enterprise-id length length */
// u8_t eidlenlen;
// /* encoding pdu length length */
// u8_t pdulenlen;
// /* encoding community length length */
// u8_t comlenlen;
// /* encoding version length length */
// u8_t verlenlen;
// /* encoding sequence length length */
// u8_t seqlenlen;
//
// /* encoding timestamp length */
// u16_t tslen;
// /* encoding specific-trap length */
// u16_t strplen;
// /* encoding generic-trap length */
// u16_t gtrplen;
// /* encoding agent-addr length */
// u16_t aaddrlen;
// /* encoding enterprise-id length */
// u16_t eidlen;
// /* encoding pdu length */
// u16_t pdulen;
// /* encoding community length */
// u16_t comlen;
// /* encoding version length */
// u16_t verlen;
// /* encoding sequence length */
// u16_t seqlen;
//};
/**
* Sums trap header field lengths from tail to head and
* returns trap_header_lengths for second encoding pass.
*
* @param vb_len varbind-list length
* @param thl points to returned header lengths
* @return the required length for encoding the trap header
*/
//static u16_t
//snmp_trap_header_sum(struct snmp_msg_trap *m_trap, u16_t vb_len)
//{
// u16_t tot_len;
// struct snmp_trap_header_lengths *thl;
//
// thl = &m_trap->thl;
// tot_len = vb_len;
//
// snmp_asn1_enc_u32t_cnt(m_trap->ts, &thl->tslen);
// snmp_asn1_enc_length_cnt(thl->tslen, &thl->tslenlen);
// tot_len += 1 + thl->tslen + thl->tslenlen;
//
// snmp_asn1_enc_s32t_cnt(m_trap->spc_trap, &thl->strplen);
// snmp_asn1_enc_length_cnt(thl->strplen, &thl->strplenlen);
// tot_len += 1 + thl->strplen + thl->strplenlen;
//
// snmp_asn1_enc_s32t_cnt(m_trap->gen_trap, &thl->gtrplen);
// snmp_asn1_enc_length_cnt(thl->gtrplen, &thl->gtrplenlen);
// tot_len += 1 + thl->gtrplen + thl->gtrplenlen;
//
// thl->aaddrlen = m_trap->sip_raw_len;
// snmp_asn1_enc_length_cnt(thl->aaddrlen, &thl->aaddrlenlen);
// tot_len += 1 + thl->aaddrlen + thl->aaddrlenlen;
//
// snmp_asn1_enc_oid_cnt(&m_trap->enterprise->id[0], m_trap->enterprise->len, &thl->eidlen);
// snmp_asn1_enc_length_cnt(thl->eidlen, &thl->eidlenlen);
// tot_len += 1 + thl->eidlen + thl->eidlenlen;
//
// thl->pdulen = tot_len;
// snmp_asn1_enc_length_cnt(thl->pdulen, &thl->pdulenlen);
// tot_len += 1 + thl->pdulenlen;
//
// thl->comlen = (u16_t)strlen(snmp_community_trap);
// snmp_asn1_enc_length_cnt(thl->comlen, &thl->comlenlen);
// tot_len += 1 + thl->comlenlen + thl->comlen;
//
// snmp_asn1_enc_s32t_cnt(snmp_version, &thl->verlen);
// snmp_asn1_enc_length_cnt(thl->verlen, &thl->verlenlen);
// tot_len += 1 + thl->verlen + thl->verlenlen;
//
// thl->seqlen = tot_len;
// snmp_asn1_enc_length_cnt(thl->seqlen, &thl->seqlenlen);
// tot_len += 1 + thl->seqlenlen;
//
// return tot_len;
//}
/**
* Encodes trap header from head to tail.
*/
//static u16_t
//snmp_trap_header_enc(struct snmp_msg_trap *m_trap, struct pbuf *p)
//{
// u16_t ofs;
//
// ofs = 0;
// snmp_asn1_enc_type(p, ofs, SNMP_ASN1_TYPE_SEQUENCE);
// ofs += 1;
// snmp_asn1_enc_length(p, ofs, m_trap->thl.seqlen);
// ofs += m_trap->thl.seqlenlen;
//
// snmp_asn1_enc_type(p, ofs, SNMP_ASN1_TYPE_INTEGER);
// ofs += 1;
// snmp_asn1_enc_length(p, ofs, m_trap->thl.verlen);
// ofs += m_trap->thl.verlenlen;
// snmp_asn1_enc_s32t(p, ofs, m_trap->thl.verlen, snmp_version);
// ofs += m_trap->thl.verlen;
//
// snmp_asn1_enc_type(p, ofs, SNMP_ASN1_TYPE_OCTET_STRING);
// ofs += 1;
// snmp_asn1_enc_length(p, ofs, m_trap->thl.comlen);
// ofs += m_trap->thl.comlenlen;
// snmp_asn1_enc_raw(p, ofs, m_trap->thl.comlen, (const u8_t *)&snmp_community_trap[0]);
// ofs += m_trap->thl.comlen;
//
// snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_CLASS_CONTEXT | SNMP_ASN1_CONTENTTYPE_CONSTRUCTED | SNMP_ASN1_CONTEXT_PDU_TRAP));
// ofs += 1;
// snmp_asn1_enc_length(p, ofs, m_trap->thl.pdulen);
// ofs += m_trap->thl.pdulenlen;
//
// snmp_asn1_enc_type(p, ofs, SNMP_ASN1_TYPE_OBJECT_ID);
// ofs += 1;
// snmp_asn1_enc_length(p, ofs, m_trap->thl.eidlen);
// ofs += m_trap->thl.eidlenlen;
// snmp_asn1_enc_oid(p, ofs, m_trap->enterprise->len, &m_trap->enterprise->id[0]);
// ofs += m_trap->thl.eidlen;
//
// snmp_asn1_enc_type(p, ofs, SNMP_ASN1_TYPE_IPADDR);
// ofs += 1;
// snmp_asn1_enc_length(p, ofs, m_trap->thl.aaddrlen);
// ofs += m_trap->thl.aaddrlenlen;
// snmp_asn1_enc_raw(p, ofs, m_trap->thl.aaddrlen, &m_trap->sip_raw[0]);
// ofs += m_trap->thl.aaddrlen;
//
// snmp_asn1_enc_type(p, ofs, SNMP_ASN1_TYPE_INTEGER);
// ofs += 1;
// snmp_asn1_enc_length(p, ofs, m_trap->thl.gtrplen);
// ofs += m_trap->thl.gtrplenlen;
// snmp_asn1_enc_u32t(p, ofs, m_trap->thl.gtrplen, m_trap->gen_trap);
// ofs += m_trap->thl.gtrplen;
//
// snmp_asn1_enc_type(p, ofs, SNMP_ASN1_TYPE_INTEGER);
// ofs += 1;
// snmp_asn1_enc_length(p, ofs, m_trap->thl.strplen);
// ofs += m_trap->thl.strplenlen;
// snmp_asn1_enc_u32t(p, ofs, m_trap->thl.strplen, m_trap->spc_trap);
// ofs += m_trap->thl.strplen;
//
// snmp_asn1_enc_type(p, ofs, SNMP_ASN1_TYPE_TIMETICKS);
// ofs += 1;
// snmp_asn1_enc_length(p, ofs, m_trap->thl.tslen);
// ofs += m_trap->thl.tslenlen;
// snmp_asn1_enc_u32t(p, ofs, m_trap->thl.tslen, m_trap->ts);
// ofs += m_trap->thl.tslen;
//
// return ofs;
//}
#endif
#endif /* LWIP_SNMP */