Skip to content

Commit

Permalink
[DCCP]: Combine allocating & zeroing header space on skb
Browse files Browse the repository at this point in the history
This is a code simplification:
it combines three often recurring operations into one inline function,

        * allocate `len' bytes header space in skb
        * fill these `len' bytes with zeroes
        * cast the start of this header space as dccp_hdr

Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
  • Loading branch information
Gerrit Renker authored and David S. Miller committed Dec 3, 2006
1 parent 89e7e57 commit 9b42078
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 24 deletions.
7 changes: 7 additions & 0 deletions include/linux/dccp.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ static inline struct dccp_hdr *dccp_hdr(const struct sk_buff *skb)
return (struct dccp_hdr *)skb->h.raw;
}

static inline struct dccp_hdr *dccp_zeroed_hdr(struct sk_buff *skb, int headlen)
{
skb->h.raw = skb_push(skb, headlen);
memset(skb->h.raw, 0, headlen);
return dccp_hdr(skb);
}

static inline struct dccp_hdr_ext *dccp_hdrx(const struct sk_buff *skb)
{
return (struct dccp_hdr_ext *)(skb->h.raw + sizeof(struct dccp_hdr));
Expand Down
9 changes: 2 additions & 7 deletions net/dccp/ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,9 @@ static void dccp_v4_reqsk_send_ack(struct sk_buff *rxskb,

/* Reserve space for headers. */
skb_reserve(skb, dccp_v4_ctl_socket->sk->sk_prot->max_header);

skb->dst = dst_clone(rxskb->dst);

skb->h.raw = skb_push(skb, dccp_hdr_ack_len);
dh = dccp_hdr(skb);
memset(dh, 0, dccp_hdr_ack_len);
dh = dccp_zeroed_hdr(skb, dccp_hdr_ack_len);

/* Build DCCP header and checksum it. */
dh->dccph_type = DCCP_PKT_ACK;
Expand Down Expand Up @@ -720,9 +717,7 @@ static void dccp_v4_ctl_send_reset(struct sk_buff *rxskb)
skb_reserve(skb, dccp_v4_ctl_socket->sk->sk_prot->max_header);
skb->dst = dst_clone(dst);

skb->h.raw = skb_push(skb, dccp_hdr_reset_len);
dh = dccp_hdr(skb);
memset(dh, 0, dccp_hdr_reset_len);
dh = dccp_zeroed_hdr(skb, dccp_hdr_reset_len);

/* Build DCCP header and checksum it. */
dh->dccph_type = DCCP_PKT_RESET;
Expand Down
8 changes: 2 additions & 6 deletions net/dccp/ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,7 @@ static void dccp_v6_ctl_send_reset(struct sk_buff *rxskb)

skb_reserve(skb, dccp_v6_ctl_socket->sk->sk_prot->max_header);

skb->h.raw = skb_push(skb, dccp_hdr_reset_len);
dh = dccp_hdr(skb);
memset(dh, 0, dccp_hdr_reset_len);
dh = dccp_zeroed_hdr(skb, dccp_hdr_reset_len);

/* Swap the send and the receive. */
dh->dccph_type = DCCP_PKT_RESET;
Expand Down Expand Up @@ -601,9 +599,7 @@ static void dccp_v6_reqsk_send_ack(struct sk_buff *rxskb,

skb_reserve(skb, dccp_v6_ctl_socket->sk->sk_prot->max_header);

skb->h.raw = skb_push(skb, dccp_hdr_ack_len);
dh = dccp_hdr(skb);
memset(dh, 0, dccp_hdr_ack_len);
dh = dccp_zeroed_hdr(skb, dccp_hdr_ack_len);

/* Build DCCP header and checksum it. */
dh->dccph_type = DCCP_PKT_ACK;
Expand Down
14 changes: 3 additions & 11 deletions net/dccp/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ static int dccp_transmit_skb(struct sock *sk, struct sk_buff *skb)
return -EPROTO;
}

skb->h.raw = skb_push(skb, dccp_header_size);
dh = dccp_hdr(skb);

/* Build DCCP header and checksum it. */
memset(dh, 0, dccp_header_size);
dh = dccp_zeroed_hdr(skb, dccp_header_size);
dh->dccph_type = dcb->dccpd_type;
dh->dccph_sport = inet->sport;
dh->dccph_dport = inet->dport;
Expand Down Expand Up @@ -340,10 +338,7 @@ struct sk_buff *dccp_make_response(struct sock *sk, struct dst_entry *dst,
return NULL;
}

skb->h.raw = skb_push(skb, dccp_header_size);

dh = dccp_hdr(skb);
memset(dh, 0, dccp_header_size);
dh = dccp_zeroed_hdr(skb, dccp_header_size);

dh->dccph_sport = inet_sk(sk)->sport;
dh->dccph_dport = inet_rsk(req)->rmt_port;
Expand Down Expand Up @@ -392,10 +387,7 @@ static struct sk_buff *dccp_make_reset(struct sock *sk, struct dst_entry *dst,
return NULL;
}

skb->h.raw = skb_push(skb, dccp_header_size);

dh = dccp_hdr(skb);
memset(dh, 0, dccp_header_size);
dh = dccp_zeroed_hdr(skb, dccp_header_size);

dh->dccph_sport = inet_sk(sk)->sport;
dh->dccph_dport = inet_sk(sk)->dport;
Expand Down

0 comments on commit 9b42078

Please sign in to comment.