Skip to content

fix(cpworker): keep the packet direction in the gre key when service_tag is unset - #317

Merged
timmy21 merged 1 commit into
0.9.xfrom
fix/296-gre-key-direction
Oct 13, 2026
Merged

timmy21 merged 1 commit into
0.9.xfrom
fix/296-gre-key-direction

Conversation

@timmy21

@timmy21 timmy21 commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Problem

The GRE output writes the packet direction into the high 4 bits of the GRE key: service_tag | (direction << 28). Without a configured gre.service_tag, cpworker used 0xFFFFFFFF, whose high nibble already fills the direction bits, so every packet was sent with key 0xFFFFFFFF whatever its direction.

cpdaemon produces this config for every CPM GRE strategy where "enable service tag" is off (Gre.ServiceTag is nil and omitted), so with a req_pattern the request/response marking was lost for all mirrored traffic. A configured tag above 28 bits overlapped the direction bits the same way; the CPM UI limits the tag to 0-4095, but cpdaemon and cpworker accept up to 32 bits.

Change

  • The default gre.service_tag is 0x0FFFFFFF instead of 0xFFFFFFFF.
  • The key takes the low 28 bits of the tag: (service_tag & 0x0FFFFFFF) | (direction << 28). A tag above 28 bits is still accepted with a warning that names the value carried in the key.
  • Without a service tag, the key is 0x0FFFFFFF / 0x1FFFFFFF / 0x2FFFFFFF (none / request / response) instead of 0xFFFFFFFF. Receivers that read the tag as key & 0x0FFFFFFF see the same 0xFFFFFFF as before.
  • USAGE-CPWORKER (en, zh-Hans) documents the default, the GRE header and the key layout.

Tests

  • config_validation: test_gre_service_tag_default expects 0x0FFFFFFF. Failed before the change (Was 0xFFFFFFFF).
  • TestWireFormat/gre: keys without a service_tag in all three directions, and tag 0xF0000123 with a req_pattern. Failed before the change (keys ffffffff and f0000123).
  • Run in Ubuntu 24.04: clang-format, build, make test 12/12, run_test.sh all ok.

Fixes #296

…tag is unset

The GRE key is service_tag | (direction << 28). Without a configured
service_tag, cpworker used 0xFFFFFFFF, whose high nibble already fills the
direction bits, so every packet carried key 0xFFFFFFFF whatever its
direction. cpdaemon produces this config for every CPM GRE strategy without
a service tag, so the request/response marking from req_pattern was lost.
A configured tag above 28 bits overlapped the direction bits the same way.

The default service_tag is now 0x0FFFFFFF, and the key takes only the low
28 bits of the tag: (service_tag & 0x0FFFFFFF) | (direction << 28). Without
a service tag, the key is 0x0FFFFFFF / 0x1FFFFFFF / 0x2FFFFFFF instead of
0xFFFFFFFF; receivers reading the tag as key & 0x0FFFFFFF see the same
0xFFFFFFF as before. USAGE-CPWORKER documents the GRE header and key layout.

Tests: config_validation expects the 0x0FFFFFFF default; TestWireFormat/gre
checks the key without a service_tag in all three directions and with a
tag above 28 bits. Both failed before the change.
@timmy21
timmy21 merged commit a02be2a into 0.9.x Oct 13, 2026
1 check passed
@timmy21
timmy21 deleted the fix/296-gre-key-direction branch October 13, 2026 10:23
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.

cpworker: GRE output loses the packet direction when service_tag is unset (default 0xFFFFFFFF fills the direction bits)

1 participant