rx-mutex-interlocked-macros-20080311
[openafs.git] / src / rx / rx.h
index f4dd0b2..ec4724d 100644 (file)
 #define _RX_
 
 #ifndef KDUMP_RX_LOCK
-/* Substitute VOID (char) for void, because some compilers are confused by void
- * in some situations */
-#ifndef AFS_NT40_ENV
-#define        VOID    char
-#endif
-
 #ifdef KERNEL
 #include "rx_kmutex.h"
 #include "rx_kernel.h"
@@ -46,6 +40,7 @@
 #else /* KERNEL */
 # include <sys/types.h>
 # include <stdio.h>
+# include <string.h>
 #ifdef AFS_PTHREAD_ENV
 # include "rx_pthread.h"
 #else
@@ -98,7 +93,7 @@
 #ifndef KERNEL
 typedef void (*rx_destructor_t) (void *);
 int rx_KeyCreate(rx_destructor_t);
-osi_socket rxi_GetHostUDPSocket(struct sockaddr_storage *saddr, int salen);
+osi_socket rxi_GetHostUDPSocket(u_int host, u_short port);
 osi_socket rxi_GetUDPSocket(u_short port);
 #endif /* KERNEL */
 
@@ -110,18 +105,8 @@ int ntoh_syserr_conv(int error);
 
 #define        rx_ConnectionOf(call)           ((call)->conn)
 #define        rx_PeerOf(conn)                 ((conn)->peer)
-#ifdef AF_INET6
-#define        rx_HostOf(peer)                 ((peer)->saddr.ss_family == AF_INET ? \
-               ((struct sockaddr_in *) &(peer)->saddr)->sin_addr.s_addr : \
-                                                               0xffffffff)
-#define        rx_PortOf(peer)                 ((peer)->saddr.ss_family == AF_INET ? \
-               ((struct sockaddr_in *) &(peer)->saddr)->sin_port : \
-               ((struct sockaddr_in6 *) &(peer)->saddr)->sin6_port)
-#else /* AF_INET6 */
-#define rx_HostOf(peer)                        (((struct sockaddr_in *) &(peer)->saddr)->sin_addr.saddr)
-#define rx_PortOf(peer)                        (((struct sockaddr_in *) &(peer)->saddr)->sin_port)
-#endif /* AF_INET6 */
-#define rx_AddrStringOf(peer)          ((peer)->addrstring)
+#define        rx_HostOf(peer)                 ((peer)->host)
+#define        rx_PortOf(peer)                 ((peer)->port)
 #define        rx_SetLocalStatus(call, status) ((call)->localStatus = (status))
 #define rx_GetLocalStatus(call, status) ((call)->localStatus)
 #define        rx_GetRemoteStatus(call)        ((call)->remoteStatus)
@@ -229,12 +214,10 @@ returned with an error code of RX_CALL_DEAD ( transient error ) */
    limited multiple asynchronous conversations. */
 #ifdef KDUMP_RX_LOCK
 struct rx_connection_rx_lock {
-    int magic;
     struct rx_connection_rx_lock *next;        /*  on hash chain _or_ free list */
     struct rx_peer_rx_lock *peer;
 #else
 struct rx_connection {
-    int magic;
     struct rx_connection *next;        /*  on hash chain _or_ free list */
     struct rx_peer *peer;
 #endif
@@ -271,7 +254,7 @@ struct rx_connection {
     u_char securityIndex;      /* corresponds to the security class of the */
     /* securityObject for this conn */
     struct rx_securityClass *securityObject;   /* Security object for this connection */
-    VOID *securityData;                /* Private data for this conn's security class */
+    void *securityData;                /* Private data for this conn's security class */
     u_short securityHeaderSize;        /* Length of security module's packet header data */
     u_short securityMaxTrailerSize;    /* Length of security module's packet trailer data */
 
@@ -308,8 +291,8 @@ struct rx_connection {
  * requests. */
 
 struct rx_service {
-    int magic;
     u_short serviceId;         /* Service number */
+    afs_uint32 serviceHost;    /* IP address for this service */
     u_short servicePort;       /* UDP port for this service */
     char *serviceName;         /* Name of the service */
     osi_socket socket;         /* socket structure or file descriptor */
@@ -360,28 +343,20 @@ struct rx_serverQueueEntry {
     osi_socket *socketp;
 };
 
-/* If we don't support IPv6, use this as a fallback */
-#ifndef INET6_ADDRSTRLEN
-#define INET6_ADDRSTRLEN 46
-#endif /* INET6_ADDRSTRLEN */
 
 /* A peer refers to a peer process, specified by a (host,port) pair.  There may be more than one peer on a given host. */
 #ifdef KDUMP_RX_LOCK
 struct rx_peer_rx_lock {
-    int magic;
     struct rx_peer_rx_lock *next;      /* Next in hash conflict or free list */
 #else
 struct rx_peer {
-    int magic;
     struct rx_peer *next;      /* Next in hash conflict or free list */
 #endif
 #ifdef RX_ENABLE_LOCKS
     afs_kmutex_t peer_lock;    /* Lock peer */
 #endif                         /* RX_ENABLE_LOCKS */
-    struct sockaddr_storage saddr;     /* Remote address structure */
-    int saddrlen;                      /* Length of saddr */
-    int socktype;                      /* Socket type (SOCK_DGRAM, etc) */
-    char addrstring[INET6_ADDRSTRLEN];  /* Printable address format */
+    afs_uint32 host;           /* Remote IP address, in net byte order */
+    u_short port;              /* Remote UDP port, in net byte order */
 
     /* interface mtu probably used for this host  -  includes RX Header */
     u_short ifMTU;             /* doesn't include IP header */
@@ -458,7 +433,6 @@ struct rx_call_rx_lock {
 #else
 struct rx_call {
 #endif
-    int magic;
     struct rx_queue queue_item_header; /* Call can be on various queues (one-at-a-time) */
     struct rx_queue tq;                /* Transmit packet queue */
     struct rx_queue rq;                /* Receive packet queue */
@@ -531,8 +505,8 @@ struct rx_call {
     int abortCount;            /* number of times last error was sent */
     u_int lastSendTime;                /* Last time a packet was sent on this call */
     u_int lastReceiveTime;     /* Last time a packet was received for this call */
-    void (*arrivalProc) (register struct rx_call * call, register VOID * mh, register int index);      /* Procedure to call when reply is received */
-    VOID *arrivalProcHandle;   /* Handle to pass to replyFunc */
+    void (*arrivalProc) (register struct rx_call * call, register void * mh, register int index);      /* Procedure to call when reply is received */
+    void *arrivalProcHandle;   /* Handle to pass to replyFunc */
     int arrivalProcArg;         /* Additional arg to pass to reply Proc */
     afs_uint32 lastAcked;      /* last packet "hard" acked by receiver */
     afs_uint32 startWait;      /* time server began waiting for input data/send quota */
@@ -658,7 +632,7 @@ struct rx_ackPacket {
 #define        RX_ACK_PING_RESPONSE    7       /* Ack'ing because we were pinged */
 #define        RX_ACK_DELAY            8       /* Ack generated since nothing has happened since receiving packet */
 #define RX_ACK_IDLE             9      /* Similar to RX_ACK_DELAY, but can 
-                                        * be */
+                                        * be used to compute RTT */
 
 /* Packet acknowledgement type */
 #define        RX_ACK_TYPE_NACK        0       /* I Don't have this packet */
@@ -716,6 +690,21 @@ struct rx_securityObjectStats {
     afs_int32 sparel[8];
 };
 
+/* Configuration settings */
+
+/* Enum for storing configuration variables which can be set via the 
+ * SetConfiguration method in the rx_securityClass, below
+ */
+
+typedef enum {
+     RXS_CONFIG_FLAGS /* afs_uint32 set of bitwise flags */
+} rx_securityConfigVariables;
+
+/* For the RXS_CONFIG_FLAGS, the following bit values are defined */
+
+/* Disable the principal name contains dot check in rxkad */
+#define RXS_CONFIG_FLAGS_DISABLE_DOTCHECK      0x01
+
 /* XXXX (rewrite this description) A security class object contains a set of
  * procedures and some private data to implement a security model for rx
  * connections.  These routines are called by rx as appropriate.  Rx knows
@@ -725,7 +714,6 @@ struct rx_securityObjectStats {
  * provide routines to create these objects.  Rx provides a basic routine to
  * allocate one of these objects; this routine must be called by the class. */
 struct rx_securityClass {
-    int magic;
     struct rx_securityOps {
        int (*op_Close) (struct rx_securityClass * aobj);
        int (*op_NewConnection) (struct rx_securityClass * aobj,
@@ -757,11 +745,15 @@ struct rx_securityClass {
        int (*op_GetStats) (struct rx_securityClass * aobj,
                            struct rx_connection * aconn,
                            struct rx_securityObjectStats * astats);
-       int (*op_Spare1) (void);
+       int (*op_SetConfiguration) (struct rx_securityClass * aobj,
+                                   struct rx_connection * aconn,
+                                   rx_securityConfigVariables atype,
+                                   void * avalue,
+                                   void ** acurrentValue);
        int (*op_Spare2) (void);
        int (*op_Spare3) (void);
     } *ops;
-    VOID *privateData;
+    void *privateData;
     int refCount;
 };
 
@@ -779,7 +771,7 @@ struct rx_securityClass {
 #define RXS_CheckPacket(obj,call,packet) RXS_OP(obj,CheckPacket,(obj,call,packet))
 #define RXS_DestroyConnection(obj,conn) RXS_OP(obj,DestroyConnection,(obj,conn))
 #define RXS_GetStats(obj,conn,stats) RXS_OP(obj,GetStats,(obj,conn,stats))
-
+#define RXS_SetConfiguration(obj, conn, type, value, currentValue) RXS_OP(obj, SetConfiguration,(obj,conn,type,value,currentValue))
 
 
 /* Structure for keeping rx statistics.  Note that this structure is returned
@@ -1057,27 +1049,54 @@ typedef struct rx_interface_stat {
 
 #define RX_STATS_SERVICE_ID 409
 
-/*
- * Definitions for handling struct sockaddr_storage casts, and IPv6
- */
-
-#ifdef AF_INET6
-#define rx_ss2pn(x) ((x)->ss_family == AF_INET6 ? \
-                       ((struct sockaddr_in6 *) (x))->sin6_port : \
-                       ((struct sockaddr_in *) (x))->sin_port)
-#define rx_ss2sin6(x) ((struct sockaddr_in6 *) (x))
-#define rx_ssfamily(x) ((x)->ss_family)
-#define rx_ss2addrp6(x) ((afs_uint16 *) &(((struct sockaddr_in6 *) (x))->sin6_addr.s6_addr))
-#define rx_ss2v4addr(x) ((x)->ss_family == AF_INET ? \
-                       ((struct sockaddr_in *) (x))->sin_addr.s_addr : \
-                       0xffffffff)
-#else /* AF_INET6 */
-#define rx_ss2pn(x) (((struct sockaddr_in *) (x))->sin_port)
-#define rx_ssfamily(x) (((struct sockaddr_in *) (x))->sin_family)
-#define rx_ss2v4addr(x) (((struct sockaddr_in *) (x))->sin_addr.s_addr)
-#endif /* AF_INET6 */
-#define rx_ss2sin(x) ((struct sockaddr_in *) (x))
-#define rx_ss2addrp(x) ((unsigned char *) &(((struct sockaddr_in *) (x))->sin_addr.s_addr))
+#ifdef AFS_NT40_ENV
+#define rx_MutexIncrement(object, mutex) InterlockedIncrement(&object)
+#define rx_MutexAdd(object, addend, mutex) InterlockedAdd(&object, addend)
+#define rx_MutexDecrement(object, mutex) InterlockedDecrement(&object)
+#define rx_MutexAdd1Increment2(object1, addend, object2, mutex) \
+    do { \
+        InterlockedAdd(&object1, addend); \
+        InterlockedIncrement(&object2); \
+    } while (0)
+#define rx_MutexAdd1Decrement2(object1, addend, object2, mutex) \
+    do { \
+        InterlockedAdd(&object1, addend); \
+        InterlockedDecrement(&object2); \
+    } while (0)
+#else
+#define rx_MutexIncrement(object, mutex) \
+    do { \
+        MUTEX_ENTER(&mutex); \
+        object++; \
+        MUTEX_EXIT(&mutex); \
+    } while(0)
+#define rx_MutexAdd(object, addend, mutex) \
+    do { \
+        MUTEX_ENTER(&mutex); \
+        object += addend; \
+        MUTEX_EXIT(&mutex); \
+    } while(0)
+#define rx_MutexAdd1Increment2(object1, addend, object2, mutex) \
+    do { \
+        MUTEX_ENTER(&mutex); \
+        object1 += addend; \
+        object2++; \
+        MUTEX_EXIT(&mutex); \
+    } while(0)
+#define rx_MutexAdd1Decrement2(object1, addend, object2, mutex) \
+    do { \
+        MUTEX_ENTER(&mutex); \
+        object1 += addend; \
+        object2--; \
+        MUTEX_EXIT(&mutex); \
+    } while(0)
+#define rx_MutexDecrement(object, mutex) \
+    do { \
+        MUTEX_ENTER(&mutex); \
+        object--; \
+        MUTEX_EXIT(&mutex); \
+    } while(0)
+#endif 
 
 #endif /* _RX_   End of rx.h */