mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-09-17 20:24:24 +00:00
SNMP: Move common MIB code into snmp_core.c helper functions
This commit is contained in:
parent
19d17adcfb
commit
7412a0e74e
@ -200,6 +200,25 @@ snmp_ip6_to_oid(const ip6_addr_t *ip, u32_t *oid)
|
|||||||
#endif /* LWIP_IPV6 */
|
#endif /* LWIP_IPV6 */
|
||||||
|
|
||||||
#if LWIP_IPV4 || LWIP_IPV6
|
#if LWIP_IPV4 || LWIP_IPV6
|
||||||
|
/**
|
||||||
|
* Convert to InetAddressType+InetAddress+InetPortNumber
|
||||||
|
* @param ip
|
||||||
|
* @param port
|
||||||
|
* @param oid
|
||||||
|
* @return OID length
|
||||||
|
*/
|
||||||
|
u8_t
|
||||||
|
snmp_ip_port_to_oid(const ip_addr_t *ip, u16_t port, u32_t *oid)
|
||||||
|
{
|
||||||
|
u8_t index;
|
||||||
|
|
||||||
|
index = snmp_ip_to_oid(ip, oid);
|
||||||
|
oid[index] = port;
|
||||||
|
index++;
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert to InetAddressType+InetAddress
|
* Convert to InetAddressType+InetAddress
|
||||||
* @param ip
|
* @param ip
|
||||||
@ -279,6 +298,39 @@ snmp_oid_to_ip(const u32_t *oid, u8_t oid_len, ip_addr_t *ip)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert from InetAddressType+InetAddress+InetPortNumber to ip_addr_t and u16_t
|
||||||
|
* @param oid
|
||||||
|
* @param oid_len
|
||||||
|
* @param ip
|
||||||
|
* @param port
|
||||||
|
* @return Parsed OID length
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
|
||||||
|
/* InetAddressType + InetAddress */
|
||||||
|
index += snmp_oid_to_ip(&oid[index], oid_len-index, ip);
|
||||||
|
if(index == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* InetPortNumber */
|
||||||
|
if(oid_len < (index+1)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(oid[index] > 0xffff) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
*port = (u16_t)oid[index];
|
||||||
|
index++;
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* LWIP_IPV4 || LWIP_IPV6 */
|
#endif /* LWIP_IPV4 || LWIP_IPV6 */
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -2079,40 +2079,22 @@ tcp_ConnectionTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8
|
|||||||
|
|
||||||
LWIP_UNUSED_ARG(value_len);
|
LWIP_UNUSED_ARG(value_len);
|
||||||
|
|
||||||
/* tcpConnectionLocalAddressType + tcpConnectionLocalAddress */
|
/* tcpConnectionLocalAddressType + tcpConnectionLocalAddress + tcpConnectionLocalPort */
|
||||||
index += snmp_oid_to_ip(&row_oid[index], row_oid_len-index, &local_ip);
|
index += snmp_oid_to_ip_port(&row_oid[index], row_oid_len-index, &local_ip, &local_port);
|
||||||
if(index == 0) {
|
if(index == 0) {
|
||||||
return SNMP_ERR_NOSUCHINSTANCE;
|
return SNMP_ERR_NOSUCHINSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* tcpConnectionLocalPort */
|
|
||||||
if(row_oid_len < (index+1)) {
|
|
||||||
return SNMP_ERR_NOSUCHINSTANCE;
|
|
||||||
}
|
|
||||||
if(row_oid[index] > 0xffff) {
|
|
||||||
return SNMP_ERR_NOSUCHINSTANCE;
|
|
||||||
}
|
|
||||||
local_port = (u16_t)row_oid[index];
|
|
||||||
index++;
|
|
||||||
|
|
||||||
/* tcpConnectionRemAddressType + tcpConnectionRemAddress */
|
/* tcpConnectionRemAddressType + tcpConnectionRemAddress + tcpConnectionRemPort */
|
||||||
index += snmp_oid_to_ip(&row_oid[index], row_oid_len-index, &remote_ip);
|
index += snmp_oid_to_ip_port(&row_oid[index], row_oid_len-index, &remote_ip, &remote_port);
|
||||||
if(index == 0) {
|
if(index == 0) {
|
||||||
return SNMP_ERR_NOSUCHINSTANCE;
|
return SNMP_ERR_NOSUCHINSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* tcpConnectionRemPort */
|
|
||||||
if(row_oid_len < (index+1)) {
|
|
||||||
return SNMP_ERR_NOSUCHINSTANCE;
|
|
||||||
}
|
|
||||||
if(row_oid[index] > 0xffff) {
|
|
||||||
return SNMP_ERR_NOSUCHINSTANCE;
|
|
||||||
}
|
|
||||||
remote_port = (u16_t)row_oid[index];
|
|
||||||
|
|
||||||
/* find tcp_pcb with requested ip and port*/
|
/* find tcp_pcb with requested ip and port*/
|
||||||
for(i=0; i<LWIP_ARRAYSIZE(tcp_pcb_nonlisten_lists); i++) {
|
for(i=0; i<LWIP_ARRAYSIZE(tcp_pcb_nonlisten_lists); i++) {
|
||||||
pcb = *tcp_pcb_nonlisten_lists[i];
|
pcb = *tcp_pcb_nonlisten_lists[i];
|
||||||
|
|
||||||
while (pcb != NULL) {
|
while (pcb != NULL) {
|
||||||
if(ip_addr_cmp(&local_ip, &pcb->local_ip) &&
|
if(ip_addr_cmp(&local_ip, &pcb->local_ip) &&
|
||||||
(local_port == pcb->local_port) &&
|
(local_port == pcb->local_port) &&
|
||||||
@ -2148,21 +2130,16 @@ tcp_ConnectionTable_get_next_cell_instance_and_value(const u32_t* column, struct
|
|||||||
/* iterate over all possible OIDs to find the next one */
|
/* iterate over all possible OIDs to find the next one */
|
||||||
for(i=0; i<LWIP_ARRAYSIZE(tcp_pcb_nonlisten_lists); i++) {
|
for(i=0; i<LWIP_ARRAYSIZE(tcp_pcb_nonlisten_lists); i++) {
|
||||||
pcb = *tcp_pcb_nonlisten_lists[i];
|
pcb = *tcp_pcb_nonlisten_lists[i];
|
||||||
|
|
||||||
while (pcb != NULL) {
|
while (pcb != NULL) {
|
||||||
u8_t index = 0;
|
u8_t index = 0;
|
||||||
u32_t test_oid[LWIP_ARRAYSIZE(result_temp)];
|
u32_t test_oid[LWIP_ARRAYSIZE(result_temp)];
|
||||||
|
|
||||||
/* tcpConnectionLocalAddressType + tcpConnectionLocalAddress */
|
/* tcpConnectionLocalAddressType + tcpConnectionLocalAddress + tcpConnectionLocalPort */
|
||||||
index += snmp_ip_to_oid(&pcb->local_ip, &test_oid[index]);
|
index += snmp_ip_port_to_oid(&pcb->local_ip, pcb->local_port, &test_oid[index]);
|
||||||
|
|
||||||
test_oid[index] = pcb->local_port; /* tcpConnectionLocalPort */
|
/* tcpConnectionRemAddressType + tcpConnectionRemAddress + tcpConnectionRemPort */
|
||||||
index++;
|
index += snmp_ip_port_to_oid(&pcb->remote_ip, pcb->remote_port, &test_oid[index]);
|
||||||
|
|
||||||
/* tcpConnectionRemAddressType + tcpConnectionRemAddress */
|
|
||||||
index += snmp_ip_to_oid(&pcb->remote_ip, &test_oid[index]);
|
|
||||||
|
|
||||||
test_oid[index] = pcb->remote_port; /* tcpConnectionRemPort */
|
|
||||||
index++;
|
|
||||||
|
|
||||||
/* check generated OID: is it a candidate for the next one? */
|
/* 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, index, pcb);
|
||||||
@ -2209,21 +2186,11 @@ tcp_ListenerTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t
|
|||||||
|
|
||||||
LWIP_UNUSED_ARG(value_len);
|
LWIP_UNUSED_ARG(value_len);
|
||||||
|
|
||||||
/* tcpListenerLocalAddressType + tcpListenerLocalAddress */
|
/* tcpListenerLocalAddressType + tcpListenerLocalAddress + tcpListenerLocalPort */
|
||||||
index += snmp_oid_to_ip(&row_oid[index], row_oid_len-index, &local_ip);
|
index += snmp_oid_to_ip_port(&row_oid[index], row_oid_len-index, &local_ip, &local_port);
|
||||||
if(index == 0) {
|
if(index == 0) {
|
||||||
return SNMP_ERR_NOSUCHINSTANCE;
|
return SNMP_ERR_NOSUCHINSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* tcpListenerLocalPort */
|
|
||||||
if(row_oid_len < (index+1)) {
|
|
||||||
return SNMP_ERR_NOSUCHINSTANCE;
|
|
||||||
}
|
|
||||||
if(row_oid[index] > 0xffff) {
|
|
||||||
return SNMP_ERR_NOSUCHINSTANCE;
|
|
||||||
}
|
|
||||||
local_port = (u16_t)row_oid[index];
|
|
||||||
index++;
|
|
||||||
|
|
||||||
/* find tcp_pcb with requested ip and port*/
|
/* find tcp_pcb with requested ip and port*/
|
||||||
pcb = tcp_listen_pcbs.listen_pcbs;
|
pcb = tcp_listen_pcbs.listen_pcbs;
|
||||||
@ -2259,11 +2226,8 @@ tcp_ListenerTable_get_next_cell_instance_and_value(const u32_t* column, struct s
|
|||||||
u8_t index = 0;
|
u8_t index = 0;
|
||||||
u32_t test_oid[LWIP_ARRAYSIZE(result_temp)];
|
u32_t test_oid[LWIP_ARRAYSIZE(result_temp)];
|
||||||
|
|
||||||
/* tcpListenerLocalAddressType + tcpListenerLocalAddress */
|
/* tcpListenerLocalAddressType + tcpListenerLocalAddress + tcpListenerLocalPort */
|
||||||
index += snmp_ip_to_oid(&pcb->local_ip, &test_oid[index]);
|
index += snmp_ip_port_to_oid(&pcb->local_ip, pcb->local_port, &test_oid[index]);
|
||||||
|
|
||||||
test_oid[index] = pcb->local_port; /* tcpListenerLocalPort */
|
|
||||||
index++;
|
|
||||||
|
|
||||||
/* check generated OID: is it a candidate for the next one? */
|
/* 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, index, NULL);
|
||||||
@ -2347,38 +2311,18 @@ udp_endpointTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t
|
|||||||
|
|
||||||
LWIP_UNUSED_ARG(value_len);
|
LWIP_UNUSED_ARG(value_len);
|
||||||
|
|
||||||
/* udpEndpointLocalAddressType + udpEndpointLocalAddress */
|
/* udpEndpointLocalAddressType + udpEndpointLocalAddress + udpEndpointLocalPort */
|
||||||
index += snmp_oid_to_ip(&row_oid[index], row_oid_len-index, &local_ip);
|
index += snmp_oid_to_ip_port(&row_oid[index], row_oid_len-index, &local_ip, &local_port);
|
||||||
if(index == 0) {
|
if(index == 0) {
|
||||||
return SNMP_ERR_NOSUCHINSTANCE;
|
return SNMP_ERR_NOSUCHINSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* udpEndpointLocalPort */
|
/* udpEndpointRemoteAddressType + udpEndpointRemoteAddress + udpEndpointRemotePort */
|
||||||
if(row_oid_len < (index+1)) {
|
index += snmp_oid_to_ip_port(&row_oid[index], row_oid_len-index, &remote_ip, &remote_port);
|
||||||
return SNMP_ERR_NOSUCHINSTANCE;
|
|
||||||
}
|
|
||||||
if(row_oid[index] > 0xffff) {
|
|
||||||
return SNMP_ERR_NOSUCHINSTANCE;
|
|
||||||
}
|
|
||||||
local_port = (u16_t)row_oid[index];
|
|
||||||
index++;
|
|
||||||
|
|
||||||
/* udpEndpointRemoteAddressType + udpEndpointRemoteAddress */
|
|
||||||
index += snmp_oid_to_ip(&row_oid[index], row_oid_len-index, &remote_ip);
|
|
||||||
if(index == 0) {
|
if(index == 0) {
|
||||||
return SNMP_ERR_NOSUCHINSTANCE;
|
return SNMP_ERR_NOSUCHINSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* udpEndpointRemotePort */
|
|
||||||
if(row_oid_len < (index+1)) {
|
|
||||||
return SNMP_ERR_NOSUCHINSTANCE;
|
|
||||||
}
|
|
||||||
if(row_oid[index] > 0xffff) {
|
|
||||||
return SNMP_ERR_NOSUCHINSTANCE;
|
|
||||||
}
|
|
||||||
remote_port = (u16_t)row_oid[index];
|
|
||||||
index++;
|
|
||||||
|
|
||||||
/* udpEndpointInstance */
|
/* udpEndpointInstance */
|
||||||
if(row_oid_len < (index+1)) {
|
if(row_oid_len < (index+1)) {
|
||||||
return SNMP_ERR_NOSUCHINSTANCE;
|
return SNMP_ERR_NOSUCHINSTANCE;
|
||||||
@ -2426,17 +2370,11 @@ udp_endpointTable_get_next_cell_instance_and_value(const u32_t* column, struct s
|
|||||||
u32_t test_oid[LWIP_ARRAYSIZE(result_temp)];
|
u32_t test_oid[LWIP_ARRAYSIZE(result_temp)];
|
||||||
u8_t index = 0;
|
u8_t index = 0;
|
||||||
|
|
||||||
/* udpEndpointLocalAddressType + udpEndpointLocalAddress */
|
/* udpEndpointLocalAddressType + udpEndpointLocalAddress + udpEndpointLocalPort */
|
||||||
index += snmp_ip_to_oid(&pcb->local_ip, &test_oid[index]);
|
index += snmp_ip_port_to_oid(&pcb->local_ip, pcb->local_port, &test_oid[index]);
|
||||||
|
|
||||||
test_oid[index] = pcb->local_port; /* udpEndpointLocalPort */
|
/* udpEndpointRemoteAddressType + udpEndpointRemoteAddress + udpEndpointRemotePort */
|
||||||
index++;
|
index += snmp_ip_port_to_oid(&pcb->remote_ip, pcb->remote_port, &test_oid[index]);
|
||||||
|
|
||||||
/* udpEndpointRemoteAddressType + udpEndpointRemoteAddress */
|
|
||||||
index += snmp_ip_to_oid(&pcb->remote_ip, &test_oid[index]);
|
|
||||||
|
|
||||||
test_oid[index] = pcb->remote_port; /* udpEndpointRemotePort */
|
|
||||||
index++;
|
|
||||||
|
|
||||||
test_oid[index] = 0; /* udpEndpointInstance */
|
test_oid[index] = 0; /* udpEndpointInstance */
|
||||||
index++;
|
index++;
|
||||||
|
@ -306,8 +306,11 @@ u8_t snmp_oid_to_ip6(const u32_t *oid, ip6_addr_t *ip);
|
|||||||
void snmp_ip6_to_oid(const ip6_addr_t *ip, u32_t *oid);
|
void snmp_ip6_to_oid(const ip6_addr_t *ip, u32_t *oid);
|
||||||
#endif /* LWIP_IPV6 */
|
#endif /* LWIP_IPV6 */
|
||||||
#if LWIP_IPV4 || LWIP_IPV6
|
#if LWIP_IPV4 || LWIP_IPV6
|
||||||
u8_t snmp_oid_to_ip(const u32_t *oid, u8_t oid_len, ip_addr_t *ip);
|
|
||||||
u8_t snmp_ip_to_oid(const ip_addr_t *ip, u32_t *oid);
|
u8_t snmp_ip_to_oid(const ip_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 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);
|
||||||
#endif /* LWIP_IPV4 || LWIP_IPV6 */
|
#endif /* LWIP_IPV4 || LWIP_IPV6 */
|
||||||
|
|
||||||
u8_t snmp_set_test_ok(struct snmp_node_instance* instance, u16_t value_len, void* value); /* generic function which can be used if test is always successful */
|
u8_t snmp_set_test_ok(struct snmp_node_instance* instance, u16_t value_len, void* value); /* generic function which can be used if test is always successful */
|
||||||
|
Loading…
Reference in New Issue
Block a user