Skip to content

lib: optional binding IP support for gRPC server - #23297

Open
PalSubham wants to merge 5 commits into
FRRouting:masterfrom
PalSubham:grpc-ip-support
Open

lib: optional binding IP support for gRPC server#23297
PalSubham wants to merge 5 commits into
FRRouting:masterfrom
PalSubham:grpc-ip-support

Conversation

@PalSubham

@PalSubham PalSubham commented Sep 9, 2026

Copy link
Copy Markdown

Usage

Binding IP can be configured in daemons file for individual daemon options using -M grpc:<IP>:<port>.
This is fully backward compatible with port-only config.

Changes

Instead of directly using std::stoul on the argument, it is divided into two parts at last occuring ":" character, given it is present. Default IP is same as 0.0.0.0.
Inside frr_grpc_init, the combined data is stored as fields of a struct whose pointer is placed in fpt->data.
This is used in AddListeningPort method of grpc::ServerBuilder inside grpc_pthread_start while building grpc::Server.

Resolves

Resolves #23294

@greptile-apps

greptile-apps Bot commented Sep 9, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds an optional host component to the gRPC module argument and passes the parsed host and port to the server thread.

  • Introduces a grpc_args structure for thread startup data.
  • Parses both legacy port-only and new host-and-port configurations.
  • Builds the gRPC listening endpoint from the configured host and port.
  • The startup routine currently reads the port from the structure pointer rather than its port field, and IPv6 endpoint formatting is incomplete.

Confidence Score: 3/5

This PR is not safe to merge because the configured gRPC port is discarded at runtime and IPv6 binding input cannot be emitted as a valid endpoint.

The new thread-data representation is incompatible with the retained pointer-to-integer port read, so both default and explicitly configured servers generally bind incorrectly or fail to start; IPv6 host formatting introduces another startup failure path.

Files Needing Attention: lib/northbound_grpc.cpp

Important Files Changed

Filename Overview
lib/northbound_grpc.cpp Adds configurable gRPC binding hosts, but currently derives the listening port from a pointer, mishandles ordinary IPv6 input, and leaves new startup data unowned.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A["-M grpc:[host:]port"] --> B["Parse host and port"]
  B --> C["Allocate grpc_args"]
  C --> D["Store pointer in fpt->data"]
  D --> E["grpc_pthread_start"]
  E --> F["Build host:port endpoint"]
  F --> G["ServerBuilder::AddListeningPort"]
  G --> H["gRPC server"]
Loading

Comments Outside Diff (1)

  1. lib/northbound_grpc.cpp, line 1276-1288 (link)

    P2 Thread Arguments Are Leaked

    The new grpc_args object remains caller-owned, but neither normal shutdown nor the frr_pthread_run failure path deletes it. Each init/finish cycle leaks this object, and a startup failure also leaves the newly registered frr_pthread undisposed, causing stale allocations to accumulate.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: lib/northbound_grpc.cpp
    Line: 1276-1288
    
    Comment:
    **Thread Arguments Are Leaked**
    
    The new `grpc_args` object remains caller-owned, but neither normal shutdown nor the `frr_pthread_run` failure path deletes it. Each init/finish cycle leaks this object, and a startup failure also leaves the newly registered `frr_pthread` undisposed, causing stale allocations to accumulate.
    
    ---
    
    For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Prompt To Fix All With AI
### Issue 1
lib/northbound_grpc.cpp:1147
**Port Read From Pointer**

`fpt->data` now points to a `grpc_args`, but this line still converts the pointer itself into the port number instead of reading `args->port`. As a result, every configuration discards the validated or default port and attempts to bind using a truncated heap address, leaving gRPC unavailable on the configured endpoint or potentially listening on an unintended port.

```suggestion
	uint port = args->port;
```

### Issue 2
lib/northbound_grpc.cpp:1156
**IPv6 Endpoint Lacks Brackets**

For an IPv6 configuration such as `2001:db8::1:50051`, parsing yields the host `2001:db8::1`, but this code reconstructs the endpoint without the brackets required around an IPv6 address. gRPC therefore receives an invalid endpoint and the server cannot start for ordinary IPv6 binding input.

### Issue 3
lib/northbound_grpc.cpp:1276-1288
**Thread Arguments Are Leaked**

The new `grpc_args` object remains caller-owned, but neither normal shutdown nor the `frr_pthread_run` failure path deletes it. Each init/finish cycle leaks this object, and a startup failure also leaves the newly registered `frr_pthread` undisposed, causing stale allocations to accumulate.

### Issue 4
lib/northbound_grpc.cpp:1366
**Malformed Ports Pass Validation**

This parser narrows the result of `std::stoul` directly to `uint` and does not check whether the full suffix was consumed. Inputs such as `127.0.0.1:50051junk` are silently accepted, while sufficiently large values can wrap into the valid range before the bounds check, making invalid configurations appear valid.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "added optional binding IP support for gr..." | Re-trigger Greptile

Comment thread lib/northbound_grpc.cpp Outdated
Comment thread lib/northbound_grpc.cpp
Comment thread lib/northbound_grpc.cpp Outdated
@github-actions github-actions Bot added size/L and removed size/M labels Sep 9, 2026
@donaldsharp

Copy link
Copy Markdown
Member

please take a few minutes and familiarize yourself with the workflow.rst documentation and follow it for your submissions. This is a no go until this is fixed

@PalSubham

Copy link
Copy Markdown
Author

I read it. I'll fix the issues.

@PalSubham PalSubham changed the title Optional binding IP support for gRPC server lib: optional binding IP support for gRPC server Sep 10, 2026
Currently northbound grpc server only supports port.
Support optional binding IP while keeping it backward
compatible with port-only config.

Signed-off-by: Subham Pal <subhampal789@gmail.com>
Add IPv6 validation along with IPv4 for grpc server.
Also, fix memory leakage of the newly added `grpc_args`
structure pointer for holding (IP, port) pair.

Signed-off-by: Subham Pal <subhampal789@gmail.com>
Remove a trailing whitespace as suggested
by pipeline validator.

Signed-off-by: Subham Pal <subhampal789@gmail.com>
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.

lib: northbound gRPC lacks the feature to mention binding IP

2 participants