From 9100f7e3abf3511009fa21de1e0b304cac5489d3 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 17 Oct 2023 09:06:10 +0300 Subject: [PATCH 1/7] docs: Fixup badge URLs with current GH API --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index af722be..6f5657c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # LuaSocket -[![Build](https://img.shields.io/github/workflow/status/lunarmodules/luasocket/Build?label=Build=Lua)](https://github.com/lunarmodules/luasocket/actions?workflow=Build) -[![Luacheck](https://img.shields.io/github/workflow/status/lunarmodules/luasocket/Luacheck?label=Luacheck&logo=Lua)](https://github.com/lunarmodules/luasocket/actions?workflow=Luacheck) +[![Build](https://img.shields.io/github/actions/workflow/status/lunarmodules/luasocket/build.yml?branch=master&label=Build&logo=Lua)](https://github.com/lunarmodules/luasocket/actions?workflow=Build) +[![Luacheck](https://img.shields.io/github/actions/workflow/status/lunarmodules/luasocket/luacheck.yml?branch=master&label=Luacheck&logo=Lua)](https://github.com/lunarmodules/luasocket/actions?workflow=Luacheck) [![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/lunarmodules/luasocket?label=Tag&logo=GitHub)](https://github.com/lunarmodules/luasocket/releases) [![Luarocks](https://img.shields.io/luarocks/v/lunarmodules/luasocket?label=Luarocks&logo=Lua)](https://luarocks.org/modules/lunarmodules/luasocket) From f741a88b80ffcf4de65b91ff82fc9f7865cbad0e Mon Sep 17 00:00:00 2001 From: Leso_KN Date: Mon, 23 Oct 2023 20:27:01 +0200 Subject: [PATCH 2/7] feat(tcp): Add 'bindtodevice' option (#408) --- src/options.c | 27 +++++++++++++++++++++++++++ src/options.h | 3 +++ src/tcp.c | 2 ++ 3 files changed, 32 insertions(+) diff --git a/src/options.c b/src/options.c index 657947c..3856797 100644 --- a/src/options.c +++ b/src/options.c @@ -54,6 +54,33 @@ int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps) return opt->func(L, ps); } +/*------------------------------------------------------*/ +/* binds socket to network interface */ +int opt_set_bindtodevice(lua_State *L, p_socket ps) +{ +#ifdef __APPLE__ + return luaL_error(L, "SO_BINDTODEVICE is not supported on this operating system"); +#else + const char *dev = luaL_checkstring(L, 3); + return opt_set(L, ps, SOL_SOCKET, SO_BINDTODEVICE, (char*)dev, strlen(dev)+1); +#endif +} + +int opt_get_bindtodevice(lua_State *L, p_socket ps) +{ +#ifdef __APPLE__ + return luaL_error(L, "SO_BINDTODEVICE is not supported on this operating system"); +#else + char dev[IFNAMSIZ]; + int len = sizeof(dev); + int err = opt_get(L, ps, SOL_SOCKET, SO_BINDTODEVICE, &dev, &len); + if (err) + return err; + lua_pushstring(L, dev); + return 1; +#endif +} + /*------------------------------------------------------*/ /* enables reuse of local address */ int opt_set_reuseaddr(lua_State *L, p_socket ps) diff --git a/src/options.h b/src/options.h index 456eeb5..26d6f02 100644 --- a/src/options.h +++ b/src/options.h @@ -53,6 +53,9 @@ int opt_get_tcp_keepintvl(lua_State *L, p_socket ps); int opt_set_tcp_defer_accept(lua_State *L, p_socket ps); #endif +int opt_set_bindtodevice(lua_State *L, p_socket ps); +int opt_get_bindtodevice(lua_State *L, p_socket ps); + int opt_set_keepalive(lua_State *L, p_socket ps); int opt_get_keepalive(lua_State *L, p_socket ps); diff --git a/src/tcp.c b/src/tcp.c index e84db84..f001206 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -71,6 +71,7 @@ static luaL_Reg tcp_methods[] = { /* socket option handlers */ static t_opt optget[] = { + {"bindtodevice", opt_get_bindtodevice}, {"keepalive", opt_get_keepalive}, {"reuseaddr", opt_get_reuseaddr}, {"reuseport", opt_get_reuseport}, @@ -92,6 +93,7 @@ static t_opt optget[] = { }; static t_opt optset[] = { + {"bindtodevice", opt_set_bindtodevice}, {"keepalive", opt_set_keepalive}, {"reuseaddr", opt_set_reuseaddr}, {"reuseport", opt_set_reuseport}, From 0bc8c56043e9fee5403516c62618b7d3acc5508a Mon Sep 17 00:00:00 2001 From: leso-kn Date: Mon, 23 Oct 2023 21:35:10 +0200 Subject: [PATCH 3/7] fix(core): Disable SO_BINDTODEVICE on windows Co-authored-by: Sewbacca --- src/options.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/options.c b/src/options.c index 3856797..6581cae 100644 --- a/src/options.c +++ b/src/options.c @@ -58,7 +58,7 @@ int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps) /* binds socket to network interface */ int opt_set_bindtodevice(lua_State *L, p_socket ps) { -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(__WIN32__) || defined(_MSC_VER) return luaL_error(L, "SO_BINDTODEVICE is not supported on this operating system"); #else const char *dev = luaL_checkstring(L, 3); @@ -68,7 +68,7 @@ int opt_set_bindtodevice(lua_State *L, p_socket ps) int opt_get_bindtodevice(lua_State *L, p_socket ps) { -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(__WIN32__) || defined(_MSC_VER) return luaL_error(L, "SO_BINDTODEVICE is not supported on this operating system"); #else char dev[IFNAMSIZ]; From 708e50f8e640540198a24798b1bacd349f3c11dd Mon Sep 17 00:00:00 2001 From: leso-kn Date: Fri, 27 Oct 2023 11:34:39 +0200 Subject: [PATCH 4/7] refactor(core): Replace check for SO_BINDTODEVICE support with platform independent version --- src/options.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/options.c b/src/options.c index 6581cae..9dea6bd 100644 --- a/src/options.c +++ b/src/options.c @@ -58,7 +58,7 @@ int opt_meth_getoption(lua_State *L, p_opt opt, p_socket ps) /* binds socket to network interface */ int opt_set_bindtodevice(lua_State *L, p_socket ps) { -#if defined(__APPLE__) || defined(__WIN32__) || defined(_MSC_VER) +#ifndef SO_BINDTODEVICE return luaL_error(L, "SO_BINDTODEVICE is not supported on this operating system"); #else const char *dev = luaL_checkstring(L, 3); @@ -68,7 +68,7 @@ int opt_set_bindtodevice(lua_State *L, p_socket ps) int opt_get_bindtodevice(lua_State *L, p_socket ps) { -#if defined(__APPLE__) || defined(__WIN32__) || defined(_MSC_VER) +#ifndef SO_BINDTODEVICE return luaL_error(L, "SO_BINDTODEVICE is not supported on this operating system"); #else char dev[IFNAMSIZ]; From 9c6195ea629077bd7f6bf73e3e9991c89ec5ba7e Mon Sep 17 00:00:00 2001 From: leso-kn Date: Fri, 27 Oct 2023 19:31:18 +0200 Subject: [PATCH 5/7] ci: Enable windows build --- .github/workflows/build.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ee6e1d4..432bafb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,22 +13,27 @@ jobs: fail-fast: false matrix: luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit", "luajit-openresty" ] - platform: [ "ubuntu-20.04", "macos-11" ] # "windows-2022" not supported by gh-actions-lua + platform: [ "ubuntu-20.04", "macos-11", "windows-2022" ] runs-on: ${{ matrix.platform }} steps: - name: Checkout uses: actions/checkout@v3 + - name: Setup ’msvc’ + uses: ilammy/msvc-dev-cmd@v1 + if: ${{ !startsWith(matrix.luaVersion, 'luajit') }} - name: Setup ‘lua’ - uses: leafo/gh-actions-lua@v9 + uses: leso-kn/gh-actions-lua@v11-staging with: luaVersion: ${{ matrix.luaVersion }} - name: Setup ‘luarocks’ - uses: leafo/gh-actions-luarocks@v4 + uses: hishamhm/gh-actions-luarocks@master - name: Make and install run: | - export DEBUG=DEBUG luarocks make -- luasocket-scm-3.rockspec + env: + DEBUG: DEBUG - name: Run regression tests + shell: bash run: | cd test lua hello.lua From 64c9d531df0efc3f4e85be6d69e5695831993430 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Wed, 8 Nov 2023 13:08:10 +0300 Subject: [PATCH 6/7] ci: Identify CI jobs better and skip irrelevant platform specific steps --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 432bafb..6d119d0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ on: jobs: build: - name: Test build on ${{ matrix.platform }} + name: Test ${{ matrix.luaVersion }} on ${{ matrix.platform }} strategy: fail-fast: false matrix: @@ -17,10 +17,10 @@ jobs: runs-on: ${{ matrix.platform }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup ’msvc’ + if: ${{ startsWith(matrix.platform, 'windows') && !startsWith(matrix.luaVersion, 'luajit') }} uses: ilammy/msvc-dev-cmd@v1 - if: ${{ !startsWith(matrix.luaVersion, 'luajit') }} - name: Setup ‘lua’ uses: leso-kn/gh-actions-lua@v11-staging with: From 43a97b7f0053313b43906371dbdc226271e6c8ab Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Wed, 8 Nov 2023 13:14:04 +0300 Subject: [PATCH 7/7] ci: Update Luacheck to v1+, use newer Ubuntu runner images --- .github/workflows/build.yml | 2 +- .github/workflows/luacheck.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6d119d0..49c2c73 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: luaVersion: [ "5.4", "5.3", "5.2", "5.1", "luajit", "luajit-openresty" ] - platform: [ "ubuntu-20.04", "macos-11", "windows-2022" ] + platform: [ "ubuntu-22.04", "macos-11", "windows-2022" ] runs-on: ${{ matrix.platform }} steps: - name: Checkout diff --git a/.github/workflows/luacheck.yml b/.github/workflows/luacheck.yml index 2f20456..9cb784c 100644 --- a/.github/workflows/luacheck.yml +++ b/.github/workflows/luacheck.yml @@ -5,9 +5,9 @@ on: [push, pull_request] jobs: luacheck: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Luacheck - uses: lunarmodules/luacheck@v0 + uses: lunarmodules/luacheck@v1