diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2011-04-04 17:44:44 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2011-04-04 17:44:44 +0000 |
commit | 6a30f7d0b34875b3f04cbe05136e7cb5dcc5a1cd (patch) | |
tree | 0229d6c6af44dfd977a80497e25d91c2d6dee1ee | |
parent | a1a24207faf15cb00cca555393dcaa17145ebe64 (diff) |
de-guttenberg our stack a bit
we don't need 7 f***ing copies of the same code to do the protocol checksums
(or not, depending on hw capabilities). claudio ok
-rw-r--r-- | sys/net/pf.c | 17 | ||||
-rw-r--r-- | sys/netinet/in.h | 3 | ||||
-rw-r--r-- | sys/netinet/ip_mroute.c | 16 | ||||
-rw-r--r-- | sys/netinet/ip_output.c | 54 | ||||
-rw-r--r-- | sys/netmpls/mpls_output.c | 8 |
5 files changed, 33 insertions, 65 deletions
diff --git a/sys/net/pf.c b/sys/net/pf.c index 1a49c0a449d..76712f57268 100644 --- a/sys/net/pf.c +++ b/sys/net/pf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pf.c,v 1.732 2011/04/04 14:16:48 henning Exp $ */ +/* $OpenBSD: pf.c,v 1.733 2011/04/04 17:44:43 henning Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -5150,20 +5150,7 @@ pf_route(struct mbuf **m, struct pf_rule *r, int dir, struct ifnet *oifp, } #endif /* IPSEC */ - /* Catch routing changes wrt. hardware checksumming for TCP or UDP. */ - if (m0->m_pkthdr.csum_flags & M_TCPV4_CSUM_OUT) { - if (!(ifp->if_capabilities & IFCAP_CSUM_TCPv4) || - ifp->if_bridge != NULL) { - in_delayed_cksum(m0); - m0->m_pkthdr.csum_flags &= ~M_TCPV4_CSUM_OUT; /* Clr */ - } - } else if (m0->m_pkthdr.csum_flags & M_UDPV4_CSUM_OUT) { - if (!(ifp->if_capabilities & IFCAP_CSUM_UDPv4) || - ifp->if_bridge != NULL) { - in_delayed_cksum(m0); - m0->m_pkthdr.csum_flags &= ~M_UDPV4_CSUM_OUT; /* Clr */ - } - } + in_proto_cksum_out(m0, ifp); if (ntohs(ip->ip_len) <= ifp->if_mtu) { ip->ip_sum = 0; diff --git a/sys/netinet/in.h b/sys/netinet/in.h index f2161ccd4f4..2577ddbfda1 100644 --- a/sys/netinet/in.h +++ b/sys/netinet/in.h @@ -1,4 +1,4 @@ -/* $OpenBSD: in.h,v 1.85 2010/09/23 04:45:15 yasuoka Exp $ */ +/* $OpenBSD: in.h,v 1.86 2011/04/04 17:44:43 henning Exp $ */ /* $NetBSD: in.h,v 1.20 1996/02/13 23:41:47 christos Exp $ */ /* @@ -800,6 +800,7 @@ void in_delayed_cksum(struct mbuf *); int in_localaddr(struct in_addr, u_int); void in_socktrim(struct sockaddr_in *); char *inet_ntoa(struct in_addr); +void in_proto_cksum_out(struct mbuf *, struct ifnet *); #define in_hosteq(s,t) ((s).s_addr == (t).s_addr) #define in_nullhost(x) ((x).s_addr == INADDR_ANY) diff --git a/sys/netinet/ip_mroute.c b/sys/netinet/ip_mroute.c index 12b94ebbb1f..2a32b430171 100644 --- a/sys/netinet/ip_mroute.c +++ b/sys/netinet/ip_mroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_mroute.c,v 1.58 2010/07/02 02:40:16 blambert Exp $ */ +/* $OpenBSD: ip_mroute.c,v 1.59 2011/04/04 17:44:43 henning Exp $ */ /* $NetBSD: ip_mroute.c,v 1.85 2004/04/26 01:31:57 matt Exp $ */ /* @@ -1809,12 +1809,7 @@ encap_send(struct ip *ip, struct vif *vifp, struct mbuf *m) struct ip *ip_copy; int i, len = ntohs(ip->ip_len) + sizeof(multicast_encap_iphdr); - /* Take care of delayed checksums */ - if (m->m_pkthdr.csum_flags & (M_TCPV4_CSUM_OUT | M_UDPV4_CSUM_OUT)) { - in_delayed_cksum(m); - m->m_pkthdr.csum_flags &= - ~(M_UDPV4_CSUM_OUT | M_TCPV4_CSUM_OUT); - } + in_proto_cksum_out(m, NULL); /* * copy the old packet & pullup its IP header into the @@ -2743,12 +2738,7 @@ pim_register_prepare(struct ip *ip, struct mbuf *m) struct mbuf *mb_copy = NULL; int mtu; - /* Take care of delayed checksums */ - if (m->m_pkthdr.csum_flags & (M_TCPV4_CSUM_OUT | M_UDPV4_CSUM_OUT)) { - in_delayed_cksum(m); - m->m_pkthdr.csum_flags &= - ~(M_UDPV4_CSUM_OUT | M_TCPV4_CSUM_OUT); - } + in_proto_cksum_out(m, NULL); /* * Copy the old packet & pullup its IP header into the diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index 0a8f4ee1be9..2e28b25c384 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_output.c,v 1.215 2011/04/04 13:57:29 henning Exp $ */ +/* $OpenBSD: ip_output.c,v 1.216 2011/04/04 17:44:43 henning Exp $ */ /* $NetBSD: ip_output.c,v 1.28 1996/02/13 23:43:07 christos Exp $ */ /* @@ -335,11 +335,7 @@ reroute: * If it needs TCP/UDP hardware-checksumming, do the * computation now. */ - if (m->m_pkthdr.csum_flags & (M_TCPV4_CSUM_OUT | M_UDPV4_CSUM_OUT)) { - in_delayed_cksum(m); - m->m_pkthdr.csum_flags &= - ~(M_UDPV4_CSUM_OUT | M_TCPV4_CSUM_OUT); - } + in_proto_cksum_out(m, NULL); /* If it's not a multicast packet, try to fast-path */ if (!IN_MULTICAST(ip->ip_dst.s_addr)) { @@ -499,12 +495,7 @@ reroute: * Can't defer TCP/UDP checksumming, do the * computation now. */ - if (m->m_pkthdr.csum_flags & - (M_TCPV4_CSUM_OUT | M_UDPV4_CSUM_OUT)) { - in_delayed_cksum(m); - m->m_pkthdr.csum_flags &= - ~(M_UDPV4_CSUM_OUT | M_TCPV4_CSUM_OUT); - } + in_proto_cksum_out(m, NULL); ip_mloopback(ifp, m, dst); } #ifdef MROUTING @@ -697,20 +688,7 @@ sendit: } #endif /* IPSEC */ - /* Catch routing changes wrt. hardware checksumming for TCP or UDP. */ - if (m->m_pkthdr.csum_flags & M_TCPV4_CSUM_OUT) { - if (!(ifp->if_capabilities & IFCAP_CSUM_TCPv4) || - ifp->if_bridge != NULL) { - in_delayed_cksum(m); - m->m_pkthdr.csum_flags &= ~M_TCPV4_CSUM_OUT; /* Clear */ - } - } else if (m->m_pkthdr.csum_flags & M_UDPV4_CSUM_OUT) { - if (!(ifp->if_capabilities & IFCAP_CSUM_UDPv4) || - ifp->if_bridge != NULL) { - in_delayed_cksum(m); - m->m_pkthdr.csum_flags &= ~M_UDPV4_CSUM_OUT; /* Clear */ - } - } + in_proto_cksum_out(m, ifp); /* * Packet filter @@ -856,11 +834,7 @@ ip_fragment(struct mbuf *m, struct ifnet *ifp, u_long mtu) * If we are doing fragmentation, we can't defer TCP/UDP * checksumming; compute the checksum and clear the flag. */ - if (m->m_pkthdr.csum_flags & (M_TCPV4_CSUM_OUT | M_UDPV4_CSUM_OUT)) { - in_delayed_cksum(m); - m->m_pkthdr.csum_flags &= ~(M_UDPV4_CSUM_OUT | M_TCPV4_CSUM_OUT); - } - + in_proto_cksum_out(m, NULL); firstlen = len; mnext = &m->m_nextpkt; @@ -2149,3 +2123,21 @@ in_delayed_cksum(struct mbuf *m) else *(u_int16_t *)(mtod(m, caddr_t) + offset) = csum; } + +void +in_proto_cksum_out(struct mbuf *m, struct ifnet *ifp) +{ + if (m->m_pkthdr.csum_flags & M_TCPV4_CSUM_OUT) { + if (!ifp || !(ifp->if_capabilities & IFCAP_CSUM_TCPv4) || + ifp->if_bridge != NULL) { + in_delayed_cksum(m); + m->m_pkthdr.csum_flags &= ~M_TCPV4_CSUM_OUT; /* Clear */ + } + } else if (m->m_pkthdr.csum_flags & M_UDPV4_CSUM_OUT) { + if (!ifp || !(ifp->if_capabilities & IFCAP_CSUM_UDPv4) || + ifp->if_bridge != NULL) { + in_delayed_cksum(m); + m->m_pkthdr.csum_flags &= ~M_UDPV4_CSUM_OUT; /* Clear */ + } + } +} diff --git a/sys/netmpls/mpls_output.c b/sys/netmpls/mpls_output.c index 8641d62f5a1..3a18614be7c 100644 --- a/sys/netmpls/mpls_output.c +++ b/sys/netmpls/mpls_output.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mpls_output.c,v 1.14 2011/04/04 16:20:02 henning Exp $ */ +/* $OpenBSD: mpls_output.c,v 1.15 2011/04/04 17:44:43 henning Exp $ */ /* * Copyright (c) 2008 Claudio Jeker <claudio@openbsd.org> @@ -175,10 +175,8 @@ mpls_do_cksum(struct mbuf *m) struct ip *ip; u_int16_t hlen; - if (m->m_pkthdr.csum_flags & (M_TCPV4_CSUM_OUT | M_UDPV4_CSUM_OUT)) { - in_delayed_cksum(m); - m->m_pkthdr.csum_flags &= ~(M_UDPV4_CSUM_OUT|M_TCPV4_CSUM_OUT); - } + in_proto_cksum_out(m, NULL); + if (m->m_pkthdr.csum_flags & M_IPV4_CSUM_OUT) { ip = mtod(m, struct ip *); hlen = ip->ip_hl << 2; |