Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cbb042f9 authored by Herbert Xu's avatar Herbert Xu Committed by David S. Miller
Browse files

[NET]: Replace skb_pull/skb_postpull_rcsum with skb_pull_rcsum



We're now starting to have quite a number of places that do skb_pull
followed immediately by an skb_postpull_rcsum.  We can merge these two
operations into one function with skb_pull_rcsum.  This makes sense
since most pull operations on receive skb's need to update the
checksum.

I've decided to make this out-of-line since it is fairly big and the
fast path where hardware checksums are enabled need to call
csum_partial anyway.

Since this is a brand new function we get to add an extra check on the
len argument.  As it is most callers of skb_pull ignore its return
value which essentially means that there is no check on the len
argument.

Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ecba320f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1691,8 +1691,8 @@ ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
		    || ppp->npmode[npi] != NPMODE_PASS) {
			kfree_skb(skb);
		} else {
			skb_pull(skb, 2);	/* chop off protocol */
			skb_postpull_rcsum(skb, skb->data - 2, 2);
			/* chop off protocol */
			skb_pull_rcsum(skb, 2);
			skb->dev = ppp->dev;
			skb->protocol = htons(npindex_to_ethertype[npi]);
			skb->mac.raw = skb->data;
+1 −2
Original line number Diff line number Diff line
@@ -337,8 +337,7 @@ static int pppoe_rcv_core(struct sock *sk, struct sk_buff *skb)
	if (sk->sk_state & PPPOX_BOUND) {
		struct pppoe_hdr *ph = (struct pppoe_hdr *) skb->nh.raw;
		int len = ntohs(ph->length);
		skb_pull(skb, sizeof(struct pppoe_hdr));
		skb_postpull_rcsum(skb, ph, sizeof(*ph));
		skb_pull_rcsum(skb, sizeof(struct pppoe_hdr));
		if (pskb_trim_rcsum(skb, len))
			goto abort_kfree;

+3 −1
Original line number Diff line number Diff line
@@ -1159,12 +1159,14 @@ static inline int skb_linearize(struct sk_buff *skb, gfp_t gfp)
 */

static inline void skb_postpull_rcsum(struct sk_buff *skb,
					 const void *start, int len)
				      const void *start, unsigned int len)
{
	if (skb->ip_summed == CHECKSUM_HW)
		skb->csum = csum_sub(skb->csum, csum_partial(start, len, 0));
}

unsigned char *skb_pull_rcsum(struct sk_buff *skb, unsigned int len);

/**
 *	pskb_trim_rcsum - trim received skb and update checksum
 *	@skb: buffer to trim
+1 −2
Original line number Diff line number Diff line
@@ -61,8 +61,7 @@ static int snap_rcv(struct sk_buff *skb, struct net_device *dev,
		/* Pass the frame on. */
		u8 *hdr = skb->data;
		skb->h.raw  += 5;
		skb_pull(skb, 5);
		skb_postpull_rcsum(skb, hdr, 5);
		skb_pull_rcsum(skb, 5);
		rc = proto->rcvfunc(skb, dev, &snap_packet_type, orig_dev);
	} else {
		skb->sk = NULL;
+2 −4
Original line number Diff line number Diff line
@@ -163,10 +163,8 @@ int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev,
	stats->rx_packets++;
	stats->rx_bytes += skb->len;

	skb_pull(skb, VLAN_HLEN); /* take off the VLAN header (4 bytes currently) */

	/* Need to correct hardware checksum */
	skb_postpull_rcsum(skb, vhdr, VLAN_HLEN);
	/* Take off the VLAN header (4 bytes currently) */
	skb_pull_rcsum(skb, VLAN_HLEN);

	/* Ok, lets check to make sure the device (dev) we
	 * came in on is what this VLAN is attached to.
Loading