summaryrefslogtreecommitdiffstats
path: root/sys/net/if_loop.c
diff options
context:
space:
mode:
authorrwatson <rwatson@FreeBSD.org>2009-03-15 20:17:44 +0000
committerrwatson <rwatson@FreeBSD.org>2009-03-15 20:17:44 +0000
commit4fc2f82f67bc08664b8ed7df98cea3f48013160d (patch)
tree530a65986c07f1088440b3c9121142d5a6112c2c /sys/net/if_loop.c
parente488f4df7ac6fbbbb933a95cb2b979f2d98ebd95 (diff)
downloadFreeBSD-src-4fc2f82f67bc08664b8ed7df98cea3f48013160d.zip
FreeBSD-src-4fc2f82f67bc08664b8ed7df98cea3f48013160d.tar.gz
Teach the loopback interface about checksum generation and validation
avoidance: - Enable setting the RXCSUM and TXCSUM flags for loopback interfaces; set both by default. - When RXCSUM is set, flag packets sent over the loopback interface as having checked and valid IP, UDP, TCP checksums so that higher protocol layers won't check them. - Always clear CSUM_{IP,UDP_TCP} checksum required flags on transmit, as they will have gotten there as a result of TXCSUM being set. This is done only for packets explicitly sent over the loopback, not simulated loopback via if_simloop() due to !SIMPLEX interfaces, etc. Note that enabling TXCSUM but not RXCSUM will lead to unhappiness, as checksums won't be generated but will be validated. Kris reports that this leads to significant performance improvements in loopback benchmarking with TCP and UDP for throughput: RXCSUM RXCSUM+TXCSUM TCP 15% 37% UDP 10% 74% Update man page. Reviewed by: sam Tested by: kris MFC after: 1 week
Diffstat (limited to 'sys/net/if_loop.c')
-rw-r--r--sys/net/if_loop.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/sys/net/if_loop.c b/sys/net/if_loop.c
index d5548fc..3fd003e 100644
--- a/sys/net/if_loop.c
+++ b/sys/net/if_loop.c
@@ -138,6 +138,8 @@ lo_clone_create(struct if_clone *ifc, int unit, caddr_t params)
ifp->if_ioctl = loioctl;
ifp->if_output = looutput;
ifp->if_snd.ifq_maxlen = ifqmaxlen;
+ ifp->if_hwassist = ifp->if_capabilities = ifp->if_capenable =
+ IFCAP_HWCSUM;
if_attach(ifp);
bpfattach(ifp, DLT_NULL, sizeof(u_int32_t));
if (V_loif == NULL)
@@ -212,6 +214,13 @@ looutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
#if 1 /* XXX */
switch (dst->sa_family) {
case AF_INET:
+ if (ifp->if_capenable & IFCAP_RXCSUM) {
+ m->m_pkthdr.csum_data = 0xffff;
+ m->m_pkthdr.csum_flags = CSUM_DATA_VALID |
+ CSUM_PSEUDO_HDR | CSUM_IP_CHECKED |
+ CSUM_IP_VALID | CSUM_SCTP_VALID;
+ }
+ m->m_pkthdr.csum_flags &= ~(CSUM_IP | CSUM_TCP | CSUM_UDP);
case AF_INET6:
case AF_IPX:
case AF_APPLETALK:
@@ -348,7 +357,7 @@ loioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
{
struct ifaddr *ifa;
struct ifreq *ifr = (struct ifreq *)data;
- int error = 0;
+ int error = 0, mask;
switch (cmd) {
case SIOCSIFADDR:
@@ -391,6 +400,18 @@ loioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
case SIOCSIFFLAGS:
break;
+ case SIOCSIFCAP:
+ mask = ifp->if_capenable ^ ifr->ifr_reqcap;
+ if ((mask & IFCAP_RXCSUM) != 0)
+ ifp->if_capenable ^= IFCAP_RXCSUM;
+ if ((mask & IFCAP_TXCSUM) != 0)
+ ifp->if_capenable ^= IFCAP_TXCSUM;
+ if (ifp->if_capenable & IFCAP_TXCSUM)
+ ifp->if_hwassist = CSUM_IP | CSUM_TCP | CSUM_UDP;
+ else
+ ifp->if_hwassist = 0;
+ break;
+
default:
error = EINVAL;
}
OpenPOWER on IntegriCloud