I'm trying to set up a forward proxy server with basic proxy authentication using Apache Traffic Server (ATS) on CentOS 6. I've already successfully deployed both SQUID and Apache httpd mod_proxy forward proxies with basic proxy authentication, and want to do the same with ATS to compare performance.
I'm trying to use the basic-auth plugin example provided by ATS, with multiple issues.
I add the latest epel repo for CentOS 6 and install both trafficserver and trafficserver-devel (required to use the ATS compiler, tsxs) packages. I copy the basic-auth.c file from source to my user directory and attempt to compile:
# tsxs -v -o /root/basic-auth.so -c /root/basic-auth.c
Whereupon I get errors for files not found - ts/ink_defs.h
This file is generated by running autoconfig -if
and configure
on the source code - so I went ahead and cloned the trafficserver git repo and ran through the steps to make the few hundred files in /opt/ts/
. I copied these to the directory that tsxs looks at - /usr/include/ts/
(which is here because it is the default location when installed using trafficserver-devel (when I previously only had installed traffic server from source, tsxs would not run).
With the files now in place, I ran the compiler again on basic-auth.cc. This time I receive errors in ts.h
, because of an sdk_version parameter:
# tsxs -v -o basic-auth.so basic-auth.c
compiling basic-auth.c -> basic-auth.lo
cc -I/usr/include -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -feliminate-unused-debug-symbols -fno-strict-aliasing -mcx16 -fpic -c basic-auth.c -o basic-auth.lo
In file included from basic-auth.c:30:
/usr/include/ts/ts.h:158: error: expected ‘)’ before ‘sdk_version’
In file included from /usr/include/ts/ink_defs.h:28,
from basic-auth.c:31:
/usr/include/ts/ink_config.h:41:26: error: ink_autoconf.h: No such file or directory
basic-auth.c: In function ‘TSPluginInit’:
basic-auth.c:222: warning: implicit declaration of function ‘TSPluginRegister’
tsxs: compilation failed: cc -I/usr/include -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -feliminate-unused-debug-symbols -fno-strict-aliasing -mcx16 -fpic -c basic-auth.c -o basic-auth.lo
I investigated the code for ts.h
and compared it with the latest source. You can see that line 156 changes:
trafficserver-devel:
tsapi TSReturnCode TSPluginRegister(TSSDKVersion sdk_version, TSPluginRegistrationInfo plugin_info);
source:
tsapi TSReturnCode TSPluginRegister(TSPluginRegistrationInfo *plugin_info);
Hence I'm assuming there's some issue with the versioning. I replaced my version of ts.h with the latest source and attempted the compile again: it works!
I copy the .so file to the plugins directory and modify plugins.config and records.config accordingly. Alas, when I try to start up trafficserver, it fails with a segmentation fault:
# /usr/bin/traffic_server
traffic_server: using root directory '/usr'
[Jul 15 16:19:21.224] Server {0x7fd9458ba7e0} DEBUG: (dns) ink_dns_init: called with init_called = 0
[Jul 15 16:19:21.227] Server {0x7fd9458ba7e0} DEBUG: (dns) localhost=vmProxy1
[Jul 15 16:19:21.227] Server {0x7fd9458ba7e0} DEBUG: (dns) Round-robin nameservers = 1
traffic_server: Segmentation fault (Signal sent by the kernel [(nil)])traffic_server - STACK TRACE:
/usr/bin/traffic_server(_Z19crash_logger_invokeiP7siginfoPv+0x99)[0x4a5209]
/lib64/libpthread.so.0[0x35b600f710]
/lib64/libc.so.6[0x35b5d3362f]
/usr/lib64/trafficserver/libtsutil.so.5(_xstrdup+0x6d)[0x7fd945f2b6cd]
/usr/bin/traffic_server(TSPluginRegister+0x7c)[0x4bcb6c]
/usr/lib64/trafficserver/plugins/basic-auth.so(TSPluginInit+0x2f)[0x7fd942334e1f]
/usr/bin/traffic_server(_Z11plugin_initb+0x322)[0x4dab22]
/usr/bin/traffic_server(main+0x1424)[0x4d2754]
/lib64/libc.so.6(__libc_start_main+0xfd)[0x35b5c1ed5d]
/usr/bin/traffic_server[0x4942a9]
Segmentation fault (core dumped)
I tried to use gdb to get a better debug log, but I don't see anything useful. There's another mention of sdk_version
- but I'm starting to think that hopping around files and replacing them isn't how it's meant to work...
Starting program: /usr/bin/traffic_server
[Thread debugging using libthread_db enabled]
traffic_server: using root directory '/usr'
[New Thread 0x7ffff7704700 (LWP 19967)]
[Jul 15 16:18:28.841] Server {0x7ffff77777e0} DEBUG: (dns) ink_dns_init: called with init_called = 0
[New Thread 0x7ffff68ff700 (LWP 19968)]
[New Thread 0x7ffff67fe700 (LWP 19969)]
[Jul 15 16:18:28.844] Server {0x7ffff77777e0} DEBUG: (dns) localhost=vmProxy1
[Jul 15 16:18:28.844] Server {0x7ffff77777e0} DEBUG: (dns) Round-robin nameservers = 1
[New Thread 0x7ffff46f5700 (LWP 19970)]
[New Thread 0x7ffff44f3700 (LWP 19971)]
Program received signal SIGSEGV, Segmentation fault.
__strlen_sse42 () at ../sysdeps/x86_64/multiarch/strlen-sse4.S:32
32 pcmpeqb (%rdi), %xmm1
Missing separate debuginfos, use: debuginfo-install tcl-8.5.7-6.el6.x86_64
(gdb) bt
#0 __strlen_sse42 () at ../sysdeps/x86_64/multiarch/strlen-sse4.S:32
#1 0x00007ffff7de86cd in _xstrdup (str=0xd46e3934ae7d6389 <Address 0xd46e3934ae7d6389 out of bounds>, length=-1)
at ink_memory.cc:231
#2 0x00000000004bcb6c in TSPluginRegister (sdk_version=<value optimized out>, plugin_info=0x7fffffffcc50)
at InkAPI.cc:1803
#3 0x00007ffff41f1e1f in TSPluginInit (argc=<value optimized out>, argv=<value optimized out>) at /root/basic-auth.c:222
#4 0x00000000004dab22 in plugin_load (validateOnly=false) at Plugin.cc:114
#5 plugin_init (validateOnly=false) at Plugin.cc:265
#6 0x00000000004d2754 in main (argv=<value optimized out>) at Main.cc:1714
Any hints or tips on what I might be doing wrong are very much appreciated.
Yeah, this is somewhat unfortunate, but the examples in the source tree is not intended to be compiled with tsxs. You would need to make a few changes in the code to make it work. For example, see this git commit I made to the version.c example:
diff --git a/example/version/version.c b/example/version/version.c
index f5c8126..4020a0c 100644
--- a/example/version/version.c
+++ b/example/version/version.c
@@ -24,10 +24,9 @@
#include <stdio.h>
#include "ts/ts.h"
-#include "ts/ink_defs.h"
void
-TSPluginInit(int argc ATS_UNUSED, const char *argv[] ATS_UNUSED)
+TSPluginInit(int argc , const char *argv[])
{
TSPluginRegistrationInfo info;
As for the Version information, this was removed for ATS v6.0.0, which means older plugins also need to be modified to remove it. This also makes previously built binaries are not compatible. There are probably better tools to use than tsxs as well, including the pkgconfig support, and traffic_layout.