mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-05-19 14:46:58 +08:00
sockets: task #14247, add CMSG and IP_PKTINFO
This commit adds CMSG infrastructure (currently used with recvmsg) and the IP_PKTINFO socket option. In order to use IP_PKTINFO, set LWIP_NETBUF_RECVINFO to 1 Unit test is added to verify this feature
This commit is contained in:
@@ -81,6 +81,10 @@ extern "C" {
|
||||
dual-stack usage by default. */
|
||||
#define NETCONN_FLAG_IPV6_V6ONLY 0x20
|
||||
#endif /* LWIP_IPV6 */
|
||||
#if LWIP_NETBUF_RECVINFO
|
||||
/** Received packet info will be recorded for this netconn */
|
||||
#define NETCONN_FLAG_PKTINFO 0x40
|
||||
#endif /* LWIP_NETBUF_RECVINFO */
|
||||
|
||||
|
||||
/* Helpers to process several netconn_types by the same code */
|
||||
|
||||
@@ -62,9 +62,7 @@ struct netbuf {
|
||||
ip_addr_t addr;
|
||||
u16_t port;
|
||||
#if LWIP_NETBUF_RECVINFO || LWIP_CHECKSUM_ON_COPY
|
||||
#if LWIP_CHECKSUM_ON_COPY
|
||||
u8_t flags;
|
||||
#endif /* LWIP_CHECKSUM_ON_COPY */
|
||||
u16_t toport_chksum;
|
||||
#if LWIP_NETBUF_RECVINFO
|
||||
ip_addr_t toaddr;
|
||||
|
||||
@@ -135,6 +135,42 @@ struct msghdr {
|
||||
#define MSG_TRUNC 0x04
|
||||
#define MSG_CTRUNC 0x08
|
||||
|
||||
/* RFC 3542, Section 20: Ancillary Data */
|
||||
struct cmsghdr {
|
||||
socklen_t cmsg_len; /* number of bytes, including header */
|
||||
int cmsg_level; /* originating protocol */
|
||||
int cmsg_type; /* protocol-specific type */
|
||||
};
|
||||
/* Data section follows header and possible padding, typically referred to as
|
||||
unsigned char cmsg_data[]; */
|
||||
|
||||
/* cmsg header/data alignment */
|
||||
#define ALIGN_H(size) LWIP_MEM_ALIGN_SIZE(size)
|
||||
#define ALIGN_D(size) LWIP_MEM_ALIGN_SIZE(size)
|
||||
|
||||
#define CMSG_FIRSTHDR(mhdr) \
|
||||
((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
|
||||
(struct cmsghdr *)(mhdr)->msg_control : \
|
||||
(struct cmsghdr *)NULL)
|
||||
|
||||
#define CMSG_NXTHDR(mhdr, cmsg) \
|
||||
(((cmsg) == NULL) ? CMSG_FIRSTHDR(mhdr) : \
|
||||
(((u8_t *)(cmsg) + ALIGN_H((cmsg)->cmsg_len) \
|
||||
+ ALIGN_D(sizeof(struct cmsghdr)) > \
|
||||
(u8_t *)((mhdr)->msg_control) + (mhdr)->msg_controllen) ? \
|
||||
(struct cmsghdr *)NULL : \
|
||||
(struct cmsghdr *)((u8_t *)(cmsg) + \
|
||||
ALIGN_H((cmsg)->cmsg_len))))
|
||||
|
||||
#define CMSG_DATA(cmsg) ((u8_t *)(cmsg) + \
|
||||
ALIGN_D(sizeof(struct cmsghdr)))
|
||||
|
||||
#define CMSG_SPACE(length) (ALIGN_D(sizeof(struct cmsghdr)) + \
|
||||
ALIGN_H(length))
|
||||
|
||||
#define CMSG_LEN(length) (ALIGN_D(sizeof(struct cmsghdr)) + \
|
||||
length)
|
||||
|
||||
/* Socket protocol types (TCP/UDP/RAW) */
|
||||
#define SOCK_STREAM 1
|
||||
#define SOCK_DGRAM 2
|
||||
@@ -221,6 +257,7 @@ struct linger {
|
||||
*/
|
||||
#define IP_TOS 1
|
||||
#define IP_TTL 2
|
||||
#define IP_PKTINFO 8
|
||||
|
||||
#if LWIP_TCP
|
||||
/*
|
||||
@@ -272,6 +309,13 @@ typedef struct ip_mreq {
|
||||
} ip_mreq;
|
||||
#endif /* LWIP_IGMP */
|
||||
|
||||
#if LWIP_IPV4
|
||||
struct in_pktinfo {
|
||||
unsigned int ipi_ifindex; /* Interface index */
|
||||
struct in_addr ipi_addr; /* Destination (from header) address */
|
||||
};
|
||||
#endif /* LWIP_IPV4 */
|
||||
|
||||
/*
|
||||
* The Type of Service provides an indication of the abstract
|
||||
* parameters of the quality of service desired. These parameters are
|
||||
|
||||
Reference in New Issue
Block a user