-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Conversation
Seems like the author name from my Github.com account is invalid for some reason. This shouldn't matter I suppose? |
There was a problem hiding this 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.
net/ser2net/files/etc/config/ser2net
Outdated
option 'state' 'raw' | ||
option 'timeout' '30' | ||
option 'device' '/dev/ttyUSB0' | ||
option 'options' '9600 1STOPBIT 8DATABITS' |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
That's a question for @champtar. |
@TimelessNL Travis is only looking at the commit, in this case the Author field of the commit |
@champtar Thanks for that clarification. |
@champtar Ah I thought I had set this in my git client. Will check, thanks! |
net/ser2net/files/etc/init.d/ser2net
Outdated
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` |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
net/ser2net/files/etc/init.d/ser2net
Outdated
if [ -z "$options" ]; then | ||
echo "$tcpport":"$state":"$timeout":"$device" >> "$CONFIGFILE" | ||
else | ||
echo "$tcpport":"$state":"$timeout":"$device":"$options" >> "$CONFIGFILE" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
net/ser2net/files/etc/init.d/ser2net
Outdated
PID=`cat /tmp/ser2net_pid` | ||
rm -f /tmp/se2net_pid | ||
kill -9 $PID | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concur with @karlp.
You probably should also have been using a branch for this, so that your rtl433 package didn't just appear here as well :) |
@karlp, Haha you are to fast, I was working on that but I typed the wrong command :) |
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? |
There was a problem hiding this 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
.
net/ser2net/files/etc/init.d/ser2net
Outdated
fi | ||
config_get state $cfg state | ||
config_get timeout $cfg timeout | ||
config_get device $cfg device |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
net/ser2net/files/etc/config/ser2net
Outdated
@@ -0,0 +1,7 @@ | |||
config 'proxy' | |||
option 'tcpport' '8000' |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
net/ser2net/files/etc/config/ser2net
Outdated
option 'state' 'raw' | ||
option 'timeout' '30' | ||
option 'device' '/dev/ttyUSB0' | ||
option 'options' '9600 1STOPBIT 8DATABITS' |
There was a problem hiding this comment.
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.
net/ser2net/files/etc/init.d/ser2net
Outdated
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` |
There was a problem hiding this comment.
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.
net/ser2net/files/etc/config/ser2net
Outdated
config 'proxy' | ||
option 'tcpport' '8000' | ||
option 'state' 'raw' | ||
option 'timeout' '30' |
There was a problem hiding this comment.
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.
net/ser2net/files/etc/config/ser2net
Outdated
@@ -0,0 +1,7 @@ | |||
config 'proxy' | |||
option 'tcpport' '8000' | |||
option 'state' 'raw' |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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.
net/ser2net/files/etc/init.d/ser2net
Outdated
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` |
There was a problem hiding this comment.
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?
Seems that my review and your rework were overlapping - sorry if this results in extra work on your side. |
@mhei no issue. Will rework some more based on your additional comments. Be back shortly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Procd changes required.
net/ser2net/files/etc/init.d/ser2net
Outdated
config_load 'ser2net' | ||
ser2net_create_config config || return 1 | ||
procd_open_instance | ||
procd_set_param command "$PROG" -c "$CONFIGFILE" |
There was a problem hiding this comment.
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
.
@mhei Don't forget about So if we don't have defaults, then what do we do when |
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? |
Sorry but it's a little bit hard to keep-up with all the comments. Would it be an option to comment globally instead inline? |
@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 |
We should definitely allow multiple
to address this. |
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. |
Can you |
Signed-off-by: Jasper Scholte <[email protected]>
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, agreed.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
Currently my time is limited but I'll resume this pull-request after the holidays. Happy holidays every one 👍 |
@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. |
Thats great! You should have access to my branch if you need to. |
@mhei Can you point me at it when you're ready to have people look at it? Thanks. |
Signed-off-by: Michael Heimpold <[email protected]>
Please have a look at the branch I push a few seconds ago. Note, that it's not yet tested fully... |
@mhei Will do, should I close this pull request? Or should I merge your code? |
@TimelessNL: no need to close/modify this PR, I will handle it during merge. Just review and/or test and add comments here. |
Signed-off-by: Michael Heimpold <[email protected]>
Signed-off-by: Michael Heimpold <[email protected]>
Signed-off-by: Michael Heimpold <[email protected]>
@mhei , see my comment on mhei@1dd54f5#commitcomment-26946566 |
Signed-off-by: Michael Heimpold <[email protected]>
Signed-off-by: Michael Heimpold <[email protected]>
Signed-off-by: Michael Heimpold <[email protected]>
Signed-off-by: Michael Heimpold <[email protected]>
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