feat: Docker Compose E2E test env, agent fixes, TAP MAC config, testclient binary

- Add docker-compose.yml with server + init + 3 clients + tester
- Add Dockerfile.server (CGO multi-stage) and Dockerfile.client
- Add .dockerignore for efficient builds
- Add cmd/testclient/main.go: full E2E test binary using SDK
- Fix agent handshake loop: only respond to new handshakes
- Add tapInterface.SetMAC() to match agent's generated MAC
- Call SetMAC() in agent SetTAPIP to fix ARP resolution
- Add data-plane debug logging for troubleshooting
- Change config database path to /tmp/data/ for container use
- Add SetMAC stub for non-Linux builds
This commit is contained in:
xieyao
2026-06-17 05:04:19 +08:00
parent e3147ac06f
commit 807c4cf323
9 changed files with 535 additions and 8 deletions

View File

@@ -4,6 +4,7 @@ package sdk
import (
"fmt"
"os/exec"
"syscall"
"unsafe"
)
@@ -35,7 +36,6 @@ func openTap(name string, mtu int) (*tapInterface, error) {
}
ti := &tapInterface{Name: devName, MTU: mtu, fd: fd}
// Set MTU via socket ioctl
s, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_DGRAM, 0)
if err == nil {
defer syscall.Close(s)
@@ -45,7 +45,7 @@ func openTap(name string, mtu int) (*tapInterface, error) {
}
copy(mtuReq.name[:], []byte(devName))
mtuReq.mtu = int32(mtu)
syscall.Syscall(syscall.SYS_IOCTL, uintptr(s), 0x400c4a52, uintptr(unsafe.Pointer(&mtuReq))) // SIOCSIFMTU
syscall.Syscall(syscall.SYS_IOCTL, uintptr(s), 0x400c4a52, uintptr(unsafe.Pointer(&mtuReq)))
}
return ti, nil
}
@@ -63,6 +63,21 @@ func (ti *tapInterface) Close() error {
return syscall.Close(ti.fd)
}
func (ti *tapInterface) SetMAC(mac [6]byte) error {
macStr := fmt.Sprintf("%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5])
return exec.Command("ip", "link", "set", ti.Name, "address", macStr).Run()
}
func (ti *tapInterface) SetIP(cidr string) error {
if err := exec.Command("ip", "addr", "add", cidr, "dev", ti.Name).Run(); err != nil {
return fmt.Errorf("add ip: %w", err)
}
if err := exec.Command("ip", "link", "set", ti.Name, "up").Run(); err != nil {
return fmt.Errorf("link up: %w", err)
}
return nil
}
func indexOfZero(s string) int {
for i, c := range []byte(s) {
if c == 0 {