From bddff706610835ab23d108b0ce8b3ba3856fbb01 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Mon, 23 May 2016 13:31:30 +0800 Subject: [PATCH] Refine ss-nat scripts --- src/Makefile.am | 1 + src/Makefile.in | 60 ++++++++++++++++++++++++++++++------ debian/ss-rule => src/ss-nat | 44 +++++++++++++++----------- 3 files changed, 77 insertions(+), 28 deletions(-) rename debian/ss-rule => src/ss-nat (76%) diff --git a/src/Makefile.am b/src/Makefile.am index a258603e..66578ce7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -85,6 +85,7 @@ ss_tunnel_SOURCES += win32.c endif if BUILD_REDIRECTOR +bin_SCRIPTS = ss-nat bin_PROGRAMS += ss-redir ss_redir_SOURCES = utils.c \ jconf.c \ diff --git a/src/Makefile.in b/src/Makefile.in index 15d60b32..a7fead60 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -16,6 +16,7 @@ + VPATH = @srcdir@ am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' am__make_running_with_option = \ @@ -147,7 +148,7 @@ am__uninstall_files_from_dir = { \ $(am__cd) "$$dir" && rm -f $$files; }; \ } am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" \ - "$(DESTDIR)$(includedir)" + "$(DESTDIR)$(bindir)" "$(DESTDIR)$(includedir)" LTLIBRARIES = $(lib_LTLIBRARIES) am__DEPENDENCIES_1 = am__DEPENDENCIES_2 = $(top_builddir)/libipset/libipset.la \ @@ -243,6 +244,7 @@ ss_tunnel_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \ ss_tunnel_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(ss_tunnel_CFLAGS) \ $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +SCRIPTS = $(bin_SCRIPTS) AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false @@ -468,6 +470,7 @@ ss_local_CFLAGS = $(AM_CFLAGS) -DMODULE_LOCAL ss_tunnel_CFLAGS = $(AM_CFLAGS) -DMODULE_TUNNEL ss_server_CFLAGS = $(AM_CFLAGS) -DMODULE_REMOTE ss_manager_CFLAGS = $(AM_CFLAGS) -DMODULE_MANAGER +@BUILD_REDIRECTOR_TRUE@bin_SCRIPTS = ss-nat @BUILD_REDIRECTOR_TRUE@ss_redir_SOURCES = utils.c \ @BUILD_REDIRECTOR_TRUE@ jconf.c \ @BUILD_REDIRECTOR_TRUE@ json.c \ @@ -627,6 +630,41 @@ ss-server$(EXEEXT): $(ss_server_OBJECTS) $(ss_server_DEPENDENCIES) $(EXTRA_ss_se ss-tunnel$(EXEEXT): $(ss_tunnel_OBJECTS) $(ss_tunnel_DEPENDENCIES) $(EXTRA_ss_tunnel_DEPENDENCIES) @rm -f ss-tunnel$(EXEEXT) $(AM_V_CCLD)$(ss_tunnel_LINK) $(ss_tunnel_OBJECTS) $(ss_tunnel_LDADD) $(LIBS) +install-binSCRIPTS: $(bin_SCRIPTS) + @$(NORMAL_INSTALL) + @list='$(bin_SCRIPTS)'; test -n "$(bindir)" || list=; \ + if test -n "$$list"; then \ + echo " $(MKDIR_P) '$(DESTDIR)$(bindir)'"; \ + $(MKDIR_P) "$(DESTDIR)$(bindir)" || exit 1; \ + fi; \ + for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + if test -f "$$d$$p"; then echo "$$d$$p"; echo "$$p"; else :; fi; \ + done | \ + sed -e 'p;s,.*/,,;n' \ + -e 'h;s|.*|.|' \ + -e 'p;x;s,.*/,,;$(transform)' | sed 'N;N;N;s,\n, ,g' | \ + $(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1; } \ + { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \ + if ($$2 == $$4) { files[d] = files[d] " " $$1; \ + if (++n[d] == $(am__install_max)) { \ + print "f", d, files[d]; n[d] = 0; files[d] = "" } } \ + else { print "f", d "/" $$4, $$1 } } \ + END { for (d in files) print "f", d, files[d] }' | \ + while read type dir files; do \ + if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \ + test -z "$$files" || { \ + echo " $(INSTALL_SCRIPT) $$files '$(DESTDIR)$(bindir)$$dir'"; \ + $(INSTALL_SCRIPT) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \ + } \ + ; done + +uninstall-binSCRIPTS: + @$(NORMAL_UNINSTALL) + @list='$(bin_SCRIPTS)'; test -n "$(bindir)" || exit 0; \ + files=`for p in $$list; do echo "$$p"; done | \ + sed -e 's,.*/,,;$(transform)'`; \ + dir='$(DESTDIR)$(bindir)'; $(am__uninstall_files_from_dir) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -1465,11 +1503,11 @@ distdir: $(DISTFILES) done check-am: all-am check: check-am -all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(HEADERS) +all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(SCRIPTS) $(HEADERS) install-binPROGRAMS: install-libLTLIBRARIES installdirs: - for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(includedir)"; do \ + for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(bindir)" "$(DESTDIR)$(includedir)"; do \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \ done install: install-am @@ -1531,7 +1569,8 @@ install-dvi: install-dvi-am install-dvi-am: -install-exec-am: install-binPROGRAMS install-libLTLIBRARIES +install-exec-am: install-binPROGRAMS install-binSCRIPTS \ + install-libLTLIBRARIES install-html: install-html-am @@ -1571,8 +1610,8 @@ ps: ps-am ps-am: -uninstall-am: uninstall-binPROGRAMS uninstall-includeHEADERS \ - uninstall-libLTLIBRARIES +uninstall-am: uninstall-binPROGRAMS uninstall-binSCRIPTS \ + uninstall-includeHEADERS uninstall-libLTLIBRARIES .MAKE: install-am install-strip @@ -1581,9 +1620,9 @@ uninstall-am: uninstall-binPROGRAMS uninstall-includeHEADERS \ clean-libtool cscopelist-am ctags ctags-am distclean \ distclean-compile distclean-generic distclean-libtool \ distclean-tags distdir dvi dvi-am html html-am info info-am \ - install install-am install-binPROGRAMS install-data \ - install-data-am install-dvi install-dvi-am install-exec \ - install-exec-am install-html install-html-am \ + install install-am install-binPROGRAMS install-binSCRIPTS \ + install-data install-data-am install-dvi install-dvi-am \ + install-exec install-exec-am install-html install-html-am \ install-includeHEADERS install-info install-info-am \ install-libLTLIBRARIES install-man install-pdf install-pdf-am \ install-ps install-ps-am install-strip installcheck \ @@ -1591,7 +1630,8 @@ uninstall-am: uninstall-binPROGRAMS uninstall-includeHEADERS \ maintainer-clean-generic mostlyclean mostlyclean-compile \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ tags tags-am uninstall uninstall-am uninstall-binPROGRAMS \ - uninstall-includeHEADERS uninstall-libLTLIBRARIES + uninstall-binSCRIPTS uninstall-includeHEADERS \ + uninstall-libLTLIBRARIES # Tell versions [3.59,3.63) of GNU make to not export all variables. diff --git a/debian/ss-rule b/src/ss-nat similarity index 76% rename from debian/ss-rule rename to src/ss-nat index 866cf4e9..7501004e 100755 --- a/debian/ss-rule +++ b/src/ss-nat @@ -13,26 +13,34 @@ FWI=$(uci get firewall.shadowsocks.path 2>/dev/null) # firewall include file usage() { cat <<-EOF - Usage: ss-rules [options] - Valid options are: + Copyright (C) 2015 OpenWrt-dist + Copyright (C) 2015 Jian Chang + + Usage: ss-nat [options] + + Valid options are: + + -s ip address of shadowsocks remote server + -l port number of shadowsocks local server + -S ip address of shadowsocks remote UDP server + -L port number of shadowsocks local UDP server + -i a file content is bypassed ip list + -a lan ip of access control, need a prefix to + define access control mode + -b wan ip of will be bypassed + -w wan ip of will be forwarded + -e extra options for iptables + -o apply the rules to the OUTPUT chain + -u enable udprelay mode, TPROXY is required + -U enable udprelay mode, using different IP + and ports for TCP and UDP + -f flush the rules + -h show this help message and exit + + This is free software, licensed under the GNU General Public License v3. + See /LICENSE for more information. - -s ip address of shadowsocks remote server - -l port number of shadowsocks local server - -S ip address of shadowsocks remote UDP server - -L port number of shadowsocks local UDP server - -i a file content is bypassed ip list - -a lan ip of access control, need a prefix to - define access control mode - -b wan ip of will be bypassed - -w wan ip of will be forwarded - -e extra options for iptables - -o apply the rules to the OUTPUT chain - -u enable udprelay mode, TPROXY is required - -U enable udprelay mode, using different IP - and ports for TCP and UDP - -f flush the rules - -h show this help message and exit EOF exit $1 }