Skip to content

Commit

Permalink
Merge branch 'main' into gray/dae0-sysctl
Browse files Browse the repository at this point in the history
  • Loading branch information
sumire88 authored Jan 22, 2024
2 parents 3df979c + db8f474 commit 89585b1
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func init() {
rootCmd.Version = strings.Join([]string{
Version,
fmt.Sprintf("go runtime %v %v/%v", runtime.Version(), runtime.GOOS, runtime.GOARCH),
"Copyright (c) 2022-2024 dae",
"Copyright (c) 2022-2024 @daeuniverse",
"License GNU AGPLv3 <https://github.com/daeuniverse/dae/blob/main/LICENSE>",
}, "\n")
}
Expand Down
27 changes: 16 additions & 11 deletions control/anyfrom_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func (a *Anyfrom) afterWrite(err error) {
a.RefreshTtl()
}
func (a *Anyfrom) RefreshTtl() {
a.deadlineTimer.Reset(a.ttl)
if a.deadlineTimer != nil {
a.deadlineTimer.Reset(a.ttl)
}
}
func (a *Anyfrom) SupportGso(size int) bool {
if size > math.MaxUint16 {
Expand Down Expand Up @@ -202,16 +204,19 @@ func (p *AnyfromPool) GetOrCreate(lAddr string, ttl time.Duration) (conn *Anyfro
gotGSOError: false,
gso: isGSOSupported(uConn),
}
af.deadlineTimer = time.AfterFunc(ttl, func() {
p.mu.Lock()
defer p.mu.Unlock()
_af := p.pool[lAddr]
if _af == af {
delete(p.pool, lAddr)
af.Close()
}
})
p.pool[lAddr] = af

if ttl > 0 {
af.deadlineTimer = time.AfterFunc(ttl, func() {
p.mu.Lock()
defer p.mu.Unlock()
_af := p.pool[lAddr]
if _af == af {
delete(p.pool, lAddr)
af.Close()
}
})
p.pool[lAddr] = af
}
return af, true, nil
} else {
af.RefreshTtl()
Expand Down
7 changes: 6 additions & 1 deletion control/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ func sendPkt(log *logrus.Logger, data []byte, from netip.AddrPort, realTo, to ne
return sendPktWithHdrWithFlag(data, from, lConn, to, lanWanFlag)
}

uConn, _, err := DefaultAnyfromPool.GetOrCreate(from.String(), AnyfromTimeout)
transparentTimeout := AnyfromTimeout
if from.Port() == 53 {
// Add port 53 (udp) to whitelist to avoid conflicts with the potential local dns server.
transparentTimeout = 0
}
uConn, _, err := DefaultAnyfromPool.GetOrCreate(from.String(), transparentTimeout)
if err != nil && errors.Is(err, syscall.EADDRINUSE) {
log.WithField("from", from).
WithField("to", to).
Expand Down
73 changes: 73 additions & 0 deletions docs/en/tutorials/run-on-centos7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Run on CentOS 7

> [!WARNING]
> CentOS 7 and RHEL 6.5/7 do not support eBPF out of the box; in other words, you must build the kernel (>= 5.8) yourself and install it.
## Introduction

CentOS 7 is a veteran Linux distribution, although its life cycle is not long, but there should still be some people using it. This article documents the steps to run dae on CentOS 7 or RHEL 6.5.

## Upgrade process

### Updating the kernel

Update the kernel that supports `BTF`

```bash
curl -s https://repo.cooluc.com/mailbox.repo > /etc/yum.repos.d/mailbox.repo
yum makecache
yum update kernel
```

> [!NOTE]
> The kernel is based on Linux 6.1 LTS, rebuilt to support `BBRv2`, and enables `eBPF` support. It can also be compiled by yourself, and the source package is available at <https://repo.cooluc.com/kernel/7/SRPMS/>
### Mount BPF

```bash
curl -s https://repo.cooluc.com/kernel/files/sys-fs-bpf.mount > /etc/systemd/system/sys-fs-bpf.mount
systemctl enable sys-fs-bpf.mount
```

### Mount Control Group v2

```bash
curl -s https://repo.cooluc.com/kernel/mount-cgroup2.service > /etc/systemd/system/mount-cgroup2.service
systemctl enable mount-cgroup2.service
```

### Reboot the system to make the kernel effective

> [!NOTE]
> Check the kernel version. If the version is `6.1.xx-1.el7.x86_64`, it means that the operation is successful.
```bash
uname -r
```

If the kernel version does not change, it means that the kernel has been updated before, and you need to rebuild the grub2 bootloader to make the new kernel the highest priority.

To set the latest kernel as the default:

```bash
grub2-set-default 0
```

To rebuild the kernel bootloader configuration:

```bash
grub2-mkconfig -o /boot/grub2/grub.cfg
```

### Running dae

Now you can download dae and run it as usual

```bash
mkdir -p /opt/dae && cd /opt/dae
wget https://github.com/daeuniverse/dae/releases/download/v0.2.2/dae-linux-x86_64.zip
unzip dae-linux-x86_64.zip && rm -f dae-linux-x86_64.zip
cp example.dae config.dae
chmod 600 config.dae
DAE_LOCATION_ASSET=$(pwd) ./dae-linux-x86_64 run -c config.dae
```

0 comments on commit 89585b1

Please sign in to comment.