[agent-go] [Bastion] - basic accomplished !

This commit is contained in:
zeaslity
2024-04-18 15:20:19 +08:00
parent 8e43f1f90f
commit 314b6054d3
14 changed files with 467 additions and 204 deletions

View File

@@ -2,7 +2,6 @@ package bastion_init
import (
"fmt"
"syscall"
"testing"
)
@@ -22,37 +21,5 @@ func TestNewTrie(t *testing.T) {
}
func TestDp(t *testing.T) {
// 获取netlink接口用于网络控制的内核机制
nl := syscall.NewLk(syscall.AT_FDCWD, "netlink")
if nl == nil {
fmt.Println("Unable to open netlink")
return
}
defer nl.Close()
// 设置对netlink的访问权限
if err := syscall.Setpgid(0, syscall.Getpid()); err != nil {
fmt.Println("Unable to set pgid", err)
return
}
// 设置netlink接口为非阻塞模式
if err := nl.Control(syscall.SET_NONBLOCK, 1); err != nil {
fmt.Println("Unable to set netlink nonblocking", err)
return
}
// 获取IPv4路由转发设置的值
var value syscall.SysctlValInt
if err := syscall.Sysctl(nl, "net/ipv4/ip_forward", &value); err != nil {
fmt.Println("Unable to get ip_forward value:", err)
return
}
// 打印IPv4路由转发的状态
if value == 1 {
fmt.Println("IPv4 routing forwarding is enabled")
} else {
fmt.Println("IPv4 routing forwarding is disabled")
}
}