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

Implement the pass through #172

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/rules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ rules:
- match: tcp dst port 11211
type: conn_handler
target: memcache
- match: tcp dst port 5000
Copy link
Member

Choose a reason for hiding this comment

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

have you tested this for other ports?

Copy link
Author

Choose a reason for hiding this comment

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

there is a problem, i have to set glutton run a specific port and implement pass through on the same port so that it works. so, i just wonder if gluuton could run a different port with pass through, i tested this situation but it shows connection refused. Also, when i test pass through within glutton running on the same port, it will accept request, but do not response, i don't if it is because i do not run any program on that port.

type: passthrough
- match: tcp
type: conn_handler
target: tcp
Expand Down
4 changes: 4 additions & 0 deletions glutton.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ func (g *Glutton) tcpListen() {
}

md, err := g.connTable.RegisterConn(conn, rule)
if md.Rule.GetRuleType() == rules.PassThrough {
continue
}

if err != nil {
g.Logger.Error("Failed to register connection", producer.ErrAttr(err))
continue
Expand Down
7 changes: 7 additions & 0 deletions rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type RuleType int
const (
UserConnHandler RuleType = iota
Drop
PassThrough
)

type Config struct {
Expand All @@ -37,6 +38,10 @@ type Rule struct {
matcher *pcap.BPF
}

func (r *Rule) GetRuleType() RuleType {
Copy link
Member

Choose a reason for hiding this comment

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

Make the attribute public instead of implementing a getter

return r.ruleType
}

func (r *Rule) String() string {
return fmt.Sprintf("Rule: %s", r.Match)
}
Expand All @@ -62,6 +67,8 @@ func (rule *Rule) init(idx int) error {
rule.ruleType = UserConnHandler
case "drop":
rule.ruleType = Drop
case "passthrough":
rule.ruleType = PassThrough
default:
return fmt.Errorf("unknown rule type: %s", rule.Type)
}
Expand Down