Skip to content

Conversation

@jlucovsky
Copy link
Contributor

Continuation of #14426

Add a configuration option for outputting shortened IPv6 addresses per RFC-5952

The configuration option:
logging.ipv6-addr-shorten has a default value of no.

When set to yes, IPv6 addresses will be shortened everywhere they are output. E.g., the IPv6 address fe80:0000:0000:0000:020c:29ff:faf2:ab42 will be output as fe80::20c:29ff:faf2:ab42

Link to ticket: https://redmine.openinfosecfoundation.org/issues/7399

Describe changes:

  • Add a configuration variable for choosing shortened IPv6 IP addresses
  • Add Rust logic to create a shortened IPv6 address
  • Document changes and usage.

Updates:

  • Address Clippy issues
  • Renamed Rust function to conform to API-naming standard
  • Eliminated extra copy in Rust function
  • s-v test updates.
  • Removed commented-out line from Rust module; added copyright
  • Misc doc updates.
  • Rearranged copyright notice
  • Updated s-v test cases with min-version

Provide values to any of the below to override the defaults.

  • To use a Suricata-Verify or Suricata-Update pull request,
    link to the pull request in the respective _BRANCH variable.
  • Leave unused overrides blank or remove.

SV_REPO=
SV_BRANCH=OISF/suricata-verify#2789
SU_REPO=
SU_BRANCH=

Issue: 7399

Use shortened IPv6 addresses in all output when configured.

IPv6 addresses are shortened per RFC5952

By default, IPv6 addresses are never shortened; set
logging.ipv6-addr-shorten=yes to shorten.

Added Rust utility function to create shortened IPv6 address.
Document the configuration variable logging.ipv6-addr-shorten

Issue: 7399
@codecov
Copy link

codecov bot commented Dec 6, 2025

Codecov Report

❌ Patch coverage is 91.89189% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.18%. Comparing base (354e998) to head (0f4fc3c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14433      +/-   ##
==========================================
- Coverage   84.20%   84.18%   -0.03%     
==========================================
  Files        1013     1014       +1     
  Lines      262383   262420      +37     
==========================================
- Hits       220936   220913      -23     
- Misses      41447    41507      +60     
Flag Coverage Δ
fuzzcorpus 63.17% <8.10%> (-0.02%) ⬇️
livemode 18.77% <5.40%> (+0.02%) ⬆️
pcap 44.60% <8.10%> (-0.01%) ⬇️
suricata-verify 64.89% <91.89%> (-0.09%) ⬇️
unittests 59.23% <8.10%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline = 28610

Copy link
Contributor

@catenacyber catenacyber left a comment

Choose a reason for hiding this comment

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

Thanks for the work, fine enough for me, but some nits

CI : ✅
Code : good
Commits segmentation : I would squash but ok
Commit messages : good
Git ID set : looks fine for me
CLA : you already contributed
Doc update : looks nice
Redmine ticket : ok
Rustfmt : ⚠️ ip_addr.rs is not formatted according ot our rustfmt.toml
Tests : some remarks on SV there but ok
Dependencies added: none

pub unsafe extern "C" fn SCIPv6Shorten(
addr: *const c_uchar, // pointer to 16-byte IPv6
out_buf: *mut c_char, // out buffer allocated by caller
out_len: usize // size of out buffer
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a MAX_IP6_ADDRESS size ? If so, could we use it a fixed size array with it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Per RFC 8200, IP v6 address sizes are 128 bits.

A constant/define can be added -- do you think it'll aid readability?

Copy link
Contributor

Choose a reason for hiding this comment

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

here I meant the max size of a ip6 as a string


unsafe {
// get 16-byte IPv6 address
let bytes = std::slice::from_raw_parts(addr, 16);
Copy link
Contributor

Choose a reason for hiding this comment

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

could rename 16 to IP6_ADDR_SIZE or similar

// Convert &[u8] → Ipv6Addr
let ipv6 = match <&[u8; 16]>::try_from(bytes) {
Ok(b) => Ipv6Addr::from(*b),
Err(_) => return 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

When can this fail ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It cannot fail, according to the documentation, as it will always generate a result based on the 16-byte bit pattern it's presented with

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there not a method that does not return a Result ?


// Sufficient room?
if ipv6_str.len() + 1 > out_len {
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ we always return 0 ! we should differentiate

Copy link
Contributor

Choose a reason for hiding this comment

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

for both success and failure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will modify to return 0 on error and the actual length on success.

Copy link
Contributor

@catenacyber catenacyber left a comment

Choose a reason for hiding this comment

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

SCIPv6Shorten always returns 0 for both failure and success

Guess this underlines lack of test or unreachable code...

@jlucovsky
Copy link
Contributor Author

SCIPv6Shorten always returns 0 for both failure and success

Guess this underlines lack of test or unreachable code...

I'll add some test cases.

@jlucovsky
Copy link
Contributor Author

Continued in #14449

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants