Hello,

I have tried to run tinc on a platform that uses connman (OpenELEC), and I
came to the conclusion that a connman tinc vpn plugin is appropriate.

I have attached a proposal, for discussion. I am no programmer, so please
bare with me.

The purpose of the attached (untested) code is merely to start a tinc
daemon (tincd -n name).

Tinc triggers scripts upon events, e.g. tinc-up after tinc comes up,
tinc-down before tinc comes down, etc. This feature could advantageously be
used to keep the tinc vpn plugin to a bare minimum, e.g. tinc-up could call
"connmanctl config service ipv4...", rather than the tinc vpn plugin.

Does this correspond to the philosophy of connman?

Additional questions:
Is it possible to configure a service without a gateway?
Is it possible to tether a vpn?

Thank you for your attention and support,

Anton Voyl
/*
 *
 *  ConnMan VPN daemon
 *
 *  Copyright (C) 2010-2014  BMW Car IT GmbH.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  This program 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 this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <net/if.h>

#include <glib.h>

#define CONNMAN_API_SUBJECT_TO_CHANGE
#include <connman/plugin.h>
#include <connman/log.h>
#include <connman/task.h>
#include <connman/dbus.h>
#include <connman/ipconfig.h>

#include "../vpn-provider.h"

#include "vpn.h"

#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))

static DBusConnection *connection;

static int tinc_notify(DBusMessage *msg, struct vpn_provider *provider)
{
	DBusMessageIter iter;
	const char *reason;

	dbus_message_iter_init(msg, &iter);

	dbus_message_iter_get_basic(&iter, &reason);
	dbus_message_iter_next(&iter);

	if (!provider) {
		connman_error("No provider found");
		return VPN_STATE_FAILURE;
	}

	if (strcmp(reason, "Ready"))
		return VPN_STATE_DISCONNECT;
}

static int tinc_connect(struct vpn_provider *provider,
			struct connman_task *task, const char *if_name,
			vpn_provider_connect_cb_t cb, const char *dbus_sender,
			void *user_data)
{
	int err = 0, fd;
	const char *name;

	task_append_config_data(provider, task);

	name = vpn_provider_get_string(provider, "Name");
	if (name)
		connman_task_add_argument(task, "-n", name);

	fd = fileno(stderr);
	err = connman_task_run(task, vpn_died, provider,
			NULL, &fd, &fd);
	if (err < 0) {
		connman_error("tinc failed to start");
		err = -EIO;
		goto done;
	}

done:
	if (cb)
		cb(provider, user_data, err);

	return err;
}

static struct vpn_driver vpn_driver = {
	.notify		= tinc_notify,
	.connect	= tinc_connect,
};

static int tinc_init(void)
{
	connection = connman_dbus_get_connection();

	return vpn_register("tinc", &vpn_driver, TINC);
}

static void tinc_exit(void)
{
	vpn_unregister("tinc");

	dbus_connection_unref(connection);
}

CONNMAN_PLUGIN_DEFINE(tinc, "tinc plugin", VERSION,
	CONNMAN_PLUGIN_PRIORITY_DEFAULT, tinc_init, tinc_exit)
_______________________________________________
connman mailing list
[email protected]
https://lists.connman.net/mailman/listinfo/connman

Reply via email to