Files
m241Neelima/components/ip_net2-6.9/iptcp/src/iptcp_debug.c
T
2026-07-30 11:19:44 +05:30

577 lines
17 KiB
C

/*
******************************************************************************
* INTERPEAK SOURCE FILE
*
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iptcp_debug.c,v $ $Revision: 1.25.10.2 $
* $Source: /home/interpeak/CVSRoot/iptcp/src/iptcp_debug.c,v $
* $Author: jren $
* $State: Exp $ $Locker: $
*
* INTERPEAK_COPYRIGHT_STRING
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
******************************************************************************
*/
/*
****************************************************************************
* 1 DESCRIPTION
****************************************************************************
*/
/*
****************************************************************************
* 2 CONFIGURATION
****************************************************************************
*/
#ifndef IPCOM_KERNEL
#define IPCOM_KERNEL
#endif
#include "iptcp_config.h"
/*
****************************************************************************
* 3 INCLUDE FILES
****************************************************************************
*/
#define IPCOM_USE_CLIB_PROTO
#include <ipcom_type.h>
#include <ipcom_clib.h>
#include <ipcom_cstyle.h>
#include "iptcp_h.h"
/*
****************************************************************************
* 4 DEFINES
****************************************************************************
*/
/*
****************************************************************************
* 5 TYPES
****************************************************************************
*/
/*
****************************************************************************
* 6 EXTERN PROTOTYPES
****************************************************************************
*/
/*
****************************************************************************
* 7 LOCAL PROTOTYPES
****************************************************************************
*/
/*
****************************************************************************
* 8 DATA
****************************************************************************
*/
/*
****************************************************************************
* 9 STATIC FUNCTIONS
****************************************************************************
*/
/*
****************************************************************************
* 10 GLOBAL FUNCTIONS
****************************************************************************
*/
/*
*===========================================================================
* iptcp_state_to_str
*===========================================================================
* Description: Returns a string representation of the state.
* Parameters: state - One of the TCP states.
* Returns: A string representation.
*
*/
IP_GLOBAL IP_CONST char *
iptcp_state_to_str(int state)
{
switch (state)
{
case IPTCP_STATE_CLOSED:
return "CLOSED";
case IPTCP_STATE_LISTEN:
return "LISTEN";
case IPTCP_STATE_SYN_SENT:
return "SYN_SENT";
case IPTCP_STATE_SYN_RCVD:
return "SYN_RECV";
case IPTCP_STATE_ESTABLISHED:
return "ESTABLISHED";
case IPTCP_STATE_CLOSE_WAIT:
return "CLOSE_WAIT";
case IPTCP_STATE_FIN_WAIT_1:
return "FIN_WAIT_1";
case IPTCP_STATE_CLOSING:
return "CLOSING";
case IPTCP_STATE_LAST_ACK:
return "LAST_ACK";
case IPTCP_STATE_FIN_WAIT_2:
return "FIN_WAIT_2";
case IPTCP_STATE_TIME_WAIT:
return "TIME_WAIT";
case IPTCP_STATE_DELETE_TCB:
return "DELETE_TCB";
default:
return "Unknown state";
}
}
/*
*===========================================================================
* iptcp_timer_to_str
*===========================================================================
* Description: Returns a string representation of the timer type.
* Parameters: state - One of the TCP timer types.
* Returns: A string representation.
*
*/
IP_GLOBAL IP_CONST char *
iptcp_timer_to_str(int type)
{
switch (type)
{
case IPTCP_TMRT_CONN:
return "CONN";
case IPTCP_TMRT_RETR:
return "RETR";
case IPTCP_TMRT_DACK:
return "DACK";
case IPTCP_TMRT_PERS:
return "PERS";
case IPTCP_TMRT_LOPE:
return "LOPE";
case IPTCP_TMRT_TIWA:
return "TIWA";
case IPTCP_TMRT_KEEP:
return "KEEP";
case IPTCP_TMRT_LNGR:
return "LNGR";
case IPTCP_TMRT_RSRT:
return "RSRT";
case IPTCP_TMRT_ZWP:
return "ZWP";
default:
return "Unkown timer type";
}
}
#ifdef IPNET_DEBUG
/*
*===========================================================================
* iptcp_tick_to_string
*===========================================================================
* Description:
* Parameters: unused -
* buf -
* buf_len -
* Returns:
*
*/
IP_GLOBAL int
iptcp_tick_to_string(void *unused, char *buf, Ip_size_t buf_len)
{
IPCOM_UNUSED_ARG(unused);
return ipcom_snprintf(buf, buf_len, "TCP tick timer.");
}
/*
*===========================================================================
* iptcp_to_string
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_STATIC int
iptcp_to_string(Iptcp_socket *sock, const char *type, char *buf, Ip_size_t buf_len)
{
return ipcom_snprintf(buf, buf_len, "TCP %s timer on socket %d",
type, sock->ipcom.fd);
}
/*
*===========================================================================
* iptcp_pers_to_string
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL int
iptcp_pers_to_string(Iptcp_socket *sock, char *buf, Ip_size_t buf_len)
{
int offset = iptcp_to_string(sock, "persist", buf, buf_len);
offset += ipcom_snprintf(&buf[offset], buf_len - offset, " response %sseen retrans %u",
sock->tcb->peer_responded_to_pers ? "" : "not ",
sock->tcb->retr_count);
return offset;
}
/*
*===========================================================================
* iptcp_keep_to_string
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL int
iptcp_keep_to_string(Iptcp_socket *sock, char *buf, Ip_size_t buf_len)
{
return iptcp_to_string(sock, "keep-alive", buf, buf_len);
}
/*
*===========================================================================
* iptcp_conn_to_string
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL int
iptcp_conn_to_string(Iptcp_socket *sock, char *buf, Ip_size_t buf_len)
{
return iptcp_to_string(sock, "connection", buf, buf_len);
}
/*
*===========================================================================
* iptcp_dack_to_string
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL int
iptcp_dack_to_string(Iptcp_socket *sock, char *buf, Ip_size_t buf_len)
{
return iptcp_to_string(sock, "delayed ack", buf, buf_len);
}
/*
*===========================================================================
* iptcp_retr_to_string
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL int
iptcp_retr_to_string(Iptcp_socket *sock, char *buf, Ip_size_t buf_len)
{
Iptcp_tcb *tcb = sock->tcb;
Iptcp_segment *seg = tcb->send.resend_head;
int offset;
if (seg == IP_NULL)
return 0;
offset = iptcp_to_string(sock, "retransmission", buf, buf_len);
offset += ipcom_snprintf(&buf[offset], buf_len - offset, " seg %u retrans %u",
(unsigned) seg->seq_start,
tcb->retr_count);
return offset;
}
/*
*===========================================================================
* iptcp_tiwa_to_string
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL int
iptcp_tiwa_to_string(Iptcp_socket *sock, char *buf, Ip_size_t buf_len)
{
return iptcp_to_string(sock, "time wait", buf, buf_len);
}
/*
*===========================================================================
* iptcp_lope_to_string
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL int
iptcp_lope_to_string(Iptcp_socket *sock, char *buf, Ip_size_t buf_len)
{
return iptcp_to_string(sock, "lost peer", buf, buf_len);
}
/*
*===========================================================================
* iptcp_lngr_to_string
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL int
iptcp_lngr_to_string(Iptcp_socket *sock, char *buf, Ip_size_t buf_len)
{
return iptcp_to_string(sock, "linger", buf, buf_len);
}
/*
*===========================================================================
* iptcp_zwp_to_string
*===========================================================================
* Description:
* Parameters:
* Returns:
*
*/
IP_GLOBAL int
iptcp_zwp_to_string(Iptcp_socket *sock, char *buf, Ip_size_t buf_len)
{
return iptcp_to_string(sock, "iptcp_zwp_to_string", buf, buf_len);
}
#endif /* IPNET_DEBUG */
/*
****************************************************************************
* 11 PUBLIC FUNCTIONS
****************************************************************************
*/
#ifdef IPTCP_DEBUG
/*
*===========================================================================
* iptcp_pkt_freecheck
*===========================================================================
* Description: Called from ipcom_pkt_free to verify pkt not in timerlist.
* Parameters:
* Returns:
*
*/
IP_PUBLIC void
iptcp_pkt_freecheck(Ipcom_pkt *pkt)
{
Ip_u32 isr;
int i;
Iptcp_segment *tcp_seg;
Ipcom_pkt *spkt;
Iptcp_socket *sock;
isr = ipcom_interrupt_disable();
if (IPCOM_PKT_HAS_MULTIPLE_OWNERS(pkt) == IP_FALSE)
{
for (i = 0; i < IP_STACK(conf_max_sockets); i++)
{
sock = ipstack->sockets[i];
if (sock == IP_NULL || sock->tcb == IP_NULL)
continue;
ipcom_atomic_inc(&sock->ref_count);
for (tcp_seg = sock->tcb->send.resend_head;
tcp_seg != IP_NULL;
tcp_seg = tcp_seg->next)
{
ip_assert(pkt != tcp_seg->pkt);
}
for (spkt = sock->tcb->send.head;
spkt != IP_NULL;
spkt = spkt->next)
{
ip_assert(spkt != pkt);
}
ipcom_atomic_dec(&sock->ref_count);
}
}
ipcom_interrupt_enable(isr);
}
/*
*===========================================================================
* iptcp_ctrl_verify_retransq
*===========================================================================
* Description: Verifies that a packet can be found in the retransmission
* queue on one of the TCP sockets.
* Parameters: pkt - Packet to find.
* Returns: The socket descriptor where the packet is in retrasmission queue.
*
*/
IP_PUBLIC Ip_fd
iptcp_ctrl_verify_retransq(Ipcom_pkt *pkt)
{
int i;
Iptcp_socket *sock;
Iptcp_segment *seg;
for (i = 0; i < IP_STACK(conf_max_sockets); i++)
{
sock = ipstack->sockets[i];
if (sock == IP_NULL || sock->tcb == IP_NULL)
/* Not a TCP socket */
continue;
for (seg = sock->tcb->send.resend_head; seg != IP_NULL; seg = seg->next)
{
if (seg->pkt == pkt)
return sock->ipcom.fd;
}
}
return IP_SOCKERR;
}
/*
*===========================================================================
* iptcp_ctrl_verify_sockrecvq
*===========================================================================
* Description: Verifies that a packet can be found in the receive
* queue on one of the sockets.
* Parameters: pkt - Packet to find.
* Returns: The socket descriptor where the packet is queued.
*
*/
IP_PUBLIC Ip_fd
iptcp_ctrl_verify_sockrecvq(Ipcom_pkt *pkt)
{
int i;
Iptcp_socket *sock;
Ipcom_pkt *rpkt;
for (i = 0; i < IP_STACK(conf_max_sockets); i++)
{
sock = ipstack->sockets[i];
if (sock == IP_NULL)
continue;
if (sock->tcb == IP_NULL)
rpkt = sock->rcv_head;
else
rpkt = sock->rcv_head;
for (; rpkt != IP_NULL; rpkt = rpkt->next)
{
if (rpkt == pkt)
return sock->ipcom.fd;
}
}
return IP_SOCKERR;
}
/*
*===========================================================================
* iptcp_ctrl_verify_sockooorecvq
*===========================================================================
* Description: Verifies that a packet can be found in the receive queue
* for out-of-order packets on one of the TCP sockets.
* Parameters: pkt - Packet to find.
* str - Buffer to print the status.
* Returns: The socket descriptor where the packet is queued in the
* out-of-order queue.
*
*/
IP_PUBLIC Ip_fd
iptcp_ctrl_verify_sockooorecvq(Ipcom_pkt *pkt)
{
int i;
Iptcp_socket *sock;
Iptcp_segment *seg;
for (i = 0; i < IP_STACK(conf_max_sockets); i++)
{
sock = ipstack->sockets[i];
if (sock == IP_NULL || sock->tcb == IP_NULL)
/* Not a TCP socket */
continue;
for (seg = sock->tcb->recv.out_of_order_seg; seg != IP_NULL; seg = seg->next)
{
if (seg->pkt == pkt)
return sock->ipcom.fd;
}
}
return IP_SOCKERR;
}
/*
*===========================================================================
* iptcp_print_tcb_flags
*===========================================================================
* Description: Converts the flags field from a TCB to a human readable form
* Parameters: flags - flags from the TCB field of a TCP socket.
* Returns:
*
*/
#ifdef NOT_CALLED_BY_ANY_OTHER_FUNCTION
IP_PUBLIC void
iptcp_print_tcb_flags(Ip_u32 flags)
{
printf("%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
flags & IPTCP_TCPC_FLAG_PASSIVE_OPEN ? "PASSIVE_OPEN\n" : "",
flags & IPTCP_TCPC_FLAG_SOCK_CLOSED ? "SOCK_CLOSED\n" : "",
flags & IPTCP_TCPC_FLAG_CONNABORTED ? "CONNABORTED\n" : "",
flags & IPTCP_TCPC_FLAG_SMALL_PKT_OUT ? "SMALL_PKT_OUT\n" : "",
flags & IPTCP_TCPC_FLAG_NO_SMDE ? "NO_SMDE\n" : "",
flags & IPTCP_TCPC_FLAG_RTT ? "RTT\n" : "",
flags & IPTCP_TCPC_FLAG_ACK_PENDING ? "ACK_PENDING\n" : "",
flags & IPTCP_TCPC_FLAG_DACK_PENDING ? "DACK_PENDING\n" : "",
flags & IPTCP_TCPC_FLAG_PERS_PENDING ? "PERS_PENDING\n" : "",
flags & IPTCP_TCPC_FLAG_KEEP_PENDING ? "KEEP_PENDING\n" : "",
flags & IPTCP_TCPC_FLAG_FIN_PENDING ? "FIN_PENDING\n" : "",
flags & IPTCP_TCPC_FLAG_TIMESTAMP_OPT ? "TIMESTAMP_OPT\n" : "",
flags & IPTCP_TCPC_FLAG_WND_SCALE_OPT ? "WND_SCALE_OPT\n" : "",
flags & IPTCP_TCPC_FLAG_RESENDING ? "RESENDING\n" : "",
flags & IPTCP_TCPC_FLAG_FAST_RETRANS ? "FAST_RETRANS\n" : "",
flags & IPTCP_TCPC_FLAG_SENDER_URG ? "SENDER_URG\n" : "",
flags & IPTCP_TCPC_FLAG_RECEIVER_URG ? "RECVEIVER_URG\n" : "",
flags & IPTCP_TCPC_FLAG_SACK ? "SACK\n" : "",
flags & IPTCP_TCPC_FLAG_CORK ? "CORK\n" : "",
flags & IPTCP_TCPC_FLAG_RFC_1122_URG ? "RFC_1122_URG\n" : "",
flags & IPTCP_TCPC_FLAG_KCLOSE_PENDING ? "KCLOSE_PENDING\n" : "",
flags & IPTCP_TCPC_FLAG_USER_REF ? "USER_REF\n" : "");
}
#endif
#endif /* IPTCP_DEBUG */
/*
****************************************************************************
* END OF FILE
****************************************************************************
*/