On 11.09.2018 12:29, dhosa wrote:
Hi, I'm trying to add & delete custom header *ESP header* 8 bytes
before IP header, I used *pbuf_header(p,8)* in *ip_output_if_opt*
before /if (pbuf_header(p, IP_HLEN))/
* |room for new header
*
________________________\/________________________________________________
* | ¦ ¦ ¦ ¦ padd ¦
ev. |
* | Ethernet ¦ IP ¦ ESP ¦ Payload(TCP,UDP ¦ next-proto ¦
ICV |
*
|__________¦_______¦______¦_____________________________¦____________¦_____|
* ¦ ¦ ¦
¦
* ¦<- room tail
->¦
struct esp_hdr {
PACK_STRUCT_FIELD(u32_t spi);
PACK_STRUCT_FIELD(u32_t sequence_number);
}
pbuf_header(p,8);
esphdr = (struct esp_hdr *) q->payload;
esphdr->spi = spi;
esphdr->sequence_number = sequence_number;
That doesn't seem completely correct. Per your later image, it seems you
need the IP header to contain proto = ESP, not proto = TCP...
is that correct? How can I delete esp header for an incoming packet
only and keep IP header?
in *ip_input* :
But you must also check it, not only remove it, don't you?
// remove ip and esp header ... 20 for ip + 8 byte for esp
pbuf_header(p,-(IP_HLEN));
esphdr = (struct esp_hdr *)p->payload;
pbuf_header(p,-(8));
// generate IP header
pbuf_header(p, IP_HLEN);
again is that correct?
No, that doesn't seem correct. pbuf_header only moves the payload
pointer, the data is still where it was before. You'll need to fiddle
around with the data or create new pbufs to achieve what you want.
If you wanted to implement this without changing the stack, you'd need
some kind of new hook (as Sergio mentioned) to add the header and change
the IP protocol.
For RX, it might be enough to implement a raw pcb that detects the IP
proto = ESP, checks and hides the header and sends the remaining pbuf up
to tcp_input().
Simon
_______________________________________________
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users