• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: implementation for ipdebug APIs
15  * Author: none
16  * Create: 2020
17  */
18 #include "lwip/opt.h"
19 
20 #ifdef LWIP_DEBUG_INFO
21 #include "lwip/memp.h"
22 #include "lwip/pbuf.h"
23 #include "netif/ifaddrs.h"
24 #include "lwip/sockets.h"
25 #include "lwip/api.h"
26 #include "lwip/sys.h"
27 #include "lwip/igmp.h"
28 #include "lwip/inet.h"
29 #include "lwip/tcp.h"
30 #include "lwip/raw.h"
31 #include "lwip/udp.h"
32 #include "lwip/tcpip.h"
33 #include "lwip/pbuf.h"
34 #include "lwip/netif.h"
35 #include "lwip/ip_addr.h"
36 #include "lwip/dhcp.h"
37 
38 #define IP_STR_LEN 64
39 
debug_ippcb_info(struct ip_pcb * ippcb)40 void debug_ippcb_info(struct ip_pcb *ippcb)
41 {
42   char local_ip_str[IP_STR_LEN];
43   char remote_ip_str[IP_STR_LEN];
44 
45   if (ippcb != NULL) {
46     (void)memset_s(local_ip_str, sizeof(local_ip_str), 0, sizeof(local_ip_str));
47     (void)memset_s(remote_ip_str, sizeof(remote_ip_str), 0, sizeof(remote_ip_str));
48     (void)ipaddr_ntoa_r(&ippcb->local_ip, local_ip_str, sizeof(local_ip_str));
49     (void)ipaddr_ntoa_r(&ippcb->remote_ip, remote_ip_str, sizeof(remote_ip_str));
50     LWIP_PLATFORM_PRINT("l_ip    :%s\n", local_ip_str);
51     LWIP_PLATFORM_PRINT("r_ip    :%s\n", remote_ip_str);
52     LWIP_PLATFORM_PRINT("so_opt  :%u\n", ippcb->so_options);
53     LWIP_PLATFORM_PRINT("tos     :%u\n", ippcb->tos);
54     LWIP_PLATFORM_PRINT("ifindex :%u\n", ippcb->netif_idx);
55     LWIP_PLATFORM_PRINT("ttl     :%u\n", ippcb->ttl);
56   }
57 }
58 
59 #if LWIP_UDP || LWIP_UDPLITE
debug_udppcb_info(struct udp_pcb * udppcb)60 void debug_udppcb_info(struct udp_pcb *udppcb)
61 {
62   if (udppcb != NULL) {
63     LWIP_PLATFORM_PRINT("\n--------------UDPPCB\n");
64     debug_ippcb_info((struct ip_pcb *)udppcb);
65     LWIP_PLATFORM_PRINT("flags   :%u\n", udppcb->flags);
66     LWIP_PLATFORM_PRINT("l_port  :%u\n", udppcb->local_port);
67     LWIP_PLATFORM_PRINT("r_port  :%u\n", udppcb->remote_port);
68     LWIP_PLATFORM_PRINT("last_p  :%u\n", udppcb->last_payload_len);
69 #if LWIP_MULTICAST_TX_OPTIONS
70 #if LWIP_IPV4
71     char buf[IP4ADDR_STRLEN_MAX];
72     (void)ip4addr_ntoa_r(&udppcb->mcast_ip4, buf, IP4ADDR_STRLEN_MAX);
73     LWIP_PLATFORM_PRINT("mcast_ip4 :%s\n", buf);
74 #endif /* LWIP_IPV4 */
75     LWIP_PLATFORM_PRINT("mcast_ifindex :%u\n", udppcb->mcast_ifindex);
76 #endif
77 #if LWIP_UDPLITE
78     LWIP_PLATFORM_PRINT("chksum_r:%u\n", udppcb->chksum_len_rx);
79     LWIP_PLATFORM_PRINT("chksum_t:%u\n", udppcb->chksum_len_tx);
80 #endif /* LWIP_UDPLITE */
81   }
82 }
83 #endif /* LWIP_UDP || LWIP_UDPLITE */
84 
85 #if LWIP_RAW
debug_rawpcb_info(struct raw_pcb * rawpcb)86 void debug_rawpcb_info(struct raw_pcb *rawpcb)
87 {
88   if (rawpcb != NULL) {
89     LWIP_PLATFORM_PRINT("\n--------------RAWPCB\n");
90     debug_ippcb_info((struct ip_pcb *)rawpcb);
91     LWIP_PLATFORM_PRINT("hdrincl :%u\n", raw_is_flag_set(rawpcb, RAW_FLAGS_HDRINCL));
92 #if PF_PKT_SUPPORT
93     LWIP_PLATFORM_PRINT("netifidx:%u\n", rawpcb->netif_idx);
94     LWIP_PLATFORM_PRINT("proto   :%u\n", rawpcb->proto.protocol);
95     LWIP_PLATFORM_PRINT("e_proto :%u\n", rawpcb->proto.eth_proto);
96 #else
97     LWIP_PLATFORM_PRINT("proto   :%u\n", rawpcb->protocol);
98 #endif /* PF_PKT_SUPPORT */
99     LWIP_PLATFORM_PRINT("flags   :%u\n", rawpcb->flags);
100   }
101 }
102 
103 #endif /* LWIIP_RAW */
104 
105 #if LWIP_TCP
debug_tcppcb_info(struct tcp_pcb * tcppcb)106 void debug_tcppcb_info(struct tcp_pcb *tcppcb)
107 {
108   if (tcppcb != NULL) {
109     LWIP_PLATFORM_PRINT("\n--------------TCPPCB\n");
110     debug_ippcb_info((struct ip_pcb *)tcppcb);
111     LWIP_PLATFORM_PRINT("l_port  :%u\n", tcppcb->local_port);
112     LWIP_PLATFORM_PRINT("state   :%u\n", tcppcb->state);
113     LWIP_PLATFORM_PRINT("prio    :%u\n", tcppcb->prio);
114     LWIP_PLATFORM_PRINT("s_buf_s :%u\n", tcppcb->snd_buf_static);
115     LWIP_PLATFORM_PRINT("r_port  :%u\n", tcppcb->remote_port);
116     LWIP_PLATFORM_PRINT("flags   :%u\n", tcppcb->flags);
117     LWIP_PLATFORM_PRINT("p_tmr   :%u\n", tcppcb->polltmr);
118     LWIP_PLATFORM_PRINT("p_intvl :%u\n", tcppcb->pollinterval);
119     LWIP_PLATFORM_PRINT("l_timer :%u\n", tcppcb->last_timer);
120     LWIP_PLATFORM_PRINT("tmr     :%u\n", tcppcb->tmr);
121     LWIP_PLATFORM_PRINT("r_nxt   :%u\n", tcppcb->rcv_nxt);
122     LWIP_PLATFORM_PRINT("r_wnd   :%u\n", tcppcb->rcv_wnd);
123     LWIP_PLATFORM_PRINT("r_ann_w :%u\n", tcppcb->rcv_ann_wnd);
124     LWIP_PLATFORM_PRINT("r_ann_r :%u\n", tcppcb->rcv_ann_right_edge);
125     LWIP_PLATFORM_PRINT("rtime   :%d\n", tcppcb->rtime);
126     LWIP_PLATFORM_PRINT("mss     :%u\n", tcppcb->mss);
127     LWIP_PLATFORM_PRINT("rttest  :%u\n", tcppcb->rttest);
128     LWIP_PLATFORM_PRINT("rtseq   :%u\n", tcppcb->rtseq);
129     LWIP_PLATFORM_PRINT("sa      :%d\n", tcppcb->sa);
130     LWIP_PLATFORM_PRINT("sv      :%d\n", tcppcb->sv);
131     LWIP_PLATFORM_PRINT("rto     :%u\n", tcppcb->rto);
132     LWIP_PLATFORM_PRINT("nrtx    :%u\n", tcppcb->nrtx);
133     LWIP_PLATFORM_PRINT("dupacks :%u\n", tcppcb->dupacks);
134     LWIP_PLATFORM_PRINT("lastack :%u\n", tcppcb->lastack);
135     LWIP_PLATFORM_PRINT("cwnd    :%u\n", tcppcb->cwnd);
136     LWIP_PLATFORM_PRINT("ssth    :%u\n", tcppcb->ssthresh);
137     LWIP_PLATFORM_PRINT("s_nxt   :%u\n", tcppcb->snd_nxt);
138     LWIP_PLATFORM_PRINT("s_sml   :%u\n", tcppcb->snd_sml);
139     LWIP_PLATFORM_PRINT("s_wl1   :%u\n", tcppcb->snd_wl1);
140     LWIP_PLATFORM_PRINT("s_w2    :%u\n", tcppcb->snd_wl2);
141     LWIP_PLATFORM_PRINT("s_lbb   :%u\n", tcppcb->snd_lbb);
142     LWIP_PLATFORM_PRINT("s_wnd   :%u\n", tcppcb->snd_wnd);
143     LWIP_PLATFORM_PRINT("s_wnd_m :%u\n", tcppcb->snd_wnd_max);
144     LWIP_PLATFORM_PRINT("s_buf   :%u\n", tcppcb->snd_buf);
145     LWIP_PLATFORM_PRINT("k_idle  :%u\n", tcppcb->keep_idle);
146     LWIP_PLATFORM_PRINT("p_cnt   :%u\n", tcppcb->persist_cnt);
147     LWIP_PLATFORM_PRINT("p_boff  :%u\n", tcppcb->persist_backoff);
148     LWIP_PLATFORM_PRINT("l_payl_l:%u\n", tcppcb->last_payload_len);
149     LWIP_PLATFORM_PRINT("s_quel  :%u\n", tcppcb->snd_queuelen);
150     LWIP_PLATFORM_PRINT("s_quel_m:%u\n", tcppcb->snd_queuelen_max);
151     LWIP_PLATFORM_PRINT("s_quel_l:%u\n", tcppcb->snd_queuelen_lowat);
152     LWIP_PLATFORM_PRINT("s_buf_l :%u\n", tcppcb->snd_buf_lowat);
153     LWIP_PLATFORM_PRINT("unsent_o:%u\n", tcppcb->unsent_oversize);
154 #if LWIP_SACK
155     LWIP_PLATFORM_PRINT("pipr    :%u\n", tcppcb->pipe);
156     LWIP_PLATFORM_PRINT("r_point :%u\n", tcppcb->recovery_point);
157     LWIP_PLATFORM_PRINT("h_data  :%u\n", tcppcb->high_data);
158     LWIP_PLATFORM_PRINT("h_rxt   :%u\n", tcppcb->high_rxt);
159     LWIP_PLATFORM_PRINT("r_rxt   :%u\n", tcppcb->rescue_rxt);
160     LWIP_PLATFORM_PRINT("n_sacks :%u\n", tcppcb->num_sacks);
161     LWIP_PLATFORM_PRINT("ooseq_c :%u\n", tcppcb->ooseq_cnt);
162 #if LWIP_SACK_PERF_OPT
163     LWIP_PLATFORM_PRINT("p_seq_n :%u\n", tcppcb->pkt_seq_num);
164     LWIP_PLATFORM_PRINT("h_s_seq :%u\n", tcppcb->high_sacked_pkt_seq);
165 #if LWIP_SACK_CWND_OPT
166     LWIP_PLATFORM_PRINT("r_cwnd  :%u\n", tcppcb->recover_cwnd);
167     LWIP_PLATFORM_PRINT("r_ssth  :%u\n", tcppcb->recover_ssthresh);
168 #endif
169 #endif /* LWIP_SACK_PERF_OPT */
170 #endif
171 
172 #if LWIP_WND_SCALE
173     LWIP_PLATFORM_PRINT("s_scale :%u\n", tcppcb->snd_scale);
174     LWIP_PLATFORM_PRINT("r_scale :%u\n", tcppcb->rcv_scale);
175 #endif /* LWIP_WND_SCALE */
176 #if LWIP_TCP_KEEPALIVE
177     LWIP_PLATFORM_PRINT("k_intvl :%u\n", tcppcb->keep_intvl);
178     LWIP_PLATFORM_PRINT("k_cnt   :%u\n", tcppcb->keep_cnt);
179     LWIP_PLATFORM_PRINT("k_cnt_s :%u\n", tcppcb->keep_cnt_sent);
180 #endif /* LWIP_TCP_KEEPALIVE */
181 #if DRIVER_STATUS_CHECK
182     LWIP_PLATFORM_PRINT("drv_s   :%u\n", tcppcb->drv_status);
183 #endif /* DRIVER_STATUS_CHECK */
184 
185 #if LWIP_TCP_TIMESTAMPS
186     LWIP_PLATFORM_PRINT("ts_lastacksent   :%u\n", tcppcb->ts_lastacksent);
187     LWIP_PLATFORM_PRINT("ts_recent   :%u\n", tcppcb->ts_recent);
188 #endif /* LWIP_TCP_TIMESTAMPS */
189 #if LWIP_TCP_TLP_SUPPORT
190     LWIP_PLATFORM_PRINT("tlp_pto   :%u\n", tcppcb->tlp_pto_cnt);
191     LWIP_PLATFORM_PRINT("tlp_rtx   :%u\n", tcppcb->tlp_rtx_out);
192     LWIP_PLATFORM_PRINT("tlp_tm   :%u\n", tcppcb->tlp_time_stamp);
193     LWIP_PLATFORM_PRINT("tlp_high   :%u\n", tcppcb->tlp_high_rxt);
194 #endif /* LWIP_TCP_TLP_SUPPORT */
195   }
196 }
197 #endif /* LWIP_TCP */
198 
debug_netconn_info(struct netconn * conn,int expend)199 void debug_netconn_info(struct netconn *conn, int expend)
200 {
201   if (conn != NULL) {
202     LWIP_PLATFORM_PRINT("\n--------------NETCONN\n");
203     LWIP_PLATFORM_PRINT("socket  :%d\n", conn->socket);
204     LWIP_PLATFORM_PRINT("s_to    :%d\n", conn->send_timeout);
205     LWIP_PLATFORM_PRINT("r_to    :%d\n", conn->recv_timeout);
206 #if LWIP_SO_RCVBUF
207     LWIP_PLATFORM_PRINT("r_buf_s :%d\n", conn->recv_bufsize);
208     LWIP_PLATFORM_PRINT("r_avail :%d\n", conn->recv_avail);
209 #endif
210     LWIP_PLATFORM_PRINT("l_err   :%d\n", conn->last_err);
211     LWIP_PLATFORM_PRINT("flags   :%u\n", conn->flags);
212     LWIP_PLATFORM_PRINT("type    :%u\n", conn->type);
213     LWIP_PLATFORM_PRINT("state   :%d\n", conn->state);
214     LWIP_PLATFORM_PRINT("shutdown:%d\n", conn->shutdown);
215 #if LWIP_TCP
216     LWIP_PLATFORM_PRINT("pending_error:%d\n", conn->pending_err);
217 #endif
218     LWIP_PLATFORM_PRINT("lrcv_left:%u\n", conn->lrcv_left);
219     LWIP_PLATFORM_PRINT("last_err:%d\n", conn->last_err);
220 
221     if (expend) {
222       if (conn->type == NETCONN_TCP) {
223 #if LWIP_TCP
224         debug_tcppcb_info((void *)conn->pcb.tcp);
225 #endif /* LWIP_TCP */
226       } else if (conn->type == NETCONN_UDP || conn->type == NETCONN_UDPLITE || conn->type == NETCONN_UDPNOCHKSUM) {
227 #if LWIP_UDP || LWIP_UDPLITE
228         debug_udppcb_info((void *)conn->pcb.udp);
229 #endif /* LWIP_UDP || LWIP_UDPLITE */
230       } else if (conn->type == NETCONN_RAW) {
231 #if LWIP_RAW
232         debug_rawpcb_info((void *)conn->pcb.raw);
233 #endif
234       } else {
235         return;
236       }
237     }
238   }
239 }
240 
241 #endif /* LWIP_DEBUG_INFO */
242