anchao commented on code in PR #7616: URL: https://github.com/apache/incubator-nuttx/pull/7616#discussion_r1027227537
########## net/icmp/icmp_input.c: ########## @@ -100,86 +100,39 @@ static uint16_t icmp_datahandler(FAR struct net_driver_s *dev, FAR struct ipv4_hdr_s *ipv4; struct sockaddr_in inaddr; FAR struct iob_s *iob; - uint16_t offset; - uint16_t buflen; uint16_t iphdrlen; - uint8_t addrsize; + uint16_t buflen; int ret; - /* Try to allocate on I/O buffer to start the chain without waiting (and - * throttling as necessary). If we would have to wait, then drop the - * packet. - */ - - iob = iob_tryalloc(true); - if (iob == NULL) - { - nerr("ERROR: Failed to create new I/O buffer chain\n"); - goto drop; - } - /* Put the IPv4 address at the beginning of the read-ahead buffer */ - ipv4 = IPv4BUF; - + iob = dev->d_iob; + ipv4 = IPv4BUF; inaddr.sin_family = AF_INET; inaddr.sin_port = 0; net_ipv4addr_copy(inaddr.sin_addr.s_addr, net_ip4addr_conv32(ipv4->srcipaddr)); memset(inaddr.sin_zero, 0, sizeof(inaddr.sin_zero)); - /* Copy the src address info into the I/O buffer chain. We will not wait - * for an I/O buffer to become available in this context. It there is - * any failure to allocated, the entire I/O buffer chain will be discarded. - */ - - addrsize = sizeof(struct sockaddr_in); - ret = iob_trycopyin(iob, &addrsize, sizeof(uint8_t), 0, true); - if (ret < 0) - { - /* On a failure, iob_trycopyin return a negated error value but does - * not free any I/O buffers. - */ - - nerr("ERROR: Failed to length to the I/O buffer chain: %d\n", ret); - goto drop_with_chain; - } - - offset = sizeof(uint8_t); - - ret = iob_trycopyin(iob, (FAR const uint8_t *)&inaddr, - sizeof(struct sockaddr_in), offset, true); - if (ret < 0) - { - /* On a failure, iob_trycopyin return a negated error value but does - * not free any I/O buffers. - */ - - nerr("ERROR: Failed to source address to the I/O buffer chain: %d\n", - ret); - goto drop_with_chain; - } - - offset += sizeof(struct sockaddr_in); - /* Get the IP header length (accounting for possible options). */ iphdrlen = (ipv4->vhl & IPv4_HLMASK) << 2; + /* Copy the src address info into the front of I/O buffer chain which + * overwrites the contents of the packet header field. + */ + + memcpy(iob->io_data, (FAR const uint8_t *)&inaddr, Review Comment: could be removed ########## net/icmpv6/icmpv6_input.c: ########## @@ -87,82 +87,33 @@ static uint16_t icmpv6_datahandler(FAR struct net_driver_s *dev, unsigned int iplen) { FAR struct ipv6_hdr_s *ipv6; - FAR struct icmpv6_hdr_s *icmpv6; - FAR struct iob_s *iob; struct sockaddr_in6 inaddr; - uint16_t offset; + FAR struct iob_s *iob; uint16_t buflen; - uint8_t addrsize; int ret; - /* Try to allocate on I/O buffer to start the chain without waiting (and - * throttling as necessary). If we would have to wait, then drop the - * packet. - */ - - iob = iob_tryalloc(true); - if (iob == NULL) - { - nerr("ERROR: Failed to create new I/O buffer chain\n"); - goto drop; - } - /* Put the IPv6 address at the beginning of the read-ahead buffer */ + iob = dev->d_iob; ipv6 = IPv6BUF; inaddr.sin6_family = AF_INET6; inaddr.sin6_port = 0; net_ipv6addr_copy(inaddr.sin6_addr.s6_addr16, ipv6->srcipaddr); - /* Copy the src address info into the I/O buffer chain. We will not wait - * for an I/O buffer to become available in this context. It there is - * any failure to allocated, the entire I/O buffer chain will be discarded. + /* Copy the src address info into the front of I/O buffer chain which + * overwrites the contents of the packet header field. */ - addrsize = sizeof(struct sockaddr_in6); - ret = iob_trycopyin(iob, &addrsize, sizeof(uint8_t), 0, true); - if (ret < 0) - { - /* On a failure, iob_trycopyin return a negated error value but does - * not free any I/O buffers. - */ - - nerr("ERROR: Failed to length to the I/O buffer chain: %d\n", ret); - goto drop_with_chain; - } - - offset = sizeof(uint8_t); - - ret = iob_trycopyin(iob, (FAR const uint8_t *)&inaddr, - sizeof(struct sockaddr_in6), offset, true); - if (ret < 0) - { - /* On a failure, iob_trycopyin return a negated error value but does - * not free any I/O buffers. - */ - - nerr("ERROR: Failed to source address to the I/O buffer chain: %d\n", - ret); - goto drop_with_chain; - } - - offset += sizeof(struct sockaddr_in6); + memcpy(iob->io_data, (FAR const uint8_t *)&inaddr, Review Comment: Done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org