Skip to content

fix: preserve numeric protocols in Cisco and Cisco object-group ACLs (#170) - #378

Open
hardikkaurani wants to merge 1 commit into
google:masterfrom
hardikkaurani:fix/cisco-numeric-protocol-170
Open

hardikkaurani wants to merge 1 commit into
google:masterfrom
hardikkaurani:fix/cisco-numeric-protocol-170

Conversation

@hardikkaurani

Copy link
Copy Markdown

Summary

Fixes #170

When a policy defines a numeric protocol (for example, protocol:: 50), the Cisco generator (cisco.py) previously rendered rules with None instead of the protocol number:

permit None any host 10.0.0.1

This occurred because cisco.Term.__str__ and cisco.ObjectGroupTerm mapped non-allowed string names via self.PROTO_MAP.get(proto). Because PROTO_MAP maps protocol names to numbers ('tcp' -> 6, 'esp' -> 50), looking up an already numeric protocol returned None.

Solution

  1. In cisco.Term.__str__ and cisco.ObjectGroupTerm: use self.PROTO_MAP.get(proto, proto) as fallback so numeric protocols retain their numerical value instead of resolving to None.
  2. In IOSXEMap.GetProtocolName: attempt numeric integer lookup if string lookup raises KeyError, ensuring string protocol numbers (e.g. '50') correctly map to their IOS-XE names (e.g. 'esp') when configure_replace_compatible is enabled.
  3. In cisco.Term.__init__: ensure ALLOWED_PROTO_STRINGS is scoped per-instance to prevent mutating and duplicating entries in the class-level attribute across multiple term instantiations.
  4. Added regression tests in tests/lib/cisco_test.py covering standard extended, object-group, IPv6, and configure_replace_compatible modes, as well as class attribute immutability.

Validation

  • Ran pytest tests/lib/cisco_test.py tests/lib/ciscoxr_test.py tests/lib/ciscoasa_test.py tests/lib/arista_test.py: 91 passed.
  • Ran flake8 linter with repository CI flags: 0 errors/warnings.

…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.
@hardikkaurani

Copy link
Copy Markdown
Author

Hi @david-wu!

Could you please take a look at this PR when you have a moment? It addresses #170 where raw numeric protocols in policy definitions rendered as None in the Cisco generator. All unit tests and linters pass cleanly. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Platform Cisco wrong numeric protocol rendering

1 participant