summaryrefslogtreecommitdiffstats
path: root/reg-tests/connection/cli_src_dst.vtc
blob: 6809d3948a688a29bdb3dd955de08b9ff3dae975 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
varnishtest "Test multi-level client source and destination addresses"

feature cmd "$HAPROXY_PROGRAM -cc 'version_atleast(2.5-dev0)'"
feature ignore_unknown_macro

haproxy h1 -conf {
    defaults
        mode http
        timeout connect "${HAPROXY_TEST_TIMEOUT-5s}"
        timeout client  "${HAPROXY_TEST_TIMEOUT-5s}"
        timeout server  "${HAPROXY_TEST_TIMEOUT-5s}"

    frontend fe1
        bind "fd@${fe1}"
        tcp-request connection set-src ipv4(10.0.0.1)
        tcp-request connection set-dst ipv4(10.0.0.2)

        tcp-request session set-var(sess.sess_fc_src) fc_src
        tcp-request session set-var(sess.sess_fc_dst) fc_dst
        tcp-request session set-var(sess.sess_src) src
        tcp-request session set-var(sess.sess_dst) dst

        tcp-request inspect-delay 100ms
        tcp-request content set-var(txn.strm_fc_src) fc_src
        tcp-request content set-var(txn.strm_fc_dst) fc_dst
        tcp-request content set-var(txn.strm_src) src
        tcp-request content set-var(txn.strm_dst) dst

        http-after-response set-header sess-fc-src %[var(sess.sess_fc_src)]
        http-after-response set-header sess-src %[var(sess.sess_src)]
        http-after-response set-header sess-fc-dst %[var(sess.sess_fc_dst)]
        http-after-response set-header sess-dst %[var(sess.sess_dst)]
        http-after-response set-header strm-fc-src %[var(txn.strm_fc_src)]
        http-after-response set-header strm-src %[var(txn.strm_src)]
        http-after-response set-header strm-fc-dst %[var(txn.strm_fc_dst)]
        http-after-response set-header strm-dst %[var(txn.strm_dst)]

        default_backend be

    frontend fe2
        bind "fd@${fe2}"
        tcp-request connection set-src ipv4(10.0.0.1)
        tcp-request connection set-dst ipv4(10.0.0.2)

        tcp-request session set-src ipv4(10.1.0.1)
        tcp-request session set-dst ipv4(10.1.0.2)
        tcp-request session set-var(sess.sess_fc_src) fc_src
        tcp-request session set-var(sess.sess_fc_dst) fc_dst
        tcp-request session set-var(sess.sess_src) src
        tcp-request session set-var(sess.sess_dst) dst

        tcp-request inspect-delay 100ms
        tcp-request content set-var(txn.strm_fc_src) fc_src
        tcp-request content set-var(txn.strm_fc_dst) fc_dst
        tcp-request content set-var(txn.strm_src) src
        tcp-request content set-var(txn.strm_dst) dst

        http-after-response set-header sess-fc-src %[var(sess.sess_fc_src)]
        http-after-response set-header sess-src %[var(sess.sess_src)]
        http-after-response set-header sess-fc-dst %[var(sess.sess_fc_dst)]
        http-after-response set-header sess-dst %[var(sess.sess_dst)]
        http-after-response set-header strm-fc-src %[var(txn.strm_fc_src)]
        http-after-response set-header strm-src %[var(txn.strm_src)]
        http-after-response set-header strm-fc-dst %[var(txn.strm_fc_dst)]
        http-after-response set-header strm-dst %[var(txn.strm_dst)]

        default_backend be

    frontend fe3
        bind "fd@${fe3}"
        tcp-request connection set-src ipv4(10.0.0.1)
        tcp-request connection set-dst ipv4(10.0.0.2)

        tcp-request session set-src ipv4(10.1.0.1)
        tcp-request session set-dst ipv4(10.1.0.2)
        tcp-request session set-var(sess.sess_fc_src) fc_src
        tcp-request session set-var(sess.sess_fc_dst) fc_dst
        tcp-request session set-var(sess.sess_src) src
        tcp-request session set-var(sess.sess_dst) dst

        tcp-request inspect-delay 100ms
        tcp-request content set-src ipv4(10.2.0.1)
        tcp-request content set-dst ipv4(10.2.0.2)
        tcp-request content set-var(txn.strm_fc_src) fc_src
        tcp-request content set-var(txn.strm_fc_dst) fc_dst
        tcp-request content set-var(txn.strm_src) src
        tcp-request content set-var(txn.strm_dst) dst

        http-after-response set-header sess-fc-src %[var(sess.sess_fc_src)]
        http-after-response set-header sess-src %[var(sess.sess_src)]
        http-after-response set-header sess-fc-dst %[var(sess.sess_fc_dst)]
        http-after-response set-header sess-dst %[var(sess.sess_dst)]
        http-after-response set-header strm-fc-src %[var(txn.strm_fc_src)]
        http-after-response set-header strm-src %[var(txn.strm_src)]
        http-after-response set-header strm-fc-dst %[var(txn.strm_fc_dst)]
        http-after-response set-header strm-dst %[var(txn.strm_dst)]


    frontend fe4
        bind "fd@${fe4}"

        tcp-request connection set-src ipv4(10.0.0.1)
        tcp-request connection set-dst ipv4(10.0.0.2)

        tcp-request session set-var(sess.sess_fc_src) fc_src
        tcp-request session set-var(sess.sess_fc_dst) fc_dst
        tcp-request session set-var(sess.sess_src) src
        tcp-request session set-var(sess.sess_dst) dst

        http-request set-src hdr(x-forwarded-for)
        http-request set-dst hdr(x-original-to)
        http-request set-var(txn.strm_fc_src) fc_src
        http-request set-var(txn.strm_fc_dst) fc_dst
        http-request set-var(txn.strm_src) src
        http-request set-var(txn.strm_dst) dst

        http-after-response set-header sess-fc-src %[var(sess.sess_fc_src)]
        http-after-response set-header sess-src %[var(sess.sess_src)]
        http-after-response set-header sess-fc-dst %[var(sess.sess_fc_dst)]
        http-after-response set-header sess-dst %[var(sess.sess_dst)]
        http-after-response set-header strm-fc-src %[var(txn.strm_fc_src)]
        http-after-response set-header strm-src %[var(txn.strm_src)]
        http-after-response set-header strm-fc-dst %[var(txn.strm_fc_dst)]
        http-after-response set-header strm-dst %[var(txn.strm_dst)]

        default_backend be

    backend be
        http-request return status 200

    listen li1
        bind "fd@${li1}"

        tcp-request connection set-src ipv4(10.0.0.1)
        tcp-request connection set-dst ipv4(10.0.0.2)

        http-request set-src ipv4(192.168.0.1)
        http-request set-dst ipv4(192.168.0.2)

        http-after-response set-header li1-fc-src %[fc_src]
        http-after-response set-header li1-src %[src]
        http-after-response set-header li1-fc-dst %[fc_dst]
        http-after-response set-header li1-dst %[dst]


        server srv ${h1_li3_addr}:${h1_li3_port} send-proxy

    listen li2
        bind "fd@${li2}"

        tcp-request connection set-src ipv4(10.0.0.1)
        tcp-request connection set-dst ipv4(10.0.0.2)

        http-request set-src ipv4(192.168.0.1)
        http-request set-dst ipv4(192.168.0.2)

        http-after-response set-header li2-fc-src %[fc_src]
        http-after-response set-header li2-src %[src]
        http-after-response set-header li2-fc-dst %[fc_dst]
        http-after-response set-header li2-dst %[dst]

        server srv ${h1_li3_addr}:${h1_li3_port} send-proxy-v2

    listen li3
        bind "fd@${li3}" accept-proxy

        tcp-request connection set-src ipv4(10.1.0.1)
        tcp-request connection set-dst ipv4(10.1.0.2)

        http-after-response set-header li3-fc-src %[fc_src]
        http-after-response set-header li3-src %[src]
        http-after-response set-header li3-fc-dst %[fc_dst]
        http-after-response set-header li3-dst %[dst]

        http-request return status 200

} -start


client c1 -connect ${h1_fe1_sock} {
    txreq
    rxresp
    expect resp.http.sess-fc-src == 10.0.0.1
    expect resp.http.sess-src    == 10.0.0.1
    expect resp.http.strm-fc-src == 10.0.0.1
    expect resp.http.strm-src    == 10.0.0.1

    expect resp.http.sess-fc-dst == 10.0.0.2
    expect resp.http.sess-dst    == 10.0.0.2
    expect resp.http.strm-fc-dst == 10.0.0.2
    expect resp.http.strm-dst    == 10.0.0.2
} -run

client c2 -connect ${h1_fe2_sock} {
    txreq
    rxresp
    expect resp.http.sess-fc-src == 10.0.0.1
    expect resp.http.sess-src    == 10.1.0.1
    expect resp.http.strm-fc-src == 10.0.0.1
    expect resp.http.strm-src    == 10.1.0.1

    expect resp.http.sess-fc-dst == 10.0.0.2
    expect resp.http.sess-dst    == 10.1.0.2
    expect resp.http.strm-fc-dst == 10.0.0.2
    expect resp.http.strm-dst    == 10.1.0.2
} -run

client c3 -connect ${h1_fe3_sock} {
    txreq
    rxresp
    expect resp.http.sess-fc-src == 10.0.0.1
    expect resp.http.sess-src    == 10.1.0.1
    expect resp.http.strm-fc-src == 10.0.0.1
    expect resp.http.strm-src    == 10.2.0.1

    expect resp.http.sess-fc-dst == 10.0.0.2
    expect resp.http.sess-dst    == 10.1.0.2
    expect resp.http.strm-fc-dst == 10.0.0.2
    expect resp.http.strm-dst    == 10.2.0.2
} -run

client c4 -connect ${h1_fe4_sock} {
    txreq  \
      -hdr "x-forwarded-for: 192.168.0.1" \
      -hdr "x-original-to: 192.168.0.2"
    rxresp
    expect resp.http.sess-fc-src == 10.0.0.1
    expect resp.http.sess-src    == 10.0.0.1
    expect resp.http.strm-fc-src == 10.0.0.1
    expect resp.http.strm-src    == 192.168.0.1

    expect resp.http.sess-fc-dst == 10.0.0.2
    expect resp.http.sess-dst    == 10.0.0.2
    expect resp.http.strm-fc-dst == 10.0.0.2
    expect resp.http.strm-dst    == 192.168.0.2

    txreq  \
      -hdr "x-forwarded-for: 192.168.1.1" \
      -hdr "x-original-to: 192.168.1.2"
    rxresp
    expect resp.http.sess-fc-src == 10.0.0.1
    expect resp.http.sess-src    == 10.0.0.1
    expect resp.http.strm-fc-src == 10.0.0.1
    expect resp.http.strm-src    == 192.168.1.1

    expect resp.http.sess-fc-dst == 10.0.0.2
    expect resp.http.sess-dst    == 10.0.0.2
    expect resp.http.strm-fc-dst == 10.0.0.2
    expect resp.http.strm-dst    == 192.168.1.2

    txreq
    rxresp
    expect resp.http.sess-fc-src == 10.0.0.1
    expect resp.http.sess-src    == 10.0.0.1
    expect resp.http.strm-fc-src == 10.0.0.1
    expect resp.http.strm-src    == 10.0.0.1

    expect resp.http.sess-fc-dst == 10.0.0.2
    expect resp.http.sess-dst    == 10.0.0.2
    expect resp.http.strm-fc-dst == 10.0.0.2
    expect resp.http.strm-dst    == 10.0.0.2
} -run

client c5 -connect ${h1_li1_sock} {
    txreq
    rxresp
    expect resp.http.li1-fc-src == 10.0.0.1
    expect resp.http.li1-src    == 192.168.0.1
    expect resp.http.li1-fc-dst == 10.0.0.2
    expect resp.http.li1-dst    == 192.168.0.2

    expect resp.http.li3-fc-src == 10.1.0.1
    expect resp.http.li3-src    == 192.168.0.1
    expect resp.http.li3-fc-dst == 10.1.0.2
    expect resp.http.li3-dst    == 192.168.0.2
} -run

client c6 -connect ${h1_li2_sock} {
    txreq
    rxresp
    expect resp.http.li2-fc-src == 10.0.0.1
    expect resp.http.li2-src    == 192.168.0.1
    expect resp.http.li2-fc-dst == 10.0.0.2
    expect resp.http.li2-dst    == 192.168.0.2

    expect resp.http.li3-fc-src == 10.1.0.1
    expect resp.http.li3-src    == 192.168.0.1
    expect resp.http.li3-fc-dst == 10.1.0.2
    expect resp.http.li3-dst    == 192.168.0.2
} -run