kamailio: Kamailio 6.0.1 uci config and init script fixes 894/head
authorPaul Donald <[email protected]>
Sun, 20 Apr 2025 01:56:56 +0000 (03:56 +0200)
committerPaul Donald <[email protected]>
Sun, 20 Apr 2025 01:56:56 +0000 (03:56 +0200)
bump pkg_memory 2MiB -> 3MiB.
space -> tab convert kamailio.init file
refactor kamailio.init check_listen() for clarity
cfg_target: append /
quote uci config values
chown kamailio:kamailio -R /etc/kamailio/*
debug_level 0
stderr 0

Signed-off-by: Paul Donald <[email protected]>
net/kamailio/Makefile
net/kamailio/files/kamailio.conf
net/kamailio/files/kamailio.init

index 2e6a0966326f86903a29de759d10a38e96426659..023df285e1e7603eddfacdeaa542f889a7fb8d19 100644 (file)
@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=kamailio
 PKG_VERSION:=6.0.1
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE_URL:=https://github.com/kamailio/kamailio/archive/refs/tags/
 PKG_SOURCE:=$(PKG_VERSION).tar.gz
@@ -263,6 +263,8 @@ endef
 define Package/kamailio
 $(call Package/kamailio/Default)
   TITLE:=Mature and flexible open source SIP server, v$(PKG_VERSION)
+  USER:=kamailio
+  GROUP:=kamailio
   USERID:=kamailio=380:kamailio=380
   MENU:=1
 endef
@@ -300,6 +302,7 @@ endef
 
 define Package/kamailio/postinst
 #!/bin/sh
+chown "$(USER)":"$(GROUP)" "/etc/kamailio" -R
 if [ -z "$${IPKG_INSTROOT}" ]; then
   echo
   echo "o-------------------------------------------------------------------o"
@@ -412,7 +415,7 @@ MAKE_FLAGS += \
        LIBDIR=lib \
        PREFIX=/usr \
        cfg_prefix="$(PKG_INSTALL_DIR)" \
-       cfg_target=/etc/kamailio \
+       cfg_target=/etc/kamailio/ \
        group_include="standard" \
        include_modules="$$(INCL_MODULES) $(EXTRA_MODULES)" \
        quiet=verbose \
index f1a9c36a4bcee4899df07a35e1fe7a2feff91ebc..b78b2cebcf3f35105c9d03366a1dc7aa61441cb2 100644 (file)
@@ -1,22 +1,25 @@
 
 config kamailio 'general'
-       option enabled 0
-       option user kamailio
-       option group kamailio
+       option enabled '0'
+       option user 'kamailio'
+       option group 'kamailio'
        # Amount of shared and private memory to allocate in MByte:
-       option shm_memory 8
-       option pkg_memory 2
+       option shm_memory '8'
+       option pkg_memory '3'
        option cfg_file /etc/kamailio/kamailio.cfg
-       # The lists "listen" and "listen6" basically have the same
-       # effect - each list entry will be added to the Kamailio command
-       # line ("-l address"). However, the init script will try to
+       option stderr '0'
+       option debug_level '0'
+       # list listen(6) have the same effect - each list entry is added to the
+       # Kamailio command line ("-l address"). The init script will try to
        # resolve any interface specifier into an IPv4 ("listen") or
-       # IPv6 ("listen6") address before starting Kamailio. These lists
+       # IPv6 ("listen6") address before starting Kamailio. These list listen(6)
        # may be helpful when using dynamic IPs.
-       #list listen udp:wan:5060
-       #list listen udp:192.168.1.1:5060
-       #list listen6 udp:wan:5060
-       # Any other option can be put between the quotes below:
+       # Examples:
+       # list listen 'udp:wan:5060'
+       # list listen 'udp:192.168.1.1:5060'
+       # list listen6 'udp:wan:5060'
+       # list listen6 'udp:[::1]:5060'
+       # Any other Kamailio start parameter can be put in the options quotes below:
        #option options ""
 
 config kamailio 'hotplug'
index bf365072327dda90138662f2acc08ac6dfcecbed..0c8c722c50488c8b06c089f5d09b106756c5c69c 100644 (file)
@@ -16,116 +16,136 @@ USE_PROCD=1
 #PROCD_DEBUG=1
 
 check_listen() {
-  local value="$1"
-  local type="$2"
-
-  local address
-  local has_proto=0
-  local one two three
-  local tmp
-
-  [ -z "$value" ] && {
-    $LOG_ERR empty $type entry
-    return 1
-  }
-
-  # IPv6 addresses need to be enclosed in square brackets. If there are
-  # square brackets in the listen entry, just copy it.
-  echo "$value" | grep "\[[0-9:A-Fa-f]*\]" &> /dev/null && {
-    options=$options" -l $value"
-    return
-  }
-
-  # Bail if more than 2 colons.
-  [ $(echo "$value" | awk -F ":" '{print NF-1}') -gt 2 ] && {
-    $LOG_ERR init script does not understand $type entry \""$value"\"
-    return 1
-  }
-
-  IFS=":" read one two three << EOF
-$value
-EOF
-
-  case "$one" in
-    udp|tcp|tls|sctp)
-      tmp="$two"
-      has_proto=1
-      ;;
-    *)
-      tmp="$one"
-      ;;
-  esac
-
-  if [ "$type" = "listen" ]; then
-    network_get_ipaddr address "$tmp" || address="$tmp"
-  else
-    network_get_ipaddr6 address "$tmp" && address="[$address]" || \
-                                                     address="$tmp"
-  fi
-
-  if [ -n "$three" ]; then
-    tmp="$one:$address:$three"
-  elif [ -n "$two" ]; then
-    if [ $has_proto = 1 ]; then
-      tmp="$one:$address"
-    else
-      tmp="$address:$two"
-    fi
-  else
-    tmp="$address"
-  fi
-
-  options=$options" -l $tmp"
+       local value="$1"
+       local type="$2"
+
+       local proto host port address result
+
+       [ -z "$value" ] && {
+               $LOG_ERR empty $type entry
+               return 1
+       }
+
+       # [IPv6] - pass through as-is
+       case "$value" in
+               *\[*\]*)
+                       options="$options -l $value"
+                       return
+                       ;;
+       esac
+
+       # Count colons. More than 2 means malformed
+       # Format: proto:host:port
+       if [ "$(echo "$value" | awk -F: '{print NF-1}')" -gt 2 ]; then
+               $LOG_ERR init script does not understand $type entry \""$value"\"
+               return 1
+       fi
+
+       # Parse proto (if present)
+       case "$value" in
+               udp:*|tcp:*|tls:*|sctp:*)
+                       proto="${value%%:*}"
+                       value="${value#*:}"
+                       ;;
+       esac
+
+       # Parse port (if present)
+       case "$value" in
+               *:* )
+                       host="${value%%:*}"
+                       port="${value#*:}"
+                       ;;
+               *)
+                       host="$value"
+                       port=""
+                       ;;
+       esac
+
+       # Resolve host to IP or interface
+       if [ "$type" = "listen" ]; then
+               network_get_ipaddr address "$host" || address="$host"
+       else
+               network_get_ipaddr6 address "$host" && address="[$address]" || address="$host"
+       fi
+
+       # Reconstruct result
+       if [ -n "$proto" ]; then
+               if [ -n "$port" ]; then
+                       result="$proto:$address:$port"
+               else
+                       result="$proto:$address"
+               fi
+       else
+               if [ -n "$port" ]; then
+                       result="$address:$port"
+               else
+                       result="$address"
+               fi
+       fi
+
+       options="$options -l $result"
 }
 
 start_service() {
-  local enabled
-  local user
-  local group
-  local shm_memory
-  local pkg_memory
-  local cfg_file
-  local options
-
-  config_load $NAME
-
-  config_get_bool enabled general enabled 0
-
-  if [ $enabled -eq 0 ]; then
-    $LOG_ERR service not enabled in /etc/config/$NAME
-    return 1
-  fi
-
-  config_get user       general user       $NAME
-  config_get group      general group      $NAME
-  config_get shm_memory general shm_memory 8
-  config_get pkg_memory general pkg_memory 2
-  config_get cfg_file   general cfg_file   /etc/$NAME/$NAME.cfg
-  config_get options    general options
-
-  . /lib/functions/network.sh
-
-  config_list_foreach general listen  check_listen listen
-  config_list_foreach general listen6 check_listen listen6
-
-  if [ ! -d $RUNDIR ]; then
-    mkdir -p $RUNDIR
-    chown "$user":"$group" $RUNDIR
-  fi
-
-  procd_open_instance
-  procd_set_param command $COMMAND
-  procd_append_param command \
-    -P $PIDFILE \
-    -f "$cfg_file" \
-    -m "$shm_memory" \
-    -M "$pkg_memory" \
-    $options \
-    -u "$user" \
-    -g "$group" \
-    -DD -E
-  # forward stderr to logd
-  procd_set_param stderr 1
-  procd_close_instance
+       local enabled
+       local user
+       local group
+       local shm_memory
+       local pkg_memory
+       local cfg_file
+       local options
+
+       config_load $NAME
+
+       config_get_bool enabled general enabled 0
+
+       if [ $enabled -eq 0 ]; then
+               $LOG_ERR service not enabled in /etc/config/$NAME
+               return 1
+       fi
+
+       config_get user        general user       $NAME
+       config_get group       general group      $NAME
+       config_get shm_memory  general shm_memory 8
+       config_get pkg_memory  general pkg_memory 3
+       config_get cfg_file    general cfg_file   /etc/$NAME/$NAME.cfg
+       config_get options     general options
+       config_get_bool stderr general stderr 0
+       config_get debug_level general debug_level 0
+
+       . /lib/functions/network.sh
+
+       config_list_foreach general listen  check_listen listen
+       config_list_foreach general listen6 check_listen listen6
+
+       if [ ! -d "$RUNDIR" ]; then
+               mkdir -p "$RUNDIR"
+               chown "$user":"$group" "$RUNDIR"
+       fi
+
+       if [ -d "/etc/kamailio" ]; then
+               chown "$user":"$group" /etc/kamailio/ -R
+       fi
+
+       procd_open_instance
+       procd_set_param command $COMMAND
+       procd_append_param command \
+               -P $PIDFILE \
+               -f "$cfg_file" \
+               -m "$shm_memory" \
+               -M "$pkg_memory" \
+               $options \
+               -u "$user" \
+               -g "$group" \
+               -DDD
+       # If log_stderror=no (default) global parameter and -E is not provided, then it writes to syslog daemon
+       [ "$stderr" -eq '1' ] && procd_append_param command -E
+       procd_append_param command --debug $debug_level
+
+       # silence stderr (useful only for debug)
+       procd_set_param stderr 0
+       # forward stdout to logd
+       procd_set_param stdout 1
+       procd_close_instance
 }