blob: 6b6d8927c51f624896822871c8ed16e75bb01965 [file] [log] [blame]
San Mehat94447ca2009-05-13 11:54:16 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
San Mehat3c5a6f02009-05-22 15:36:13 -070016
San Mehat94447ca2009-05-13 11:54:16 -070017#include <errno.h>
San Mehat5d6d4172009-05-14 15:00:06 -070018#include <netinet/in.h>
19#include <arpa/inet.h>
San Mehat94447ca2009-05-13 11:54:16 -070020
21#define LOG_TAG "OpenVpnController"
22#include <cutils/log.h>
23#include <cutils/properties.h>
24
San Mehat5d6d4172009-05-14 15:00:06 -070025#include <sysutils/ServiceManager.h>
26
San Mehat94447ca2009-05-13 11:54:16 -070027#include "OpenVpnController.h"
San Mehat3c5a6f02009-05-22 15:36:13 -070028#include "PropertyManager.h"
San Mehat94447ca2009-05-13 11:54:16 -070029
30#define DAEMON_PROP_NAME "vpn.openvpn.status"
San Mehat5d6d4172009-05-14 15:00:06 -070031#define DAEMON_CONFIG_FILE "/data/misc/openvpn/openvpn.conf"
San Mehat94447ca2009-05-13 11:54:16 -070032
San Mehat3aff2d12009-06-15 14:10:44 -070033OpenVpnController::OpenVpnController(PropertyManager *propmngr,
34 IControllerHandler *handlers) :
35 VpnController(propmngr, handlers) {
San Mehat5d6d4172009-05-14 15:00:06 -070036 mServiceManager = new ServiceManager();
37}
38
39OpenVpnController::~OpenVpnController() {
40 delete mServiceManager;
San Mehat94447ca2009-05-13 11:54:16 -070041}
42
43int OpenVpnController::start() {
San Mehat3aff2d12009-06-15 14:10:44 -070044 return VpnController::start();
San Mehat94447ca2009-05-13 11:54:16 -070045}
46
47int OpenVpnController::stop() {
San Mehat3aff2d12009-06-15 14:10:44 -070048 return VpnController::stop();
San Mehat94447ca2009-05-13 11:54:16 -070049}
50
51int OpenVpnController::enable() {
San Mehat2fd9c582009-05-20 10:15:23 -070052 char svc[PROPERTY_VALUE_MAX];
53 char tmp[64];
San Mehat3c5a6f02009-05-22 15:36:13 -070054
55 if (!mPropMngr->get("vpn.gateway", tmp, sizeof(tmp))) {
Steve Block01dda202012-01-06 14:13:42 +000056 ALOGE("Error reading property 'vpn.gateway' (%s)", strerror(errno));
San Mehat94447ca2009-05-13 11:54:16 -070057 return -1;
58 }
San Mehat2fd9c582009-05-20 10:15:23 -070059 snprintf(svc, sizeof(svc), "openvpn:--remote %s 1194", tmp);
San Mehat94447ca2009-05-13 11:54:16 -070060
San Mehat2fd9c582009-05-20 10:15:23 -070061 if (mServiceManager->start(svc))
San Mehat5d6d4172009-05-14 15:00:06 -070062 return -1;
63
San Mehat94447ca2009-05-13 11:54:16 -070064 return 0;
65}
66
67int OpenVpnController::disable() {
San Mehat5d6d4172009-05-14 15:00:06 -070068 if (mServiceManager->stop("openvpn"))
69 return -1;
70 return 0;
71}