Sharp send tableid for route - #20634
Conversation
Greptile OverviewGreptile SummaryAdded optional table ID parameter to sharpd route install/remove commands, allowing routes to be installed into specific routing tables. Added Key changes:
Issues from previous review threads:
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant VTY as sharp_vty.c
participant Helper as sharp_zebra.c
participant Zebra as zebra daemon
Note over User,Zebra: Install routes with table ID
User->>VTY: sharp install routes ... table 100
VTY->>VTY: Set sg.r.tableid=100, tableid_set=true
VTY->>Helper: sharp_install_routes_helper(tableid, tableid_set)
Helper->>Helper: sharp_install_routes_restart()
loop For each route
Helper->>Helper: route_add(tableid, tableid_set)
Helper->>Helper: Set api.tableid, ZAPI_MESSAGE_TABLEID
Helper->>Zebra: ZEBRA_ROUTE_ADD with table ID
alt Buffer full
Helper->>Helper: Store state in wb (including tableid)
Zebra-->>Helper: Buffer ready callback
Helper->>Helper: Resume from wb state
end
end
Zebra-->>Helper: ZAPI_ROUTE_INSTALLED notifications
Note over User,Zebra: Remove routes with table ID
User->>VTY: sharp remove routes ... table 100
VTY->>VTY: Set sg.r.tableid=100, tableid_set=true
VTY->>Helper: sharp_remove_routes_helper(tableid, tableid_set)
Helper->>Helper: sharp_remove_routes_restart()
loop For each route
Helper->>Helper: route_delete(tableid, tableid_set)
Helper->>Helper: Set api.tableid, ZAPI_MESSAGE_TABLEID
Helper->>Zebra: ZEBRA_ROUTE_DELETE with table ID
end
Note over User,Zebra: Stop operation
User->>VTY: sharp install stop
VTY->>Helper: sharp_install_stop()
Helper->>Helper: Set stop_loop=true, clear INSTALL restart
Helper->>Helper: sharp_remove_routes_helper() to cleanup
|
| if (tableid_set) { | ||
| api.tableid = tableid; | ||
| SET_FLAG(api.flags, ZEBRA_FLAG_TABLEID); |
There was a problem hiding this comment.
Inconsistent flag usage with route_add(). In route_add() at line 257, you use SET_FLAG(api.message, ZAPI_MESSAGE_TABLEID), but here you use SET_FLAG(api.flags, ZEBRA_FLAG_TABLEID). Both should use ZAPI_MESSAGE_TABLEID in api.message for consistency. The zclient library automatically sets the flag bit in api.flags when the message bit is set (see lib/zclient.c:1422-1423).
| if (tableid_set) { | |
| api.tableid = tableid; | |
| SET_FLAG(api.flags, ZEBRA_FLAG_TABLEID); | |
| if (tableid_set) { | |
| api.tableid = tableid; | |
| SET_FLAG(api.message, ZAPI_MESSAGE_TABLEID); | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: sharpd/sharp_zebra.c
Line: 328:330
Comment:
Inconsistent flag usage with `route_add()`. In `route_add()` at line 257, you use `SET_FLAG(api.message, ZAPI_MESSAGE_TABLEID)`, but here you use `SET_FLAG(api.flags, ZEBRA_FLAG_TABLEID)`. Both should use `ZAPI_MESSAGE_TABLEID` in `api.message` for consistency. The zclient library automatically sets the flag bit in `api.flags` when the message bit is set (see lib/zclient.c:1422-1423).
```suggestion
if (tableid_set) {
api.tableid = tableid;
SET_FLAG(api.message, ZAPI_MESSAGE_TABLEID);
}
```
How can I resolve this? If you propose a fix, please make it concise.| if (table_id_str) { | ||
| if (table_id > UINT32_MAX) { | ||
| vty_out(vty, "%% invalid input for table: %s\n", table_id_str); | ||
| return CMD_WARNING; | ||
| } | ||
| sg.r.tableid = (uint32_t)table_id; | ||
| sg.r.tableid_set = true; | ||
| SET_FLAG(sg.r.flags, ZEBRA_FLAG_TABLEID); | ||
| } |
There was a problem hiding this comment.
Redundant validation check. The CLI definition specifies [table (0-4294967295)$table_id] where 4294967295 equals UINT32_MAX, so the check at line 355 will never be true. The CLI parser already ensures table_id is within the valid range for uint32_t.
| if (table_id_str) { | |
| if (table_id > UINT32_MAX) { | |
| vty_out(vty, "%% invalid input for table: %s\n", table_id_str); | |
| return CMD_WARNING; | |
| } | |
| sg.r.tableid = (uint32_t)table_id; | |
| sg.r.tableid_set = true; | |
| SET_FLAG(sg.r.flags, ZEBRA_FLAG_TABLEID); | |
| } | |
| if (table_id_str) { | |
| sg.r.tableid = (uint32_t)table_id; | |
| sg.r.tableid_set = true; | |
| SET_FLAG(sg.r.flags, ZEBRA_FLAG_TABLEID); | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: sharpd/sharp_vty.c
Line: 354:362
Comment:
Redundant validation check. The CLI definition specifies `[table (0-4294967295)$table_id]` where 4294967295 equals UINT32_MAX, so the check at line 355 will never be true. The CLI parser already ensures `table_id` is within the valid range for uint32_t.
```suggestion
if (table_id_str) {
sg.r.tableid = (uint32_t)table_id;
sg.r.tableid_set = true;
SET_FLAG(sg.r.flags, ZEBRA_FLAG_TABLEID);
}
```
How can I resolve this? If you propose a fix, please make it concise.| if (table_id_str) { | ||
| if (table_id > UINT32_MAX) { | ||
| vty_out(vty, "%% invalid input for table: %s\n", table_id_str); | ||
| return CMD_WARNING; | ||
| } | ||
| sg.r.tableid = (uint32_t)table_id; | ||
| sg.r.tableid_set = true; | ||
| } |
There was a problem hiding this comment.
Same redundant validation as in install_routes_cmd. The CLI definition limits the range to UINT32_MAX, making this check unnecessary.
| if (table_id_str) { | |
| if (table_id > UINT32_MAX) { | |
| vty_out(vty, "%% invalid input for table: %s\n", table_id_str); | |
| return CMD_WARNING; | |
| } | |
| sg.r.tableid = (uint32_t)table_id; | |
| sg.r.tableid_set = true; | |
| } | |
| if (table_id_str) { | |
| sg.r.tableid = (uint32_t)table_id; | |
| sg.r.tableid_set = true; | |
| } |
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!
Prompt To Fix With AI
This is a comment left during a code review.
Path: sharpd/sharp_vty.c
Line: 818:825
Comment:
Same redundant validation as in `install_routes_cmd`. The CLI definition limits the range to UINT32_MAX, making this check unnecessary.
```suggestion
if (table_id_str) {
sg.r.tableid = (uint32_t)table_id;
sg.r.tableid_set = true;
}
```
<sub>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!</sub>
How can I resolve this? If you propose a fix, please make it concise.f8e94d7 to
c06f2ea
Compare
|
@greptile review |
| if (wb.restart == SHARP_INSTALL_ROUTES_RESTART) | ||
| wb.restart = SHARP_RESTART_NONE; |
There was a problem hiding this comment.
Missing handling for SHARP_DELETE_ROUTES_RESTART. If a route removal operation is in progress when sharp install stop is called, the wb.restart state won't be cleared, causing the buffer ready callback to continue removing routes.
| if (wb.restart == SHARP_INSTALL_ROUTES_RESTART) | |
| wb.restart = SHARP_RESTART_NONE; | |
| if (wb.restart == SHARP_INSTALL_ROUTES_RESTART || wb.restart == SHARP_DELETE_ROUTES_RESTART) | |
| wb.restart = SHARP_RESTART_NONE; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: sharpd/sharp_zebra.c
Line: 496:497
Comment:
Missing handling for `SHARP_DELETE_ROUTES_RESTART`. If a route removal operation is in progress when `sharp install stop` is called, the `wb.restart` state won't be cleared, causing the buffer ready callback to continue removing routes.
```suggestion
if (wb.restart == SHARP_INSTALL_ROUTES_RESTART || wb.restart == SHARP_DELETE_ROUTES_RESTART)
wb.restart = SHARP_RESTART_NONE;
```
How can I resolve this? If you propose a fix, please make it concise.| } | ||
| sg.r.tableid = (uint32_t)table_id; | ||
| sg.r.tableid_set = true; | ||
| SET_FLAG(sg.r.flags, ZEBRA_FLAG_TABLEID); |
There was a problem hiding this comment.
Redundant flag set. The zclient library automatically sets ZEBRA_FLAG_TABLEID in api.flags when ZAPI_MESSAGE_TABLEID is set in api.message (see lib/zclient.c:1422-1423). This line can be removed.
Prompt To Fix With AI
This is a comment left during a code review.
Path: sharpd/sharp_vty.c
Line: 372:372
Comment:
Redundant flag set. The zclient library automatically sets `ZEBRA_FLAG_TABLEID` in `api.flags` when `ZAPI_MESSAGE_TABLEID` is set in `api.message` (see lib/zclient.c:1422-1423). This line can be removed.
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
Seems this is right what greptile is saying?
| sg.r.tableid = 0; | ||
| sg.r.tableid_set = false; | ||
| if (table_id_str) { | ||
| if (table_id > UINT32_MAX) { |
There was a problem hiding this comment.
I think that's not possible, right?
Wanted the ability to push routes into a random table for some testing that I want to do. Just add the ability to allow this. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
If you have a large number of routes being repeatedly installed/removed, add a `sharp install stop` command. This allows for the stopping of the loop. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
c06f2ea to
43c4fee
Compare
Allow the optional send of a table id for the installation/removal of routes.