Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the container configurable via env variable; update documentation #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 1 addition & 52 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,52 +1 @@
# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
*.tar
16 changes: 1 addition & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
FROM alpine AS builder
ARG MDNS_REPEATER_VERSION=local
ADD mdns-repeater.c mdns-repeater.c
RUN set -ex && \
apk add build-base && \
gcc -o /bin/mdns-repeater mdns-repeater.c -DMDNS_REPEATER_VERSION=\"${MDNS_REPEATER_VERSION}\"

FROM alpine

RUN set -ex && \
apk add vlan libcap bash
COPY --from=builder /bin/mdns-repeater /bin/mdns-repeater
RUN chmod +x /bin/mdns-repeater
RUN setcap cap_net_raw=+ep /bin/mdns-repeater
FROM monstrenyatko/mdns-repeater

COPY run.sh /app/
RUN chmod +x /app/run.sh

ENTRYPOINT ["/app/run.sh"]
CMD ["/bin/mdns-repeater", "-f", "eth0.20", "eth0.100"]
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
container_name := mdns-repeater
repo_name := mag1024/mikrotik-docker-mdns-repeater

default: container/arm64
all: container/arm64 container/arm-v6
clean:
rm -f *.tar

container/%:
docker buildx build --load --platform linux/$(subst -,/,$*) -t $(container_name) .
docker save $(container_name) -o $(container_name)-$*.tar

push:
docker buildx build --platform linux/arm64,linux/arm/v6 --push github.com/$(repo_name) -t $(repo_name):latest
125 changes: 58 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,73 @@
# DEPRECATED
As of RouterOS 7.16, Mikrotik now has a built-in mDNS repeater implementation: e.g.
`/ip/dns/set mdns-repeat-ifaces=bridge,vlan-iot`

# docker-mdns-repeater-mikrotik
mdns-repeater in mikrotik container
An mDNS repeater that can run as a container on Mikrotik routers.

Based on:
https://github.com/geekman/mdns-repeater
https://github.com/monstrenyatko/docker-mdns-repeater
* [geekman/mdns-repeater](https://github.com/geekman/mdns-repeater)
* [monstrenyatko/docker-mdns-repeater](https://github.com/monstrenyatko/docker-mdns-repeater)
* [TheMickeyMike/docker-mdns-repeater-mikrotik](https://github.com/TheMickeyMike/docker-mdns-repeater-mikrotik)

This is work in progress, but you can base your config on that.
Images availabe on Dockerhub at [mag1024/mikrotik-docker-mdns-repeater](https://hub.docker.com/repository/docker/mag1024/mikrotik-docker-mdns-repeater).

## Mikrotik config
Based on official docs https://help.mikrotik.com/docs/display/ROS/Container
Instead of adding `veth2` to docker bridge i've added it to my home-lan bridge `BR1`.
Veth2 is added as tagged port with two vlans (20,100), so in container on `eth0` i will create two vlan interfaces `eth0.20` and `eth0.100` with active dhcp client for IP leese, please look at `run.sh`.
## How it works
As of Oct 2022, the Mikrotik container implementation is limited to exactly one
network interface. There is no option for an equivalent of 'host' mode
networking, and the interface must be of type veth, so we have to get creative
to get a functional repeater. The key is to attach the veth to a trunk bridge
that contains multiple vlans corresponding to the networks we want to repeat
across, and then create interfaces for each of the vlans inside the container,
using the veth as the parent. The set of vlans/interfaces to use is specified
via the _REPEATER_INTERFACES_ env variable, and the container runs a dhcp client
to obtain an IP for each of them.

```
/interface/bridge/port/print
Flags: I - INACTIVE; H - HW-OFFLOAD
Columns: INTERFACE, BRIDGE, HW, PVID, PRIORITY, PATH-COST, INTERNAL-PATH-COST, HOR
IZON
# INTERFACE BRIDGE HW PVID PRIORITY PATH-COST IN HORIZON
10 veth2 BR1 1 0x80 10 10 none
## Setup
Begin by following the [Mikrotik container
documentation](https://help.mikrotik.com/docs/display/ROS/Container) to create
the veth interface. Instead of creating a separate docker bridge, assign the
new interface as a 'tagged' port to the bridge containing the interfaces you
wish to repeat across. These interfaces can be vlan interfaces, or physical
interfaces with pvid set -- depending on whether you use vlans for the rest of
your network setup. Refer to the [Mikrotik bridge
documentation](https://help.mikrotik.com/docs/display/ROS/Bridge+VLAN+Table) for
more details.

The following example uses _veth-trunk_ veth interface and _br-trunk_ bridge,
configured with vlans 10, 11, 12.

Note: The address here does not matter, but it must have one to make the
interface 'active'.
```
/interface/veth/print
Flags: X - disabled; R - running
0 R name="veth-trunk" address=10.200.200.200/24 gateway=10.200.200.1
```

/interface/bridge/vlan/print
Flags: D - DYNAMIC
Columns: BRIDGE, VLAN-IDS, CURRENT-TAGGED, CURRENT-UNTAGGED
# BRIDGE VLAN-IDS CURRENT-TAGGED CURRENT-UNTAGGED
0 BR1 100 BR1
veth2
3 BR1 20 BR1
veth2
4 D BR1 1 BR1
veth2
Note: Again, pvid of the _veth_ itself does not matter.
```
/interface/bridge/port/print
Flags: I - INACTIVE; H - HW-OFFLOAD
Columns: INTERFACE, BRIDGE, HW, PVID, PRIORITY, PATH-COST, INTERNAL-PATH-COST, HORIZON
# INTERFACE BRIDGE HW PVID PRIORITY PATH-COST INTERNAL-PATH-COST HORIZON
0 H ether2 br-trunk yes 10 0x80 10 10 none
1 H ether3 br-trunk yes 13 0x80 10 10 none
...
8 veth-trunk br-trunk 111 0x80 10 10 none
```

## Build & pack container
Note: The name of the interface inside the container is always _eth0_.
```
docker buildx build --no-cache --platform linux/arm/v6 -t mdns .
docker save mdns -o mdns.tar
8.8M mdns.tar # size after pack
/container/envs/print
0 name="repeater_envs" key="REPEATER_INTERFACES" value="eth0.10 eth0.11 eth0.12"
```

## Logs from running container
Note: you may have to set the registry first via `/container/config/set registry-url=https://registry-1.docker.io`.
Note: `start-on-boot` is only available on Mikrotik 7.6+
```
log print where topics~"container"
jun/29 22:01:28 container,info,debug create interface eth0.20
jun/29 22:01:28 container,info,debug bring up eth0.20 interface
jun/29 22:01:28 container,info,debug /app/run.sh: line 25: kill: (19) - No such process
jun/29 22:01:28 container,info,debug starting dhcp client on eth0.20
jun/29 22:01:28 container,info,debug udhcpc: started, v1.35.0
jun/29 22:01:29 container,info,debug udhcpc: broadcasting discover
jun/29 22:01:29 container,info,debug udhcpc: broadcasting select for 10.0.20.27, server 10.0.20.1
jun/29 22:01:29 container,info,debug udhcpc: lease of 10.0.20.27 obtained from 10.0.20.1, lease time 86400
jun/29 22:01:29 container,info,debug create interface eth0.100
jun/29 22:01:29 container,info,debug bring up eth0.100 interface
jun/29 22:01:29 container,info,debug /app/run.sh: line 25: kill: (34) - No such process
jun/29 22:01:29 container,info,debug starting dhcp client on eth0.100
jun/29 22:01:29 container,info,debug udhcpc: started, v1.35.0
jun/29 22:01:29 container,info,debug udhcpc: broadcasting discover
jun/29 22:01:30 container,info,debug udhcpc: broadcasting select for 10.0.100.244, server 10.0.100.1
jun/29 22:01:30 container,info,debug udhcpc: lease of 10.0.100.244 obtained from 10.0.100.1, lease time 86400
jun/29 22:01:30 container,info,debug + exec /bin/mdns-repeater -f eth0.20 eth0.100
jun/29 22:01:30 container,info,debug mdns-repeater: dev eth0.20 addr 10.0.20.27 mask 255.255.255.0 net 10.0.20.0
jun/29 22:01:30 container,info,debug mdns-repeater: dev eth0.100 addr 10.0.100.244 mask 255.255.255.0 net 10.0.100.0
jul/01 21:49:34 container,info,debug bring up eth0.20 interface
jul/01 21:49:34 container,info,debug /app/run.sh: line 25: kill: (22) - No such process
jul/01 21:49:34 container,info,debug starting dhcp client on eth0.20
jul/01 21:49:34 container,info,debug udhcpc: started, v1.35.0
jul/01 21:49:34 container,info,debug udhcpc: broadcasting discover
jul/01 21:49:34 container,info,debug udhcpc: broadcasting select for 10.0.20.27, server 10.0.20.1
jul/01 21:49:34 container,info,debug udhcpc: lease of 10.0.20.27 obtained from 10.0.20.1, lease time 86400
jul/01 21:49:34 container,info,debug bring up eth0.100 interface
jul/01 21:49:34 container,info,debug /app/run.sh: line 25: kill: (40) - No such process
jul/01 21:49:34 container,info,debug starting dhcp client on eth0.100
jul/01 21:49:34 container,info,debug udhcpc: started, v1.35.0
jul/01 21:49:34 container,info,debug udhcpc: broadcasting discover
jul/01 21:49:35 container,info,debug udhcpc: broadcasting select for 10.0.100.244, server 10.0.100.1
jul/01 21:49:35 container,info,debug udhcpc: lease of 10.0.100.244 obtained from 10.0.100.1, lease time 86400
jul/01 21:49:35 container,info,debug + exec /bin/mdns-repeater -f eth0.20 eth0.100
jul/01 21:49:35 container,info,debug mdns-repeater: dev eth0.20 addr 10.0.20.27 mask 255.255.255.0 net 10.0.20.0
jul/01 21:49:35 container,info,debug mdns-repeater: dev eth0.100 addr 10.0.100.244 mask 255.255.255.0 net 10.0.100.0
/container/print
0 ... tag="mag1024/mikrotik-docker-mdns-repeater:latest" os="linux"
arch="arm64" interface=veth-trunk envlist="repeater_envs" mounts="" dns="" hostname="mdns-repeater" logging=yes
start-on-boot=yes status=running
```
Loading