refactor: extract session/netcfg/tunnel, add mac/dhcp/policy-route flags

- Split cmd/softether-go into main.go (flags, reconnect loop) and
  session.go (session lifecycle, DHCP orchestration)
- Extract network config to pkg/netcfg (TAP config, routing, DNS, policy routes)
- Move frame bridging to pkg/client/tunnel.go as Bridge() method
- Add -mac, -dhcp, -policy-route-table CLI flags
- Add SetMAC() to pkg/tap for deterministic DHCP assignments
- Update all docs to reflect new structure and flags

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Git Sagar 2026-06-06 16:43:12 +05:30
parent 846ed96ff4
commit 17c1063e1f
10 changed files with 495 additions and 332 deletions

View file

@ -106,6 +106,27 @@ func (d *Device) MAC() (net.HardwareAddr, error) {
return mac, nil
}
// SetMAC sets the hardware (MAC) address of the TAP interface.
func (d *Device) SetMAC(mac net.HardwareAddr) error {
sock, err := unix.Socket(unix.AF_INET, unix.SOCK_DGRAM, 0)
if err != nil {
return fmt.Errorf("socket: %w", err)
}
defer unix.Close(sock)
var ifr [40]byte
copy(ifr[:ifnameSize], d.Name)
ifr[ifnameSize] = 1 // sa_family = ARPHRD_ETHER
ifr[ifnameSize+1] = 0
copy(ifr[ifnameSize+2:ifnameSize+8], mac)
_, _, errno := unix.Syscall(unix.SYS_IOCTL, uintptr(sock), unix.SIOCSIFHWADDR, uintptr(unsafe.Pointer(&ifr[0])))
if errno != 0 {
return fmt.Errorf("SIOCSIFHWADDR: %w", errno)
}
return nil
}
// SetUp brings the TAP interface up (equivalent to `ip link set <name> up`).
func (d *Device) SetUp() error {
sock, err := unix.Socket(unix.AF_INET, unix.SOCK_DGRAM, 0)