linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / net / dccp / dccp.h
index a5c5475..93f26dd 100644 (file)
@@ -5,13 +5,14 @@
  *
  *  An implementation of the DCCP protocol
  *  Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
- *  Copyright (c) 2005-6 Ian McDonald <ian.mcdonald@jandi.co.nz>
+ *  Copyright (c) 2005 Ian McDonald <iam4@cs.waikato.ac.nz>
  *
  *     This program is free software; you can redistribute it and/or modify it
  *     under the terms of the GNU General Public License version 2 as
  *     published by the Free Software Foundation.
  */
 
+#include <linux/config.h>
 #include <linux/dccp.h>
 #include <net/snmp.h>
 #include <net/sock.h>
@@ -58,6 +59,8 @@ extern void dccp_time_wait(struct sock *sk, int state, int timeo);
 
 #define DCCP_RTO_MAX ((unsigned)(120 * HZ)) /* FIXME: using TCP value */
 
+extern struct proto dccp_prot;
+
 /* is seq1 < seq2 ? */
 static inline int before48(const u64 seq1, const u64 seq2)
 {
@@ -81,14 +84,6 @@ static inline u64 max48(const u64 seq1, const u64 seq2)
        return after48(seq1, seq2) ? seq1 : seq2;
 }
 
-/* is seq1 next seqno after seq2 */
-static inline int follows48(const u64 seq1, const u64 seq2)
-{
-       int diff = (seq1 & 0xFFFF) - (seq2 & 0xFFFF);
-
-       return diff==1;
-}
-
 enum {
        DCCP_MIB_NUM = 0,
        DCCP_MIB_ACTIVEOPENS,                   /* ActiveOpens */
@@ -125,6 +120,7 @@ DECLARE_SNMP_STAT(struct dccp_mib, dccp_statistics);
 
 extern int  dccp_retransmit_skb(struct sock *sk, struct sk_buff *skb);
 
+extern int dccp_send_response(struct sock *sk);
 extern void dccp_send_ack(struct sock *sk);
 extern void dccp_send_delayed_ack(struct sock *sk);
 extern void dccp_send_sync(struct sock *sk, const u64 seq,
@@ -144,8 +140,53 @@ extern unsigned int dccp_sync_mss(struct sock *sk, u32 pmtu);
 extern const char *dccp_packet_name(const int type);
 extern const char *dccp_state_name(const int state);
 
-extern void dccp_set_state(struct sock *sk, const int state);
-extern void dccp_done(struct sock *sk);
+static inline void dccp_set_state(struct sock *sk, const int state)
+{
+       const int oldstate = sk->sk_state;
+
+       dccp_pr_debug("%s(%p) %-10.10s -> %s\n",
+                     dccp_role(sk), sk,
+                     dccp_state_name(oldstate), dccp_state_name(state));
+       WARN_ON(state == oldstate);
+
+       switch (state) {
+       case DCCP_OPEN:
+               if (oldstate != DCCP_OPEN)
+                       DCCP_INC_STATS(DCCP_MIB_CURRESTAB);
+               break;
+
+       case DCCP_CLOSED:
+               if (oldstate == DCCP_CLOSING || oldstate == DCCP_OPEN)
+                       DCCP_INC_STATS(DCCP_MIB_ESTABRESETS);
+
+               sk->sk_prot->unhash(sk);
+               if (inet_csk(sk)->icsk_bind_hash != NULL &&
+                   !(sk->sk_userlocks & SOCK_BINDPORT_LOCK))
+                       inet_put_port(&dccp_hashinfo, sk);
+               /* fall through */
+       default:
+               if (oldstate == DCCP_OPEN)
+                       DCCP_DEC_STATS(DCCP_MIB_CURRESTAB);
+       }
+
+       /* Change state AFTER socket is unhashed to avoid closed
+        * socket sitting in hash tables.
+        */
+       sk->sk_state = state;
+}
+
+static inline void dccp_done(struct sock *sk)
+{
+       dccp_set_state(sk, DCCP_CLOSED);
+       dccp_clear_xmit_timers(sk);
+
+       sk->sk_shutdown = SHUTDOWN_MASK;
+
+       if (!sock_flag(sk, SOCK_DEAD))
+               sk->sk_state_change(sk);
+       else
+               inet_csk_destroy_sock(sk);
+}
 
 static inline void dccp_openreq_init(struct request_sock *req,
                                     struct dccp_sock *dp,
@@ -168,6 +209,10 @@ extern struct sock *dccp_create_openreq_child(struct sock *sk,
 
 extern int dccp_v4_do_rcv(struct sock *sk, struct sk_buff *skb);
 
+extern void dccp_v4_err(struct sk_buff *skb, u32);
+
+extern int dccp_v4_rcv(struct sk_buff *skb);
+
 extern struct sock *dccp_v4_request_recv_sock(struct sock *sk,
                                              struct sk_buff *skb,
                                              struct request_sock *req,
@@ -183,30 +228,24 @@ extern int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
 extern int dccp_rcv_established(struct sock *sk, struct sk_buff *skb,
                                const struct dccp_hdr *dh, const unsigned len);
 
-extern int dccp_init_sock(struct sock *sk, const __u8 ctl_sock_initialized);
-extern int dccp_destroy_sock(struct sock *sk);
+extern int dccp_v4_init_sock(struct sock *sk);
+extern int dccp_v4_destroy_sock(struct sock *sk);
 
 extern void            dccp_close(struct sock *sk, long timeout);
 extern struct sk_buff  *dccp_make_response(struct sock *sk,
                                            struct dst_entry *dst,
                                            struct request_sock *req);
+extern struct sk_buff  *dccp_make_reset(struct sock *sk,
+                                        struct dst_entry *dst,
+                                        enum dccp_reset_codes code);
 
 extern int        dccp_connect(struct sock *sk);
 extern int        dccp_disconnect(struct sock *sk, int flags);
-extern void       dccp_hash(struct sock *sk);
 extern void       dccp_unhash(struct sock *sk);
 extern int        dccp_getsockopt(struct sock *sk, int level, int optname,
                                   char __user *optval, int __user *optlen);
 extern int        dccp_setsockopt(struct sock *sk, int level, int optname,
                                   char __user *optval, int optlen);
-#ifdef CONFIG_COMPAT
-extern int        compat_dccp_getsockopt(struct sock *sk,
-                               int level, int optname,
-                               char __user *optval, int __user *optlen);
-extern int        compat_dccp_setsockopt(struct sock *sk,
-                               int level, int optname,
-                               char __user *optval, int optlen);
-#endif
 extern int        dccp_ioctl(struct sock *sk, int cmd, unsigned long arg);
 extern int        dccp_sendmsg(struct kiocb *iocb, struct sock *sk,
                                struct msghdr *msg, size_t size);
@@ -223,14 +262,15 @@ extern int           dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr,
                                   int addr_len);
 
 extern int        dccp_v4_checksum(const struct sk_buff *skb,
-                                   const __be32 saddr, const __be32 daddr);
+                                   const u32 saddr, const u32 daddr);
 
-extern int        dccp_send_reset(struct sock *sk, enum dccp_reset_codes code);
+extern int        dccp_v4_send_reset(struct sock *sk,
+                                     enum dccp_reset_codes code);
 extern void       dccp_send_close(struct sock *sk, const int active);
 extern int        dccp_invalid_packet(struct sk_buff *skb);
 
 static inline int dccp_bad_service_code(const struct sock *sk,
-                                       const __be32 service)
+                                       const __u32 service)
 {
        const struct dccp_sock *dp = dccp_sk(sk);
 
@@ -294,29 +334,41 @@ static inline void dccp_hdr_set_seq(struct dccp_hdr *dh, const u64 gss)
 {
        struct dccp_hdr_ext *dhx = (struct dccp_hdr_ext *)((void *)dh +
                                                           sizeof(*dh));
-       dh->dccph_seq2 = 0;
-       dh->dccph_seq = htons((gss >> 32) & 0xfffff);
+
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+       dh->dccph_seq      = htonl((gss >> 32)) >> 8;
+#elif defined(__BIG_ENDIAN_BITFIELD)
+       dh->dccph_seq      = htonl((gss >> 32));
+#else
+#error  "Adjust your <asm/byteorder.h> defines"
+#endif
        dhx->dccph_seq_low = htonl(gss & 0xffffffff);
 }
 
 static inline void dccp_hdr_set_ack(struct dccp_hdr_ack_bits *dhack,
                                    const u64 gsr)
 {
-       dhack->dccph_reserved1 = 0;
-       dhack->dccph_ack_nr_high = htons(gsr >> 32);
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+       dhack->dccph_ack_nr_high = htonl((gsr >> 32)) >> 8;
+#elif defined(__BIG_ENDIAN_BITFIELD)
+       dhack->dccph_ack_nr_high = htonl((gsr >> 32));
+#else
+#error  "Adjust your <asm/byteorder.h> defines"
+#endif
        dhack->dccph_ack_nr_low  = htonl(gsr & 0xffffffff);
 }
 
 static inline void dccp_update_gsr(struct sock *sk, u64 seq)
 {
        struct dccp_sock *dp = dccp_sk(sk);
-       const struct dccp_minisock *dmsk = dccp_msk(sk);
 
        dp->dccps_gsr = seq;
        dccp_set_seqno(&dp->dccps_swl,
-                      dp->dccps_gsr + 1 - (dmsk->dccpms_sequence_window / 4));
+                      (dp->dccps_gsr + 1 -
+                       (dp->dccps_options.dccpo_sequence_window / 4)));
        dccp_set_seqno(&dp->dccps_swh,
-                      dp->dccps_gsr + (3 * dmsk->dccpms_sequence_window) / 4);
+                      (dp->dccps_gsr +
+                       (3 * dp->dccps_options.dccpo_sequence_window) / 4));
 }
 
 static inline void dccp_update_gss(struct sock *sk, u64 seq)
@@ -326,7 +378,7 @@ static inline void dccp_update_gss(struct sock *sk, u64 seq)
        dp->dccps_awh = dp->dccps_gss = seq;
        dccp_set_seqno(&dp->dccps_awl,
                       (dp->dccps_gss -
-                       dccp_msk(sk)->dccpms_sequence_window + 1));
+                       dp->dccps_options.dccpo_sequence_window + 1));
 }
                                
 static inline int dccp_ack_pending(const struct sock *sk)
@@ -334,22 +386,24 @@ static inline int dccp_ack_pending(const struct sock *sk)
        const struct dccp_sock *dp = dccp_sk(sk);
        return dp->dccps_timestamp_echo != 0 ||
 #ifdef CONFIG_IP_DCCP_ACKVEC
-              (dccp_msk(sk)->dccpms_send_ack_vector &&
+              (dp->dccps_options.dccpo_send_ack_vector &&
                dccp_ackvec_pending(dp->dccps_hc_rx_ackvec)) ||
 #endif
               inet_csk_ack_scheduled(sk);
 }
 
-extern int dccp_insert_options(struct sock *sk, struct sk_buff *skb);
-extern int dccp_insert_option_elapsed_time(struct sock *sk,
+extern void dccp_insert_options(struct sock *sk, struct sk_buff *skb);
+extern void dccp_insert_option_elapsed_time(struct sock *sk,
                                            struct sk_buff *skb,
                                            u32 elapsed_time);
-extern int dccp_insert_option_timestamp(struct sock *sk,
+extern void dccp_insert_option_timestamp(struct sock *sk,
                                         struct sk_buff *skb);
-extern int dccp_insert_option(struct sock *sk, struct sk_buff *skb,
+extern void dccp_insert_option(struct sock *sk, struct sk_buff *skb,
                               unsigned char option,
                               const void *value, unsigned char len);
 
+extern struct socket *dccp_ctl_socket;
+
 extern void dccp_timestamp(const struct sock *sk, struct timeval *tv);
 
 static inline suseconds_t timeval_usecs(const struct timeval *tv)
@@ -390,18 +444,4 @@ static inline void timeval_sub_usecs(struct timeval *tv,
        }
 }
 
-#ifdef CONFIG_SYSCTL
-extern int dccp_sysctl_init(void);
-extern void dccp_sysctl_exit(void);
-#else
-static inline int dccp_sysctl_init(void)
-{
-       return 0;
-}
-
-static inline void dccp_sysctl_exit(void)
-{
-}
-#endif
-
 #endif /* _DCCP_H */