mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-06-13 08:23:56 +08:00
Add hook for TCP Initial Sequence Number generation
lwIP produces a TCP Initial Sequence Number (ISN) for each new TCP connection. The current algorithm is simple and predictable however. The result is that lwIP TCP connections may be the target of TCP spoofing attacks. The problem of such attacks is well known, and a recommended ISN generation algorithm is standardized in RFC 6528. This algorithm requires a high-resolution timer and cryptographic hashing function, though. The implementation (or best-effort approximation) of both of these aspects is well beyond the scope of lwIP itself. For that reason, this patch adds LWIP_HOOK_TCP_ISN, a hook that allows each platform to implement its own ISN generation using locally available means. The hook provides full flexibility, in that the hook may generate anything from a simple random number (by being set to LWIP_RAND()) to a full RFC 6528 implementation. Implementation note: Users of the hook would typically declare the function prototype of the hook function in arch/cc.h, as this is the last place where such prototypes can be supplied. However, at that point, the ip_addr_t type has not yet been defined. For that reason, this patch removes the leading underscore from "struct _ip_addr", so that a prototype of the hook function can use "struct ip_addr" instead of "ip_addr_t". Signed-off-by: sg <goldsimon@gmx.de>
This commit is contained in:
committed by
sg
parent
da15132aa0
commit
a8b986bbb6
@@ -880,10 +880,11 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port,
|
||||
#endif /* SO_REUSE */
|
||||
}
|
||||
|
||||
iss = tcp_next_iss();
|
||||
iss = tcp_next_iss(pcb);
|
||||
pcb->rcv_nxt = 0;
|
||||
pcb->snd_nxt = iss;
|
||||
pcb->lastack = iss - 1;
|
||||
pcb->snd_wl2 = iss - 1;
|
||||
pcb->snd_lbb = iss - 1;
|
||||
/* Start with a window that does not need scaling. When window scaling is
|
||||
enabled and used, the window is enlarged when both sides agree on scaling. */
|
||||
@@ -1491,7 +1492,6 @@ struct tcp_pcb *
|
||||
tcp_alloc(u8_t prio)
|
||||
{
|
||||
struct tcp_pcb *pcb;
|
||||
u32_t iss;
|
||||
|
||||
pcb = (struct tcp_pcb *)memp_malloc(MEMP_TCP_PCB);
|
||||
if (pcb == NULL) {
|
||||
@@ -1554,11 +1554,6 @@ tcp_alloc(u8_t prio)
|
||||
pcb->sv = 3000 / TCP_SLOW_INTERVAL;
|
||||
pcb->rtime = -1;
|
||||
pcb->cwnd = 1;
|
||||
iss = tcp_next_iss();
|
||||
pcb->snd_wl2 = iss;
|
||||
pcb->snd_nxt = iss;
|
||||
pcb->lastack = iss;
|
||||
pcb->snd_lbb = iss;
|
||||
pcb->tmr = tcp_ticks;
|
||||
pcb->last_timer = tcp_timer_ctr;
|
||||
|
||||
@@ -1826,12 +1821,18 @@ tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb)
|
||||
* @return u32_t pseudo random sequence number
|
||||
*/
|
||||
u32_t
|
||||
tcp_next_iss(void)
|
||||
tcp_next_iss(struct tcp_pcb *pcb)
|
||||
{
|
||||
#ifdef LWIP_HOOK_TCP_ISN
|
||||
return LWIP_HOOK_TCP_ISN(&pcb->local_ip, pcb->local_port, &pcb->remote_ip, pcb->remote_port);
|
||||
#else /* LWIP_HOOK_TCP_ISN */
|
||||
static u32_t iss = 6510;
|
||||
|
||||
LWIP_UNUSED_ARG(pcb);
|
||||
|
||||
iss += tcp_ticks; /* XXX */
|
||||
return iss;
|
||||
#endif /* LWIP_HOOK_TCP_ISN */
|
||||
}
|
||||
|
||||
#if TCP_CALCULATE_EFF_SEND_MSS
|
||||
|
||||
@@ -542,6 +542,7 @@ static void
|
||||
tcp_listen_input(struct tcp_pcb_listen *pcb)
|
||||
{
|
||||
struct tcp_pcb *npcb;
|
||||
u32_t iss;
|
||||
err_t rc;
|
||||
|
||||
if (flags & TCP_RST) {
|
||||
@@ -589,6 +590,11 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
|
||||
npcb->state = SYN_RCVD;
|
||||
npcb->rcv_nxt = seqno + 1;
|
||||
npcb->rcv_ann_right_edge = npcb->rcv_nxt;
|
||||
iss = tcp_next_iss(npcb);
|
||||
npcb->snd_wl2 = iss;
|
||||
npcb->snd_nxt = iss;
|
||||
npcb->lastack = iss;
|
||||
npcb->snd_lbb = iss;
|
||||
npcb->snd_wl1 = seqno - 1;/* initialise to seqno-1 to force window update */
|
||||
npcb->callback_arg = pcb->callback_arg;
|
||||
#if LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG
|
||||
|
||||
Reference in New Issue
Block a user