@@ -76,22 +76,33 @@ TSPluginInit(int argc, char const *argv[])
7676 return ;
7777 }
7878
79+ bool dump_body = false ;
7980 bool sensitive_fields_were_specified = false ;
8081 traffic_dump::sensitive_fields_t user_specified_fields;
8182 ts::file::path log_dir{traffic_dump::SessionData::default_log_directory};
8283 int64_t sample_pool_size = traffic_dump::SessionData::default_sample_pool_size;
8384 int64_t max_disk_usage = traffic_dump::SessionData::default_max_disk_usage;
8485 std::string sni_filter;
86+ std::string client_ip_filter;
8587
8688 // / Commandline options
87- static const struct option longopts[] = {
88- {" logdir" , required_argument, nullptr , ' l' }, {" sample" , required_argument, nullptr , ' s' },
89- {" limit" , required_argument, nullptr , ' m' }, {" sensitive-fields" , required_argument, nullptr , ' f' },
90- {" sni-filter" , required_argument, nullptr , ' n' }, {nullptr , no_argument, nullptr , 0 }};
91- int opt = 0 ;
89+ static const struct option longopts[] = {{" dump_body" , no_argument, nullptr , ' b' },
90+ {" logdir" , required_argument, nullptr , ' l' },
91+ {" sample" , required_argument, nullptr , ' s' },
92+ {" limit" , required_argument, nullptr , ' m' },
93+ {" sensitive-fields" , required_argument, nullptr , ' f' },
94+ {" sni-filter" , required_argument, nullptr , ' n' },
95+ {" client_ipv4" , required_argument, nullptr , ' 4' },
96+ {" client_ipv6" , required_argument, nullptr , ' 6' },
97+ {nullptr , no_argument, nullptr , 0 }};
98+ int opt = 0 ;
9299 while (opt >= 0 ) {
93- opt = getopt_long (argc, const_cast <char *const *>(argv), " l: " , longopts, nullptr );
100+ opt = getopt_long (argc, const_cast <char *const *>(argv), " bf:l:s:m:n:4:6 " , longopts, nullptr );
94101 switch (opt) {
102+ case ' b' : {
103+ dump_body = true ;
104+ break ;
105+ }
95106 case ' f' : {
96107 // --sensitive-fields takes a comma-separated list of HTTP fields that
97108 // are sensitive. The field values for these fields will be replaced
@@ -128,6 +139,12 @@ TSPluginInit(int argc, char const *argv[])
128139 }
129140 case ' m' : {
130141 max_disk_usage = static_cast <int64_t >(std::strtol (optarg, nullptr , 0 ));
142+ break ;
143+ }
144+ case ' 4' :
145+ case ' 6' : {
146+ client_ip_filter = std::string (optarg);
147+ break ;
131148 }
132149 case -1 :
133150 case ' ?' :
@@ -143,26 +160,26 @@ TSPluginInit(int argc, char const *argv[])
143160 log_dir = ts::file::path (TSInstallDirGet ()) / log_dir;
144161 }
145162 if (sni_filter.empty ()) {
146- if (!traffic_dump::SessionData::init (log_dir.view (), max_disk_usage, sample_pool_size)) {
163+ if (!traffic_dump::SessionData::init (log_dir.view (), max_disk_usage, sample_pool_size, client_ip_filter )) {
147164 TSError (" [%s] Failed to initialize session state." , traffic_dump::debug_tag);
148165 return ;
149166 }
150167 } else {
151- if (!traffic_dump::SessionData::init (log_dir.view (), max_disk_usage, sample_pool_size, sni_filter)) {
168+ if (!traffic_dump::SessionData::init (log_dir.view (), max_disk_usage, sample_pool_size, client_ip_filter, sni_filter)) {
152169 TSError (" [%s] Failed to initialize session state with an SNI filter." , traffic_dump::debug_tag);
153170 return ;
154171 }
155172 }
156173
157174 if (sensitive_fields_were_specified) {
158- if (!traffic_dump::TransactionData::init (std::move (user_specified_fields))) {
175+ if (!traffic_dump::TransactionData::init (dump_body, std::move (user_specified_fields))) {
159176 TSError (" [%s] Failed to initialize transaction state with user-specified fields." , traffic_dump::debug_tag);
160177 return ;
161178 }
162179 } else {
163180 // The user did not provide their own list of sensitive fields. Use the
164181 // default.
165- if (!traffic_dump::TransactionData::init ()) {
182+ if (!traffic_dump::TransactionData::init (dump_body )) {
166183 TSError (" [%s] Failed to initialize transaction state." , traffic_dump::debug_tag);
167184 return ;
168185 }
0 commit comments