Skip to content

Add remap command for TCP listen port remapping (Closes #169)#190

Open
UtkarshSingh-06 wants to merge 1 commit intocheckpoint-restore:mainfrom
UtkarshSingh-06:remap-tcp-listen-ports-169
Open

Add remap command for TCP listen port remapping (Closes #169)#190
UtkarshSingh-06 wants to merge 1 commit intocheckpoint-restore:mainfrom
UtkarshSingh-06:remap-tcp-listen-ports-169

Conversation

@UtkarshSingh-06
Copy link

Description

This PR implements the remapping of TCP listen ports in container checkpoint archives, addressing issue #169. This provides functionality similar to the --tcp-listen-remap\ option of \criu-image-streamer\ or the \edit_files_img.py\ script.

Changes

  • Added a new
    emap\ command to checkpointctl
  • Implemented \RemapTCPListenPorts\ function that:
    • Extracts \ iles.img\ from checkpoint archives
    • Parses \ iles.img\ to find TCP listen sockets (SOCK_STREAM, TCP protocol, LISTEN state)
    • Remaps source ports according to user-provided mappings
    • Repacks the modified \ iles.img\ back into the checkpoint archive
  • Implemented \RepackFileToArchive\ function to handle archive repacking with proper compression format preservation

Usage

The command accepts port mappings in the format \old_port:new_port:

\\�ash
checkpointctl remap checkpoint.tar --tcp-listen-remap 8080:80
\\

Multiple port mappings can be specified by separating them with commas:

\\�ash
checkpointctl remap checkpoint.tar --tcp-listen-remap 8080:80,8443:443
\\

Technical Details

  • Identifies TCP listen sockets by checking: \Proto == TCP (6), \Type == SOCK_STREAM (1), and \State == TCP_LISTEN (10)\
  • Modifies \InetSkEntry.SrcPort\ in \ iles.img\ entries
  • Uses go-criu library for decoding/encoding CRIU image files
  • Preserves archive compression format (tar.gz)

Related Issue

Closes #169

Testing

The implementation:

  • Validates port mappings (range 1-65535)
  • Handles multiple port mappings
  • Preserves all other checkpoint data
  • Maintains archive compression format

All code changes are well-documented with comments explaining the functionality.

This commit adds a new 'remap' command to checkpointctl that allows
remapping TCP listen ports in checkpoint archives. This addresses
issue checkpoint-restore#169 by providing functionality similar to --tcp-listen-remap
option of criu-image-streamer or edit_files_img.py script.

The implementation:
- Adds a new 'remap' command that accepts --tcp-listen-remap flag
- Extracts files.img from checkpoint archives
- Parses files.img to find TCP listen sockets (SOCK_STREAM, TCP_LISTEN state)
- Remaps the source port according to the provided mappings
- Repacks the modified files.img back into the checkpoint archive

Port mappings are specified in the format old_port:new_port, with
multiple mappings separated by commas.

Closes checkpoint-restore#169

Signed-off-by: UtkarshSingh-06 <[email protected]>
--tcp-listen-remap 8080:80,8443:443

Example:
checkpointctl remap checkpoint.tar --tcp-listen-remap 8080:80`,
Copy link
Member

@rst0git rst0git Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to use more generic command name. For example, something like the following:

checkpointctl edit --tcp-listen-remap 8080:80 checkpoint.tar

This will allow us to extend the "edit" functionality with other features in the future.

defer os.RemoveAll(tempDir)

// Extract entire archive
if err := extractArchive(archiveFile.Name(), tempDir); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In some cases, container checkpoints can be very large (>100 GB). Extracting the entire archive then recreating it again is not the best way of implementing this edit operation. Perhaps we can avoid both temporary storage requirements and unnecessary I/O by using a streaming tar reader/writer and replace the modified CRIU image on the fly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remapping of TCP listen ports

2 participants