Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib.yang: support for pattern restrictions #1263

Merged
merged 26 commits into from
Jul 2, 2018

Conversation

eugeneia
Copy link
Member

@eugeneia eugeneia commented Jan 11, 2018

Adds support for pattern and to lib.yang. The XSD Regex implementation is of questionable design (at least it was fun to hack), and has some restrictions:

  • no unicode support (the implementation is 8‑bit clean though)
  • no block escapes

Generally speaking, its not advisable to use it for sanitizing non-ASCII input. It’s good enough to parse things like the IP address patterns we use though.

I could add full unicode support (I have a branch that interprets the strings as UTF-8), it’s just that I have decided not to, because I wasn’t sure if sticking a whole Unicode databse into the snabb binary was worth it. If anyone actually needs Unicode support in Yang patterns, I will happily add it back in!

Cc @wingo

General categories are only implemented for the ASCII range, the
predicates return false for all codepoints outside of ASCII.

For lib.xsd_regexp that means it can’t match category escapes on
non-ASCII input, i.e. it can’t fully handle Unicode input. It can
however apply all valid regular expressions to ASCII input.
Caveat: users of category escapes must restrict their input to ASCII.

In order to fix this, we would need (access to) a full Unicode database
in which we could look up codepoints and their attributes.
lib.maxpc: add backtracking combinators
@eugeneia eugeneia requested a review from wingo January 11, 2018 18:49
@eugeneia
Copy link
Member Author

Right, this can’t work right now since IP addresses are converted to numbers before the validators see them… I didn’t notice this before because I have disabled that behavior on my downstream branch, my bad!

I guess I can guard the pattern validator on the invariant that the value to be validated is a string.

This extra guard is necessary because some intrinsic lib.yang extensions
will parse/validate some types natively (e.g. IP addresses using
lib.protocol.ipvX) circumventing the YANG validation stack.
@eugeneia
Copy link
Member Author

eugeneia commented Jan 12, 2018

That being fixed, the next error appears to be a lwaftr test assuming ranges are single intervals:

https://gist.github.com/SnabbBot/47076ad6d12879c3ce4d9ba4bf8ccbd7#file-log-L816

Edit: Actually they just use a different format.

When hacking the range validator I had misunderstood the format used
to express YANG range restrictions (I thought it didn’t feature
multiple intervals), and changed it along the way. I think the new
format is a bit simpler though (more regular) and requires less special
cases, so I decided to keep it.
@eugeneia eugeneia force-pushed the yang-restrictions-upstream branch from 8b27755 to e577721 Compare January 12, 2018 19:06
@eugeneia
Copy link
Member Author

All good to go!

@wingo
Copy link
Contributor

wingo commented Jan 15, 2018

Given that wingo-next has a lot of changes to some of the same stuff and that it's ready to go modulo some unrelated perf regression, I propose holding off here; unless you want to change the base branch to wingo-next of course. WDYT?

@eugeneia
Copy link
Member Author

I am in no particular rush to get this merged, so I guess feel free to pick it up whenever convenient.

@eugeneia eugeneia force-pushed the yang-restrictions-upstream branch 2 times, most recently from 5579f1e to 4396c52 Compare March 5, 2018 11:56
@eugeneia eugeneia force-pushed the yang-restrictions-upstream branch from 4396c52 to 03daccb Compare March 5, 2018 12:23
@eugeneia eugeneia changed the title lib.yang: support for pattern and range restrictions lib.yang: support for pattern restrictions Mar 5, 2018
@eugeneia
Copy link
Member Author

eugeneia commented Mar 5, 2018

Merged the current master. Note that besides the pattern validator this PR also...

  • adds contextual errors to validators by passing in a parser
  • fixes a bug where explicit values were not recognized in ranges

@eugeneia
Copy link
Member Author

eugeneia commented Mar 19, 2018

Actually, I found a glaring omission in the Regex implementation (duh) over the weekend, so please put merging this on hold until I come up with a fix. :-)

  • Implement Regex quantifiers properly (their backtracking is broken)

Removes the broken match.range and replaces match.all with a simple
implementation by means of match.plus.

In lib.xsd_regexp implement backtracking match.range combinator by means of
match.all.

Simplify variable argument variants of match.plus and match.alternate along the
way.
@eugeneia
Copy link
Member Author

eugeneia commented Apr 9, 2018

Ok should be better now! :-)

Copy link
Contributor

@tsyesika tsyesika left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@wingo wingo left a comment

Choose a reason for hiding this comment

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

Jessica kindly had a thorough look and says LGTM, so I say LGTM as well :) Looks really cool!

wingo added a commit that referenced this pull request Jun 1, 2018
@wingo wingo added the merged label Jun 1, 2018
@eugeneia eugeneia merged commit be6c657 into snabbco:master Jul 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants