when doing TSO, avoid to use duplicated ip_id heavily.

XXX ip_randomid
This commit is contained in:
yamt 2005-04-07 12:22:47 +00:00
parent 9eabef72e3
commit 0b4d50d7bd
2 changed files with 46 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_output.c,v 1.149 2005/03/11 17:07:51 matt Exp $ */ /* $NetBSD: ip_output.c,v 1.150 2005/04/07 12:22:47 yamt Exp $ */
/* /*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -98,7 +98,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.149 2005/03/11 17:07:51 matt Exp $"); __KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.150 2005/04/07 12:22:47 yamt Exp $");
#include "opt_pfil_hooks.h" #include "opt_pfil_hooks.h"
#include "opt_inet.h" #include "opt_inet.h"
@ -235,7 +235,26 @@ ip_output(struct mbuf *m0, ...)
if ((flags & (IP_FORWARDING|IP_RAWOUTPUT)) == 0) { if ((flags & (IP_FORWARDING|IP_RAWOUTPUT)) == 0) {
ip->ip_v = IPVERSION; ip->ip_v = IPVERSION;
ip->ip_off = htons(0); ip->ip_off = htons(0);
ip->ip_id = ip_newid(); if ((m->m_pkthdr.csum_flags & M_CSUM_TSOv4) == 0) {
ip->ip_id = ip_newid();
} else {
/*
* TSO capable interfaces (typically?) increment
* ip_id for each segment.
* "allocate" enough ids here to increase the chance
* for them to be unique.
*
* note that the following calculation is not
* needed to be precise. wasting some ip_id is fine.
*/
unsigned int segsz = m->m_pkthdr.segsz;
unsigned int datasz = ntohs(ip->ip_len) - hlen;
unsigned int num = howmany(datasz, segsz);
ip->ip_id = ip_newid_range(num);
}
ip->ip_hl = hlen >> 2; ip->ip_hl = hlen >> 2;
ipstat.ips_localout++; ipstat.ips_localout++;
} else { } else {

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_var.h,v 1.69 2004/12/15 04:25:19 thorpej Exp $ */ /* $NetBSD: ip_var.h,v 1.70 2005/04/07 12:22:47 yamt Exp $ */
/* /*
* Copyright (c) 1982, 1986, 1993 * Copyright (c) 1982, 1986, 1993
@ -263,13 +263,33 @@ static __inline uint16_t ip_newid(void);
u_int16_t ip_randomid(void); u_int16_t ip_randomid(void);
extern int ip_do_randomid; extern int ip_do_randomid;
/*
* ip_newid_range: "allocate" num contiguous ip_ids.
*
* => return the first id.
*/
static __inline uint16_t
ip_newid_range(unsigned int num)
{
uint16_t id;
if (ip_do_randomid) {
/* XXX ignore num */
return ip_randomid();
}
id = htons(ip_id);
ip_id += num;
return id;
}
static __inline uint16_t static __inline uint16_t
ip_newid(void) ip_newid(void)
{ {
if (ip_do_randomid)
return ip_randomid();
return htons(ip_id++); return ip_newid_range(1);
} }
#endif /* _KERNEL */ #endif /* _KERNEL */