X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/blobdiff_plain/de8edc7fdb0a26ca9cb736a49b020a64ee4a0d40..8d513103f66617e96234d19813ab655ed9d5d13d:/server/tripe.h diff --git a/server/tripe.h b/server/tripe.h index ad2c0bd7..baae9078 100644 --- a/server/tripe.h +++ b/server/tripe.h @@ -9,19 +9,18 @@ * * This file is part of Trivial IP Encryption (TrIPE). * - * TrIPE is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * TrIPE is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your + * option) any later version. * - * TrIPE is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * TrIPE is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. * * You should have received a copy of the GNU General Public License - * along with TrIPE; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * along with TrIPE. If not, see . */ #ifndef TRIPE_H @@ -67,6 +66,7 @@ #include #include #include +#include #include #include #include @@ -110,6 +110,8 @@ #include #include #include +#include +#include #include "priv.h" #include "protocol.h" @@ -200,7 +202,7 @@ typedef struct dhops { int (*ldpriv)(key_file */*kf*/, key */*k*/, key_data */*d*/, kdata */*kd*/, dstr */*t*/, dstr */*e*/); /* Load a private key from @d@, storing the data in @kd@. The key's - * file and key object are in @kf@ and @k, mostly in case its + * file and key object are in @kf@ and @k@, mostly in case its * attributes are interesting; the key tag is in @t@; errors are * reported by writing tokens to @e@ and returning nonzero. */ @@ -208,7 +210,7 @@ typedef struct dhops { int (*ldpub)(key_file */*kf*/, key */*k*/, key_data */*d*/, kdata */*kd*/, dstr */*t*/, dstr */*e*/); /* Load a public key from @d@, storing the data in @kd@. The key's - * file and key object are in @kf@ and @k, mostly in case its + * file and key object are in @kf@ and @k@, mostly in case its * attributes are interesting; the key tag is in @t@; errors are * reported by writing tokens to @e@ and returning nonzero. */ @@ -408,6 +410,23 @@ extern const bulkops bulktab[]; /*----- Data structures ---------------------------------------------------*/ +/* --- The address-family table --- */ + +#define ADDRFAM(_) \ + _(INET) + +enum { +#define ENUM(af) AFIX_##af, + ADDRFAM(ENUM) +#undef ENUM + NADDRFAM +}; + +extern const struct addrfam { + int af; + const char *name; +} aftab[NADDRFAM]; + /* --- Socket addresses --- * * * A magic union of supported socket addresses. @@ -593,7 +612,6 @@ typedef struct peerspec { const tunnel_ops *tops; /* Tunnel operations */ unsigned long t_ka; /* Keep alive interval */ addr sa; /* Socket address to speak to */ - size_t sasz; /* Socket address size */ unsigned f; /* Flags for the peer */ #define PSF_KXMASK 255u /* Key-exchange flags to set */ #define PSF_MOBILE 256u /* Address may change rapidly */ @@ -614,6 +632,7 @@ typedef struct peer { peer_byaddr *byaddr; /* Lookup-by-address block */ struct ping *pings; /* Pings we're waiting for */ peerspec spec; /* Specifications for this peer */ + int afix; /* Index of address family */ tunnel *t; /* Tunnel for local packets */ char *ifname; /* Interface name for tunnel */ keyset *ks; /* List head for keysets */ @@ -673,6 +692,7 @@ typedef struct admin_resop { bres_client r; /* Background resolver task */ sel_timer t; /* Timer for resolver */ addr sa; /* Socket address */ + unsigned port; /* Port number chosen */ size_t sasz; /* Socket address size */ void (*func)(struct admin_resop *, int); /* Handler */ } admin_resop; @@ -740,7 +760,7 @@ struct admin { #define AF_NOTE 4u /* Catch notifications */ #define AF_WARN 8u /* Catch warning messages */ #ifndef NTRACE - #define AF_TRACE 16u /* Catch tracing */ +# define AF_TRACE 16u /* Catch tracing */ #endif #define AF_FOREGROUND 32u /* Quit server when client closes */ @@ -756,6 +776,7 @@ extern sel_state sel; /* Global I/O event state */ 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 */ +extern sel_file udpsock[NADDRFAM]; /* The master UDP sockets */ extern kdata *master; /* Default private key */ extern const char *tag_priv; /* Default private key tag */ @@ -973,9 +994,8 @@ extern void ks_derivekey(octet */*k*/, size_t /*ksz*/, * the key material; between @k + x@ and @k + y@ is `your' * contribution; and between @k + y@ and @k + z@ is a shared * value we made together. These are used to construct two - * pairs of symmetric keys. Each pair consists of an encryption - * key and a message authentication key. One pair is used for - * outgoing messages, the other for incoming messages. + * collections of symmetric keys: one for outgoing messages, the + * other for incoming messages. * * The new key is marked so that it won't be selected for output * by @ksl_encrypt@. You can still encrypt data with it by @@ -1409,6 +1429,19 @@ extern void ps_quit(void); /*----- Peer management ---------------------------------------------------*/ +/* --- @p_updateaddr@ --- * + * + * Arguments: @peer *p@ = pointer to peer block + * @const addr *a@ = address to associate with this peer + * + * Returns: Zero if the address was changed; @+1@ if it was already + * right. + * + * Use: Updates our idea of @p@'s address. + */ + +extern int p_updateaddr(peer */*p*/, const addr */*a*/); + /* --- @p_txstart@ --- * * * Arguments: @peer *p@ = pointer to peer block @@ -1564,12 +1597,12 @@ extern void p_init(struct in_addr /*addr*/, unsigned /*port*/); /* --- @p_port@ --- * * - * Arguments: --- + * Arguments: @int i@ = address family index to retrieve * * Returns: Port number used for socket. */ -unsigned p_port(void); +extern unsigned p_port(int /*i*/); /* --- @p_create@ --- * * @@ -1729,6 +1762,24 @@ extern const char *timestr(time_t /*t*/); extern int mystrieq(const char */*x*/, const char */*y*/); +/* --- @afix@ --- * + * + * Arguments: @int af@ = an address family code + * + * Returns: The index of the address family's record in @aftab@, or @-1@. + */ + +extern int afix(int af); + +/* --- @addrsz@ --- * + * + * Arguments: @const addr *a@ = a network address + * + * Returns: The size of the address, for passing into the sockets API. + */ + +extern socklen_t addrsz(const addr */*a*/); + /* --- @seq_reset@ --- * * * Arguments: @seqwin *s@ = sequence-checking window