Browse Source

MT#15157 integrate redis module into main code tree

obsoletes the entire plugin/module system

Change-Id: I6997b7e6e49dac568e844c3e132fa3756cf147cb
changes/69/2669/1
Richard Fuchs 10 years ago
parent
commit
dafde10571
8 changed files with 1377 additions and 148 deletions
  1. +0
    -4
      README.md
  2. +2
    -1
      daemon/Makefile
  3. +1
    -1
      daemon/call.c
  4. +1
    -94
      daemon/main.c
  5. +1266
    -5
      daemon/redis.c
  6. +102
    -24
      daemon/redis.h
  7. +5
    -18
      debian/control
  8. +0
    -1
      debian/rules

+ 0
- 4
README.md View File

@ -82,10 +82,6 @@ The generated files are (with version 2.3.0 being built on an amd64 system):
Debugging symbols for the daemon. Optional. Debugging symbols for the daemon. Optional.
* `ngcp-rtpengine-dev_2.3.0_all.deb`
Development headers from the daemon. Only necessary if additional modules need to be compiled.
* `ngcp-rtpengine-iptables_2.3.0_amd64.deb` * `ngcp-rtpengine-iptables_2.3.0_amd64.deb`
Installs the plugin for `iptables` and `ip6tables`. Necessary for in-kernel operation. Installs the plugin for `iptables` and `ip6tables`. Necessary for in-kernel operation.


+ 2
- 1
daemon/Makefile View File

@ -41,7 +41,7 @@ else
CFLAGS+= -O3 CFLAGS+= -O3
endif endif
LDFLAGS= -ldl -rdynamic -lm
LDFLAGS= -lm
LDFLAGS+= `pkg-config --libs glib-2.0` LDFLAGS+= `pkg-config --libs glib-2.0`
LDFLAGS+= `pkg-config --libs gthread-2.0` LDFLAGS+= `pkg-config --libs gthread-2.0`
LDFLAGS+= `pkg-config --libs zlib` LDFLAGS+= `pkg-config --libs zlib`
@ -50,6 +50,7 @@ LDFLAGS+= `pkg-config --libs libcrypto`
LDFLAGS+= `pkg-config --libs openssl` LDFLAGS+= `pkg-config --libs openssl`
LDFLAGS+= `pcre-config --libs` LDFLAGS+= `pcre-config --libs`
LDFLAGS+= `xmlrpc-c-config client --libs` LDFLAGS+= `xmlrpc-c-config client --libs`
LDFLAGS+= -lhiredis
ifneq ($(DBG),yes) ifneq ($(DBG),yes)
DPKG_BLDFLGS= $(shell which dpkg-buildflags 2>/dev/null) DPKG_BLDFLGS= $(shell which dpkg-buildflags 2>/dev/null)


+ 1
- 1
daemon/call.c View File

@ -3721,7 +3721,7 @@ void calls_dump_redis(struct callmaster *m) {
return; return;
ilog(LOG_DEBUG, "Start dumping all call data to Redis...\n"); ilog(LOG_DEBUG, "Start dumping all call data to Redis...\n");
redis_wipe_mod(m->conf.redis);
redis_wipe(m->conf.redis);
g_hash_table_foreach(m->callhash, calls_dump_iterator, NULL); g_hash_table_foreach(m->callhash, calls_dump_iterator, NULL);
ilog(LOG_DEBUG, "Finished dumping all call data to Redis\n"); ilog(LOG_DEBUG, "Finished dumping all call data to Redis\n");
} }


+ 1
- 94
daemon/main.c View File

@ -7,7 +7,6 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <dlfcn.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
@ -42,34 +41,6 @@
ilog(LOG_CRIT, x); \ ilog(LOG_CRIT, x); \
exit(-1); \ exit(-1); \
} while(0) } while(0)
#define dlresolve(n) do { \
n ## _mod = dlsym(dlh, "mod_" #n); \
if (!n ## _mod) \
die("Failed to resolve symbol from plugin: %s", "mod_" #n); \
} while(0)
#define check_struct_size(x) do { \
unsigned long *uip; \
uip = dlsym(dlh, "__size_struct_" #x); \
if (!uip) \
die("Failed to resolve symbol from plugin: %s", "__size_struct_" #x); \
if (*uip != sizeof(struct x)) \
die("Struct size mismatch in plugin: %s", #x); \
} while(0)
#define check_struct_offset(x,y) do { \
unsigned long *uip; \
uip = dlsym(dlh, "__offset_struct_" #x "_" #y); \
if (!uip) \
die("Failed to resolve symbol from plugin: %s", \
"__offset_struct_" #x "_" #y); \
if (*uip != (unsigned long) &(((struct x *) 0)->y)) \
die("Struct offset mismatch in plugin: %s->%s", #x, #y); \
uip = dlsym(dlh, "__size_struct_" #x "_" #y); \
if (!uip) \
die("Failed to resolve symbol from plugin: %s", \
"__size_struct_" #x "_" #y); \
if (*uip != sizeof(((struct x *) 0)->y)) \
die("Struct member size mismatch in plugin: %s->%s", #x, #y); \
} while(0)
@ -474,58 +445,6 @@ static void init_everything() {
ice_init(); ice_init();
} }
void redis_mod_verify(void *dlh) {
dlresolve(redis_new);
dlresolve(redis_restore);
dlresolve(redis_update);
dlresolve(redis_delete);
dlresolve(redis_wipe);
check_struct_size(call);
check_struct_size(packet_stream);
check_struct_size(call_media);
check_struct_size(call_monologue);
check_struct_size(crypto_suite);
check_struct_size(crypto_context);
check_struct_offset(call, callmaster);
check_struct_offset(call, master_lock);
check_struct_offset(call, monologues);
check_struct_offset(call, tags);
check_struct_offset(call, streams);
check_struct_offset(call, stream_fds);
check_struct_offset(call, dtls_cert);
check_struct_offset(call, callid);
check_struct_offset(call, last_signal);
check_struct_offset(packet_stream, media);
check_struct_offset(packet_stream, call);
check_struct_offset(packet_stream, rtcp_sibling);
check_struct_offset(packet_stream, handler);
check_struct_offset(packet_stream, crypto);
check_struct_offset(packet_stream, dtls_cert);
check_struct_offset(packet_stream, ps_flags);
check_struct_offset(call_media, monologue);
check_struct_offset(call_media, call);
check_struct_offset(call_media, protocol);
check_struct_offset(call_media, fingerprint);
check_struct_offset(call_media, streams);
check_struct_offset(call_media, media_flags);
check_struct_offset(call_monologue, call);
check_struct_offset(call_monologue, tag);
check_struct_offset(call_monologue, created);
check_struct_offset(call_monologue, other_tags);
check_struct_offset(call_monologue, active_dialogue);
check_struct_offset(call_monologue, medias);
check_struct_offset(stream_fd, fd);
check_struct_offset(stream_fd, call);
check_struct_offset(stream_fd, stream);
check_struct_offset(stream_fd, dtls);
}
void create_everything(struct main_context *ctx) { void create_everything(struct main_context *ctx) {
struct callmaster_config mc; struct callmaster_config mc;
struct control_tcp *ct; struct control_tcp *ct;
@ -533,8 +452,6 @@ void create_everything(struct main_context *ctx) {
struct control_ng *cn; struct control_ng *cn;
struct cli *cl; struct cli *cl;
int kfd = -1; int kfd = -1;
void *dlh;
const char **strp;
struct timeval tmp_tv; struct timeval tmp_tv;
if (table < 0) if (table < 0)
@ -615,17 +532,7 @@ no_kernel:
} }
if (redis_ip) { if (redis_ip) {
dlh = dlopen(RE_PLUGIN_DIR "/rtpengine-redis.so", RTLD_NOW | RTLD_GLOBAL);
if (!dlh && !g_file_test(RE_PLUGIN_DIR "/rtpengine-redis.so", G_FILE_TEST_IS_REGULAR)
&& g_file_test("../../rtpengine-redis/redis.so", G_FILE_TEST_IS_REGULAR))
dlh = dlopen("../../rtpengine-redis/redis.so", RTLD_NOW | RTLD_GLOBAL);
if (!dlh)
die("Failed to open redis plugin, aborting (%s)", dlerror());
strp = dlsym(dlh, "__module_version");
if (!strp || !*strp || strcmp(*strp, REDIS_MODULE_VERSION))
die("Incorrect redis module version: %s", *strp);
redis_mod_verify(dlh);
mc.redis = redis_new_mod(redis_ip, redis_port, redis_db);
mc.redis = redis_new(redis_ip, redis_port, redis_db);
if (!mc.redis) if (!mc.redis)
die("Cannot start up without Redis database"); die("Cannot start up without Redis database");
} }


+ 1266
- 5
daemon/redis.c
File diff suppressed because it is too large
View File


+ 102
- 24
daemon/redis.h View File

@ -1,45 +1,123 @@
#ifndef __REDIS_H__
#define __REDIS_H__
#ifndef __REDIS_MOD_H__
#define __REDIS_MOD_H__
#include <sys/types.h>
#include "compat.h"
#include "aux.h"
#include <glib.h>
#include <sys/types.h>
#include <hiredis/hiredis.h>
struct callmaster; struct callmaster;
struct call; struct call;
struct redis;
extern struct redis *(*redis_new_mod)(u_int32_t, u_int16_t, int);
extern int (*redis_restore_mod)(struct callmaster *, struct redis *);
extern void (*redis_update_mod)(struct call *, struct redis *);
extern void (*redis_delete_mod)(struct call *, struct redis *);
extern void (*redis_wipe_mod)(struct redis *);
struct redis {
u_int32_t ip;
char host[32];
int port;
redisContext *ctx;
int db;
mutex_t lock;
unsigned int pipeline;
};
struct redis_hash {
redisReply *rr;
GHashTable *ht;
};
struct redis_list {
GQueue q;
struct redis_hash rh;
};
struct list_item {
redisReply *id;
struct redis_hash rh;
void *ptr;
};
INLINE void redis_update(struct call *c, struct redis *r) {
if (!redis_update_mod)
return;
redis_update_mod(c, r);
}
INLINE void redis_delete(struct call *c, struct redis *r) {
if (!redis_delete_mod)
return;
redis_delete_mod(c, r);
}
INLINE int redis_restore(struct callmaster *m, struct redis *r) {
if (!redis_restore_mod)
return 0;
return redis_restore_mod(m, r);
#if !GLIB_CHECK_VERSION(2,40,0)
INLINE gboolean g_hash_table_insert_check(GHashTable *h, gpointer k, gpointer v) {
gboolean ret = TRUE;
if (g_hash_table_contains(h, k))
ret = FALSE;
g_hash_table_insert(h, k, v);
return ret;
} }
#else
# define g_hash_table_insert_check g_hash_table_insert
#endif
#define rlog(l, x...) ilog(l | LOG_FLAG_RESTORE, x)
#define REDIS_FMT(x) (x)->len, (x)->str
struct redis *redis_new(u_int32_t, u_int16_t, int);
int redis_restore(struct callmaster *, struct redis *);
void redis_update(struct call *, struct redis *);
void redis_delete(struct call *, struct redis *);
void redis_wipe(struct redis *);
#define define_get_type_format(name, type) \
static int redis_hash_get_ ## name ## _v(type *out, const struct redis_hash *h, const char *f, \
va_list ap) \
{ \
char key[64]; \
\
vsnprintf(key, sizeof(key), f, ap); \
return redis_hash_get_ ## name(out, h, key); \
} \
static int redis_hash_get_ ## name ## _f(type *out, const struct redis_hash *h, const char *f, ...) { \
va_list ap; \
int ret; \
\
va_start(ap, f); \
ret = redis_hash_get_ ## name ## _v(out, h, f, ap); \
va_end(ap); \
return ret; \
}
#define define_get_int_type(name, type, func) \
static int redis_hash_get_ ## name(type *out, const struct redis_hash *h, const char *k) { \
redisReply *r; \
\
r = g_hash_table_lookup(h->ht, k); \
if (!r) \
return -1; \
*out = func(r->str, NULL, 10); \
return 0; \
}


+ 5
- 18
debian/control View File

@ -7,6 +7,7 @@ Build-Depends: debhelper (>= 5),
libcurl4-openssl-dev | libcurl4-gnutls-dev | libcurl4-openssl-dev | libcurl4-gnutls-dev |
libcurl3-openssl-dev | libcurl3-gnutls-dev, libcurl3-openssl-dev | libcurl3-gnutls-dev,
libglib2.0-dev (>= 2.30), libglib2.0-dev (>= 2.30),
libhiredis-dev,
libpcre3-dev, libpcre3-dev,
libssl-dev (>= 1.0.1), libssl-dev (>= 1.0.1),
libxmlrpc-c3-dev (>= 1.16.07) | libxmlrpc-core-c3-dev (>= 1.16.07), libxmlrpc-c3-dev (>= 1.16.07) | libxmlrpc-core-c3-dev (>= 1.16.07),
@ -20,8 +21,10 @@ Architecture: any
Suggests: ngcp-system-tools Suggests: ngcp-system-tools
Depends: ${misc:Depends}, Depends: ${misc:Depends},
${shlibs:Depends} ${shlibs:Depends}
Conflicts: ngcp-mediaproxy-ng-daemon
Replaces: ngcp-mediaproxy-ng-daemon
Conflicts: ngcp-mediaproxy-ng-daemon,
ngcp-rtpengine-redis1
Replaces: ngcp-mediaproxy-ng-daemon,
ngcp-rtpengine-redis1
Recommends: netcat-openbsd | netcat Recommends: netcat-openbsd | netcat
Description: Proxy for RTP and media streams used in NGCP, userspace part. Description: Proxy for RTP and media streams used in NGCP, userspace part.
This daemon handles the first stages of proxying media streams and talks to This daemon handles the first stages of proxying media streams and talks to
@ -73,22 +76,6 @@ Description: IPtables kernel module for the NGCP media proxy - DKMS.
performance packet forwarding. performance packet forwarding.
This package contains the source to be built with dkms. This package contains the source to be built with dkms.
Package: ngcp-rtpengine-dev
Architecture: all
Section: libdevel
Depends: libglib2.0-dev,
libpcre3-dev,
libssl-dev (>= 1.0.1),
${misc:Depends}
Conflicts: ngcp-mediaproxy-ng-dev
Replaces: ngcp-mediaproxy-ng-dev
Description: Development files for rtpengine
This package provides the header files of the rtpengine
software.
.
Install this package if you wish to develop your own programs using
rtpengine.
Package: ngcp-rtpengine-dbg Package: ngcp-rtpengine-dbg
Architecture: any Architecture: any
Section: debug Section: debug


+ 0
- 1
debian/rules View File

@ -110,7 +110,6 @@ binary-arch: install \
# Build architecture independant packages # Build architecture independant packages
binary-indep: build install \ binary-indep: build install \
ngcp-rtpengine \ ngcp-rtpengine \
ngcp-rtpengine-dev \
ngcp-rtpengine-kernel-dkms \ ngcp-rtpengine-kernel-dkms \
ngcp-rtpengine-kernel-source ngcp-rtpengine-kernel-source


Loading…
Cancel
Save