aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerrit Renker <gerrit@erg.abdn.ac.uk>2006-11-10 08:22:32 -0500
committerDavid S. Miller <davem@sunset.davemloft.net>2006-12-03 00:21:55 -0500
commit9b42078ed6edfe04e9dc9a59b946ad912aeef717 (patch)
treed3d20e17aa85e1bb16b99397f98f151d197b3177
parent89e7e57778ecd8744fee97491300f05a9fb1388a (diff)
[DCCP]: Combine allocating & zeroing header space on skb
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>
-rw-r--r--include/linux/dccp.h7
-rw-r--r--net/dccp/ipv4.c9
-rw-r--r--net/dccp/ipv6.c8
-rw-r--r--net/dccp/output.c14
4 files changed, 14 insertions, 24 deletions
diff --git a/include/linux/dccp.h b/include/linux/dccp.h
index 53553c99cad6..90d04ffddae8 100644
--- a/include/linux/dccp.h
+++ b/include/linux/dccp.h
@@ -256,6 +256,13 @@ static inline struct dccp_hdr *dccp_hdr(const struct sk_buff *skb)
256 return (struct dccp_hdr *)skb->h.raw; 256 return (struct dccp_hdr *)skb->h.raw;
257} 257}
258 258
259static inline struct dccp_hdr *dccp_zeroed_hdr(struct sk_buff *skb, int headlen)
260{
261 skb->h.raw = skb_push(skb, headlen);
262 memset(skb->h.raw, 0, headlen);
263 return dccp_hdr(skb);
264}
265
259static inline struct dccp_hdr_ext *dccp_hdrx(const struct sk_buff *skb) 266static inline struct dccp_hdr_ext *dccp_hdrx(const struct sk_buff *skb)
260{ 267{
261 return (struct dccp_hdr_ext *)(skb->h.raw + sizeof(struct dccp_hdr)); 268 return (struct dccp_hdr_ext *)(skb->h.raw + sizeof(struct dccp_hdr));
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index de64e6c7f93d..ce8eed32dbeb 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -212,12 +212,9 @@ static void dccp_v4_reqsk_send_ack(struct sk_buff *rxskb,
212 212
213 /* Reserve space for headers. */ 213 /* Reserve space for headers. */
214 skb_reserve(skb, dccp_v4_ctl_socket->sk->sk_prot->max_header); 214 skb_reserve(skb, dccp_v4_ctl_socket->sk->sk_prot->max_header);
215
216 skb->dst = dst_clone(rxskb->dst); 215 skb->dst = dst_clone(rxskb->dst);
217 216
218 skb->h.raw = skb_push(skb, dccp_hdr_ack_len); 217 dh = dccp_zeroed_hdr(skb, dccp_hdr_ack_len);
219 dh = dccp_hdr(skb);
220 memset(dh, 0, dccp_hdr_ack_len);
221 218
222 /* Build DCCP header and checksum it. */ 219 /* Build DCCP header and checksum it. */
223 dh->dccph_type = DCCP_PKT_ACK; 220 dh->dccph_type = DCCP_PKT_ACK;
@@ -720,9 +717,7 @@ static void dccp_v4_ctl_send_reset(struct sk_buff *rxskb)
720 skb_reserve(skb, dccp_v4_ctl_socket->sk->sk_prot->max_header); 717 skb_reserve(skb, dccp_v4_ctl_socket->sk->sk_prot->max_header);
721 skb->dst = dst_clone(dst); 718 skb->dst = dst_clone(dst);
722 719
723 skb->h.raw = skb_push(skb, dccp_hdr_reset_len); 720 dh = dccp_zeroed_hdr(skb, dccp_hdr_reset_len);
724 dh = dccp_hdr(skb);
725 memset(dh, 0, dccp_hdr_reset_len);
726 721
727 /* Build DCCP header and checksum it. */ 722 /* Build DCCP header and checksum it. */
728 dh->dccph_type = DCCP_PKT_RESET; 723 dh->dccph_type = DCCP_PKT_RESET;
diff --git a/net/dccp/ipv6.c b/net/dccp/ipv6.c
index 6f1c2ad88608..116bddb64b80 100644
--- a/net/dccp/ipv6.c
+++ b/net/dccp/ipv6.c
@@ -537,9 +537,7 @@ static void dccp_v6_ctl_send_reset(struct sk_buff *rxskb)
537 537
538 skb_reserve(skb, dccp_v6_ctl_socket->sk->sk_prot->max_header); 538 skb_reserve(skb, dccp_v6_ctl_socket->sk->sk_prot->max_header);
539 539
540 skb->h.raw = skb_push(skb, dccp_hdr_reset_len); 540 dh = dccp_zeroed_hdr(skb, dccp_hdr_reset_len);
541 dh = dccp_hdr(skb);
542 memset(dh, 0, dccp_hdr_reset_len);
543 541
544 /* Swap the send and the receive. */ 542 /* Swap the send and the receive. */
545 dh->dccph_type = DCCP_PKT_RESET; 543 dh->dccph_type = DCCP_PKT_RESET;
@@ -601,9 +599,7 @@ static void dccp_v6_reqsk_send_ack(struct sk_buff *rxskb,
601 599
602 skb_reserve(skb, dccp_v6_ctl_socket->sk->sk_prot->max_header); 600 skb_reserve(skb, dccp_v6_ctl_socket->sk->sk_prot->max_header);
603 601
604 skb->h.raw = skb_push(skb, dccp_hdr_ack_len); 602 dh = dccp_zeroed_hdr(skb, dccp_hdr_ack_len);
605 dh = dccp_hdr(skb);
606 memset(dh, 0, dccp_hdr_ack_len);
607 603
608 /* Build DCCP header and checksum it. */ 604 /* Build DCCP header and checksum it. */
609 dh->dccph_type = DCCP_PKT_ACK; 605 dh->dccph_type = DCCP_PKT_ACK;
diff --git a/net/dccp/output.c b/net/dccp/output.c
index 2cc4f4b2a9dd..1ae2248557c6 100644
--- a/net/dccp/output.c
+++ b/net/dccp/output.c
@@ -88,11 +88,9 @@ static int dccp_transmit_skb(struct sock *sk, struct sk_buff *skb)
88 return -EPROTO; 88 return -EPROTO;
89 } 89 }
90 90
91 skb->h.raw = skb_push(skb, dccp_header_size);
92 dh = dccp_hdr(skb);
93 91
94 /* Build DCCP header and checksum it. */ 92 /* Build DCCP header and checksum it. */
95 memset(dh, 0, dccp_header_size); 93 dh = dccp_zeroed_hdr(skb, dccp_header_size);
96 dh->dccph_type = dcb->dccpd_type; 94 dh->dccph_type = dcb->dccpd_type;
97 dh->dccph_sport = inet->sport; 95 dh->dccph_sport = inet->sport;
98 dh->dccph_dport = inet->dport; 96 dh->dccph_dport = inet->dport;
@@ -340,10 +338,7 @@ struct sk_buff *dccp_make_response(struct sock *sk, struct dst_entry *dst,
340 return NULL; 338 return NULL;
341 } 339 }
342 340
343 skb->h.raw = skb_push(skb, dccp_header_size); 341 dh = dccp_zeroed_hdr(skb, dccp_header_size);
344
345 dh = dccp_hdr(skb);
346 memset(dh, 0, dccp_header_size);
347 342
348 dh->dccph_sport = inet_sk(sk)->sport; 343 dh->dccph_sport = inet_sk(sk)->sport;
349 dh->dccph_dport = inet_rsk(req)->rmt_port; 344 dh->dccph_dport = inet_rsk(req)->rmt_port;
@@ -392,10 +387,7 @@ static struct sk_buff *dccp_make_reset(struct sock *sk, struct dst_entry *dst,
392 return NULL; 387 return NULL;
393 } 388 }
394 389
395 skb->h.raw = skb_push(skb, dccp_header_size); 390 dh = dccp_zeroed_hdr(skb, dccp_header_size);
396
397 dh = dccp_hdr(skb);
398 memset(dh, 0, dccp_header_size);
399 391
400 dh->dccph_sport = inet_sk(sk)->sport; 392 dh->dccph_sport = inet_sk(sk)->sport;
401 dh->dccph_dport = inet_sk(sk)->dport; 393 dh->dccph_dport = inet_sk(sk)->dport;