unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alex Kost <alezost@gmail.com>
To: Danny Milosavljevic <dannym@scratchpost.org>
Cc: guix-devel@gnu.org
Subject: Re: (pre-)creation of tunnel network interfaces
Date: Fri, 26 Feb 2016 14:47:42 +0300	[thread overview]
Message-ID: <87ziunu201.fsf@gmail.com> (raw)
In-Reply-To: <20160225234418.610eed7f@scratchpost.org> (Danny Milosavljevic's message of "Thu, 25 Feb 2016 23:44:18 +0100")

[-- Attachment #1: Type: text/plain, Size: 643 bytes --]

Danny Milosavljevic (2016-02-26 01:44 +0300) wrote:

> Hi,
>
> I'm using openconnect to connect to a few VPNs.
>
> Most of openconnect actually doesn't require root.
> In order to avoid root, I'd like to pre-create the tunnel interfaces.
>
> This would be done by
>
>   # ip tuntap add vpn0 mode tun user dannym
>                   ^                  ^--- this is the user that is allowed to use the tunnel later
>                    ---- the new tunnel interface
>
> How do I specify this in a system config?

By adding a service that starts this command to your operating-system
declaration.  It would be something like this (not tested!):


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: vpn-tunnel-system.scm --]
[-- Type: text/x-scheme, Size: 1268 bytes --]

(use-modules
 (ice-9 match)
 (gnu)
 (gnu packages linux) ; for iproute
 (gnu services)
 (gnu services shepherd)
 (guix records))

(define-record-type* <vpn-tunnel>
  vpn-tunnel make-vpn-tunnel
  vpn-tunnel?
  (interface-name vpn-tunnel-interface-name)
  (user-name vpn-tunnel-user-name))

(define vpn-tunnel-service-type
  (shepherd-service-type
   'vpn-tunnel
   (match-lambda
     (($ <vpn-tunnel> interface user)
      (let ((ip #~(string-append #$iproute "/sbin/ip")))
        (shepherd-service
         (documentation "Create tunnel interface.")
         (provision '(vpn-tunnel))
         (requirement '(networking))
         (start
          #~(lambda _
              ;; Return #t if successfully started.
              (zero? (system* #$ip "tuntap" "add" #$interface
                              "mode" "tun"
                              "user" #$user))))
         (respawn? #f)))))))

(define (vpn-tunnel-service interface-name user-name)
  "Return a service that ..."
  (service vpn-tunnel-service-type
           (vpn-tunnel (interface-name interface-name)
                       (user-name user-name))))

(operating-system
  ;; ...
  (services (cons* (vpn-tunnel-service "vpn0" "dannym")
                   ;; ...
                   %desktop-services)))

[-- Attachment #3: Type: text/plain, Size: 10 bytes --]


-- 
Alex

  reply	other threads:[~2016-02-26 11:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-25 22:44 (pre-)creation of tunnel network interfaces Danny Milosavljevic
2016-02-26 11:47 ` Alex Kost [this message]
2016-02-26 23:28   ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ziunu201.fsf@gmail.com \
    --to=alezost@gmail.com \
    --cc=dannym@scratchpost.org \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).