Changeset 2692

Show
Ignore:
Timestamp:
03/01/08 01:22:34 (9 months ago)
Author:
dhozac
Message:

Add basic support for creating tun/tap interfaces in the configuration.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/doc/configuration.xml

    r2666 r2692  
    13421342          </description> 
    13431343        </boolean> 
     1344        <boolean name="tun" since="0.30.215"> 
     1345          <description> 
     1346When this file exists, a tun interface will be created when the guest 
     1347starts, and removed when the guest stops. 
     1348          </description> 
     1349        </boolean> 
     1350        <boolean name="tap" since="0.30.215"> 
     1351          <description> 
     1352When this file exists, a tap interface will be created when the guest 
     1353starts, and removed when the guest stops. 
     1354          </description> 
     1355        </boolean> 
     1356        <boolean name="nocsum" since="0.30.215"> 
     1357          <description> 
     1358If a tun or tap interface is created, the presence of this file will 
     1359disable checksumming on it. 
     1360          </description> 
     1361        </boolean> 
     1362        <boolean name="shared" since="0.30.215"> 
     1363          <description> 
     1364When this file exists, the tun/tap interface created will not be 
     1365owned by this particular guest. 
     1366          </description> 
     1367        </boolean> 
     1368        <scalar name="uid" since="0.30.215"> 
     1369          <description> 
     1370Sets the ownership of tun/tap interfaces. Requires a user id, not a 
     1371username. 
     1372          </description> 
     1373        </scalar> 
     1374        <scalar name="gid" since="0.30.215"> 
     1375          <description> 
     1376Sets the group ownership of tun/tap interfaces. Requires a group id, 
     1377not a group name. 
     1378          </description> 
     1379        </scalar> 
     1380        <scalar name="linktype" since="0.30.215"> 
     1381          <description> 
     1382Sets the link type of tun/tap interfaces. 
     1383          </description> 
     1384        </scalar> 
    13441385      </collection> 
    13451386    </collection> 
  • trunk/scripts/util-vserver-vars.pathsubst

    r2626 r2692  
    7171_SHOWPERM="$__LEGACYDIR/showperm" 
    7272_START_VSERVERS="$__PKGLIBDIR/start-vservers" 
     73_TUNCTL="$__PKGLIBDIR/tunctl" 
    7374_VAPT_GET="$__SBINDIR/vapt-get" 
    7475_VAPT_GET_WORKER="$__PKGLIBDIR/vapt-get-worker" 
  • trunk/scripts/vserver.functions

    r2664 r2692  
    6767 
    6868S_CONTEXT= 
     69N_CONTEXT= 
    6970 
    7071SILENT_OPT= 
     
    109110    getFileValue lback "$f" 
    110111 
    111     getFileValue nid "$vdir/ncontext" "$vdir/context" 
    112      
    113     CHBIND_CMD=( $_CHBIND $SILENT_OPT --secure ${nid:+--nid "$nid"} 
     112    CHBIND_CMD=( $_CHBIND $SILENT_OPT --secure ${N_CONTEXT:+--nid "$N_CONTEXT"} 
    114113                 ${bcast:+--bcast "$bcast"} ${lback:+--lback "$lback"} 
    115114                ) 
     
    513512} 
    514513 
     514function _getTunInfo 
     515{ 
     516    local iface="$1" 
     517 
     518    test -e "$iface/tun" -o -e "$iface/tap" || return 1 
     519    test ! -e "$iface/tun"     || echo --tun 
     520    test ! -e "$iface/tap"     || echo --tap 
     521    test ! -e "$iface/nocsum"  || echo --~checksum 
     522    test   -e "$iface/shared"  || echo --nid-failure-ok "$N_CONTEXT" 
     523    if test -e "$iface/uid"; then 
     524        local uid 
     525        getFileValue uid "$iface/uid" 
     526        echo --uid "$uid" 
     527    fi 
     528    if test -e "$iface/gid"; then 
     529        local gid 
     530        getFileValue gid "$iface/gid" 
     531        echo --gid "$gid" 
     532    fi 
     533    if test -e "$iface/linktype"; then 
     534        local linktype 
     535        getFileValue linktype "$iface/linktype" 
     536        echo --linktype "$linktype" 
     537    fi 
     538    return 0 
     539} 
     540 
    515541## Usage: _processSingleInterface <interface-directory> 
    516542function _processSingleInterface 
     
    572598        if ! test -e "$iface"/indirect; then 
    573599            # XXX: IPv6 hack 
    574             use_bcast="broadcast ${bcast:-+}" 
     600            local use_bcast="broadcast ${bcast:-+}" 
    575601            echo "$ip" | $_GREP -q : && use_bcast= 
     602 
     603            local tun_info 
     604            if tun_info=$(_getTunInfo "$iface"); then 
     605                _addInterfaceCmd TUNCTL "$dev" $tun_info 
     606            fi 
     607 
    576608            _addInterfaceCmd IP_ADDR  "$ip${prefix:+/$prefix}" $use_bcast ${name:+label "$dev:$name"} dev "$dev" 
    577609            #_addInterfaceCmd IP_ROUTE "$ip${prefix:+/$prefix}" dev "$dev" 
    578610            _addInterfaceCmd IP_LINK  "$dev" $up 
    579         elif ! test -n "$ctx"; then 
     611        elif ! test -n "$N_CONTEXT"; then 
    580612            echo $"Using 'dummy' (indirect) for interface '$dev' requires a fixed context number; dynamic ctx are not supported" >&2 
    581613            return 1 
    582614        else 
    583             test -z "$mac" || _generateMac mac "$(basename $iface)" "$ctx" || return 1 
     615            test -z "$mac" || _generateMac mac "$(basename $iface)" "$N_CONTEXT" || return 1 
    584616            _addInterfaceCmd MODPROBE dummy "$dev" 
    585617            _addInterfaceCmd IP_LINK  dev dummy0 address "$mac" 
    586618            _addInterfaceCmd NAMEIF   "$dev" "$mac" 
    587619            _addInterfaceCmd IP_ADDR  "$ip${prefix:+/$prefix}" dev "$dev" 
    588             test -z "$extip" || _addInterfaceCmd IPTABLES "$ip${prefix:+/$prefix}" ${name:+label "$dev:$name"} "$ctx" "$extip" 
     620            test -z "$extip" || _addInterfaceCmd IPTABLES "$ip${prefix:+/$prefix}" ${name:+label "$dev:$name"} "$N_CONTEXT" "$extip" 
    589621        fi 
    590622 
     
    597629{ 
    598630    local iface 
    599     local ctx 
    600  
    601     test ! -e "$1"/context || read ctx <"$1"/context 
     631 
     632    # XXX: This is here instead of in _generateChbindOptions 
     633    #      to avoid a circular dependency 
     634    getFileValue N_CONTEXT "$1/ncontext" "$1/context" 
     635    test -n "$N_CONTEXT" -o -z "$S_CONTEXT" || N_CONTEXT="$S_CONTEXT" 
    602636 
    603637    for iface in "$1/interfaces/"*; do 
     
    638672            IP_LINK)            $_IP link  set   "$@";; 
    639673            IP_ROUTE)           $_IP route add   "$@";; 
     674            TUNCTL) 
     675                local dev="$1" 
     676                shift 
     677                $_TUNCTL --persist "$@" "$dev" 
     678                ;; 
    640679            *)                  echo "Unknown interface-command type '$type'" >&2; false;; 
    641680        esac 
     
    673712            IP_LINK)            ;; ## Ignore the link-down command for now 
    674713            IP_ROUTE)           $_IP route del "$@";; 
     714            TUNCTL)             $_TUNCTL --~persist "$1";; 
    675715            *)                  echo "Unknown interface-command type '$type'" >&2; false;; 
    676716        esac 
  • trunk/scripts/vserver.stop

    r2691 r2692  
    9696# Remove persistent so those contexts can be stopped 
    9797$_VATTRIBUTE --set --xid "$S_CONTEXT" --flag !persistent 2>/dev/null || : 
    98 if $_VSERVER_INFO -q "$S_CONTEXT" XIDTYPE static && 
     98if $_VSERVER_INFO -q "$N_CONTEXT" XIDTYPE static && 
    9999   $_VSERVER_INFO - FEATURE vnet; then 
    100     $_NATTRIBUTE --set --nid "$S_CONTEXT" --flag !persistent 2>/dev/null || : 
     100    $_NATTRIBUTE --set --nid "$N_CONTEXT" --flag !persistent 2>/dev/null || : 
    101101fi 
    102102 
  • trunk/src/tunctl.c

    r2688 r2692  
    6262#define CMD_TUN                 0x0200 
    6363#define CMD_TAP                 0x0400 
     64#define CMD_NID_FAILURE_OK      (0x0800 | CMD_NID) 
    6465 
    6566int             wrapper_exit_code  =  255; 
     
    6768struct option const 
    6869CMDLINE_OPTIONS[] = { 
    69   { "help",       no_argument,       0, CMD_HELP }, 
    70   { "version",    no_argument,       0, CMD_VERSION }, 
    71   { "nid",        required_argument, 0, CMD_NID }, 
    72   { "device",     required_argument, 0, CMD_DEVICE }, 
    73   { "persist",    no_argument,       0, CMD_PERSIST }, 
    74   { "~persist",   no_argument,       0, CMD_NOPERSIST }, 
    75   { "checksum",   no_argument,       0, CMD_CSUM }, 
    76   { "~checksum",  no_argument,       0, CMD_NOCSUM }, 
    77   { "uid",        required_argument, 0, CMD_UID }, 
    78   { "gid",        required_argument, 0, CMD_GID }, 
    79   { "linktype",   required_argument, 0, CMD_LINKTYPE }, 
    80   { "tun",        no_argument,       0, CMD_TUN }, 
    81   { "tap",        no_argument,       0, CMD_TAP }, 
     70  { "help",           no_argument,       0, CMD_HELP }, 
     71  { "version",        no_argument,       0, CMD_VERSION }, 
     72  { "nid",            required_argument, 0, CMD_NID }, 
     73  { "device",         required_argument, 0, CMD_DEVICE }, 
     74  { "persist",        no_argument,       0, CMD_PERSIST }, 
     75  { "~persist",       no_argument,       0, CMD_NOPERSIST }, 
     76  { "checksum",       no_argument,       0, CMD_CSUM }, 
     77  { "~checksum",      no_argument,       0, CMD_NOCSUM }, 
     78  { "uid",            required_argument, 0, CMD_UID }, 
     79  { "gid",            required_argument, 0, CMD_GID }, 
     80  { "linktype",       required_argument, 0, CMD_LINKTYPE }, 
     81  { "tun",            no_argument,       0, CMD_TUN }, 
     82  { "tap",            no_argument,       0, CMD_TAP }, 
     83  { "nid-failure-ok", required_argument, 0, CMD_NID_FAILURE_OK }, 
    8284  {0,0,0,0} 
    8385}; 
     
    141143  if (args->set & CMD_GID) 
    142144    EioctlD(fd, TUNSETGROUP, (void *) (long) args->gid); 
    143   if (args->set & CMD_NID) 
    144     EioctlD(fd, TUNSETNID, (void *) (long) args->nid); 
     145  if (args->set & CMD_NID) { 
     146    if (args->set & CMD_NID_FAILURE_OK) 
     147      ioctl(fd, TUNSETNID, (void *) (long) args->nid); 
     148    else 
     149      EioctlD(fd, TUNSETNID, (void *) (long) args->nid); 
     150  } 
    145151  if (args->set & CMD_LINKTYPE) 
    146152    EioctlD(fd, TUNSETLINK, (void *) (long) args->linktype); 
     
    175181      case CMD_VERSION  :  showVersion(); 
    176182 
     183      case CMD_NID_FAILURE_OK: 
    177184      case CMD_NID      :  args.nid = Evc_nidopt2nid(optarg, true);     break; 
    178185      case CMD_DEVICE   :  args.device = optarg;                        break;