All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH ipvs 2/2] net: ipvs: sctp: do not recalc sctp checksum when not needed
@ 2013-10-25  9:05 ` Daniel Borkmann
  0 siblings, 0 replies; 34+ messages in thread
From: Daniel Borkmann @ 2013-10-25  9:05 UTC (permalink / raw)
  To: linux-sctp

Unlike UDP or TCP, we do not take the pseudo-header into account
in SCTP checksums [1]. So in case port mapping is the very same, we
do not need to recalculate the whole SCTP checksum in software, which
is expensive.

Also, similarly as in IPVS/TCP, take into account when a private
helper mangled the packet. In that case, we also need to recalculate
the checksum even if ports might be same.

 [1] http://tools.ietf.org/html/rfc4960#section-6.8

Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
---
 net/netfilter/ipvs/ip_vs_proto_sctp.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/net/netfilter/ipvs/ip_vs_proto_sctp.c b/net/netfilter/ipvs/ip_vs_proto_sctp.c
index 9ca7aa0..e56661e 100644
--- a/net/netfilter/ipvs/ip_vs_proto_sctp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_sctp.c
@@ -81,6 +81,7 @@ sctp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,
 {
 	sctp_sctphdr_t *sctph;
 	unsigned int sctphoff = iph->len;
+	bool payload_csum = false;
 
 #ifdef CONFIG_IP_VS_IPV6
 	if (cp->af = AF_INET6 && iph->fragoffs)
@@ -92,19 +93,27 @@ sctp_snat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,
 		return 0;
 
 	if (unlikely(cp->app != NULL)) {
+		int ret;
+
 		/* Some checks before mangling */
 		if (pp->csum_check && !pp->csum_check(cp->af, skb, pp))
 			return 0;
 
 		/* Call application helper if needed */
-		if (!ip_vs_app_pkt_out(cp, skb))
+		if (!(ret = ip_vs_app_pkt_out(cp, skb)))
 			return 0;
+		/* ret=2: csum update is needed after payload mangling */
+		if (ret = 2)
+			payload_csum = true;
 	}
 
 	sctph = (void *) skb_network_header(skb) + sctphoff;
-	sctph->source = cp->vport;
 
-	sctp_nat_csum(skb, sctph, sctphoff);
+	/* Only update csum if we really have to */
+	if (sctph->source != cp->vport || payload_csum) {
+		sctph->source = cp->vport;
+		sctp_nat_csum(skb, sctph, sctphoff);
+	}
 
 	return 1;
 }
@@ -115,6 +124,7 @@ sctp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,
 {
 	sctp_sctphdr_t *sctph;
 	unsigned int sctphoff = iph->len;
+	bool payload_csum = false;
 
 #ifdef CONFIG_IP_VS_IPV6
 	if (cp->af = AF_INET6 && iph->fragoffs)
@@ -126,19 +136,27 @@ sctp_dnat_handler(struct sk_buff *skb, struct ip_vs_protocol *pp,
 		return 0;
 
 	if (unlikely(cp->app != NULL)) {
+		int ret;
+
 		/* Some checks before mangling */
 		if (pp->csum_check && !pp->csum_check(cp->af, skb, pp))
 			return 0;
 
 		/* Call application helper if needed */
-		if (!ip_vs_app_pkt_in(cp, skb))
+		if (!(ret = ip_vs_app_pkt_in(cp, skb)))
 			return 0;
+		/* ret=2: csum update is needed after payload mangling */
+		if (ret = 2)
+			payload_csum = true;
 	}
 
 	sctph = (void *) skb_network_header(skb) + sctphoff;
-	sctph->dest = cp->dport;
 
-	sctp_nat_csum(skb, sctph, sctphoff);
+	/* Only update csum if we really have to */
+	if (sctph->dest != cp->dport || payload_csum) {
+		sctph->dest = cp->dport;
+		sctp_nat_csum(skb, sctph, sctphoff);
+	}
 
 	return 1;
 }
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread
* [PATCH ipvs 1/2] net: ipvs: sctp: add missing verdict assignments in sctp_conn_schedule
@ 2013-10-25  9:05 ` Daniel Borkmann
  0 siblings, 0 replies; 34+ messages in thread
From: Daniel Borkmann @ 2013-10-25  9:05 UTC (permalink / raw)
  To: linux-sctp

If skb_header_pointer() fails, we need to assign a verdict, that is
NF_DROP in this case, otherwise, we would leave the verdict from
conn_schedule() uninitialized when returning.

Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
---
 net/netfilter/ipvs/ip_vs_proto_sctp.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/net/netfilter/ipvs/ip_vs_proto_sctp.c b/net/netfilter/ipvs/ip_vs_proto_sctp.c
index 23e596e..9ca7aa0 100644
--- a/net/netfilter/ipvs/ip_vs_proto_sctp.c
+++ b/net/netfilter/ipvs/ip_vs_proto_sctp.c
@@ -20,13 +20,18 @@ sctp_conn_schedule(int af, struct sk_buff *skb, struct ip_vs_proto_data *pd,
 	sctp_sctphdr_t *sh, _sctph;
 
 	sh = skb_header_pointer(skb, iph->len, sizeof(_sctph), &_sctph);
-	if (sh = NULL)
+	if (sh = NULL) {
+		*verdict = NF_DROP;
 		return 0;
+	}
 
 	sch = skb_header_pointer(skb, iph->len + sizeof(sctp_sctphdr_t),
 				 sizeof(_schunkh), &_schunkh);
-	if (sch = NULL)
+	if (sch = NULL) {
+		*verdict = NF_DROP;
 		return 0;
+	}
+
 	net = skb_net(skb);
 	ipvs = net_ipvs(net);
 	rcu_read_lock();
-- 
1.7.11.7


^ permalink raw reply related	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2013-10-28  9:38 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-25  9:05 [PATCH ipvs 2/2] net: ipvs: sctp: do not recalc sctp checksum when not needed Daniel Borkmann
2013-10-25  9:05 ` Daniel Borkmann
2013-10-25  9:48 ` Jesper Dangaard Brouer
2013-10-25  9:48   ` Jesper Dangaard Brouer
2013-10-25 13:01 ` Neil Horman
2013-10-25 13:01   ` Neil Horman
2013-10-25 21:00 ` Julian Anastasov
2013-10-25 21:00   ` Julian Anastasov
2013-10-26 18:55 ` Daniel Borkmann
2013-10-26 18:55   ` Daniel Borkmann
2013-10-28  1:39 ` Simon Horman
2013-10-28  1:39   ` Simon Horman
2013-10-28  8:11 ` Daniel Borkmann
2013-10-28  8:11   ` Daniel Borkmann
2013-10-28  8:11 ` Julian Anastasov
2013-10-28  8:11   ` Julian Anastasov
2013-10-28  8:50 ` Simon Horman
2013-10-28  8:50   ` Simon Horman
2013-10-28  9:00 ` Julian Anastasov
2013-10-28  9:00   ` Julian Anastasov
2013-10-28  9:38 ` Simon Horman
2013-10-28  9:38   ` Simon Horman
  -- strict thread matches above, loose matches on Subject: below --
2013-10-25  9:05 [PATCH ipvs 1/2] net: ipvs: sctp: add missing verdict assignments in sctp_conn_schedule Daniel Borkmann
2013-10-25  9:05 ` Daniel Borkmann
2013-10-25  9:39 ` Jesper Dangaard Brouer
2013-10-25  9:39   ` Jesper Dangaard Brouer
2013-10-25  9:55 ` Simon Horman
2013-10-25  9:55   ` Simon Horman
2013-10-25 10:03 ` Daniel Borkmann
2013-10-25 10:03   ` Daniel Borkmann
2013-10-25 12:59 ` Neil Horman
2013-10-25 12:59   ` Neil Horman
2013-10-25 21:05 ` Julian Anastasov
2013-10-25 21:05   ` Julian Anastasov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.