Skip to content

Conversation

@kaey
Copy link

@kaey kaey commented Nov 22, 2025

Summary by CodeRabbit

  • New Features
    • Added support for three additional SEG6 encapsulation modes.
    • Added functionality to encode Segment Routing Headers for network segments.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Nov 22, 2025

Walkthrough

Added three new SEG6 encapsulation mode constants (L2ENCAP, ENCAP_RED, L2ENCAP_RED) and introduced the EncodeSEG6Srh function to encode Segment Routing Headers for IP segments. Extended SEG6EncapModeString to handle the new modes.

Changes

Cohort / File(s) Summary
SEG6 Encapsulation Modes and Encoding
nl/seg6_linux.go
Added three new enumeration constants for seg6 encap modes (L2ENCAP, ENCAP_RED, L2ENCAP_RED); introduced EncodeSEG6Srh function to encode Segment Routing Headers with segment validation; extended SEG6EncapModeString to support string representations of the new modes

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • EncodeSEG6Srh function: Verify validation logic for non-empty input and SRH payload construction correctness
  • Constant definitions: Confirm values align with kernel definitions and existing SEG6_IPTUN_MODE_\* pattern
  • SEG6EncapModeString extension: Ensure string mappings ("l2encap", "encap.red", "l2encap.red") are accurate

Poem

🐰 Three modes hopping in with care,
L2ENCAP, RED in the air,
SRH headers now encode,
Along the segment routing road,
Rabbit's gift to routes so fair! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'add more srv6 encap mode consts' accurately describes the main change: adding new SRV6/SEG6 encapsulation mode constants and related functionality to the codebase.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
nl/seg6_linux.go (1)

130-149: Consider refactoring to eliminate code duplication.

The function logic is correct and consistent with EncodeSEG6Encap. However, the SRH encoding logic (lines 137-148) is duplicated from EncodeSEG6Encap (lines 69-79). Consider refactoring EncodeSEG6Encap to call EncodeSEG6Srh and prepend the mode bytes, reducing maintenance burden.

Example refactor for EncodeSEG6Encap:

 func EncodeSEG6Encap(mode int, segments []net.IP) ([]byte, error) {
-	nsegs := len(segments) // nsegs: number of segments
-	if nsegs == 0 {
+	srh, err := EncodeSEG6Srh(segments)
+	if err != nil {
-		return nil, errors.New("EncodeSEG6Encap: No Segment in srh")
+		return nil, err
 	}
-	b := make([]byte, 12, 12+len(segments)*16)
+	b := make([]byte, 4, 4+len(srh))
 	native := NativeEndian()
 	native.PutUint32(b, uint32(mode))
-	b[4] = 0                      // srh.nextHdr (0 when calling netlink)
-	b[5] = uint8(16 * nsegs >> 3) // srh.hdrLen (in 8-octets unit)
-	b[6] = IPV6_SRCRT_TYPE_4      // srh.routingType (assigned by IANA)
-	b[7] = uint8(nsegs - 1)       // srh.segmentsLeft
-	b[8] = uint8(nsegs - 1)       // srh.firstSegment
-	b[9] = 0                      // srh.flags (SR6_FLAG1_HMAC for srh_hmac)
-	// srh.reserved: Defined as "Tag" in draft-ietf-6man-segment-routing-header-07
-	native.PutUint16(b[10:], 0) // srh.reserved
-	for _, netIP := range segments {
-		b = append(b, netIP...) // srh.Segments
-	}
+	b = append(b, srh...)
 	return b, nil
 }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6e61cd4 and 2f6addb.

📒 Files selected for processing (1)
  • nl/seg6_linux.go (4 hunks)
🔇 Additional comments (2)
nl/seg6_linux.go (2)

158-163: Implementation verified and correct.

The string representations ("l2encap", "encap.red", "l2encap.red") match the iproute2 format for SEG6 encapsulation modes, confirming the implementation is correct.


40-47: Based on my verification through the Linux kernel source code, the kernel's net/ipv6/seg6_iptunnel.c uses all five modes in switch statements: SEG6_IPTUN_MODE_INLINE, SEG6_IPTUN_MODE_ENCAP, SEG6_IPTUN_MODE_ENCAP_RED, SEG6_IPTUN_MODE_L2ENCAP, and SEG6_IPTUN_MODE_L2ENCAP_RED. This confirms that all the constants you've defined are valid and exist in the kernel.

Your Go code correctly defines these constants using iota continuation, which assigns sequential values 0, 1, 2, 3, and 4 respectively. This matches the expected enumeration pattern for these tunnel modes.

No changes are needed to the constant definitions.

Copy link
Contributor

@akerouanton akerouanton left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +158 to +163
case SEG6_IPTUN_MODE_L2ENCAP:
return "l2encap"
case SEG6_IPTUN_MODE_ENCAP_RED:
return "encap.red"
case SEG6_IPTUN_MODE_L2ENCAP_RED:
return "l2encap.red"
Copy link
Contributor

Choose a reason for hiding this comment

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

These matches https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/tree/ip/iproute_lwtunnel.c?id=2a82227f984b3f97354e4a490d3f172eedf07f63#n133:

static const char *seg6_mode_types[] = {
	[SEG6_IPTUN_MODE_INLINE]	= "inline",
	[SEG6_IPTUN_MODE_ENCAP]		= "encap",
	[SEG6_IPTUN_MODE_L2ENCAP]	= "l2encap",
	[SEG6_IPTUN_MODE_ENCAP_RED]	= "encap.red",
	[SEG6_IPTUN_MODE_L2ENCAP_RED]	= "l2encap.red",
};

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.

2 participants