aboutsummaryrefslogtreecommitdiffstats
path: root/net/dccp/ipv4.c
diff options
context:
space:
mode:
authorYoshifumi Nishida <nishida@csl.sony.co.jp>2005-08-09 23:15:35 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2005-08-29 18:49:55 -0400
commit95b81ef794278c835b321f6376b0522cd5df59b7 (patch)
treec2163130b2a2e1bc8ced9ee70b4c87fcbe7cdf8e /net/dccp/ipv4.c
parenta019d6fe2b9da68ea4ba6cf3c4e86fc1dbf554c3 (diff)
[DCCP]: Fix checksum routines
Signed-off-by: Yoshifumi Nishida <nishida@csl.sony.co.jp> Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dccp/ipv4.c')
-rw-r--r--net/dccp/ipv4.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/net/dccp/ipv4.c b/net/dccp/ipv4.c
index 083bacaecb3b..7b90606ec10e 100644
--- a/net/dccp/ipv4.c
+++ b/net/dccp/ipv4.c
@@ -802,9 +802,9 @@ static struct sock *dccp_v4_hnd_req(struct sock *sk, struct sk_buff *skb)
802 return sk; 802 return sk;
803} 803}
804 804
805int dccp_v4_checksum(struct sk_buff *skb) 805int dccp_v4_checksum(const struct sk_buff *skb, const u32 saddr, const u32 daddr)
806{ 806{
807 struct dccp_hdr* dh = dccp_hdr(skb); 807 const struct dccp_hdr* dh = dccp_hdr(skb);
808 int checksum_len; 808 int checksum_len;
809 u32 tmp; 809 u32 tmp;
810 810
@@ -816,24 +816,24 @@ int dccp_v4_checksum(struct sk_buff *skb)
816 } 816 }
817 817
818 tmp = csum_partial((unsigned char *)dh, checksum_len, 0); 818 tmp = csum_partial((unsigned char *)dh, checksum_len, 0);
819 return csum_fold(tmp); 819 return csum_tcpudp_magic(saddr, daddr, checksum_len, IPPROTO_DCCP, tmp);
820} 820}
821 821
822static int dccp_v4_verify_checksum(struct sk_buff *skb) 822static int dccp_v4_verify_checksum(struct sk_buff *skb,
823 const u32 saddr, const u32 daddr)
823{ 824{
824 struct dccp_hdr *th = dccp_hdr(skb); 825 struct dccp_hdr *dh = dccp_hdr(skb);
825 const u16 remote_checksum = th->dccph_checksum; 826 int checksum_len;
826 u16 local_checksum; 827 u32 tmp;
827
828 /* FIXME: don't mess with skb payload */
829 th->dccph_checksum = 0; /* zero it for computation */
830
831 local_checksum = dccp_v4_checksum(skb);
832
833 /* FIXME: don't mess with skb payload */
834 th->dccph_checksum = remote_checksum; /* put it back */
835 828
836 return remote_checksum == local_checksum ? 0 : -1; 829 if (dh->dccph_cscov == 0)
830 checksum_len = skb->len;
831 else {
832 checksum_len = (dh->dccph_cscov + dh->dccph_x) * sizeof(u32);
833 checksum_len = checksum_len < skb->len ? checksum_len : skb->len;
834 }
835 tmp = csum_partial((unsigned char *)dh, checksum_len, 0);
836 return csum_tcpudp_magic(saddr, daddr, checksum_len, IPPROTO_DCCP, tmp) == 0 ? 0 : -1;
837} 837}
838 838
839static struct dst_entry* dccp_v4_route_skb(struct sock *sk, 839static struct dst_entry* dccp_v4_route_skb(struct sock *sk,
@@ -902,7 +902,8 @@ void dccp_v4_ctl_send_reset(struct sk_buff *rxskb)
902 dccp_hdr_set_seq(dh, DCCP_SKB_CB(rxskb)->dccpd_ack_seq); 902 dccp_hdr_set_seq(dh, DCCP_SKB_CB(rxskb)->dccpd_ack_seq);
903 dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), DCCP_SKB_CB(rxskb)->dccpd_seq); 903 dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), DCCP_SKB_CB(rxskb)->dccpd_seq);
904 904
905 dh->dccph_checksum = dccp_v4_checksum(skb); 905 dh->dccph_checksum = dccp_v4_checksum(skb, rxskb->nh.iph->saddr,
906 rxskb->nh.iph->daddr);
906 907
907 bh_lock_sock(dccp_ctl_socket->sk); 908 bh_lock_sock(dccp_ctl_socket->sk);
908 err = ip_build_and_send_pkt(skb, dccp_ctl_socket->sk, 909 err = ip_build_and_send_pkt(skb, dccp_ctl_socket->sk,
@@ -1024,7 +1025,8 @@ static inline int dccp_invalid_packet(struct sk_buff *skb)
1024 } 1025 }
1025 1026
1026 /* If the header checksum is incorrect, drop packet and return */ 1027 /* If the header checksum is incorrect, drop packet and return */
1027 if (dccp_v4_verify_checksum(skb) < 0) { 1028 if (dccp_v4_verify_checksum(skb, skb->nh.iph->saddr,
1029 skb->nh.iph->daddr) < 0) {
1028 dccp_pr_debug("header checksum is incorrect\n"); 1030 dccp_pr_debug("header checksum is incorrect\n");
1029 return 1; 1031 return 1;
1030 } 1032 }