Giter Club home page Giter Club logo

Comments (18)

pymumu avatar pymumu commented on July 18, 2024

rust应该有nfset的库吧

from smartdns.

mokeyish avatar mokeyish commented on July 18, 2024

他们是用工具根据 nftset 的 c 头文件生成一堆函数,然后封装的也不全。
比如这个 https://gitlab.com/rustwall/rustables/-/blob/master/rustables/build.rs?ref_type=heads

看不明白怎么用,看你这有,除了上面提到日志相关的依赖,其他都是的系统和nft类库依赖吧,这样只要用这头文件里定义的函数生成对应的两个 rust 函数,这样也精简,不用生成一堆用不到的函数定义。

from smartdns.

pymumu avatar pymumu commented on July 18, 2024

lib.tar.gz

试试吧

from smartdns.

mokeyish avatar mokeyish commented on July 18, 2024

@pymumu 非常感谢。我前面的意思是,日志相关的用个条件编译。你这边编译就把条件开启来,我那边就下载你主分支对应文件,只不过编译时不开,这样后续就共用一份代码了,也不用单独维护。

from smartdns.

pymumu avatar pymumu commented on July 18, 2024

这个改的不多,直接copy吧

from smartdns.

mokeyish avatar mokeyish commented on July 18, 2024

@pymumu 大佬,我这样调用不对?
https://github.com/mokeyish/nftcli/blob/ce7fed148ab52abacef94ac9afaf225ce71a7f5c/src/main.rs#L107

image

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.

pymumu avatar pymumu commented on July 18, 2024

ip是二进制数据,不是字符串
v4地址4字节,v6地址16字节

from smartdns.

mokeyish avatar mokeyish commented on July 18, 2024

是这样的这里转成 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.

pymumu avatar pymumu commented on July 18, 2024

from smartdns.

mokeyish avatar mokeyish commented on July 18, 2024

可以添加成功和删除成功了。不过返回值都是 -1。c 语言里面貌似正常是 0,错误是 1?

image

addr_len 既然是根据 ip 定的,封装后,可以省略了,直接填 IP,这样更简洁
https://github.com/mokeyish/nftcli/blob/main/src/main.rs#L108
image

from smartdns.

pymumu avatar pymumu commented on July 18, 2024

成功是返回0,-1是错误

from smartdns.

mokeyish avatar mokeyish commented on July 18, 2024

那就奇怪了,IP 是进去了,但是返回都是 -1。
如果 IP 字节没问题,那就是字符串了。
字符串传入的是 cstring 的指针,c 里面有特殊字节表示结尾(长度)的?

from smartdns.

mokeyish avatar mokeyish commented on July 18, 2024

大佬有时间帮我看看,
仓库:https://github.com/mokeyish/nftcli
c 代码有变更运行 cargo clean
编译 cargo build
运行 sudo ./target/debug/nftapp

from smartdns.

pymumu avatar pymumu commented on July 18, 2024
static int _nftset_socket_send(void *msg, int msg_len)
{
	return _nftset_socket_request(msg, msg_len, NULL, 0);
}

这个改成这样,给你的代码,之前有错误。

from smartdns.

mokeyish avatar mokeyish commented on July 18, 2024

@pymumu 程序搞定了,测试可行。

还有两个小问题。

  1. 按你上面的改后,不论是否成功,全部都返回 0 了(如果没有对应table set,没添加上去也是 0)

  2. 这个执行 nftset_add, 程序端是否有缓存判断已经加入 nftset 了,还是直接调用此函数,剩下的有系统自己判断是否重复添加?

from smartdns.

pymumu avatar pymumu commented on July 18, 2024

之前代码是有确认结果的,但一般请netlink通信不会有问题。所以就只发送没有接收确认结果。
重复加入如果timeout>0是会先删除的,否则也没必要判断重复。

from smartdns.

mokeyish avatar mokeyish commented on July 18, 2024

Ok, 非常感谢🙇‍

from smartdns.

mokeyish avatar mokeyish commented on July 18, 2024

https://github.com/mokeyish/nftapp

from smartdns.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.