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

Using IP address extracted from net interface #182

Open
arietto opened this issue Feb 22, 2019 · 7 comments
Open

Using IP address extracted from net interface #182

arietto opened this issue Feb 22, 2019 · 7 comments

Comments

@arietto
Copy link

arietto commented Feb 22, 2019

Hello! If I use the following snippet (in ini file)

[wsgi]
http-socket=3000

will REST server listen on all net interfaces?
Is it possible in future to put net interface name instead of hardcoded IP address?
For example,

net_interface=`eth0` 
local_port=3000
http_ver=1

It will be transformed programmatically into http-socket=192.168.21.50:3000.
I use the following heuristics (for IPv4) in other project (works for Linux (like eth0) and human-readable net interface names in Windows):

QString get_local_ip_by_interface(const QString & net_interface)
{
 if (net_interface.isEmpty())
 {
  return QString();
 }
 QList<QNetworkInterface> net_interface_list = QNetworkInterface::allInterfaces();
 for (const auto & current_interface : qAsConst(net_interface_list))
 {
  QNetworkInterface::InterfaceFlags flags = current_interface.flags();
  if ((flags & QNetworkInterface::IsRunning) &&
  ((current_interface.name() == net_interface) ||
  (current_interface.humanReadableName() == net_interface)))
  {
   auto address_entries = current_interface.addressEntries();
   for (const auto& addr : qAsConst(address_entries))
   {
    auto host_addr = addr.ip();
    if (host_addr.protocol() == QAbstractSocket::IPv4Protocol)
    {
     return addr.ip().toString();
    }
   }
  }		
 }
 return QString();
}//end
@dantti
Copy link
Member

dantti commented Mar 6, 2019

The proper syntax for all ip addresses is:
http-socket=:3000

It would be confusing to have:
http-socket=eth0:3000

because eth0 is expected to be a hostname such as:
http-socket=localhost:3000

I can't really think on a good syntax for this, does uWSGI supports this?

@arietto
Copy link
Author

arietto commented Mar 13, 2019

Hello! I mean that we can add optional parameters:
net_interface=eth0
local_port=3000
http_ver=1.1
They will be used if http-socket is absent. http_ver=1.1 means autogeneration for http-socket.
cutelyst-wsgi2 will implicitly generate resulting string (in-memory):
http-socket=192.168.21.95:3000

@dantti
Copy link
Member

dantti commented Mar 13, 2019

Ok, I had an idea, option --http-iface=eth0:3000, --https-iface=eth0:3000, --fcgi-iface=eth0:3000 and --h2-iface=eth0:3000.

Which will resolve the interface addresses and append them to the http-socket list, can you do a PR for this?

@arietto
Copy link
Author

arietto commented Mar 31, 2019

I have no time at the moment (though I have done some primary dirty stuff in local copy). Should I consider only IPv4? Perhaps, I'll try to make a PR in mid-April.

@dantti
Copy link
Member

dantti commented Mar 31, 2019

Well both IPv4 and IPv6 should be supported

@arietto
Copy link
Author

arietto commented Apr 1, 2019

BTW, could you please explain parsing address & port in bool TcpServerBalancer::listen(const QString &line, Protocol *protocol, bool secure) method? When and why comma, square bracket symbols should be considered?

@dantti
Copy link
Member

dantti commented Apr 1, 2019

it's [IP]:PORT,ssl-cofig-files same syntax of uWSGI.

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

No branches or pull requests

2 participants