diff --git a/CMakeLists.txt b/CMakeLists.txt index b785ec1348fa4e9354ac79d9e17c90eba997f466..ee7017f9aeb3eae77a032dd43534501296729a2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -PROJECT (accel-pptpd) +PROJECT (accel-pptpd C) cmake_minimum_required(VERSION 2.6) ADD_SUBDIRECTORY(accel-pptpd) diff --git a/README b/README index a0a9a907fb62a044401b0b9cc914043505d3cbcc..b126d3f361ebe1d82caea9215d087baa96beac58 100644 --- a/README +++ b/README @@ -30,7 +30,6 @@ Requirment ---------- 1. modern linux distribution 2. kernel-2.6.25 or later -3. glibc-2.8 or later 4. cmake-2.6 or later 5. libnl-2.0 or probably later (required for l2tp and builtin shaper) diff --git a/accel-pptpd/CMakeLists.txt b/accel-pptpd/CMakeLists.txt index b234cbaaf7e57d122b63ab07aa7183b1f92cf7bf..fb88d1b4c277d280006c9ac0de82d1b48bee6095 100644 --- a/accel-pptpd/CMakeLists.txt +++ b/accel-pptpd/CMakeLists.txt @@ -1,3 +1,16 @@ +INCLUDE(CheckLibraryExists) +INCLUDE(CheckIncludeFiles) + +CHECK_LIBRARY_EXISTS(ssl MD5_Init "" HAVE_SSL) +IF (NOT HAVE_SSL) + MESSAGE(FATAL_ERROR "openssl library not found") +ENDIF (NOT HAVE_SSL) + +CHECK_INCLUDE_FILES("openssl/md5.h" HAVE_SSL) +IF (NOT HAVE_SSL) + MESSAGE(FATAL_ERROR "openssl headers not found") +ENDIF (NOT HAVE_SSL) + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fvisibility=hidden -D_GNU_SOURCE -DGCC_SPINLOCK -DMEMDEBUG") INCLUDE_DIRECTORIES(include) diff --git a/accel-pptpd/extra/sigchld.c b/accel-pptpd/extra/sigchld.c index 49bcfd437c709e925e11f8755eac2cd53803fc75..240b0ddbf066e273b45f1dfefa17f201703c1954 100644 --- a/accel-pptpd/extra/sigchld.c +++ b/accel-pptpd/extra/sigchld.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include "triton.h" diff --git a/accel-pptpd/include/linux_ppp.h b/accel-pptpd/include/linux_ppp.h index 560d04376bb9326e6aa739a940525fc6b1c11b57..ebb4c23588bba39a000ceb7c33dd250ffe4552c5 100644 --- a/accel-pptpd/include/linux_ppp.h +++ b/accel-pptpd/include/linux_ppp.h @@ -11,9 +11,9 @@ #define __aligned_u64 __u64 __attribute__((aligned(8))) #endif +#include #include #include -#include #endif diff --git a/accel-pptpd/logs/CMakeLists.txt b/accel-pptpd/logs/CMakeLists.txt index de66b1e42fd2de7516579a0995fb9fc39efaa28b..b2c432d002aab884987ade29113539cdca60f525 100644 --- a/accel-pptpd/logs/CMakeLists.txt +++ b/accel-pptpd/logs/CMakeLists.txt @@ -1,5 +1,5 @@ ADD_LIBRARY(log_file SHARED log_file.c) -TARGET_LINK_LIBRARIES(log_file aio rt) +TARGET_LINK_LIBRARIES(log_file rt) INSTALL(TARGETS log_file LIBRARY DESTINATION usr/lib/accel-pptp diff --git a/accel-pptpd/logs/log_file.c b/accel-pptpd/logs/log_file.c index be615ad8e108cf97d0c7f3194e894ac6bb7c8c3a..f343286b0ff85bde905d8d0c5733c686a38017a8 100644 --- a/accel-pptpd/logs/log_file.c +++ b/accel-pptpd/logs/log_file.c @@ -6,7 +6,6 @@ #include #include #include -#include #include "log.h" #include "events.h" diff --git a/accel-pptpd/triton/CMakeLists.txt b/accel-pptpd/triton/CMakeLists.txt index 8e9fd3573b8655ed84abbff63f894213eea41ad2..e9133ae71878f5055e259a7a151b0ae832e019e8 100644 --- a/accel-pptpd/triton/CMakeLists.txt +++ b/accel-pptpd/triton/CMakeLists.txt @@ -9,6 +9,25 @@ SET(sources_c event.c ) +INCLUDE(CheckFunctionExists) +CHECK_FUNCTION_EXISTS(timerfd_create HAVE_TIMERFD) + +IF (HAVE_TIMERFD) + ADD_DEFINITIONS(-DHAVE_TIMERFD) +ELSE (HAVE_TIMERFD) + INCLUDE (CheckCSourceCompiles) + CHECK_C_SOURCE_COMPILES(" + #include + int main() + { + syscall(SYS_timerfd_create); + }" HAVE_SYSCALL) + IF (NOT HAVE_SYSCALL) + MESSAGE(FATAL_ERROR "Your system is too old and is not supported by accel-pptp, sorry...") + ENDIF (NOT HAVE_SYSCALL) + SET(sources_c ${sources_c} timerfd.c) +ENDIF (HAVE_TIMERFD) + INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) ADD_DEFINITIONS(-DMODULE_PATH="${CMAKE_INSTALL_PREFIX}/usr/lib/accel-pptp") diff --git a/accel-pptpd/triton/timer.c b/accel-pptpd/triton/timer.c index cbf2b13dcb38720a87cd68789ef006cd3cfec2b8..43cb56f6b85889f44993fde857ef2d775c3dd68e 100644 --- a/accel-pptpd/triton/timer.c +++ b/accel-pptpd/triton/timer.c @@ -2,10 +2,16 @@ #include #include #include -#include #include #include #include +#include + +#ifdef HAVE_TIMERFD +#include +#else +#include "timerfd.h" +#endif #include "triton_p.h" @@ -94,6 +100,7 @@ void *timer_thread(void *arg) return NULL; } + int __export triton_timer_add(struct triton_context_t *ctx, struct triton_timer_t *ud, int abs_time) { struct _triton_timer_t *t = mempool_alloc(timer_pool); @@ -106,20 +113,22 @@ int __export triton_timer_add(struct triton_context_t *ctx, struct triton_timer_ t->ctx = (struct _triton_context_t *)ctx->tpd; else t->ctx = (struct _triton_context_t *)default_ctx->tpd; - t->fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); + t->fd = timerfd_create(CLOCK_MONOTONIC, 0); if (t->fd < 0) { - triton_log_error("timer:timerfd_create: %s" ,strerror(errno)); + triton_log_error("timer:timerfd_create: %s", strerror(errno)); mempool_free(t); return -1; } + + if (fcntl(t->fd, F_SETFL, O_NONBLOCK)) { + triton_log_error("timer: failed to set nonblocking mode: %s\n", strerror(errno)); + goto out_err; + } ud->tpd = t; - if (triton_timer_mod(ud, abs_time)) { - close(t->fd); - mempool_free(t); - return -1; - } + if (triton_timer_mod(ud, abs_time)) + goto out_err; spin_lock(&t->ctx->lock); list_add_tail(&t->entry, &t->ctx->timers); @@ -131,15 +140,18 @@ int __export triton_timer_add(struct triton_context_t *ctx, struct triton_timer_ t->ud = NULL; list_del(&t->entry); spin_unlock(&t->ctx->lock); - close(t->fd); - mempool_free(t); - ud->tpd = NULL; - return -1; + goto out_err; } __sync_fetch_and_add(&triton_stat.timer_count, 1); return 0; + +out_err: + ud->tpd = NULL; + close(t->fd); + mempool_free(t); + return -1; } int __export triton_timer_mod(struct triton_timer_t *ud,int abs_time) { diff --git a/accel-pptpd/triton/timerfd.c b/accel-pptpd/triton/timerfd.c new file mode 100644 index 0000000000000000000000000000000000000000..b026258f2e1d9704c6090ef32176d8b2b6470d41 --- /dev/null +++ b/accel-pptpd/triton/timerfd.c @@ -0,0 +1,19 @@ +#include +#include +#include + +#include "timerfd.h" + +int timerfd_create (clockid_t __clock_id, int __flags) +{ + return syscall(SYS_timerfd_create, __clock_id, __flags); +} + + +int timerfd_settime (int __ufd, int __flags, + __const struct itimerspec *__utmr, + struct itimerspec *__otmr) +{ + return syscall(SYS_timerfd_settime, __ufd, __flags, __utmr, __otmr); +} + diff --git a/accel-pptpd/triton/timerfd.h b/accel-pptpd/triton/timerfd.h new file mode 100644 index 0000000000000000000000000000000000000000..c1bb06f5ff15d2fe1e7a17231f0c2e1a90bc9efe --- /dev/null +++ b/accel-pptpd/triton/timerfd.h @@ -0,0 +1,60 @@ +/* Copyright (C) 2008 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _SYS_TIMERFD_H +#define _SYS_TIMERFD_H 1 + +#include + + +/* Bits to be set in the FLAGS parameter of `timerfd_create'. */ +enum + { + TFD_CLOEXEC = 02000000, +#define TFD_CLOEXEC TFD_CLOEXEC + TFD_NONBLOCK = 04000 +#define TFD_NONBLOCK TFD_NONBLOCK + }; + + +/* Bits to be set in the FLAGS parameter of `timerfd_settime'. */ +enum + { + TFD_TIMER_ABSTIME = 1 << 0 +#define TFD_TIMER_ABSTIME TFD_TIMER_ABSTIME + }; + + +__BEGIN_DECLS + +/* Return file descriptor for new interval timer source. */ +extern int timerfd_create (clockid_t __clock_id, int __flags) __THROW; + +/* Set next expiration time of interval timer source UFD to UTMR. If + FLAGS has the TFD_TIMER_ABSTIME flag set the timeout value is + absolute. Optionally return the old expiration time in OTMR. */ +extern int timerfd_settime (int __ufd, int __flags, + __const struct itimerspec *__utmr, + struct itimerspec *__otmr) __THROW; + +/* Return the next expiration time of UFD. */ +extern int timerfd_gettime (int __ufd, struct itimerspec *__otmr) __THROW; + +__END_DECLS + +#endif /* sys/timerfd.h */