[packet_interface] Leave no room, instead of underflowing, on a small link

As in the other layers, addressing ports and fragmentation get no room
when max_packet_size is smaller than their header, and fragmentation
fails its setup instead of dividing by zero.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
clydebarrow
2026-10-20 08:41:59 +11:00
co-authored by Claude Opus 5.5
parent 592d1820ba
commit 13ec5f27e9
5 changed files with 30 additions and 2 deletions
@@ -191,4 +191,13 @@ TEST_F(BasicFragmentationTest, OversizedSingleFragmentDropped) {
EXPECT_EQ(received, std::vector<Packet>{Packet({1, 2, 3, 4})});
}
TEST_F(BasicFragmentationTest, LinkTooSmallFailsSetup) {
this->link_a.set_max_packet_size(BasicFragmentation::HEADER_SIZE);
BasicFragmentation fragmentation(&this->link_a, 100);
fragmentation.setup();
EXPECT_TRUE(fragmentation.is_failed());
Packet packet{1};
EXPECT_FALSE(fragmentation.send_to_interface(PacketBuffer(packet), {}));
}
} // namespace esphome::packet_interface::fragmentation_testing