summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGraham Leggett <minfrin@apache.org>2023-11-22 18:19:49 +0100
committerGraham Leggett <minfrin@apache.org>2023-11-22 18:19:49 +0100
commitcf5e1a0601dd8616866f389cdc05dcd3d9dd9368 (patch)
tree592e80de1d21a359317ca58a7f9f07a2dc829824
parentmention httpd.conf and install root dependency (diff)
downloadapache2-cf5e1a0601dd8616866f389cdc05dcd3d9dd9368.tar.xz
apache2-cf5e1a0601dd8616866f389cdc05dcd3d9dd9368.zip
Add an option to specify a source address.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1914045 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--changes-entries/ab-source-address.txt4
-rw-r--r--docs/man/ab.13
-rw-r--r--support/ab.c16
3 files changed, 22 insertions, 1 deletions
diff --git a/changes-entries/ab-source-address.txt b/changes-entries/ab-source-address.txt
new file mode 100644
index 0000000000..7ddbeea9a8
--- /dev/null
+++ b/changes-entries/ab-source-address.txt
@@ -0,0 +1,4 @@
+
+ *) Add an option to specify a source address. PR32524
+ [Daniel Rench <gauze omnimental tmetic com>]
+
diff --git a/docs/man/ab.1 b/docs/man/ab.1
index e64e02503f..64d5865fc3 100644
--- a/docs/man/ab.1
+++ b/docs/man/ab.1
@@ -136,6 +136,9 @@ String to use as attributes for \fB<table>\fR\&. Attributes are inserted \fB<tab
\fB-X \fIproxy\fR[:\fIport\fR]\fR
Use a proxy server for the requests\&.
.TP
+\fB-o \fIsrc_address\fR\fR
+Set the local source address\&.
+.TP
\fB-y \fI<tr>-attributes\fR\fR
String to use as attributes for \fB<tr>\fR\&.
.TP
diff --git a/support/ab.c b/support/ab.c
index dfca869710..664c4f8bb1 100644
--- a/support/ab.c
+++ b/support/ab.c
@@ -435,6 +435,7 @@ int bind_count = 0;
const char **bind_hosts;
apr_sockaddr_t **bind_addrs;
apr_port_t connectport;
+char *src_address;
const char *gnuplot; /* GNUplot file */
const char *csvperc; /* CSV Percentile file */
const char *fullurl;
@@ -1613,6 +1614,7 @@ static void start_connection(struct connection * c)
{
struct worker *worker = c->worker;
apr_status_t rv;
+ apr_sockaddr_t *from;
if (!worker_can_connect(worker)) {
return;
@@ -1678,6 +1680,14 @@ static void start_connection(struct connection * c)
}
}
+ if (src_address) {
+ if ((rv = apr_sockaddr_info_get(&from, src_address, destsa->family,
+ 0, 0, c->ctx)) != APR_SUCCESS)
+ graceful_strerror("src_address get", rv);
+ if ((rv = apr_socket_bind(c->aprsock, from)) != APR_SUCCESS)
+ graceful_strerror("src_address bind", rv);
+ }
+
c->read = 0;
c->bread = 0;
c->length = 0;
@@ -2790,6 +2800,7 @@ static void usage(const char *progname)
fprintf(stderr, " -P attribute Add Basic Proxy Authentication, the attributes\n");
fprintf(stderr, " are a colon separated username and password.\n");
fprintf(stderr, " -X proxy:port Proxyserver and port number to use\n");
+ fprintf(stderr, " -o src_address Set the local source address\n");
fprintf(stderr, " -V Print version number and exit\n");
fprintf(stderr, " -k Use HTTP KeepAlive feature\n");
fprintf(stderr, " -d Do not show percentiles served table.\n");
@@ -3030,7 +3041,7 @@ int main(int argc, const char * const argv[])
#endif
apr_getopt_init(&opt, cntxt, argc, argv);
- while ((status = apr_getopt(opt, "n:c:t:s:b:T:p:u:v:lrkVhwiIx:y:z:C:H:P:A:g:X:de:SqQDB:m:R:"
+ while ((status = apr_getopt(opt, "n:c:t:s:b:T:p:u:v:lrkVhwiIx:y:z:C:H:P:A:g:X:de:SqQDB:m:R:o:"
#if APR_HAS_THREADS
"W:"
#endif
@@ -3056,6 +3067,9 @@ int main(int argc, const char * const argv[])
case 'k':
keepalive = 1;
break;
+ case 'o':
+ src_address = strdup(optarg);
+ break;
case 'q':
heartbeatres = 0;
break;