Page MenuHomeFreeBSD

netlink: add snl(3) - simple netlink library
ClosedPublic

Authored by melifaro on Dec 18 2022, 5:35 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Feb 11, 5:02 PM
Unknown Object (File)
Sun, Feb 11, 5:02 PM
Unknown Object (File)
Jan 15 2024, 3:40 PM
Unknown Object (File)
Jan 5 2024, 1:17 PM
Unknown Object (File)
Dec 20 2023, 7:40 AM
Unknown Object (File)
Dec 17 2023, 12:10 PM
Unknown Object (File)
Dec 10 2023, 10:40 AM
Unknown Object (File)
Dec 2 2023, 12:15 PM

Details

Summary

Overview

With netlink landed. it is desired to have some netlink library in base, to simplify netlink interactions for both base and third-party applications.
There are the following goals:

  1. the library should be small and simple (inlined) so it can be used in the critical tools like route(8).
  2. the library should have a compatible license to be included in base
  3. there should be an easy way to push FreeBSD-specific changes to the library

The popular libraries like libnl or libml does not look positive when evaluating (2) and (3).

As a result, the snl(3) library is written to address all 3 requirements. De-facto it is a userland port of the sys/netlink/netlink_message_parser.[ch]

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 48752
Build 45638: arc lint + arc unit

Event Timeline

pauamma_gundo.com added inline comments.
share/man/man3/snl.3
97
98–99
101
108
111
119

Shouldn't the example declare ss somewhere?

Also noting that ss is a struct snl_state here but a struct snl_state * in function declarations above and below. This could confuse unwary readers.

124

(or "unique message numbers")

142

"XXX"?

143
158
160

Perhaps a reminder or a clarification of which values <type> can take?

164
166
169
170
172
173
175
179
181
184
188
199
201

Same question about listing values of <type> as above.

230

Unless my rusty C reading skills mislead me.

240–253

Is there a rule for the order in which declarations and statements can or should appear? Here I see a declaration, statements, another declaration, then more statements.

263

Should this be continue or break?

267

Same question.

274

Empty section?

286
This revision now requires changes to proceed.Dec 18 2022, 7:08 PM
lwhsu added inline comments.
share/man/man3/snl.3
124

"an" ?

share/man/man3/snl.3
124

"an" ?

https://www.merriam-webster.com/dictionary/unique says "a" in quoted examples, eg "a unique identifier".

melifaro marked 20 inline comments as done.
melifaro edited the summary of this revision. (Show Details)
  • Address comments.
  • Update snl(3) library.
share/man/man3/snl.3
119

I omitted it for brevity.
The full working example exists at the end of the man page.
Switched to ss instead of &ss, does it look better now?

240–253

IIRC relaxed style(9) rules some time ago -

Variables may be initialized where
    declared especially when they are constant for the rest of the scope.
    Declarations may be placed before executable lines at the start of any
    block.
263

Can be both. Maybe break is more logical here.

267

It depends on the app failure model - is partial failure okay (e.g. getting "some" result) or not.

Also: thank you for the review & feedback! It helps greatly.

Fixable on commit if there are no other changes.

share/man/man3/snl.3
119

Fair enough re brevity. And yes, it looks better to my no-longer-trained eye.

279

Missed it the first time.

This revision is now accepted and ready to land.Dec 20 2022, 12:34 AM
sys/netlink/netlink_snl.h
359

Isn't all the RT* things specific to netlink_route ? should snl impose the inclusion of netlink_route.h?

I manage to convert my code to use snl.h its ok for me.

Quick remarks, I plan to add snl_genl.h for genl specific case, would that be ok for you?
Doesn't the routing specific part needs to be moved to a snl_route.h?

melifaro marked 2 inline comments as done.

Add a bit more accessors.
Move NETLINK_ROUTE specific helpers to a separate file.
Update the manpage.

This revision now requires review to proceed.Dec 23 2022, 2:56 PM
In D37736#859376, @bapt wrote:

I manage to convert my code to use snl.h its ok for me.

Awesome!

Quick remarks, I plan to add snl_genl.h for genl specific case, would that be ok for you?

Of course.

Doesn't the routing specific part needs to be moved to a snl_route.h?

Yep, that makes sense. Moved to netlink_snl_route.h.

This revision was not accepted when it landed; it landed in state Needs Review.Dec 23 2022, 3:03 PM
This revision was automatically updated to reflect the committed changes.