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

[0.23.x] Support dual stack network, IP v4 and v6 #369

Draft
wants to merge 1 commit into
base: 0.23.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function launchServer() {
local imgVersion=${JBOSS_IMAGE_VERSION:-$IMAGE_VERSION}
log_info "Running $imgName image, version $imgVersion"

${cmd} ${JAVA_PROXY_OPTIONS} ${JBOSS_HA_ARGS} ${JBOSS_MESSAGING_ARGS} ${CLI_EXECUTION_OPTS} &
${cmd} -bmanagement ${SERVER_BIND_ALL_ADDR} -bbindall ${SERVER_BIND_ALL_ADDR} ${JAVA_PROXY_OPTIONS} ${JBOSS_HA_ARGS} ${JBOSS_MESSAGING_ARGS} ${CLI_EXECUTION_OPTS} &

local pid=$!

Expand Down
102 changes: 102 additions & 0 deletions jboss/container/wildfly/launch-config/os/added/launch/launch-common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,106 @@ function splitAttributesStringIntoLines() {
local temp
temp=$(echo $input | sed "s|\" ${attribute_name}=\"|\" \n${attribute_name}=\"|g" | awk -F "\"" '{print $2}')
echo "${temp}"
}

# retrieves the first IP v6 address
function get_host_ipv6() {
unset -v "$1" || echo "Invalid identifier: $1" >&2

local input="/proc/net/if_inet6"

if [ ! -f "$input" ]; then
log_error "$input file doesn't exist. Can't discover ip v6 address."
exit 1
fi
local count=0
while IFS= read -r line
do
arr=($line)
address=${arr[0]}
# Skip loopback and link local addresses
if [ $address != "00000000000000000000000000000001" ] && [[ $address != fe80* ]]; then
if [ -z "$ipv6" ]; then
local ipv6="${address:0:4}:${address:4:4}:${address:8:4}:${address:12:4}:${address:16:4}:${address:20:4}:${address:24:4}:${address:28:4}"
fi
count=$((count+1))
fi
done < "$input"

if [[ "$count" == "0" ]]; then
log_error "No IP v6 address found. Can't configure IPv6"
exit 1
fi

if [[ "$count" != "1" ]]; then
log_warning "get_host_ipv6() returned $count ipv6 addresses, only the first address $ipv6 will be used. To use different address please set $JBOSS_HA_IP and $JBOSS_MESSAGING_HOST."
fi

printf -v "$1" '%s' "${ipv6}"
}

#
# Find the first ipv4 address of the host
# The host could have 1 or more ipv4 addresses
# For this function we need to return a single ipv4 address
#
# /proc/net/fib_tree contains the Forwarding Information Base table
#
# awk is using a block-pattern to filter lines with 32 or host
#
# python or other languages can not be used and it must be /bin/sh compatible
#
# depends on the following tools:
# sh, awk, sort, uniq, grep, wc, head
function get_host_ipv4() {
unset -v "$1" || echo "Invalid identifier: $1" >&2
local input="/proc/net/fib_trie"

if [ ! -f "$input" ]; then
log_error "$input file doesn't exist. Can't discover ip v4 address."
exit 1
fi
local allIPs=$(awk '/32 host/ { print f } {f=$2}' <<< "$(<$input)" | sort -n | uniq | grep -v '127.0.0.')
local count=$(echo "$allIPs" | wc -l)

local ipv4=$(echo "$allIPs" | head -n1)

if [[ "$count" == "0" ]]; then
log_error "No IP v4 address found."
exit 1
fi
if [[ "$count" != "1" ]]; then
log_warning "get_host_ipv4() returned $count ipv4 addresses, only the first address $ipv4 will be used. To use different address please set \$JBOSS_HA_IP and \$JBOSS_MESSAGING_HOST."
fi
printf -v "$1" '%s' "${ipv4}"
}

# Retrieves the ip v4 (the default) or ip v6 (if SERVER_USE_IPV6 env variable is set).
# The passed argument is a name of a variable that will be set by this function
# Usage:
# local ip=
# get_host_ip_address "ip"
# echo $ip
function get_host_ip_address() {
if [ "xxx$SERVER_USE_IPV6" == "xxxtrue" ]; then
get_host_ipv6 "$1"
else
get_host_ipv4 "$1"
fi
}

function get_bind_all_address() {
if [ "xxx$SERVER_USE_IPV6" == "xxxtrue" ]; then
echo "::"
else
echo "0.0.0.0"
fi
}

function get_loopback_address() {
if [ "xxx$SERVER_USE_IPV6" == "xxxtrue" ]; then
echo "::1"
else
echo "127.0.0.1"
fi
}
31 changes: 31 additions & 0 deletions jboss/container/wildfly/launch/ip-address/added/ip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh
# only processes a single environment as the placeholder is not preserved

source $JBOSS_HOME/bin/launch/logging.sh

function prepareEnv() {
unset SERVER_USE_IPV6
}

function configure() {
configure_ip
}

function configureEnv() {
configure
}

function configure_ip() {
SERVER_IP_ADDR=
get_host_ip_address "SERVER_IP_ADDR"
export SERVER_IP_ADDR
SERVER_BIND_ALL_ADDR=$(get_bind_all_address)
export SERVER_BIND_ALL_ADDR
SERVER_LOOPBACK_ADDRESS=$(get_loopback_address)
export SERVER_LOOPBACK_ADDRESS
log_info "Server IP address $SERVER_IP_ADDR, bindAll adress $SERVER_BIND_ALL_ADDR"
if [ "xxx$SERVER_USE_IPV6" == "xxxtrue" ]; then
JAVA_OPTS_APPEND="-Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Addresses=true $JAVA_OPTS_APPEND"
export JAVA_OPTS_APPEND
fi
}
9 changes: 9 additions & 0 deletions jboss/container/wildfly/launch/ip-address/configure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

set -e

SCRIPT_DIR=$(dirname $0)
ADDED_DIR=${SCRIPT_DIR}/added

mkdir -p ${JBOSS_HOME}/bin/launch/
cp -p ${ADDED_DIR}/ip.sh ${JBOSS_HOME}/bin/launch/
10 changes: 10 additions & 0 deletions jboss/container/wildfly/launch/ip-address/module.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
schema_version: 1
name: jboss.container.wildfly.launch.ip-address
version: '1.0'
description: Configure ip address.
execute:
- script: configure.sh
user: '185'
envs:
- name: "SERVER_USE_IPV6"
description: By default IP v4 is used. Set this env variable to true to enable IP v6.
3 changes: 1 addition & 2 deletions jboss/container/wildfly/launch/jgroups/added/launch/ha.sh
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,7 @@ generate_dns_ping_config() {

configure_ha_args() {
# Set HA args
IP_ADDR=`hostname -i`
JBOSS_HA_ARGS="-b ${JBOSS_HA_IP:-${IP_ADDR}} -bprivate ${JBOSS_HA_IP:-${IP_ADDR}}"
JBOSS_HA_ARGS="-b ${JBOSS_HA_IP:-${SERVER_IP_ADDR}} -bprivate ${JBOSS_HA_IP:-${SERVER_IP_ADDR}}"

init_node_name

Expand Down
2 changes: 1 addition & 1 deletion jboss/container/wildfly/launch/jgroups/test/ha.bats
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ EOF
# check that non-empty OPENSHIFT_DNS_PING_SERVICE_NAME is present when using dns.DNS_PING
@test "Generate JGroups ping config - dns.DNS_PING requires service name" {
expected=$(cat <<EOF
/tmp/jboss_home/bin/launch/ha.sh: line 295: init_node_name: command not found
/tmp/jboss_home/bin/launch/ha.sh: line 294: init_node_name: command not found
ERROR Environment variable OPENSHIFT_DNS_PING_SERVICE_NAME is required when using dns.DNS_PING ping protocol. Please refer to the documentation for configuration.
EOF
)
Expand Down
1 change: 0 additions & 1 deletion jboss/container/wildfly/launch/keycloak/added/keycloak.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,6 @@ function configure_client() {
client_config="${client_config},\"attributes\":{\"saml.signing.certificate\":\"${pem}\"${server_signature}}"
fi
else
service_addr=$(hostname -i)
client_config="{\"redirectUris\":[${redirects}]"

if [ -n "$HOSTNAME_HTTP" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function configure() {
}

function configure_artemis_address() {
IP_ADDR=${JBOSS_MESSAGING_HOST:-`hostname -i`}
IP_ADDR=${JBOSS_MESSAGING_HOST:-${SERVER_IP_ADDR}}
JBOSS_MESSAGING_ARGS="${JBOSS_MESSAGING_ARGS} -Djboss.messaging.host=${IP_ADDR}"
}
# /subsystem=messaging-activemq/server=default/jms-queue=queue_name:add(entries=[])
Expand Down