]> git.basschouten.com Git - openhab-addons.git/commitdiff
[eKey] Add sourceIp in cases of NAT (Kubernetes deployments) (#14616)
authorRobert D <querdenker2k@gmx.de>
Mon, 10 Apr 2023 08:35:56 +0000 (10:35 +0200)
committerGitHub <noreply@github.com>
Mon, 10 Apr 2023 08:35:56 +0000 (10:35 +0200)
* add natIp

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

Signed-off-by: querdenker2k <querdenker2k@gmx.de>
bundles/org.openhab.binding.ekey/README.md
bundles/org.openhab.binding.ekey/src/main/java/org/openhab/binding/ekey/internal/EkeyConfiguration.java
bundles/org.openhab.binding.ekey/src/main/java/org/openhab/binding/ekey/internal/api/EkeyUdpPacketReceiver.java
bundles/org.openhab.binding.ekey/src/main/java/org/openhab/binding/ekey/internal/handler/EkeyHandler.java
bundles/org.openhab.binding.ekey/src/main/resources/OH-INF/i18n/ekey.properties
bundles/org.openhab.binding.ekey/src/main/resources/OH-INF/thing/thing-types.xml

index f21f1516f7c18b619255a968b1ac6acec3a95362..fb728c13e8eedbb5858d023a626f51ff1a7811c2 100644 (file)
@@ -6,20 +6,21 @@ This binding connects to [ekey](https://ekey.net/) converter UDP (CV-LAN) using
 \r
 This binding only supports one thing type:\r
 \r
-| Thing       | Thing Type | Description                                 |\r
-|-------------|------------|---------------------------------------------|\r
+| Thing | Thing Type | Description                            |\r
+|-------|------------|----------------------------------------|\r
 | cvlan | Thing      | Represents a single ekey converter UDP |\r
 \r
 ## Thing Configuration\r
 \r
 The binding uses the following configuration parameters.\r
 \r
-| Parameter | Description                                                    |\r
-|-----------|----------------------------------------------------------------|\r
-| ipAddress | IPv4 address of the eKey udp converter.  A static IP address is recommended.|\r
-| port      | The port as configured during the UDP Converter configuration.  e.g. 56000 (Binding default)     |\r
-| protocol  | Can be RARE, MULTI or HOME depending on what the system supports. Binding defaults to RARE  |\r
-| 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)  |\r
+| Parameter | Description                                                                                                                                                                              |\r
+|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\r
+| ipAddress | IPv4 address of the eKey udp converter.  A static IP address is recommended.                                                                                                             |\r
+| port      | The port as configured during the UDP Converter configuration.  e.g. 56000 (Binding default)                                                                                             |\r
+| protocol  | Can be RARE, MULTI or HOME depending on what the system supports. Binding defaults to RARE                                                                                               |\r
+| 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) |\r
+| natIp     | [Optional] IPv4 address of a received eKey udp packet. Can be different from the ipAddress when using NAT. (e.g. in Kubernetes)                                                          |\r
 \r
 ## Channels\r
 \r
@@ -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 |\r
 | fingerId   | Number    | R/M/H    | This indicates the finger that was used by a person.                                                                                                                                                                                                  | 0-9,-1                               |\r
 | fsName     | String    | M        | This returns the 4-character-long name that was specified on the controller for the specific terminals.                                                                                                                                               |                                      |\r
-| fsSerial     | Number    | R/M/H        | This returns the serial number for the specific terminal.                                     |\r
+| fsSerial   | Number    | R/M/H    | This returns the serial number for the specific terminal.                                                                                                                                                                                             |                                      |\r
 | 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                               |\r
 | keyId      | Number    | M        | This indicates which of the four keys was used. See ekey documentation on "keys".                                                                                                                                                                     | 0-4,-1                               |\r
 | relayId    | Number    | R/H      | This indicates which relay has been switched.                                                                                                                                                                                                         | 0-3,-1                               |\r
index 48fae0e3b9021a4f97b1e49c93f0a7eef66ee60d..823269c4983a6ba218f249276059efae6571d351 100644 (file)
 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;
 }
index 38cf98c554a85ba82e0be032f1d133071f726890..6e1fe8862c5288ce5f20fa0befdff7011b69191c 100644 (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());
index 42a1030b27fb17a8f5d62427da42312e755711fc..eb59497eae92c854e9dd8f08d230843d1593bb24 100644 (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();
index 6e042dfc3db594bfa411d224721d84c9f0ab19ba..0da0edd53fa430c64904787dd061e0fd58645fda 100644 (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
index 04a217258df7466bb5beb8b52670cff1458ee38c..e4d6a882c9d85b11614d85584518851553c3ecbb 100644 (file)
                                <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>