Skip to content

[openconfig_acl] Allow setting ICMP type/code to 0#6932

Merged
daall merged 3 commits intosonic-net:masterfrom
daall:openconfig_bug_fix
Mar 2, 2021
Merged

[openconfig_acl] Allow setting ICMP type/code to 0#6932
daall merged 3 commits intosonic-net:masterfrom
daall:openconfig_bug_fix

Conversation

@daall
Copy link
Copy Markdown
Contributor

@daall daall commented Mar 1, 2021

Signed-off-by: Danny Allen [email protected]

Why I did it

There is a bug in how pyangbind translates yang models into python bindings. The model always sets integer values to 0 by default, so there is no way to check if a user has provided a value that is equal to 0. This is problematic for ICMP and VLAN (among others) because 0 is a valid input value.

We also discovered that if the input is an integer and a string value is provided then the field will be silently ignored, which may be problematic in the case of ACL rules.

How I did it

I converted ICMP and VLAN fields to union types so that acl-loader will treat them as null values unless a user explicitly adds an integer value.

How to verify it

Run sonic-mgmt tests to verify existing acl behavior is intact. See also new tests in sonic-net/sonic-utilities#1469.

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012

Description for the changelog

A picture of a cute animal (not mandatory but encouraged)

@daall daall added Bug 🐛 sonic-cfggen SONiC Configuration Generator Tool Request for 202012 Branch labels Mar 1, 2021
@daall daall requested review from lguohan and qiluo-msft March 1, 2021 21:47
Comment thread src/sonic-config-engine/sonic-acl-extension.yang
self.__source_mac = YANGDynClass(base=RestrictedClassType(base_type=six.text_type, restriction_dict={u'pattern': u'[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}'}), is_leaf=True, yang_name="source-mac", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='http://openconfig.net/yang/acl', defining_module='openconfig-acl', yang_type='yang:mac-address', is_config=True)
self.__source_mac_mask = YANGDynClass(base=RestrictedClassType(base_type=six.text_type, restriction_dict={u'pattern': u'[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}'}), is_leaf=True, yang_name="source-mac-mask", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='http://openconfig.net/yang/acl', defining_module='openconfig-acl', yang_type='yang:mac-address', is_config=True)
self.__vlan_id = YANGDynClass(base=RestrictedClassType(base_type=RestrictedClassType(base_type=int, restriction_dict={'range': ['0..65535']},int_size=16), restriction_dict={u'range': [u'0..4095']}), is_leaf=True, yang_name="vlan-id", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='https://github.com/Azure/sonic-buildimage', defining_module='sonic-acl-extension', yang_type='vlan-id-type', is_config=True)
self.__vlan_id = YANGDynClass(base=RestrictedClassType(base_type=six.text_type, restriction_dict={u'length': [u'1..4']}), is_leaf=True, yang_name="vlan-id", parent=self, path_helper=self._path_helper, extmethods=self._extmethods, register_paths=True, namespace='https://github.com/Azure/sonic-buildimage', defining_module='sonic-acl-extension', yang_type='vlan-id-type', is_config=True)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting. I remember while writing the translation in sonic-Yang-mgmt, I converted each Yang model in Json format using Libyang and got similar data for each leaf\list\container in yang model.

FYI: https://github.com/Azure/sonic-buildimage/blob/0f1d41dac2f79f0e29279e497b12af69c0baac32/src/sonic-yang-mgmt/sonic_yang_ext.py#L208

@daall daall changed the title [openconfig_acl] Treat VLAN ID and ICMP type/code as strings instead of integer types [openconfig_acl] Allow setting ICMP type/code to 0 Mar 2, 2021
@daall daall merged commit 880a743 into sonic-net:master Mar 2, 2021
yxieca pushed a commit that referenced this pull request Mar 4, 2021
There is a bug in how pyangbind translates yang models into python bindings. The model always sets integer values to 0 by default, so there is no way to check if a user has provided a value that is equal to 0. This is problematic for ICMP and VLAN (among others) because 0 is a valid input value.

This change converts ICMP and VLAN fields to union types so that acl-loader will treat them as null values unless a user explicitly adds an integer value.

Signed-off-by: Danny Allen <[email protected]>
carl-nokia pushed a commit to carl-nokia/sonic-buildimage that referenced this pull request Aug 7, 2021
There is a bug in how pyangbind translates yang models into python bindings. The model always sets integer values to 0 by default, so there is no way to check if a user has provided a value that is equal to 0. This is problematic for ICMP and VLAN (among others) because 0 is a valid input value.

This change converts ICMP and VLAN fields to union types so that acl-loader will treat them as null values unless a user explicitly adds an integer value.

Signed-off-by: Danny Allen <[email protected]>
lolyu pushed a commit to lolyu/sonic-buildimage that referenced this pull request Sep 13, 2021
There is a bug in how pyangbind translates yang models into python bindings. The model always sets integer values to 0 by default, so there is no way to check if a user has provided a value that is equal to 0. This is problematic for ICMP and VLAN (among others) because 0 is a valid input value.

This change converts ICMP and VLAN fields to union types so that acl-loader will treat them as null values unless a user explicitly adds an integer value.

Signed-off-by: Danny Allen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants