From a85997b59537776397ad52219eeeee812f15f297 Mon Sep 17 00:00:00 2001 From: liangbotong Date: Tue, 14 Jan 2025 11:12:39 +0800 Subject: [PATCH] Clean code warnings for NewIP Signed-off-by: liangbotong --- newip/examples/check_nip_enable.c | 4 ++-- newip/examples/get_af_ninet.c | 4 ++-- newip/examples/nip_addr.c | 14 +++++++------- newip/examples/nip_addr_cfg_demo.c | 2 +- newip/examples/nip_lib.c | 6 +++--- newip/examples/nip_route.c | 16 ++++++++-------- newip/examples/nip_route_cfg_demo.c | 2 +- newip/examples/nip_tcp_client_demo.c | 10 +++++----- newip/examples/nip_tcp_server_demo.c | 11 ++++++----- newip/examples/nip_udp_client_demo.c | 10 +++++----- newip/examples/nip_udp_server_demo.c | 9 +++++---- newip/src/common/nip_addr.c | 2 +- newip/src/common/nip_checksum.c | 6 +++--- newip/src/common/nip_hdr_decap.c | 2 +- newip/src/common/nip_hdr_encap.c | 2 +- .../src/linux-5.10/net/newip/tcp_nip_parameter.c | 14 +++++++------- .../linux-5.10/net/newip/ninet_hashtables.c | 2 +- .../linux-5.10/net/newip/tcp_nip_output.c | 2 +- 18 files changed, 60 insertions(+), 58 deletions(-) diff --git a/newip/examples/check_nip_enable.c b/newip/examples/check_nip_enable.c index d894792..7273a20 100644 --- a/newip/examples/check_nip_enable.c +++ b/newip/examples/check_nip_enable.c @@ -19,7 +19,7 @@ int g_nip_enable = NIP_ENABLE_INVALID; -void _check_nip_enable(void) +static void _check_nip_enable(void) { char tmp[NIP_DISABLE_LENTH]; FILE *fn = fopen(NIP_DISABLE_PATH, "r"); @@ -42,7 +42,7 @@ void _check_nip_enable(void) g_nip_enable = atoi(tmp) ? 0 : 1; } -int check_nip_enable(void) +static int check_nip_enable(void) { if (g_nip_enable == NIP_ENABLE_INVALID) { _check_nip_enable(); diff --git a/newip/examples/get_af_ninet.c b/newip/examples/get_af_ninet.c index a3f8449..214c64c 100644 --- a/newip/examples/get_af_ninet.c +++ b/newip/examples/get_af_ninet.c @@ -18,7 +18,7 @@ int g_af_ninet; -void _get_af_ninet(void) +static void _get_af_ninet(void) { char tmp[AF_NINET_LENTH]; FILE *fn = fopen(AF_NINET_PATH, "r"); @@ -41,7 +41,7 @@ void _get_af_ninet(void) g_af_ninet = atoi(tmp); } -int get_af_ninet(void) +static int get_af_ninet(void) { if (g_af_ninet == 0) _get_af_ninet(); diff --git a/newip/examples/nip_addr.c b/newip/examples/nip_addr.c index 9fb3fee..5ca2744 100644 --- a/newip/examples/nip_addr.c +++ b/newip/examples/nip_addr.c @@ -24,7 +24,7 @@ * ioctl(fd, SIOGIFINDEX, &ifr); * ifr.ifr_ifindex; ===> ifindex */ -int nip_add_addr(int ifindex, const struct nip_addr *addr, int opt) +static int nip_add_addr(int ifindex, const struct nip_addr *addr, int opt) { int fd, ret; struct nip_ifreq ifrn; @@ -37,7 +37,7 @@ int nip_add_addr(int ifindex, const struct nip_addr *addr, int opt) ifrn.ifrn_addr = *addr; ifrn.ifrn_ifindex = ifindex; - ret = ioctl(fd, opt, &ifrn); + ret = ioctl(fd, (unsigned long)opt, &ifrn); if (ret < 0 && errno != EEXIST) { // ignore File Exists error printf("cfg newip addr fail, ifindex=%d, opt=%d, ret=%d.\n", ifindex, opt, ret); close(fd); @@ -48,16 +48,16 @@ int nip_add_addr(int ifindex, const struct nip_addr *addr, int opt) return 0; } -void cmd_help(void) +static void cmd_help(void) { /* nip_addr wlan0 add 01 (在wlan0上配置地址01) */ /* nip_addr wlan0 del 01 (在wlan0上删除地址01) */ printf("[cmd example] nip_addr { add | del } \n"); } -int parse_name(char **argv, int *ifindex, char *dev) +static int parse_name(char **argv, int *ifindex, char *dev) { - int len = strlen(*argv); + size_t len = strlen(*argv); memset(dev, 0, ARRAY_LEN); if (!len || len >= (ARRAY_LEN - 1)) @@ -73,10 +73,10 @@ int parse_name(char **argv, int *ifindex, char *dev) return nip_get_ifindex(dev, ifindex); } -int parse_cmd(char **argv, int *opt) +static int parse_cmd(char **argv, int *opt) { char cmd[ARRAY_LEN]; - int len = strlen(*argv); + size_t len = strlen(*argv); memset(cmd, 0, ARRAY_LEN); if (!len || len >= (ARRAY_LEN - 1)) diff --git a/newip/examples/nip_addr_cfg_demo.c b/newip/examples/nip_addr_cfg_demo.c index 308725f..dcf0837 100644 --- a/newip/examples/nip_addr_cfg_demo.c +++ b/newip/examples/nip_addr_cfg_demo.c @@ -24,7 +24,7 @@ * ioctl(fd, SIOGIFINDEX, &ifr); * ifr.ifr_ifindex; ===> ifindex */ -int nip_add_addr(int ifindex, const unsigned char *addr, unsigned char addr_len) +static int nip_add_addr(int ifindex, const unsigned char *addr, unsigned char addr_len) { int fd, ret; struct nip_ifreq ifrn; diff --git a/newip/examples/nip_lib.c b/newip/examples/nip_lib.c index 5169540..7a007eb 100644 --- a/newip/examples/nip_lib.c +++ b/newip/examples/nip_lib.c @@ -46,7 +46,7 @@ int32_t nip_get_ifindex(const char *ifname, int *ifindex) return 0; } -int nip_addr_fmt(char *addr_str, struct nip_addr *sap, int addrlen_input) +static int nip_addr_fmt(unsigned char *addr_str, struct nip_addr *sap, int addrlen_input) { unsigned char first_byte; int addrlen, i; @@ -93,7 +93,7 @@ int nip_addr_fmt(char *addr_str, struct nip_addr *sap, int addrlen_input) return 1; } - sap->bitlen = addrlen * NIP_ADDR_LEN_8; + sap->bitlen = (unsigned char)(addrlen * NIP_ADDR_LEN_8); printf("*************************************************\n"); printf("Newip addr len=%d\n", addrlen); for (i = 0; i < addrlen; i++) { @@ -108,7 +108,7 @@ int nip_addr_fmt(char *addr_str, struct nip_addr *sap, int addrlen_input) int nip_get_addr(char **args, struct nip_addr *addr) { - unsigned int len; + size_t len; char *sp = *args; int addrlen_input = 0; __u8 addr_str[INDEX_MAX] = {0}; diff --git a/newip/examples/nip_route.c b/newip/examples/nip_route.c index d916252..d016488 100644 --- a/newip/examples/nip_route.c +++ b/newip/examples/nip_route.c @@ -26,7 +26,7 @@ * ioctl(fd, SIOGIFINDEX, &ifr); * ifr.ifr_ifindex; ===> ifindex */ -int nip_route_add(int ifindex, const struct nip_addr *dst_addr, +static int nip_route_add(int ifindex, const struct nip_addr *dst_addr, const struct nip_addr *gateway_addr, __u8 gateway_flag, int opt) { int fd, ret; @@ -46,7 +46,7 @@ int nip_route_add(int ifindex, const struct nip_addr *dst_addr, rt.rtmsg_flags |= RTF_GATEWAY; } - ret = ioctl(fd, opt, &rt); + ret = ioctl(fd, (unsigned long)opt, &rt); if (ret < 0 && errno != EEXIST) { // ignore File Exists error close(fd); return -1; @@ -56,7 +56,7 @@ int nip_route_add(int ifindex, const struct nip_addr *dst_addr, return 0; } -void cmd_help(void) +static void cmd_help(void) { /* nip_route add 02 wlan0 * (配置目的地址02设备路由,出口是wlan0) @@ -70,9 +70,9 @@ void cmd_help(void) printf("nip_route { add | del } \n"); } -int parse_name(char **argv, int *ifindex, char *dev) +static int parse_name(char **argv, int *ifindex, char *dev) { - int len = strlen(*argv); + size_t len = strlen(*argv); memset(dev, 0, ARRAY_LEN); if (len >= (ARRAY_LEN - 1) || !len) @@ -88,9 +88,9 @@ int parse_name(char **argv, int *ifindex, char *dev) return nip_get_ifindex(dev, ifindex); } -int parse_cmd(char **argv, int *opt) +static int parse_cmd(char **argv, int *opt) { - int len = strlen(*argv); + size_t len = strlen(*argv); char cmd[ARRAY_LEN]; memset(cmd, 0, ARRAY_LEN); @@ -111,7 +111,7 @@ int parse_cmd(char **argv, int *opt) return 0; } -int parse_args(char **argv, int *opt, __u8 *gateway_flag, int *ifindex, +static int parse_args(char **argv, int *opt, __u8 *gateway_flag, int *ifindex, struct nip_addr *dst_addr, struct nip_addr *gateway_addr, char *dev, int argc) { /* 配置参数1解析: { add | del } */ diff --git a/newip/examples/nip_route_cfg_demo.c b/newip/examples/nip_route_cfg_demo.c index b5a0a1e..d7bc3a8 100644 --- a/newip/examples/nip_route_cfg_demo.c +++ b/newip/examples/nip_route_cfg_demo.c @@ -27,7 +27,7 @@ * ioctl(fd, SIOGIFINDEX, &ifr); * ifr.ifr_ifindex; ===> ifindex */ -int nip_route_add(int ifindex, const unsigned char *dst_addr, uint8_t dst_addr_len, +static int nip_route_add(int ifindex, const unsigned char *dst_addr, uint8_t dst_addr_len, const unsigned char *gateway_addr, uint8_t gateway_addr_len) { int fd, ret; diff --git a/newip/examples/nip_tcp_client_demo.c b/newip/examples/nip_tcp_client_demo.c index b96a47c..391f048 100644 --- a/newip/examples/nip_tcp_client_demo.c +++ b/newip/examples/nip_tcp_client_demo.c @@ -24,7 +24,7 @@ #include #include -int _send(int cfd, int pkt_num) +static int _send(int cfd, int pkt_num) { char buf[BUFLEN] = {0}; struct timeval sys_time; @@ -44,7 +44,7 @@ int _send(int cfd, int pkt_num) return 0; } -int _recv(int cfd, int pkt_num, int *success) +static int _recv(int cfd, int pkt_num, int *success) { char buf[BUFLEN] = {0}; fd_set readfds; @@ -61,7 +61,7 @@ int _recv(int cfd, int pkt_num, int *success) } if (FD_ISSET(cfd, &readfds)) { - int ret; + ssize_t ret; int no = 0; ret = recv(cfd, buf, PKTLEN, MSG_WAITALL); @@ -75,7 +75,7 @@ int _recv(int cfd, int pkt_num, int *success) printf("Received --%s sock %d success:%6d/%6d/no=%6d\n", buf, cfd, *success, pkt_num + 1, no); } else { - printf("recv fail, ret=%d\n", ret); + printf("recv fail, ret=%zd\n", ret); return -1; } } @@ -83,7 +83,7 @@ int _recv(int cfd, int pkt_num, int *success) return 0; } -void *send_recv(void *args) +static void *send_recv(void *args) { int cfd = ((struct thread_args *)args)->cfd; int success = 0; diff --git a/newip/examples/nip_tcp_server_demo.c b/newip/examples/nip_tcp_server_demo.c index 5c05ffb..f3c9423 100644 --- a/newip/examples/nip_tcp_server_demo.c +++ b/newip/examples/nip_tcp_server_demo.c @@ -22,14 +22,15 @@ #include "nip_lib.h" #include "newip_route.h" -void *recv_send(void *args) +static void *recv_send(void *args) { - int cfd, ret; + int cfd; + ssize_t ret; char buf[BUFLEN] = {0}; memcpy(&cfd, args, sizeof(int)); for (int i = 0; i < PKTCNT; i++) { - int recv_num = recv(cfd, buf, PKTLEN, MSG_WAITALL); + ssize_t recv_num = recv(cfd, buf, PKTLEN, MSG_WAITALL); if (recv_num < 0) { perror("recv"); @@ -37,13 +38,13 @@ void *recv_send(void *args) } else if (recv_num == 0) { /* no data */ ; } else { - printf("Received -- %s --:%d\n", buf, recv_num); + printf("Received -- %s --:%zd\n", buf, recv_num); ret = send(cfd, buf, recv_num, 0); if (ret < 0) { perror("send"); goto END; } - printf("Sending -- %s --:%d\n", buf, recv_num); + printf("Sending -- %s --:%zd\n", buf, recv_num); } } END: close(cfd); diff --git a/newip/examples/nip_udp_client_demo.c b/newip/examples/nip_udp_client_demo.c index 05ffa62..efad5d2 100644 --- a/newip/examples/nip_udp_client_demo.c +++ b/newip/examples/nip_udp_client_demo.c @@ -23,7 +23,7 @@ #include "nip_lib.h" #include "newip_route.h" -int _sendto(int cfd, struct sockaddr_nin *si_server, int pkt_num) +static int _sendto(int cfd, struct sockaddr_nin *si_server, int pkt_num) { char buf[BUFLEN] = {0}; struct timeval sys_time; @@ -44,7 +44,7 @@ int _sendto(int cfd, struct sockaddr_nin *si_server, int pkt_num) return 0; } -int _recvfrom(int cfd, struct sockaddr_nin *si_server, int pkt_num, int *success) +static int _recvfrom(int cfd, struct sockaddr_nin *si_server, int pkt_num, int *success) { char buf[BUFLEN] = {0}; fd_set readfds; @@ -62,7 +62,7 @@ int _recvfrom(int cfd, struct sockaddr_nin *si_server, int pkt_num, int *success } if (FD_ISSET(cfd, &readfds)) { - int ret; + ssize_t ret; int no = 0; ret = recvfrom(cfd, buf, BUFLEN, 0, (struct sockaddr *)si_server, &slen); @@ -73,7 +73,7 @@ int _recvfrom(int cfd, struct sockaddr_nin *si_server, int pkt_num, int *success printf("Received --%s sock %d success:%6d/%6d/no=%6d\n", buf, cfd, *success, pkt_num + 1, no); } else { - printf("client recvfrom fail, ret=%d\n", ret); + printf("client recvfrom fail, ret=%zd\n", ret); return -1; } } @@ -81,7 +81,7 @@ int _recvfrom(int cfd, struct sockaddr_nin *si_server, int pkt_num, int *success return 0; } -void *send_recv(void *args) +static void *send_recv(void *args) { int success = 0; int cfd = ((struct thread_args *)args)->cfd; diff --git a/newip/examples/nip_udp_server_demo.c b/newip/examples/nip_udp_server_demo.c index fb2eb1a..40f767b 100644 --- a/newip/examples/nip_udp_server_demo.c +++ b/newip/examples/nip_udp_server_demo.c @@ -24,10 +24,11 @@ #include "nip_lib.h" #include "newip_route.h" -void *recv_send(void *args) +static void *recv_send(void *args) { char buf[BUFLEN] = {0}; - int fd, ret, recv_num; + int fd; + ssize_t recv_num, ret; int count = 0; socklen_t slen; struct sockaddr_nin si_remote; @@ -39,7 +40,7 @@ void *recv_send(void *args) memset(&si_remote, 0, sizeof(si_remote)); recv_num = recvfrom(fd, buf, BUFLEN, 0, (struct sockaddr *)&si_remote, &slen); if (recv_num < 0) { - printf("server recvfrom fail, ret=%d\n", ret); + printf("server recvfrom fail, recv_num=%zd\n", recv_num); goto END; } else if (recv_num == 0) { /* no data */ ; @@ -49,7 +50,7 @@ void *recv_send(void *args) slen = sizeof(si_remote); ret = sendto(fd, buf, BUFLEN, 0, (struct sockaddr *)&si_remote, slen); if (ret < 0) { - printf("server sendto fail, ret=%d\n", ret); + printf("server sendto fail, ret=%zd\n", ret); goto END; } printf("Sending -- %s -- to 0x%0x:%d\n", buf, diff --git a/newip/src/common/nip_addr.c b/newip/src/common/nip_addr.c index 31105bc..d61d879 100644 --- a/newip/src/common/nip_addr.c +++ b/newip/src/common/nip_addr.c @@ -424,7 +424,7 @@ unsigned char *decode_nip_addr(struct nip_buff *nbuf, struct nip_addr *addr) addr->NIP_ADDR_FIELD8[i] = *nbuf->data; nip_buff_pull(nbuf, sizeof(unsigned char)); } - addr->bitlen = addr_len * NIP_ADDR_BIT_LEN_8; + addr->bitlen = (unsigned char)(addr_len * NIP_ADDR_BIT_LEN_8); ret = nip_addr_invalid(addr); if (ret) diff --git a/newip/src/common/nip_checksum.c b/newip/src/common/nip_checksum.c index a5ecef1..47f196a 100644 --- a/newip/src/common/nip_checksum.c +++ b/newip/src/common/nip_checksum.c @@ -14,7 +14,7 @@ #define USHORT_PAYLOAD 16 #define NIP_CHECKSUM_UINT8_PAYLOAD 8 -unsigned int _nip_check_sum(const unsigned char *data, unsigned short data_len) +static unsigned int _nip_check_sum(const unsigned char *data, unsigned short data_len) { unsigned int i = 0; unsigned int sum = 0; @@ -30,10 +30,10 @@ unsigned int _nip_check_sum(const unsigned char *data, unsigned short data_len) return sum; } -unsigned int _nip_header_chksum(struct nip_pseudo_header *chksum_header) +static unsigned int _nip_header_chksum(struct nip_pseudo_header *chksum_header) { int i, j; - int addr_len; + unsigned short addr_len; unsigned char pseudo_header[NIP_HDR_MAX] = {0}; unsigned short hdr_len = 0; diff --git a/newip/src/common/nip_hdr_decap.c b/newip/src/common/nip_hdr_decap.c index abec609..1637fdc 100644 --- a/newip/src/common/nip_hdr_decap.c +++ b/newip/src/common/nip_hdr_decap.c @@ -285,7 +285,7 @@ int nip_hdr_parse(unsigned char *rcv_buf, unsigned int buf_len, struct nip_hdr_d if (buf_len < nbuf.remaining_len) return -NIP_HDR_RCV_BUF_READ_OUT_RANGE; - niph->hdr_real_len = buf_len - nbuf.remaining_len; + niph->hdr_real_len = (unsigned char)(buf_len - nbuf.remaining_len); ret = nip_hdr_check(niph); if (ret < 0) return ret; diff --git a/newip/src/common/nip_hdr_encap.c b/newip/src/common/nip_hdr_encap.c index b971834..4e9e11c 100644 --- a/newip/src/common/nip_hdr_encap.c +++ b/newip/src/common/nip_hdr_encap.c @@ -53,7 +53,7 @@ static inline void _nip_hdr_len_encap(struct nip_hdr_encap *head) static inline void _nip_update_hdr_len(struct nip_hdr_encap *head) { - *head->hdr_len_pos = head->hdr_buf_pos; + *head->hdr_len_pos = (unsigned char)head->hdr_buf_pos; } static inline void _nip_hdr_nexthdr_encap(struct nip_hdr_encap *head) diff --git a/newip/src/linux-5.10/net/newip/tcp_nip_parameter.c b/newip/src/linux-5.10/net/newip/tcp_nip_parameter.c index 3964fac..7a794a8 100644 --- a/newip/src/linux-5.10/net/newip/tcp_nip_parameter.c +++ b/newip/src/linux-5.10/net/newip/tcp_nip_parameter.c @@ -171,7 +171,7 @@ int get_dup_ack_snd_max(void) /* RTT timestamp parameters */ /*********************************************************************************************/ int g_rtt_tstamp_rto_up = 100; // rtt_tstamp >= 100 ==> shorten rto -module_param_named(rtt_tstamp_rto_up, g_rtt_tstamp_rto_up, int, 0644); +module_param_named(rtt_tstamp_rto_up, g_rtt_tstamp_rto_up, int, 0644); int get_rtt_tstamp_rto_up(void) { @@ -179,7 +179,7 @@ int get_rtt_tstamp_rto_up(void) } int g_rtt_tstamp_high = 30; // rtt_tstamp >= 30 ==> ssthresh = 100K -module_param_named(rtt_tstamp_high, g_rtt_tstamp_high, int, 0644); +module_param_named(rtt_tstamp_high, g_rtt_tstamp_high, int, 0644); int get_rtt_tstamp_high(void) { @@ -187,7 +187,7 @@ int get_rtt_tstamp_high(void) } int g_rtt_tstamp_mid_high = 20; // rtt_tstamp >= 20 ==> ssthresh = 250K -module_param_named(rtt_tstamp_mid_high, g_rtt_tstamp_mid_high, int, 0644); +module_param_named(rtt_tstamp_mid_high, g_rtt_tstamp_mid_high, int, 0644); int get_rtt_tstamp_mid_high(void) { @@ -198,7 +198,7 @@ int get_rtt_tstamp_mid_high(void) * rtt_tstamp < 10 ==> ssthresh = 1.5M */ int g_rtt_tstamp_mid_low = 10; -module_param_named(rtt_tstamp_mid_low, g_rtt_tstamp_mid_low, int, 0644); +module_param_named(rtt_tstamp_mid_low, g_rtt_tstamp_mid_low, int, 0644); int get_rtt_tstamp_mid_low(void) { @@ -206,7 +206,7 @@ int get_rtt_tstamp_mid_low(void) } int g_ack_to_nxt_snd_tstamp = 500; -module_param_named(ack_to_nxt_snd_tstamp, g_ack_to_nxt_snd_tstamp, int, 0644); +module_param_named(ack_to_nxt_snd_tstamp, g_ack_to_nxt_snd_tstamp, int, 0644); int get_ack_to_nxt_snd_tstamp(void) { @@ -359,7 +359,7 @@ bool get_nip_debug(void) /* Debugging of threshold change */ bool g_rtt_ssthresh_debug; -module_param_named(rtt_ssthresh_debug, g_rtt_ssthresh_debug, bool, 0644); +module_param_named(rtt_ssthresh_debug, g_rtt_ssthresh_debug, bool, 0644); bool get_rtt_ssthresh_debug(void) { @@ -368,7 +368,7 @@ bool get_rtt_ssthresh_debug(void) /* Debugging of packet retransmission after ACK */ bool g_ack_retrans_debug; -module_param_named(ack_retrans_debug, g_ack_retrans_debug, bool, 0644); +module_param_named(ack_retrans_debug, g_ack_retrans_debug, bool, 0644); bool get_ack_retrans_debug(void) { diff --git a/newip/third_party/linux-5.10/net/newip/ninet_hashtables.c b/newip/third_party/linux-5.10/net/newip/ninet_hashtables.c index 33f7c5e..ee52eeb 100644 --- a/newip/third_party/linux-5.10/net/newip/ninet_hashtables.c +++ b/newip/third_party/linux-5.10/net/newip/ninet_hashtables.c @@ -343,7 +343,7 @@ found: return sk; } -static inline int nip_tcp_compute_score(struct sock *sk, struct net *net, +static int nip_tcp_compute_score(struct sock *sk, struct net *net, const unsigned short hnum, const struct nip_addr *daddr, const int dif, int sdif) diff --git a/newip/third_party/linux-5.10/net/newip/tcp_nip_output.c b/newip/third_party/linux-5.10/net/newip/tcp_nip_output.c index 0f957ae..875684d 100644 --- a/newip/third_party/linux-5.10/net/newip/tcp_nip_output.c +++ b/newip/third_party/linux-5.10/net/newip/tcp_nip_output.c @@ -79,7 +79,7 @@ static bool tcp_nip_write_xmit(struct sock *sk, unsigned int mss_now, int nonagl int push_one, gfp_t gfp); /* Calculate MSS not accounting any TCP options. */ -static inline int __tcp_nip_mtu_to_mss(struct sock *sk, int pmtu) +static int __tcp_nip_mtu_to_mss(struct sock *sk, int pmtu) { const struct tcp_sock *tp = tcp_sk(sk); const struct inet_connection_sock *icsk = inet_csk(sk); -- Gitee