~bigbes/shroud

ref: 3394139df40339ebdae50f853d922c14fca77c35 shroud/internal/awgserver/tun_linux.go -rw-r--r-- 598 bytes
3394139d — Eugene Blikh docs: update README with VLESS+REALITY, CI/CD site deployment a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//go:build linux

package awgserver

import (
	"fmt"
	"log/slog"
	"os/exec"
)

func setTUNAddress(tunName, address string, logger *slog.Logger) error {
	cmd := exec.Command("ip", "addr", "add", address, "dev", tunName)
	if out, err := cmd.CombinedOutput(); err != nil {
		return fmt.Errorf("ip addr add: %s: %w", string(out), err)
	}
	cmd = exec.Command("ip", "link", "set", "up", "dev", tunName)
	if out, err := cmd.CombinedOutput(); err != nil {
		return fmt.Errorf("ip link set up: %s: %w", string(out), err)
	}
	logger.Info("TUN configured.", "name", tunName, "address", address)
	return nil
}