mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-05-20 15:17:05 +08:00
raw: core support for IP_HDRINCL socket option
This patch adds a new RAW_FLAGS_HDRINCL flag to the raw core implementation. When this flag is set on a RAW PCB, the raw send routines expect the caller to supply an IP header for the given packet, and will use that IP header instead of prepending one to the packet themselves. This feature allows the IP_HDRINCL socket option to be implemented in higher layers with no further effort. Even thoguh that option is traditionally supported for IPv4 sockets only (e.g., see RFC 3542 Sec. 3), the RAW_FLAGS_HDRINCL flag supports both IPv4 and IPv6, as much of the lower-level infrastructure was already in place anyway.
This commit is contained in:
committed by
Dirk Ziegelmeier
parent
162cc4d343
commit
b59472cf63
@@ -287,11 +287,9 @@ raw_recv(struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg)
|
||||
|
||||
/**
|
||||
* @ingroup raw_raw
|
||||
* Send the raw IP packet to the given address. Note that actually you cannot
|
||||
* modify the IP headers (this is inconsistent with the receive callback where
|
||||
* you actually get the IP headers), you can only specify the IP payload here.
|
||||
* It requires some more changes in lwIP. (there will be a raw_send() function
|
||||
* then.)
|
||||
* Send the raw IP packet to the given address. An IP header will be prepended
|
||||
* to the packet, unless the RAW_FLAGS_HDRINCL flag is set on the PCB. In that
|
||||
* case, the packet must include an IP header, which will then be sent as is.
|
||||
*
|
||||
* @param pcb the raw pcb which to send
|
||||
* @param p the IP payload to send
|
||||
@@ -342,7 +340,9 @@ raw_sendto(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr)
|
||||
/**
|
||||
* @ingroup raw_raw
|
||||
* Send the raw IP packet to the given address, using a particular outgoing
|
||||
* netif and source IP address. An IP header will be prepended to the packet.
|
||||
* netif and source IP address. An IP header will be prepended to the packet,
|
||||
* unless the RAW_FLAGS_HDRINCL flag is set on the PCB. In that case, the
|
||||
* packet must include an IP header, which will then be sent as is.
|
||||
*
|
||||
* @param pcb RAW PCB used to send the data
|
||||
* @param p chain of pbufs to be sent
|
||||
@@ -372,6 +372,20 @@ raw_sendto_if_src(struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip,
|
||||
IP6_HLEN);
|
||||
#endif
|
||||
|
||||
/* Handle the HDRINCL option as an exception: none of the code below applies
|
||||
* to this case, and sending the packet needs to be done differently too. */
|
||||
if (pcb->flags & RAW_FLAGS_HDRINCL) {
|
||||
/* A full header *must* be present in the first pbuf of the chain, as the
|
||||
* output routines may access its fields directly. */
|
||||
if (p->len < header_size) {
|
||||
return ERR_VAL;
|
||||
}
|
||||
NETIF_SET_HWADDRHINT(netif, &pcb->addr_hint);
|
||||
err = ip_output_if_hdrincl(p, src_ip, dst_ip, netif);
|
||||
NETIF_SET_HWADDRHINT(netif, NULL);
|
||||
return err;
|
||||
}
|
||||
|
||||
/* not enough space to add an IP header to first pbuf in given p chain? */
|
||||
if (pbuf_header(p, header_size)) {
|
||||
/* allocate header in new pbuf */
|
||||
|
||||
Reference in New Issue
Block a user