zhhyu7 opened a new pull request, #22593:
URL: https://github.com/apache/nuttx/pull/22593
## Summary
A CAN gateway rule could be added and removed, but not turned off: to stop
forwarding for a while a client had to delete the rule and build it again,
which loses the rule and races with the frames in flight.
Carry the state in the rule instead. `CGW_FLAGS_CAN_DISABLED` is a new flag
of
`struct rtcanmsg`, and `can_forward()` skips a rule that has it, so a
disabled
rule stays on the list and forwards nothing.
The request reuses `RTM_NEWROUTE` with `NLM_F_REPLACE`, which is what that
flag
means, rather than a new message type that could collide with a Linux one.
`netlink_modify_can_route()` applies the flag to the rules that `CGW_FILTER`
and
`CGW_DST_IF` select, or to every rule of the device when neither is given,
and
reports `ENOENT` when nothing matched. Only the `CGW_FLAGS_CAN_DISABLED` bit
is
taken from the request, so the other flags of a rule are left alone.
## Impact
New feature: yes, enabling and disabling a CAN gateway rule over rtnetlink.
A client that does not send `NLM_F_REPLACE` sees no change.
Impacted area: `net/netlink` (rtnetlink CAN routes), `net/netforward`
(`CONFIG_NET_CANFORWARD`). No change to a configuration that leaves
`CONFIG_NET_CANFORWARD` off.
User impact: none for existing users; `CGW_FLAGS_CAN_DISABLED` is a new bit
in
the flags of `struct rtcanmsg`, which was previously unused.
## Testing
Built and run on the simulator with two vcan interfaces on the host
(`ip link add dev can0 type vcan`, same for `can1`).
Test program: a raw netlink client that sends each request and reports the
result of `sendto()` together with the ACK. The enable/disable section
(section 6) is new in this PR; sections 1 to 5 cover the rule add and remove
that is already upstream.
```
--- 6. disable and enable a rule ---
CGW add id=0x321 send=0 ACK=0
add a rule to toggle got=0 want=0 PASS
CGW disable id=0x321 send=0 ACK=0
disable the matching rule got=0 want=0 PASS
CGW enable id=0x321 send=0 ACK=0
enable it again got=0 want=0 PASS
CGW disable id=0x999 (no match) send=-2 ACK=-2
disable a rule that is not there got=-2 want=-2 PASS
CGW disable every rule send=0 ACK=0
disable all rules got=0 want=0 PASS
CGW flush send=0 ACK=0
a disabled rule can still be removed got=0 want=0 PASS
CGW disable on an empty list send=-2 ACK=0
disable with no rules left got=0 want=-2 FAIL
```
Every request returns what it should, which the `send=` column shows.
The `FAIL` on the last line is **not caused by this change**: the ACK column
is
one reply behind from section 3 onwards, because a successful CAN route
request
now gets two ACKs. `netlink_sendmsg()` sends one since commit 03cd1dee7e0
("net/netlink: Answer a request with `NLM_F_ACK`"), and
`netlink_route.c:2230`/`:2251` still send their own through
`netlink_can_ack()`. The duplicate predates this PR and will be fixed
separately.
Builds, `sim:dynconns`:
| `CONFIG_NET_CANFORWARD` | `CONFIG_NETLINK_DISABLE_NEWROUTE` | result |
| --- | --- | --- |
| n | n | 0 errors |
| y | n | 0 errors |
| y | y | 0 errors |
`./tools/checkpatch.sh -c -u -m -g` passes on the commit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]