Repository navigation
fix: preserve numeric protocols in Cisco and Cisco object-group ACLs (#170) - #378
Open
hardikkaurani wants to merge 1 commit into
Open
hardikkaurani wants to merge 1 commit into
hardikkaurani wants to merge 1 commit into
Conversation
…oogle#170) When a numeric protocol (e.g. protocol:: 50) is specified in a policy term, cisco.Term.__str__ and cisco.ObjectGroupTerm previously attempted to map it using self.PROTO_MAP.get(proto). Because PROTO_MAP maps names to numbers, it returned None, rendering lines like 'permit None any any'. Fallback to preserving the protocol number when it is not a protocol name in PROTO_MAP, ensure string protocol numbers resolve to named aliases under IOSXEMap.GetProtocolName when configure_replace_compatible is enabled, and avoid mutating class-level ALLOWED_PROTO_STRINGS on Term initialization.
Author
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.
Summary
Fixes #170
When a policy defines a numeric protocol (for example,
protocol:: 50), the Cisco generator (cisco.py) previously rendered rules withNoneinstead of the protocol number:This occurred because
cisco.Term.__str__andcisco.ObjectGroupTermmapped non-allowed string names viaself.PROTO_MAP.get(proto). BecausePROTO_MAPmaps protocol names to numbers ('tcp' -> 6,'esp' -> 50), looking up an already numeric protocol returnedNone.Solution
cisco.Term.__str__andcisco.ObjectGroupTerm: useself.PROTO_MAP.get(proto, proto)as fallback so numeric protocols retain their numerical value instead of resolving toNone.IOSXEMap.GetProtocolName: attempt numeric integer lookup if string lookup raisesKeyError, ensuring string protocol numbers (e.g.'50') correctly map to their IOS-XE names (e.g.'esp') whenconfigure_replace_compatibleis enabled.cisco.Term.__init__: ensureALLOWED_PROTO_STRINGSis scoped per-instance to prevent mutating and duplicating entries in the class-level attribute across multiple term instantiations.tests/lib/cisco_test.pycovering standard extended, object-group, IPv6, andconfigure_replace_compatiblemodes, as well as class attribute immutability.Validation
pytest tests/lib/cisco_test.py tests/lib/ciscoxr_test.py tests/lib/ciscoasa_test.py tests/lib/arista_test.py: 91 passed.