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

Regular expression (regexp) matcher #220

Merged
merged 2 commits into from
Jul 24, 2024
Merged

Regular expression (regexp) matcher #220

merged 2 commits into from
Jul 24, 2024

Conversation

vnxme
Copy link
Collaborator

@vnxme vnxme commented Jul 22, 2024

Summary

The idea behind regexp matcher is to allow low-level packet matching. It's pretty simple under the hood, but actually very powerful. With this matcher Caddy can multiplex virtually any protocol, if a regular expression syntax is enough to distinguish the desired one from others.

Code examples

Proxy a connection starting with a 0xFFEEDD000000 sequence to another machine

{
  "apps": {
    "layer4": {
      "servers": {
        "example": {
          "listen": ["0.0.0.0:443"],
          "routes": [
            {
              "handle": [
                {
                  "handler": "proxy",
                  "upstreams": [
                    {"dial": ["another.machine.local:456"]}
                  ]
                }
              ],
              "match": [
                {"regexp": {"count": 6, "pattern": "^\\xFF\\xEE\\xDD\\x00\\x00\\x00$"}}
              ]
            },
            {
              "handle": [
                {
                  "handler": "tls"
                },
                {
                  "handler": "proxy",
                  "upstreams": [
                    {"dial": ["localhost:8080"]}
                  ]
                }
              ],
              "match": [
                {"tls": {}}
              ]
            }
          ]
        }
      }
    }
  }
}

Copy link
Owner

@mholt mholt left a comment

Choose a reason for hiding this comment

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

This looks great! I'm excited to see how people use it.

README.md Outdated Show resolved Hide resolved
modules/l4regexp/matcher.go Show resolved Hide resolved
Copy link
Owner

@mholt mholt left a comment

Choose a reason for hiding this comment

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

LGTM! Anything else before we merge it?

@vnxme
Copy link
Collaborator Author

vnxme commented Jul 24, 2024

Rebased onto master and added integration tests. I think, it's ready to be merged now.

@mholt mholt merged commit 32fede4 into mholt:master Jul 24, 2024
6 checks passed
@mholt
Copy link
Owner

mholt commented Jul 24, 2024

Awesome! Thanks!

@vnxme vnxme deleted the regexp branch July 24, 2024 15:32
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.

2 participants