-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gradually increase TCP ports up to 1024 (#16)
- Set an high limit to TCP ports allocation (1024). - Deallocate the predefined TCP_PORTS_RANGE in create-module. - Dynamically allocate the TCP ports, up to 1024 limit. - Reuse previously allocated ports for existing installations. Refs NethServer/dev#7102
- Loading branch information
1 parent
b205f20
commit cabd003
Showing
4 changed files
with
68 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2024 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
import agent | ||
|
||
# Clean-up the initial TCP ports allocation | ||
agent.deallocate_ports("tcp") | ||
agent.unset_env("TCP_PORT") | ||
agent.unset_env("TCP_PORTS") | ||
agent.unset_env("TCP_PORTS_RANGE") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# | ||
# Copyright (C) 2024 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
# | ||
|
||
import agent | ||
import sys | ||
import os | ||
|
||
if not 'TCP_PORTS' in os.environ: | ||
sys.exit(0) | ||
|
||
agent_id = os.environ['AGENT_ID'] | ||
rdb = agent.redis_connect(privileged=True) | ||
domain_port = rdb.hgetall(f'{agent_id}/data/domain_port') | ||
|
||
# Versions up to 1.0.2 have a fixed range of 8 ports allocated by the core | ||
# when the module instance is created. They are listed in "TCP_PORTS" | ||
# environment variable. We consider unused ports as "released", so the | ||
# "allocate-ports" procedure can reuse them before asking for new ports to | ||
# the local node. | ||
unused_ports = set(os.environ['TCP_PORTS'].split(",")) - set(domain_port.values()) | ||
rdb.sadd(f'{agent_id}/data/released_ports', *unused_ports) | ||
|
||
agent.unset_env("TCP_PORT") | ||
agent.unset_env("TCP_PORTS") | ||
agent.unset_env("TCP_PORTS_RANGE") |