[cvl] Enforce mandatory field validation for OP_CREATE operations#212
Open
Sumalatha-G-ML wants to merge 1 commit intosonic-net:masterfrom
Open
[cvl] Enforce mandatory field validation for OP_CREATE operations#212Sumalatha-G-ML wants to merge 1 commit intosonic-net:masterfrom
Sumalatha-G-ML wants to merge 1 commit intosonic-net:masterfrom
Conversation
Issue: CVL's ValidateEditConfig() does not enforce YANG mandatory true fields on OP_CREATE operations, allowing invalid configurations to be written to CONFIG_DB. Root Cause: CVL performs mandatory field validation only for OP_DELETE operations but skips this critical check for OP_CREATE operations. This allows entries to be created without required mandatory fields defined in YANG models. Solution: - Added checkMandatoryFieldsForCreate() function to validate mandatory fields - Function iterates through YANG leaf nodes and checks if mandatory fields exist - Returns CVL_SEMANTIC_ERROR with clear error message if mandatory field is missing - Called during OP_CREATE case in ValidateEditConfig() Impact: - Prevents invalid configurations from being written to CONFIG_DB - Provides clear error messages indicating which mandatory field is missing - Consistent with existing OP_DELETE mandatory field validation - No hardware dependency - pure software validation Testing: - CREATE operations with missing mandatory fields will now fail with proper error - CREATE operations with all mandatory fields will continue to work normally - Error includes table name, key, field name, and descriptive message Fixes: sonic-net/SONiC#2283 Signed-off-by: Sumalatha G <[email protected]>
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Hi, faraazbrcm replied to me with the following fix "Mandatory validation is a syntax validation, CVL relies on libyang for this. Ygot does not support such validation. And I added the following fix grep -n 'lyd_check_mandatory_tree' /sonic/src/libyang/libyang/src/tree_data.c | head -5
If you see `int lyd_check_mandatory_tree` (no API prefix), then the patch is NOT applied.
You need to apply the fix to the source:
sed -i 's/^int$/API int/' /sonic/src/libyang/libyang/src/tree_data.c
Then verify:
grep -B1 'lyd_check_mandatory_tree' /sonic/src/libyang/libyang/src/tree_data.c | head -3
It must show `API int` on the line before `lyd_check_mandatory_tree`.
Apply the above fix right after the relevant comment in the source file.I tried it, and it’s working now — it checks both the mandatory fields and the when conditions as well. |
Author
|
Thank you for sharing @faraazbrcm's feedback about using libyang's But I have below questions
@faraazbrcm - Which approach do you prefer? |
|
@Sumalatha-G-ML You can mention your issue in the main repo here for faster reply. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue: CVL's ValidateEditConfig() does not enforce YANG mandatory true fields on OP_CREATE operations, allowing invalid configurations to be written to CONFIG_DB.
Root Cause:
CVL performs mandatory field validation only for OP_DELETE operations but skips this critical check for OP_CREATE operations. This allows entries to be created without required mandatory fields defined in YANG models.
Solution:
Impact:
Testing:
Fixes: sonic-net/SONiC#2283