Skip to content

*: consolidate sockopt_ apis in sockopt.c module - #21746

Merged
donaldsharp merged 1 commit into
FRRouting:masterfrom
mjstapp:move_sockopt_apis
Apr 28, 2026
Merged

*: consolidate sockopt_ apis in sockopt.c module#21746
donaldsharp merged 1 commit into
FRRouting:masterfrom
mjstapp:move_sockopt_apis

Conversation

@mjstapp

@mjstapp mjstapp commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Several sockopt_xxx apis were in the sockunion module - move them into the sockopt module and header.

@greptile-apps

greptile-apps Bot commented Apr 22, 2026

Copy link
Copy Markdown

Greptile Summary

This PR relocates five socket-option helpers (sockopt_reuseaddr, sockopt_reuseport, sockopt_ttl, sockopt_minttl, sockopt_v6only) from lib/sockunion.{c,h} into the more appropriate lib/sockopt.{c,h} module, and updates three call sites accordingly. The move is purely mechanical β€” no logic changes β€” and all sockunion_* symbols remain reachable at the affected call sites because lib/sockopt.h itself includes sockunion.h, and prefix.h (included everywhere) also pulls in sockunion.h transitively.

Confidence Score: 5/5

Safe to merge β€” purely a code-move refactor with no functional changes; both findings are minor style issues.

All remaining comments are P2 (a misleading #endif comment and an inconsistent include path). No logic was altered; transitive include analysis confirms no broken symbols at any call site.

lib/sockopt.c (misleading #endif /* 0 */ comment) and ospfd/ospf_apiserver.c (lib/ prefix inconsistency).

Important Files Changed

Filename Overview
lib/sockopt.c Receives moved implementations of sockopt_reuseaddr, sockopt_reuseport, sockopt_ttl, sockopt_minttl, and sockopt_v6only; logic is identical to the removed sockunion.c code, but the #endif comment for SO_REUSEPORT is incorrectly labeled /* 0 */.
lib/sockopt.h Adds declarations for the five moved sockopt functions; change is straightforward and correct.
lib/sockunion.c Removes the five sockopt_* function implementations; no other logic is affected.
lib/sockunion.h Removes declarations for the five moved sockopt functions; callers now get them from sockopt.h, which is already included (directly or transitively) everywhere they're used.
ospfd/ospf_apiserver.c Replaces sockunion.h with lib/sockopt.h; all sockunion_* symbols remain available via prefix.h→sockunion.h, but the new include uses the lib/ prefix inconsistently with all other headers in the file.
bgpd/bgp_bmp.c Replaces sockunion.h with sockopt.h; all sockunion_* symbols remain available transitively through prefix.h; include style matches the rest of the file.
bfdd/dplane.c Adds lib/sockopt.h so the direct call to sockopt_reuseaddr now has an explicit, correct declaration source; consistent with the lib/ prefix pattern used by other includes in this file.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["sockopt_reuseaddr\nsockopt_reuseport\nsockopt_ttl\nsockopt_minttl\nsockopt_v6only"]

    subgraph Before
        S1["lib/sockunion.c\n(implementation)"]
        S2["lib/sockunion.h\n(declaration)"]
    end

    subgraph After
        T1["lib/sockopt.c\n(implementation)"]
        T2["lib/sockopt.h\n(declaration)"]
    end

    A -->|was in| Before
    A -->|moved to| After

    T2 -->|includes| SU["lib/sockunion.h\n(still available transitively)"]

    CALLERS["bfdd/dplane.c\nbgpd/bgp_bmp.c\nospfd/ospf_apiserver.c"] -->|now include| T2
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: ospfd/ospf_apiserver.c
Line: 24

Comment:
**Inconsistent include path style**

All other lib headers in this file are included without the `lib/` prefix (e.g. `"linklist.h"`, `"prefix.h"`, `"frrevent.h"`), but the newly-added include uses the full `"lib/sockopt.h"` form. This is inconsistent with the existing style in this file and should be `"sockopt.h"` to match.

```suggestion
#include "sockopt.h"
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: lib/sockopt.c
Line: 803

Comment:
**Misleading `#endif` comment**

The closing `#endif` comment says `/* 0 */`, which has no relation to the guarding `#ifdef SO_REUSEPORT` above it. This was copied as-is from `sockunion.c`, but now that this is the canonical location the comment should be corrected to reflect the actual macro name.

```suggestion
#endif /* SO_REUSEPORT */
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "*: consolidate sockopt_ apis in sockopt...." | Re-trigger Greptile

Comment thread ospfd/ospf_apiserver.c
#include "hash.h"
#include "sockunion.h" /* for inet_aton() */
#include "buffer.h"
#include "lib/sockopt.h"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Inconsistent include path style

All other lib headers in this file are included without the lib/ prefix (e.g. "linklist.h", "prefix.h", "frrevent.h"), but the newly-added include uses the full "lib/sockopt.h" form. This is inconsistent with the existing style in this file and should be "sockopt.h" to match.

Suggested change
#include "lib/sockopt.h"
#include "sockopt.h"
Prompt To Fix With AI
This is a comment left during a code review.
Path: ospfd/ospf_apiserver.c
Line: 24

Comment:
**Inconsistent include path style**

All other lib headers in this file are included without the `lib/` prefix (e.g. `"linklist.h"`, `"prefix.h"`, `"frrevent.h"`), but the newly-added include uses the full `"lib/sockopt.h"` form. This is inconsistent with the existing style in this file and should be `"sockopt.h"` to match.

```suggestion
#include "sockopt.h"
```

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment thread lib/sockopt.c

int sockopt_ttl(int family, int sock, int ttl)
{
int ret;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Misleading #endif comment

The closing #endif comment says /* 0 */, which has no relation to the guarding #ifdef SO_REUSEPORT above it. This was copied as-is from sockunion.c, but now that this is the canonical location the comment should be corrected to reflect the actual macro name.

Suggested change
int ret;
#endif /* SO_REUSEPORT */
Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/sockopt.c
Line: 803

Comment:
**Misleading `#endif` comment**

The closing `#endif` comment says `/* 0 */`, which has no relation to the guarding `#ifdef SO_REUSEPORT` above it. This was copied as-is from `sockunion.c`, but now that this is the canonical location the comment should be corrected to reflect the actual macro name.

```suggestion
#endif /* SO_REUSEPORT */
```

How can I resolve this? If you propose a fix, please make it concise.

Several sockopt_xxx apis were in sockunion - move them into
the sockopt module and header.

Signed-off-by: Mark Stapp <mjs@cisco.com>
@mjstapp
mjstapp force-pushed the move_sockopt_apis branch from 124aae4 to 4abc1b7 Compare April 22, 2026 20:59
@mjstapp

mjstapp commented Apr 22, 2026

Copy link
Copy Markdown
Contributor Author

pushed a fix for the checkpatch report

@rzalamena

Copy link
Copy Markdown
Member

@mjstapp please fix frrbot complaint and this is ready to go

@mjstapp

mjstapp commented Apr 24, 2026

Copy link
Copy Markdown
Contributor Author

@mjstapp please fix frrbot complaint and this is ready to go

all of those are the "100 columns" things that are still optional?

@donaldsharp
donaldsharp merged commit 8a6c2ad into FRRouting:master Apr 28, 2026
23 checks passed
@mjstapp
mjstapp deleted the move_sockopt_apis branch June 1, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants