• R/O
  • HTTP
  • SSH
  • HTTPS

ultramonkey-l7-v2: コミット

UltraMonkey-L7 V2(single-thread implementation)


コミットメタ情報

リビジョン11d85152c6ebf8a1f6bd45111b5a0280b32bbf0a (tree)
日時2010-06-21 20:24:42
作者Kohei TANUMA <tanuma@user...>
コミッターKohei TANUMA

ログメッセージ

Implement transparent proxy.

  • Add new real server forward option -m as Masq and -t as TProxy.
  • ex. $ sudo l7vsadm -A -t 0.0.0.0:80 -m sessionless
$ sudo l7vsadm -a -t 0.0.0.0:80 -m sessionless -r 192.168.0.101:80 -t # TProxy
$ sudo l7vsadm -a -t 0.0.0.0:80 -m sessionless -r 192.168.0.102:80 -m # Masq
$ sudo l7vsadm -a -t 0.0.0.0:80 -m sessionless -r 192.168.0.103:80 # Masq
$ sudo l7vsadm -l -n
Layer-7 Virtual Server version 2.1.3-0
Prot LocalAddress:Port ProtoMod Scheduler
-> RemoteAddress:Port Forward Weight ActiveConn InactConn
TCP 0.0.0.0:80 sessionless wrr
-> 192.168.0.101:80 TProxy 1 0 0
-> 192.168.0.102:80 Masq 1 0 0
-> 192.168.0.103:80 Masq 1 0 0
  • Also add new option to l7directord.
  • ex. $ cat l7directord.cf
virtual = 0.0.0.0:80
real = 192.168.0.101:80 tproxy
real = 192.168.0.102:80 masq
real = 192.168.0.103:80
module = sessionless

変更サマリ

差分

--- a/configure.ac
+++ b/configure.ac
@@ -59,6 +59,12 @@ AC_CHECK_HEADERS([log4cxx/logger.h],,
5959 [AC_MSG_ERROR(l7vsd requires log4cxx. Does your system have log4cxx headers?)])
6060 AC_LANG_POP([C++])
6161
62+# Checks for declarations.
63+AC_CHECK_DECLS([IP_TRANSPARENT], [], [], [[
64+ #include <sys/socket.h>
65+ #include <linux/in.h>
66+]])
67+
6268 # Checks for typedefs, structures, and compiler characteristics.
6369 AC_HEADER_STDBOOL
6470 AC_C_CONST
--- a/include/l7vs.h
+++ b/include/l7vs.h
@@ -26,6 +26,7 @@
2626 #ifndef L7VS_H
2727 #define L7VS_H
2828
29+#include <stdio.h>
2930 #include <string.h>
3031
3132 #define L7VS_VERSION_STRING VERSION
--- a/include/l7vs_conn.h
+++ b/include/l7vs_conn.h
@@ -34,6 +34,11 @@
3434 #include "l7vs_dest.h"
3535 #include "logger_wrapper.h"
3636
37+#include "config.h"
38+#if HAVE_DECL_IP_TRANSPARENT && !defined(IP_TRANSPARENT)
39+#define IP_TRANSPARENT 19
40+#endif
41+
3742 #define FDSET_SIZE (8192)
3843 struct my_fd_set{
3944 char x[FDSET_SIZE];
--- a/include/l7vs_dest.h
+++ b/include/l7vs_dest.h
@@ -13,17 +13,25 @@
1313 #include <sys/socket.h>
1414 #include <netinet/in.h>
1515 #include <arpa/inet.h>
16+#include <stdio.h>
1617 #include "logger_wrapper.h"
1718
19+// ! real-server forward type
20+enum l7vs_dest_forward_type{
21+ L7VS_DEST_FORWARD_MASQ = 0, //! Masquarade
22+ L7VS_DEST_FORWARD_TPROXY = 1 //! Transparent Proxy
23+};
24+
1825 //
1926 // ! real-server datatype
2027 //
2128 //
2229 struct l7vs_dest{
23- struct sockaddr_in addr; //! sockaddr
24- int weight; //! schedule weight use
25- int nactive; //! nactive
26- int ninact; //! ninactive
30+ struct sockaddr_in addr; //! sockaddr
31+ int weight; //! schedule weight use
32+ enum l7vs_dest_forward_type forward; //! forward mode
33+ int nactive; //! nactive
34+ int ninact; //! ninactive
2735 };
2836
2937 //
@@ -31,16 +39,17 @@ struct l7vs_dest{
3139 //
3240 //
3341 struct l7vs_dest_arg{
34- struct sockaddr_in addr;
35- int weight;
36- int nactive;
37- int ninact;
42+ struct sockaddr_in addr;
43+ int weight;
44+ enum l7vs_dest_forward_type forward;
45+ int nactive;
46+ int ninact;
3847 };
3948
4049 //
4150 // functions.
4251 //
43-extern struct l7vs_dest* l7vs_dest_create( struct sockaddr_in*, int );
52+extern struct l7vs_dest* l7vs_dest_create( struct sockaddr_in*, int, enum l7vs_dest_forward_type );
4453 extern void l7vs_dest_destroy( struct l7vs_dest* );
4554 extern void l7vs_dest_to_arg( struct l7vs_dest*, struct l7vs_dest_arg* );
4655
@@ -86,11 +95,13 @@ inline void l7vs_dest_c_str(char *ret,const struct l7vs_dest *dest)
8695 "dest = %p: "
8796 "addr = %s: "
8897 "weight= %d: "
98+ "forward= %d: "
8999 "nactive= %d: "
90100 "ninact= %d: ",
91101 dest,
92102 addr_str,
93103 dest->weight,
104+ dest->forward,
94105 dest->nactive,
95106 dest->ninact);
96107 }
@@ -114,10 +125,12 @@ inline void l7vs_darg_c_str(char *ret,const struct l7vs_dest_arg *darg)
114125 snprintf(ret, DEBUG_STR_LEN,
115126 "addr = %s: "
116127 "weight= %d: "
128+ "forward= %d: "
117129 "nactive= %d: "
118130 "ninact= %d: ",
119131 addr_str,
120132 darg->weight,
133+ darg->forward,
121134 darg->nactive,
122135 darg->ninact);
123136 }
--- a/include/l7vs_iomuxlist.h
+++ b/include/l7vs_iomuxlist.h
@@ -29,6 +29,7 @@
2929 #define L7VS_IOMUX_LIST_REMOVED_MYSELF 1
3030 #define L7VS_IOMUX_LIST_REMOVED_OTHER 2
3131
32+#include <stdio.h>
3233 #include <stdint.h>
3334 #include "l7vs_iom.h"
3435 #include "logger_wrapper.h"
--- a/include/l7vsadm.h
+++ b/include/l7vsadm.h
@@ -82,6 +82,8 @@ enum L7VSADM_OPTION_CODE_TAG {
8282 OPT_QOS_DOWN, //!< QoS-DOWN option(-q)
8383 OPT_REAL_SERVER, //!< RealServer option(-r)
8484 OPT_WEIGHT, //!< RealServer weight option(-w)
85+ OPT_MASQ, //!< RealServer forward option(-m)
86+ OPT_TPROXY, //!< RealServer forward option(-t)
8587 OPT_SWITCH, //!< Replication switching option(-s)
8688 OPT_FORCE, //!< Force Replication option(-f)
8789 OPT_DUMP, //!< Replication data dump option(-d)
@@ -128,6 +130,7 @@ struct l7vsadm_option_data {
128130 int category_all_flag; //!< All Log-Category flag
129131 int replication_start_flag; //!< Start Replication flag
130132 enum PARAMETER_COMPONENT_TAG reload_param; //!< Parameter Reload Componet
133+ enum l7vs_dest_forward_type forward; //!< Forward code
131134 };
132135
133136 //! L7vsadm command code list.
--- a/l7directord/conf/l7directord.cf.sample
+++ b/l7directord/conf/l7directord.cf.sample
@@ -46,4 +46,4 @@ virtual = 192.168.0.50:80
4646 checkcount = 2
4747 #realdowncallback = /opt/down.sh
4848 #realrecovercallback = /opt/recover.sh
49- #customcheck = ping -c1 -w1 _IP_
49+ #customcheck = ping -c1 -w1 _IP_
--- a/l7directord/l7directord
+++ b/l7directord/l7directord
@@ -1067,7 +1067,7 @@ sub parse_fallback {
10671067 if ( !defined $ip_port ) {
10681068 config_error($line, 'ERR0114', $config_line);
10691069 }
1070- if (defined $forward && $forward !~ /^masq$/i) {
1070+ if (defined $forward && $forward !~ /^(?:masq|tproxy)$/i) {
10711071 config_error($line, 'ERR0107', $config_line);
10721072 }
10731073
@@ -1084,7 +1084,7 @@ sub parse_fallback {
10841084 # Parse a real server
10851085 # pre: line: line number real server was read from
10861086 # real: Should be of the form
1087-# ip_address|hostname[:port|:service_name] masq
1087+# ip_address|hostname[:port|:service_name] [masq|tproxy]
10881088 # config_line: line read from configuration file
10891089 # post: real is parsed
10901090 # return: Reference to array include real server hash reference
@@ -1118,7 +1118,7 @@ sub parse_real {
11181118 my %real = %REAL;
11191119 if (defined $forward) {
11201120 $forward = lc $forward;
1121- if ($forward !~ /^masq$/) {
1121+ if ($forward !~ /^(?:masq|tproxy)$/) {
11221122 config_error($line, 'ERR0107', $config_line);
11231123 }
11241124 $real{forward} = $forward;
@@ -1360,7 +1360,7 @@ sub ld_setup {
13601360 #
13611361 # rip_address: IP address of real server
13621362 # rport: Port of real server
1363-# forwarding_mechanism: Forwarding mechanism for real server. This would be only masq.
1363+# forwarding_mechanism: Forwarding mechanism for real server. This would be masq or tproxy.
13641364 # weight: Weight of real server
13651365 #
13661366 # pre: none
@@ -1496,7 +1496,7 @@ sub ld_delete_virtual {
14961496 # ld_operate_real
14971497 # Operate real server on l7vsd by l7vsadm command.
14981498 sub ld_operate_real {
1499- my ($v, $r, $weight, $option, $success_code, $error_code) = @_;
1499+ my ($v, $r, $weight, $forward, $option, $success_code, $error_code) = @_;
15001500 if (!defined $v || !defined $r || !defined $option || !defined $success_code || !defined $error_code) {
15011501 ld_log( _message('ERR0501') );
15021502 return;
@@ -1509,6 +1509,10 @@ sub ld_operate_real {
15091509 if (defined $weight) {
15101510 $command .= ' -w ' . $weight;
15111511 }
1512+ if (defined $forward) {
1513+ $command .= ' -m' if $forward eq 'masq';
1514+ $command .= ' -t' if $forward eq 'tproxy';
1515+ }
15121516 $command .= ' 2>&1';
15131517
15141518 my ($result, $output) = command_wrapper($command);
@@ -1529,22 +1533,22 @@ sub ld_operate_real {
15291533 # ld_add_real
15301534 # Call operate real with add option.
15311535 sub ld_add_real {
1532- my ($v, $r, $weight) = @_;
1533- ld_operate_real($v, $r, $weight, '-a', 'INF0204', 'ERR0204');
1536+ my ($v, $r, $weight, $forward) = @_;
1537+ ld_operate_real($v, $r, $weight, $forward, '-a', 'INF0204', 'ERR0204');
15341538 }
15351539
15361540 # ld_edit_real
15371541 # Call operate real with edit option.
15381542 sub ld_edit_real {
1539- my ($v, $r, $weight) = @_;
1540- ld_operate_real($v, $r, $weight, '-e', 'INF0205', 'ERR0205');
1543+ my ($v, $r, $weight, $forward) = @_;
1544+ ld_operate_real($v, $r, $weight, $forward, '-e', 'INF0205', 'ERR0205');
15411545 }
15421546
15431547 # ld_delete_real
15441548 # Call operate real with delete option.
15451549 sub ld_delete_real {
15461550 my ($v, $r) = @_;
1547- ld_operate_real($v, $r, undef, '-d', 'INF0206', 'ERR0206');
1551+ ld_operate_real($v, $r, undef, undef, '-d', 'INF0206', 'ERR0206');
15481552 }
15491553
15501554 # ld_start
@@ -3037,10 +3041,10 @@ sub _remove_service {
30373041
30383042 if ($is_quiescent) {
30393043 if (defined $or) {
3040- ld_edit_real($v, $r, 0);
3044+ ld_edit_real( $v, $r, 0, $r->{forward} );
30413045 }
30423046 else {
3043- ld_add_real($v, $r, 0);
3047+ ld_add_real( $v, $r, 0, $r->{forward} );
30443048 }
30453049 if (!defined $tag || $tag eq 'real') {
30463050 ld_log( _message( 'INF0303', get_ip_port($r) ) );
@@ -3115,10 +3119,10 @@ sub _restore_service {
31153119 }
31163120
31173121 if (defined $or) {
3118- ld_edit_real( $v, $r, $r->{weight} );
3122+ ld_edit_real( $v, $r, $r->{weight}, $r->{forward} );
31193123 }
31203124 else {
3121- ld_add_real( $v, $r, $r->{weight} );
3125+ ld_add_real( $v, $r, $r->{weight}, $r->{forward} );
31223126 }
31233127
31243128 if (!defined $tag || $tag eq 'real') {
@@ -3614,15 +3618,14 @@ sub get_virtual_id_str {
36143618
36153619 # get_forward_flag
36163620 # Get the l7vsadm flag corresponging to a forwarding mechanism
3617-# pre: forward: Name of forwarding mechanism.
3618-# Should be masq
3621+# pre: forward: Name of forwarding mechanism. (masq or tproxy)
36193622 # post: none
36203623 # return: l7vsadm flag corresponding to the forwading mechanism
36213624 # " " if $forward is unknown
36223625 sub get_forward_flag {
36233626 my $forward = shift;
36243627
3625- if (defined $forward && $forward =~ /^masq$/i) {
3628+ if (defined $forward && $forward =~ /^(?:masq|tproxy)$/i) {
36263629 return '-m';
36273630 }
36283631 return q{};
@@ -3819,7 +3822,7 @@ sub _message_only {
38193822 ERR0105 => "Invalid value (set `lc', `rr' or `wrr') `%s'.",
38203823 ERR0106 => "Invalid value (set `http', `https', `ftp', `smtp', `pop', `imap', "
38213824 . "`ldap', `nntp', `dns', `mysql', `pgsql', `sip', or `none') `%s'.",
3822- ERR0107 => "Invalid value (forwarding mode must be `masq') `%s'.",
3825+ ERR0107 => "Invalid value (forwarding mode must be `masq' or `tproxy') `%s'.",
38233826 ERR0108 => "Invalid port number `%s'.",
38243827 ERR0109 => "Invalid protocol (protocol must be `tcp') `%s'.",
38253828 ERR0110 => "Invalid HTTP method (set `GET' or `HEAD') `%s'.",
@@ -4202,7 +4205,7 @@ This directive might also be used to restart B<l7directord> automatically
42024205 after the configuration file changed on disk. However, if B<autoreload>
42034206 is set to B<yes>, the configuration is reloaded anyway.
42044207
4205-=item B<fallback = >I<ip_address|hostname[:portnumber|servicename]> [B<masq>]
4208+=item B<fallback = >I<ip_address|hostname[:portnumber|servicename]> [B<masq>|B<tproxy>]
42064209
42074210 the server onto which a web service is redirected if all real
42084211 servers are down. Typically this would be 127.0.0.1 with
@@ -4210,7 +4213,7 @@ an emergency page.
42104213
42114214 This directive may also appear within a virtual server, in which
42124215 case it will override the global fallback server, if set.
4213-Only a value of B<masq> can be specified here. The default is I<masq>.
4216+You can set forwarding mode either B<masq> or B<tproxy>. The default is I<masq>.
42144217
42154218 =item B<logfile = ">I</path/to/logfile>B<">|syslog_facility
42164219
@@ -4253,14 +4256,14 @@ with a minimum of 4 spaces or one tab.
42534256
42544257 =over
42554258
4256-=item B<real => I<ip_address|hostname[-E<gt>ip_address|hostname][:portnumber|servicename>] [B<masq>] [I<n>] [B<">I<request>B<", ">I<receive>B<">]
4259+=item B<real => I<ip_address|hostname[-E<gt>ip_address|hostname][:portnumber|servicename>] [B<masq>|B<tproxy>] [I<n>] [B<">I<request>B<", ">I<receive>B<">]
42574260
42584261 Defines a real service by IP-address (or hostname) and port (or
42594262 servicename). If the port is omitted then a 0 will be used.
42604263 Optionally a range of IP addresses (or two hostnames) may be
42614264 given, in which case each IP address in the range will be treated as a real
42624265 server using the given port. The second argument defines the forwarding
4263-method, it must be B<masq> only. The third argument defines the weight of
4266+method, it must be B<masq> or B<tproxy>. The third argument defines the weight of
42644267 each real service. This argument is optional. Default is 1. The last two
42654268 arguments are optional too. They define a request-receive pair to be used to
42664269 check if a server is alive. They override the request-receive pair in the
--- a/l7directord/t/34_change_service.t
+++ b/l7directord/t/34_change_service.t
@@ -69,7 +69,7 @@ our $system_wrapper_arg = ();
6969 local $get_virtual_id_str_return = 'vipid';
7070 local $ld_read_l7vsadm_return = { vipid => { '127.0.0.1:80' => { weight => 1, option => { forward => '-m' } } } };
7171 _remove_service($v, $r, $tag);
72- is_deeply $ld_edit_real_arg, [$v, $r, 0], '_remove_service - quiescent and exist real, no realdowncallback';
72+ is_deeply $ld_edit_real_arg, [$v, $r, 0, undef], '_remove_service - quiescent and exist real, no realdowncallback';
7373 }
7474 {
7575 set_default();
@@ -79,7 +79,7 @@ our $system_wrapper_arg = ();
7979 local $get_virtual_id_str_return = 'vipid';
8080 local $ld_read_l7vsadm_return = { vipid => { '127.0.0.1:80' => { weight => 1, option => { forward => '-m' } } } };
8181 _remove_service($v, $r, $tag);
82- is_deeply $ld_edit_real_arg, [$v, $r, 0], '_remove_service - quiescent and exist real, realdowncallback, first healthcheck';
82+ is_deeply $ld_edit_real_arg, [$v, $r, 0, undef], '_remove_service - quiescent and exist real, realdowncallback, first healthcheck';
8383 }
8484 {
8585 set_default();
@@ -89,7 +89,7 @@ our $system_wrapper_arg = ();
8989 local $get_virtual_id_str_return = 'vipid';
9090 local $ld_read_l7vsadm_return = { vipid => { '127.0.0.1:80' => { weight => 1, option => { forward => '-m' } } } };
9191 _remove_service($v, $r, $tag);
92- is_deeply $ld_edit_real_arg, [$v, $r, 0], '_remove_service - quiescent and exist real, realdowncallback, not first healthcheck';
92+ is_deeply $ld_edit_real_arg, [$v, $r, 0, undef], '_remove_service - quiescent and exist real, realdowncallback, not first healthcheck';
9393 is_deeply $system_wrapper_arg, ['/bin/sh', '127.0.0.1:80'], '_remove_service - run realdowncallback';
9494 }
9595 {
@@ -100,7 +100,7 @@ our $system_wrapper_arg = ();
100100 local $get_virtual_id_str_return = 'vipid';
101101 local $ld_read_l7vsadm_return = { vipid => {} };
102102 _remove_service($v, $r, $tag);
103- is_deeply $ld_add_real_arg, [$v, $r, 0], '_remove_service - quiescent and not exist real, no realdowncallback';
103+ is_deeply $ld_add_real_arg, [$v, $r, 0, undef], '_remove_service - quiescent and not exist real, no realdowncallback';
104104 }
105105 {
106106 set_default();
@@ -110,7 +110,7 @@ our $system_wrapper_arg = ();
110110 local $get_virtual_id_str_return = 'vipid';
111111 local $ld_read_l7vsadm_return = { vipid => {} };
112112 _remove_service($v, $r, $tag);
113- is_deeply $ld_add_real_arg, [$v, $r, 0], '_remove_service - quiescent and not exist real, realdowncallback, first healthcheck';
113+ is_deeply $ld_add_real_arg, [$v, $r, 0, undef], '_remove_service - quiescent and not exist real, realdowncallback, first healthcheck';
114114 }
115115 {
116116 set_default();
@@ -120,7 +120,7 @@ our $system_wrapper_arg = ();
120120 local $get_virtual_id_str_return = 'vipid';
121121 local $ld_read_l7vsadm_return = { vipid => {} };
122122 _remove_service($v, $r, $tag);
123- is_deeply $ld_add_real_arg, [$v, $r, 0], '_remove_service - quiescent and not exist real, realdowncallback, not first healthcheck';
123+ is_deeply $ld_add_real_arg, [$v, $r, 0, undef], '_remove_service - quiescent and not exist real, realdowncallback, not first healthcheck';
124124 is_deeply $system_wrapper_arg, ['/bin/sh', '127.0.0.1:80'], '_remove_service - run realdowncallback';
125125 }
126126 {
@@ -191,7 +191,7 @@ our $system_wrapper_arg = ();
191191 local $get_virtual_id_str_return = 'vipid';
192192 local $ld_read_l7vsadm_return = { vipid => { '127.0.0.1:80' => { weight => 2, option => { forward => '-m' } } } };
193193 _restore_service($v, $r, $tag);
194- is_deeply $ld_edit_real_arg, [$v, $r, 1], '_restore_service - change weight, no realrecovercallback';
194+ is_deeply $ld_edit_real_arg, [$v, $r, 1, undef], '_restore_service - change weight, no realrecovercallback';
195195 }
196196 {
197197 set_default();
@@ -201,7 +201,7 @@ our $system_wrapper_arg = ();
201201 local $get_virtual_id_str_return = 'vipid';
202202 local $ld_read_l7vsadm_return = { vipid => { '127.0.0.1:80' => { weight => 2, option => { forward => '-m' } } } };
203203 _restore_service($v, $r, $tag);
204- is_deeply $ld_edit_real_arg, [$v, $r, 1], '_restore_service - change weight, realrecovercallback, first healthcheck';
204+ is_deeply $ld_edit_real_arg, [$v, $r, 1, undef], '_restore_service - change weight, realrecovercallback, first healthcheck';
205205 }
206206 {
207207 set_default();
@@ -211,7 +211,7 @@ our $system_wrapper_arg = ();
211211 local $get_virtual_id_str_return = 'vipid';
212212 local $ld_read_l7vsadm_return = { vipid => { '127.0.0.1:80' => { weight => 2, option => { forward => '-m' } } } };
213213 _restore_service($v, $r, $tag);
214- is_deeply $ld_edit_real_arg, [$v, $r, 1], '_restore_service - change weight, realrecovercallback, not first healthcheck';
214+ is_deeply $ld_edit_real_arg, [$v, $r, 1, undef], '_restore_service - change weight, realrecovercallback, not first healthcheck';
215215 is_deeply $system_wrapper_arg, ['/bin/sh', '127.0.0.1:80'], '_restore_service - run realrecovercallback';
216216 }
217217 {
@@ -222,7 +222,7 @@ our $system_wrapper_arg = ();
222222 local $get_virtual_id_str_return = 'vipid';
223223 local $ld_read_l7vsadm_return = { vipid => {} };
224224 _restore_service($v, $r, $tag);
225- is_deeply $ld_add_real_arg, [$v, $r, 1], '_restore_service - add real, no realrecovercallback';
225+ is_deeply $ld_add_real_arg, [$v, $r, 1, undef], '_restore_service - add real, no realrecovercallback';
226226 }
227227 {
228228 set_default();
@@ -232,7 +232,7 @@ our $system_wrapper_arg = ();
232232 local $get_virtual_id_str_return = 'vipid';
233233 local $ld_read_l7vsadm_return = { vipid => {} };
234234 _restore_service($v, $r, $tag);
235- is_deeply $ld_add_real_arg, [$v, $r, 1], '_restore_service - add real, realrecovercallback, first healthcheck';
235+ is_deeply $ld_add_real_arg, [$v, $r, 1, undef], '_restore_service - add real, realrecovercallback, first healthcheck';
236236 }
237237 {
238238 set_default();
@@ -242,7 +242,7 @@ our $system_wrapper_arg = ();
242242 local $get_virtual_id_str_return = 'vipid';
243243 local $ld_read_l7vsadm_return = { vipid => {} };
244244 _restore_service($v, $r, $tag);
245- is_deeply $ld_add_real_arg, [$v, $r, 1], '_restore_service - add real, realrecovercallback, not first healthcheck';
245+ is_deeply $ld_add_real_arg, [$v, $r, 1, undef], '_restore_service - add real, realrecovercallback, not first healthcheck';
246246 is_deeply $system_wrapper_arg, ['/bin/sh', '127.0.0.1:80'], '_restore_service - run realrecovercallback';
247247 }
248248 # test end
--- a/logger/logger_impl.h
+++ b/logger/logger_impl.h
@@ -25,6 +25,7 @@
2525 #ifndef __LOGGER_IMPL_H__
2626 #define __LOGGER_IMPL_H__
2727
28+#include <cstdio>
2829 #include <string>
2930 #include <map>
3031 #include <log4cxx/logger.h>
--- a/parameter/parameter_impl.h
+++ b/parameter/parameter_impl.h
@@ -2,6 +2,7 @@
22 #define __PARAMETER_IMPL_H__
33
44 #include "parameter_enum.h"
5+#include <cstdio>
56 #include <iostream>
67 #include <string>
78 #include <map>
--- a/src/config.c
+++ b/src/config.c
@@ -1148,8 +1148,9 @@ l7vs_config_edit_rs(union l7vs_config_req *arg,
11481148 l7vs_config_iomux->status = iomux_config_command_edit_rs_rs_found;
11491149
11501150 if(req->darg.weight != -1){
1151- dest->weight = req->darg.weight;
1151+ dest->weight = req->darg.weight;
11521152 }
1153+ dest->forward = req->darg.forward;
11531154
11541155 l7vs_config_iomux->status = iomux_config_command_edit_rs_succeeded;
11551156
--- a/src/conn.c
+++ b/src/conn.c
@@ -3139,6 +3139,20 @@ l7vs_conn_connect_rs(struct l7vs_conn *conn, struct l7vs_dest *dest)
31393139 /*------ DEBUG LOG END ------*/
31403140 }
31413141
3142+#ifdef IP_TRANSPARENT
3143+ if (dest->forward == L7VS_DEST_FORWARD_TPROXY) {
3144+ int value = 1;
3145+ ret = setsockopt(s, SOL_IP, IP_TRANSPARENT, &value, sizeof(int));
3146+ if (ret != 0) {
3147+ LOGGER_PUT_LOG_WARN(LOG_CAT_L7VSD_SYSTEM_SOCKET,/*XXX*/999, "setsockopt(IP_TRANSPARENT) not supported on this platform.");
3148+ } else {
3149+ ret = bind(s, (struct sockaddr*) &conn->caddr, sizeof(struct sockaddr));
3150+ if (ret != 0) {
3151+ LOGGER_PUT_LOG_WARN(LOG_CAT_L7VSD_SYSTEM_SOCKET,/*XXX*/999, "Cannot bind client address.");
3152+ }
3153+ }
3154+ }
3155+#endif
31423156 /*-------- DEBUG LOG --------*/
31433157 if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_L7VSD_NETWORK)) {
31443158 char addr_str[DEBUG_STR_LEN] = {0};
--- a/src/dest.c
+++ b/src/dest.c
@@ -37,10 +37,11 @@
3737 * create struct dest
3838 * @param[in] *addr sockaddr_in
3939 * @param[in] weight source int
40+ * @param[in] forward forward type
4041 * @return struct l7vs_dest *
4142 */
4243 struct l7vs_dest *
43-l7vs_dest_create(struct sockaddr_in *addr, int weight)
44+l7vs_dest_create(struct sockaddr_in *addr, int weight, enum l7vs_dest_forward_type forward)
4445 {
4546 char dest_str[DEBUG_STR_LEN] = {0};
4647 struct l7vs_dest *dest;
@@ -50,10 +51,10 @@ l7vs_dest_create(struct sockaddr_in *addr, int weight)
5051 if (LOG_LV_DEBUG == logger_get_log_level(LOG_CAT_L7VSD_REAL_SERVER)) {
5152 l7vs_dest_sockaddr_in_c_str(addr_str,addr);
5253 LOGGER_PUT_LOG_DEBUG(LOG_CAT_L7VSD_REAL_SERVER,9,
53- "in_function: struct l7vs_dest * l7vs_dest_create(struct sockaddr_in *addr, int weight)"
54- "addr = %s"
55- "weight = %d",
56- addr_str,weight);
54+ "in_function: struct l7vs_dest * l7vs_dest_create"
55+ "(struct sockaddr_in *addr, int weight, enum l7vs_dest_forward_type forward)"
56+ "addr = %s, weight = %d, forward = %d",
57+ addr_str, weight, forward);
5758 }
5859
5960 dest = (struct l7vs_dest *)malloc(sizeof(*dest));
@@ -71,6 +72,7 @@ l7vs_dest_create(struct sockaddr_in *addr, int weight)
7172
7273 dest->addr = *addr;
7374 dest->weight = weight;
75+ dest->forward = forward;
7476 dest->nactive = dest->ninact = 0;
7577
7678 l7vs_dest_c_str(dest_str, dest);
@@ -135,6 +137,7 @@ l7vs_dest_to_arg(struct l7vs_dest *dest, struct l7vs_dest_arg *darg)
135137 {
136138 darg->addr = dest->addr;
137139 darg->weight = dest->weight;
140+ darg->forward = dest->forward;
138141 darg->nactive = dest->nactive;
139142 darg->ninact = dest->ninact;
140143 }
--- a/src/l7vsadm_main.c
+++ b/src/l7vsadm_main.c
@@ -145,6 +145,8 @@ static struct l7vsadm_option_list l7vsadm_option_table_vs[] = {
145145 //! Table for RealServer command argument check.(optional argument)
146146 static struct l7vsadm_option_list l7vsadm_option_table_rs[] = {
147147 {OPT_WEIGHT, "-w", "--weight", 0},
148+ {OPT_MASQ, "-m", "--masq", 0},
149+ {OPT_TPROXY, "-t", "--tproxy", 0},
148150 {OPT_NONE, NULL, NULL, 0}
149151 };
150152
@@ -1318,6 +1320,28 @@ parse_option_rs(int argc, char *argv[])
13181320 return -1;
13191321 }
13201322 break;
1323+ case OPT_MASQ:
1324+ l7vsadm_option_data.forward = L7VS_DEST_FORWARD_MASQ;
1325+ break;
1326+ case OPT_TPROXY:
1327+#ifdef IP_TRANSPARENT
1328+ l7vsadm_option_data.forward = L7VS_DEST_FORWARD_TPROXY;
1329+ break;
1330+#else
1331+ LOGGER_PUT_LOG_WARN(LOG_CAT_L7VSADM_PARSE,/*XXX*/999,
1332+ "not supported tproxy on this platform.");
1333+ fprintf(stderr, "PARSE ERROR : "
1334+ "not supported tproxy on this platform.\n");
1335+ /*-------- DEBUG LOG --------*/
1336+ if (log_level_parse == LOG_LV_DEBUG) {
1337+ LOGGER_PUT_LOG_DEBUG(LOG_CAT_L7VSADM_PARSE,/*XXX*/999,
1338+ "out_function : static int "
1339+ "parse_option_rs(int argc, char *argv[]) : "
1340+ "return = -1");
1341+ }
1342+ /*------ DEBUG LOG END ------*/
1343+ return -1;
1344+#endif
13211345 default:
13221346 break;
13231347 }
@@ -3571,6 +3595,7 @@ operate_add_rs(void)
35713595
35723596 req.darg.addr = l7vsadm_option_data.rs_addr;
35733597 req.darg.weight = l7vsadm_option_data.weight;
3598+ req.darg.forward = l7vsadm_option_data.forward;
35743599
35753600 // Set data for request
35763601 iov_data.req_iov[0].iov_base = &req;
@@ -4250,6 +4275,8 @@ operate_help(void)
42504275 " --qos-down -q QoSval-down QoS Threshold(bps) set to client direction\n"
42514276 " --real-server -r server-address server-address is host:port\n"
42524277 " --weight -w weight scheduling weight set to real server\n"
4278+ " --masq -m forward mode 'Masquarade'\n"
4279+ " --tproxy -t forward mode 'Transparent Proxy'\n"
42534280 " --switch -s replication-switch start or stop replication\n"
42544281 " --force -f force replication start\n"
42554282 " --dump -d dump replication memory\n"
@@ -5134,7 +5161,10 @@ list_rs(struct l7vs_dest_arg *darg)
51345161
51355162 // Display RealServer.
51365163 printf(" -> %-28s %-7s %-6d %-10d %-10d\n",
5137- endpoint_name, "Masq", darg->weight, darg->nactive, darg->ninact);
5164+ endpoint_name,
5165+ darg->forward == L7VS_DEST_FORWARD_MASQ ? "Masq" :
5166+ darg->forward == L7VS_DEST_FORWARD_TPROXY ? "TProxy" : "Unknown",
5167+ darg->weight, darg->nactive, darg->ninact);
51385168
51395169 /*-------- DEBUG LOG --------*/
51405170 if (log_level_operate == LOG_LV_DEBUG) {
@@ -5882,7 +5912,7 @@ usage(FILE *fp)
58825912 " l7vsadm -D -t service-address -m proto-module [module-args]\n"
58835913 " l7vsadm -C\n"
58845914 " l7vsadm -a|e -t service-address -m proto-module [module-args]\n"
5885- " -r server-address [-w weight]\n"
5915+ " -r server-address [-w weight] [-m|-t]\n"
58865916 " l7vsadm -d -t service-address -m proto-module [module-args]\n"
58875917 " -r server-address\n"
58885918 " l7vsadm -R -s replication-switch\n"
--- a/src/service.c
+++ b/src/service.c
@@ -191,10 +191,11 @@ set_replication_data( unsigned int num, struct l7vs_service_repdata* rep_data, l
191191 srv->sorry_cc = rep_data[i].sorry_cc;
192192 //if sorry is "NULL". Make a sorry_data.
193193 if( NULL == srv->sorry_dest ){
194- srv->sorry_dest = l7vs_dest_create( (struct sockaddr_in*)&rep_data[i].sorry_addr, 1 );
194+ srv->sorry_dest = l7vs_dest_create( (struct sockaddr_in*)&rep_data[i].sorry_addr, 1, L7VS_DEST_FORWARD_MASQ );
195195 }else{
196196 memcpy( (void*)&srv->sorry_dest->addr, (void*)&rep_data[i].sorry_addr, sizeof(struct sockaddr_in) );
197197 srv->sorry_dest->weight = 1;
198+ srv->sorry_dest->forward = L7VS_DEST_FORWARD_MASQ;
198199 srv->sorry_flag = rep_data[i].sorry_flag;
199200 srv->qos_threshold_up = rep_data[i].qos_threshold_up;
200201 srv->qos_threshold_down = rep_data[i].qos_threshold_down;
@@ -699,7 +700,7 @@ l7vs_service_create(struct l7vs_service_arg_multi *arg, int *err)
699700
700701 // create new destination for sorry-server (weight not set)
701702 // FIXME ignore IPv6 address???
702- sorry_dest = (struct l7vs_dest *)l7vs_dest_create((struct sockaddr_in *)&arg->srv_arg.sorry_addr, 0);
703+ sorry_dest = (struct l7vs_dest *)l7vs_dest_create((struct sockaddr_in *)&arg->srv_arg.sorry_addr, 0, L7VS_DEST_FORWARD_MASQ);
703704 if (sorry_dest == NULL) {
704705 l7vs_sched_put(sched);
705706 l7vs_protomod_put(pmod);
@@ -1169,7 +1170,7 @@ l7vs_service_add_dest(struct l7vs_service *srv,
11691170 return -1;
11701171 }
11711172
1172- d = (struct l7vs_dest*) l7vs_dest_create(&darg->addr, darg->weight);
1173+ d = (struct l7vs_dest*) l7vs_dest_create(&darg->addr, darg->weight, darg->forward);
11731174 if (d == NULL) {
11741175 LOGGER_PUT_LOG_ERROR( LOG_CAT_L7VSD_REAL_SERVER,1, "Could not allocate memory" );
11751176 //DEBUG output
旧リポジトリブラウザで表示