Manual:Partes/Rede/Estendendo

From Gentoo Wiki
Jump to: navigation, search
This page is a translated version of the page Handbook:Parts/Networking/Extending and the translation is 19% complete.

Other languages:
Deutsch • ‎English • ‎español • ‎français • ‎português do Brasil • ‎русский • ‎中文(中国大陆)‎ • ‎日本語 • ‎한국어
Parts Handbook
Installation
About the installation
Choosing the media
Configuring the network
Preparing the disks
Installing stage3
Installing base system
Configuring the kernel
Configuring the system
Installing tools
Configuring the bootloader
Finalizing
Working with Gentoo
Portage introduction
USE flags
Portage features
Initscript system
Environment variables
Working with Portage
Files and directories
Variables
Mixing software branches
Additional tools
Custom package repository
Advanced features
Network configuration
Getting started
Advanced configuration
Modular networking
Wireless
Adding functionality
Dynamic management


Standard function hooks

Quatro funções podem ser definidas em /etc/conf.d/net que serão chamadas em torno das operações de iniciar/parar. As funções são chamadas com o nome da interface primeiro de modo que a função pode controlar múltiplos adaptadores.

Os valores de retorno das funções preup() e predown() deve ser 0 (sucesso) para indicar que a configuração ou desconfiguração da interface pode continuar. Se preup() retornar um valor não zero, a configuração da interface será abortada. Se predown() retornar um valor não zero, a interface não será permitida a continuar a desconfiguração.

Os valores de retorno das funções postup() e postdown() são ignorados uma vez que nada resta a fazer se elas indicarem falha.

${IFACE} é a interface sendo configurada ou desconfigurada. ${IFVAR} é ${IFACE} convertida para nome de variável permitida pelo bash.

FILE /etc/conf.d/netpre/post up/down function examples
preup() {
  # Test for link on the interface prior to bringing it up.  This
  # only works on some network adapters and requires the ethtool
  # package to be installed.
  if ethtool ${IFACE} | grep -q 'Link detected: no'; then
    ewarn "No link on ${IFACE}, aborting configuration"
    return 1
  fi
  
  # Remember to return 0 on success
  return 0
}
  
predown() {
  # The default in the script is to test for NFS root and disallow
  # downing interfaces in that case.  Note that if you specify a
  # predown() function you will override that logic.  Here it is, in
  # case you still want it...
  if is_net_fs /; then
    eerror "root filesystem is network mounted -- can't stop ${IFACE}"
    return 1
  fi
  
  # Remember to return 0 on success
  return 0
}
  
postup() {
  # This function could be used, for example, to register with a
  # dynamic DNS service.  Another possibility would be to
  # send/receive mail once the interface is brought up.
       return 0
}
  
postdown() {
  # This function is mostly here for completeness... I haven't
  # thought of anything nifty to do with it yet ;-)
  return 0
}
Nota
Para mais informações sobre escrever funções, por favor veja /usr/share/doc/netifrc-*/net.example.bz2.

Wireless tools function hook

Note
This will not work with WPA Supplicant - but the ${ESSID} and ${ESSIDVAR} variables are available in the postup() function.

Two functions can be defined in /etc/conf.d/net which will be called surrounding the associate function. The functions are called with the interface name first so that one function can control multiple adapters.

Os valores de retorno da função preassociate() deve ser 0 (sucesso) para indicar que a configuração e desconfiguração da interface pode continuar. Se preassociate() retornar um valor não zero, a configuração da interface é abortada.

O valor de retorno da função postassociate() é ignorado uma vez que não há nada a ser feito se ele indicar falha.

${ESSID} is set to the exact ESSID of the AP the system is connecting to. ${ESSIDVAR} is ${ESSID} converted to a variable name bash allows.

FILE /etc/conf.d/netpre/post association functions
preassociate() {
  # The below adds two configuration variables leap_user_ESSID
  # and leap_pass_ESSID. When they are both configured for the ESSID
  # being connected to then we run the CISCO LEAP script
  
  local user pass
  eval user=\"\$\{leap_user_${ESSIDVAR}\}\"
  eval pass=\"\$\{leap_pass_${ESSIDVAR}\}\"
  
  if [[ -n ${user} && -n ${pass} ]]; then
    if [[ ! -x /opt/cisco/bin/leapscript ]]; then
      eend "For LEAP support, please emerge net-misc/cisco-aironet-client-utils"
      return 1
    fi
    einfo "Waiting for LEAP Authentication on \"${ESSID//\\\\//}\""
    if /opt/cisco/bin/leapscript ${user} ${pass} | grep -q 'Login incorrect'; then
      ewarn "Login Failed for ${user}"
      return 1
    fi
  fi
  
  return 0
}
  
postassociate() {
  # This function is mostly here for completeness... I haven't
  # thought of anything nifty to do with it yet ;-)
  
  return 0
}
Note
${ESSID} and ${ESSIDVAR} are unavailable in predown() and postdown() functions.
Note
For more information on writing custom functions, please read /usr/share/doc/netifrc-*/net.example.bz2.