@@ -251,7 +251,9 @@ name: bar
251
251
addOrUpdateListener (parseListenerFromV3Yaml (yaml1));
252
252
EXPECT_THROW_WITH_MESSAGE (
253
253
addOrUpdateListener (parseListenerFromV3Yaml (yaml2)), EnvoyException,
254
- " error adding listener: 'bar' has duplicate address '127.0.0.1:1234' as existing listener" );
254
+ " error adding listener: 'bar' has duplicate address '127.0.0.1:1234' as existing listener, "
255
+ " to check if the listener has duplicated addresses with other listeners or "
256
+ " 'enable_reuse_port' is set to 'false' for the listener" );
255
257
}
256
258
257
259
TEST_P (ListenerManagerImplWithRealFiltersTest, DuplicateNonIPAddressNotAllowed) {
@@ -278,7 +280,9 @@ name: bar
278
280
addOrUpdateListener (parseListenerFromV3Yaml (yaml1));
279
281
EXPECT_THROW_WITH_MESSAGE (
280
282
addOrUpdateListener (parseListenerFromV3Yaml (yaml2)), EnvoyException,
281
- " error adding listener: 'bar' has duplicate address '/path' as existing listener" );
283
+ " error adding listener: 'bar' has duplicate address '/path' as existing listener, to check "
284
+ " if the listener has duplicated addresses with other listeners or 'enable_reuse_port' is set "
285
+ " to 'false' for the listener" );
282
286
}
283
287
284
288
TEST_P (ListenerManagerImplWithRealFiltersTest, MultipleAddressesDuplicatePortNotAllowed) {
@@ -318,7 +322,9 @@ name: bar
318
322
addOrUpdateListener (parseListenerFromV3Yaml (yaml1));
319
323
EXPECT_THROW_WITH_MESSAGE (addOrUpdateListener (parseListenerFromV3Yaml (yaml2)), EnvoyException,
320
324
" error adding listener: 'bar' has duplicate address "
321
- " '127.0.0.1:1234,127.0.0.3:1234' as existing listener" );
325
+ " '127.0.0.1:1234,127.0.0.3:1234' as existing listener, to check if the "
326
+ " listener has duplicated addresses with other listeners or "
327
+ " 'enable_reuse_port' is set to 'false' for the listener" );
322
328
}
323
329
324
330
TEST_P (ListenerManagerImplWithRealFiltersTest,
@@ -358,9 +364,11 @@ bind_to_port: false
358
364
)EOF" ;
359
365
360
366
addOrUpdateListener (parseListenerFromV3Yaml (yaml1));
361
- EXPECT_THROW_WITH_MESSAGE (addOrUpdateListener (parseListenerFromV3Yaml (yaml2)), EnvoyException,
362
- " error adding listener: 'bar' has duplicate address "
363
- " '127.0.0.1:0,127.0.0.3:0' as existing listener" );
367
+ EXPECT_THROW_WITH_MESSAGE (
368
+ addOrUpdateListener (parseListenerFromV3Yaml (yaml2)), EnvoyException,
369
+ " error adding listener: 'bar' has duplicate address "
370
+ " '127.0.0.1:0,127.0.0.3:0' as existing listener, to check if the listener has duplicated "
371
+ " addresses with other listeners or 'enable_reuse_port' is set to 'false' for the listener" );
364
372
}
365
373
366
374
TEST_P (ListenerManagerImplWithRealFiltersTest, AllowCreateListenerWithMutipleZeroPorts) {
@@ -402,6 +410,98 @@ name: bar
402
410
addOrUpdateListener (parseListenerFromV3Yaml (yaml2));
403
411
}
404
412
413
+ TEST_P (ListenerManagerImplWithRealFiltersTest, AllowAddressesUpdatePartially) {
414
+ // Update one of the addresses from '127.0.0.2:1000' to '127.0.0.3:2000'.
415
+ const std::string yaml1 = R"EOF(
416
+ name: foo
417
+ address:
418
+ socket_address:
419
+ address: 127.0.0.1
420
+ port_value: 1000
421
+ additional_addresses:
422
+ - address:
423
+ socket_address:
424
+ address: 127.0.0.2
425
+ port_value: 1000
426
+ filter_chains:
427
+ - filters: []
428
+ name: foo
429
+ )EOF" ;
430
+
431
+ const std::string yaml2 = R"EOF(
432
+ name: foo
433
+ address:
434
+ socket_address:
435
+ address: 127.0.0.1
436
+ port_value: 1000
437
+ additional_addresses:
438
+ - address:
439
+ socket_address:
440
+ address: 127.0.0.3
441
+ port_value: 2000
442
+ filter_chains:
443
+ - filters: []
444
+ name: foo
445
+ )EOF" ;
446
+
447
+ EXPECT_CALL (listener_factory_, createListenSocket (_, _, _, default_bind_type, _, 0 )).Times (2 );
448
+ addOrUpdateListener (parseListenerFromV3Yaml (yaml1));
449
+ EXPECT_CALL (listener_factory_, createListenSocket (_, _, _, default_bind_type, _, 0 )).Times (2 );
450
+ addOrUpdateListener (parseListenerFromV3Yaml (yaml2));
451
+ }
452
+
453
+ TEST_P (ListenerManagerImplWithRealFiltersTest,
454
+ AllowUpdateSocketOptionsIfNotDuplicatedEvenReusePortIsDisabled) {
455
+ // All addresses are different, so it should be allowed to update socket options even
456
+ // reuse port is disabled.
457
+ const std::string yaml1 = R"EOF(
458
+ name: foo
459
+ address:
460
+ socket_address:
461
+ address: 127.0.0.1
462
+ port_value: 1000
463
+ additional_addresses:
464
+ - address:
465
+ socket_address:
466
+ address: 127.0.0.2
467
+ port_value: 1000
468
+ enable_reuse_port: false
469
+ filter_chains:
470
+ - filters: []
471
+ name: foo
472
+ )EOF" ;
473
+
474
+ const std::string yaml2 = R"EOF(
475
+ name: foo
476
+ address:
477
+ socket_address:
478
+ address: 127.0.0.4
479
+ port_value: 1000
480
+ additional_addresses:
481
+ - address:
482
+ socket_address:
483
+ address: 127.0.0.3
484
+ port_value: 2000
485
+ enable_reuse_port: false
486
+ socket_options:
487
+ - level: 1
488
+ name: 9
489
+ int_value: 1
490
+ filter_chains:
491
+ - filters: []
492
+ name: foo
493
+ )EOF" ;
494
+
495
+ EXPECT_CALL (listener_factory_,
496
+ createListenSocket (_, _, _, ListenerComponentFactory::BindType::NoReusePort, _, 0 ))
497
+ .Times (2 );
498
+ addOrUpdateListener (parseListenerFromV3Yaml (yaml1));
499
+ EXPECT_CALL (listener_factory_,
500
+ createListenSocket (_, _, _, ListenerComponentFactory::BindType::NoReusePort, _, 0 ))
501
+ .Times (2 );
502
+ addOrUpdateListener (parseListenerFromV3Yaml (yaml2));
503
+ }
504
+
405
505
TEST_P (ListenerManagerImplWithRealFiltersTest, SetListenerPerConnectionBufferLimit) {
406
506
const std::string yaml = R"EOF(
407
507
address:
@@ -2298,7 +2398,9 @@ name: bar
2298
2398
)EOF" ;
2299
2399
2300
2400
const std::string expected_error_message =
2301
- " error adding listener: 'bar' has duplicate address '127.0.0.1:1234' as existing listener" ;
2401
+ " error adding listener: 'bar' has duplicate address '127.0.0.1:1234' as existing listener, "
2402
+ " to check if the listener has duplicated addresses with other listeners or "
2403
+ " 'enable_reuse_port' is set to 'false' for the listener" ;
2302
2404
testListenerUpdateWithSocketOptionsChangeRejected (listener_origin, listener_updated,
2303
2405
expected_error_message);
2304
2406
}
@@ -3343,7 +3445,9 @@ bind_to_port: false
3343
3445
EXPECT_CALL (*listener_bar, onDestroy ());
3344
3446
EXPECT_THROW_WITH_MESSAGE (
3345
3447
addOrUpdateListener (parseListenerFromV3Yaml (listener_bar_yaml)), EnvoyException,
3346
- " error adding listener: 'bar' has duplicate address '0.0.0.0:1234' as existing listener" );
3448
+ " error adding listener: 'bar' has duplicate address '0.0.0.0:1234' as existing listener, to "
3449
+ " check if the listener has duplicated addresses with other listeners or 'enable_reuse_port' "
3450
+ " is set to 'false' for the listener" );
3347
3451
3348
3452
// Move foo to active and then try to add again. This should still fail.
3349
3453
EXPECT_CALL (*worker_, addListener (_, _, _, _, _));
@@ -3354,7 +3458,9 @@ bind_to_port: false
3354
3458
EXPECT_CALL (*listener_bar, onDestroy ());
3355
3459
EXPECT_THROW_WITH_MESSAGE (
3356
3460
addOrUpdateListener (parseListenerFromV3Yaml (listener_bar_yaml)), EnvoyException,
3357
- " error adding listener: 'bar' has duplicate address '0.0.0.0:1234' as existing listener" );
3461
+ " error adding listener: 'bar' has duplicate address '0.0.0.0:1234' as existing listener, to "
3462
+ " check if the listener has duplicated addresses with other listeners or 'enable_reuse_port' "
3463
+ " is set to 'false' for the listener" );
3358
3464
3359
3465
EXPECT_CALL (*listener_foo, onDestroy ());
3360
3466
}
0 commit comments