mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-10-05 22:29:49 +00:00
tcp: add LWIP_HOOK_TCP_INPACKET_PCB
This hook is called from tcp_input() for all kinds of input pcbs when selected to receive a pbuf (LISTEN, TIME_WAIT, rest). I can parse or drop an rx pbuf. Signed-off-by: goldsimon <goldsimon@gmx.de>
This commit is contained in:
parent
0e85582bc0
commit
77d0ee0961
@ -61,6 +61,10 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifdef LWIP_HOOK_FILENAME
|
||||
#include LWIP_HOOK_FILENAME
|
||||
#endif
|
||||
|
||||
/** Initial CWND calculation as defined RFC 2581 */
|
||||
#define LWIP_TCP_CALC_INITIAL_CWND(mss) ((tcpwnd_size_t)LWIP_MIN((4U * (mss)), LWIP_MAX((2U * (mss)), 4380U)))
|
||||
|
||||
@ -295,7 +299,13 @@ tcp_input(struct pbuf *p, struct netif *inp)
|
||||
of the list since we are not very likely to receive that
|
||||
many segments for connections in TIME-WAIT. */
|
||||
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packed for TIME_WAITing connection.\n"));
|
||||
tcp_timewait_input(pcb);
|
||||
#ifdef LWIP_HOOK_TCP_INPACKET_PCB
|
||||
if (LWIP_HOOK_TCP_INPACKET_PCB(pcb, tcphdr, tcphdr_optlen, tcphdr_opt1len,
|
||||
tcphdr_opt2, p) == ERR_OK)
|
||||
#endif
|
||||
{
|
||||
tcp_timewait_input(pcb);
|
||||
}
|
||||
pbuf_free(p);
|
||||
return;
|
||||
}
|
||||
@ -361,7 +371,13 @@ tcp_input(struct pbuf *p, struct netif *inp)
|
||||
}
|
||||
|
||||
LWIP_DEBUGF(TCP_INPUT_DEBUG, ("tcp_input: packed for LISTENing connection.\n"));
|
||||
tcp_listen_input(lpcb);
|
||||
#ifdef LWIP_HOOK_TCP_INPACKET_PCB
|
||||
if (LWIP_HOOK_TCP_INPACKET_PCB((struct tcp_pcb *)lpcb, tcphdr, tcphdr_optlen,
|
||||
tcphdr_opt1len, tcphdr_opt2, p) == ERR_OK)
|
||||
#endif
|
||||
{
|
||||
tcp_listen_input(lpcb);
|
||||
}
|
||||
pbuf_free(p);
|
||||
return;
|
||||
}
|
||||
@ -374,6 +390,13 @@ tcp_input(struct pbuf *p, struct netif *inp)
|
||||
#endif /* TCP_INPUT_DEBUG */
|
||||
|
||||
|
||||
#ifdef LWIP_HOOK_TCP_INPACKET_PCB
|
||||
if ((pcb != NULL) && LWIP_HOOK_TCP_INPACKET_PCB(pcb, tcphdr, tcphdr_optlen,
|
||||
tcphdr_opt1len, tcphdr_opt2, p) != ERR_OK) {
|
||||
pbuf_free(p);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (pcb != NULL) {
|
||||
/* The incoming segment belongs to a connection. */
|
||||
#if TCP_INPUT_DEBUG
|
||||
|
@ -2696,6 +2696,35 @@
|
||||
#define LWIP_HOOK_TCP_ISN(local_ip, local_port, remote_ip, remote_port)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* LWIP_HOOK_TCP_INPACKET_PCB:
|
||||
* Hook for intercepting incoming packets before they are passed to a pcb. This
|
||||
* allows updating some state or even dropping a packet.
|
||||
* Signature:
|
||||
* err_t my_hook_tcp_inpkt(struct tcp_pcb *pcb, struct tcp_hdr *hdr, u16_t optlen, u16_t opt1len, u8_t *opt2, struct pbuf *p);
|
||||
* Arguments:
|
||||
* - pcb: tcp_pcb selected for input of this packet (ATTENTION: this may be
|
||||
* struct tcp_pcb_listen if pcb->state == LISTEN)
|
||||
* - hdr: pointer to tcp header (ATTENTION: tcp options may not be in one piece!)
|
||||
* - optlen: tcp option length
|
||||
* - opt1len: tcp option length 1st part
|
||||
* - opt2: if this is != NULL, tcp options are split among 2 pbufs. In that case,
|
||||
* options start at right after the tcp header ('(u8_t*)(hdr + 1)') for
|
||||
* the first 'opt1len' bytes and the rest starts at 'opt2'. opt2len can
|
||||
* be simply calculated: 'opt2len = optlen - opt1len;'
|
||||
* - p: input packet, p->payload points to application data (that's why tcp hdr
|
||||
* and options are passed in seperately)
|
||||
* Return value:
|
||||
* - ERR_OK: continue input of this packet as normal
|
||||
* - != ERR_OK: drop this packet for input (don't continue input processing)
|
||||
*
|
||||
* ATTENTION: don't call any tcp api functions that might change tcp state (pcb
|
||||
* state or any pcb lists) from this callback!
|
||||
*/
|
||||
#ifdef __DOXYGEN__
|
||||
#define LWIP_HOOK_TCP_INPACKET_PCB(pcb, hdr, optlen, opt1len, opt2, p)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* LWIP_HOOK_IP4_INPUT(pbuf, input_netif):
|
||||
* Called from ip_input() (IPv4)
|
||||
|
Loading…
Reference in New Issue
Block a user