Page MenuHomeFreeBSD

libifconfig: fix carp key configuration
ClosedPublic

Authored by kp on Apr 28 2023, 5:01 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, May 10, 9:26 PM
Unknown Object (File)
Mar 22 2024, 3:12 PM
Unknown Object (File)
Mar 22 2024, 3:02 PM
Unknown Object (File)
Mar 22 2024, 10:00 AM
Unknown Object (File)
Mar 22 2024, 10:00 AM
Unknown Object (File)
Mar 8 2024, 7:48 AM
Unknown Object (File)
Dec 20 2023, 7:05 AM
Unknown Object (File)
Dec 2 2023, 10:21 PM
Subscribers

Details

Summary

There were two issues with the carp key configuration in the new netlink
code.

The first is that userspace failed to actually pass the CARP_NL_KEY
attribute to the kernel, so a key was never set.

The second issue is that snl_attr_get_string() returns a pointer to the
string inside the netlink message. It does not copy the string to the
target buffer. That's somewhat inconvenient to work with in libifconfig
where we have a static buffer for the key.
Introduce snl_attr_cpy_string() which can copy a string to a target
buffer and uses the 'arg' parameter to pass the buffer size, so it
doesn't accidentally exceed the available space.

Sponsored by: Rubicon Communications, LLC ("Netgate")

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kp requested review of this revision.Apr 28 2023, 5:01 PM
melifaro added inline comments.
lib/libifconfig/libifconfig_carp.c
58

Nit: maybe it's worth having an anonymous union of arg, so one can use arg_u32 or something like that.

sys/netlink/netlink_snl.h
597

I'd rather spell it snl_attr_cpy_string() to make it easier to remember

600–609

Nit: probably it has the same readability, but is a bit shorter. Not insisting on this version, though.

This revision is now accepted and ready to land.Apr 30 2023, 9:38 AM
lib/libifconfig/libifconfig_carp.c
58

Good idea. I'll work up an update with that change.

sys/netlink/netlink_snl.h
597

Did you mean snl_attr_copy_string()?

600–609

Nit: probably it has the same readability, but is a bit shorter. Not insisting on this version, though.

I tend to default to the error out early because it tends to reduce nesting. It's more obvious if there are multiple checks though. For one there's not much difference either way.

  • add a union for the argument I've chosen to only add arg_u32 rather than guess at what others would be useful.
  • rename (cpy -> copy)
This revision now requires review to proceed.Apr 30 2023, 11:09 AM
This revision is now accepted and ready to land.Apr 30 2023, 1:19 PM
This revision was automatically updated to reflect the committed changes.