Summary: lwip 2.1.0 socket raw api lack of IPv6 cmsghdr
Project: lwIP - A Lightweight TCP/IP stack
Submitted by: yanhc
Submitted on: Fri 16 Nov 2018 03:03:11 PM UTC
Severity: 3 - Normal
Item Group: Feature Request
Assigned to: None
Discussion Lock: Any
Planned Release: None
lwIP version: 2.1.0
Recently, I am using socket raw api to just receive ipv6 payload. In my
project, I need the cmsghdr information. However, I found that there is only
IPv4 cmsghdr support and no IPv6 cmsghdr support in "lwip_recvfrom_udp_raw"
function in sockets.c. So I add the IPv6 cmsghdr support following the example
of IPv4 in sockets.c and sockets.h which can be found the attached diff file.
Since the IPv6 cmsghdr need the destaddr and if_idx info, again, I found that
in "recv_raw" function in api_msg.c, there is lack support for
LWIP_NETBUF_RECVINFO. So I add the LWIP_NETBUF_RECVINFO support following the
example in "recv_udp" function.
The information of buf->p->if_idx is also lost in "pbuf_clone" in "recv_udp"
function in api_msg.c where pbuf p is copied to pbuf q. So I just add the
"q->if_idx = p->if_idx;" in "pbuf_clone" function.
The changing of api_msg.c and pbuf.c can also be found in the attached diff
Another issue is about MLD for socket raw api, I found that MLD only check UDP
and ignore RAW in "lwip_setsockopt_impl" function in sockets.c. Since in my
project I only use MLD from RAW api so I just change the following line to
NETCONN_RAW rather than support both RAW and UDP which is not appropriate.
LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, struct ipv6_mreq,
I am not sure whether the above changes are appropriate, so I just pointed out
and wait for offical update.
[bug #55037] lwip 2.1.0 socket raw api lack of IPv6 cmsghdr information
Follow-up Comment #2, bug #55037 (project lwip):
I Checked the patch #9554 and it really provides most of this post already
except the pbuf_clone changes if I did not miss it.
I have another question.
Since I use SOCK_RAW to get exactly IPv6 payload info, however, I will receive
all IPv6 packet include IPv6 header in the application. I notice that in line
1053 of ip6.c, the ipv6 header is added again as following:
/* p points to IPv6 header again for raw_input. */
/* raw input did not eat the packet? */
raw_status = raw_input(p, inp);
So why raw_input need the IPv6 header info? What is the motivation behind
this? At least, I do not need the IPv6 header in my application since the
cmsghdr has already provide destaddr information which maybe the most commonly
used IPv6 header information.