[eKey] Add sourceIp in cases of NAT (Kubernetes deployments) (#14616)

* add natIp

Signed-off-by: querdenker2k <querdenker2k@gmx.de>

---------

Signed-off-by: querdenker2k <querdenker2k@gmx.de>
This commit is contained in:
Robert D 2023-04-10 10:35:56 +02:00 committed by GitHub
parent 14d6b3e4fe
commit 71dfbcf12c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 26 additions and 12 deletions

View File

@ -6,20 +6,21 @@ This binding connects to [ekey](https://ekey.net/) converter UDP (CV-LAN) using
This binding only supports one thing type:
| Thing | Thing Type | Description |
|-------------|------------|---------------------------------------------|
| Thing | Thing Type | Description |
|-------|------------|----------------------------------------|
| cvlan | Thing | Represents a single ekey converter UDP |
## Thing Configuration
The binding uses the following configuration parameters.
| Parameter | Description |
|-----------|----------------------------------------------------------------|
| ipAddress | IPv4 address of the eKey udp converter. A static IP address is recommended.|
| port | The port as configured during the UDP Converter configuration. e.g. 56000 (Binding default) |
| protocol | Can be RARE, MULTI or HOME depending on what the system supports. Binding defaults to RARE |
| delimiter | The delimiter is also defined on the ekey UDP converter - use the ekey configuration software to determine which delimiter is used or to change it. Binding default is `_` (underscore) |
| Parameter | Description |
|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ipAddress | IPv4 address of the eKey udp converter. A static IP address is recommended. |
| port | The port as configured during the UDP Converter configuration. e.g. 56000 (Binding default) |
| protocol | Can be RARE, MULTI or HOME depending on what the system supports. Binding defaults to RARE |
| delimiter | The delimiter is also defined on the ekey UDP converter - use the ekey configuration software to determine which delimiter is used or to change it. Binding default is `_` (underscore) |
| natIp | [Optional] IPv4 address of a received eKey udp packet. Can be different from the ipAddress when using NAT. (e.g. in Kubernetes) |
## Channels
@ -28,7 +29,7 @@ The binding uses the following configuration parameters.
| action | Number | R/M/H | This indicates whether access was granted (value=0) or denied (value=-1). | 0,-1 (136 and 137 with RARE protocol |
| fingerId | Number | R/M/H | This indicates the finger that was used by a person. | 0-9,-1 |
| fsName | String | M | This returns the 4-character-long name that was specified on the controller for the specific terminals. | |
| fsSerial | Number | R/M/H | This returns the serial number for the specific terminal. |
| fsSerial | Number | R/M/H | This returns the serial number for the specific terminal. | |
| inputId | Number | M | This indicates which of the four digital inputs was triggered. Value is number of Input. "-1" indicates that no input was triggered. | 0-4,-1 |
| keyId | Number | M | This indicates which of the four keys was used. See ekey documentation on "keys". | 0-4,-1 |
| relayId | Number | R/H | This indicates which relay has been switched. | 0-3,-1 |

View File

@ -13,11 +13,13 @@
package org.openhab.binding.ekey.internal;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
/**
* The {@link EkeyConfiguration} class contains fields mapping thing configuration parameters.
*
* @author Hans-Jörg Merk - Initial contribution
* @author Robert Delbrück - Add natIp
*/
@NonNullByDefault
public class EkeyConfiguration {
@ -26,4 +28,5 @@ public class EkeyConfiguration {
public int port;
public String protocol = "";
public String delimiter = "";
public @Nullable String natIp;
}

View File

@ -119,7 +119,8 @@ public class EkeyUdpPacketReceiver {
lastPacket = packet.getData();
readMessage(lastPacket);
} else {
logger.warn("Packet received from unknown source- {}", packet.getData());
logger.warn("Packet received from unknown source (ip={}) - {}",
packet.getAddress().getHostAddress(), packet.getData());
}
} catch (UnknownHostException e) {
logger.debug("Exception during address conversion - {}", e.getMessage());

View File

@ -18,6 +18,7 @@ import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNullByDefault;
@ -49,6 +50,7 @@ import org.slf4j.LoggerFactory;
* sent to one of the channels.
*
* @author Hans-Jörg Merk - Initial contribution
* @author Robert Delbrück - Add natIp
*/
@NonNullByDefault
public class EkeyHandler extends BaseThingHandler implements EkeyPacketListener {
@ -82,8 +84,8 @@ public class EkeyHandler extends BaseThingHandler implements EkeyPacketListener
populateChannels(config.protocol);
String readerThreadName = "OH-binding-" + getThing().getUID().getAsString();
EkeyUdpPacketReceiver localReceiver = receiver = new EkeyUdpPacketReceiver(config.ipAddress,
config.port, readerThreadName);
EkeyUdpPacketReceiver localReceiver = receiver = new EkeyUdpPacketReceiver(
Optional.ofNullable(config.natIp).orElse(config.ipAddress), config.port, readerThreadName);
localReceiver.addEkeyPacketListener(this);
try {
localReceiver.openConnection();

View File

@ -15,6 +15,8 @@ thing-type.config.ekey.protocol.label = Protocol
thing-type.config.ekey.protocol.description = Can be RARE, MULTI or HOME depending on what the system supports
thing-type.config.ekey.delimiter.label = Delimiter
thing-type.config.ekey.delimiter.description = The delimiter is also defined on the ekey UDP converter - use the ekey configuration software to determine which delimiter is used or to change it. Another option is _ (underscore)
thing-type.config.ekey.natIp.label = NAT IP
thing-type.config.ekey.natIp.description = NAT rewritten source IPv4 address of a received eKey udp packet. Can be different from the ipAddress when using NAT. (e.g. in Kubernetes)
# channel types
channel-type.ekey.userId.label = User ID

View File

@ -41,6 +41,11 @@
<description>@text/thing-type.config.ekey.delimiter.description</description>
<default>_</default>
</parameter>
<parameter name="natIp" type="text" required="false">
<context>network-address</context>
<label>@text/thing-type.config.ekey.natIp.label</label>
<description>@text/thing-type.config.ekey.natIp.description</description>
</parameter>
</config-description>
</thing-type>