nfx/slrp

Configuration from PWD/config.yml read, but not applied

aslian opened this issue · 1 comments

Platform info

Hello. I'm using

OS:

$ cat /etc/lsb-release /etc/upstream-release/lsb-release 
DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=18.1
DISTRIB_CODENAME=serena
DISTRIB_DESCRIPTION="Linux Mint 18.1 Serena"
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04 LTS"

Kernel:

$ uname -a
Linux linux 4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Binary from: https://github.com/nfx/slrp/releases/download/v0.0.7/slrp_0.0.7_linux_amd64.tar.gz

Expected behaviour

  1. I place the following configuration (taken from README.md) in $PWD/config.yml:
$ cat config.yml 
app:
    state: $HOME/.slrp/data
    sync: 1m
log:
    level: warn
    format: pretty
server:
    addr: "localhost:8089"
    read_timeout: 15s
    enable_profiler: false
mitm:
    addr: "0.0.0.0:8090"
    read_timeout: 15s
    idle_timeout: 15s
    write_timeout: 15s
checker:
    timeout: 5s
    strategy: simple
history:
    limit: 1000

Log level and listen address are changed here.

  1. Configuration is read and applied.

Observed behaviour

  1. Configuration is being ignored by app.
$ strace -o debug -y -yy -yyy -s 2000 -vf ./slrp
slrp v0.0.7
6:39PM INF loaded service=probe
6:39PM INF loaded service=pool
6:39PM INF loaded service=stats
6:39PM INF starting service=server
6:39PM INF starting service=mitm
6:39PM INF started refresh source=checkerproxy.net
6:39PM INF Loading proxy checker database
6:39PM INF started refresh source=proxylists.net
^C
$ ag -v getdent debug | ag '\.yml|8090'
1619:29035 openat(AT_FDCWD, "/home/user/tmp/slrp/slrp.yml", O_RDONLY|O_CLOEXEC <unfinished ...>
1623:29035 openat(AT_FDCWD, "/home/user/tmp/slrp/config.yml", O_RDONLY|O_CLOEXEC <unfinished ...>
1625:29035 <... openat resumed> )            = 9</home/user/tmp/slrp/config.yml>
1626:29035 epoll_ctl(4<anon_inode:[eventpoll]>, EPOLL_CTL_ADD, 9</home/user/tmp/slrp/config.yml>, {EPOLLIN|EPOLLOUT|EPOLLRDHUP|EPOLLET, {u32=2547521208, u64=140654136530616}}) = -1 EPERM (Operation not permitted)
1627:29035 fstat(9</home/user/tmp/slrp/config.yml>, {st_dev=makedev(8, 18), st_ino=8674353, st_mode=S_IFREG|0644, st_nlink=1, st_uid=1000, st_gid=1000, st_blksize=4096, st_blocks=8, st_size=339, st_atime=2022/08/19-18:38:41, st_mtime=2022/08/19-18:32:44, st_ctime=2022/08/19-18:38:16}) = 0
1628:29035 read(9</home/user/tmp/slrp/config.yml>, "app:\n    state: $HOME/.slrp/data\n    sync: 1m\nlog:\n    level: warn\n    format: pretty\nserver:\n    addr: \"localhost:8089\"\n    read_timeout: 15s\n    enable_profiler: false\nmitm:\n    addr: \"0.0.0.0:8090\"\n    read_timeout: 15s\n    idle_timeout: 15s\n    write_timeout: 15s\nchecker:\n    timeout: 5s\n    strategy: simple\nhistory:\n    limit: 1000\n", 512) = 339
1629:29035 read(9</home/user/tmp/slrp/config.yml>, "", 173) = 0
1630:29035 close(9</home/user/tmp/slrp/config.yml>) = 0
1631:29035 openat(AT_FDCWD, "/home/user/.slrp/config.yml", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
3535:29044 bind(3<TCP:[43385928]>, {sa_family=AF_INET, sin_port=htons(8090), sin_addr=inet_addr("127.0.0.1")}, 16 <unfinished ...>
3543:29044 epoll_ctl(4<anon_inode:[eventpoll]>, EPOLL_CTL_ADD, 3<TCP:[127.0.0.1:8090]>, {EPOLLIN|EPOLLOUT|EPOLLRDHUP|EPOLLET, {u32=2547521208, u64=140654136530616}} <unfinished ...>
3547:29044 getsockname(3<TCP:[127.0.0.1:8090]>,  <unfinished ...>
3549:29044 <... getsockname resumed> {sa_family=AF_INET, sin_port=htons(8090), sin_addr=inet_addr("127.0.0.1")}, [16]) = 0
3851:29041 accept4(3<TCP:[127.0.0.1:8090]>,  <unfinished ...>

From the trace it's obvivous that

  1. App successfully finds the config.
  2. App successfully reads the config.
  3. But it got ignored: it start listening at default IP address, not one included in config.

When the same config file is moved to ~/.slrp/ it work like expected.

$ mv config.yml ~/.slrp/

$ strace -o debug -y -yy -yyy -s 2000 -vf ./slrp 
slrp v0.0.7
^C

$ ag -v getdent debug | ag '8090'
1443:2412  read(9</home/user/.slrp/config.yml>, "app:\n    state: $HOME/.slrp/data\n    sync: 1m\nlog:\n    level: warn\n    format: pretty\nserver:\n    addr: \"localhost:8089\"\n    read_timeout: 15s\n    enable_profiler: false\nmitm:\n    addr: \"0.0.0.0:8090\"\n    read_timeout: 15s\n    idle_timeout: 15s\n    write_timeout: 15s\nchecker:\n    timeout: 5s\n    strategy: simple\nhistory:\n    limit: 1000\n", 512) = 339
3617:2422  bind(3<TCPv6:[43449405]>, {sa_family=AF_INET6, sin6_port=htons(8090), inet_pton(AF_INET6, "::", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, 28 <unfinished ...>
3624:2422  epoll_ctl(4<anon_inode:[eventpoll]>, EPOLL_CTL_ADD, 3<TCPv6:[:::8090]>, {EPOLLIN|EPOLLOUT|EPOLLRDHUP|EPOLLET, {u32=4270608472, u64=140230657855576}} <unfinished ...>
3627:2422  getsockname(3<TCPv6:[:::8090]>,  <unfinished ...>
3629:2422  <... getsockname resumed> {sa_family=AF_INET6, sin6_port=htons(8090), inet_pton(AF_INET6, "::", &sin6_addr), sin6_flowinfo=0, sin6_scope_id=0}, [28]) = 0
3869:2422  accept4(3<TCPv6:[:::8090]>,  <unfinished ...>
8090:2412  read(111<TCP:[192.168.1.230:45866->103.117.192.14:80]>,  <unfinished ...>
nfx commented

interesting, need to add more test cases for config resolution part. currently app package is not unit tested.

PRs with fixes are always welcome!