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

ser2net: Added support for config file. #5302

merged 1 commit into from
Jan 7, 2018

Conversation

TimelessNL
Copy link
Contributor

Maintainer: Jasper Scholte [email protected]
Compile tested: (x86, GEODE, LEDE 17.01.02)
Run tested: (x86, GEODE, LEDE 17.01.02, tested written configuration and startup of ser2net)

Description:
This adds support for ser2net /etc/config/ser2net config file and corresponding init.d/ser2net script.

Note: this changeset is based on https://github.com/JiapengLi/OpenWrt-luci-app-ser2net/blob/master/openwrt-packages-add-luci-app-ser2net-support.patch

@TimelessNL
Copy link
Contributor Author

Seems like the author name from my Github.com account is invalid for some reason. This shouldn't matter I suppose?

Copy link
Member

@pprindeville pprindeville left a comment

Choose a reason for hiding this comment

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

The handling of options needs to be more complete and have sane defaults.

option 'state' 'raw'
option 'timeout' '30'
option 'device' '/dev/ttyUSB0'
option 'options' '9600 1STOPBIT 8DATABITS'
Copy link
Member

Choose a reason for hiding this comment

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

I think 2-stop bits is only ever used with 110 baud, and in any case the stop bits should be inferred from the baud rate if not given. Likewise, 8-databits can be safely inferred unless something else is given.

Lastly, you don't seem to be including the parity (which, when absent, can be omitted and safely default to NONE which is the prevalent assumption in this post-Latin1/UTF8 world where we can't assume that everything is 7-bit ASCII).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can be mistaken but the default options is now set to 1STOPBIT? So your comment about 2-stop bits is not right?

Currently I put these patches in a pull-request and left the defaults as is. So if something can improved sure, no problem.

I personally don't know good defaults but I saw these: [9600 8DATABITS NONE 1STOPBIT] from here: https://www.domoticz.com/wiki/SharingSerialDevices is that ok?

Copy link
Member

Choose a reason for hiding this comment

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

I can be mistaken but the default options is now set to 1STOPBIT? So your comment about 2-stop bits is not right?

Not sure what you think isn't right about it. I'm saying that 2 stopbits are never used except at 110 bps.

Most low-end serial devices are 38400. Most high-end devices are 115200.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for not understanding. But where do you see 2 stop bits? Currently the option is "1STOPBIT" that is 1 stop bit right?

Copy link
Member

Choose a reason for hiding this comment

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

I'm saying in the options, only the baud rate should be required (if that). The rest can be implied by the "normal" settings for any given seen (2-stopbits for 110 baud, 1-stopbit for anything else... no parity, 8-databits).

Copy link
Member

Choose a reason for hiding this comment

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

@TimelessNL Not sure what you mean by (1). Are you talking about a GUI in LUA?

(2) sounds good to me.

@karlp I'm not making assumptions. I'm going by the ECMA and ITU standards for RS-232. If someone wants 2-stopbits they can explicitly call that out. I'm just saying that for baud rates above 110, the same default is 1-stopbit.

Copy link
Member

Choose a reason for hiding this comment

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

I don't like the current approach. Please change it to support the following config style:

config proxy
    ...
    option baudrate <int>
    option databits <8|7|6|5>
    option parity <odd|even|none|space|mark>
    option stopbits <1|2>
    list options 'remctl'
    list options 'local'
    list options '-xonxoff'

Yes, this requires more work for generating the config since we need a mapping but I really think, this is the way we should go.

I agree with @karlp that we don't add assumptions here.

Copy link
Contributor Author

@TimelessNL TimelessNL Dec 20, 2017

Choose a reason for hiding this comment

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

@pprindeville Aah sorry about (1) I was already thinking ahead. I also got a pull-request for a LuCI-app so that's why I mentioned the dropdown :P. ofc this is invalid here.

@ both. Is it ok if I wait before doing anything until you 2 figured it out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mhei Thanks. I will have to look into this coding a little bit. This all is still a little bit new for me. So it could take some time.

Copy link
Member

Choose a reason for hiding this comment

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

The optional 4th argument to config_get is a default value.

@pprindeville
Copy link
Member

Seems like the author name from my Github.com account is invalid for some reason. This shouldn't matter I suppose?

That's a question for @champtar.

@champtar
Copy link
Member

@TimelessNL Travis is only looking at the commit, in this case the Author field of the commit
Putting you real name in that, and having a matching signed-off-by is good practice in my opinion
Regards

@pprindeville
Copy link
Member

@champtar Thanks for that clarification.

@TimelessNL
Copy link
Contributor Author

@champtar Ah I thought I had set this in my git client. Will check, thanks!

@mhei mhei self-assigned this Dec 20, 2017
state=`uci get ser2net.@proxy["$i"].state 2> /dev/null`
timeout=`uci get ser2net.@proxy["$i"].timeout 2> /dev/null`
device=`uci get ser2net.@proxy["$i"].device 2> /dev/null`
options=`uci get ser2net.@proxy["$i"].options 2> /dev/null`
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 pretty gross. Look at how other packages use config_load instead.

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 will look into that.

Copy link
Member

Choose a reason for hiding this comment

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

I'll review this part when you updated the PR. Please update this PR and do not create a new one.

Copy link
Member

Choose a reason for hiding this comment

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

Just one note: I think about adding the dynamically generated part of the configuration file, i.e. using /etc/ser2net.conf as base and then adding the generated lines add the end. This way, the user can manually edit some defaults or additional items which are not (yet) configurable via UCI but also has the comfort of controlling the main aspects via UCI. What do you think about this idea?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would be feasible indeed. But I also think that if people miss something in our current package they should notify it so it gets supported for everyone. Otherwise people will do local changes and do not bother to mention them upstream. I know this is a little bit harsh but I think it's for the best.

Copy link
Member

Choose a reason for hiding this comment

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

But how would you know what the devices were?

if [ -z "$options" ]; then
echo "$tcpport":"$state":"$timeout":"$device" >> "$CONFIGFILE"
else
echo "$tcpport":"$state":"$timeout":"$device":"$options" >> "$CONFIGFILE"
Copy link
Contributor

Choose a reason for hiding this comment

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

you know this can be more than just a port right? you can put in things like ipv4,tcp,localhost,2000 in that first field even.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I check https://linux.die.net/man/8/ser2net and look at the Configuration section they also mention it as TCP port.

Their setup is: TCP port : state : timeout : device : options

Copy link
Contributor

Choose a reason for hiding this comment

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

That man file is out of date. Look at the docs within the existing /etc/ser2net.conf

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, so the new name is "network port". So changing it to "networkport" will be sufficient?
ser2net.conf.txt

PID=`cat /tmp/ser2net_pid`
rm -f /tmp/se2net_pid
kill -9 $PID
}
Copy link
Contributor

Choose a reason for hiding this comment

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

just make this a proper procd service. there's no need for this mucking about trying to track pidfiles manually. it would be simpler to do this properly.

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 will look into that.

Copy link
Member

Choose a reason for hiding this comment

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

Concur with @karlp.

@karlp
Copy link
Contributor

karlp commented Dec 20, 2017

You probably should also have been using a branch for this, so that your rtl433 package didn't just appear here as well :)

@TimelessNL
Copy link
Contributor Author

TimelessNL commented Dec 20, 2017

@karlp, Haha you are to fast, I was working on that but I typed the wrong command :)
Should be fixed now.

@TimelessNL
Copy link
Contributor Author

Ok, I took the init.d files form "cron" and "minidlna" as an example and came up with this new init.d ser2net script. Procd is still new for me but I think I included everything?

Copy link
Member

@pprindeville pprindeville left a comment

Choose a reason for hiding this comment

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

Doesn't make sense to not populate device.

fi
config_get state $cfg state
config_get timeout $cfg timeout
config_get device $cfg device
Copy link
Member

@pprindeville pprindeville Dec 20, 2017

Choose a reason for hiding this comment

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

Shouldn't the device also be requisite?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It probably is :) I'll add this

@@ -0,0 +1,7 @@
config 'proxy'
option 'tcpport' '8000'
Copy link
Member

Choose a reason for hiding this comment

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

I'm not happy with "tcpport", nor the "upstream" version "networkport". I would prefer just simple "port" here. I'm still thinking about whether we should accept the advanced configuration items of upstream, i.e. passing this simply down into the config, or whether we should force this to be a simple port number. The latter facilitates a UCI type check...

@@ -0,0 +1,7 @@
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 'state' 'raw'
option 'timeout' '30'
option 'device' '/dev/ttyUSB0'
option 'options' '9600 1STOPBIT 8DATABITS'
Copy link
Member

Choose a reason for hiding this comment

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

I don't like the current approach. Please change it to support the following config style:

config proxy
    ...
    option baudrate <int>
    option databits <8|7|6|5>
    option parity <odd|even|none|space|mark>
    option stopbits <1|2>
    list options 'remctl'
    list options 'local'
    list options '-xonxoff'

Yes, this requires more work for generating the config since we need a mapping but I really think, this is the way we should go.

I agree with @karlp that we don't add assumptions here.

state=`uci get ser2net.@proxy["$i"].state 2> /dev/null`
timeout=`uci get ser2net.@proxy["$i"].timeout 2> /dev/null`
device=`uci get ser2net.@proxy["$i"].device 2> /dev/null`
options=`uci get ser2net.@proxy["$i"].options 2> /dev/null`
Copy link
Member

Choose a reason for hiding this comment

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

I'll review this part when you updated the PR. Please update this PR and do not create a new one.

config 'proxy'
option 'tcpport' '8000'
option 'state' 'raw'
option 'timeout' '30'
Copy link
Member

Choose a reason for hiding this comment

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

Please add proper default handling when create config file in case timeout option is not given in UCI.

@@ -0,0 +1,7 @@
config 'proxy'
option 'tcpport' '8000'
option 'state' 'raw'
Copy link
Member

Choose a reason for hiding this comment

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

Yes, I know "upstream" calls this state... but please change it to "protocol".

Copy link
Contributor

Choose a reason for hiding this comment

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

Why? when I saw protocol in this later, I thought it was an error, mixingin tcp/udp options or v4/v6, both which go in the "port" section of the config string.

state=`uci get ser2net.@proxy["$i"].state 2> /dev/null`
timeout=`uci get ser2net.@proxy["$i"].timeout 2> /dev/null`
device=`uci get ser2net.@proxy["$i"].device 2> /dev/null`
options=`uci get ser2net.@proxy["$i"].options 2> /dev/null`
Copy link
Member

Choose a reason for hiding this comment

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

Just one note: I think about adding the dynamically generated part of the configuration file, i.e. using /etc/ser2net.conf as base and then adding the generated lines add the end. This way, the user can manually edit some defaults or additional items which are not (yet) configurable via UCI but also has the comfort of controlling the main aspects via UCI. What do you think about this idea?

@mhei
Copy link
Member

mhei commented Dec 20, 2017

Seems that my review and your rework were overlapping - sorry if this results in extra work on your side.

@TimelessNL
Copy link
Contributor Author

@mhei no issue. Will rework some more based on your additional comments. Be back shortly.

Copy link
Member

@pprindeville pprindeville left a comment

Choose a reason for hiding this comment

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

Procd changes required.

config_load 'ser2net'
ser2net_create_config config || return 1
procd_open_instance
procd_set_param command "$PROG" -c "$CONFIGFILE"
Copy link
Member

@pprindeville pprindeville Dec 20, 2017

Choose a reason for hiding this comment

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

For procd, you will need -n.

@pprindeville
Copy link
Member

@mhei Don't forget about rtscts flow-control.

So if we don't have defaults, then what do we do when databits or parity or stopbits are omitted?

@karlp
Copy link
Contributor

karlp commented Dec 20, 2017

You still need some global config option with an "enable" flag to allow turning off your (it will always be, unfortunately) limited uci support and allow using the native config file.

@pprindeville
Copy link
Member

You still need some global config option with an "enable" flag to allow turning off your (it will always be, unfortunately) limited uci support and allow using the native config file.

@karlp What would a canned config look like? What serial lines can you count on reliably being present?

@TimelessNL
Copy link
Contributor Author

Sorry but it's a little bit hard to keep-up with all the comments.
Especially since some get hidden when I update some lines.

Would it be an option to comment globally instead inline?

@pprindeville
Copy link
Member

@mhei @karlp I'm confused. Does enable turn off ser2net globally, or just cause it to process any additional UCI configuration?

@pprindeville
Copy link
Member

@mhei Am I missing something, or is only a single config block with a single device permitted? I have a Xeon 1U server with a Startech PEX16S952LP 16-port serial PCI card in it, that is both firewall and terminal server for all of my headless servers (which run console=ttyS0,115200n8r).

@TimelessNL TimelessNL changed the title ser2net - Added support for config file. ser2net: Added support for config file. Dec 20, 2017
@mhei
Copy link
Member

mhei commented Dec 20, 2017

We should definitely allow multiple config proxy sections. Each section will result in one ser2net config line. The enabled option in one section should only prevent this section to be processed, but not to disable ser2net globally. We could add a

config global
    option enabled ...

config proxy
    option ...

to address this.

@TimelessNL
Copy link
Contributor Author

TimelessNL commented Dec 20, 2017

Correct me if I'm wrong, I think we should concentrate on version-1 first, instead of wanting the final solution immediately. I understand allot of things are wanted. But right now we have to start somewhere I suppose.

@pprindeville
Copy link
Member

Can you git rebase -i HEAD~6 and then git push -f -u origin master to combine all your commits into one single one?

@TimelessNL
Copy link
Contributor Author

Sorry I was unable to do a rebase, and did a soft reset instead. Hope this is sufficient.


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.

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)

@TimelessNL
Copy link
Contributor Author

Currently my time is limited but I'll resume this pull-request after the holidays. Happy holidays every one 👍

@mhei
Copy link
Member

mhei commented Dec 28, 2017

@TimelessNL: I'll pick your current version and extend it with my ideas. Please give me some time - I think I can present my version for discussion in one or two days.

@TimelessNL
Copy link
Contributor Author

Thats great! You should have access to my branch if you need to.

@pprindeville
Copy link
Member

@mhei Can you point me at it when you're ready to have people look at it? Thanks.

mhei added a commit to mhei/packages that referenced this pull request Dec 30, 2017
@mhei
Copy link
Member

mhei commented Dec 30, 2017

Please have a look at the branch I push a few seconds ago. Note, that it's not yet tested fully...

@TimelessNL
Copy link
Contributor Author

@mhei Will do, should I close this pull request? Or should I merge your code?

@mhei
Copy link
Member

mhei commented Jan 4, 2018

@TimelessNL: no need to close/modify this PR, I will handle it during merge. Just review and/or test and add comments here.

@mhei mhei merged commit e190a22 into openwrt:master Jan 7, 2018
mhei added a commit that referenced this pull request Jan 7, 2018
salzmdan pushed a commit to salzmdan/packages that referenced this pull request Jan 8, 2018
jow- pushed a commit to jow-/packages that referenced this pull request Jan 15, 2018
@TimelessNL
Copy link
Contributor Author

@mhei , see my comment on mhei@1dd54f5#commitcomment-26946566

mhei added a commit that referenced this pull request Jan 18, 2018
val-kulkov pushed a commit to val-kulkov/openwrt-packages that referenced this pull request Jan 26, 2018
lynxis pushed a commit to lynxis/packages that referenced this pull request Jan 3, 2019
lynxis pushed a commit to lynxis/packages that referenced this pull request Jan 3, 2019
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.

5 participants