Comments (18)
rust应该有nfset的库吧
from smartdns.
他们是用工具根据 nftset 的 c 头文件生成一堆函数,然后封装的也不全。
比如这个 https://gitlab.com/rustwall/rustables/-/blob/master/rustables/build.rs?ref_type=heads
看不明白怎么用,看你这有,除了上面提到日志相关的依赖,其他都是的系统和nft类库依赖吧,这样只要用这头文件里定义的函数生成对应的两个 rust 函数,这样也精简,不用生成一堆用不到的函数定义。
from smartdns.
试试吧
from smartdns.
@pymumu 非常感谢。我前面的意思是,日志相关的用个条件编译。你这边编译就把条件开启来,我那边就下载你主分支对应文件,只不过编译时不开,这样后续就共用一份代码了,也不用单独维护。
from smartdns.
这个改的不多,直接copy吧
from smartdns.
@pymumu 大佬,我这样调用不对?
https://github.com/mokeyish/nftcli/blob/ce7fed148ab52abacef94ac9afaf225ce71a7f5c/src/main.rs#L107
family_name 我试了 ip inet 都不行。。。它返回的时 -1。IP 地址我写的是 4 个字节的数组指针,这个字节序应该是 big endian 吧?
#!/usr/sbin/nft -f
table inet ray
delete table inet ray
table inet ray {
set directlist_v4 {
type ipv4_addr
flags interval
}
}
table ip ray
delete table ip ray
table ip ray_v4 {
set directlist_v4 {
type ipv4_addr
flags interval
}
}
from smartdns.
ip是二进制数据,不是字符串
v4地址4字节,v6地址16字节
from smartdns.
是这样的这里转成 4 字节了。https://github.com/mokeyish/nftcli/blob/ce7fed148ab52abacef94ac9afaf225ce71a7f5c/src/main.rs#L17
打印控制台打印确定程序是执行到 ret = _nftset_socket_send(buf, buffer_len);
,它返回 —1
难道 addr_len 是ip字节长度(只能填4和16)?还是地址前缀长度?
from smartdns.
对
from smartdns.
可以添加成功和删除成功了。不过返回值都是 -1。c 语言里面貌似正常是 0,错误是 1?
addr_len 既然是根据 ip 定的,封装后,可以省略了,直接填 IP,这样更简洁
https://github.com/mokeyish/nftcli/blob/main/src/main.rs#L108
from smartdns.
成功是返回0,-1是错误
from smartdns.
那就奇怪了,IP 是进去了,但是返回都是 -1。
如果 IP 字节没问题,那就是字符串了。
字符串传入的是 cstring 的指针,c 里面有特殊字节表示结尾(长度)的?
from smartdns.
大佬有时间帮我看看,
仓库:https://github.com/mokeyish/nftcli
c 代码有变更运行 cargo clean
。
编译 cargo build
运行 sudo ./target/debug/nftapp
from smartdns.
static int _nftset_socket_send(void *msg, int msg_len)
{
return _nftset_socket_request(msg, msg_len, NULL, 0);
}
这个改成这样,给你的代码,之前有错误。
from smartdns.
@pymumu 程序搞定了,测试可行。
还有两个小问题。
-
按你上面的改后,不论是否成功,全部都返回 0 了(如果没有对应table set,没添加上去也是 0)
-
这个执行 nftset_add, 程序端是否有缓存判断已经加入 nftset 了,还是直接调用此函数,剩下的有系统自己判断是否重复添加?
from smartdns.
之前代码是有确认结果的,但一般请netlink通信不会有问题。所以就只发送没有接收确认结果。
重复加入如果timeout>0是会先删除的,否则也没必要判断重复。
from smartdns.
Ok, 非常感谢🙇
from smartdns.
https://github.com/mokeyish/nftapp
from smartdns.
Related Issues (20)
- ttl 的默认值不正常 HOT 19
- 测试发现强解析存在bug HOT 3
- 无法获取新域名的 HOT 18
- 【正则匹配】域名规则有没有可能支持正则配置?
- doh支持使用特定token限制访问
- 用户日志能否支持功能调用IP识别运营商接口nali或者纯真qqwry.dat库支持日志展示
- 定义了组名的服务器没有从默认组中排除 HOT 1
- 使用代理地址报错 HOT 4
- domain-set 能否增加实时监听 -file 文件变动,实现不需要重启服务即可添加新的域名?
- 给上游服务器组设置备用上游
- nameserver 规则对私有IPv4地址的PTR记录无效
- 能做到根据ipv4返回的地址,选择上游服务器并返回结果么(即根据ip分流) HOT 10
- SmartDNS是否可以支持多节点之间的配置同步?或者提供对应API&Cli? HOT 1
- `sendto fdbd:dc01:fe:1009::1, id 217, Permission denied` HOT 18
- 广告屏蔽 HOT 9
- 关于DNS缓存的一些问题 HOT 9
- 能否提供单独关闭DNS64的按钮或者指令,仅限制v6访问v6,v4访问v4,部分程序不支持转换访问 HOT 1
- 目前看文档提供给用户侧支持DoT、DoH还有H3 和 DoQ目前暂不支持,想咨询一下如何验证 HOT 1
- multiple server entries, what order? HOT 3
- Bug Report:SmartDNS crashes due to misaligned memory access in `fast_ping.c`. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from smartdns.