59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package bastion_init
|
||
|
||
import (
|
||
"fmt"
|
||
"syscall"
|
||
"testing"
|
||
)
|
||
|
||
func TestNewTrie(t *testing.T) {
|
||
|
||
words := []string{"apple", "apricot", "apprentice", "application"}
|
||
tcc := NewTrie()
|
||
tcc.InsertAll(words)
|
||
|
||
prefix := "ap"
|
||
closest, err := FindClosestWord(tcc, prefix)
|
||
if err != nil {
|
||
fmt.Println(err)
|
||
} else {
|
||
fmt.Printf("The closest word to '%s' is '%s'\n", prefix, closest)
|
||
}
|
||
}
|
||
|
||
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")
|
||
}
|
||
}
|