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

ser2net: Added support for config file. #5302

Merged
merged 1 commit into from
Jan 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ser2net: added support for config file.
Signed-off-by: Jasper Scholte <[email protected]>
  • Loading branch information
TimelessNL committed Dec 21, 2017
commit e190a22c6aec7a421cd1f35985fe8acf9a68c08b
4 changes: 4 additions & 0 deletions net/ser2net/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ define Package/ser2net/install
$(CP) $(PKG_INSTALL_DIR)/usr/sbin/ser2net $(1)/usr/sbin/
$(INSTALL_DIR) $(1)/etc
$(INSTALL_CONF) $(PKG_BUILD_DIR)/ser2net.conf $(1)/etc/
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) ./files/etc/config/ser2net $(1)/etc/config/ser2net
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/etc/init.d/ser2net $(1)/etc/init.d/ser2net
endef

$(eval $(call BuildPackage,ser2net))
8 changes: 8 additions & 0 deletions net/ser2net/files/etc/config/ser2net
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
config 'proxy'
Copy link
Member

Choose a reason for hiding this comment

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

Hm, "proxy" is not my first choice, but in the absence of a better idea... The important thing is, that we might add additional types later, e.g. for LED configuration etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just device? one section for each device line?

Copy link
Contributor Author

@TimelessNL TimelessNL Dec 21, 2017

Choose a reason for hiding this comment

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

there is already a parameter device? I think changing it to device makes it confusing. And I suppose ser2net is proxying the serial data to network data. So it seems ok to me?

Copy link
Member

Choose a reason for hiding this comment

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

The port # and the device name are unique strings... I would differentiate the blocks based on either one of those, and make the other one a mandatory parameter.

Copy link
Contributor

Choose a reason for hiding this comment

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

well, they're not actually. ser2net can have the same port and multiple devices, or multiple ports for the same device, and have them enabled/disabled separately at runtime via the control port.

option 'enabled' '0'
option 'port' '8000'
option 'protocol' 'raw'
option 'timeout' '30'
option 'device' '/dev/ttyUSB0'
option 'options' '9600 1STOPBIT 8DATABITS'

46 changes: 46 additions & 0 deletions net/ser2net/files/etc/init.d/ser2net
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2017 OpenWrt.org

START=75
STOP=10
CONFIGFILE="/tmp/ser2net.conf"

USE_PROCD=1
PROG=/usr/sbin/ser2net

start_service() {
config_load 'ser2net'

local enabled
config_get_bool enabled config 'enabled' '0'
[ "$enabled" -gt 0 ] || return 1
Copy link
Contributor

Choose a reason for hiding this comment

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

You want the enable to be on the use of the UCI conversion. There's still a gain to be had from an functional init script with the existing /etc/ser2net.conf file. particularly when you'll never be able to match the depth of availlable config in the UCI model. Like https://github.com/openwrt/packages/blob/master/net/mosquitto/files/etc/init.d/mosquitto#L186-L191

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So what you meant is:
if enabled: the /etc/config/ser2net config file gets parsed to /tmp/ser2net.conf.
if disabled: the /etc/ser2net.conf file is used.

Is my assumption correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, that's what I was talking about at least.

Copy link
Contributor Author

@TimelessNL TimelessNL Dec 21, 2017

Choose a reason for hiding this comment

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

Seems feasible to me. Do I have to provide a default /etc/ser2net.conf file or can I just check for its existence and fail if not found?

Copy link
Contributor

Choose a reason for hiding this comment

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

well, the package is already installing one, so I wouldn't bother doing any further checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, agreed.

Copy link
Member

Choose a reason for hiding this comment

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

Unless the user explicitly removes it...

Copy link
Contributor

Choose a reason for hiding this comment

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

@pprindeville What if they remove the package itself?! where do you stop?

Copy link
Member

@pprindeville pprindeville Dec 21, 2017

Choose a reason for hiding this comment

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

Let's not go over the top.

For someone concerned about security and not having a "fail open" policy, removing defaults to stop a (unconfigured) service from running is good security practice.


ser2net_create_config config || return 1
procd_open_instance
procd_set_param command "$PROG" -n -c "$CONFIGFILE"
procd_close_instance
}

ser2net_create_config() {
local cfg=$1
local port
local device

config_get port $cfg port
config_get device $cfg device
[ -z "$port" -o -t "$device" ] && return 1

local protocol
local timeout
local options

config_get protocol $cfg protocol
Copy link
Contributor

Choose a reason for hiding this comment

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

this is called "state" in the ser2net configs, is there any real good reason to use a different word here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was requested by @mhei : #5302 (comment)

config_get timeout $cfg timeout
config_get options $cfg options

if [ -z "$options" ]; then
echo "$port":"$protocol":"$timeout":"$device" >> "$CONFIGFILE
else
echo "$port":"$protocol":"$timeout":"$device":"$options" >> "$CONFIGFILE"
fi
}