Skip to content

Commit

Permalink
listener: allow rebuild listener if the num of addresses are not chan…
Browse files Browse the repository at this point in the history
…ged but values are changed

Signed-off-by: Rei Shimizu <[email protected]>
  • Loading branch information
Shikugawa committed Feb 25, 2025
1 parent 0b83af5 commit 6d642fc
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
10 changes: 2 additions & 8 deletions source/common/listener_manager/listener_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,8 @@ bool ListenerImpl::socketOptionsEqual(const ListenerImpl& other) const {
}

bool ListenerImpl::hasCompatibleAddress(const ListenerImpl& other) const {
if ((socket_type_ != other.socket_type_) || (addresses_.size() != other.addresses().size())) {
if ((socket_type_ != other.socket_type_) || (addresses_.size() != other.addresses().size()) ||
!ListenerMessageUtil::socketOptionsEqual(config(), other.config())) {
return false;
}

Expand All @@ -1157,13 +1158,6 @@ bool ListenerImpl::hasCompatibleAddress(const ListenerImpl& other) const {
}

bool ListenerImpl::hasDuplicatedAddress(const ListenerImpl& other) const {
// Skip the duplicate address check if this is the case of a listener update with new socket
// options.
if ((name_ == other.name_) &&
!ListenerMessageUtil::socketOptionsEqual(config(), other.config())) {
return false;
}

if (socket_type_ != other.socket_type_) {
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions source/common/listener_manager/listener_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,11 @@ absl::StatusOr<bool> ListenerManagerImpl::addOrUpdateListenerInternal(
bool ListenerManagerImpl::hasListenerWithDuplicatedAddress(const ListenerList& list,
const ListenerImpl& listener) {
for (const auto& existing_listener : list) {
// Skip if the listener is the same. It's because that the listener
// with same name was proven to be incompatible.
if (existing_listener->name() == listener.name()) {
continue;
}
if (existing_listener->hasDuplicatedAddress(listener)) {
return true;
}
Expand Down
40 changes: 40 additions & 0 deletions test/common/listener_manager/listener_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,46 @@ name: bar
addOrUpdateListener(parseListenerFromV3Yaml(yaml2));
}

TEST_P(ListenerManagerImplWithRealFiltersTest,
AllowUpdateListenerWithSameNumberPortsButPortNumberChanged) {
const std::string yaml1 = R"EOF(
name: foo
address:
socket_address:
address: 127.0.0.1
port_value: 1000
additional_addresses:
- address:
socket_address:
address: 127.0.0.2
port_value: 1000
filter_chains:
- filters: []
name: foo
)EOF";

const std::string yaml2 = R"EOF(
name: foo
address:
socket_address:
address: 127.0.0.1
port_value: 1000
additional_addresses:
- address:
socket_address:
address: 127.0.0.2
port_value: 2000
filter_chains:
- filters: []
name: foo
)EOF";

EXPECT_CALL(listener_factory_, createListenSocket(_, _, _, default_bind_type, _, 0)).Times(2);
addOrUpdateListener(parseListenerFromV3Yaml(yaml1));
EXPECT_CALL(listener_factory_, createListenSocket(_, _, _, default_bind_type, _, 0)).Times(2);
addOrUpdateListener(parseListenerFromV3Yaml(yaml2));
}

TEST_P(ListenerManagerImplWithRealFiltersTest, SetListenerPerConnectionBufferLimit) {
const std::string yaml = R"EOF(
address:
Expand Down

0 comments on commit 6d642fc

Please sign in to comment.