Skip to content

nginx-util: add package#10960

Merged
neheb merged 1 commit into
openwrt:masterfrom
peter-stadler:nginx-util
Jan 17, 2020
Merged

nginx-util: add package#10960
neheb merged 1 commit into
openwrt:masterfrom
peter-stadler:nginx-util

Conversation

@peter-stadler
Copy link
Copy Markdown
Contributor

Maintainer: me
Compile tested: MIPS 74K, Asus RT-N16, master snapshot
Run tested: MIPS 74K, Asus RT-N16, master snapshot, run nginx-util [init_lan|get_env [name]|add_ssl _lan] using the file /etc/nginx/conf.d/_lan.conf:

server {
    server_name _lan;
    include conf.d/*.locations;
}

Description: This utility builds dynamically LAN listen directives for nginx.

For nginx-ssl, this tool manages SSL directives for its server parts and can create corresponding (self-signed) certificates using libopenssl, too.

So, it can do the main work of nginx/nginx-ssl init script as proposed in #9859 which will be superseeded by a version using this tool.

There would be also a px5g implementation using libopenssl. Should I activate it/move it to another package?

Comment thread net/nginx-util/Makefile
CATEGORY:=Network
SUBMENU:=Web Servers/Proxies
TITLE:=Builder of LAN listen directives for Nginx
DEPENDS:=+libstdcpp +libubus +libubox +libpthread
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, does this build with uClibc++?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now it is not working, it complains about missing array, mutex, string_view and thread libraries. At least in my test, maybe I am doing it wrong: Do I have to include only uclibc++.mk and use $(CXX_DEPENDS) in the Makefile?

Comment thread net/nginx-util/Makefile
Comment thread net/nginx-util/src/nginx-ssl-util.cpp Outdated
Comment thread net/nginx-util/src/nginx-ssl-util.cpp Outdated
Comment thread net/nginx-util/src/px5g.cpp Outdated
@neheb
Copy link
Copy Markdown
Contributor

neheb commented Jan 9, 2020

Where does the code for this come from? If it is homegrown, I strongly recommend running it against clang-tidy.

@peter-stadler
Copy link
Copy Markdown
Contributor Author

Thank you for the comments, I will look into it :-)

@peter-stadler
Copy link
Copy Markdown
Contributor Author

peter-stadler commented Jan 16, 2020

I did change the code according to cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON . && run-clang-tidy-9 -header-filter=.* (is that right?) with all checks except:

  • fuchsia-* because it disallows many c++ features

  • misc-definitions-in-headers since I did not divide them

  • llvm-header-guard as it suggests names including full path

  • hicpp-signed-bitwise because it is triggered by the defines of OpenSSL

  • google-runtime-references as I am using smatch as non-const reference like in std::regex

  • android-cloexec-creat for auto fd = creat(keypath.c_str(), mask); since its fix triggers cppcoreguidelines-pro-type-vararg in turn

What do you think?

Edit: Right now I cannot test it, I will do that on Monday.

@neheb
Copy link
Copy Markdown
Contributor

neheb commented Jan 16, 2020

Ahem.

cmake has direct support for clang-tidy.

cmake . -DCMAKE_CXX_CLANG_TIDY="clang-tidy -fix"

The checks it can grab from a .clang-tidy file in the same directory.

I will try to review the changes.

@neheb
Copy link
Copy Markdown
Contributor

neheb commented Jan 16, 2020

/home/mangix/devstuff/openwrt/build_dir/target-mips_24kc_musl/nginx-util-1.0/px5g.cpp: In function 'int main(int, const char**)':
/home/mangix/devstuff/openwrt/build_dir/target-mips_24kc_musl/nginx-util-1.0/px5g.cpp:394:9: error: too many initializers for 'std::__1::array<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, 2>'
  394 |         },
      |         ^
/home/mangix/devstuff/openwrt/build_dir/target-mips_24kc_musl/nginx-util-1.0/px5g.cpp:397:9: error: too many initializers for 'std::__1::array<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, 2>'
  397 |         },
      |         ^
/home/mangix/devstuff/openwrt/build_dir/target-mips_24kc_musl/nginx-util-1.0/px5g.cpp:400:9: error: too many initializers for 'std::__1::array<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, 2>'
  400 |         },
      |         ^
/home/mangix/devstuff/openwrt/build_dir/target-mips_24kc_musl/nginx-util-1.0/px5g.cpp:405:9: error: too many initializers for 'std::__1::array<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, 2>'
  405 |         },
      |         ^
/home/mangix/devstuff/openwrt/build_dir/target-mips_24kc_musl/nginx-util-1.0/px5g.cpp:406:5: error: cannot deduce template arguments of 'std::__1::array<_Tp, _Size>', as it has no viable deduction guides
  406 |     };
      |     ^
/home/mangix/devstuff/openwrt/build_dir/target-mips_24kc_musl/nginx-util-1.0/px5g.cpp:425:25: error: unable to deduce 'auto&&' from 'cmds'
  425 |         for (auto cmd : cmds) {

Tested with libcxx.

#endif

// once a year:
static constexpr auto CRON_INTERVAL = std::string_view{"3 3 12 12 *"};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fuchsia-statically-constructed-objects warns about static here. Correct me if I'm wrong, but static on a constexpr function is useless, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There can be a difference between static constexpr and constexpr in general as explained at stackoverflow. But, here it is maybe pointless. Would it be better to remove it? I will remove it at least for the literals _server_name and co. They exist only for using them in the template …

@neheb
Copy link
Copy Markdown
Contributor

neheb commented Jan 17, 2020

/home/mangix/devstuff/openwrt/build_dir/target-mips_24kc_musl/nginx-util-1.0/px5g.cpp: In function 'int main(int, const char**)':
/home/mangix/devstuff/openwrt/build_dir/target-mips_24kc_musl/nginx-util-1.0/px5g.cpp:394:9: error: too many initializers for 'std::__1::array<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, 2>'
  394 |         },
      |         ^
/home/mangix/devstuff/openwrt/build_dir/target-mips_24kc_musl/nginx-util-1.0/px5g.cpp:397:9: error: too many initializers for 'std::__1::array<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, 2>'
  397 |         },
      |         ^
/home/mangix/devstuff/openwrt/build_dir/target-mips_24kc_musl/nginx-util-1.0/px5g.cpp:400:9: error: too many initializers for 'std::__1::array<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, 2>'
  400 |         },
      |         ^
/home/mangix/devstuff/openwrt/build_dir/target-mips_24kc_musl/nginx-util-1.0/px5g.cpp:405:9: error: too many initializers for 'std::__1::array<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, 2>'
  405 |         },
      |         ^
/home/mangix/devstuff/openwrt/build_dir/target-mips_24kc_musl/nginx-util-1.0/px5g.cpp:406:5: error: cannot deduce template arguments of 'std::__1::array<_Tp, _Size>', as it has no viable deduction guides
  406 |     };
      |     ^
/home/mangix/devstuff/openwrt/build_dir/target-mips_24kc_musl/nginx-util-1.0/px5g.cpp:425:25: error: unable to deduce 'auto&&' from 'cmds'
  425 |         for (auto cmd : cmds) {

Tested with libcxx.

Figured it out:

--- a/net/nginx-util/src/px5g.cpp
+++ b/net/nginx-util/src/px5g.cpp
@@ -1,4 +1,5 @@
 #include "px5g-openssl.hpp"
+#include <array>
 #include <iostream>
 #include <string>
 #include <string_view>
@@ -388,17 +389,17 @@ auto main(int argc, const char ** argv) -> int
 {
     auto args = argv_view{argv, argc};
 
-    std::array cmds = {
-        std::array<std::string, 2>{"checkend",
+    std::array<std::array<std::string, 2>, 4> cmds = {
+        {"checkend",
             " [-der] [-in certificate_path] [seconds_remaining]"
         },
-        std::array<std::string, 2>{"eckey",
+        {"eckey",
             " [-der] [-out key_path] [curve_name]"
         },
-        std::array<std::string, 2>{"rsakey",
+        {"rsakey",
             " [-der] [-out key_path] [-3] [key_size]"
         },
-        std::array<std::string, 2>{"selfsigned",
+        {"selfsigned",
             " [-der] [-keyout key_path] [-out certificate_path]"
             " [-newkey ec|rsa:key_size] [-pkeyopt ec_paramgen_curve:name]"
             " [-days validity] [-subj /C=.../ST=.../L=.../O=.../CN=.../... ]"

This can do the main work of nginx/nginx-ssl init script.
For nginx-ssl it can create selfsigned certificates, too.
It uses libpcre and libopenssl iff nginx(-ssl) uses them.

Signed-off-by: Peter Stadler <peter.stadler@student.uibk.ac.at>
@peter-stadler
Copy link
Copy Markdown
Contributor Author

peter-stadler commented Jan 17, 2020

I think I forgot to #include <array> instead, fixed that in the last force-push. Is it working?

@neheb
Copy link
Copy Markdown
Contributor

neheb commented Jan 17, 2020

Hrm yeah it is. Never mind then.

@peter-stadler
Copy link
Copy Markdown
Contributor Author

Thank you for pointing me to it :-)

@neheb
Copy link
Copy Markdown
Contributor

neheb commented Jan 17, 2020

:) sure. BTW the fuschia warnings are specific to google's kernel. They can be ignored.

@neheb neheb closed this Jan 17, 2020
@neheb neheb reopened this Jan 17, 2020
@neheb
Copy link
Copy Markdown
Contributor

neheb commented Jan 17, 2020

Anyway, merging. The libcxx stuff is neither here nor there. It will be dealt with in separate commits.

@neheb neheb merged commit e3f278d into openwrt:master Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants