-
Notifications
You must be signed in to change notification settings - Fork 230
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
feat(config): wildcard lan interface name support #729
base: main
Are you sure you want to change the base?
feat(config): wildcard lan interface name support #729
Conversation
golang 使用 tab 作为缩进,请用 |
已经重新 commit , cmd/internal 文件大面积爆红是因为上次提交的时候没有 format
另外,在群内讨论到后面可能需要单独修改 Callback的逻辑,以便于在 |
抱歉,回复有些晚。 或许我们可以用较为通用的 shell pattern,go 的标准库 path.Match 可以做到这一点: package path
// Match reports whether name matches the shell pattern.
// The pattern syntax is:
//
// pattern:
// { term }
// term:
// '*' matches any sequence of non-/ characters
// '?' matches any single non-/ character
// '[' [ '^' ] { character-range } ']'
// character class (must be non-empty)
// c matches character c (c != '*', '?', '\\', '[')
// '\\' c matches character c
//
// character-range:
// c matches character c (c != '\\', '-', ']')
// '\\' c matches character c
// lo '-' hi matches character c for lo <= c <= hi
//
// Match requires pattern to match all of name, not just a substring.
// The only possible returned error is [ErrBadPattern], when pattern
// is malformed.
func Match(pattern, name string) (matched bool, err error) 其中 * 匹配多个,? 匹配一个。 为了降低复杂度,我们或许可以对所有表达式通用这个 matcher,而不需要 InterfaceMather 接口并给出两个实现。 @woshikedayaa 你怎么看? |
今天才看到邮件消息,这个回复可能稍晚。 我觉得不错,支持更多了,且更标准,比我自己搓的 re来匹配好得多,我后面会提交一个新的commit来修改。 |
@woshikedayaa 👍🏻👍🏻👍🏻 |
目前的代码逻辑是:
由于改为了 wild match,不能每次都退出协程,可以考虑:
|
#758 已做实现,可以一同测试一下 |
Background
#724
Checklist
Full Changelogs
实现了 #724 的请求,现在支持了对于 lan_interfaces的匹配支持。
匹配规则支持 + 匹配一个字符,* 匹配多个字符。
代码变化
主要变动的是匹配部分,首先入口变成了
bindLanWildcard
内部实现是,首先根据匹配的 pattern 来匹配。如果不是 pattern 就只绑定单独的if。
给
addNewLinkBindLanCb
方法添加了一个keep bool
参数来决定是否需要持续监听。另外就是 bindLan 方法的变化。因为全局已经有一个 通过监听匹配表达式的监听回调,所以用一个参数表面如果监听删除的网卡是来自 wildcard 就不添加新的监听了。
最后,文档将在合并后添加。谢谢各位开发者的耐心查看代码。
另外还有个小问题,个人未修复(不知道咋修)。具体表现为,在一个被泛型匹配到的网卡被删除后,会报错
[Jan 04 16:49:01] ERROR addQdisc: Link not found
往提出修改意见修复(小bug 不影响使用)。
Issue Reference
#724
Test Result
在我的电脑工作正常。
帖一个测试脚本