Uploaded image for project: 'Funtoo Linux'
  1. Funtoo Linux
  2. FL-3299

Allow better control of wpa_supplicant (per interface)

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Normal Normal
    • None
    • None
    • None

      Runned into a problem with wpa_supplicant where it's init script hijacks all my interfaces on a system where all need different configs and some must be managed by hostapd.

      Created network scripts to fix that:

      /etc/netif.d/wpa_supplicant
      #!/bin/sh
      
      command="/usr/sbin/wpa_supplicant"
      pidfile="/var/run/wpa_supplicant/${interface}.pid"
      config="/etc/wpa_supplicant/${interface}.conf"
      command_args="-s -B -i${interface} -P${pidfile} -c${config}"
      
      netif_depend () {
          need localmount
          use logger
          after bootmisc modules
          before dns dhcpcd net
      }
      
      netif_pre_up() {
          if [ ! -f "${command}" ]; then
      	echo "wpa_supplicant binary not found. Did you emerge net-wireless/wpa_supplicant?"
      	exit 1
          fi
      
          if [ ! -f "${config}" ]; then
      	echo "There's no ${config} file for interface ${interface} in. Aborting."
      	exit 1
          fi
      
          local count=-1
          local label
          local bcast
          for ipnm in $ipaddr $ipaddrs; do
      	if [ $count -ge 0 ]
      	then
      	    label=$interface:$count
      	else
      	    label=""
      	fi
      	if [ -n "$(if_ipv4 $ipnm)" ]
      	then
      	    bcast="broadcast $(get_option "$ipnm" broadcast +)"
      	else
      	    bcast=""
      	fi
      	if [ -z "$label" ]
      	then
      	    ip addr add $(get_ipnm_part "$ipnm") $bcast \
      	       dev $interface || die "Couldn't add $ipnm to $interface"
      	else
      	    ip addr add $(get_ipnm_part "$ipnm") $bcast \
      	       label $label dev $interface || die "Couldn't add $ipnm to $interface"
      	fi
      	count=$(( $count + 1 ))
          done
      }
      
      netif_post_up () {
          if [ -f "${pidfile}" ]; then
      	echo "There's a PID file for interface $interface. Aborting."
      	exit 2
          fi
      
          if [ -n "$driver" ]; then
      	 command_args="${command_args} -D$driver" 
          fi 
      
          $command $command_args
      }
      
      netif_pre_down() {
          if [ ! -f "${pidfile}" ]; then
      	echo "There's no PID file for interface ${interface}. Aborting."
      	exit 3
          fi
          start-stop-daemon --stop --exec "${command}" --pidfile "${pidfile}"
      }
      

      This wasn't really needed because you specify the configs manual but like this more:

      /etc/netif.d/hostapd
      #!/bin/sh
      
      command="/usr/sbin/hostapd"
      pidfile="/var/run/hostapd/${interface}.pid"
      config="/etc/hostapd/${interface}.conf"
      command_args="-B -P${pidfile} ${config}"
      
      netif_depend () {
          use logger
          before dns dhcpcd net
      }
      
      netif_pre_up() {
          if [ ! -f "${command}" ]; then
      	echo "hostapd binary not found. Did you emerge net-wireless/hostapd?"
      	exit 1
          fi
      
          if [ ! -f "${config}" ]; then
      	echo "There's no ${config} file for interface ${interface} in. Aborting."
      	exit 1
          fi
      
          local count=-1
          local label
          local bcast
          for ipnm in $ipaddr $ipaddrs; do
      	if [ $count -ge 0 ]
      	then
      	    label=$interface:$count
      	else
      	    label=""
      	fi
      	if [ -n "$(if_ipv4 $ipnm)" ]
      	then
      	    bcast="broadcast $(get_option "$ipnm" broadcast +)"
      	else
      	    bcast=""
      	fi
      	if [ -z "$label" ]
      	then
      	    ip addr add $(get_ipnm_part "$ipnm") $bcast \
      	       dev $interface || die "Couldn't add $ipnm to $interface"
      	else
      	    ip addr add $(get_ipnm_part "$ipnm") $bcast \
      	       label $label dev $interface || die "Couldn't add $ipnm to $interface"
      	fi
      	count=$(( $count + 1 ))
          done
      }
      
      netif_post_up () {
          if [ -f "${pidfile}" ]; then
      	echo "There's a PID file for interface $interface. Aborting."
      	exit 2
          fi
      
          $command $command_args
      }
      
      netif_pre_down() {
          if [ ! -f "${pidfile}" ]; then
      	echo "There's no PID file for interface ${interface}. Aborting."
      	exit 3
          fi
          start-stop-daemon --stop --exec "${command}" --pidfile "${pidfile}"
      }
      

            drobbins drobbins
            c||_mt Cor Legemaat
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: