From 84570275acd84628586a6ca591a283d074ca10f0 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 26 Feb 2012 12:33:16 +0100 Subject: [PATCH] Ensure all SPTPS functions are prefixed with sptps_. --- src/connection.c | 2 +- src/meta.c | 4 ++-- src/protocol_auth.c | 2 +- src/sptps.c | 10 +++++----- src/sptps.h | 10 +++++----- src/sptps_test.c | 13 ++++++++----- 6 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/connection.c b/src/connection.c index b61609ad..ee44e539 100644 --- a/src/connection.c +++ b/src/connection.c @@ -69,7 +69,7 @@ void free_connection(connection_t *c) { cipher_close(&c->outcipher); digest_close(&c->outdigest); - stop_sptps(&c->sptps); + sptps_stop(&c->sptps); ecdsa_free(&c->ecdsa); rsa_free(&c->rsa); diff --git a/src/meta.c b/src/meta.c index baa4c2eb..fa031dbd 100644 --- a/src/meta.c +++ b/src/meta.c @@ -57,7 +57,7 @@ bool send_meta(connection_t *c, const char *buffer, int length) { c->name, c->hostname); if(c->protocol_minor >= 2) - return send_record(&c->sptps, 0, buffer, length); + return sptps_send_record(&c->sptps, 0, buffer, length); /* Add our data to buffer */ if(c->status.encryptout) { @@ -163,7 +163,7 @@ bool receive_meta(connection_t *c) { do { if(c->protocol_minor >= 2) { logger(LOG_DEBUG, "Receiving %d bytes of SPTPS data", inlen); - return receive_data(&c->sptps, bufp, inlen); + return sptps_receive_data(&c->sptps, bufp, inlen); } if(!c->status.decryptin) { diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 65e96342..c91723b1 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -144,7 +144,7 @@ bool id_h(connection_t *c, char *request) { else snprintf(label, sizeof label, "tinc TCP key expansion %s %s", c->name, myself->name); - return start_sptps(&c->sptps, c, c->outgoing, myself->connection->ecdsa, c->ecdsa, label, sizeof label, send_meta_sptps, receive_meta_sptps); + return sptps_start(&c->sptps, c, c->outgoing, myself->connection->ecdsa, c->ecdsa, label, sizeof label, send_meta_sptps, receive_meta_sptps); } else { return send_metakey(c); } diff --git a/src/sptps.c b/src/sptps.c index 5088d65d..395c92fc 100644 --- a/src/sptps.c +++ b/src/sptps.c @@ -85,7 +85,7 @@ static bool send_record_priv(sptps_t *s, uint8_t type, const char *data, uint16_ } // Send an application record. -bool send_record(sptps_t *s, uint8_t type, const char *data, uint16_t len) { +bool sptps_send_record(sptps_t *s, uint8_t type, const char *data, uint16_t len) { // Sanity checks: application cannot send data before handshake is finished, // and only record types 0..127 are allowed. if(!s->outstate) @@ -288,7 +288,7 @@ static bool receive_sig(sptps_t *s, const char *data, uint16_t len) { } // Force another Key EXchange (for testing purposes). -bool force_kex(sptps_t *s) { +bool sptps_force_kex(sptps_t *s) { if(!s->outstate || s->state != SPTPS_SECONDARY_KEX) return error(s, EINVAL, "Cannot force KEX in current state"); @@ -332,7 +332,7 @@ static bool receive_handshake(sptps_t *s, const char *data, uint16_t len) { } // Receive incoming data. Check if it contains a complete record, if so, handle it. -bool receive_data(sptps_t *s, const char *data, size_t len) { +bool sptps_receive_data(sptps_t *s, const char *data, size_t len) { while(len) { // First read the 2 length bytes. if(s->buflen < 6) { @@ -422,7 +422,7 @@ bool receive_data(sptps_t *s, const char *data, size_t len) { } // Start a SPTPS session. -bool start_sptps(sptps_t *s, void *handle, bool initiator, ecdsa_t mykey, ecdsa_t hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record) { +bool sptps_start(sptps_t *s, void *handle, bool initiator, ecdsa_t mykey, ecdsa_t hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record) { // Initialise struct sptps memset(s, 0, sizeof *s); @@ -453,7 +453,7 @@ bool start_sptps(sptps_t *s, void *handle, bool initiator, ecdsa_t mykey, ecdsa_ } // Stop a SPTPS session. -bool stop_sptps(sptps_t *s) { +bool sptps_stop(sptps_t *s) { // Clean up any resources. ecdh_free(&s->ecdh); free(s->inbuf); diff --git a/src/sptps.h b/src/sptps.h index 17dfa9c2..065c6a09 100644 --- a/src/sptps.h +++ b/src/sptps.h @@ -76,10 +76,10 @@ typedef struct sptps { receive_record_t receive_record; } sptps_t; -extern bool start_sptps(sptps_t *s, void *handle, bool initiator, ecdsa_t mykey, ecdsa_t hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record); -extern bool stop_sptps(sptps_t *s); -extern bool send_record(sptps_t *s, uint8_t type, const char *data, uint16_t len); -extern bool receive_data(sptps_t *s, const char *data, size_t len); -extern bool force_kex(sptps_t *s); +extern bool sptps_start(sptps_t *s, void *handle, bool initiator, ecdsa_t mykey, ecdsa_t hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record); +extern bool sptps_stop(sptps_t *s); +extern bool sptps_send_record(sptps_t *s, uint8_t type, const char *data, uint16_t len); +extern bool sptps_receive_data(sptps_t *s, const char *data, size_t len); +extern bool sptps_force_kex(sptps_t *s); #endif diff --git a/src/sptps_test.c b/src/sptps_test.c index 6ab7dacb..06d8deab 100644 --- a/src/sptps_test.c +++ b/src/sptps_test.c @@ -118,7 +118,7 @@ int main(int argc, char *argv[]) { fprintf(stderr, "Keys loaded\n"); sptps_t s; - if(!start_sptps(&s, &sock, initiator, mykey, hiskey, "sptps_test", 10, send_data, receive_record)) + if(!sptps_start(&s, &sock, initiator, mykey, hiskey, "sptps_test", 10, send_data, receive_record)) return 1; while(true) { @@ -141,11 +141,11 @@ int main(int argc, char *argv[]) { if(len == 0) break; if(buf[0] == '^') - send_record(&s, SPTPS_HANDSHAKE, NULL, 0); + sptps_send_record(&s, SPTPS_HANDSHAKE, NULL, 0); else if(buf[0] == '$') - force_kex(&s); + sptps_force_kex(&s); else - if(!send_record(&s, buf[0] == '!' ? 1 : 0, buf, buf[0] == '\n' ? 0 : buf[0] == '*' ? sizeof buf : len)) + if(!sptps_send_record(&s, buf[0] == '!' ? 1 : 0, buf, buf[0] == '\n' ? 0 : buf[0] == '*' ? sizeof buf : len)) return 1; } @@ -162,10 +162,13 @@ int main(int argc, char *argv[]) { char hex[len * 2 + 1]; bin2hex(buf, hex, len); fprintf(stderr, "Received %zd bytes of data:\n%s\n", len, hex); - if(!receive_data(&s, buf, len)) + if(!sptps_receive_data(&s, buf, len)) return 1; } } + if(!sptps_stop(&s)) + return 1; + return 0; } -- 2.39.5