chiark / gitweb /
svc/conntrack{,.8}.in: Better diagnostics.
[tripe] / server / tripe.h
index 217a88dfd00ab4c9760ca767640f9f351a68f135..72a47a108b45739de63e1d7d1eb8f600b6edc909 100644 (file)
 
 #define SEC(n) (n##u)
 #define MIN(n) (n##u * 60u)
+#define F_2P32 (65536.0*65536.0)
 #define MEG(n) (n##ul * 1024ul * 1024ul)
 
+/* --- Timing parameters --- */
+
+#define T_EXP MIN(60)                  /* Expiry time for a key */
+#define T_REGEN MIN(40)                        /* Regeneration time for a key */
+
+#define T_VALID SEC(20)                        /* Challenge validity period */
+#define T_RETRYMIN SEC(2)              /* Minimum retry interval */
+#define T_RETRYMAX MIN(5)              /* Maximum retry interval */
+#define T_RETRYGROW (5.0/4.0)          /* Retry interval growth factor */
+
+#define T_WOBBLE (1.0/3.0)             /* Relative timer randomness */
+
 /* --- Other things --- */
 
 #define PKBUFSZ 65536
@@ -153,8 +166,6 @@ typedef struct algswitch {
   size_t cksz, mksz;                   /* Key lengths for @c@ and @m@ */
 } algswitch;
 
-extern algswitch algs;
-
 typedef struct kdata {
   unsigned ref;                                /* Reference counter */
   struct knode *kn;                    /* Pointer to cache entry */
@@ -258,6 +269,10 @@ typedef struct keyset {
  * Clive Jones.
  */
 
+typedef struct retry {
+  double t;                            /* Current retry time */
+} retry;
+
 #define KX_NCHAL 16u
 
 typedef struct kxchal {
@@ -267,6 +282,7 @@ typedef struct kxchal {
   keyset *ks;                          /* Pointer to temporary keyset */
   unsigned f;                          /* Various useful flags */
   sel_timer t;                         /* Response timer for challenge */
+  retry rs;                            /* Retry state */
   octet hc[MAXHASHSZ];                 /* Hash of his challenge */
   octet ck[MAXHASHSZ];                 /* His magical check value */
   octet hswrq_in[MAXHASHSZ];           /* Inbound switch request message */
@@ -277,12 +293,13 @@ typedef struct kxchal {
 
 typedef struct keyexch {
   struct peer *p;                      /* Pointer back to the peer */
+  kdata *kpriv;                                /* Private key and related info */
+  kdata *kpub;                         /* Peer's public key */
   keyset **ks;                         /* Peer's list of keysets */
   unsigned f;                          /* Various useful flags */
   unsigned s;                          /* Current state in exchange */
   sel_timer t;                         /* Timer for next exchange */
-  ge *kpub;                            /* Peer's public key */
-  time_t texp_kpub;                    /* Expiry time for public key */
+  retry rs;                            /* Retry state */
   mp *alpha;                           /* My temporary secret */
   ge *c;                               /* My challenge */
   ge *rx;                              /* The expected response */
@@ -355,6 +372,7 @@ typedef struct stats {
 
 typedef struct peerspec {
   char *name;                          /* Peer's name */
+  char *privtag;                       /* Private key tag */
   char *tag;                           /* Public key tag */
   const tunnel_ops *tops;              /* Tunnel operations */
   unsigned long t_ka;                  /* Keep alive interval */
@@ -519,10 +537,6 @@ typedef struct admin {
 /*----- Global variables --------------------------------------------------*/
 
 extern sel_state sel;                  /* Global I/O event state */
-extern group *gg;                      /* The group we work in */
-extern size_t indexsz;                 /* Size of exponent for the group */
-extern mp *kpriv;                      /* Our private key */
-extern ge *kpub;                       /* Our public key */
 extern octet buf_i[PKBUFSZ], buf_o[PKBUFSZ], buf_t[PKBUFSZ], buf_u[PKBUFSZ];
 extern const tunnel_ops *tunnels[];    /* Table of tunnels (0-term) */
 extern const tunnel_ops *tun_default;  /* Default tunnel to use */
@@ -621,21 +635,6 @@ extern void km_unref(kdata */*kd*/);
 
 extern const char *km_tag(kdata */*kd*/);
 
-/* --- @km_getpubkey@ --- *
- *
- * Arguments:  @const char *tag@ = public key tag to load
- *             @ge *kpub@ = where to put the public key
- *             @time_t *t_exp@ = where to put the expiry time
- *
- * Returns:    Zero if OK, nonzero if it failed.
- *
- * Use:                Fetches a public key from the keyring.  (Temporary
- *             compatibility hack.)
- */
-
-extern int km_getpubkey(const char */*tag*/, ge */*kpub*/,
-                       time_t */*t_exp*/);
-
 /*----- Key exchange ------------------------------------------------------*/
 
 /* --- @kx_start@ --- *
@@ -749,15 +748,6 @@ extern keyset *ks_gen(const void */*k*/,
                      size_t /*x*/, size_t /*y*/, size_t /*z*/,
                      peer */*p*/);
 
-/* --- @ks_tregen@ --- *
- *
- * Arguments:  @keyset *ks@ = pointer to a keyset
- *
- * Returns:    The time at which moves ought to be made to replace this key.
- */
-
-extern time_t ks_tregen(keyset */*ks*/);
-
 /* --- @ks_activate@ --- *
  *
  * Arguments:  @keyset *ks@ = pointer to a keyset
@@ -1351,6 +1341,15 @@ extern const char *p_name(peer */*p*/);
 
 extern const char *p_tag(peer */*p*/);
 
+/* --- @p_privtag@ --- *
+ *
+ * Arguments:  @peer *p@ = pointer to a peer block
+ *
+ * Returns:    A pointer to the peer's private key tag.
+ */
+
+extern const char *p_privtag(peer */*p*/);
+
 /* --- @p_spec@ --- *
  *
  * Arguments:  @peer *p@ = pointer to a peer block