Skip to content

Commit

Permalink
Merge pull request #48 from synfinatic/startup
Browse files Browse the repository at this point in the history
Add startup scripts for pfSense & UDM/UDMPro & Docker
  • Loading branch information
synfinatic authored Jan 18, 2021
2 parents ce6b4e1 + bdb84a3 commit 65ac448
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 4 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@

## Unreleased

## v0.0.6 - ??-??-2020
## v0.0.6 - 2021-01-18

Added:
- Support for cross-compiling arm64/Linux for RasPi/Ubiquiti UDM(Pro) #31
- Support Site-to-Site OpenVPN tunnels via --fixed-ip #41
- Add startup scripts for pfSense/BSD and link to tooling for Ubiquiti Dream
Machine (Pro)
- Add docker image for running udp-proxy-2020 in a container
- Add docker-compose support

Fixed:
- Vagrant file for FreeBSD now always builds the latest code #39

## v0.0.5 - 16-10-2020
## v0.0.5 - 2020-10-16

Added:

- Support for Wireguard (LinkType RAW) interfaces #29
- Add str2pcap for improved debugging of logs

## v0.0.4 - 02-10-2020
## v0.0.4 - 2020-10-02

Initial release
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM golang:1.15.5-alpine3.12 as builder

ARG VERSION

# base applications
RUN apk add --update git build-base libpcap libpcap-dev && \
mkdir udp-proxy-2020
COPY . udp-proxy-2020/

RUN cd udp-proxy-2020 && \
DOCKER_VERSION=${VERSION} make .docker && \
mkdir -p /usr/local/bin && \
cp dist/udp-proxy-2020 /usr/local/bin/udp-proxy-2020

FROM alpine:3.12
RUN apk add --update libpcap && \
mkdir -p /usr/local/bin
COPY --from=builder /usr/local/bin/udp-proxy-2020 /usr/local/bin/

ENV PORTS=9003
ENV INTERFACES=""
ENV TIMEOUT=250
ENV CACHETTL=90
ENV EXTRA_ARGS=""
CMD /usr/local/bin/udp-proxy-2020 --port ${PORTS} --interface ${INTERFACES} \
--timeout ${TIMEOUT} --cachettl ${CACHETTL} ${EXTRA_ARGS}
26 changes: 25 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $(STR2PCAP_NAME): str2pcap/*.go

include help.mk # place after ALL target and before all other targets

release: linux-amd64 linux-mips64 linux-arm64 $(OUTPUT_NAME) freebsd ## Build our release binaries
release: linux-amd64 linux-mips64 linux-arm64 $(OUTPUT_NAME) freebsd docker ## Build our release binaries

.PHONY: run
run: cmd/*.go ## build and run udp-proxy-2020 using $UDP_PROXY_2020_ARGS
Expand Down Expand Up @@ -223,3 +223,27 @@ $(LINUX_ARM64_S_NAME): .prepare
linux-arm64-clean: ## Remove Linux/arm64 Docker image
docker image rm $(DOCKER_REPO)/$(PROJECT_NAME)-arm64:latest
rm dist/*linux-arm64


DOCKER_VERSION ?= v$(PROJECT_VERSION)
.PHONY: docker
docker: ## Build docker image
docker build -t $(DOCKER_REPO)/$(PROJECT_NAME):$(DOCKER_VERSION) \
--build-arg VERSION=$(DOCKER_VERSION) \
-f Dockerfile .

.docker:
CGO_ENABLED=1 \
go build -ldflags '$(LDFLAGS)' -o dist/udp-proxy-2020 cmd/*.go

docker-shell: ## get a shell in the docker image
docker run --rm -it --network=host \
$(DOCKER_REPO)/$(PROJECT_NAME):$(DOCKER_VERSION) \
/bin/sh

docker-relelase: docker ## Tag latest and push docker images
docker push $(DOCKER_REPO)/$(PROJECT_NAME):$(DOCKER_VERSION)
docker tag $(DOCKER_REPO)/$(PROJECT_NAME):$(DOCKER_VERSION) $(DOCKER_REPO)/$(PROJECT_NAME):latest
docker push $(DOCKER_REPO)/$(PROJECT_NAME):latest


6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ Currently there are only a few flags you probaly need to worry about:

There are other flags of course, run `./udp-proxy-2020 --help` for a full list.

## Installation & Startup Scripts

There are now instructions and startup scripts available in the [startup-scripts](
startup-scripts) directory. If you figure out how to add support for another
platform, please send me a pull request!

## FAQ

### So is it a "proxy"? Are there any proxy config settings I need to configure in my app?
Expand Down
4 changes: 4 additions & 0 deletions startup-scripts/Docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Docker

Just edit `docker-compose.yaml` and modify the environment variables as necessary
and then run `docker-compose up` to start!
12 changes: 12 additions & 0 deletions startup-scripts/Docker/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3.3'
services:
udp-proxy-2020:
image: synfinatic/udp-proxy-2020:latest
environment:
- PORTS=9003
- INTERFACES=eth0,eth1
- EXTRA_ARGS="--debug"
- TIMEOUT=250
- CACHETTL=90
restart: always
network_mode: host
9 changes: 9 additions & 0 deletions startup-scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Startup Scripts

Since UDP Proxy 2020 tends to run on non-standard hardware (firewalls mostly)
I'm creating a collection of startup scripts for different platforms to
make it easier to auto-start the program on boot.

* [pfSense](pfSense) - Used for pfSense and probably many BSD-based operating systems
* [Ubiquiti Dream Machine/Dream Machine Pro](https://github.com/boostchicken/udm-utilities) - Use UDM Utilities
* [Docker](Docker) - Use [Docker Compose](https://docs.docker.com/compose/) to run udp-proxy-2020
12 changes: 12 additions & 0 deletions startup-scripts/pfSense/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# pfSense/BSD startup scripts

## Configuration

1. Edit `etc/local/etc/udp-proxy-2020.conf` as necessary
1. Copy files to the directories on your pfSense/BSD box
1. Edit `/etc/rc.conf.local` and add the line `udp_proxy_2020_enable=YES`
1. Copy udp-proxy-2020 binary to `/usr/local/etc/bin/udp-proxy-2020`

## Run

Execute `/usr/local/etc/rc.d/udp-proxy-2020 start`
1 change: 1 addition & 0 deletions startup-scripts/pfSense/etc/rc.conf.local
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
udp_proxy_2020_enable=YES
46 changes: 46 additions & 0 deletions startup-scripts/pfSense/usr/local/etc/rc.d/udp-proxy-2020
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: udp-proxy-2020
# REQUIRE: DAEMON NETWORKING
#
# Add the following lines to /etc/rc.conf.local to enable UDP Proxy 2020
#
# udp_proxy_2020_enable="YES"
#

. /etc/rc.subr
. /usr/local/etc/udp-proxy-2020.conf

name=udp-proxy-2020
rcvar=udp_proxy_2020_enable
pidfile=/var/run/udp-proxy-2020.pid

extra_commands="status cleanup"
start_cmd="${name}_start"
stop_cmd="${name}_stop"
status_cmd="${name}_status"
cleanup_cmd="${name}_cleanup"

load_rc_config ${name}
: ${udp_proxy_2020_enable:=no}


udp-proxy-2020_start() {
/usr/sbin/daemon -cf -p ${pidfile} /usr/local/bin/udp-proxy-2020 ${udp_vars}
}

udp-proxy-2020_stop() {
[ -f ${pidfile} ] && kill `cat ${pidfile}` || echo "Unable to kill ${name}. Missing pid file?"
}

udp-proxy-2020_cleanup() {
[ -f ${pidfile} ] && rm ${pidfile}
}

udp-proxy-2020_status() {
[ ! -n "`pgrep -F $(pidfile)`" ]
}

run_rc_command "$1"
2 changes: 2 additions & 0 deletions startup-scripts/pfSense/usr/local/etc/udp-proxy-2020.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# change the port and add --dev {dev-name} as many times as needed.
udp_vars="--port 9003 --interface lagg0,lagg0.200,lagg0.400,ovpns2"

0 comments on commit 65ac448

Please sign in to comment.