along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: net_socket.c,v 1.1.2.36 2003/12/20 19:47:52 guus Exp $
+ $Id: net_socket.c,v 1.1.2.38 2003/12/22 11:04:16 guus Exp $
*/
#include "system.h"
+#include <gnutls/gnutls.h>
+
#include "avl_tree.h"
#include "conf.h"
#include "connection.h"
listen_socket_t listen_socket[MAXSOCKETS];
int listen_sockets;
+int certselfunc(gnutls_session session, const gnutls_datum *client_cert, int ncerts, const gnutls_datum* req_ca_cert, int nreqs) {
+ logger(LOG_DEBUG, "Client certificate select function called with %d certs, %d requests\n", ncerts, nreqs);
+ return 0;
+}
+
+int scertselfunc(gnutls_session session, const gnutls_datum *server_cert, int ncerts) {
+ logger(LOG_DEBUG, "Server certificate select function called with %d certs\n", ncerts);
+ return 0;
+}
+
/* Setup sockets */
int setup_listen_socket(const sockaddr_t *sa)
{
bool choice;
- if(get_config_bool(lookup_config(myself->connection->config_tree, "DontFragment"), &choice) && choice) {
+ if(get_config_bool(lookup_config(myself->connection->config_tree, "PMTUDiscovery"), &choice) && choice) {
option = IP_PMTUDISC_DO;
- if(setsockopt(nfd, SOL_IP, IP_MTU_DISCOVER, &option, sizeof(option))) {
- closesocket(nfd);
- logger(LOG_ERR, _("Can't set MTU discovery mode: %s"), strerror(errno));
- return -1;
- }
+ setsockopt(nfd, SOL_IP, IP_MTU_DISCOVER, &option, sizeof(option));
+ }
+ }
+#endif
+
+#if defined(SOL_IPV6) && defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DO)
+ {
+ bool choice;
+
+ if(get_config_bool(lookup_config(myself->connection->config_tree, "PMTUDiscovery"), &choice) && choice) {
+ option = IPV6_PMTUDISC_DO;
+ setsockopt(nfd, SOL_IPV6, IPV6_MTU_DISCOVER, &option, sizeof(option));
}
}
#endif
void finish_connecting(connection_t *c)
{
+ int result;
+
cp();
ifdebug(CONNECTIONS) logger(LOG_INFO, _("Connected to %s (%s)"), c->name, c->hostname);
c->last_ping_time = now;
- send_id(c);
+ gnutls_init(&c->session, GNUTLS_SERVER);
+ gnutls_set_default_priority(c->session);
+ gnutls_credentials_set(c->session, GNUTLS_CRD_CERTIFICATE, myself->connection->credentials);
+ gnutls_certificate_server_set_request(c->session, GNUTLS_CERT_REQUEST);
+// gnutls_certificate_client_set_select_function(c->session, certselfunc);
+// gnutls_certificate_server_set_select_function(c->session, scertselfunc);
+ gnutls_transport_set_ptr(c->session, c->socket);
}
void do_outgoing_connection(connection_t *c)
goto begin;
}
+ logger(LOG_DEBUG, _("finishing connection"));
finish_connecting(c);
return;
c = new_connection();
c->name = xstrdup(outgoing->name);
- c->outcipher = myself->connection->outcipher;
- c->outdigest = myself->connection->outdigest;
- c->outmaclength = myself->connection->outmaclength;
- c->outcompression = myself->connection->outcompression;
init_configuration(&c->config_tree);
read_connection_config(c);
connection_t *c;
sockaddr_t sa;
int fd, len = sizeof(sa);
+ int result;
cp();
return false;
}
+#ifdef O_NONBLOCK
+ {
+ int flags = fcntl(fd, F_GETFL);
+
+ if(fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
+ closesocket(fd);
+ logger(LOG_ERR, _("System call `%s' failed: %s"), "fcntl",
+ strerror(errno));
+ return -1;
+ }
+ }
+#endif
+
sockaddrunmap(&sa);
c = new_connection();
- c->outcipher = myself->connection->outcipher;
- c->outdigest = myself->connection->outdigest;
- c->outmaclength = myself->connection->outmaclength;
- c->outcompression = myself->connection->outcompression;
c->address = sa;
c->hostname = sockaddr2hostname(&sa);
connection_add(c);
c->allow_request = ID;
- send_id(c);
+ gnutls_init(&c->session, GNUTLS_CLIENT);
+ gnutls_set_default_priority(c->session);
+ gnutls_credentials_set(c->session, GNUTLS_CRD_CERTIFICATE, myself->connection->credentials);
+ gnutls_certificate_server_set_request(c->session, GNUTLS_CERT_REQUEST);
+// gnutls_certificate_client_set_select_function(c->session, certselfunc);
+// gnutls_certificate_server_set_select_function(c->session, scertselfunc);
+ gnutls_transport_set_ptr(c->session, c->socket);
+ gnutls_handshake(c->session);
return true;
}