Skip to content
Snippets Groups Projects
Verified Commit ddeac2d9 authored by Jan Pavlinec's avatar Jan Pavlinec
Browse files

atlas-probe: add busybox part of RIPE atlas part SW

Note:
Patches for OpenSSL are ported from https://github.com/libevent/libevent/commit/3e9e0a0d46e4508e8782ec3787c6d86bab63046d
parent ee4d77e1
Branches
Tags
2 merge requests!259Turris OS 5.0 merge,!146atlas-probe: add busybox part of RIPE atlas part SW
#
# Copyright (C) 2019 CZ.NIC z.s.p.o. (https://www.nic.cz/)
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=atlas-probe
PKG_VERSION:=2.0.0
PKG_RELEASE:=1
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/RIPE-NCC/ripe-atlas-probe-busybox.git
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_VERSION:=v$(PKG_VERSION)
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_MAINTAINER:=CZ.NIC <packaging@turris.cz>
PKG_LICENSE:=GPL-2.0-or-later
PKG_LICENSE_FILES:=LICENSE
include $(INCLUDE_DIR)/package.mk
define Package/atlas-probe
SECTION:=net
CATEGORY:=Network
TITLE:=RIPE Atlas probe measurement
DEPENDS:=+librt +libopenssl +openssh-client +sudo
USERID:=atlas=444:atlas=444
URL:=https://atlas.ripe.net/
endef
define Package/atlas-probe/description
RIPE Atlas is a global, open, distributed Internet measurement platform,
consisting of thousands of measurement devices that measure Internet
connectivity in real time.
endef
TARGET_CFLAGS += $(FPIC)
CONFIGURE_ARGS += \
--disable-shared \
--enable-static
CONFIGURE_PATH = libevent-2.0.20-stable
TARGET_LDFLAGS = -L$(PKG_BUILD_DIR)/$(CONFIGURE_PATH)/.libs
define Build/Compile
+$(MAKE_VARS) \
$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR)/$(CONFIGURE_PATH) \
$(MAKE_FLAGS)
+$(MAKE_VARS) \
$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
$(MAKE_FLAGS)
endef
define Package/atlas-probe/install
+$(MAKE_VARS) \
$(MAKE) $(PKG_JOBS) -C $(PKG_BUILD_DIR) \
$(MAKE_FLAGS) CONFIG_PREFIX=$(1)/usr/libexec/atlas-probe install
$(INSTALL_DIR) $(1)/usr/libexec/atlas-probe/state
echo $(PKG_VERSION) > $(1)/usr/libexec/atlas-probe/state/FIRMWARE_APPS_VERSION
endef
$(eval $(call BuildPackage,atlas-probe))
--- /dev/null
+++ b/libevent-2.0.20-stable/openssl-compat.h
@@ -0,0 +1,44 @@
+#ifndef OPENSSL_COMPAT_H
+#define OPENSSL_COMPAT_H
+
+#include <openssl/bio.h>
+#include "util-internal.h"
+
+#if (OPENSSL_VERSION_NUMBER < 0x10100000L) || \
+ (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L)
+
+static inline BIO_METHOD *BIO_meth_new(int type, const char *name)
+{
+ BIO_METHOD *biom = calloc(1, sizeof(BIO_METHOD));
+
+ if (biom != NULL) {
+ biom->type = type;
+ biom->name = name;
+ }
+ return biom;
+}
+
+#define BIO_meth_set_write(b, f) (b)->bwrite = (f)
+#define BIO_meth_set_read(b, f) (b)->bread = (f)
+#define BIO_meth_set_puts(b, f) (b)->bputs = (f)
+#define BIO_meth_set_ctrl(b, f) (b)->ctrl = (f)
+#define BIO_meth_set_create(b, f) (b)->create = (f)
+#define BIO_meth_set_destroy(b, f) (b)->destroy = (f)
+
+#define BIO_set_init(b, val) (b)->init = (val)
+#define BIO_set_data(b, val) (b)->ptr = (val)
+#define BIO_set_shutdown(b, val) (b)->shutdown = (val)
+#define BIO_get_init(b) (b)->init
+#define BIO_get_data(b) (b)->ptr
+#define BIO_get_shutdown(b) (b)->shutdown
+
+#define TLS_method SSLv23_method
+
+#endif /* (OPENSSL_VERSION_NUMBER < 0x10100000L) || \
+ (defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER < 0x20700000L) */
+
+#if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER >= 0x20700000L
+#define BIO_get_init(b) (b)->init
+#endif
+
+#endif /* OPENSSL_COMPAT_H */
--- a/libevent-2.0.20-stable/bufferevent_openssl.c
+++ b/libevent-2.0.20-stable/bufferevent_openssl.c
@@ -60,6 +60,7 @@
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
+#include "openssl-compat.h"
/*
* Define an OpenSSL bio that targets a bufferevent.
@@ -103,10 +104,8 @@
static int
bio_bufferevent_new(BIO *b)
{
+ BIO_set_init(b, 0);
+ BIO_set_data(b, NULL); /* We'll be putting the bufferevent in this field.*/
- b->init = 0;
- b->num = -1;
- b->ptr = NULL; /* We'll be putting the bufferevent in this field.*/
- b->flags = 0;
return 1;
}
@@ -116,12 +115,10 @@
{
if (!b)
return 0;
+ if (BIO_get_shutdown(b)) {
+ if (BIO_get_init(b) && BIO_get_data(b))
+ bufferevent_free(BIO_get_data(b));
+ BIO_free(b);
- if (b->shutdown) {
- if (b->init && b->ptr)
- bufferevent_free(b->ptr);
- b->init = 0;
- b->flags = 0;
- b->ptr = NULL;
}
return 1;
}
@@ -137,10 +134,10 @@
if (!out)
return 0;
+ if (!BIO_get_data(b))
- if (!b->ptr)
return -1;
+ input = bufferevent_get_input(BIO_get_data(b));
- input = bufferevent_get_input(b->ptr);
if (evbuffer_get_length(input) == 0) {
/* If there's no data to read, say so. */
BIO_set_retry_read(b);
@@ -156,13 +153,13 @@
static int
bio_bufferevent_write(BIO *b, const char *in, int inlen)
{
+ struct bufferevent *bufev = BIO_get_data(b);
- struct bufferevent *bufev = b->ptr;
struct evbuffer *output;
size_t outlen;
BIO_clear_retry_flags(b);
+ if (!BIO_get_data(b))
- if (!b->ptr)
return -1;
output = bufferevent_get_output(bufev);
@@ -188,15 +185,15 @@
static long
bio_bufferevent_ctrl(BIO *b, int cmd, long num, void *ptr)
{
+ struct bufferevent *bufev = BIO_get_data(b);
- struct bufferevent *bufev = b->ptr;
long ret = 1;
switch (cmd) {
case BIO_CTRL_GET_CLOSE:
+ ret = BIO_get_shutdown(b);
- ret = b->shutdown;
break;
case BIO_CTRL_SET_CLOSE:
+ BIO_set_shutdown(b, (int)num);
- b->shutdown = (int)num;
break;
case BIO_CTRL_PENDING:
ret = evbuffer_get_length(bufferevent_get_input(bufev)) != 0;
@@ -225,23 +222,24 @@
}
/* Method table for the bufferevent BIO */
+static BIO_METHOD *methods_bufferevent;
-static BIO_METHOD methods_bufferevent = {
- BIO_TYPE_LIBEVENT, "bufferevent",
- bio_bufferevent_write,
- bio_bufferevent_read,
- bio_bufferevent_puts,
- NULL /* bio_bufferevent_gets */,
- bio_bufferevent_ctrl,
- bio_bufferevent_new,
- bio_bufferevent_free,
- NULL /* callback_ctrl */,
-};
/* Return the method table for the bufferevents BIO */
static BIO_METHOD *
BIO_s_bufferevent(void)
{
+ if (methods_bufferevent == NULL) {
+ methods_bufferevent = BIO_meth_new(BIO_TYPE_LIBEVENT, "bufferevent");
+ if (methods_bufferevent == NULL)
+ return NULL;
+ BIO_meth_set_write(methods_bufferevent, bio_bufferevent_write);
+ BIO_meth_set_read(methods_bufferevent, bio_bufferevent_read);
+ BIO_meth_set_puts(methods_bufferevent, bio_bufferevent_puts);
+ BIO_meth_set_ctrl(methods_bufferevent, bio_bufferevent_ctrl);
+ BIO_meth_set_create(methods_bufferevent, bio_bufferevent_new);
+ BIO_meth_set_destroy(methods_bufferevent, bio_bufferevent_free);
+ }
+ return methods_bufferevent;
- return &methods_bufferevent;
}
/* Create a new BIO to wrap communication around a bufferevent. If close_flag
@@ -254,9 +252,9 @@
return NULL;
if (!(result = BIO_new(BIO_s_bufferevent())))
return NULL;
+ BIO_set_init(result, 1);
+ BIO_set_data(result, bufferevent);
+ BIO_set_shutdown(result, close_flag ? 1 : 0);
- result->init = 1;
- result->ptr = bufferevent;
- result->shutdown = close_flag ? 1 : 0;
return result;
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment