Skip to content

Commit

Permalink
cifX0 IP settings now in Host UI
Browse files Browse the repository at this point in the history
  • Loading branch information
hilschernetpi committed Nov 28, 2019
1 parent 21d9015 commit 57daed9
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 68 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ LABEL org.label-schema.build-date=$BUILD_DATE \
RUN [ "cross-build-start" ]

#version
ENV HILSCHERNETPI_CODESYS_BASIS_VERSION 1.1.1
ENV HILSCHERNETPI_CODESYS_BASIS_VERSION 1.2.0

#execute all commands as root
USER root
Expand Down
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,7 @@ The container configures the two RJ45 Industrial Ethernet ports (RTE) as standar
* host device `/dev/spidev0.0` granting access to the network controller netX driving the RTE ports
* host device `/dev/net/tun` granting access to network interface registering logic

#### Environment variables (optional)

On netPI RTE 3 target only (optional):

The configuration of the LAN interface `cifx0` is done with the following variables

* IP_ADDRESS with a value in the format `x.x.x.x` e.g. 192.168.0.1 configures the interface IP address. A value `dhcp` instead enables the dhcp mode and the interface waits to receive its IP address through a DCHP server.
* SUBNET_MASK with a value in the format `x.x.x.x` e.g. 255.255.255.0 configures the interface subnet mask. Not necessary to configure in dhcp mode.
* GATEWAY with a value in the format `x.x.x.x` e.g. 192.168.0.10 configures the interface gateway address. A gateway is optional. Not necessary to configure in dhcp mode.
In "Host network" mode the Host treats the `cifx0` as a standard LAN interface. This is why the `cifx0` IP settings are configured in the device's network/LAN settings dialog (like "eth0" interface). Any change on the IP settings needs a container restart to accept the new IP parameters.

### Container deployment

Expand All @@ -91,9 +83,6 @@ Parameter | Value | Remark
*Runtime > Devices > +add device* | *Host path* **/dev/hidraw0** -> *Container path* **/dev/hidraw0** | for CODESYS Runtime Key Dongle
*Runtime > Devices > +add device* | *Host path* **/dev/spidev0.0** -> *Container path* **/dev/spidev0.0** | for `cifx0` LAN
*Runtime > Devices > +add device* | *Host path* **/dev/net/tun** -> *Container path* **/dev/net/tun** | for `cifx0` LAN
*Runtime > Env* | *name* **IP_ADDRESS** -> *value* **e.g.192.168.0.1** or **dhcp** | for `cifx0` LAN
*Runtime > Env* | *name* **SUBNET_MASK** -> *value* **e.g.255.255.255.0** | for `cifx0` LAN, no need for `dhcp`
*Runtime > Env* | *name* **GATEWAY** -> *value* **e.g.192.168.0.10** | optional for `cifx0` LAN, no need for `dhcp`
*Runtime > Privileged mode* | **On** |

STEP 4. Press the button *Actions > Start/Deploy container*
Expand Down
55 changes: 0 additions & 55 deletions init.d/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,64 +63,9 @@ if [[ -e "/dev/spidev0.0" ]]&& [[ -e "/dev/net/tun" ]]; then
# create netx "cifx0" ethernet network interface
/opt/cifx/cifx0daemon

#interface needs a little time to start
sleep 5

# bring interface up first of all
ip link set cifx0 up

# ip address configured as environment variable?
if [ -z "$IP_ADDRESS" ]
then
echo "No cifx0 IP address configured as environment variable $IP_ADDRESS. Falling back to 192.168.253.1"
# set alternative
IP_ADDRESS="192.168.253.1"
fi

# subnet mask configured as environment variable?
if [ -z "${SUBNET_MASK}" ]
then
echo "No cifx0 subnet mask configured as environment variable $SUBNET_MASK. Falling back to 255.255.255.0"
# set alternative
SUBNET_MASK="255.255.255.0"
fi

if [ "$IP_ADDRESS" == "dhcp" ]
then
echo "cifx0 configured to dhcp"
# set dhcp mode
dhclient cifx0
else
#split given parameters in factors
IFS=. read -r i1 i2 i3 i4 <<< "$IP_ADDRESS"
IFS=. read -r m1 m2 m3 m4 <<< "$SUBNET_MASK"

#calculate the broadcast address
BROADCAST=$((i1 & m1 | 255-m1)).$((i2 & m2 | 255-m2)).$((i3 & m3 | 255-m3)).$((i4 & m4 | 255-m4))

# set ip address and subnet mask
ip addr add $IP_ADDRESS/$SUBNET_MASK broadcast $BROADCAST dev cifx0

echo "cifx0 ip address/subnet mask set to" $IP_ADDRESS"/"$SUBNET_MASK

#is a gateway set?
if [ -n "${GATEWAY}" ]
then
echo "gateway set to" $GATEWAY

# flush default routes
ip route flush dev cifx0

# make gateway known
ip route add $GATEWAY dev cifx0

# set route via gateway
NETWORK=$((i1 & m1)).$((i2 & m2)).$((i3 & m3)).$((i4 & m4))
ip route add $NETWORK/$SUBNET_MASK via $GATEWAY src $IP_ADDRESS dev cifx0
else
echo "No cifx0 gateway address configured as environment variable $GATEWAY"
fi
fi
else
echo "cifx0 hardware support (TCP/IP over RTE LAN ports) not configured."
fi
Expand Down

0 comments on commit 57daed9

Please sign in to comment.